mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-07 22:47:29 +00:00
feat[anrdoid]: remove some static variables, fix java warnings
This commit is contained in:
parent
c7a660325c
commit
7b4d135c8e
8 changed files with 159 additions and 174 deletions
|
|
@ -1,6 +1,5 @@
|
|||
package com.tavultesoft.kmea;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
|
|
@ -8,14 +7,23 @@ import android.content.DialogInterface;
|
|||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.tavultesoft.kmea.data.CloudApiTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
/**
|
||||
* Confirmation dialog for downloading or deleting a Keyman keyboard/model
|
||||
*/
|
||||
public class ConfirmDialogFragment extends DialogFragment {
|
||||
public static final String ARG_DIALOG_TYPE = "ConfirmDialogFragment.dialogType";
|
||||
public static final String ARG_TITLE = "ConfirmDialogFragment.title";
|
||||
public static final String ARG_MESSAGE = "ConfirmDialogFragment.message";
|
||||
public static final String ARG_ITEM_KEY = "confirmDialogFragment.itemKey";
|
||||
private static final String ARG_DIALOG_TYPE = "ConfirmDialogFragment.dialogType";
|
||||
private static final String ARG_TITLE = "ConfirmDialogFragment.title";
|
||||
private static final String ARG_MESSAGE = "ConfirmDialogFragment.message";
|
||||
private static final String ARG_ITEM_KEY = "confirmDialogFragment.itemKey";
|
||||
private static final String ARG_DOWNLOAD_QUERIES_KEY = "confirmDialogFragment.downloadQueries";
|
||||
private static final String ARG_MODEL_ID_KEY = "confirmDialogFragment.modelId";
|
||||
private static final String ARG_LANG_ID_KEY = "confirmDialogFragment.langId";
|
||||
private static final String ARG_KB_ID_KEY = "confirmDialogFragment.kbId";
|
||||
private boolean dismissOnSelect = false;
|
||||
|
||||
public enum DialogType {
|
||||
|
|
@ -25,17 +33,36 @@ public class ConfirmDialogFragment extends DialogFragment {
|
|||
DIALOG_TYPE_DELETE_MODEL
|
||||
}
|
||||
|
||||
public static ConfirmDialogFragment newInstance(DialogType dialogType, String title, String message) {
|
||||
public static ConfirmDialogFragment newInstanceForKeyboard(DialogType dialogType, String title, String message,
|
||||
String aLangId, String aKbId,
|
||||
ArrayList<CloudApiTypes.CloudApiParam> aQueries) {
|
||||
ConfirmDialogFragment frag = new ConfirmDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(ARG_DIALOG_TYPE, dialogType);
|
||||
args.putString(ARG_TITLE, title);
|
||||
args.putString(ARG_MESSAGE, message);
|
||||
args.putString(ARG_LANG_ID_KEY, aLangId);
|
||||
args.putString(ARG_KB_ID_KEY, aKbId);
|
||||
args.putSerializable(ARG_DOWNLOAD_QUERIES_KEY,aQueries);
|
||||
frag.setArguments(args);
|
||||
return frag;
|
||||
}
|
||||
|
||||
public static ConfirmDialogFragment newInstance(DialogType dialogType, String title, String message, String itemKey) {
|
||||
public static ConfirmDialogFragment newInstanceForLexicalModel(DialogType dialogType, String title, String message,
|
||||
String aModelId,
|
||||
ArrayList<CloudApiTypes.CloudApiParam> aQueries) {
|
||||
ConfirmDialogFragment frag = new ConfirmDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(ARG_DIALOG_TYPE, dialogType);
|
||||
args.putString(ARG_TITLE, title);
|
||||
args.putString(ARG_MESSAGE, message);
|
||||
args.putString(ARG_MODEL_ID_KEY, aModelId);
|
||||
args.putSerializable(ARG_DOWNLOAD_QUERIES_KEY,aQueries);
|
||||
frag.setArguments(args);
|
||||
return frag;
|
||||
}
|
||||
|
||||
public static ConfirmDialogFragment newInstanceForItemKeyBasedAction(DialogType dialogType, String title, String message, String itemKey) {
|
||||
ConfirmDialogFragment frag = new ConfirmDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(ARG_DIALOG_TYPE, dialogType);
|
||||
|
|
@ -48,12 +75,17 @@ public class ConfirmDialogFragment extends DialogFragment {
|
|||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
Dialog dialog = super.onCreateDialog(savedInstanceState);
|
||||
super.onCreateDialog(savedInstanceState);
|
||||
|
||||
final DialogType dialogType = (DialogType)getArguments().getSerializable(ARG_DIALOG_TYPE);
|
||||
final String title = getArguments().getString(ARG_TITLE);
|
||||
final String message = getArguments().getString(ARG_MESSAGE);
|
||||
final String itemKey = getArguments().getString(ARG_ITEM_KEY);
|
||||
final String _langId = getArguments().getString(ARG_LANG_ID_KEY);
|
||||
final String _kbId = getArguments().getString(ARG_KB_ID_KEY);
|
||||
final String _modelId = getArguments().getString(ARG_MODEL_ID_KEY);
|
||||
final ArrayList<CloudApiTypes.CloudApiParam> _preparedCloudApiParams =
|
||||
(ArrayList)getArguments().getSerializable(ARG_DOWNLOAD_QUERIES_KEY);
|
||||
String positiveLabel = (dialogType == DialogType.DIALOG_TYPE_DOWNLOAD_KEYBOARD ||
|
||||
dialogType == DialogType.DIALOG_TYPE_DOWNLOAD_MODEL) ?
|
||||
getString(R.string.label_download) : getString(R.string.label_delete);
|
||||
|
|
@ -66,9 +98,11 @@ public class ConfirmDialogFragment extends DialogFragment {
|
|||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (dialogType) {
|
||||
case DIALOG_TYPE_DOWNLOAD_KEYBOARD :
|
||||
|
||||
// Confirmation to download keyboard
|
||||
if (KMManager.hasConnection(getActivity())) {
|
||||
KMKeyboardDownloaderActivity.downloadUsingDownloadManager(getActivity(), false);
|
||||
KMKeyboardDownloaderActivity.downloadKeyboardUsingDownloadManager(
|
||||
getActivity(), _langId, _kbId,_preparedCloudApiParams);
|
||||
} else {
|
||||
Toast.makeText(getActivity(), "No internet connection", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
|
@ -82,7 +116,8 @@ public class ConfirmDialogFragment extends DialogFragment {
|
|||
case DIALOG_TYPE_DOWNLOAD_MODEL :
|
||||
// Confirmation to download lexical model
|
||||
if (KMManager.hasConnection(getActivity())) {
|
||||
KMKeyboardDownloaderActivity.downloadUsingDownloadManager(getActivity(), true);
|
||||
KMKeyboardDownloaderActivity.downloadLexicalModelUsingDownloadManager(getActivity(),
|
||||
_modelId, _preparedCloudApiParams);
|
||||
} else {
|
||||
Toast.makeText(getActivity(), "No internet connection", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,23 +60,24 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
public static final String KMKey_KeyboardBaseURI = "keyboardBaseUri";
|
||||
public static final String KMKey_FontBaseURI = "fontBaseUri";
|
||||
|
||||
//TODO: use keyboard model class, should not be static
|
||||
private static String pkgID;
|
||||
private static String kbID;
|
||||
private static String langID;
|
||||
private static String modelID;
|
||||
private static String modelName;
|
||||
private static String kbName;
|
||||
private static String langName;
|
||||
private static Boolean isCustom;
|
||||
private static Boolean downloadOnlyLexicalModel;
|
||||
//TODO: use keyboard model class
|
||||
private String pkgID;
|
||||
private String kbID;
|
||||
private String langID;
|
||||
private String modelID;
|
||||
private String modelName;
|
||||
private String kbName;
|
||||
private String langName;
|
||||
private Boolean isCustom;
|
||||
private Boolean downloadOnlyLexicalModel;
|
||||
|
||||
private static String customKeyboard;
|
||||
private static String customLanguage;
|
||||
private static Boolean isDirect;
|
||||
private static String url;
|
||||
private static String filename;
|
||||
private String customKeyboard;
|
||||
private String customLanguage;
|
||||
private Boolean isDirect;
|
||||
private String url;
|
||||
private String filename;
|
||||
|
||||
//TODO: move to keyboard manager class
|
||||
private static ArrayList<KeyboardEventHandler.OnKeyboardDownloadEventListener> kbDownloadEventListeners = null;
|
||||
|
||||
@Override
|
||||
|
|
@ -119,7 +120,7 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
String title = "";
|
||||
String title;
|
||||
if (url != null) {
|
||||
title = String.format("%s: %s", getString(R.string.custom_keyboard), filename);
|
||||
} else if (customKeyboard != null && customLanguage != null &&
|
||||
|
|
@ -141,52 +142,47 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
DialogFragment dialog;
|
||||
if (downloadOnlyLexicalModel) {
|
||||
title = String.format("%s: %s", langName, modelName);
|
||||
dialog = ConfirmDialogFragment.newInstance(
|
||||
DIALOG_TYPE_DOWNLOAD_MODEL, title, getString(R.string.confirm_download_model));
|
||||
dialog = ConfirmDialogFragment.newInstanceForLexicalModel(
|
||||
DIALOG_TYPE_DOWNLOAD_MODEL, title, getString(R.string.confirm_download_model),
|
||||
modelID,
|
||||
prepareCloudApiParamsForLexicalModelDownload());
|
||||
} else {
|
||||
dialog = ConfirmDialogFragment.newInstance(
|
||||
DIALOG_TYPE_DOWNLOAD_KEYBOARD, title, getString(R.string.confirm_download_keyboard));
|
||||
dialog = ConfirmDialogFragment.newInstanceForKeyboard(
|
||||
DIALOG_TYPE_DOWNLOAD_KEYBOARD, title, getString(R.string.confirm_download_keyboard),
|
||||
langID, kbID,
|
||||
prepareCloudApiParamsForKeyboardDownload());
|
||||
}
|
||||
|
||||
dialog.show(getFragmentManager(), "dialog");
|
||||
}
|
||||
|
||||
/**
|
||||
* Download in keyboards and lexical model using download manager.
|
||||
* @param context the context
|
||||
* @param aDownloadOnlyLexicalModel is lexical model download
|
||||
* prepare cloud api params for lexical models download.
|
||||
* @return the result
|
||||
*/
|
||||
public static void downloadUsingDownloadManager(final Context context,
|
||||
final boolean aDownloadOnlyLexicalModel)
|
||||
{
|
||||
if(aDownloadOnlyLexicalModel)
|
||||
{
|
||||
downloadLexicalModelUsingDownloadManager(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
downloadKeyboardUsingDownloadManager(context);
|
||||
}
|
||||
private ArrayList<CloudApiTypes.CloudApiParam> prepareCloudApiParamsForLexicalModelDownload() {
|
||||
ArrayList<CloudApiTypes.CloudApiParam> _params = new ArrayList<>();
|
||||
_params.add(new CloudApiTypes.CloudApiParam(
|
||||
CloudApiTypes.ApiTarget.LexicalModelPackage, url));
|
||||
return _params;
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare and execute keyboard download using downloadmanager.
|
||||
* @param context the context
|
||||
* @param aLangId the language id
|
||||
* @param aKbId the keyman keyboard id
|
||||
* @param aPreparedCloudApiParams the prepared api params
|
||||
*/
|
||||
private static void downloadKeyboardUsingDownloadManager(Context context)
|
||||
public static void downloadKeyboardUsingDownloadManager(Context context,
|
||||
String aLangId, String aKbId,
|
||||
List<CloudApiTypes.CloudApiParam> aPreparedCloudApiParams)
|
||||
{
|
||||
if (pkgID == null || pkgID.trim().isEmpty() ||
|
||||
(!isCustom && (langID == null || langID.trim().isEmpty() || kbID == null || kbID.trim().isEmpty()))) {
|
||||
throw new IllegalStateException("Invalid keyboard");
|
||||
}
|
||||
|
||||
List<CloudApiTypes.CloudApiParam> cloudQueries = getPrepareCloudQueriesForKeyboardDownload(context);
|
||||
|
||||
String _downloadid= CloudKeyboardMetaDataDownloadCallback.createDownloadId(langID , kbID);
|
||||
String _downloadid= CloudKeyboardMetaDataDownloadCallback.createDownloadId(aLangId , aKbId);
|
||||
|
||||
if( CloudDownloadMgr.getInstance().alreadyDownloadingData(_downloadid)
|
||||
|| CloudDownloadMgr.getInstance().alreadyDownloadingData(
|
||||
CloudKeyboardDataDownloadCallback.createDownloadId(kbID)))
|
||||
CloudKeyboardDataDownloadCallback.createDownloadId(aKbId)))
|
||||
{
|
||||
Toast.makeText(context,
|
||||
context.getString(R.string.keyboard_download_is_running_in_background),
|
||||
|
|
@ -195,7 +191,6 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
else
|
||||
{
|
||||
CloudKeyboardMetaDataDownloadCallback _callback = new CloudKeyboardMetaDataDownloadCallback();
|
||||
_callback.setDownloadEventListeners(kbDownloadEventListeners);
|
||||
|
||||
Toast.makeText(context,
|
||||
context.getString(R.string.keyboard_download_start_in_background),
|
||||
|
|
@ -203,22 +198,26 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
|
||||
CloudDownloadMgr.getInstance().executeAsDownload(
|
||||
context, _downloadid, null, _callback,
|
||||
cloudQueries.toArray(new CloudApiTypes.CloudApiParam[0]));
|
||||
aPreparedCloudApiParams.toArray(new CloudApiTypes.CloudApiParam[0]));
|
||||
}
|
||||
|
||||
((AppCompatActivity) context).finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the cloud queries for keyboard metadata download.
|
||||
* @param context the context
|
||||
* Prepare the cloud api params for keyboard metadata download.
|
||||
* @return the result
|
||||
*/
|
||||
private static List<CloudApiTypes.CloudApiParam> getPrepareCloudQueriesForKeyboardDownload(Context context)
|
||||
private ArrayList<CloudApiTypes.CloudApiParam> prepareCloudApiParamsForKeyboardDownload()
|
||||
{
|
||||
List<CloudApiTypes.CloudApiParam> cloudQueries = new ArrayList<>();
|
||||
if (pkgID == null || pkgID.trim().isEmpty() ||
|
||||
(!isCustom && (langID == null || langID.trim().isEmpty() || kbID == null || kbID.trim().isEmpty()))) {
|
||||
throw new IllegalStateException("Invalid keyboard");
|
||||
}
|
||||
|
||||
String deviceType = CloudDataJsonUtil.getDeviceTypeForCloudQuery(context);
|
||||
ArrayList<CloudApiTypes.CloudApiParam> cloudQueries = new ArrayList<>();
|
||||
|
||||
String deviceType = CloudDataJsonUtil.getDeviceTypeForCloudQuery(this);
|
||||
|
||||
if (isCustom) {
|
||||
//TODO: will end up in an exception during download???
|
||||
|
|
@ -249,11 +248,15 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
/**
|
||||
* prepare and execute lexical model download using downloadmanager.
|
||||
* @param context the context
|
||||
* @param aModelId the lexical model id
|
||||
* @param aPreparedCloudApiParams the prepared api params
|
||||
*/
|
||||
private static void downloadLexicalModelUsingDownloadManager(Context context) {
|
||||
public static void downloadLexicalModelUsingDownloadManager(Context context,
|
||||
String aModelId,
|
||||
List<CloudApiTypes.CloudApiParam> aPreparedCloudApiParams) {
|
||||
|
||||
|
||||
String _downloadid= CloudLexicalPackageDownloadCallback.createDownloadId(modelID);
|
||||
String _downloadid= CloudLexicalPackageDownloadCallback.createDownloadId(aModelId);
|
||||
|
||||
if( CloudDownloadMgr.getInstance().alreadyDownloadingData(_downloadid))
|
||||
{
|
||||
|
|
@ -264,17 +267,14 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
else
|
||||
{
|
||||
CloudLexicalPackageDownloadCallback _callback = new CloudLexicalPackageDownloadCallback();
|
||||
_callback.setDownloadEventListeners(kbDownloadEventListeners);
|
||||
|
||||
CloudApiTypes.CloudApiParam _param = new CloudApiTypes.CloudApiParam(
|
||||
CloudApiTypes.ApiTarget.LexicalModelPackage, url);
|
||||
|
||||
Toast.makeText(context,
|
||||
context.getString(R.string.dictionary_download_start_in_background),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
|
||||
CloudDownloadMgr.getInstance().executeAsDownload(
|
||||
context, _downloadid, null, _callback, _param);
|
||||
context, _downloadid, null, _callback,
|
||||
aPreparedCloudApiParams.toArray(new CloudApiTypes.CloudApiParam[0]));
|
||||
}
|
||||
|
||||
((AppCompatActivity) context).finish();
|
||||
|
|
@ -294,7 +294,7 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
|
||||
public static void addKeyboardDownloadEventListener(KeyboardEventHandler.OnKeyboardDownloadEventListener listener) {
|
||||
if (kbDownloadEventListeners == null) {
|
||||
kbDownloadEventListeners = new ArrayList<KeyboardEventHandler.OnKeyboardDownloadEventListener>();
|
||||
kbDownloadEventListeners = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (listener != null && !kbDownloadEventListeners.contains(listener)) {
|
||||
|
|
@ -307,4 +307,8 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
kbDownloadEventListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<KeyboardEventHandler.OnKeyboardDownloadEventListener> getKbDownloadEventListeners() {
|
||||
return kbDownloadEventListeners;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,17 @@
|
|||
/**
|
||||
/*
|
||||
* Copyright (C) 2019 SIL International. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.tavultesoft.kmea;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import android.app.DialogFragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
|
|
@ -39,14 +36,11 @@ import static com.tavultesoft.kmea.ConfirmDialogFragment.DialogType.DIALOG_TYPE_
|
|||
// Public access is necessary to avoid IllegalAccessException
|
||||
public final class KeyboardSettingsActivity extends AppCompatActivity {
|
||||
|
||||
private static Toolbar toolbar = null;
|
||||
private static ListView listView = null;
|
||||
private DialogFragment dialog;
|
||||
private static ArrayList<HashMap<String, String>> infoList = null;
|
||||
protected static Typeface titleFont = null;
|
||||
private final String titleKey = "title";
|
||||
private final String subtitleKey = "subtitle";
|
||||
private final String iconKey = "icon";
|
||||
private static Typeface titleFont = null;
|
||||
private static final String titleKey = "title";
|
||||
private static final String subtitleKey = "subtitle";
|
||||
private static final String iconKey = "icon";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -56,13 +50,13 @@ public final class KeyboardSettingsActivity extends AppCompatActivity {
|
|||
final String authority = FileProviderUtils.getAuthority(context);
|
||||
|
||||
setContentView(R.layout.activity_list_layout);
|
||||
toolbar = (Toolbar) findViewById(R.id.list_toolbar);
|
||||
final Toolbar toolbar = findViewById(R.id.list_toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||
|
||||
listView = (ListView) findViewById(R.id.listView);
|
||||
final ListView listView = findViewById(R.id.listView);
|
||||
|
||||
final String packageID = getIntent().getStringExtra(KMManager.KMKey_PackageID);
|
||||
final String languageID = getIntent().getStringExtra(KMManager.KMKey_LanguageID);
|
||||
|
|
@ -71,22 +65,22 @@ public final class KeyboardSettingsActivity extends AppCompatActivity {
|
|||
final String kbName = getIntent().getStringExtra(KMManager.KMKey_KeyboardName);
|
||||
final String kbVersion = getIntent().getStringExtra(KMManager.KMKey_KeyboardVersion);
|
||||
|
||||
final TextView textView = (TextView) findViewById(R.id.bar_title);
|
||||
final TextView textView = findViewById(R.id.bar_title);
|
||||
textView.setText(kbName);
|
||||
if (titleFont != null)
|
||||
textView.setTypeface(titleFont, Typeface.BOLD);
|
||||
|
||||
infoList = new ArrayList<HashMap<String, String>>();
|
||||
infoList = new ArrayList<>();
|
||||
// Display keyboard version title
|
||||
final String noIcon = "0";
|
||||
HashMap<String, String> hashMap = new HashMap<String, String>();
|
||||
HashMap<String, String> hashMap = new HashMap<>();
|
||||
hashMap.put(titleKey, getString(R.string.keyboard_version));
|
||||
hashMap.put(subtitleKey, kbVersion);
|
||||
hashMap.put(iconKey, noIcon);
|
||||
infoList.add(hashMap);
|
||||
|
||||
// Display keyboard help link
|
||||
hashMap = new HashMap<String, String>();
|
||||
hashMap = new HashMap<>();
|
||||
final String helpUrlStr = getIntent().getStringExtra(KMManager.KMKey_HelpLink);
|
||||
final String customHelpLink = getIntent().getStringExtra(KMManager.KMKey_CustomHelpLink);
|
||||
// Check if app declared FileProvider
|
||||
|
|
@ -104,7 +98,7 @@ public final class KeyboardSettingsActivity extends AppCompatActivity {
|
|||
// Display uninstall keyboard
|
||||
if (!packageID.equalsIgnoreCase(KMManager.KMDefault_UndefinedPackageID) ||
|
||||
!kbID.equalsIgnoreCase(KMManager.KMDefault_KeyboardID)) {
|
||||
hashMap = new HashMap<String, String>();
|
||||
hashMap = new HashMap<>();
|
||||
hashMap.put(titleKey, getString(R.string.uninstall_keyboard));
|
||||
hashMap.put(subtitleKey, "");
|
||||
hashMap.put(iconKey, noIcon);
|
||||
|
|
@ -117,7 +111,7 @@ public final class KeyboardSettingsActivity extends AppCompatActivity {
|
|||
ListAdapter adapter = new SimpleAdapter(context, infoList, R.layout.list_row_layout2, from, to) {
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
HashMap<String, String> hashMap = (HashMap<String, String>)infoList.get(position);
|
||||
HashMap<String, String> hashMap = infoList.get(position);
|
||||
String itemTitle = MapCompat.getOrDefault(hashMap, titleKey, "");
|
||||
String icon = MapCompat.getOrDefault(hashMap, iconKey, noIcon);
|
||||
if (itemTitle.equals(getString(R.string.keyboard_version))) {
|
||||
|
|
@ -173,7 +167,7 @@ public final class KeyboardSettingsActivity extends AppCompatActivity {
|
|||
// Uninstall selected keyboard
|
||||
String title = String.format("%s: %s", languageName, kbName);
|
||||
String keyboardKey = String.format("%s_%s", languageID, kbID);
|
||||
DialogFragment dialog = ConfirmDialogFragment.newInstance(
|
||||
DialogFragment dialog = ConfirmDialogFragment.newInstanceForItemKeyBasedAction(
|
||||
DIALOG_TYPE_DELETE_KEYBOARD, title, getString(R.string.confirm_delete_keyboard), keyboardKey);
|
||||
dialog.show(getFragmentManager(), "dialog");
|
||||
}
|
||||
|
|
@ -190,9 +184,7 @@ public final class KeyboardSettingsActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public void onDestroy(){
|
||||
super.onDestroy();
|
||||
if ( dialog !=null ){
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
/**
|
||||
/*
|
||||
* Copyright (C) 2017 SIL International. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.tavultesoft.kmea;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -18,14 +17,11 @@ import android.net.Uri;
|
|||
import android.os.Bundle;
|
||||
import androidx.core.content.FileProvider;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.SimpleAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
|
@ -39,10 +35,7 @@ import static com.tavultesoft.kmea.ConfirmDialogFragment.DialogType.DIALOG_TYPE_
|
|||
// Public access is necessary to avoid IllegalAccessException
|
||||
public final class ModelInfoActivity extends AppCompatActivity {
|
||||
|
||||
private static Toolbar toolbar = null;
|
||||
private static ListView listView = null;
|
||||
private static ArrayList<HashMap<String, String>> infoList = null;
|
||||
protected static Typeface titleFont = null;
|
||||
private final String titleKey = "title";
|
||||
private final String subtitleKey = "subtitle";
|
||||
private final String iconKey = "icon";
|
||||
|
|
@ -55,13 +48,13 @@ public final class ModelInfoActivity extends AppCompatActivity {
|
|||
final String authority = FileProviderUtils.getAuthority(context);
|
||||
|
||||
setContentView(R.layout.activity_list_layout);
|
||||
toolbar = (Toolbar) findViewById(R.id.list_toolbar);
|
||||
final Toolbar toolbar = findViewById(R.id.list_toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||
|
||||
listView = (ListView) findViewById(R.id.listView);
|
||||
final ListView listView = findViewById(R.id.listView);
|
||||
|
||||
final String packageID = getIntent().getStringExtra(KMManager.KMKey_PackageID);
|
||||
final String languageID = getIntent().getStringExtra(KMManager.KMKey_LanguageID);
|
||||
|
|
@ -69,23 +62,20 @@ public final class ModelInfoActivity extends AppCompatActivity {
|
|||
final String modelName = getIntent().getStringExtra(KMManager.KMKey_LexicalModelName);
|
||||
final String modelVersion = getIntent().getStringExtra(KMManager.KMKey_LexicalModelVersion);
|
||||
|
||||
final TextView textView = (TextView) findViewById(R.id.bar_title);
|
||||
final TextView textView = findViewById(R.id.bar_title);
|
||||
textView.setText(String.format(getString(R.string.model_info_header), modelName));
|
||||
if (titleFont != null)
|
||||
textView.setTypeface(titleFont, Typeface.BOLD);
|
||||
|
||||
|
||||
infoList = new ArrayList<HashMap<String, String>>();
|
||||
infoList = new ArrayList<>();
|
||||
// Display model version title
|
||||
final String noIcon = "0";
|
||||
HashMap<String, String> hashMap = new HashMap<String, String>();
|
||||
HashMap<String, String> hashMap = new HashMap<>();
|
||||
hashMap.put(titleKey, getString(R.string.model_version));
|
||||
hashMap.put(subtitleKey, modelVersion);
|
||||
hashMap.put(iconKey, noIcon);
|
||||
infoList.add(hashMap);
|
||||
|
||||
// Display model help link
|
||||
hashMap = new HashMap<String, String>();
|
||||
hashMap = new HashMap<>();
|
||||
final String customHelpLink = getIntent().getStringExtra(KMManager.KMKey_CustomHelpLink);
|
||||
// Check if app declared FileProvider
|
||||
// Currently, model help only available if custom link exists
|
||||
|
|
@ -102,7 +92,7 @@ public final class ModelInfoActivity extends AppCompatActivity {
|
|||
infoList.add(hashMap);
|
||||
|
||||
// Display link to uninstall model
|
||||
hashMap = new HashMap<String, String>();
|
||||
hashMap = new HashMap<>();
|
||||
hashMap.put(titleKey, getString(R.string.uninstall_model));
|
||||
hashMap.put(subtitleKey, "");
|
||||
hashMap.put(iconKey, noIcon);
|
||||
|
|
@ -114,7 +104,7 @@ public final class ModelInfoActivity extends AppCompatActivity {
|
|||
ListAdapter adapter = new SimpleAdapter(context, infoList, R.layout.list_row_layout2, from, to) {
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
HashMap<String, String> hashMap = (HashMap<String, String>)infoList.get(position);
|
||||
HashMap<String, String> hashMap = infoList.get(position);
|
||||
String itemTitle = MapCompat.getOrDefault(hashMap, titleKey, "");
|
||||
String icon = MapCompat.getOrDefault(hashMap, iconKey, noIcon);
|
||||
if (itemTitle.equals(getString(R.string.model_version))) {
|
||||
|
|
@ -168,7 +158,7 @@ public final class ModelInfoActivity extends AppCompatActivity {
|
|||
} else if (itemTitle.equals(getString(R.string.uninstall_model))) {
|
||||
// Uninstall selected model
|
||||
String lexicalModelKey = String.format("%s_%s_%s", packageID, languageID, modelID);
|
||||
DialogFragment dialog = ConfirmDialogFragment.newInstance(
|
||||
DialogFragment dialog = ConfirmDialogFragment.newInstanceForItemKeyBasedAction(
|
||||
DIALOG_TYPE_DELETE_MODEL, modelName, getString(R.string.confirm_delete_model), lexicalModelKey);
|
||||
dialog.show(getFragmentManager(), "dialog");
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ import org.json.JSONArray;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CloudApiTypes {
|
||||
protected static class CloudApiReturns {
|
||||
|
|
@ -69,11 +69,14 @@ public class CloudApiTypes {
|
|||
Object
|
||||
}
|
||||
|
||||
public static class CloudApiParam {
|
||||
public static class CloudApiParam implements Serializable {
|
||||
|
||||
static final long serialVersionUID = 1L;
|
||||
|
||||
public final ApiTarget target;
|
||||
public final String url;
|
||||
public JSONType type;
|
||||
private Map<String,Object> additionalProperties = new HashMap<>();
|
||||
private final HashMap<String,Serializable> additionalProperties = new HashMap<>();
|
||||
|
||||
public CloudApiParam(ApiTarget target, String url) {
|
||||
this.target = target;
|
||||
|
|
@ -84,24 +87,24 @@ public class CloudApiTypes {
|
|||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
public CloudApiParam setAdditionalProperty(String aProperty, Object aValue)
|
||||
public CloudApiParam setAdditionalProperty(String aProperty, Serializable aValue)
|
||||
{
|
||||
additionalProperties.put(aProperty,aValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> T getAdditionalProperty(String aProperty,Class<T> aType)
|
||||
public <T extends Serializable> T getAdditionalProperty(String aProperty,Class<T> aType)
|
||||
{
|
||||
return (T)additionalProperties.get(aProperty);
|
||||
return aType.cast(additionalProperties.get(aProperty));
|
||||
}
|
||||
}
|
||||
|
||||
public static class SingleCloudDownload
|
||||
{
|
||||
private DownloadManager.Request request;
|
||||
private final DownloadManager.Request request;
|
||||
private boolean downloadFinished =false;
|
||||
private long downloadId;
|
||||
private File destinationFile;
|
||||
private final File destinationFile;
|
||||
private CloudApiParam cloudParams;
|
||||
|
||||
public SingleCloudDownload(DownloadManager.Request aRequest,File aDestinationFile)
|
||||
|
|
@ -142,9 +145,9 @@ public class CloudApiTypes {
|
|||
* @param <ResultType> the result type of the download
|
||||
*/
|
||||
public static class CloudDownloadSet<ModelType,ResultType> {
|
||||
private String downloadIdentifier;
|
||||
private ModelType targetModel;
|
||||
private LinkedList<SingleCloudDownload> downloads = new LinkedList<>();
|
||||
private final String downloadIdentifier;
|
||||
private final ModelType targetModel;
|
||||
private final LinkedList<SingleCloudDownload> downloads = new LinkedList<>();
|
||||
|
||||
private ICloudDownloadCallback<ModelType,ResultType> callback;
|
||||
|
||||
|
|
@ -213,7 +216,6 @@ public class CloudApiTypes {
|
|||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,17 +4,15 @@ import android.content.Context;
|
|||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.tavultesoft.kmea.KMKeyboardDownloaderActivity;
|
||||
import com.tavultesoft.kmea.KeyboardEventHandler;
|
||||
import com.tavultesoft.kmea.R;
|
||||
import com.tavultesoft.kmea.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static com.tavultesoft.kmea.KMManager.KMDefault_UndefinedPackageID;
|
||||
|
||||
/**
|
||||
* Install keyboard data, when download is finished.
|
||||
* Could be keyboard packages or fonts.
|
||||
|
|
@ -27,7 +25,6 @@ public class CloudKeyboardDataDownloadCallback implements ICloudDownloadCallback
|
|||
|
||||
private File dataDir;
|
||||
|
||||
private ArrayList<KeyboardEventHandler.OnKeyboardDownloadEventListener> downloadEventListeners = new ArrayList<>();
|
||||
private HashMap<String,String> keyboardInfo;
|
||||
|
||||
/**
|
||||
|
|
@ -44,16 +41,6 @@ public class CloudKeyboardDataDownloadCallback implements ICloudDownloadCallback
|
|||
*/
|
||||
public static final String PARAM_PACKAGE = "package";
|
||||
|
||||
/**
|
||||
* listeners to inform after installation is completed.
|
||||
* @param aDownloadEventListeners the listeners
|
||||
*/
|
||||
public void setDownloadEventListeners(ArrayList<KeyboardEventHandler.OnKeyboardDownloadEventListener> aDownloadEventListeners)
|
||||
{
|
||||
downloadEventListeners.clear();
|
||||
downloadEventListeners.addAll(aDownloadEventListeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Keyboard meta data.
|
||||
* @param aKeyboardInfo the keyboard
|
||||
|
|
@ -121,7 +108,8 @@ public class CloudKeyboardDataDownloadCallback implements ICloudDownloadCallback
|
|||
|
||||
if(keyboardInfo!=null)
|
||||
{
|
||||
KeyboardEventHandler.notifyListeners(downloadEventListeners, KeyboardEventHandler.EventType.KEYBOARD_DOWNLOAD_FINISHED,
|
||||
KeyboardEventHandler.notifyListeners(KMKeyboardDownloaderActivity.getKbDownloadEventListeners(),
|
||||
KeyboardEventHandler.EventType.KEYBOARD_DOWNLOAD_FINISHED,
|
||||
keyboardInfo, aCloudResult.kbdResult);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class CloudKeyboardMetaDataDownloadCallback implements ICloudDownloadCall
|
|||
/**
|
||||
* the metadata result and all necessary downloads which should be started.
|
||||
*/
|
||||
public static class MetaDataResult
|
||||
static class MetaDataResult
|
||||
{
|
||||
CloudApiTypes.CloudApiReturns returnjson;
|
||||
CloudApiTypes.CloudApiParam params;
|
||||
|
|
@ -38,8 +38,6 @@ public class CloudKeyboardMetaDataDownloadCallback implements ICloudDownloadCall
|
|||
|
||||
private static final String TAG = "CloudKeyboardMetaDldCb";
|
||||
|
||||
private ArrayList<KeyboardEventHandler.OnKeyboardDownloadEventListener> downloadEventListeners = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Additional Cloud API parameter: Is custom keyboard.
|
||||
*/
|
||||
|
|
@ -53,14 +51,7 @@ public class CloudKeyboardMetaDataDownloadCallback implements ICloudDownloadCall
|
|||
*/
|
||||
public static final String PARAM_KB_ID = "kb_id";
|
||||
|
||||
/**
|
||||
* Listeners to notify about starting the data download.
|
||||
* @param aDownloadEventListeners
|
||||
*/
|
||||
public void setDownloadEventListeners(ArrayList<KeyboardEventHandler.OnKeyboardDownloadEventListener> aDownloadEventListeners) {
|
||||
downloadEventListeners.clear();
|
||||
downloadEventListeners.addAll(aDownloadEventListeners);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initializeContext(Context context) {
|
||||
|
|
@ -118,7 +109,6 @@ public class CloudKeyboardMetaDataDownloadCallback implements ICloudDownloadCall
|
|||
if(_r.returnjson.target== CloudApiTypes.ApiTarget.Keyboard)
|
||||
{
|
||||
CloudKeyboardDataDownloadCallback _callback = new CloudKeyboardDataDownloadCallback();
|
||||
_callback.setDownloadEventListeners(downloadEventListeners);
|
||||
_callback.setKeyboardInfo(_r.keyboardInfo);
|
||||
|
||||
if( CloudDownloadMgr.getInstance().alreadyDownloadingData(_r.additionalDownloadid))
|
||||
|
|
@ -126,7 +116,8 @@ public class CloudKeyboardMetaDataDownloadCallback implements ICloudDownloadCall
|
|||
continue;
|
||||
}
|
||||
|
||||
KeyboardEventHandler.notifyListeners(downloadEventListeners,
|
||||
KeyboardEventHandler.notifyListeners(
|
||||
KMKeyboardDownloaderActivity.getKbDownloadEventListeners(),
|
||||
KeyboardEventHandler.EventType.KEYBOARD_DOWNLOAD_STARTED, _r.keyboardInfo, 0);
|
||||
|
||||
CloudDownloadMgr.getInstance().executeAsDownload(aContext, _r.additionalDownloadid, null, _callback,
|
||||
|
|
@ -142,7 +133,6 @@ public class CloudKeyboardMetaDataDownloadCallback implements ICloudDownloadCall
|
|||
continue;
|
||||
}
|
||||
CloudLexicalPackageDownloadCallback _callback = new CloudLexicalPackageDownloadCallback();
|
||||
_callback.setDownloadEventListeners(downloadEventListeners);
|
||||
|
||||
Toast.makeText(aContext,
|
||||
aContext.getString(R.string.dictionary_download_start_in_background),
|
||||
|
|
@ -266,11 +256,11 @@ public class CloudKeyboardMetaDataDownloadCallback implements ICloudDownloadCall
|
|||
}
|
||||
if (oskFontUrls != null) {
|
||||
for (String url : oskFontUrls) {
|
||||
if (!urls.contains(url))
|
||||
if (fontUrls==null || ! fontUrls.contains(url))
|
||||
urls.add(new CloudApiTypes.CloudApiParam(CloudApiTypes.ApiTarget.KeyboardData, url)
|
||||
.setAdditionalProperty(
|
||||
CloudKeyboardDataDownloadCallback.PARAM_PACKAGE, _pkgID));
|
||||
;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import android.content.Context;
|
|||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.tavultesoft.kmea.KMKeyboardDownloaderActivity;
|
||||
import com.tavultesoft.kmea.KeyboardEventHandler;
|
||||
import com.tavultesoft.kmea.R;
|
||||
import com.tavultesoft.kmea.packages.LexicalModelPackageProcessor;
|
||||
|
|
@ -16,14 +15,10 @@ import org.json.JSONException;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.tavultesoft.kmea.KMManager.KMDefault_UndefinedPackageID;
|
||||
|
||||
/**
|
||||
* Install lexical model.
|
||||
*/
|
||||
|
|
@ -36,18 +31,6 @@ public class CloudLexicalPackageDownloadCallback implements ICloudDownloadCallba
|
|||
private File resourceRoot;
|
||||
private File cacheDir;
|
||||
|
||||
private ArrayList<KeyboardEventHandler.OnKeyboardDownloadEventListener> downloadEventListeners = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* listeners to inform after installation is completed.
|
||||
* @param aDownloadEventListeners the listeners
|
||||
*/
|
||||
public void setDownloadEventListeners(ArrayList<KeyboardEventHandler.OnKeyboardDownloadEventListener> aDownloadEventListeners)
|
||||
{
|
||||
downloadEventListeners.clear();
|
||||
downloadEventListeners.addAll(aDownloadEventListeners);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeContext(Context context)
|
||||
{
|
||||
|
|
@ -108,7 +91,8 @@ public class CloudLexicalPackageDownloadCallback implements ICloudDownloadCallba
|
|||
|
||||
if(aCloudResult.installedLexicalModels != null)
|
||||
{
|
||||
KeyboardEventHandler.notifyListeners(downloadEventListeners, KeyboardEventHandler.EventType.LEXICAL_MODEL_INSTALLED,
|
||||
KeyboardEventHandler.notifyListeners(KMKeyboardDownloaderActivity.getKbDownloadEventListeners(),
|
||||
KeyboardEventHandler.EventType.LEXICAL_MODEL_INSTALLED,
|
||||
aCloudResult.installedLexicalModels, aCloudResult.kbdResult);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue