List of usage examples for android.app Activity startActivity
@Override public void startActivity(Intent intent)
From source file:carnero.cgeo.cgBase.java
public boolean runNavigation(Activity activity, Resources res, cgSettings settings, cgWarning warning, GoogleAnalyticsTracker tracker, Double latitude, Double longitude, Double latitudeNow, Double longitudeNow) {//from w ww .j a va 2 s.c o m if (activity == null) { return false; } if (settings == null) { return false; } // Google Navigation if (settings.useGNavigation == 1) { try { activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:ll=" + latitude + "," + longitude))); sendAnal(activity, tracker, "/external/native/navigation"); return true; } catch (Exception e) { // nothing } } // Google Maps Directions try { if (latitudeNow != null && longitudeNow != null) { activity.startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?f=d&saddr=" + latitudeNow + "," + longitudeNow + "&daddr=" + latitude + "," + longitude))); } else { activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?f=d&daddr=" + latitude + "," + longitude))); } sendAnal(activity, tracker, "/external/native/maps"); return true; } catch (Exception e) { // nothing } Log.i(cgSettings.tag, "cgBase.runNavigation: No navigation application available."); if (warning != null && res != null) { warning.showToast(res.getString(R.string.err_navigation_no)); } return false; }
From source file:ch.uzh.supersede.feedbacklibrary.utils.Utils.java
/** * This method opens the FeedbackActivity from the feedback library in case if a PULL feedback is triggered with a random PULL configuration. * * @param baseURL the base URL//from ww w . j a v a2 s .c om * @param activity the activity in which the method is called * @param applicationId the application id * @param language the language */ public static void triggerRandomPullFeedback(@NonNull final String baseURL, @NonNull final Activity activity, final long applicationId, final @NonNull String language) { Retrofit rtf = new Retrofit.Builder().baseUrl(baseURL).addConverterFactory(GsonConverterFactory.create()) .build(); feedbackAPI fbAPI = rtf.create(feedbackAPI.class); final Call<ResponseBody> checkUpAndRunning = fbAPI.pingOrchestrator(); if (checkUpAndRunning != null) { checkUpAndRunning.enqueue(new Callback<ResponseBody>() { @Override public void onFailure(Call<ResponseBody> call, Throwable t) { Log.e(TAG, "Failed to ping the server. onFailure method called", t); } @Override public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { if (response.code() == 200) { Retrofit rtf = new Retrofit.Builder().baseUrl(baseURL) .addConverterFactory(GsonConverterFactory.create()).build(); feedbackAPI fbAPI = rtf.create(feedbackAPI.class); Call<OrchestratorConfigurationItem> result = fbAPI.getConfiguration(language, applicationId); // Asynchronous call if (result != null) { result.enqueue(new Callback<OrchestratorConfigurationItem>() { @Override public void onFailure(Call<OrchestratorConfigurationItem> call, Throwable t) { Log.e(TAG, "Failed to retrieve the configuration. onFailure method called", t); DialogUtils.showInformationDialog(activity, new String[] { activity.getResources().getString( R.string.supersede_feedbacklibrary_feedback_application_unavailable_text) }, true); } @Override public void onResponse(Call<OrchestratorConfigurationItem> call, Response<OrchestratorConfigurationItem> response) { if (response.code() == 200) { Log.i(TAG, "Configuration successfully retrieved"); OrchestratorConfigurationItem configuration = response.body(); if (configuration != null) { List<ConfigurationItem> configurationItems = configuration .getConfigurationItems(); List<Long> shuffleIds = new ArrayList<>(); Map<Long, List<Map<String, Object>>> idParameters = new HashMap<>(); for (ConfigurationItem configurationItem : configurationItems) { if (configurationItem.getType().equals("PULL")) { shuffleIds.add(configurationItem.getId()); idParameters.put(configurationItem.getId(), configurationItem .getGeneralConfigurationItem().getParameters()); } } Random rnd = new Random(System.nanoTime()); Collections.shuffle(shuffleIds, rnd); for (int i = 0; i < shuffleIds.size(); ++i) { double likelihood = -1; // If no "showIntermediateDialog" is provided, show it boolean showIntermediateDialog = true; for (Map<String, Object> parameter : idParameters .get(shuffleIds.get(i))) { String key = (String) parameter.get("key"); // Likelihood if (key.equals("likelihood")) { likelihood = (((Double) parameter.get("value")) .floatValue()); } // Intermediate dialog if (key.equals("showIntermediateDialog")) { showIntermediateDialog = (Utils.intToBool( ((Double) parameter.get("value")).intValue())); } } if (!(rnd.nextDouble() > likelihood)) { Intent intent = new Intent(activity, FeedbackActivity.class); String jsonString = new Gson().toJson(configuration); intent.putExtra(FeedbackActivity.IS_PUSH_STRING, false); intent.putExtra(FeedbackActivity.JSON_CONFIGURATION_STRING, jsonString); intent.putExtra( FeedbackActivity.SELECTED_PULL_CONFIGURATION_INDEX_STRING, shuffleIds.get(i)); intent.putExtra(FeedbackActivity.EXTRA_KEY_BASE_URL, baseURL); intent.putExtra(FeedbackActivity.EXTRA_KEY_LANGUAGE, language); if (!showIntermediateDialog) { // Start the feedback activity without asking the user activity.startActivity(intent); break; } else { // Ask the user if (s)he would like to give feedback or not DialogUtils.PullFeedbackIntermediateDialog d = DialogUtils.PullFeedbackIntermediateDialog .newInstance(activity.getResources().getString( ch.uzh.supersede.feedbacklibrary.R.string.supersede_feedbacklibrary_pull_feedback_question_string), jsonString, shuffleIds.get(i), baseURL, language); d.show(activity.getFragmentManager(), "feedbackPopupDialog"); break; } } } } } else { Log.e(TAG, "Failed to retrieve the configuration. Response code == " + response.code()); } } }); } else { Log.e(TAG, "Failed to retrieve the configuration. Call<OrchestratorConfigurationItem> result is null"); } } else { Log.e(TAG, "The server is not up and running. Response code == " + response.code()); } } }); } else { Log.e(TAG, "Failed to ping the server. Call<ResponseBody> checkUpAndRunning result is null"); } }
From source file:carnero.cgeo.original.libs.Base.java
public boolean runExternalMap(int application, Activity activity, Resources res, Warning warning, GoogleAnalyticsTracker tracker, Cache cache, Waypoint waypoint, Double latitude, Double longitude) { if (cache == null && waypoint == null && latitude == null && longitude == null) { return false; }/*from w w w. ja v a2 s . co m*/ if (application == mapAppLocus) { // locus try { final Intent intentTest = new Intent(Intent.ACTION_VIEW); intentTest.setData(Uri.parse("menion.points:x")); if (isIntentAvailable(activity, intentTest) == true) { final ArrayList<Waypoint> waypoints = new ArrayList<Waypoint>(); // get only waypoints with coordinates if (cache != null && cache.waypoints != null && cache.waypoints.isEmpty() == false) { for (Waypoint wp : cache.waypoints) { if (wp.latitude != null && wp.longitude != null) { waypoints.add(wp); } } } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream dos = new DataOutputStream(baos); dos.writeInt(1); // not used if (cache != null) { if (waypoints == null || waypoints.isEmpty() == true) { dos.writeInt(1); // cache only } else { dos.writeInt((1 + waypoints.size())); // cache and waypoints } } else { dos.writeInt(1); // one waypoint } int icon = -1; if (cache != null) { icon = getIcon(true, cache.type, cache.own, cache.found, cache.disabled || cache.archived); } else if (waypoint != null) { icon = getIcon(false, waypoint.type, false, false, false); } else { icon = getIcon(false, "waypoint", false, false, false); } if (icon > 0) { // load icon Bitmap bitmap = BitmapFactory.decodeResource(res, icon); ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2); byte[] image = baos2.toByteArray(); dos.writeInt(image.length); dos.write(image); } else { // no icon dos.writeInt(0); // no image } // name if (cache != null && cache.name != null && cache.name.length() > 0) { dos.writeUTF(cache.name); } else if (waypoint != null && waypoint.name != null && waypoint.name.length() > 0) { dos.writeUTF(waypoint.name); } else { dos.writeUTF(""); } // description if (cache != null && cache.geocode != null && cache.geocode.length() > 0) { dos.writeUTF(cache.geocode.toUpperCase()); } else if (waypoint != null && waypoint.lookup != null && waypoint.lookup.length() > 0) { dos.writeUTF(waypoint.lookup.toUpperCase()); } else { dos.writeUTF(""); } // additional data :: keyword, button title, package, activity, data name, data content if (cache != null && cache.geocode != null && cache.geocode.length() > 0) { dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeodetail;geocode;" + cache.geocode); } else if (waypoint != null && waypoint.id != null && waypoint.id > 0) { dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + waypoint.id); } else { dos.writeUTF(""); } if (cache != null && cache.latitude != null && cache.longitude != null) { dos.writeDouble(cache.latitude); // latitude dos.writeDouble(cache.longitude); // longitude } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) { dos.writeDouble(waypoint.latitude); // latitude dos.writeDouble(waypoint.longitude); // longitude } else { dos.writeDouble(latitude); // latitude dos.writeDouble(longitude); // longitude } // cache waypoints if (waypoints != null && waypoints.isEmpty() == false) { for (Waypoint wp : waypoints) { if (wp == null || wp.latitude == null || wp.longitude == null) { continue; } final int wpIcon = getIcon(false, wp.type, false, false, false); if (wpIcon > 0) { // load icon Bitmap bitmap = BitmapFactory.decodeResource(res, wpIcon); ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2); byte[] image = baos2.toByteArray(); dos.writeInt(image.length); dos.write(image); } else { // no icon dos.writeInt(0); // no image } // name if (wp.lookup != null && wp.lookup.length() > 0) { dos.writeUTF(wp.lookup.toUpperCase()); } else { dos.writeUTF(""); } // description if (wp.name != null && wp.name.length() > 0) { dos.writeUTF(wp.name); } else { dos.writeUTF(""); } // additional data :: keyword, button title, package, activity, data name, data content if (wp.id != null && wp.id > 0) { dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + wp.id); } else { dos.writeUTF(""); } dos.writeDouble(wp.latitude); // latitude dos.writeDouble(wp.longitude); // longitude } } final Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse("menion.points:data")); intent.putExtra("data", baos.toByteArray()); activity.startActivity(intent); sendAnal(activity, tracker, "/external/locus"); return true; } } catch (Exception e) { // nothing } } if (application == mapAppRmaps) { // rmaps try { final Intent intent = new Intent("com.robert.maps.action.SHOW_POINTS"); if (isIntentAvailable(activity, intent) == true) { final ArrayList<String> locations = new ArrayList<String>(); if (cache != null && cache.latitude != null && cache.longitude != null) { locations.add(String.format((Locale) null, "%.6f", cache.latitude) + "," + String.format((Locale) null, "%.6f", cache.longitude) + ";" + cache.geocode + ";" + cache.name); } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) { locations.add(String.format((Locale) null, "%.6f", waypoint.latitude) + "," + String.format((Locale) null, "%.6f", waypoint.longitude) + ";" + waypoint.lookup + ";" + waypoint.name); } intent.putStringArrayListExtra("locations", locations); activity.startActivity(intent); sendAnal(activity, tracker, "/external/rmaps"); return true; } } catch (Exception e) { // nothing } } if (application == mapAppAny) { // fallback try { if (cache != null && cache.latitude != null && cache.longitude != null) { activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + cache.latitude + "," + cache.longitude))); // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) { activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + waypoint.latitude + "," + waypoint.longitude))); // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps } sendAnal(activity, tracker, "/external/native/maps"); return true; } catch (Exception e) { // nothing } } Log.i(Settings.tag, "cgBase.runExternalMap: No maps application available."); if (warning != null && res != null) { warning.showToast(res.getString(R.string.err_application_no)); } return false; }
From source file:carnero.cgeo.cgBase.java
public boolean runExternalMap(int application, Activity activity, Resources res, cgWarning warning, GoogleAnalyticsTracker tracker, cgCache cache, cgWaypoint waypoint, Double latitude, Double longitude) { if (cache == null && waypoint == null && latitude == null && longitude == null) { return false; }//from w w w . j av a 2 s.c om if (application == mapAppLocus) { // locus try { final Intent intentTest = new Intent(Intent.ACTION_VIEW); intentTest.setData(Uri.parse("menion.points:x")); if (isIntentAvailable(activity, intentTest) == true) { final ArrayList<cgWaypoint> waypoints = new ArrayList<cgWaypoint>(); // get only waypoints with coordinates if (cache != null && cache.waypoints != null && cache.waypoints.isEmpty() == false) { for (cgWaypoint wp : cache.waypoints) { if (wp.latitude != null && wp.longitude != null) { waypoints.add(wp); } } } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream dos = new DataOutputStream(baos); dos.writeInt(1); // not used if (cache != null) { if (waypoints == null || waypoints.isEmpty() == true) { dos.writeInt(1); // cache only } else { dos.writeInt((1 + waypoints.size())); // cache and waypoints } } else { dos.writeInt(1); // one waypoint } int icon = -1; if (cache != null) { icon = getIcon(true, cache.type, cache.own, cache.found, cache.disabled || cache.archived); } else if (waypoint != null) { icon = getIcon(false, waypoint.type, false, false, false); } else { icon = getIcon(false, "waypoint", false, false, false); } if (icon > 0) { // load icon Bitmap bitmap = BitmapFactory.decodeResource(res, icon); ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2); byte[] image = baos2.toByteArray(); dos.writeInt(image.length); dos.write(image); } else { // no icon dos.writeInt(0); // no image } // name if (cache != null && cache.name != null && cache.name.length() > 0) { dos.writeUTF(cache.name); } else if (waypoint != null && waypoint.name != null && waypoint.name.length() > 0) { dos.writeUTF(waypoint.name); } else { dos.writeUTF(""); } // description if (cache != null && cache.geocode != null && cache.geocode.length() > 0) { dos.writeUTF(cache.geocode.toUpperCase()); } else if (waypoint != null && waypoint.lookup != null && waypoint.lookup.length() > 0) { dos.writeUTF(waypoint.lookup.toUpperCase()); } else { dos.writeUTF(""); } // additional data :: keyword, button title, package, activity, data name, data content if (cache != null && cache.geocode != null && cache.geocode.length() > 0) { dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeodetail;geocode;" + cache.geocode); } else if (waypoint != null && waypoint.id != null && waypoint.id > 0) { dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + waypoint.id); } else { dos.writeUTF(""); } if (cache != null && cache.latitude != null && cache.longitude != null) { dos.writeDouble(cache.latitude); // latitude dos.writeDouble(cache.longitude); // longitude } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) { dos.writeDouble(waypoint.latitude); // latitude dos.writeDouble(waypoint.longitude); // longitude } else { dos.writeDouble(latitude); // latitude dos.writeDouble(longitude); // longitude } // cache waypoints if (waypoints != null && waypoints.isEmpty() == false) { for (cgWaypoint wp : waypoints) { if (wp == null || wp.latitude == null || wp.longitude == null) { continue; } final int wpIcon = getIcon(false, wp.type, false, false, false); if (wpIcon > 0) { // load icon Bitmap bitmap = BitmapFactory.decodeResource(res, wpIcon); ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2); byte[] image = baos2.toByteArray(); dos.writeInt(image.length); dos.write(image); } else { // no icon dos.writeInt(0); // no image } // name if (wp.lookup != null && wp.lookup.length() > 0) { dos.writeUTF(wp.lookup.toUpperCase()); } else { dos.writeUTF(""); } // description if (wp.name != null && wp.name.length() > 0) { dos.writeUTF(wp.name); } else { dos.writeUTF(""); } // additional data :: keyword, button title, package, activity, data name, data content if (wp.id != null && wp.id > 0) { dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + wp.id); } else { dos.writeUTF(""); } dos.writeDouble(wp.latitude); // latitude dos.writeDouble(wp.longitude); // longitude } } final Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse("menion.points:data")); intent.putExtra("data", baos.toByteArray()); activity.startActivity(intent); sendAnal(activity, tracker, "/external/locus"); return true; } } catch (Exception e) { // nothing } } if (application == mapAppRmaps) { // rmaps try { final Intent intent = new Intent("com.robert.maps.action.SHOW_POINTS"); if (isIntentAvailable(activity, intent) == true) { final ArrayList<String> locations = new ArrayList<String>(); if (cache != null && cache.latitude != null && cache.longitude != null) { locations.add(String.format((Locale) null, "%.6f", cache.latitude) + "," + String.format((Locale) null, "%.6f", cache.longitude) + ";" + cache.geocode + ";" + cache.name); } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) { locations.add(String.format((Locale) null, "%.6f", waypoint.latitude) + "," + String.format((Locale) null, "%.6f", waypoint.longitude) + ";" + waypoint.lookup + ";" + waypoint.name); } intent.putStringArrayListExtra("locations", locations); activity.startActivity(intent); sendAnal(activity, tracker, "/external/rmaps"); return true; } } catch (Exception e) { // nothing } } if (application == mapAppAny) { // fallback try { if (cache != null && cache.latitude != null && cache.longitude != null) { activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + cache.latitude + "," + cache.longitude))); // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) { activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + waypoint.latitude + "," + waypoint.longitude))); // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps } sendAnal(activity, tracker, "/external/native/maps"); return true; } catch (Exception e) { // nothing } } Log.i(cgSettings.tag, "cgBase.runExternalMap: No maps application available."); if (warning != null && res != null) { warning.showToast(res.getString(R.string.err_application_no)); } return false; }