mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
dictionaries list has been added
This commit is contained in:
parent
876c37f3cd
commit
58c448f02e
1 changed files with 61 additions and 8 deletions
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package org.geometerplus.android.fbreader;
|
package org.geometerplus.android.fbreader;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.SearchManager;
|
import android.app.SearchManager;
|
||||||
|
@ -26,18 +28,68 @@ import android.content.ComponentName;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
import org.geometerplus.android.util.UIUtil;
|
import org.geometerplus.android.util.UIUtil;
|
||||||
import org.geometerplus.android.util.PackageUtil;
|
import org.geometerplus.android.util.PackageUtil;
|
||||||
|
|
||||||
|
class PackageInfo {
|
||||||
|
public final String PackageName;
|
||||||
|
public final String ClassName;
|
||||||
|
public final String Title;
|
||||||
|
|
||||||
|
PackageInfo(String packageName, String className, String title) {
|
||||||
|
PackageName = packageName;
|
||||||
|
ClassName = className;
|
||||||
|
Title = title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
abstract class DictionaryUtil {
|
abstract class DictionaryUtil {
|
||||||
|
private static LinkedList<PackageInfo> ourDictionaryInfos = new LinkedList<PackageInfo>();
|
||||||
|
private static ZLStringOption ourDictionaryOption;
|
||||||
|
|
||||||
|
public static List<PackageInfo> dictionaryInfos() {
|
||||||
|
if (ourDictionaryInfos.isEmpty()) {
|
||||||
|
ourDictionaryInfos.add(new PackageInfo(
|
||||||
|
"com.socialnmobile.colordict",
|
||||||
|
"com.socialnmobile.colordict.activity.Main",
|
||||||
|
"ColorDict"
|
||||||
|
));
|
||||||
|
ourDictionaryInfos.add(new PackageInfo(
|
||||||
|
"com.ngc.fora",
|
||||||
|
"com.ngc.fora.ForaDictionary",
|
||||||
|
"Fora Dictionary"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return ourDictionaryInfos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ZLStringOption dictionaryOption() {
|
||||||
|
if (ourDictionaryOption == null) {
|
||||||
|
ourDictionaryOption =
|
||||||
|
new ZLStringOption("Dictionary", "Class", dictionaryInfos().get(0).ClassName);
|
||||||
|
}
|
||||||
|
return ourDictionaryOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PackageInfo getCurrentDictionaryInfo() {
|
||||||
|
final String className = dictionaryOption().getValue();
|
||||||
|
for (PackageInfo info : dictionaryInfos()) {
|
||||||
|
if (info.ClassName.equals(className)) {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dictionaryInfos().get(0);
|
||||||
|
}
|
||||||
|
|
||||||
public static Intent getDictionaryIntent(String text) {
|
public static Intent getDictionaryIntent(String text) {
|
||||||
|
final PackageInfo dictionaryInfo = getCurrentDictionaryInfo();
|
||||||
return new Intent(Intent.ACTION_SEARCH)
|
return new Intent(Intent.ACTION_SEARCH)
|
||||||
.setComponent(new ComponentName(
|
.setComponent(new ComponentName(
|
||||||
"com.socialnmobile.colordict",
|
dictionaryInfo.PackageName,
|
||||||
"com.socialnmobile.colordict.activity.Main"
|
dictionaryInfo.ClassName
|
||||||
))
|
))
|
||||||
.putExtra(SearchManager.QUERY, text);
|
.putExtra(SearchManager.QUERY, text);
|
||||||
}
|
}
|
||||||
|
@ -46,19 +98,20 @@ abstract class DictionaryUtil {
|
||||||
if (PackageUtil.canBeStarted(activity, getDictionaryIntent("test"))) {
|
if (PackageUtil.canBeStarted(activity, getDictionaryIntent("test"))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final PackageInfo dictionaryInfo = getCurrentDictionaryInfo();
|
||||||
|
|
||||||
final ZLResource dialogResource = ZLResource.resource("dialog");
|
final ZLResource dialogResource = ZLResource.resource("dialog");
|
||||||
final ZLResource buttonResource = dialogResource.getResource("button");
|
final ZLResource buttonResource = dialogResource.getResource("button");
|
||||||
final ZLResource installResource = dialogResource.getResource("installDictionary");
|
final ZLResource installResource = dialogResource.getResource("installDictionary");
|
||||||
new AlertDialog.Builder(activity)
|
new AlertDialog.Builder(activity)
|
||||||
.setTitle(installResource.getResource("title").getValue())
|
.setTitle(installResource.getResource("title").getValue())
|
||||||
.setMessage(installResource.getResource("message").getValue().replace("%s", "ColorDict"))
|
.setMessage(installResource.getResource("message").getValue().replace("%s", dictionaryInfo.Title))
|
||||||
.setIcon(0)
|
.setIcon(0)
|
||||||
.setPositiveButton(
|
.setPositiveButton(
|
||||||
buttonResource.getResource("install").getValue(),
|
buttonResource.getResource("install").getValue(),
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
installDictionary(activity);
|
installDictionary(activity, dictionaryInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -66,9 +119,9 @@ abstract class DictionaryUtil {
|
||||||
.create().show();
|
.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void installDictionary(Activity activity) {
|
private static void installDictionary(Activity activity, PackageInfo dictionaryInfo) {
|
||||||
if (!PackageUtil.installFromMarket(activity, "com.socialnmobile.colordict")) {
|
if (!PackageUtil.installFromMarket(activity, dictionaryInfo.PackageName)) {
|
||||||
UIUtil.showErrorMessage(activity, "cannotRunAndroidMarket", "ColorDict");
|
UIUtil.showErrorMessage(activity, "cannotRunAndroidMarket", dictionaryInfo.Title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue