mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-22 07:37:40 +00:00
docs: comments for better understanding
This commit is contained in:
parent
a84332b240
commit
72bf489774
7 changed files with 173 additions and 51 deletions
|
|
@ -169,6 +169,7 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
* Used by the <code>download</code> method to handle asynchronous downloading and evaluation of
|
||||
* packages and keyboards.
|
||||
*/
|
||||
@Deprecated
|
||||
static class DownloadTask extends AsyncTask<Void, Integer, DownloadTask.Result> {
|
||||
static class Result {
|
||||
public final Integer kbdResult;
|
||||
|
|
@ -539,7 +540,12 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
new DownloadTask(context, showProgressDialog, aDownloadOnlyLexicalModel).execute();
|
||||
}
|
||||
|
||||
public static void downloadUsingDownloadManager(final Context context,
|
||||
/**
|
||||
* Download in keyboards and lexical model using download manager.
|
||||
* @param context the context
|
||||
* @param aDownloadOnlyLexicalModel is lexical model download
|
||||
*/
|
||||
private static void downloadUsingDownloadManager(final Context context,
|
||||
final boolean aDownloadOnlyLexicalModel)
|
||||
{
|
||||
if(aDownloadOnlyLexicalModel)
|
||||
|
|
@ -552,19 +558,59 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private static void downloadKeyboardUsingDownloadManager(Context context) {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* prepare and execute keyboard download using downloadmanager.
|
||||
* @param context the context
|
||||
*/
|
||||
private static void downloadKeyboardUsingDownloadManager(Context context)
|
||||
{
|
||||
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);
|
||||
|
||||
|
||||
List<CloudApiTypes.CloudApiParam> cloudQueries = getPrepareCloudQueriesForKeyboardDownload(context);
|
||||
|
||||
String _downloadid= CloudKeyboardMetaDataDownloadCallback.createDownloadId(langID , kbID);
|
||||
|
||||
if( CloudDownloadMgr.getInstance().alreadyDownloadingData(_downloadid)
|
||||
|| CloudDownloadMgr.getInstance().alreadyDownloadingData(
|
||||
CloudKeyboardDataDownloadCallback.createDownloadId(kbID)))
|
||||
{
|
||||
Toast.makeText(context,
|
||||
context.getString(R.string.keyboard_download_is_running_in_background),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else
|
||||
{
|
||||
CloudKeyboardMetaDataDownloadCallback _callback = new CloudKeyboardMetaDataDownloadCallback();
|
||||
_callback.setDownloadEventListeners(kbDownloadEventListeners);
|
||||
|
||||
Toast.makeText(context,
|
||||
context.getString(R.string.keyboard_download_start_in_background),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
|
||||
CloudDownloadMgr.getInstance().executeAsDownload(
|
||||
context, _downloadid, null, _callback,
|
||||
cloudQueries.toArray(new CloudApiTypes.CloudApiParam[0]));
|
||||
}
|
||||
|
||||
((AppCompatActivity) context).finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the cloud queries for keyboard metadata download.
|
||||
* @param context the context
|
||||
* @return the result
|
||||
*/
|
||||
private static List<CloudApiTypes.CloudApiParam> getPrepareCloudQueriesForKeyboardDownload(Context context)
|
||||
{
|
||||
List<CloudApiTypes.CloudApiParam> cloudQueries = new ArrayList<>();
|
||||
|
||||
String deviceType = CloudDataJsonUtil.getDeviceTypeForCloudQuery(context);
|
||||
|
||||
if (isCustom) {
|
||||
//TODO: will end up in an exception during download???
|
||||
cloudQueries.add(new CloudApiTypes.CloudApiParam(
|
||||
|
|
@ -588,34 +634,13 @@ public class KMKeyboardDownloaderActivity extends AppCompatActivity {
|
|||
CloudApiTypes.ApiTarget.KeyBoardLexicalModels, _remoteLexicalModelUrl)
|
||||
.setType(CloudApiTypes.JSONType.Array));
|
||||
}
|
||||
|
||||
String _downloadid= "metadata_" + langID + "_" + kbID;
|
||||
|
||||
if( CloudDownloadMgr.getInstance().alreadyDownloadingData(_downloadid)
|
||||
|| CloudDownloadMgr.getInstance().alreadyDownloadingData(
|
||||
CloudKeyboardDataDownloadCallback.createDownloadId(kbID)))
|
||||
{
|
||||
Toast.makeText(context,
|
||||
context.getString(R.string.keyboard_download_is_running_in_background),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else
|
||||
{
|
||||
CloudKeyboardMetaDataDownloadCallback _callback = new CloudKeyboardMetaDataDownloadCallback();
|
||||
_callback.setDownloadEventListeners(kbDownloadEventListeners);
|
||||
|
||||
Toast.makeText(context,
|
||||
context.getString(R.string.keyboard_download_start_in_background),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
|
||||
CloudDownloadMgr.getInstance().executeAsDownload(
|
||||
context, _downloadid, null, _callback,
|
||||
cloudQueries.toArray(new CloudApiTypes.CloudApiParam[0]));
|
||||
}
|
||||
|
||||
((AppCompatActivity) context).finish();
|
||||
return cloudQueries;
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare and execute lexical model download using downloadmanager.
|
||||
* @param context the context
|
||||
*/
|
||||
private static void downloadLexicalModelUsingDownloadManager(Context context) {
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -237,6 +237,11 @@ public class CloudDataJsonUtil {
|
|||
return new File(context.getCacheDir(), jsonLexicalCacheFilename);
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve a json object from a downloaded file.
|
||||
* @param aDownload the download
|
||||
* @return the result
|
||||
*/
|
||||
public static CloudApiTypes.CloudApiReturns retrieveJsonFromDownload( CloudApiTypes.SingleCloudDownload aDownload)
|
||||
{
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
|
|
@ -397,6 +402,12 @@ public class CloudDataJsonUtil {
|
|||
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
/**
|
||||
* select device type for api queries.
|
||||
* @param aContext a context
|
||||
* @return the result
|
||||
*/
|
||||
public static String getDeviceTypeForCloudQuery(Context aContext)
|
||||
{
|
||||
String deviceType = aContext.getString(R.string.device_type);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@ 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.
|
||||
*/
|
||||
public class CloudKeyboardDataDownloadCallback implements ICloudDownloadCallback<
|
||||
Void, CloudKeyboardDownloadReturns>
|
||||
{
|
||||
|
|
@ -26,14 +30,34 @@ public class CloudKeyboardDataDownloadCallback implements ICloudDownloadCallback
|
|||
private ArrayList<KeyboardEventHandler.OnKeyboardDownloadEventListener> downloadEventListeners = new ArrayList<>();
|
||||
private HashMap<String,String> keyboardInfo;
|
||||
|
||||
/**
|
||||
* Additional Cloud API parameter:
|
||||
* Parameter to force a special destination file name during installation.
|
||||
* Default name is the file name of the url.
|
||||
*/
|
||||
public static final String PARAM_DESTINATION_FILE_NAME = "destination_file_name";
|
||||
|
||||
/**
|
||||
* Additional Cloud API parameter:
|
||||
* Parameter to force a special destination file name during installation.
|
||||
* Default name is the file name of the url.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public void setKeyboardInfo(HashMap<String, String> aKeyboardInfo) {
|
||||
this.keyboardInfo = aKeyboardInfo;
|
||||
}
|
||||
|
|
@ -56,8 +80,9 @@ public class CloudKeyboardDataDownloadCallback implements ICloudDownloadCallback
|
|||
|
||||
try {
|
||||
|
||||
String _pkg = _d.getCloudParams().getAdditionalProperty(PARAM_PACKAGE,String.class);
|
||||
String destination = dataDir.toString() +
|
||||
File.separator + KMDefault_UndefinedPackageID + File.separator;
|
||||
File.separator + _pkg + File.separator;
|
||||
|
||||
String _filename = _d.getCloudParams().getAdditionalProperty(PARAM_DESTINATION_FILE_NAME,String.class);
|
||||
if (_filename==null) {
|
||||
|
|
@ -99,11 +124,13 @@ public class CloudKeyboardDataDownloadCallback implements ICloudDownloadCallback
|
|||
KeyboardEventHandler.notifyListeners(downloadEventListeners, KeyboardEventHandler.EventType.KEYBOARD_DOWNLOAD_FINISHED,
|
||||
keyboardInfo, aCloudResult.kbdResult);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* create a download id for the keyboard data.
|
||||
* @param aKeyboardId the keyboard id
|
||||
* @return the result
|
||||
*/
|
||||
public static String createDownloadId(String aKeyboardId)
|
||||
{
|
||||
return "keyboarddata_" + aKeyboardId;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ package com.tavultesoft.kmea.data;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* key board and lexical model download result.
|
||||
*/
|
||||
public class CloudKeyboardDownloadReturns {
|
||||
public final Integer kbdResult;
|
||||
public final List<Map<String, String>> installedLexicalModels;
|
||||
|
|
|
|||
|
|
@ -18,9 +18,15 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Start the keyboard download when keyboard metadata is downloaded.
|
||||
*/
|
||||
public class CloudKeyboardMetaDataDownloadCallback implements ICloudDownloadCallback<Void,
|
||||
List<CloudKeyboardMetaDataDownloadCallback.MetaDataResult>>
|
||||
{
|
||||
/**
|
||||
* the metadata result and all necessary downloads which should be started.
|
||||
*/
|
||||
public static class MetaDataResult
|
||||
{
|
||||
CloudApiTypes.CloudApiReturns returnjson;
|
||||
|
|
@ -32,14 +38,25 @@ public class CloudKeyboardMetaDataDownloadCallback implements ICloudDownloadCall
|
|||
|
||||
private static final String TAG = "CloudKeyboardMetaDldCb";
|
||||
|
||||
private static ArrayList<KeyboardEventHandler.OnKeyboardDownloadEventListener> downloadEventListeners = new ArrayList<>();
|
||||
|
||||
private ArrayList<KeyboardEventHandler.OnKeyboardDownloadEventListener> downloadEventListeners = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Additional Cloud API parameter: Is custom keyboard.
|
||||
*/
|
||||
public static final String PARAM_IS_CUSTOM = "is_custom";
|
||||
/**
|
||||
* Additional Cloud API parameter: language id.
|
||||
*/
|
||||
public static final String PARAM_LANG_ID = "lang_id";
|
||||
/**
|
||||
* Additional Cloud API parameter: keyboard id.
|
||||
*/
|
||||
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);
|
||||
|
|
@ -88,8 +105,13 @@ public class CloudKeyboardMetaDataDownloadCallback implements ICloudDownloadCall
|
|||
startDownloads(aContext, aCloudResult);
|
||||
}
|
||||
|
||||
private void startDownloads(Context aContext, List<MetaDataResult> aCloudResult) {
|
||||
for(MetaDataResult _r:aCloudResult)
|
||||
/**
|
||||
* Start the keyboard data and lexical model download.
|
||||
* @param aContext the context
|
||||
* @param aMetaDataResult the meta data result
|
||||
*/
|
||||
private void startDownloads(Context aContext, List<MetaDataResult> aMetaDataResult) {
|
||||
for(MetaDataResult _r:aMetaDataResult)
|
||||
{
|
||||
if(_r.additionalDownloads!=null)
|
||||
{
|
||||
|
|
@ -134,8 +156,12 @@ public class CloudKeyboardMetaDataDownloadCallback implements ICloudDownloadCall
|
|||
}
|
||||
}
|
||||
|
||||
private void processCloudResults(List<MetaDataResult> aCloudResult) {
|
||||
for(MetaDataResult _r:aCloudResult)
|
||||
/**
|
||||
* process the meta data result and prepare the additional downloads.
|
||||
* @param aMetaDataResult the meta data results
|
||||
*/
|
||||
private void processCloudResults(List<MetaDataResult> aMetaDataResult) {
|
||||
for(MetaDataResult _r:aMetaDataResult)
|
||||
{
|
||||
if(_r.returnjson.target== CloudApiTypes.ApiTarget.Keyboard)
|
||||
{
|
||||
|
|
@ -229,13 +255,17 @@ public class CloudKeyboardMetaDataDownloadCallback implements ICloudDownloadCall
|
|||
ArrayList<String> oskFontUrls = CloudDataJsonUtil.fontUrls(jsonOskFont, fontBaseUri, true);
|
||||
if (fontUrls != null) {
|
||||
for (String url : fontUrls) {
|
||||
urls.add(new CloudApiTypes.CloudApiParam(CloudApiTypes.ApiTarget.KeyboardData, url));
|
||||
urls.add(new CloudApiTypes.CloudApiParam(CloudApiTypes.ApiTarget.KeyboardData, url)
|
||||
.setAdditionalProperty(
|
||||
CloudKeyboardDataDownloadCallback.PARAM_PACKAGE, _pkgID));
|
||||
}
|
||||
}
|
||||
if (oskFontUrls != null) {
|
||||
for (String url : oskFontUrls) {
|
||||
if (!urls.contains(url))
|
||||
urls.add(new CloudApiTypes.CloudApiParam(CloudApiTypes.ApiTarget.KeyboardData, url));
|
||||
urls.add(new CloudApiTypes.CloudApiParam(CloudApiTypes.ApiTarget.KeyboardData, url)
|
||||
.setAdditionalProperty(
|
||||
CloudKeyboardDataDownloadCallback.PARAM_PACKAGE, _pkgID));
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
@ -285,13 +315,26 @@ public class CloudKeyboardMetaDataDownloadCallback implements ICloudDownloadCall
|
|||
_js_filename = _kbFilename.substring(start);
|
||||
}
|
||||
}
|
||||
|
||||
String _pkgID = aKeyboard.optString(KMManager.KMKey_PackageID, KMManager.KMDefault_UndefinedPackageID);
|
||||
String kbUrl = kbBaseUri + _kbFilename;
|
||||
|
||||
return new CloudApiTypes.CloudApiParam(CloudApiTypes.ApiTarget.KeyboardData, kbUrl)
|
||||
.setAdditionalProperty(
|
||||
CloudKeyboardDataDownloadCallback.PARAM_PACKAGE, _pkgID)
|
||||
.setAdditionalProperty(
|
||||
CloudKeyboardDataDownloadCallback.PARAM_DESTINATION_FILE_NAME, _js_filename);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* create a download id for the keyboard metadata.
|
||||
* @param aLanguageId the language id
|
||||
* @param aKeyboardId the keyboard id
|
||||
* @return the result
|
||||
*/
|
||||
public static String createDownloadId(String aLanguageId, String aKeyboardId)
|
||||
{
|
||||
return "metadata_" + aLanguageId + "_" + aKeyboardId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@ import java.util.Map;
|
|||
|
||||
import static com.tavultesoft.kmea.KMManager.KMDefault_UndefinedPackageID;
|
||||
|
||||
/**
|
||||
* Install lexical model.
|
||||
*/
|
||||
public class CloudLexicalPackageDownloadCallback implements ICloudDownloadCallback<
|
||||
Void, CloudKeyboardDownloadReturns>
|
||||
{
|
||||
|
|
@ -35,6 +38,10 @@ public class CloudLexicalPackageDownloadCallback implements ICloudDownloadCallba
|
|||
|
||||
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();
|
||||
|
|
@ -52,7 +59,6 @@ public class CloudLexicalPackageDownloadCallback implements ICloudDownloadCallba
|
|||
public CloudKeyboardDownloadReturns extractCloudResultFromDownloadSet(
|
||||
CloudApiTypes.CloudDownloadSet<Void, CloudKeyboardDownloadReturns> aDownload)
|
||||
{
|
||||
|
||||
LexicalModelPackageProcessor kmpProcessor = new LexicalModelPackageProcessor(resourceRoot);
|
||||
List<Map<String, String>> installedLexicalModels = null;
|
||||
|
||||
|
|
@ -105,12 +111,15 @@ public class CloudLexicalPackageDownloadCallback implements ICloudDownloadCallba
|
|||
KeyboardEventHandler.notifyListeners(downloadEventListeners, KeyboardEventHandler.EventType.LEXICAL_MODEL_INSTALLED,
|
||||
aCloudResult.installedLexicalModels, aCloudResult.kbdResult);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static String createDownloadId(String aModelID)
|
||||
/**
|
||||
* create a download id for the model.
|
||||
* @param aModelId the lexical model id
|
||||
* @return the result
|
||||
*/
|
||||
public static String createDownloadId(String aModelId)
|
||||
{
|
||||
return "dictionary_" + aModelID;
|
||||
return "dictionary_" + aModelId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@ import android.content.Context;
|
|||
*/
|
||||
public interface ICloudDownloadCallback<ModelType,ResultType> {
|
||||
|
||||
/**
|
||||
* Initialize callback using context.
|
||||
* @param context the context
|
||||
*/
|
||||
void initializeContext(Context context);
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue