Allow alternative apps

This commit is contained in:
vshcherb 2013-11-04 19:51:02 +01:00
parent 0e1365b30b
commit 116c5da336
7 changed files with 453 additions and 168 deletions

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="remember_choice">Remember my choice</string>
<string name="gps_status_eclipsim">GPS status</string>
<string name="default_and">and</string>
<string name="default_or">or</string>
<string name="route_is_too_long">The route is possibly too long to be calculated by the OsmAnd offline router.

View file

@ -756,7 +756,8 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<String> LIVE_MONITORING_URL = new StringPreference("live_monitoring_url",
"http://example.com?lat={0}&lon={1}&timestamp={2}&hdop={3}&altitude={4}&speed={5}").makeGlobal();
public final CommonPreference<String> GPS_STATUS_APP = new StringPreference("gps_status_app", "").makeGlobal();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> SHOW_OSM_BUGS = new BooleanPreference("show_osm_bugs", false).makeGlobal();

View file

@ -1,7 +1,5 @@
package net.osmand.plus.activities;
import java.io.File;
import java.text.Collator;
import java.text.MessageFormat;
@ -39,33 +37,26 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.Version;
import net.osmand.plus.activities.actions.OsmAndDialogs;
import net.osmand.plus.activities.actions.ShareLocation;
import net.osmand.plus.activities.actions.StartGPSStatus;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.BaseMapLayer;
import net.osmand.plus.views.MapTileLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.util.MapUtils;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.RectF;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.text.Html;
import android.util.FloatMath;
import android.view.View;
import android.view.View.OnClickListener;
@ -85,22 +76,17 @@ import android.widget.ToggleButton;
public class MapActivityActions implements DialogProvider {
private static final String GPS_STATUS_COMPONENT = "com.eclipsim.gpsstatus2"; //$NON-NLS-1$
private static final String GPS_STATUS_ACTIVITY = "com.eclipsim.gpsstatus2.GPSStatus"; //$NON-NLS-1$
private static final String ZXING_BARCODE_SCANNER_COMPONENT = "com.google.zxing.client.android"; //$NON-NLS-1$
private static final String ZXING_BARCODE_SCANNER_ACTIVITY = "com.google.zxing.client.android.ENCODE"; //$NON-NLS-1$
private static final String KEY_LONGITUDE = "longitude";
private static final String KEY_LATITUDE = "latitude";
private static final String KEY_NAME = "name";
private static final String KEY_FAVORITE = "favorite";
private static final String KEY_ZOOM = "zoom";
public static final String KEY_LONGITUDE = "longitude";
public static final String KEY_LATITUDE = "latitude";
public static final String KEY_NAME = "name";
public static final String KEY_FAVORITE = "favorite";
public static final String KEY_ZOOM = "zoom";
private static final int DIALOG_ADD_FAVORITE = 100;
private static final int DIALOG_REPLACE_FAVORITE = 101;
private static final int DIALOG_ADD_WAYPOINT = 102;
private static final int DIALOG_RELOAD_TITLE = 103;
private static final int DIALOG_SHARE_LOCATION = 104;
private static final int DIALOG_SAVE_DIRECTIONS = 106;
// make static
private static Bundle dialogBundle = new Bundle();
@ -301,115 +287,7 @@ public class MapActivityActions implements DialogProvider {
});
}
protected void shareLocation(final double latitude, final double longitude, int zoom){
enhance(dialogBundle,latitude,longitude,zoom);
mapActivity.showDialog(DIALOG_SHARE_LOCATION);
}
private Dialog createShareLocationDialog(final Bundle args) {
AlertDialog.Builder builder = new Builder(mapActivity);
builder.setTitle(R.string.send_location_way_choose_title);
builder.setItems(new String[]{
"Email", "SMS", "Clipboard", "geo:", "QR-Code"
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final double latitude = args.getDouble(KEY_LATITUDE);
final double longitude = args.getDouble(KEY_LONGITUDE);
final int zoom = args.getInt(KEY_ZOOM);
try {
final String shortOsmUrl = MapUtils.buildShortOsmUrl(latitude, longitude, zoom);
final String appLink = "http://download.osmand.net/go?lat=" + ((float) latitude) + "&lon=" + ((float) longitude) + "&z=" + zoom;
String sms = mapActivity.getString(R.string.send_location_sms_pattern, shortOsmUrl, appLink);
if (which == 0) {
sendEmail(shortOsmUrl, appLink);
} else if (which == 1) {
sendSms(sms);
} else if (which == 2) {
sendToClipboard(sms);
} else if (which == 3) {
sendGeoActivity(latitude, longitude, zoom);
} else if (which == 4) {
sendQRCode(latitude, longitude);
}
} catch (RuntimeException e) {
Toast.makeText(mapActivity, R.string.input_output_error, Toast.LENGTH_SHORT).show();
}
}
});
return builder.create();
}
private void sendEmail(final String shortOsmUrl, final String appLink) {
String email = mapActivity.getString(R.string.send_location_email_pattern, shortOsmUrl, appLink);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$
intent.putExtra(Intent.EXTRA_SUBJECT, "Location"); //$NON-NLS-1$
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(email));
intent.setType("text/html");
mapActivity.startActivity(Intent.createChooser(intent, getString(R.string.send_location)));
}
private void sendSms(String sms) {
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", sms);
sendIntent.setType("vnd.android-dir/mms-sms");
mapActivity.startActivity(sendIntent);
}
private void sendToClipboard(String sms) {
ClipboardManager clipboard = (ClipboardManager) mapActivity.getSystemService(Activity.CLIPBOARD_SERVICE);
clipboard.setText(sms);
}
private void sendGeoActivity(final double latitude, final double longitude, final int zoom) {
final String simpleGeo = "geo:"+((float) latitude)+","+((float)longitude) +"?z="+zoom;
Uri location = Uri.parse(simpleGeo);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
mapActivity.startActivity(mapIntent);
}
private void sendQRCode(final double latitude, final double longitude) {
Bundle bundle = new Bundle();
bundle.putFloat("LAT", (float) latitude);
bundle.putFloat("LONG", (float) longitude);
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setAction(ZXING_BARCODE_SCANNER_ACTIVITY);
ResolveInfo resolved = mapActivity.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolved != null) {
intent.putExtra("ENCODE_TYPE", "LOCATION_TYPE");
intent.putExtra("ENCODE_DATA", bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
mapActivity.startActivity(intent);
} else {
if (Version.isMarketEnabled(mapActivity.getMyApplication())) {
AlertDialog.Builder builder = new AccessibleAlertBuilder(mapActivity);
builder.setMessage(getString(R.string.zxing_barcode_scanner_not_found));
builder.setPositiveButton(getString(R.string.default_buttons_yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(mapActivity.getMyApplication())
+ ZXING_BARCODE_SCANNER_COMPONENT));
try {
mapActivity.startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
builder.setNegativeButton(getString(R.string.default_buttons_no), null);
builder.show();
} else {
Toast.makeText(mapActivity, R.string.zxing_barcode_scanner_not_found, Toast.LENGTH_LONG).show();
}
}
}
protected void aboutRoute() {
Intent intent = new Intent(mapActivity, ShowRouteInfoActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@ -989,7 +867,8 @@ public class MapActivityActions implements DialogProvider {
IntermediatePointsDialog.openIntermediatePointsDialog(mapActivity);
}
} else if (standardId == R.string.context_menu_item_share_location) {
shareLocation(latitude, longitude, mapActivity.getMapView().getZoom());
enhance(dialogBundle,latitude,longitude,mapActivity.getMapView().getZoom());
new ShareLocation(mapActivity).run();
} else if (standardId == R.string.context_menu_item_add_favorite) {
addFavouritePoint(latitude, longitude);
}
@ -1055,12 +934,10 @@ public class MapActivityActions implements DialogProvider {
return createAddWaypointDialog(args);
case DIALOG_RELOAD_TITLE:
return createReloadTitleDialog(args);
case DIALOG_SHARE_LOCATION:
return createShareLocationDialog(args);
case DIALOG_SAVE_DIRECTIONS:
return createSaveDirections(mapActivity);
}
return null;
return OsmAndDialogs.createDialog(id, mapActivity, args);
}
@Override
@ -1256,7 +1133,7 @@ public class MapActivityActions implements DialogProvider {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
startGpsStatusIntent();
new StartGPSStatus(mapActivity).run();
}
}).reg();
}
@ -1359,36 +1236,7 @@ public class MapActivityActions implements DialogProvider {
}
private void startGpsStatusIntent() {
Intent intent = new Intent();
intent.setComponent(new ComponentName(GPS_STATUS_COMPONENT,
GPS_STATUS_ACTIVITY));
ResolveInfo resolved = mapActivity.getPackageManager().resolveActivity(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (resolved != null) {
mapActivity.startActivity(intent);
} else {
if (Version.isMarketEnabled(getMyApplication())) {
AlertDialog.Builder builder = new AccessibleAlertBuilder(mapActivity);
builder.setMessage(getString(R.string.gps_status_app_not_found));
builder.setPositiveButton(getString(R.string.default_buttons_yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(getMyApplication()) + GPS_STATUS_COMPONENT));
try {
mapActivity.startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
builder.setNegativeButton(getString(R.string.default_buttons_no), null);
builder.show();
} else {
Toast.makeText(mapActivity, R.string.gps_status_app_not_found, Toast.LENGTH_LONG).show();
}
}
}
private void whereAmIDialog() {
final List<String> items = new ArrayList<String>();
items.add(getString(R.string.show_location));

View file

@ -0,0 +1,58 @@
package net.osmand.plus.activities.actions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapTileView;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
public class OsmAndAction {
protected MapActivity mapActivity;
public OsmAndAction(MapActivity mapActivity) {
this.mapActivity = mapActivity;
OsmAndDialogs.registerDialogAction(this);
}
public MapActivity getMapActivity() {
return mapActivity;
}
public OsmandMapTileView getMapView() {
return mapActivity.getMapView();
}
public OsmandSettings getSettings() {
return mapActivity.getMyApplication().getSettings();
}
protected OsmandApplication getMyApplication() {
return mapActivity.getMyApplication();
}
protected String getString(int res) {
return mapActivity.getString(res);
}
public void run() {
}
public int getDialogID() {
return 0;
}
public Dialog createDialog(Activity activity, Bundle args) {
return null;
}
public void prepareDialog(Activity activity, Bundle args, Dialog dlg) {
}
public void showDialog() {
mapActivity.showDialog(getDialogID());
}
}

View file

@ -0,0 +1,42 @@
package net.osmand.plus.activities.actions;
import java.util.HashMap;
import java.util.Map;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
public class OsmAndDialogs {
private static Map<Integer, OsmAndAction> dialogActions = new HashMap<Integer, OsmAndAction>();
public static Dialog createDialog(int dialogID, Activity activity, Bundle args) {
OsmAndAction action = dialogActions.get(dialogID);
if(action != null) {
return action.createDialog(activity, args);
}
return null;
}
public static void prepareDialog(int dialogID, Activity activity, Bundle args, Dialog dlg) {
OsmAndAction action = dialogActions.get(dialogID);
if(action != null) {
action.prepareDialog(activity, args, dlg);
}
}
public static void registerDialogAction(OsmAndAction action) {
if(action.getDialogID() != 0) {
dialogActions.put(action.getDialogID(), action);
}
}
public static final int DIALOG_ADD_FAVORITE = 200;
public static final int DIALOG_REPLACE_FAVORITE = 201;
public static final int DIALOG_ADD_WAYPOINT = 202;
public static final int DIALOG_RELOAD_TITLE = 203;
public static final int DIALOG_SHARE_LOCATION = 204;
public static final int DIALOG_SAVE_DIRECTIONS = 206;
public static final int DIALOG_START_GPS = 207;
}

View file

@ -0,0 +1,151 @@
package net.osmand.plus.activities.actions;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.text.Html;
import android.widget.Toast;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.util.MapUtils;
public class ShareLocation extends OsmAndAction {
private static final String ZXING_BARCODE_SCANNER_COMPONENT = "com.google.zxing.client.android"; //$NON-NLS-1$
private static final String ZXING_BARCODE_SCANNER_ACTIVITY = "com.google.zxing.client.android.ENCODE"; //$NON-NLS-1$
public ShareLocation(MapActivity mapActivity) {
super(mapActivity);
}
@Override
public int getDialogID() {
return OsmAndDialogs.DIALOG_SHARE_LOCATION;
}
@Override
public void run() {
super.showDialog();
}
public Dialog createDialog(Activity activity, final Bundle args) {
mapActivity = (MapActivity) activity;
AlertDialog.Builder builder = new Builder(mapActivity);
builder.setTitle(R.string.send_location_way_choose_title);
builder.setItems(new String[]{
"Email", "SMS", "Clipboard", "geo:", "QR-Code"
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final double latitude = args.getDouble(MapActivityActions.KEY_LATITUDE);
final double longitude = args.getDouble(MapActivityActions.KEY_LONGITUDE);
final int zoom = args.getInt(MapActivityActions.KEY_ZOOM);
try {
final String shortOsmUrl = MapUtils.buildShortOsmUrl(latitude, longitude, zoom);
final String appLink = "http://download.osmand.net/go?lat=" + ((float) latitude) + "&lon=" + ((float) longitude) + "&z=" + zoom;
String sms = mapActivity.getString(R.string.send_location_sms_pattern, shortOsmUrl, appLink);
if (which == 0) {
sendEmail(shortOsmUrl, appLink);
} else if (which == 1) {
sendSms(sms);
} else if (which == 2) {
sendToClipboard(sms);
} else if (which == 3) {
sendGeoActivity(latitude, longitude, zoom);
} else if (which == 4) {
sendQRCode(latitude, longitude);
}
} catch (RuntimeException e) {
Toast.makeText(mapActivity, R.string.input_output_error, Toast.LENGTH_SHORT).show();
}
}
});
return builder.create();
}
private void sendEmail(final String shortOsmUrl, final String appLink) {
String email = mapActivity.getString(R.string.send_location_email_pattern, shortOsmUrl, appLink);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$
intent.putExtra(Intent.EXTRA_SUBJECT, "Location"); //$NON-NLS-1$
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(email));
intent.setType("text/html");
mapActivity.startActivity(Intent.createChooser(intent, getString(R.string.send_location)));
}
private void sendSms(String sms) {
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", sms);
sendIntent.setType("vnd.android-dir/mms-sms");
mapActivity.startActivity(sendIntent);
}
private void sendToClipboard(String sms) {
ClipboardManager clipboard = (ClipboardManager) mapActivity.getSystemService(Activity.CLIPBOARD_SERVICE);
clipboard.setText(sms);
}
private void sendGeoActivity(final double latitude, final double longitude, final int zoom) {
final String simpleGeo = "geo:"+((float) latitude)+","+((float)longitude) +"?z="+zoom;
Uri location = Uri.parse(simpleGeo);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
mapActivity.startActivity(mapIntent);
}
private void sendQRCode(final double latitude, final double longitude) {
Bundle bundle = new Bundle();
bundle.putFloat("LAT", (float) latitude);
bundle.putFloat("LONG", (float) longitude);
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setAction(ZXING_BARCODE_SCANNER_ACTIVITY);
ResolveInfo resolved = mapActivity.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolved != null) {
intent.putExtra("ENCODE_TYPE", "LOCATION_TYPE");
intent.putExtra("ENCODE_DATA", bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
mapActivity.startActivity(intent);
} else {
if (Version.isMarketEnabled(mapActivity.getMyApplication())) {
AlertDialog.Builder builder = new AccessibleAlertBuilder(mapActivity);
builder.setMessage(getString(R.string.zxing_barcode_scanner_not_found));
builder.setPositiveButton(getString(R.string.default_buttons_yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(mapActivity.getMyApplication())
+ ZXING_BARCODE_SCANNER_COMPONENT));
try {
mapActivity.startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
builder.setNegativeButton(getString(R.string.default_buttons_no), null);
builder.show();
} else {
Toast.makeText(mapActivity, R.string.zxing_barcode_scanner_not_found, Toast.LENGTH_LONG).show();
}
}
}
}

View file

@ -0,0 +1,183 @@
package net.osmand.plus.activities.actions;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapTileView;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class StartGPSStatus extends OsmAndAction {
public enum GpsStatusApps {
GPS_STATUS("GPS Status & Toolbox", "com.eclipsim.gpsstatus2", "com.eclipsim.gpsstatus2.GPSStatus"),
GPS_TEST("GPS Test", "com.chartcross.gpstest", ""),
INVIU_GPS("inViu GPS-details ", "de.enaikoon.android.inviu.gpsdetails", "");
public final String stringRes;
public final String activity;
public final String appName;
GpsStatusApps(String res, String appName, String activity) {
this.stringRes = res;
this.appName = appName;
this.activity = activity;
}
public boolean installed(Activity a) {
boolean installed = false;
try{
installed = a.getPackageManager().getPackageInfo(appName, 0) != null;
} catch ( NameNotFoundException e){
}
return installed;
}
}
public StartGPSStatus(MapActivity mapActivity) {
super(mapActivity);
}
@Override
public void run() {
String appName = getSettings().GPS_STATUS_APP.get();
GpsStatusApps[] values = GpsStatusApps.values();
for(GpsStatusApps g : values) {
if(appName.length() > 0 && g.appName.equals(appName)) {
if(g.installed(mapActivity)) {
runChosenGPSStatus(g);
return;
} else {
getSettings().GPS_STATUS_APP.set("");
}
}
}
showDialog();
}
@Override
public int getDialogID() {
return OsmAndDialogs.DIALOG_START_GPS;
}
@Override
public Dialog createDialog(Activity activity, Bundle args) {
GpsStatusApps[] values = GpsStatusApps.values();
String[] res = new String[values.length];
int i = 0;
for(GpsStatusApps g : values) {
res[i++] = g.stringRes;
}
OsmandMapTileView view = mapActivity.getMapView();
AlertDialog.Builder builder = new AccessibleAlertBuilder(mapActivity);
LinearLayout ll = new LinearLayout(view.getContext());
final ListView lv = new ListView(view.getContext());
lv.setPadding(7, 3, 7, 0);
final CheckBox cb = new CheckBox(view.getContext());
cb.setText(R.string.remember_choice);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.setMargins(7, 10, 7, 0);
cb.setLayoutParams(lp);
final int layout;
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){
layout = R.layout.list_menu_item;
} else {
layout = R.layout.list_menu_item_native;
}
final ArrayAdapter<GpsStatusApps> adapter = new ArrayAdapter<GpsStatusApps>(mapActivity, layout, GpsStatusApps.values()) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = mapActivity.getLayoutInflater().inflate(layout, null);
TextView tv = (TextView)v.findViewById(R.id.title);
tv.setText(getItem(position).stringRes);
v.findViewById(R.id.check_item).setVisibility(View.INVISIBLE);
return v;
}
};
lv.setAdapter(adapter);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(lv);
ll.addView(cb);
final AlertDialog dlg = builder.create();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
boolean remember = cb.isChecked();
GpsStatusApps item = adapter.getItem(position);
if(remember) {
getSettings().GPS_STATUS_APP.set(item.appName);
}
dlg.dismiss();
runChosenGPSStatus(item);
}
});
dlg.setView(ll);
return dlg;
}
private void runChosenGPSStatus(final GpsStatusApps g) {
if (g.installed(mapActivity)) {
Intent intent = null;
// if (g.activity.length() == 0) {
PackageManager pm = mapActivity.getPackageManager();
try {
intent = pm.getLaunchIntentForPackage(g.appName);
} catch (RuntimeException e) {
}
// } else {
// intent = new Intent();
// intent.setComponent(new ComponentName(g.appName, g.activity));
// }
if(intent == null) {
return;
}
intent.addCategory(Intent.CATEGORY_LAUNCHER);
mapActivity.startActivity(intent);
} else {
if (Version.isMarketEnabled(getMyApplication())) {
AlertDialog.Builder builder = new AccessibleAlertBuilder(mapActivity);
builder.setMessage(mapActivity. getString(R.string.gps_status_app_not_found));
builder.setPositiveButton(mapActivity.getString(R.string.default_buttons_yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(getMyApplication()) + g.appName));
try {
mapActivity.startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
builder.setNegativeButton(mapActivity.getString(R.string.default_buttons_no), null);
builder.show();
} else {
Toast.makeText(mapActivity, R.string.gps_status_app_not_found, Toast.LENGTH_LONG).show();
}
}
}
}