This commit is contained in:
Yuriy Liskov
2020-01-30 00:17:42 +02:00
parent ff7676b0f9
commit 87da1e34c6
19 changed files with 145 additions and 42 deletions

View File

@@ -23,7 +23,7 @@ import android.util.SparseIntArray;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.SparseArrayCompat;
import com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.Logger;
import com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.log.Logger;
import java.lang.ref.WeakReference;
import java.util.Arrays;

View File

@@ -27,7 +27,7 @@ import android.util.AttributeSet;
import android.util.Xml;
//import com.liskovsoft.keyboardaddons.apklangfactory.AnySoftKeyboard;
import com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.Logger;
import com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.log.Logger;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

View File

@@ -5,7 +5,7 @@ import android.content.res.Resources;
import android.util.SparseIntArray;
import androidx.annotation.NonNull;
import com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.Logger;
import com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.log.Logger;
import java.util.ArrayList;
import java.util.List;

View File

@@ -27,7 +27,7 @@ import com.liskovsoft.leankeyboard.addons.KeyboardBuilder;
import com.liskovsoft.leankeyboard.addons.KeyboardFactory;
import com.liskovsoft.leankeyboard.addons.apkkbdfactory.addons.AddOn;
import com.liskovsoft.leankeyboard.addons.apkkbdfactory.addons.AddOnsFactory;
import com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.Logger;
import com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.log.Logger;
import java.util.ArrayList;
import java.util.List;

View File

