From bd84a00fc140d2d02b8eafbf6c94c009da62c9cd Mon Sep 17 00:00:00 2001 From: Satoshi Kataoka Date: Thu, 27 Jun 2013 15:56:16 +0900 Subject: [PATCH] Open an API in ExternalDictionaryGetterForDebug and extend it Change-Id: Id2ba8dd8928a6327d3b31eb35f7cc314e2d31050 --- .../ExternalDictionaryGetterForDebug.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/ExternalDictionaryGetterForDebug.java b/java/src/com/android/inputmethod/latin/ExternalDictionaryGetterForDebug.java index 18f4920d9..47d9bf34d 100644 --- a/java/src/com/android/inputmethod/latin/ExternalDictionaryGetterForDebug.java +++ b/java/src/com/android/inputmethod/latin/ExternalDictionaryGetterForDebug.java @@ -19,6 +19,7 @@ package com.android.inputmethod.latin; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; +import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnClickListener; import android.os.Environment; @@ -59,7 +60,7 @@ public class ExternalDictionaryGetterForDebug { if (0 == fileNames.length) { showNoFileDialog(context); } else if (1 == fileNames.length) { - askInstallFile(context, fileNames[0]); + askInstallFile(context, SOURCE_FOLDER, fileNames[0], null /* completeRunnable */); } else { showChooseFileDialog(context, fileNames); } @@ -82,14 +83,19 @@ public class ExternalDictionaryGetterForDebug { .setItems(fileNames, new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { - askInstallFile(context, fileNames[which]); + askInstallFile(context, SOURCE_FOLDER, fileNames[which], + null /* completeRunnable */); } }) .create().show(); } - private static void askInstallFile(final Context context, final String fileName) { - final File file = new File(SOURCE_FOLDER, fileName.toString()); + /** + * Shows a dialog which offers the user to install the external dictionary. + */ + public static void askInstallFile(final Context context, final String dirPath, + final String fileName, final Runnable completeRunnable) { + final File file = new File(dirPath, fileName.toString()); final FileHeader header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(file); final StringBuilder message = new StringBuilder(); final String locale = header.getLocaleString(); @@ -109,12 +115,26 @@ public class ExternalDictionaryGetterForDebug { @Override public void onClick(final DialogInterface dialog, final int which) { dialog.dismiss(); + if (completeRunnable != null) { + completeRunnable.run(); + } } }).setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { installFile(context, file, header); dialog.dismiss(); + if (completeRunnable != null) { + completeRunnable.run(); + } + } + }).setOnCancelListener(new OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + // Canceled by the user by hitting the back key + if (completeRunnable != null) { + completeRunnable.run(); + } } }).create().show(); }