From 6ab3dced755241e0a0eb13eed97258f92c67859f Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 27 May 2012 16:32:53 +0200 Subject: [PATCH] Add basic class providing Main activities for application --- .../plus/activities/MainMenuActivity.java | 9 +++---- .../osmand/plus/activities/MapActivity.java | 16 +++++------ .../osmand/plus/activities/OsmandIntents.java | 27 +++++++++++++++++++ 3 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/activities/OsmandIntents.java diff --git a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java index f6d79a6a64..ef2d30d0fd 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java @@ -12,7 +12,6 @@ import net.osmand.plus.ResourceManager; import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.render.MapRenderRepositories; import android.app.Activity; -import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.Dialog; import android.app.ProgressDialog; @@ -185,7 +184,7 @@ public class MainMenuActivity extends Activity { showMap.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - final Intent mapIndent = new Intent(activity, MapActivity.class); + final Intent mapIndent = new Intent(activity, OsmandIntents.getMapActivity()); activity.startActivityForResult(mapIndent, 0); } }); @@ -193,7 +192,7 @@ public class MainMenuActivity extends Activity { settingsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - final Intent settings = new Intent(activity, SettingsActivity.class); + final Intent settings = new Intent(activity, OsmandIntents.getSettingsActivity()); activity.startActivity(settings); } }); @@ -202,7 +201,7 @@ public class MainMenuActivity extends Activity { favouritesButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - final Intent favorites = new Intent(activity, FavouritesActivity.class); + final Intent favorites = new Intent(activity, OsmandIntents.getFavoritesActivity()); favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); activity.startActivity(favorites); } @@ -228,7 +227,7 @@ public class MainMenuActivity extends Activity { searchButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - final Intent search = new Intent(activity, SearchActivity.class); + final Intent search = new Intent(activity, OsmandIntents.getSearchActivity()); search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); activity.startActivity(search); } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 9d9e31259a..b1f17d9553 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -138,7 +138,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe private List dialogProviders = new ArrayList(2); private Notification getNotification(){ - Intent notificationIndent = new Intent(this, MapActivity.class); + Intent notificationIndent = new Intent(this, OsmandIntents.getMapActivity()); notificationIndent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Notification notification = new Notification(R.drawable.icon, "", //$NON-NLS-1$ System.currentTimeMillis()); @@ -451,7 +451,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe settingsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - final Intent settings = new Intent(MapActivity.this, SettingsActivity.class); + final Intent settings = new Intent(MapActivity.this, OsmandIntents.getSettingsActivity()); MapActivity.this.startActivity(settings); dlg.dismiss(); } @@ -461,7 +461,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe favouritesButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - final Intent favorites = new Intent(MapActivity.this, FavouritesActivity.class); + final Intent favorites = new Intent(MapActivity.this, OsmandIntents.getFavoritesActivity()); favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); MapActivity.this.startActivity(favorites); dlg.dismiss(); @@ -476,7 +476,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe getMyApplication().closeApplication(); // 1. Work for almost all cases when user open apps from main menu - Intent newIntent = new Intent(MapActivity.this, MainMenuActivity.class); + Intent newIntent = new Intent(MapActivity.this, OsmandIntents.getMainMenuActivity()); newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); newIntent.putExtra(MainMenuActivity.APP_EXIT_KEY, MainMenuActivity.APP_EXIT_CODE); startActivity(newIntent); @@ -493,7 +493,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe searchButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - final Intent search = new Intent(MapActivity.this, SearchActivity.class); + final Intent search = new Intent(MapActivity.this, OsmandIntents.getSearchActivity()); LatLon loc = getMapLocation(); search.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude()); search.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude()); @@ -537,7 +537,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe } return true; } else if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) { - Intent newIntent = new Intent(MapActivity.this, SearchActivity.class); + Intent newIntent = new Intent(MapActivity.this, OsmandIntents.getSearchActivity()); // causes wrong position caching: newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); LatLon loc = getMapLocation(); newIntent.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude()); @@ -1178,7 +1178,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe public boolean onOptionsItemSelected(MenuItem item) { final int itemId = item.getItemId(); if (itemId == R.id.map_show_settings) { - final Intent intentSettings = new Intent(MapActivity.this, SettingsActivity.class); + final Intent intentSettings = new Intent(MapActivity.this, OsmandIntents.getSettingsActivity()); startActivity(intentSettings); return true; } else if (itemId == R.id.map_where_am_i) { @@ -1320,7 +1320,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe } public static void launchMapActivityMoveToTop(Activity activity){ - Intent newIntent = new Intent(activity, MapActivity.class); + Intent newIntent = new Intent(activity, OsmandIntents.getMapActivity()); newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); activity.startActivity(newIntent); } diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandIntents.java b/OsmAnd/src/net/osmand/plus/activities/OsmandIntents.java new file mode 100644 index 0000000000..bc5805f7a5 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandIntents.java @@ -0,0 +1,27 @@ +package net.osmand.plus.activities; + +import net.osmand.plus.activities.search.SearchActivity; + +public class OsmandIntents { + + public static Class getSettingsActivity(){ + return SettingsActivity.class; + } + + public static Class getMapActivity(){ + return MapActivity.class; + } + + public static Class getSearchActivity(){ + return SearchActivity.class; + } + + public static Class getFavoritesActivity(){ + return FavouritesActivity.class; + } + + public static Class getMainMenuActivity() { + return MainMenuActivity.class; + } + +}