diff options
author | jandegr <jandegr@users.noreply.github.com> | 2018-05-29 13:29:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-29 13:29:52 +0200 |
commit | dd72b006bb249cfe391ff936609466bd89bb4ff1 (patch) | |
tree | 8a573e7a55ae732b72bfe62a33b492ec479f6f33 | |
parent | 349caaef4d62686cd3c23fb9426ba2d751eba0b9 (diff) | |
download | navit-dd72b006bb249cfe391ff936609466bd89bb4ff1.tar.gz |
cleanup
3 files changed, 132 insertions, 128 deletions
diff --git a/navit/android/src/org/navitproject/navit/NavitBackupTask.java b/navit/android/src/org/navitproject/navit/NavitBackupTask.java index 6330cd4d4..de495cc91 100644 --- a/navit/android/src/org/navitproject/navit/NavitBackupTask.java +++ b/navit/android/src/org/navitproject/navit/NavitBackupTask.java @@ -43,19 +43,22 @@ public class NavitBackupTask extends AsyncTask<Void, Void, String> { /* Create the Main Backup Directory if it doesn't exist */ if (!mainBackupDir.isDirectory()) { - if (!mainBackupDir.mkdirs()) + if (!mainBackupDir.mkdirs()) { return mActivity.getString(R.string.failed_to_create_backup_directory); + } } /* Create a Timestamp in the format YYYY-MM-DD-Index */ - String timestamp = now.year + "-" + String.format("%02d", now.month+1) + "-" + String.format("%02d", now.monthDay); + String timestamp = now.year + "-" + String.format("%02d", now.month + 1) + + "-" + String.format("%02d", now.monthDay); /* Get the next free index */ int index = 1; for (String s : mainBackupDir.list()) { if (s.contains(timestamp)) { int newIndex = Integer.parseInt(s.substring(11)); - if (newIndex >= index) + if (newIndex >= index) { index = newIndex + 1; + } } } timestamp += "-" + index; @@ -66,16 +69,20 @@ public class NavitBackupTask extends AsyncTask<Void, Void, String> { /* Create the Backup Directory if it doesn't exist */ if (!backupDir.isDirectory()) { - if (!backupDir.mkdirs()) + if (!backupDir.mkdirs()) { return mActivity.getString(R.string.failed_to_create_backup_directory); + } } ObjectOutputStream preferencesOOs = null; try { /* Backup Files in home */ - mActivity.copyFileIfExists(Navit.NAVIT_DATA_DIR + "/home/bookmark.txt", backupDir.getPath() + "/bookmark.txt"); - mActivity.copyFileIfExists(Navit.NAVIT_DATA_DIR + "/home/destination.txt", backupDir.getPath() + "/destination.txt"); - mActivity.copyFileIfExists(Navit.NAVIT_DATA_DIR + "/home/gui_internal.txt", backupDir.getPath() + "/gui_internal.txt"); + mActivity.copyFileIfExists(Navit.NAVIT_DATA_DIR + "/home/bookmark.txt", backupDir.getPath() + + "/bookmark.txt"); + mActivity.copyFileIfExists(Navit.NAVIT_DATA_DIR + "/home/destination.txt", backupDir.getPath() + + "/destination.txt"); + mActivity.copyFileIfExists(Navit.NAVIT_DATA_DIR + "/home/gui_internal.txt", backupDir.getPath() + + "/gui_internal.txt"); /* Backup Shared Preferences */ preferencesOOs = new ObjectOutputStream(new FileOutputStream @@ -90,8 +97,9 @@ public class NavitBackupTask extends AsyncTask<Void, Void, String> { finally { /* Close Stream to prevent Resource Leaks */ try { - if (preferencesOOs != null) + if (preferencesOOs != null) { preferencesOOs.close(); + } } catch (IOException e) { e.printStackTrace(); diff --git a/navit/android/src/org/navitproject/navit/NavitRestoreTask.java b/navit/android/src/org/navitproject/navit/NavitRestoreTask.java index a44ef7b2e..849b2466d 100644 --- a/navit/android/src/org/navitproject/navit/NavitRestoreTask.java +++ b/navit/android/src/org/navitproject/navit/NavitRestoreTask.java @@ -1,3 +1,4 @@ + package org.navitproject.navit; import android.app.NotificationManager; @@ -7,6 +8,7 @@ import android.content.SharedPreferences.Editor; import android.os.AsyncTask; import android.os.Environment; import android.widget.Toast; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -22,7 +24,7 @@ public class NavitRestoreTask extends AsyncTask<Void, Void, String> { private String mTimestamp; - public NavitRestoreTask(Navit context, String timestamp) { + NavitRestoreTask(Navit context, String timestamp) { mActivity = context; mTimestamp = timestamp; } @@ -34,7 +36,7 @@ public class NavitRestoreTask extends AsyncTask<Void, Void, String> { /* Create a Wait Progress Dialog to inform the User that we are working */ mDialog = new ProgressDialog(mActivity); mDialog.setIndeterminate(true); - mDialog.setMessage(mActivity.getTstring(R.string.restoring)); + mDialog.setMessage(mActivity.getString(R.string.restoring)); mDialog.show(); } @@ -43,38 +45,30 @@ public class NavitRestoreTask extends AsyncTask<Void, Void, String> { protected String doInBackground(Void... v) { /* This is the Directory where all Subdirectories are stored by date */ - File backupDir = new File( - Environment.getExternalStorageDirectory().getPath() + "/navit/backup/" - + mTimestamp); - + File backupDir = new File(Environment.getExternalStorageDirectory().getPath() + "/navit/backup/" + mTimestamp); + /* Check if there is a Backup Directory */ - if (!backupDir.isDirectory()) { - return mActivity.getTstring(R.string.backup_not_found); - } + if (!backupDir.isDirectory()) + return mActivity.getString(R.string.backup_not_found); - ObjectInputStream preferenceOIS = null; + ObjectInputStream prefObjInStream = null; try { /* Delete all old Files in Home */ mActivity.removeFileIfExists(Navit.NAVIT_DATA_DIR + "/home/bookmark.txt"); mActivity.removeFileIfExists(Navit.NAVIT_DATA_DIR + "/home/destination.txt"); mActivity.removeFileIfExists(Navit.NAVIT_DATA_DIR + "/home/gui_internal.txt"); - + /* Restore Files in home */ - mActivity.copyFileIfExists(backupDir.getPath() + "/bookmark.txt", - Navit.NAVIT_DATA_DIR + "/home/bookmark.txt"); - mActivity.copyFileIfExists(backupDir.getPath() + "/destination.txt", - Navit.NAVIT_DATA_DIR + "/home/destination.txt"); - mActivity.copyFileIfExists(backupDir.getPath() + "/gui_internal.txt", - Navit.NAVIT_DATA_DIR + "/home/gui_internal.txt"); + mActivity.copyFileIfExists(backupDir.getPath() + "/bookmark.txt", Navit.NAVIT_DATA_DIR + "/home/bookmark.txt"); + mActivity.copyFileIfExists(backupDir.getPath() + "/destination.txt", Navit.NAVIT_DATA_DIR + "/home/destination.txt"); + mActivity.copyFileIfExists(backupDir.getPath() + "/gui_internal.txt", Navit.NAVIT_DATA_DIR + "/home/gui_internal.txt"); /* Restore Shared Preferences */ - preferenceOIS = new ObjectInputStream( - new FileInputStream(backupDir.getPath() + "/preferences.bak")); - Map<String, ?> entries = (Map<String, ?>) preferenceOIS.readObject(); + prefObjInStream = new ObjectInputStream(new FileInputStream(backupDir.getPath() + "/preferences.bak")); + Map<String, ?> entries = (Map<String, ?>) prefObjInStream.readObject(); - Editor prefEditor = mActivity - .getSharedPreferences(Navit.NAVIT_PREFS, Context.MODE_PRIVATE).edit(); + Editor prefEditor = mActivity.getSharedPreferences(Navit.NAVIT_PREFS, Context.MODE_PRIVATE).edit(); /* Remove all old Preferences */ prefEditor.clear(); @@ -84,33 +78,33 @@ public class NavitRestoreTask extends AsyncTask<Void, Void, String> { Object value = entry.getValue(); String key = entry.getKey(); - if (value instanceof Boolean) { - prefEditor.putBoolean(key, ((Boolean) value).booleanValue()); - } else if (value instanceof Float) { - prefEditor.putFloat(key, ((Float) value).floatValue()); - } else if (value instanceof Integer) { - prefEditor.putInt(key, ((Integer) value).intValue()); - } else if (value instanceof Long) { - prefEditor.putLong(key, ((Long) value).longValue()); - } else if (value instanceof String) { + if (value instanceof Boolean) + prefEditor.putBoolean(key, (Boolean) value); + else if (value instanceof Float) + prefEditor.putFloat(key, (Float) value); + else if (value instanceof Integer) + prefEditor.putInt(key, (Integer) value); + else if (value instanceof Long) + prefEditor.putLong(key, (Long) value); + else if (value instanceof String) prefEditor.putString(key, (String) value); - } } - if (!prefEditor.commit()) { - return mActivity.getTstring(R.string.failed_to_restore); - } + if (!prefEditor.commit()) + return mActivity.getString(R.string.failed_to_restore); - } catch (Exception e) { + } + catch (Exception e) { e.printStackTrace(); - return mActivity.getTstring(R.string.failed_to_restore); - } finally { + return mActivity.getString(R.string.failed_to_restore); + } + finally { try { /* Close Stream to prevent Resource leak */ - if (preferenceOIS != null) { - preferenceOIS.close(); - } - } catch (IOException e) { + if (prefObjInStream != null) + prefObjInStream.close(); + } + catch (IOException e) { } } @@ -132,11 +126,8 @@ public class NavitRestoreTask extends AsyncTask<Void, Void, String> { } /* Navit needs to be restarted. Currently the User has to restart it by himself */ - Toast.makeText(mActivity, - mActivity.getTstring(R.string.restore_successful_please_restart_navit), - Toast.LENGTH_LONG).show(); - NotificationManager nm = (NotificationManager) mActivity - .getSystemService(Context.NOTIFICATION_SERVICE); + Toast.makeText(mActivity, mActivity.getString(R.string.restore_successful_please_restart_navit), Toast.LENGTH_LONG).show(); + NotificationManager nm = (NotificationManager) mActivity.getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(R.string.app_name); NavitVehicle.removeListener(); mActivity.finish(); @@ -145,8 +136,7 @@ public class NavitRestoreTask extends AsyncTask<Void, Void, String> { @Override protected void onCancelled() { super.onCancelled(); - Toast.makeText(mActivity, mActivity.getTstring(R.string.restore_failed), Toast.LENGTH_LONG) - .show(); + Toast.makeText(mActivity, mActivity.getString(R.string.restore_failed), Toast.LENGTH_LONG).show(); mDialog.dismiss(); - } + } } diff --git a/navit/android/src/org/navitproject/navit/NavitWatch.java b/navit/android/src/org/navitproject/navit/NavitWatch.java index 7933d1b0a..e23ac1f08 100644 --- a/navit/android/src/org/navitproject/navit/NavitWatch.java +++ b/navit/android/src/org/navitproject/navit/NavitWatch.java @@ -19,80 +19,86 @@ package org.navitproject.navit; +import java.lang.Thread; import android.os.Handler; import android.os.Message; import android.util.Log; -import java.lang.Thread; - -public class NavitWatch implements Runnable { - private Thread thread; - private static Handler handler =new Handler() { - public void handleMessage(Message m) { - Log.e("NavitWatch","Handler received message"); - } - }; - private boolean removed; - private int watch_func; - private int watch_fd; - private int watch_cond; - private int watch_callbackid; - private boolean callback_pending; - private Runnable callback_runnable; - public native void poll(int func, int fd, int cond); - public native void WatchCallback(int id); +class NavitWatch implements Runnable { + private Thread thread; + private static Handler handler = new Handler() { + public void handleMessage(Message m) { + Log.e("NavitWatch","Handler received message"); + } + }; + private boolean removed; + private int watch_func; + private int watch_fd; + private int watch_cond; + private int watch_callbackid; + private boolean callback_pending; + private Runnable callback_runnable; + public native void poll(int func, int fd, int cond); + public native void watchCallback(int id); - NavitWatch(int func, int fd, int cond, int callbackid) { - // Log.e("NavitWatch","Creating new thread for "+fd+" "+cond+" from current thread " + java.lang.Thread.currentThread().getName()); - watch_func=func; - watch_fd=fd; - watch_cond=cond; - watch_callbackid=callbackid; - final NavitWatch navitwatch=this; - callback_runnable = new Runnable() { - public void run() { - navitwatch.callback(); - } - }; - thread = new Thread(this, "poll thread"); - thread.start(); - } - public void run() { - for (;;) { - // Log.e("NavitWatch","Polling "+watch_fd+" "+watch_cond + " from " + java.lang.Thread.currentThread().getName()); - poll(watch_func, watch_fd, watch_cond); - // Log.e("NavitWatch","poll returned"); - if (removed) - break; - callback_pending=true; - handler.post(callback_runnable); - try { - // Log.e("NavitWatch","wait"); - synchronized(this) { - if (callback_pending) - this.wait(); - } - // Log.e("NavitWatch","wait returned"); - } catch (Exception e) { - Log.e("NavitWatch","Exception "+e.getMessage()); - } - if (removed) - break; - } - } - public void callback() { - // Log.e("NavitWatch","Calling Callback"); - if (!removed) - WatchCallback(watch_callbackid); - synchronized(this) { - callback_pending=false; - // Log.e("NavitWatch","Waking up"); - this.notify(); - } - } - public void remove() { - removed=true; - thread.interrupt(); - } + NavitWatch(int func, int fd, int cond, int callbackid) + { + // Log.e("NavitWatch","Creating new thread for "+fd+" "+cond+" from current thread " + // + java.lang.Thread.currentThread().getName()); + watch_func = func; + watch_fd = fd; + watch_cond = cond; + watch_callbackid = callbackid; + final NavitWatch navitwatch = this; + callback_runnable = new Runnable() { + public void run() + { + navitwatch.callback(); + } + }; + thread = new Thread(this, "poll thread"); + thread.start(); + } + public void run() + { + for (;;) { + // Log.e("NavitWatch","Polling "+watch_fd+" "+watch_cond + " from " + // + java.lang.Thread.currentThread().getName()); + poll(watch_func, watch_fd, watch_cond); + // Log.e("NavitWatch","poll returned"); + if (removed) + break; + callback_pending = true; + handler.post(callback_runnable); + try { + // Log.e("NavitWatch","wait"); + synchronized(this) { + if (callback_pending) + this.wait(); + } + // Log.e("NavitWatch","wait returned"); + } catch (Exception e) { + Log.e("NavitWatch","Exception "+e.getMessage()); + } + if (removed) + break; + } + } + public void callback() + { + // Log.e("NavitWatch","Calling Callback"); + if (!removed) + watchCallback(watch_callbackid); + synchronized(this) { + callback_pending = false; + // Log.e("NavitWatch","Waking up"); + this.notify(); + } + } + public void remove() + { + removed=true; + thread.interrupt(); + } } |