summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjandegr <jandegr@users.noreply.github.com>2018-05-28 10:59:39 +0200
committerGitHub <noreply@github.com>2018-05-28 10:59:39 +0200
commitce79c4708969b441cb0ae3735836e4cc951849c7 (patch)
treeec79a16c60a2821c79d7e304dd6a10553e3f0eb1
parent2378537d06e53a7e430aaebf2bf309be8a365ed3 (diff)
downloadnavit-ce79c4708969b441cb0ae3735836e4cc951849c7.tar.gz
cleanup
-rw-r--r--navit/android/src/org/navitproject/navit/Navit.java159
1 files changed, 86 insertions, 73 deletions
diff --git a/navit/android/src/org/navitproject/navit/Navit.java b/navit/android/src/org/navitproject/navit/Navit.java
index f5c56676b..b9d650c40 100644
--- a/navit/android/src/org/navitproject/navit/Navit.java
+++ b/navit/android/src/org/navitproject/navit/Navit.java
@@ -147,11 +147,12 @@ public class Navit extends Activity {
}
} finally {
/* Close the FileStreams to prevent Resource leaks */
- if (is != null)
+ if (is != null) {
is.close();
-
- if (os != null)
+ }
+ if (os != null) {
os.close();
+ }
}
}
@@ -166,7 +167,7 @@ public class Navit extends Activity {
}
private boolean extractRes(String resname, String result) {
- boolean needs_update = false;
+ boolean needsUpdate = false;
Log.e(TAG, "Res Name " + resname + ", result " + result);
int id = NavitResources.getIdentifier(resname, "raw", NAVIT_PACKAGE_NAME);
Log.e(TAG, "Res ID " + id);
@@ -175,7 +176,7 @@ public class Navit extends Activity {
File resultfile = new File(result);
if (!resultfile.exists()) {
- needs_update = true;
+ needsUpdate = true;
File path = resultfile.getParentFile();
if ( !path.exists() && !resultfile.getParentFile().mkdirs())
return false;
@@ -191,10 +192,10 @@ public class Navit extends Activity {
e.printStackTrace();
}
if (apkUpdateTime > resultfile.lastModified())
- needs_update = true;
+ needsUpdate = true;
}
- if (needs_update) {
+ if (needsUpdate) {
Log.e(TAG, "Extracting resource");
try {
@@ -251,10 +252,11 @@ public class Navit extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
+ if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
- else
+ } else {
this.getActionBar().hide();
+ }
navit = this;
dialogs = new NavitDialogs(this);
@@ -297,17 +299,16 @@ public class Navit extends Activity {
navigation_bar_height = (nhid > 0) ? resources.getDimensionPixelSize(nhid) : 0;
navigation_bar_height_landscape = (nhlid > 0) ? resources.getDimensionPixelSize(nhlid) : 0;
navigation_bar_width = (nwid > 0) ? resources.getDimensionPixelSize(nwid) : 0;
- Log.d(TAG,
- String.format("status_bar_height=%d, action_bar_default_height=%d, navigation_bar_height=%d, navigation_bar_height_landscape=%d, navigation_bar_width=%d",
- status_bar_height, action_bar_default_height, navigation_bar_height, navigation_bar_height_landscape,
- navigation_bar_width));
- if ((ContextCompat.checkSelfPermission(this,
- Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)||
- (ContextCompat.checkSelfPermission(this,
+ Log.d(TAG, String.format("status_bar_height=%d, action_bar_default_height=%d, navigation_bar_height=%d,"
+ + "navigation_bar_height_landscape=%d, navigation_bar_width=%d", status_bar_height,
+ action_bar_default_height, navigation_bar_height, navigation_bar_height_landscape,
+ navigation_bar_width));
+ if ((ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
+ PackageManager.PERMISSION_GRANTED)|| (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
Log.d (TAG,"ask for permission(s)");
- ActivityCompat.requestPermissions(this,
- new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.ACCESS_FINE_LOCATION},MY_PERMISSIONS_REQUEST_ALL);
+ ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE,
+ Manifest.permission.ACCESS_FINE_LOCATION},MY_PERMISSIONS_REQUEST_ALL);
}
// get the local language -------------
Locale locale = java.util.Locale.getDefault();
@@ -329,7 +330,8 @@ public class Navit extends Activity {
Log.d(TAG, "Language " + lang);
SharedPreferences prefs = getSharedPreferences(NAVIT_PREFS,MODE_PRIVATE);
- map_filename_path = prefs.getString("filenamePath", Environment.getExternalStorageDirectory().getPath() + "/navit/");
+ map_filename_path = prefs.getString("filenamePath",
+ Environment.getExternalStorageDirectory().getPath() + "/navit/");
// make sure the new path for the navitmap.bin file(s) exist!!
File navit_maps_dir = new File(map_filename_path);
@@ -339,13 +341,13 @@ public class Navit extends Activity {
File navit_data_share_dir = new File(NAVIT_DATA_SHARE_DIR);
navit_data_share_dir.mkdirs();
- Display display_ = getWindowManager().getDefaultDisplay();
- int width_ = display_.getWidth();
- int height_ = display_.getHeight();
+ Display display = getWindowManager().getDefaultDisplay();
+ int width = display.getWidth();
+ int height = display.getHeight();
metrics = new DisplayMetrics();
- display_.getMetrics(Navit.metrics);
- int densityDpi = (int)(( Navit.metrics.density*160)-.5f);
- Log.d(TAG, "Navit -> pixels x=" + width_ + " pixels y=" + height_);
+ display.getMetrics(Navit.metrics);
+ int densityDpi = (int)(( Navit.metrics.density * 160) - .5f);
+ Log.d(TAG, "Navit -> pixels x=" + width + " pixels y=" + height);
Log.d(TAG, "Navit -> dpi=" + densityDpi);
Log.d(TAG, "Navit -> density=" + Navit.metrics.density);
Log.d(TAG, "Navit -> scaledDensity=" + Navit.metrics.scaledDensity);
@@ -373,7 +375,7 @@ public class Navit extends Activity {
} else if (densityDpi < 640) {
my_display_density = "xxxhdpi";
} else {
- Log.e(TAG, "found device of very high density ("+densityDpi+")");
+ Log.e(TAG, "found device of very high density (" + densityDpi + ")");
Log.e(TAG, "using xxxhdpi values");
my_display_density = "xxxhdpi";
}
@@ -423,10 +425,11 @@ public class Navit extends Activity {
if (show_soft_keyboard_now_showing) {
/* Calling showNativeKeyboard() directly won't work here, we need to use the message queue */
View cf = getCurrentFocus();
- if (cf == null)
+ if (cf == null) {
Log.e(TAG, "no view in focus, can't get a handler");
- else
+ } else {
cf.getHandler().post(new SoftInputRestorer());
+ }
}
}
@@ -444,23 +447,25 @@ public class Navit extends Activity {
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
- case MY_PERMISSIONS_REQUEST_ALL: {
- if (grantResults.length > 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED
- && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
- return;
- }
- AlertDialog.Builder infobox = new AlertDialog.Builder(this);
- infobox.setTitle(getTstring(R.string.permissions_info_box_title)); // TRANS
- infobox.setCancelable(false);
- infobox.setMessage(getTstring(R.string.permissions_not_granted));
- // TRANS
- infobox.setPositiveButton(getTstring(R.string.initial_info_box_OK), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface arg0, int arg1) {
- exit();
+ case MY_PERMISSIONS_REQUEST_ALL:
+ if (grantResults.length > 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED
+ && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
+ return;
}
- });
- infobox.show();
- }
+ AlertDialog.Builder infobox = new AlertDialog.Builder(this);
+ infobox.setTitle(getTstring(R.string.permissions_info_box_title)); // TRANS
+ infobox.setCancelable(false);
+ infobox.setMessage(getTstring(R.string.permissions_not_granted));
+ // TRANS
+ infobox.setPositiveButton(getTstring(R.string.initial_info_box_OK),
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface arg0, int arg1) {
+ exit();
+ }
+ });
+ infobox.show();
+ default:
+ break;
}
}
@@ -520,8 +525,8 @@ public class Navit extends Activity {
}
}
- public void setActivityResult(int requestCode, NavitActivityResult ActivityResult) {
- ActivityResults[requestCode] = ActivityResult;
+ public void setActivityResult(int requestCode, NavitActivityResult activityResult) {
+ ActivityResults[requestCode] = activityResult;
}
@@ -557,11 +562,11 @@ public class Navit extends Activity {
private NavitGraphics N_NavitGraphics = null;
// callback id gets set here when called from NavitGraphics
- public void setKeypressCallback(int kp_cb_id, NavitGraphics ng) {
+ public void setKeypressCallback(int kpCbId, NavitGraphics ng) {
N_NavitGraphics = ng;
}
- public void setMotionCallback(int mo_cb_id, NavitGraphics ng) {
+ public void setMotionCallback(int moCbId, NavitGraphics ng) {
N_NavitGraphics = ng;
}
@@ -592,13 +597,15 @@ public class Navit extends Activity {
switch (id) {
case 1 :
// zoom in
- Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_IN.ordinal()).sendToTarget();
+ Message.obtain(N_NavitGraphics.callback_handler,
+ NavitGraphics.msg_type.CLB_ZOOM_IN.ordinal()).sendToTarget();
// if we zoom, hide the bubble
Log.d(TAG, "onOptionsItemSelected -> zoom in");
break;
case 2 :
// zoom out
- Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_OUT.ordinal()).sendToTarget();
+ Message.obtain(N_NavitGraphics.callback_handler,
+ NavitGraphics.msg_type.CLB_ZOOM_OUT.ordinal()).sendToTarget();
// if we zoom, hide the bubble
Log.d(TAG, "onOptionsItemSelected -> zoom out");
break;
@@ -609,7 +616,8 @@ public class Navit extends Activity {
break;
case 5 :
// toggle the normal POI layers and labels (to avoid double POIs)
- Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_CALL_CMD.ordinal());
+ Message msg = Message.obtain(N_NavitGraphics.callback_handler,
+ NavitGraphics.msg_type.CLB_CALL_CMD.ordinal());
Bundle b = new Bundle();
b.putString("cmd", "toggle_layer(\"POI Symbols\");");
msg.setData(b);
@@ -646,6 +654,8 @@ public class Navit extends Activity {
this.onStop();
this.exit();
break;
+ default:
+ break;
}
}
@@ -673,9 +683,10 @@ public class Navit extends Activity {
*/
Configuration config = getResources().getConfiguration();
if ((config.keyboard == Configuration.KEYBOARD_QWERTY)
- && (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO))
+ && (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO)){
/* physical keyboard present, exit */
return 0;
+ }
/* Use SHOW_FORCED here, else keyboard won't show in landscape mode */
mgr.showSoftInput(getCurrentFocus(), InputMethodManager.SHOW_FORCED);
@@ -686,13 +697,14 @@ public class Navit extends Activity {
* is about 62-63% of available screen width (in portrait mode) but no more than slightly above
* 46% of height (in landscape mode).
*/
- Display display_ = getWindowManager().getDefaultDisplay();
- int width_ = display_.getWidth();
- int height_ = display_.getHeight();
- int maxHeight = height_ * 47 / 100;
- int inputHeight = width_ * 63 / 100;
- if (inputHeight > (maxHeight))
+ Display display = getWindowManager().getDefaultDisplay();
+ int width = display.getWidth();
+ int height = display.getHeight();
+ int maxHeight = height * 47 / 100;
+ int inputHeight = width * 63 / 100;
+ if (inputHeight > (maxHeight)) {
inputHeight = maxHeight;
+ }
/* the receiver isn't going to fire before the UI thread becomes idle, well after this method returns */
Log.d(TAG, "showNativeKeyboard:return (assuming true)");
@@ -710,10 +722,11 @@ 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.makeText(getApplicationContext(),getTstring(R.string.address_search_set_destination) + "\n" + address,
Toast.LENGTH_LONG).show(); //TRANS
- Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal());
+ Message msg = Message.obtain(N_NavitGraphics.callback_handler,
+ NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal());
Bundle b = new Bundle();
b.putFloat("lat", latitude);
b.putFloat("lon", longitude);
@@ -726,15 +739,15 @@ public class Navit extends Activity {
switch (requestCode) {
case Navit.NavitDownloaderSelectMap_id :
if (resultCode == Activity.RESULT_OK) {
- Message msg = dialogs.obtainMessage(NavitDialogs.MSG_START_MAP_DOWNLOAD
- , data.getIntExtra("map_index", -1), 0);
+ Message msg = dialogs.obtainMessage(NavitDialogs.MSG_START_MAP_DOWNLOAD,
+ data.getIntExtra("map_index", -1), 0);
msg.sendToTarget();
}
break;
case NavitAddressSearch_id :
- if (resultCode == Activity.RESULT_OK) {
+ if (resultCode == Activity.RESULT_OK) {
Bundle destination = data.getExtras();
- Toast.makeText( getApplicationContext(), getTstring(R.string.address_search_set_destination)
+ Toast.makeText(getApplicationContext(), getTstring(R.string.address_search_set_destination)
+ "\n" + destination.getString(("q")), Toast.LENGTH_LONG).show(); //TRANS
Message msg = Message.obtain(N_NavitGraphics.callback_handler,
NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal());
@@ -743,21 +756,21 @@ public class Navit extends Activity {
}
break;
case NavitSelectStorage_id :
- if(resultCode == RESULT_OK) {
+ if (resultCode == RESULT_OK) {
String newDir = data.getStringExtra(FileBrowserActivity.returnDirectoryParameter);
- Log.d(TAG, "selected path= "+newDir);
- if(!newDir.contains("/navit")) {
+ Log.d(TAG, "selected path= " + newDir);
+ if (!newDir.contains("/navit")) {
newDir = newDir + "/navit/";
- }
- else {
+ } else {
newDir = newDir + "/";
}
SharedPreferences prefs = this.getSharedPreferences(NAVIT_PREFS,MODE_PRIVATE);
- SharedPreferences.Editor prefs_editor = prefs.edit();
- prefs_editor.putString("filenamePath", newDir);
- prefs_editor.apply();
+ SharedPreferences.Editor prefsEditor = prefs.edit();
+ prefsEditor.putString("filenamePath", newDir);
+ prefsEditor.apply();
- Toast.makeText(this, String.format(getTstring(R.string.map_location_changed),newDir),Toast.LENGTH_LONG).show();
+ Toast.makeText(this, String.format(getTstring(R.string.map_location_changed),newDir),
+ Toast.LENGTH_LONG).show();
} else {
Log.w(TAG, "select path failed");
}