forked from organicmaps/organicmaps
[] SearchTask for monkey.
This commit is contained in:
parent
7755720fdb
commit
5b3661b640
4 changed files with 142 additions and 42 deletions
|
@ -1,11 +1,15 @@
|
|||
package com.mapswithme.test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.mapswithme.maps.MWMActivity;
|
||||
import com.mapswithme.maps.MWMActivity.OpenUrlTask;
|
||||
import com.mapswithme.maps.MWMActivity.MapTask;
|
||||
import com.mapswithme.maps.SearchActivity;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.SimpleLogger;
|
||||
|
||||
|
@ -13,19 +17,80 @@ public class TestEventsReceiver extends BroadcastReceiver
|
|||
{
|
||||
|
||||
|
||||
Logger l = SimpleLogger.get("TestBro");
|
||||
static Logger l = SimpleLogger.get("TestBro");
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
l.d(intent.toString());
|
||||
final String uri = intent.getStringExtra("uri");
|
||||
l.d(uri);
|
||||
ExtractableMapTask mapTask = KEY_TO_TASK.get(intent.getStringExtra(EXTRA_TASK));
|
||||
if (mapTask != null)
|
||||
{
|
||||
mapTask = mapTask.extract(intent);
|
||||
l.d(mapTask.toString());
|
||||
intent = new Intent(context, MWMActivity.class);
|
||||
intent.putExtra(MWMActivity.EXTRA_TASK, mapTask);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
else
|
||||
l.d("No task found");
|
||||
}
|
||||
|
||||
MWMActivity.OpenUrlTask oTask = new OpenUrlTask(uri);
|
||||
|
||||
intent = new Intent(context, MWMActivity.class);
|
||||
intent.putExtra(MWMActivity.EXTRA_TASK, oTask);
|
||||
public interface ExtractableMapTask extends MapTask
|
||||
{
|
||||
public ExtractableMapTask extract(Intent intent);
|
||||
};
|
||||
|
||||
private static String EXTRA_TASK = "task";
|
||||
private static String TYPE_SEARCH = "task_search";
|
||||
private static String TYPE_POINT = "task_point";
|
||||
private static String TYPE_BOOKMARK = "task_bmk";
|
||||
private static String TYPE_PPAGE = "task_ppage";
|
||||
|
||||
private static final Map<String, ExtractableMapTask> KEY_TO_TASK = new HashMap<String, ExtractableMapTask>(4);
|
||||
|
||||
static {
|
||||
KEY_TO_TASK.put(TYPE_POINT, null);
|
||||
KEY_TO_TASK.put(TYPE_BOOKMARK, null);
|
||||
KEY_TO_TASK.put(TYPE_SEARCH, new SearchTask());
|
||||
KEY_TO_TASK.put(TYPE_PPAGE, null);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class SearchTask implements ExtractableMapTask
|
||||
{
|
||||
String query;
|
||||
int scope;
|
||||
|
||||
@Override
|
||||
public boolean run(MWMActivity target)
|
||||
{
|
||||
SearchActivity.startForSearch(target, query, scope);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtractableMapTask extract(Intent data)
|
||||
{
|
||||
SearchTask task = new SearchTask();
|
||||
|
||||
task.query = data.getStringExtra(SearchActivity.EXTRA_QUERY);
|
||||
l.d("q: ", task.query);
|
||||
|
||||
final String scopeStr = data.getStringExtra(SearchActivity.EXTRA_SCOPE);
|
||||
l.d("s: ", scopeStr);
|
||||
if (scopeStr != null) task.scope = Integer.parseInt(scopeStr);
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "SearchTask [query=" + query + ", scope=" + scope + "]";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.mapswithme.maps;
|
|||
|
||||
import android.app.ActionBar;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
|
@ -12,7 +13,6 @@ import android.util.Log;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.BaseAdapter;
|
||||
|
@ -34,6 +34,16 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati
|
|||
private static String TAG = "SearchActivity";
|
||||
public static final String SEARCH_RESULT = "search_result";
|
||||
|
||||
public static final String EXTRA_SCOPE = "search_scope";
|
||||
public static final String EXTRA_QUERY = "search_query";
|
||||
|
||||
public static void startForSearch(Context context, String query, int scope)
|
||||
{
|
||||
Intent i = new Intent(context, SearchActivity.class);
|
||||
i.putExtra(EXTRA_SCOPE, scope).putExtra(EXTRA_QUERY, query);
|
||||
context.startActivity(i);
|
||||
}
|
||||
|
||||
private static class SearchAdapter extends BaseAdapter
|
||||
{
|
||||
private final SearchActivity m_context;
|
||||
|
@ -488,6 +498,19 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati
|
|||
|
||||
// Create search list view adapter.
|
||||
setListAdapter(new SearchAdapter(this));
|
||||
|
||||
|
||||
//checking search intent
|
||||
final Intent intent = getIntent();
|
||||
if (intent != null)
|
||||
{
|
||||
if (intent.hasExtra(EXTRA_QUERY))
|
||||
{
|
||||
m_searchBox.setText(intent.getStringExtra(EXTRA_QUERY));
|
||||
m_modesSpinner.setSelection(intent.getIntExtra(EXTRA_SCOPE, 0));
|
||||
runSearch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,25 +8,36 @@ package = 'com.mapswithme.maps.pro'
|
|||
activity = 'com.mapswithme.maps.DownloadResourcesActivity'
|
||||
mapactivity = 'com.mapswithme.maps.MWMActivity'
|
||||
|
||||
sampleUris = ([
|
||||
('ge0://o4aXJl2FbJ/TNT_Rock_Club', 0),
|
||||
('ge0://o4aXJlDxJj/Newman', 1),
|
||||
('ge0://Q4CNu8AejK/Paris', 2),
|
||||
('ge0://04aXJfyIVr/Опоп-69', 3),
|
||||
('ge0://jwDj9dKFgF/Port_Harcourt', 4)
|
||||
])
|
||||
|
||||
|
||||
def follow_path(device, path):
|
||||
MonkeyRunner.sleep(10)
|
||||
for x in range(0, len(path)):
|
||||
print path[x]
|
||||
sendUrl(device, path[x][0], path[x][1])
|
||||
|
||||
|
||||
def sendUrl(device, geoUri, index=0):
|
||||
device.broadcastIntent(action='mwmtest', extras={'uri': geoUri})
|
||||
MonkeyRunner.sleep(1)
|
||||
device.wake()
|
||||
def run_tasks(device, tasks):
|
||||
MonkeyRunner.sleep(5)
|
||||
di = DeviceInfo(device)
|
||||
device.takeSnapshot().writeToFile(di.get_screenshot_path(index))
|
||||
for x in range(0, len(tasks)):
|
||||
print tasks[x]
|
||||
tasks[x].send(device)
|
||||
MonkeyRunner.sleep(5)
|
||||
device.takeSnapshot().writeToFile(di.get_screenshot_path(x))
|
||||
|
||||
|
||||
class MWMTask:
|
||||
def send(self, device):
|
||||
pass
|
||||
|
||||
|
||||
class SearchTask(MWMTask):
|
||||
task = 'task_search'
|
||||
query = ''
|
||||
scope = 0
|
||||
|
||||
def __init__(self, query, scope=0):
|
||||
self.query = query
|
||||
self.scope = scope
|
||||
|
||||
|
||||
def send(self, device):
|
||||
device.broadcastIntent(action='mwmtest',
|
||||
extras={'task': self.task, 'search_query': str(self.query),
|
||||
'search_scope': str(self.scope)})
|
||||
|
||||
def __str__(self):
|
||||
return 'SearchTask %s %s' % (self.query, str(self.scope))
|
||||
|
|
|
@ -1,14 +1,23 @@
|
|||
#!/usr/bin/env monkeyrunner
|
||||
# coding=utf-8
|
||||
|
||||
import sys
|
||||
|
||||
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
|
||||
from mapswithme import activity
|
||||
import mapswithme as mwm
|
||||
from mapswithme import *
|
||||
|
||||
|
||||
sampleTasks = (SearchTask('Minsk'),
|
||||
SearchTask('London'),
|
||||
SearchTask('еда'),
|
||||
SearchTask('кино'),
|
||||
SearchTask('drink'),
|
||||
SearchTask('eat'),
|
||||
SearchTask('tener'),
|
||||
SearchTask('\"улица ленина\"'),
|
||||
SearchTask('Berlin'))
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
# using specified id
|
||||
id = sys.argv[1]
|
||||
print 'Connecting to device %s' % id
|
||||
device = MonkeyRunner.waitForConnection(5, id)
|
||||
|
@ -21,18 +30,10 @@ if not device:
|
|||
else:
|
||||
print 'Connected'
|
||||
|
||||
apkPath = mwm.apkPath
|
||||
activity = mwm.activity
|
||||
package = mwm.package
|
||||
|
||||
print 'Installing file %s' % apkPath
|
||||
|
||||
device.installPackage(apkPath)
|
||||
|
||||
device.wake()
|
||||
|
||||
runComponent = package + '/' + activity
|
||||
print 'Starting activity %s' % activity
|
||||
device.startActivity(component=runComponent)
|
||||
|
||||
#mu.dumb_test(device, package)
|
||||
mwm.follow_path(device, mwm.sampleUris)
|
||||
run_tasks(device, sampleTasks)
|
Loading…
Add table
Reference in a new issue