@@ -1,4 +1,4 @@
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils;
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.log;
public class BuildConfig {
public final static boolean TESTING_BUILD = true;

View File

@@ -1,4 +1,4 @@
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils;
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.log;
import android.os.Build;
import android.util.Log;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils;
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.log;
public interface LogProvider {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils;
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.log;
import androidx.annotation.NonNull;

View File

@@ -1,4 +1,4 @@
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils;
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.log;
/**
* Doesn't do anything. For release.

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils;
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.xml;
import android.util.Xml;

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils;
package com.liskovsoft.leankeyboard.addons.apkkbdfactory.utils.xml;
import java.io.File;
import java.io.FileWriter;
@@ -67,8 +67,6 @@ public class XmlWriter {
/**
* Begin to output an entity.
*
* @param String name of entity.
*/
public XmlWriter writeEntity(String name) throws IOException {
closeOpeningTag(true);
@@ -202,7 +200,7 @@ public class XmlWriter {
* @param text String to do search and replace in
* @param repl String to search for
* @param with String to replace with
* @param n int values to replace
* @param max int values to replace
* @return String with n values replacEd
*/
static public String replaceString(String text, String repl, String with, int max) {

View File

@@ -3,7 +3,6 @@ package com.liskovsoft.leankeyboard.keyboard.android.leanback.ime;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
@@ -40,8 +39,8 @@ import com.liskovsoft.leankeyboard.keyboard.android.leanback.ime.voice.Recognize
import com.liskovsoft.leankeyboard.keyboard.android.leanback.ime.voice.SpeechLevelSource;
import com.liskovsoft.leankeyboard.keyboard.leanback.ime.LeanbackImeService;
import com.liskovsoft.leankeyboard.settings.settings.KbSettingsActivity;
import com.liskovsoft.leankeyboard.utils.LeanKeySettings;
import com.liskovsoft.leankeyboard.addons.KeyboardManager;
import com.liskovsoft.leankeyboard.utils.helpers.MessageHelpers;
import com.liskovsoft.leankeykeyboard.R;
import java.util.ArrayList;
@@ -502,7 +501,7 @@ public class LeanbackKeyboardContainer {
}
/**
* Speech recognizer routine
* NOTE: Speech recognizer routine
* @param context context
*/
private void startRecognition(Context context) {
@@ -520,6 +519,7 @@ public class LeanbackKeyboardContainer {
@Override
public void onBufferReceived(byte[] buffer) {
// NOP
}
@Override
@@ -531,32 +531,39 @@ public class LeanbackKeyboardContainer {
@Override
public void onError(int error) {
cancelVoiceRecording();
String errorMsg;
switch (error) {
case SpeechRecognizer.ERROR_SERVER:
Log.d("LbKbContainer", "recognizer error server error");
return;
errorMsg = "recognizer error server error";
break;
case SpeechRecognizer.ERROR_CLIENT:
Log.d("LbKbContainer", "recognizer error client error");
return;
errorMsg = "recognizer error client error";
break;
case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
Log.d("LbKbContainer", "recognizer error speech timeout");
return;
errorMsg = "recognizer error speech timeout";
break;
case SpeechRecognizer.ERROR_NO_MATCH:
Log.d("LbKbContainer", "recognizer error no match");
return;
errorMsg = "recognizer error no match";
break;
default:
Log.d("LbKbContainer", "recognizer other error " + error);
errorMsg = "recognizer other error " + error;
}
MessageHelpers.showLongMessage(mContext, errorMsg);
Log.d(TAG, errorMsg);
}
@Override
public void onEvent(int eventType, Bundle bundle) {
// NOP
}
@Override
public void onPartialResults(Bundle bundle) {
synchronized (this) {
}
// NOP
}
@Override
@@ -567,6 +574,7 @@ public class LeanbackKeyboardContainer {
@Override
public void onResults(Bundle bundle) {
List<String> results = bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if (results != null && mVoiceListener != null) {
mVoiceListener.onVoiceResult(results.get(0));
}
@@ -1135,10 +1143,9 @@ public class LeanbackKeyboardContainer {
if (mVoiceEnabled) {
if (!mVoiceKeyDismissesEnabled) {
mVoiceAnimator.startEnterAnimation();
return;
} else {
mDismissListener.onDismiss(true);
}
mDismissListener.onDismiss(true);
}
}
@@ -1380,17 +1387,18 @@ public class LeanbackKeyboardContainer {
private void start(final boolean enterVoice) {
mValueAnimator.cancel();
mValueAnimator.removeAllListeners();
ValueAnimator animation = mValueAnimator;
AnimatorListener listener;
if (enterVoice) {
listener = mEnterListener;
} else {
listener = mExitListener;
}
animation.addListener(listener);
mValueAnimator.addListener(listener);
mValueAnimator.removeAllUpdateListeners();
mValueAnimator.addUpdateListener(animation1 -> {
mValueAnimator.addUpdateListener(animation -> {
float scale = (Float) mValueAnimator.getAnimatedValue();
float calcOpacity = mAlphaIn + mAlphaOut - scale;
float opacity;
@@ -1432,14 +1440,12 @@ public class LeanbackKeyboardContainer {
if (!isVoiceVisible() && !mValueAnimator.isRunning()) {
start(true);
}
}
void startExitAnimation() {
if (isVoiceVisible() && !mValueAnimator.isRunning()) {
start(false);
}
}
}

View File

@@ -9,7 +9,7 @@ import androidx.core.content.ContextCompat;
import androidx.leanback.app.GuidedStepSupportFragment;
import androidx.leanback.widget.GuidanceStylist.Guidance;
import androidx.leanback.widget.GuidedAction;
import com.liskovsoft.leankeyboard.utils.AppInfoHelpers;
import com.liskovsoft.leankeyboard.utils.helpers.AppInfoHelpers;
import com.liskovsoft.leankeykeyboard.R;
import java.util.List;

View File

@@ -4,6 +4,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import com.liskovsoft.leankeyboard.utils.helpers.Helpers;
import com.liskovsoft.leankeyboard.utils.helpers.LocaleUtility;
import java.util.ArrayList;
import java.util.List;

View File

@@ -1,4 +1,4 @@
package com.liskovsoft.leankeyboard.utils;
package com.liskovsoft.leankeyboard.utils.helpers;
import android.app.Activity;
import android.content.ComponentName;

View File

@@ -1,4 +1,4 @@
package com.liskovsoft.leankeyboard.utils;
package com.liskovsoft.leankeyboard.utils.helpers;
import android.app.ActivityManager;
import android.content.ComponentName;
@@ -16,7 +16,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.util.Date;
@@ -89,6 +88,14 @@ public class Helpers {
return false;
}
public static String toString(Throwable ex) {
if (ex instanceof IllegalStateException &&
ex.getCause() != null) {
ex = ex.getCause();
}
return String.format("%s: %s", ex.getClass().getCanonicalName(), ex.getMessage());
}
public static String toString(InputStream inputStream) {
if (inputStream == null) {
return null;

View File

@@ -1,4 +1,4 @@
package com.liskovsoft.leankeyboard.utils;
package com.liskovsoft.leankeyboard.utils.helpers;
import java.util.HashMap;
import java.util.Locale;

View File

@@ -1,4 +1,4 @@
package com.liskovsoft.leankeyboard.utils;
package com.liskovsoft.leankeyboard.utils.helpers;
import android.content.Context;
import android.content.res.Configuration;

View File

@@ -0,0 +1,90 @@
package com.liskovsoft.leankeyboard.utils.helpers;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;
public class MessageHelpers {
private static long sExitMsgTimeMS = 0;
private static final int LONG_MSG_TIMEOUT = 5000;
public static void showMessage(final Context ctx, final String TAG, final Throwable ex) {
showMessage(ctx, TAG, Helpers.toString(ex));
}
public static void showMessage(final Context ctx, final String TAG, final String msg) {
showMessage(ctx, String.format("%s: %s", TAG, msg));
}
public static void showMessageThrottled(final Context ctx, final String msg) {
// throttle msg calls
if (System.currentTimeMillis() - sExitMsgTimeMS < LONG_MSG_TIMEOUT) {
return;
}
sExitMsgTimeMS = System.currentTimeMillis();
showMessage(ctx, msg);
}
public static void showMessage(final Context ctx, final String msg) {
if (ctx == null) {
return;
}
Runnable toast = () -> {
try {
Toast.makeText(ctx, msg, Toast.LENGTH_LONG).show();
} catch (Exception ex) { // NPE fix
ex.printStackTrace();
}
};
if (Looper.myLooper() == Looper.getMainLooper()) {
toast.run();
} else {
new Handler(Looper.getMainLooper()).post(toast);
}
}
/**
* Shows long toast message.<br/>
* Uses resource id as message.
* @param ctx context
* @param resId resource id
*/
public static void showLongMessage(Context ctx, int resId) {
showLongMessage(ctx, ctx.getResources().getString(resId));
}
public static void showLongMessage(Context ctx, String msg) {
for (int i = 0; i < 3; i++) {
showMessage(ctx, msg);
}
}
public static void showLongMessage(Context ctx, String TAG, String msg) {
for (int i = 0; i < 3; i++) {
showMessage(ctx, TAG, msg);
}
}
/**
* Shows toast message.<br/>
* Uses resource id as message.
* @param ctx context
* @param resId resource id
*/
public static void showMessage(Context ctx, int resId) {
showMessage(ctx, ctx.getResources().getString(resId));
}
public static void showLongMessageEndPause(Context context, int resId) {
showLongMessage(context, resId);
try {
Thread.sleep(5_000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}