This commit is contained in:
Yuriy Liskov
2020-01-18 17:13:06 +02:00
parent 5e93ab5953
commit c08fc9feb7
7 changed files with 82 additions and 78 deletions

View File

@@ -44,6 +44,12 @@ allprojects {
// com.android.support libs
maven { url 'https://maven.google.com' }
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
task clean(type: Delete) {

View File

@@ -18,6 +18,7 @@ import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.core.content.ContextCompat;
import com.liskovsoft.leankeykeyboard.R;
import java.util.Iterator;
@@ -134,7 +135,7 @@ public class LeanbackKeyboardView extends FrameLayout {
mPaint.setAlpha(255);
mPadding = new Rect(0, 0, 0, 0);
mModeChangeTextSize = (int) res.getDimension(R.dimen.function_key_mode_change_font_size);
mKeyTextColor = res.getColor(R.color.key_text_default);
mKeyTextColor = ContextCompat.getColor(getContext(), R.color.key_text_default);
mFocusIndex = -1;
mShiftState = 0;
mFocusedScale = res.getFraction(R.fraction.focused_scale, 1, 1);
@@ -190,13 +191,13 @@ public class LeanbackKeyboardView extends FrameLayout {
if (key.codes[0] == NOT_A_KEY) {
switch (mShiftState) {
case SHIFT_OFF:
key.icon = getContext().getResources().getDrawable(R.drawable.ic_ime_shift_off);
key.icon = ContextCompat.getDrawable(getContext(), R.drawable.ic_ime_shift_off);
break;
case SHIFT_ON:
key.icon = getContext().getResources().getDrawable(R.drawable.ic_ime_shift_on);
key.icon = ContextCompat.getDrawable(getContext(), R.drawable.ic_ime_shift_on);
break;
case SHIFT_LOCKED:
key.icon = getContext().getResources().getDrawable(R.drawable.ic_ime_shift_lock_on);
key.icon = ContextCompat.getDrawable(getContext(), R.drawable.ic_ime_shift_lock_on);
}
}

View File

@@ -14,6 +14,7 @@ import android.graphics.Rect;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.view.View;
import androidx.core.content.ContextCompat;
import com.liskovsoft.leankeykeyboard.R;
public class BitmapSoundLevelView extends View {
@@ -159,13 +160,13 @@ public class BitmapSoundLevelView extends View {
size = (centerX - this.mMinimumLevelSize) * this.mCurrentVolume / 100 + this.mMinimumLevelSize;
this.mDestRect.set(centerX - size, centerY - size, centerX + size, centerY + size);
canvas.drawBitmap(this.mPrimaryLevel, (Rect) null, this.mDestRect, this.mEmptyPaint);
this.mPaint.setColor(this.getResources().getColor(R.color.search_mic_background));
this.mPaint.setColor(ContextCompat.getColor(getContext(), R.color.search_mic_background));
this.mPaint.setStyle(Style.FILL);
canvas.drawCircle((float) centerX, (float) centerY, (float) (this.mMinimumLevelSize - 3), this.mPaint);
}
if (this.mTrailLevel != null && this.mPrimaryLevel != null) {
this.mPaint.setColor(this.getResources().getColor(R.color.search_mic_levels_guideline));
this.mPaint.setColor(ContextCompat.getColor(getContext(), R.color.search_mic_levels_guideline));
this.mPaint.setStyle(Style.STROKE);
canvas.drawCircle((float) centerX, (float) centerY, (float) (centerX - 13), this.mPaint);
}

View File

@@ -4,6 +4,8 @@ import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Intent;
import android.inputmethodservice.InputMethodService;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
@@ -32,30 +34,34 @@ public class LeanbackImeService extends InputMethodService {
private static final int SUGGESTIONS_CLEAR_DELAY = 1000;
private static final String TAG = "LbImeService";
private boolean mEnterSpaceBeforeCommitting;
private final Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == MSG_SUGGESTIONS_CLEAR && LeanbackImeService.this.mShouldClearSuggestions) {
LeanbackImeService.this.mSuggestionsFactory.clearSuggestions();
LeanbackImeService.this.mKeyboardController.updateSuggestions(LeanbackImeService.this.mSuggestionsFactory.getSuggestions());
LeanbackImeService.this.mShouldClearSuggestions = false;
}
}
};
private LeanbackKeyboardController.InputListener mInputListener = new LeanbackKeyboardController.InputListener() {
@Override
public void onEntry(int type, int keyCode, CharSequence text) {
LeanbackImeService.this.handleTextEntry(type, keyCode, text);
}
};
private View mInputView;
private LeanbackKeyboardController mKeyboardController;
private boolean mShouldClearSuggestions = true;
private LeanbackSuggestionsFactory mSuggestionsFactory;
@SuppressLint("HandlerLeak")
private final Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == MSG_SUGGESTIONS_CLEAR && mShouldClearSuggestions) {
mSuggestionsFactory.clearSuggestions();
mKeyboardController.updateSuggestions(mSuggestionsFactory.getSuggestions());
mShouldClearSuggestions = false;
}
}
};
private LeanbackKeyboardController.InputListener mInputListener = new LeanbackKeyboardController.InputListener() {
@Override
public void onEntry(int type, int keyCode, CharSequence text) {
handleTextEntry(type, keyCode, text);
}
};
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public LeanbackImeService() {
if (!enableHardwareAcceleration()) {
if (VERSION.SDK_INT < 21 && !enableHardwareAcceleration()) {
Log.w("LbImeService", "Could not enable hardware acceleration");
}
}
@@ -246,14 +252,14 @@ public class LeanbackImeService extends InputMethodService {
}
/**
* At this point, decision whether to show kbd taking place
* At this point, decision whether to show kbd taking place<br/>
* <a href="https://stackoverflow.com/questions/7449283/is-it-possible-to-have-both-physical-keyboard-and-soft-keyboard-active-at-the-sa">More info</a>
* @return whether to show kbd
*/
@SuppressLint("MissingSuperCall")
@Override
public boolean onEvaluateInputViewShown() {
//return mKeyboardController.showInputView();
return true; // force to show even when there is an hardware kbd
return mKeyboardController.showInputView();
}
@Override

View File

@@ -1,8 +1,8 @@
package com.liskovsoft.leankeyboard.other;
import android.app.*;
import android.content.*;
import android.content.res.*;
import android.util.*;
import com.liskovsoft.leankeyboard.utils.LocaleUtility;
import java.util.*;
@@ -57,16 +57,8 @@ public class RestartServiceReceiver extends BroadcastReceiver {
private void switchLocale(Context ctx) {
Log.e("RestartServiceReceiver", "Trying to switch locale back and forward");
Locale savedLocale = Locale.getDefault();
trySwitchLocale(ctx, new Locale("ru"));
trySwitchLocale(ctx, savedLocale);
}
private void trySwitchLocale(Context ctx, Locale locale) {
Locale.setDefault(locale);
Configuration config = ctx.getResources().getConfiguration();
config.locale = locale;
ctx.getResources().updateConfiguration(config,
ctx.getResources().getDisplayMetrics());
LocaleUtility.forceLocaleOld(ctx, new Locale("ru"));
LocaleUtility.forceLocaleOld(ctx, savedLocale);
}
private String getPackageName(Context ctx) {

View File

@@ -74,11 +74,7 @@ public class LangUpdater {
}
Locale locale = parseLangCode(langCode);
Locale.setDefault(locale);
Configuration config = mContext.getResources().getConfiguration();
config.locale = locale;
mContext.getResources().updateConfiguration(config,
mContext.getResources().getDisplayMetrics());
LocaleUtility.forceLocaleOld(mContext, locale);
}
private boolean isRussianPackage(String pkgName) {
@@ -103,7 +99,7 @@ public class LangUpdater {
public String getLocale() {
Configuration config = mContext.getResources().getConfiguration();
return config.locale.getLanguage();
return LocaleUtility.getSystemLocale(config).getLanguage();
}
/**

View File

@@ -1,35 +1,14 @@
package com.liskovsoft.leankeyboard.utils;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Build.VERSION;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/*
* Copyright 2013 Phil Brown
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* Get Script name by Locale
* <br>
* @author Phil Brown
* @since 9:47:09 AM Dec 20, 2013
*
*/
/*
* Additional info:
* https://en.wikipedia.org/wiki/Writing_system
@@ -750,19 +729,42 @@ public class LocaleUtility {
return script == null ? scripts.get("") : script;
}
public static Locale getSystemLocale(Context context) {
return getSystemLocale(context.getResources().getConfiguration());
}
/**
* Obtain right locale even if the user changes their Locale in settings after your application process is running.
* Android N (Api level 24) update (no warnings).
* @param context activity
* @return locale
*/
public static Locale getCurrentLocale(Context context){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
return context.getResources().getConfiguration().getLocales().get(0);
} else{
//noinspection deprecation
return context.getResources().getConfiguration().locale;
public static void setSystemLocale(Context context, Locale locale) {
setSystemLocale(context.getResources().getConfiguration(), locale);
}
@SuppressWarnings("deprecation")
public static void setSystemLocale(Configuration config, Locale locale) {
if (VERSION.SDK_INT < 24) {
config.locale = locale;
} else {
config.setLocale(locale);
}
}
@SuppressWarnings("deprecation")
public static Locale getSystemLocale(Configuration config) {
if (VERSION.SDK_INT < 24) {
return config.locale;
} else {
return config.getLocales().get(0);
}
}
/**
* <a href="https://stackoverflow.com/questions/40221711/android-context-getresources-updateconfiguration-deprecated/40704077#40704077">Modern Solution</a>
*/
@SuppressWarnings("deprecation")
public static void forceLocaleOld(Context ctx, Locale locale) {
Locale.setDefault(locale);
Configuration config = ctx.getResources().getConfiguration();
LocaleUtility.setSystemLocale(config, locale);
ctx.getResources().updateConfiguration(config,
ctx.getResources().getDisplayMetrics());
}
}