diff options
Diffstat (limited to 'navit/android/src/org/navitproject/navit/Navit.java')
-rw-r--r-- | navit/android/src/org/navitproject/navit/Navit.java | 230 |
1 files changed, 63 insertions, 167 deletions
diff --git a/navit/android/src/org/navitproject/navit/Navit.java b/navit/android/src/org/navitproject/navit/Navit.java index 2fa2f312d..bacc15213 100644 --- a/navit/android/src/org/navitproject/navit/Navit.java +++ b/navit/android/src/org/navitproject/navit/Navit.java @@ -73,84 +73,8 @@ import java.util.regex.Pattern; public class Navit extends Activity { - /** - * Nested class storing the intent that was sent to the main navit activity at startup. - **/ - private class StartupIntent { - /** - * Constructor. - * - * @param intent The intent to store in this object - **/ - public StartupIntent(Intent intent) { - mStartupIntent = intent; - mStartupIntentTimestamp = System.currentTimeMillis(); - } - - /** - * Check if the encapsulated intent still valid or too old. - * - * @return true if the encapsulated intent is recent enough - **/ - public boolean isRecentEnough() { - if (mStartupIntent == null) { - return false; - } - /* We consider the intent is valid for 4s */ - return (System.currentTimeMillis() <= getExpirationTimeMillis()); - } - - /** - * Compute the system time when the stored intent will become invalid. - * - * @return The system time for invalidation (in ms) - **/ - private long getExpirationTimeMillis() { - if (mStartupIntent == null) { - return 0; - } - /* We give 4s to navit to process the intent */ - return mStartupIntentTimestamp + 4000L; - } - /** - * Getter for the encapsulated intent. - * - * @return The encapsulated intent - **/ - public Intent getIntent() { - return mStartupIntent; - } - - /** - * Represent this object as a string. - * - * @return A string containing the summary of the data we store here - **/ - public String toString() { - if (mStartupIntent == null) { - return "{null}"; - } else { - String validForStr; - long remainingValidity = getExpirationTimeMillis() - System.currentTimeMillis(); - if (remainingValidity < 0) { - validForStr = "(expired since " + -remainingValidity + "ms)"; - } else { - validForStr = "(valid for " + remainingValidity + "ms)"; - } - return "{ act=" + mStartupIntent.getAction() + " data=" + mStartupIntent.getDataString() - + " " + validForStr + " }"; - } - } - - private Intent mStartupIntent; /*!< The intent we store */ - private long mStartupIntentTimestamp; /*!< A timestamp (in ms) for when mStartupIntent was recorded */ - } - - - public static DisplayMetrics sMetrics; public static boolean sShowSoftKeyboardShowing; - private static StartupIntent sStartupIntent; private static final int MY_PERMISSIONS_REQ_FINE_LOC = 103; private static final int NavitDownloaderSelectMap_id = 967; private static final int NavitAddressSearch_id = 70; @@ -158,7 +82,6 @@ public class Navit extends Activity { private static final String NAVIT_PACKAGE_NAME = "org.navitproject.navit"; private static final String TAG = "Navit"; static String sMapFilenamePath; - static String sNavitDataDir; boolean mIsFullscreen; private NavitDialogs mDialogs; private PowerManager.WakeLock mWakeLock; @@ -287,7 +210,7 @@ public class Navit extends Activity { } /** - * Show the first start infoxbox (presentation of navit and link website for more info). + * Show the first start infobox (presentation of navit and link website for more info). **/ private void showInfos() { SharedPreferences settings = getSharedPreferences(NavitAppConfig.NAVIT_PREFS, MODE_PRIVATE); @@ -335,17 +258,12 @@ public class Navit extends Activity { @Override public void onCreate(Bundle savedInstanceState) { - Log.d(TAG, "OnCreate"); + Log.d(TAG, "onCreate"); super.onCreate(savedInstanceState); windowSetup(); mDialogs = new NavitDialogs(this); - /* Only store the startup intent, onResume() gets called all the time (e.g. when screenblanks, etc.) and - will process this intent later on if needed */ - sStartupIntent = new StartupIntent(this.getIntent()); - Log.d(TAG, "Recording intent " + sStartupIntent.toString()); - createNotificationChannel(); buildNotification(); verifyPermissions(); @@ -369,34 +287,34 @@ public class Navit extends Activity { Log.d(TAG, "Language " + lang); SharedPreferences prefs = getSharedPreferences(NavitAppConfig.NAVIT_PREFS,MODE_PRIVATE); - sNavitDataDir = getApplicationContext().getFilesDir().getPath(); + String navitDataDir = getApplicationContext().getFilesDir().getPath(); String candidateFileNamePath = getApplicationContext().getExternalFilesDir(null).toString(); sMapFilenamePath = prefs.getString("filenamePath", candidateFileNamePath + '/'); - Log.i(TAG,"NavitDataDir = " + sNavitDataDir); + Log.i(TAG,"NavitDataDir = " + navitDataDir); Log.i(TAG,"mapFilenamePath = " + sMapFilenamePath); // make sure the new path for the navitmap.bin file(s) exist!! File navitMapsDir = new File(sMapFilenamePath); navitMapsDir.mkdirs(); // make sure the share dir exists - File navitDataShareDir = new File(sNavitDataDir + "/share"); + File navitDataShareDir = new File(navitDataDir + "/share"); navitDataShareDir.mkdirs(); Display display = getWindowManager().getDefaultDisplay(); - sMetrics = new DisplayMetrics(); - display.getMetrics(sMetrics); - int densityDpi = (int)((sMetrics.density * 160) - .5f); + DisplayMetrics metrics = new DisplayMetrics(); + display.getMetrics(metrics); + int densityDpi = (int)((metrics.density * 160) - .5f); Log.d(TAG, "-> pixels x=" + display.getWidth() + " pixels y=" + display.getHeight()); Log.d(TAG, "-> dpi=" + densityDpi); - Log.d(TAG, "-> density=" + sMetrics.density); - Log.d(TAG, "-> scaledDensity=" + sMetrics.scaledDensity); + Log.d(TAG, "-> density=" + metrics.density); + Log.d(TAG, "-> scaledDensity=" + metrics.scaledDensity); mActivityResults = new NavitActivityResult[16]; setVolumeControlStream(AudioManager.STREAM_MUSIC); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,"navit:DoNotDimScreen"); - if (!extractRes(langc, sNavitDataDir + "/locale/" + langc + "/LC_MESSAGES/navit.mo")) { + if (!extractRes(langc, navitDataDir + "/locale/" + langc + "/LC_MESSAGES/navit.mo")) { Log.e(TAG, "Failed to extract language resource " + langc); } @@ -425,7 +343,7 @@ public class Navit extends Activity { String[] children = assetMgr.list("config/" + myDisplayDensity); for (String child : children) { Log.d(TAG, "Processing config file '" + child + "' from assets"); - if (!extractAsset("config/" + myDisplayDensity + "/" + child, sNavitDataDir + "/share/" + child)) { + if (!extractAsset("config/" + myDisplayDensity + "/" + child, navitDataDir + "/share/" + child)) { Log.e(TAG, "Failed to extract asset config/" + myDisplayDensity + "/" + child); } } @@ -433,8 +351,26 @@ public class Navit extends Activity { Log.e(TAG, "Failed to access assets using AssetManager"); } Log.d(TAG, "android.os.Build.VERSION.SDK_INT=" + Integer.valueOf(Build.VERSION.SDK)); - navitMain(navitLanguage, sNavitDataDir + "/bin/navit", sMapFilenamePath); + navitMain(navitLanguage, navitDataDir + "/bin/navit", sMapFilenamePath); showInfos(); + + Intent startupIntent = new Intent(this.getIntent()); + Log.d(TAG, "onCreate intent " + startupIntent.toString()); + handleIntent(startupIntent); + } + + private void handleIntent(Intent intent) { + String naviScheme = intent.getScheme(); + if (naviScheme != null) { + Log.d(TAG, "Using intent " + intent.toString()); + if (naviScheme.equals("google.navigation")) { + parseNavigationURI(intent.getData().getSchemeSpecificPart()); + } else if (naviScheme.equals("geo") + && intent.getAction().equals("android.intent.action.VIEW")) { + invokeCallbackOnGeo(intent.getData().getSchemeSpecificPart(), + NavitCallbackHandler.MsgType.CLB_SET_DESTINATION, ""); + } + } } private void windowSetup() { @@ -491,58 +427,32 @@ public class Navit extends Activity { public void onRestart() { super.onRestart(); - Log.d(TAG, "OnRestart"); + Log.d(TAG, "onRestart"); } public void onStart() { super.onStart(); - Log.d(TAG, "OnStart"); + Log.d(TAG, "onStart"); } @Override public void onNewIntent(Intent intent) { - Log.d(TAG, "OnNewIntent"); - sStartupIntent = new StartupIntent(intent); - Log.d(TAG, "Recording intent " + sStartupIntent.toString()); + Log.d(TAG, "onNewIntent"); + handleIntent(intent); } @Override public void onResume() { super.onResume(); - Log.d(TAG, "OnResume"); - //InputMethodManager sInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - // DEBUG - // intent_data = "google.navigation:q=Wien Burggasse 27"; - // intent_data = "google.navigation:q=48.25676,16.643"; - // intent_data = "google.navigation:ll=48.25676,16.643&q=blabla-strasse"; - // intent_data = "google.navigation:ll=48.25676,16.643"; - // intent_data = "geo:48.25676,16.643"; - if (sStartupIntent != null) { - Log.d(TAG, "Using stored startup intent " + sStartupIntent.toString()); - if (sStartupIntent.isRecentEnough()) { - Intent startupIntent = sStartupIntent.getIntent(); - String naviScheme = startupIntent.getScheme(); - if (naviScheme != null) { - if (naviScheme.equals("google.navigation")) { - parseNavigationURI(startupIntent.getData().getSchemeSpecificPart()); - } else if (naviScheme.equals("geo") - && startupIntent.getAction().equals("android.intent.action.VIEW")) { - invokeCallbackOnGeo(startupIntent.getData().getSchemeSpecificPart(), - NavitGraphics.MsgType.CLB_SET_DESTINATION, - ""); - } - } - } else { - Log.e(TAG, "timestamp for startup intent expired! not using data"); - } - sStartupIntent = null; - } + NavitCallbackHandler.sendCommand(NavitCallbackHandler.CmdType.CMD_UNBLOCK); + Log.d(TAG, "onResume"); } @Override public void onPause() { super.onPause(); - Log.d(TAG, "OnPause"); + NavitCallbackHandler.sendCommand(NavitCallbackHandler.CmdType.CMD_BLOCK); + Log.d(TAG, "onPause"); } @Override @@ -567,30 +477,30 @@ public class Navit extends Activity { } /** - * Invoke NavitGraphics.sCallbackHandler on a geographical position + * Invoke CallbackHandler on a geographical position. * * @param geoString A string containing the target geographical position with a format like "48.25676,16.643" - * @param msgType The type of message to send to the callback (see NavitGraphics.MsgType for possible values) + * @param msgType The type of message to send * @param name The name/label to associate to the geographical position **/ - private void invokeCallbackOnGeo(String geoString, NavitGraphics.MsgType msgType, String name) { + private void invokeCallbackOnGeo(String geoString, NavitCallbackHandler.MsgType msgType, String name) { String[] geo = geoString.split(","); if (geo.length == 2) { try { Bundle b = new Bundle(); - Float lat = Float.valueOf(geo[0]); - Float lon = Float.valueOf(geo[1]); + float lat = Float.parseFloat(geo[0]); + float lon = Float.parseFloat(geo[1]); b.putFloat("lat", lat); b.putFloat("lon", lon); b.putString("q", name); - Message msg = Message.obtain(NavitGraphics.sCallbackHandler, + Message msg = Message.obtain(NavitCallbackHandler.sCallbackHandler, msgType.ordinal()); msg.setData(b); msg.sendToTarget(); Log.d(TAG, "target found (b): " + geoString); } catch (NumberFormatException e) { - e.printStackTrace(); + Log.e(TAG,"numberFormatException"); } } else { Log.w(TAG, "Ignoring invalid geo string: " + geoString); @@ -598,7 +508,7 @@ public class Navit extends Activity { } /** - * Parse google navigation URIs (usually starting with "google.navigation:") and take the appropriate actions + * Parse google navigation URIs (usually starting with "google.navigation:") and take the appropriate actions. * * @param schemeSpecificPart A string containing the URI scheme, for example "ll=48.25676,16.643&q=blabla-strasse" **/ @@ -628,7 +538,7 @@ public class Navit extends Activity { if (geoString != null) { if (geoString.matches("^[+-]{0,1}\\d+(|\\.\\d*),[+-]{0,1}\\d+(|\\.\\d*)$")) { - invokeCallbackOnGeo(geoString, NavitGraphics.MsgType.CLB_SET_DESTINATION, address); + invokeCallbackOnGeo(geoString, NavitCallbackHandler.MsgType.CLB_SET_DESTINATION, address); } else { start_targetsearch_from_intent(geoString); } @@ -683,15 +593,13 @@ public class Navit extends Activity { switch (id) { case 1 : // zoom in - Message.obtain(NavitGraphics.sCallbackHandler, - NavitGraphics.MsgType.CLB_ZOOM_IN.ordinal()).sendToTarget(); + NavitCallbackHandler.sendCommand(NavitCallbackHandler.CmdType.CMD_ZOOM_IN); // if we zoom, hide the bubble Log.d(TAG, "onOptionsItemSelected -> zoom in"); break; case 2 : // zoom out - Message.obtain(NavitGraphics.sCallbackHandler, - NavitGraphics.MsgType.CLB_ZOOM_OUT.ordinal()).sendToTarget(); + NavitCallbackHandler.sendCommand(NavitCallbackHandler.CmdType.CMD_ZOOM_OUT); // if we zoom, hide the bubble Log.d(TAG, "onOptionsItemSelected -> zoom out"); break; @@ -702,21 +610,22 @@ public class Navit extends Activity { break; case 5 : // toggle the normal POI layers and labels (to avoid double POIs) - Message msg = Message.obtain(NavitGraphics.sCallbackHandler, - NavitGraphics.MsgType.CLB_CALL_CMD.ordinal()); + Message msg = Message.obtain(NavitCallbackHandler.sCallbackHandler, + NavitCallbackHandler.MsgType.CLB_CALL_CMD.ordinal()); Bundle b = new Bundle(); b.putString("cmd", "toggle_layer(\"POI Symbols\");"); msg.setData(b); msg.sendToTarget(); - - msg = Message.obtain(NavitGraphics.sCallbackHandler, NavitGraphics.MsgType.CLB_CALL_CMD.ordinal()); + msg = Message.obtain(NavitCallbackHandler.sCallbackHandler, + NavitCallbackHandler.MsgType.CLB_CALL_CMD.ordinal()); b = new Bundle(); b.putString("cmd", "toggle_layer(\"POI Labels\");"); msg.setData(b); msg.sendToTarget(); // toggle full POI icons on/off - msg = Message.obtain(NavitGraphics.sCallbackHandler, NavitGraphics.MsgType.CLB_CALL_CMD.ordinal()); + msg = Message.obtain(NavitCallbackHandler.sCallbackHandler, + NavitCallbackHandler.MsgType.CLB_CALL_CMD.ordinal()); b = new Bundle(); b.putString("cmd", "toggle_layer(\"Android-POI-Icons-full\");"); msg.setData(b); @@ -768,7 +677,8 @@ public class Navit extends Activity { Log.d(TAG, "showNativeKeyboard"); Configuration config = getResources().getConfiguration(); if ((config.keyboard == Configuration.KEYBOARD_QWERTY) - && (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO)) { + && (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) + && (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P)) { /* physical keyboard present */ return 0; } @@ -777,7 +687,6 @@ public class Navit extends Activity { ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .showSoftInput(getCurrentFocus(), InputMethodManager.SHOW_FORCED); sShowSoftKeyboardShowing = true; - return 1; } @@ -793,20 +702,6 @@ public class Navit extends Activity { } - void setDestination(float latitude, float longitude, String address) { - Toast.makeText(getApplicationContext(), getTstring(R.string.address_search_set_destination) + "\n" - + address, Toast.LENGTH_LONG).show(); //TRANS - - Bundle b = new Bundle(); - b.putFloat("lat", latitude); - b.putFloat("lon", longitude); - b.putString("q", address); - Message msg = Message.obtain(NavitGraphics.sCallbackHandler, - NavitGraphics.MsgType.CLB_SET_DESTINATION.ordinal()); - msg.setData(b); - msg.sendToTarget(); - } - protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case Navit.NavitDownloaderSelectMap_id : @@ -823,8 +718,8 @@ public class Navit extends Activity { getTstring(R.string.address_search_set_destination) + "\n" + destination.getString(("q")), Toast.LENGTH_LONG).show(); //TRANS - Message msg = Message.obtain(NavitGraphics.sCallbackHandler, - NavitGraphics.MsgType.CLB_SET_DESTINATION.ordinal()); + Message msg = Message.obtain(NavitCallbackHandler.sCallbackHandler, + NavitCallbackHandler.MsgType.CLB_SET_DESTINATION.ordinal()); msg.setData(destination); msg.sendToTarget(); } @@ -887,7 +782,7 @@ public class Navit extends Activity { @Override public void onDestroy() { super.onDestroy(); - Log.d(TAG, "OnDestroy"); + Log.d(TAG, "onDestroy"); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.cancelAll(); NavitVehicle.removeListeners(this); @@ -897,7 +792,7 @@ public class Navit extends Activity { public void onStop() { super.onStop(); - Log.d(TAG, "OnStop"); + Log.d(TAG, "onStop"); } @@ -916,6 +811,7 @@ public class Navit extends Activity { } + @SuppressWarnings("unused") void disableSuspend() { mWakeLock.acquire(); mWakeLock.release(); |