diff --git a/floatingJapaneseDictionary/build.gradle b/floatingJapaneseDictionary/build.gradle index b8c5a05..6d579a8 100644 --- a/floatingJapaneseDictionary/build.gradle +++ b/floatingJapaneseDictionary/build.gradle @@ -6,7 +6,7 @@ android { defaultConfig { applicationId "pedals.is.floatingjapanesedictionary" - minSdkVersion 11 + minSdkVersion 14 targetSdkVersion 21 testApplicationId "pedals.is.floatingjapanesedictionary.test" diff --git a/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/FloatingJapaneseDictionaryLauncherActivity.java b/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/FloatingJapaneseDictionaryLauncherActivity.java index a05aa59..0a01d64 100644 --- a/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/FloatingJapaneseDictionaryLauncherActivity.java +++ b/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/FloatingJapaneseDictionaryLauncherActivity.java @@ -28,7 +28,7 @@ public class FloatingJapaneseDictionaryLauncherActivity extends Activity { - private static final String TAG = "FloatingJapaneseDictionaryLauncherActivity"; + private static final String TAG = "FJDLauncherActivity"; @Override protected void onStart() { diff --git a/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/FloatingJapaneseDictionaryService.java b/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/FloatingJapaneseDictionaryService.java index fdca52a..cc0bd17 100644 --- a/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/FloatingJapaneseDictionaryService.java +++ b/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/FloatingJapaneseDictionaryService.java @@ -56,12 +56,12 @@ public class FloatingJapaneseDictionaryService extends StandOutWindow { private static final String APP_NAME = "Floating Japanese Dictionary"; private static final int APP_ICON = android.R.drawable.ic_menu_add; - private static File saveLocation = new File( + private static final File saveLocation = new File( Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "Words.txt"); - private static final String TAG = "FloatingJapaneseDictionaryService"; + private static final String TAG = "FJDService"; private static final int CLOSED = 0, OPENED = 1; @@ -168,7 +168,7 @@ public void onClick(final View searchView) { } }); - adapter = new ArrayAdapter(this, + adapter = new ArrayAdapter<>(this, R.layout.dictionaryentry, entries); ListView listView = (ListView) view.findViewById(R.id.results); listView.setAdapter(adapter); @@ -183,7 +183,7 @@ public void onItemClick(AdapterView parent, View view, Log.d(TAG, "item clicked " + entry.toString()); try { FileWriter filewriter = new FileWriter(saveLocation, true); - filewriter.append("\r\n" + entry.toString()); + filewriter.append("\r\n").append(entry.toString()); filewriter.close(); Log.d(TAG, "item saved to " + saveLocation.getAbsolutePath()); @@ -221,10 +221,10 @@ private void synchronizePositions(int id, StandOutLayoutParams... params) { StandOutLayoutParams currentParam = getParams(id); Log.d(TAG, "Synchronizing position: x, y " + currentParam.x + " " + currentParam.y); - for (int i = 0; i < params.length; i++) { - if (params[i] != null) { - params[i].x = currentParam.x; - params[i].y = currentParam.y; + for (StandOutLayoutParams param : params) { + if (param != null) { + param.x = currentParam.x; + param.y = currentParam.y; } } } @@ -345,7 +345,7 @@ private void displaySearch(Window window, String text) { @Override public List getDropDownItems(int id) { - List items = new ArrayList(); + List items = new ArrayList<>(); items.add(new DropDownListItem(0, "About", new Runnable() { @Override diff --git a/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/deinflector/DeInflector.java b/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/deinflector/DeInflector.java index 4492ac9..68ea7cd 100644 --- a/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/deinflector/DeInflector.java +++ b/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/deinflector/DeInflector.java @@ -39,8 +39,8 @@ public class DeInflector { - private static final ArrayList reasons = new ArrayList(); - private static final ArrayList rules = new ArrayList(); + private static final ArrayList reasons = new ArrayList<>(); + private static final ArrayList rules = new ArrayList<>(); static { reasons.add("polite past negative"); @@ -199,10 +199,10 @@ public class DeInflector { public static ArrayList deInflect( final String inflectedWord) { - final HashMap have = new HashMap(); + final HashMap have = new HashMap<>(); have.put(inflectedWord, 0); - final ArrayList r = new ArrayList(); + final ArrayList r = new ArrayList<>(); r.add(new DeinflectorTerm(inflectedWord, 0xFF, "")); int i = 0; diff --git a/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/dictionarysearcher/DictionaryEntries.java b/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/dictionarysearcher/DictionaryEntries.java index cee3c2e..4b43898 100644 --- a/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/dictionarysearcher/DictionaryEntries.java +++ b/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/dictionarysearcher/DictionaryEntries.java @@ -38,7 +38,7 @@ public static DictionaryEntries fromParcelable( public ArrayList toParcelableContentValues() { - ArrayList ret = new ArrayList(); + ArrayList ret = new ArrayList<>(); for (DictionaryEntry entry : this) { ContentValues value = entry.toContentValues(); ret.add(value); diff --git a/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/dictionarysearcher/DictionarySearcher.java b/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/dictionarysearcher/DictionarySearcher.java index e9fbb27..aaf880a 100644 --- a/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/dictionarysearcher/DictionarySearcher.java +++ b/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/dictionarysearcher/DictionarySearcher.java @@ -48,15 +48,14 @@ public class DictionarySearcher { - @SuppressWarnings("unused") + private static final int USING_LOCAL = 1, USING_EXTERNAL = 2, USING_BUILT_IN = 3; - public static final int DICTIONARY_TYPE = USING_LOCAL; + private static final int DICTIONARY_TYPE = USING_LOCAL; public static final String DICTIONARY_NAME = "dict.sqlite"; // TABLE dict (kanji TEXT, kana TEXT, entry TEXT) - @SuppressWarnings("unused") private static SQLiteDatabase getDatabase(Context context) { if (DICTIONARY_TYPE == USING_EXTERNAL) { @@ -83,13 +82,16 @@ else if (DICTIONARY_TYPE == USING_LOCAL) { return SQLiteDatabase.openDatabase(dictionaryPath, null, SQLiteDatabase.OPEN_READONLY); } - else { + else if (DICTIONARY_TYPE == USING_BUILT_IN){ DictionaryOpenHelper dictOpener = new DictionaryOpenHelper(context); return dictOpener.getReadableDatabase(); } + else { + throw new IllegalStateException( + "Unhandled Dictionary Type"); + } } - @SuppressWarnings("unused") public static boolean dictionaryExists(Context context) { File dictionaryFile; diff --git a/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/downloader/DictionaryManagerService.java b/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/downloader/DictionaryManagerService.java index 65ec99d..815bef3 100644 --- a/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/downloader/DictionaryManagerService.java +++ b/floatingJapaneseDictionary/src/main/java/pedals/is/floatingjapanesedictionary/downloader/DictionaryManagerService.java @@ -66,7 +66,6 @@ else if (message.obj.equals("reset")) { deleteFiles(); RUNNING = false; stopSelf(message.arg1); - return; } else if (message.obj.equals("download")) { // no pending download @@ -87,13 +86,13 @@ else if (message.obj.equals("download")) { private Looper looper; private ServiceHandler handler; - public static String DOWNLOAD_URL = "https://addons.mozilla.org/firefox/downloads/latest/398350/addon-398350-latest.xpi?src=ss"; + private static String DOWNLOAD_URL = "https://addons.mozilla.org/firefox/downloads/latest/398350/addon-398350-latest.xpi?src=ss"; private static final String DOWNLOAD_FILE_NAME = "dict.xpi"; private static long enqueuedID = -1; public static boolean RUNNING = false; - private static final String TAG = "DictionaryManagerService"; + private static final String TAG = "FJDManagerService"; // callback for when download is complete // it handles extracting the sqlite database out of the xpi file @@ -228,7 +227,11 @@ private void downloadDictionary() { private void deleteFiles() { - for (File file : this.getExternalFilesDir(null).listFiles()) { + File[] files = this.getExternalFilesDir(null).listFiles(); + if(files == null){ + return; + } + for (File file : files) { Log.d(TAG, "Deleting file: " + file.getAbsolutePath()); file.delete(); } @@ -238,7 +241,7 @@ private void deleteFiles() { private File extractFile(Uri uri, String desiredFile) { Log.d(TAG, "Trying to extract " + desiredFile); - File unzippedFile = null; + File unzippedFile; try { File zippedFile = new File(uri.getPath()); ZipFile zipFile = new ZipFile(zippedFile, ZipFile.OPEN_READ);