Checkstyle fixes

master
Ravi Agarwal 2 years ago
parent 542e41c83b
commit 9140e2c9f6
  1. 20
      8vim/src/main/java/inc/flide/vim8/MainInputMethodService.java
  2. 4
      8vim/src/main/java/inc/flide/vim8/geometry/Circle.java
  3. 8
      8vim/src/main/java/inc/flide/vim8/geometry/GeometricUtilities.java
  4. 5
      8vim/src/main/java/inc/flide/vim8/keyboardActionListners/ButtonKeypadActionListener.java
  5. 17
      8vim/src/main/java/inc/flide/vim8/keyboardActionListners/KeypadActionListener.java
  6. 11
      8vim/src/main/java/inc/flide/vim8/keyboardActionListners/MainKeypadActionListener.java
  7. 27
      8vim/src/main/java/inc/flide/vim8/keyboardHelpers/InputMethodServiceHelper.java
  8. 8
      8vim/src/main/java/inc/flide/vim8/keyboardHelpers/InputMethodViewHelper.java
  9. 3
      8vim/src/main/java/inc/flide/vim8/keyboardHelpers/KeyboardDataXmlParser.java
  10. 8
      8vim/src/main/java/inc/flide/vim8/preferences/SharedPreferenceHelper.java
  11. 10
      8vim/src/main/java/inc/flide/vim8/structures/Constants.java
  12. 14
      8vim/src/main/java/inc/flide/vim8/structures/CustomKeycode.java
  13. 2
      8vim/src/main/java/inc/flide/vim8/structures/KeyboardAction.java
  14. 3
      8vim/src/main/java/inc/flide/vim8/structures/KeyboardData.java
  15. 8
      8vim/src/main/java/inc/flide/vim8/structures/LayoutFileName.java
  16. 29
      8vim/src/main/java/inc/flide/vim8/ui/AboutUsActivity.java
  17. 33
      8vim/src/main/java/inc/flide/vim8/ui/SettingsActivity.java
  18. 8
      8vim/src/main/java/inc/flide/vim8/ui/SettingsFragment.java
  19. 4
      8vim/src/main/java/inc/flide/vim8/views/ButtonKeypadView.java
  20. 2
      8vim/src/main/java/inc/flide/vim8/views/NumberKeypadView.java
  21. 16
      8vim/src/main/java/inc/flide/vim8/views/mainKeyboard/MainKeyboardView.java
  22. 130
      8vim/src/main/java/inc/flide/vim8/views/mainKeyboard/XpadView.java
  23. 48
      checkstyle.xml

@ -40,7 +40,7 @@ public class MainInputMethodService extends InputMethodService {
private int capsLockFlag;
private int modifierFlags;
private void setCurrentKeypadView(View view){
private void setCurrentKeypadView(View view) {
this.currentKeypadView = view;
currentKeypadView.invalidate();
setInputView(currentKeypadView);
@ -206,13 +206,21 @@ public class MainInputMethodService extends InputMethodService {
}
public void switchToSelectionKeypad() { setCurrentKeypadView(selectionKeypadView); }
public void switchToSelectionKeypad() {
setCurrentKeypadView(selectionKeypadView);
}
public void switchToSymbolsKeypad() { setCurrentKeypadView(symbolKeypadView); }
public void switchToSymbolsKeypad() {
setCurrentKeypadView(symbolKeypadView);
}
public void switchToMainKeypad() { setCurrentKeypadView(mainKeyboardView); }
public void switchToMainKeypad() {
setCurrentKeypadView(mainKeyboardView);
}
public void switchToNumberPad() { setCurrentKeypadView(numberKeypadView); }
public void switchToNumberPad() {
setCurrentKeypadView(numberKeypadView);
}
public void cut() {
inputConnection.performContextMenuAction(android.R.id.cut);
@ -297,7 +305,7 @@ public class MainInputMethodService extends InputMethodService {
*/
public void commitImeOptionsBasedEnter() {
int imeAction = this.editorInfo.imeOptions & EditorInfo.IME_MASK_ACTION;
switch(imeAction) {
switch (imeAction) {
case EditorInfo.IME_ACTION_GO:
case EditorInfo.IME_ACTION_SEARCH:
case EditorInfo.IME_ACTION_SEND:

@ -44,11 +44,11 @@ public class Circle {
double dSquare = GeometricUtilities.getSquaredDistanceBetweenPoints(point, centre);
double rSquare = Math.pow(radius, 2);
return (dSquare - rSquare);
return dSquare - rSquare;
}
public boolean isPointInsideCircle(PointF point) {
return (getPowerOfPoint(point) < 0);
return getPowerOfPoint(point) < 0;
}
/**

@ -2,11 +2,13 @@ package inc.flide.vim8.geometry;
import android.graphics.PointF;
public class GeometricUtilities {
public final class GeometricUtilities {
private GeometricUtilities() { }
public static double getSquaredDistanceBetweenPoints(PointF a, PointF b) {
double xSquare = Math.pow((a.x - b.x), 2);
double ySquare = Math.pow((a.y - b.y), 2);
double xSquare = Math.pow(a.x - b.x, 2);
double ySquare = Math.pow(a.y - b.y, 2);
double distanceSquare = Math.abs(xSquare + ySquare);
return distanceSquare;
}

@ -11,11 +11,6 @@ public class ButtonKeypadActionListener extends KeypadActionListener implements
super(mainInputMethodService, view);
}
@Override
public void onText(CharSequence text) {
super.onText(text);
}
@Override
public void onKey(int primaryCode, int[] keyCodes) {
super.handleInputKey(primaryCode, 0);

@ -26,8 +26,7 @@ public class KeypadActionListener {
}
private boolean keyCodeIsValid(int keyCode) {
//return keyCode >= KeyEvent.KEYCODE_UNKNOWN && keyCode <= KeyEvent.KEYCODE_PROFILE_SWITCH;
return keyCode >= 0 && keyCode <= 288;
return keyCode >= KeyEvent.KEYCODE_UNKNOWN && keyCode <= KeyEvent.KEYCODE_PROFILE_SWITCH;
}
private boolean customKeyCodeIsValid(int keyCode) {
@ -66,19 +65,19 @@ public class KeypadActionListener {
}
private void performInputAcceptedFeedback(int keySound) {
SharedPreferenceHelper pref = SharedPreferenceHelper.getInstance(mainInputMethodService);
boolean user_enabled_haptic_feedback =
boolean userEnabledHapticFeedback =
pref.getBoolean(
mainInputMethodService.getString(R.string.pref_haptic_feedback_key),
true);
if (user_enabled_haptic_feedback) {
if (userEnabledHapticFeedback) {
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP,
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}
boolean user_enabled_sound_feedback = pref
boolean userEnabledSoundFeedback = pref
.getBoolean(
mainInputMethodService.getString(R.string.pref_sound_feedback_key),
true);
if (user_enabled_sound_feedback) {
if (userEnabledSoundFeedback) {
audioManager.playSoundEffect(keySound);
}
}
@ -178,11 +177,11 @@ public class KeypadActionListener {
}
}
private void moveSelection(int dpad_keyCode) {
private void moveSelection(int dpadKeyCode) {
if (isSelectionOn) {
mainInputMethodService.sendDownKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, 0);
}
mainInputMethodService.sendDownAndUpKeyEvent(dpad_keyCode, 0);
mainInputMethodService.sendDownAndUpKeyEvent(dpadKeyCode, 0);
if (isSelectionOn) {
mainInputMethodService.sendUpKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, 0);
}
@ -197,7 +196,7 @@ public class KeypadActionListener {
}
public boolean isShiftSet() {
return mainInputMethodService.getShiftLockFlag() == KeyEvent.META_SHIFT_ON ;
return mainInputMethodService.getShiftLockFlag() == KeyEvent.META_SHIFT_ON;
}
public boolean isCapsLockSet() {

@ -1,7 +1,6 @@
package inc.flide.vim8.keyboardActionListners;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Handler;
@ -10,9 +9,7 @@ import android.view.View;
import java.util.ArrayList;
import java.util.List;
import androidx.preference.PreferenceManager;
import inc.flide.vim8.MainInputMethodService;
import inc.flide.vim8.R;
import inc.flide.vim8.keyboardHelpers.InputMethodServiceHelper;
import inc.flide.vim8.structures.KeyboardAction;
import inc.flide.vim8.structures.KeyboardData;
@ -20,10 +17,9 @@ import inc.flide.vim8.structures.Constants;
import inc.flide.vim8.structures.FingerPosition;
import inc.flide.vim8.structures.MovementSequenceType;
public class MainKeypadActionListener extends KeypadActionListener{
public class MainKeypadActionListener extends KeypadActionListener {
private final Handler longPressHandler = new Handler();
private final View mainKeyboardView;
private static KeyboardData keyboardData;
private final List<FingerPosition> movementSequence;
private FingerPosition currentFingerPosition;
@ -42,7 +38,6 @@ public class MainKeypadActionListener extends KeypadActionListener{
public MainKeypadActionListener(MainInputMethodService inputMethodService, View view) {
super(inputMethodService, view);
this.mainKeyboardView = view;
keyboardData = mainInputMethodService.buildKeyboardActionMap();
movementSequence = new ArrayList<>();
@ -77,7 +72,7 @@ public class MainKeypadActionListener extends KeypadActionListener{
FingerPosition lastKnownFingerPosition = currentFingerPosition;
currentFingerPosition = fingerPosition;
boolean isFingerPositionChanged = (lastKnownFingerPosition != currentFingerPosition);
boolean isFingerPositionChanged = lastKnownFingerPosition != currentFingerPosition;
if (isFingerPositionChanged) {
interruptLongPress();
@ -103,7 +98,7 @@ public class MainKeypadActionListener extends KeypadActionListener{
currentMovementSequenceType = MovementSequenceType.NO_MOVEMENT;
}
public void movementCanceled(){
public void movementCanceled() {
longPressHandler.removeCallbacks(longPressRunnable);
isLongPressCallbackSet = false;
movementSequence.clear();

@ -17,14 +17,18 @@ import inc.flide.vim8.structures.KeyboardAction;
import inc.flide.vim8.structures.KeyboardData;
import inc.flide.vim8.structures.LayoutFileName;
public class InputMethodServiceHelper {
public final class InputMethodServiceHelper {
public static KeyboardData initializeKeyboardActionMap(Resources resources, Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean useCustomSelectedKeyboardLayout = sharedPreferences.getBoolean(context.getString(R.string.pref_use_custom_selected_keyboard_layout), false);
boolean useCustomSelectedKeyboardLayout = sharedPreferences.getBoolean(
context.getString(R.string.pref_use_custom_selected_keyboard_layout),
false);
if (useCustomSelectedKeyboardLayout) {
String customKeyboardLayoutString = sharedPreferences.getString(context.getString(R.string.pref_selected_custom_keyboard_layout_uri), null);
String customKeyboardLayoutString = sharedPreferences.getString(
context.getString(R.string.pref_selected_custom_keyboard_layout_uri),
null);
if (customKeyboardLayoutString != null && !customKeyboardLayoutString.isEmpty()) {
Uri customKeyboardLayout = Uri.parse(customKeyboardLayoutString);
return initializeKeyboardActionMapForCustomLayout(resources, context, customKeyboardLayout);
@ -82,27 +86,27 @@ public class InputMethodServiceHelper {
String currentLanguageLayout = SharedPreferenceHelper
.getInstance(context)
.getString(resources.getString(R.string.pref_selected_keyboard_layout),
new LayoutFileName().getResourceName() );
new LayoutFileName().getResourceName());
return resources.getIdentifier(currentLanguageLayout, "raw", context.getPackageName());
}
private static void addToKeyboardActionsMapUsingResourceId( KeyboardData keyboardData, Resources resources, int resourceId) {
try (InputStream inputStream = resources.openRawResource(resourceId)){
private static void addToKeyboardActionsMapUsingResourceId(KeyboardData keyboardData, Resources resources, int resourceId) {
try (InputStream inputStream = resources.openRawResource(resourceId)) {
addToKeyboardActionsMapUsingInputStream(keyboardData, inputStream);
} catch (Exception exception) {
exception.printStackTrace();
}
}
private static void addToKeyboardActionsMapUsingUri( KeyboardData keyboardData, Context context, Uri customLayoutUri) {
try (InputStream inputStream = context.getContentResolver().openInputStream(customLayoutUri)){
private static void addToKeyboardActionsMapUsingUri(KeyboardData keyboardData, Context context, Uri customLayoutUri) {
try (InputStream inputStream = context.getContentResolver().openInputStream(customLayoutUri)) {
addToKeyboardActionsMapUsingInputStream(keyboardData, inputStream);
} catch (Exception exception) {
exception.printStackTrace();
}
}
private static void addToKeyboardActionsMapUsingInputStream( KeyboardData keyboardData, InputStream inputStream) throws Exception{
private static void addToKeyboardActionsMapUsingInputStream(KeyboardData keyboardData, InputStream inputStream) throws Exception {
KeyboardDataXmlParser keyboardDataXmlParser = new KeyboardDataXmlParser(inputStream);
KeyboardData tempKeyboardData = keyboardDataXmlParser.readKeyboardData();
if (validateNoConflictingActions(keyboardData.getActionMap(), tempKeyboardData.getActionMap())) {
@ -125,8 +129,8 @@ public class InputMethodServiceHelper {
if (mainKeyboardActionsMap == null || mainKeyboardActionsMap.isEmpty()) {
return true;
}
for (Map.Entry<List<FingerPosition>, KeyboardAction> newKeyboardAction: newKeyboardActionsMap.entrySet()) {
if(mainKeyboardActionsMap.containsKey(newKeyboardAction.getKey())) {
for (Map.Entry<List<FingerPosition>, KeyboardAction> newKeyboardAction : newKeyboardActionsMap.entrySet()) {
if (mainKeyboardActionsMap.containsKey(newKeyboardAction.getKey())) {
return false;
}
}
@ -134,4 +138,5 @@ public class InputMethodServiceHelper {
return true;
}
private InputMethodServiceHelper() { }
}

@ -2,19 +2,19 @@ package inc.flide.vim8.keyboardHelpers;
import inc.flide.vim8.geometry.Dimension;
public class InputMethodViewHelper {
public final class InputMethodViewHelper {
public static Dimension onMeasureHelper(int width, int height, int orientation) {
if (orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE) {
//Landscape is just un-usable right now.
// TODO: Landscape mode requires more clarity, what exactly do you want to do?
width = Math.round(1.33f * height);
} else // Portrait mode
{
} else { // Portrait mode
height = Math.round(0.8f * (width - (60 * 3)));
//height = Math.round(0.8f * (width));
}
return new Dimension(width, height);
}
private InputMethodViewHelper() { }
}

@ -137,6 +137,7 @@ class KeyboardDataXmlParser {
break;
case INPUT_KEY_FLAGS_TAG:
flags = readInputFlags();
break;
default:
//Logger.w(this, "keyboard_actions xml has unknown tag : " + tagName);
}
@ -184,7 +185,7 @@ class KeyboardDataXmlParser {
//Strictly the inputKey has to has to be a Keycode from the KeyEvent class
//Or it needs to be one of the customKeyCodes
int keyCode = KeyEvent.keyCodeFromString(inputKeyString);
if ( keyCode == KeyEvent.KEYCODE_UNKNOWN) {
if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
try {
keyCode = CustomKeycode.valueOf(inputKeyString).getKeyCode();
} catch (IllegalArgumentException error) {

@ -10,7 +10,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class SharedPreferenceHelper implements SharedPreferences.OnSharedPreferenceChangeListener {
public final class SharedPreferenceHelper implements SharedPreferences.OnSharedPreferenceChangeListener {
private SharedPreferences sharedPreferences;
private static SharedPreferenceHelper singleton = null;
@ -18,13 +18,13 @@ public class SharedPreferenceHelper implements SharedPreferences.OnSharedPrefere
void onPreferenceChanged();
}
public static SharedPreferenceHelper getInstance(Context context){
public static SharedPreferenceHelper getInstance(Context context) {
//These two ifs should be probably swapped as it can still return null
//when singleton is null.
if (context == null) {
return singleton;
}
if(singleton == null){
if (singleton == null) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
singleton = new SharedPreferenceHelper(sp);
}
@ -38,7 +38,7 @@ public class SharedPreferenceHelper implements SharedPreferences.OnSharedPrefere
listeners.add(note);
}
private SharedPreferenceHelper (SharedPreferences sharedPreferences){
private SharedPreferenceHelper(SharedPreferences sharedPreferences) {
this.sharedPreferences = sharedPreferences;
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}

@ -1,7 +1,9 @@
package inc.flide.vim8.structures;
public interface Constants {
String SELF_KEYBOARD_ID = "inc.flide.vi8/inc.flide.vim8.MainInputMethodService";
int DELAY_MILLIS_LONG_PRESS_INITIATION = 500;
int DELAY_MILLIS_LONG_PRESS_CONTINUATION = 50;
public final class Constants {
public static final String SELF_KEYBOARD_ID = "inc.flide.vi8/inc.flide.vim8.MainInputMethodService";
public static final int DELAY_MILLIS_LONG_PRESS_INITIATION = 500;
public static final int DELAY_MILLIS_LONG_PRESS_CONTINUATION = 50;
private Constants() { }
}

@ -4,9 +4,6 @@ import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import inc.flide.vim8.MainInputMethodService;
import inc.flide.vim8.R;
public enum CustomKeycode {
MOVE_CURRENT_END_POINT_LEFT(-1),
MOVE_CURRENT_END_POINT_RIGHT(-2),
@ -23,13 +20,13 @@ public enum CustomKeycode {
SWITCH_TO_EMOTICON_KEYBOARD(-13),
HIDE_KEYBOARD(-14);
private static final Map<Integer, CustomKeycode> keyCodeToStringCode;
private static final Map<Integer, CustomKeycode> KEY_CODE_TO_STRING_CODE_MAP;
private final int keyCode;
static {
keyCodeToStringCode = new HashMap<>();
for (CustomKeycode customKeycode: EnumSet.allOf(CustomKeycode.class)) {
keyCodeToStringCode.put(customKeycode.getKeyCode(), customKeycode);
KEY_CODE_TO_STRING_CODE_MAP = new HashMap<>();
for (CustomKeycode customKeycode : EnumSet.allOf(CustomKeycode.class)) {
KEY_CODE_TO_STRING_CODE_MAP.put(customKeycode.getKeyCode(), customKeycode);
}
}
@ -42,7 +39,6 @@ public enum CustomKeycode {
}
public static CustomKeycode fromIntValue(int value) {
CustomKeycode ret = keyCodeToStringCode.get(value);
return ret;
return KEY_CODE_TO_STRING_CODE_MAP.get(value);
}
}

@ -2,8 +2,6 @@ package inc.flide.vim8.structures;
import java.util.Locale;
import inc.flide.vim8.structures.KeyboardActionType;
public class KeyboardAction {
private final KeyboardActionType keyboardActionType;

@ -4,9 +4,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import inc.flide.vim8.structures.FingerPosition;
import inc.flide.vim8.structures.KeyboardAction;
public class KeyboardData {
private Map<List<FingerPosition>, KeyboardAction> actionMap;
private String lowerCaseCharacters;

@ -8,10 +8,8 @@ import java.util.Locale;
import java.util.Set;
public class LayoutFileName {
private static final Set<String> ISO_LANGUAGES = new HashSet<String>
(Arrays.asList(Locale.getISOLanguages()));
private static final Set<String> FONT_CODES = new HashSet<String>
(Arrays.asList(new String[]{"regular", "bold", "italic", "underline"}));
private static final Set<String> ISO_LANGUAGES = new HashSet<String>(Arrays.asList(Locale.getISOLanguages()));
private static final Set<String> FONT_CODES = new HashSet<String>(Arrays.asList(new String[]{"regular", "bold", "italic", "underline"}));
private String languageCode;
private String fontCode;
@ -34,7 +32,7 @@ public class LayoutFileName {
public LayoutFileName(String fileName) {
this();
String[] nameComponents = fileName.split("_", 3);
if (nameComponents.length !=3 ) {
if (nameComponents.length != 3) {
setLayoutValidityFalse();
return;
}

@ -5,11 +5,9 @@ import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.constraintlayout.widget.ConstraintLayout;
import inc.flide.vim8.R;
@ -22,8 +20,6 @@ public class AboutUsActivity extends AppCompatActivity {
private ConstraintLayout twitter;
private ConstraintLayout googlePlayStore;
CardView cardView_back_arrow;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_us_activity_layout);
@ -115,23 +111,18 @@ public class AboutUsActivity extends AppCompatActivity {
});
ImageView back_arrow = findViewById(R.id.back_arrow);
ImageView backArrow = findViewById(R.id.back_arrow);
back_arrow.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN)
{
back_arrow.setBackgroundColor(Color.LTGRAY);
}
if(motionEvent.getAction() == MotionEvent.ACTION_UP)
{
back_arrow.setBackgroundColor(Color.WHITE);
Intent intent = new Intent(AboutUsActivity.this, SettingsActivity.class);
startActivity(intent);
}
return true;
backArrow.setOnTouchListener((view, motionEvent) -> {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
backArrow.setBackgroundColor(Color.LTGRAY);
}
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
backArrow.setBackgroundColor(Color.WHITE);
Intent intent = new Intent(AboutUsActivity.this, SettingsActivity.class);
startActivity(intent);
}
return true;
});
}

@ -1,32 +1,22 @@
package inc.flide.vim8.ui;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.transition.Fade;
import android.transition.Transition;
import android.transition.TransitionManager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SwitchCompat;
import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
@ -37,7 +27,6 @@ import java.util.List;
import inc.flide.vim8.BuildConfig;
import inc.flide.vim8.R;
import inc.flide.vim8.preferences.SharedPreferenceHelper;
import inc.flide.vim8.structures.Constants;
public class SettingsActivity extends AppCompatActivity
@ -45,9 +34,9 @@ public class SettingsActivity extends AppCompatActivity
private boolean isKeyboardEnabled;
boolean press_back_twice;
private boolean pressBackTwice;
boolean isActivityRestarting;
private boolean isActivityRestarting;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -75,7 +64,7 @@ public class SettingsActivity extends AppCompatActivity
@Override
public void onBackPressed() {
if(press_back_twice){
if (pressBackTwice) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@ -85,9 +74,9 @@ public class SettingsActivity extends AppCompatActivity
}
press_back_twice = true;
Toast.makeText(SettingsActivity.this,"Please press Back again to exit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(() -> press_back_twice = false,2000);
pressBackTwice = true;
Toast.makeText(SettingsActivity.this, "Please press Back again to exit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(() -> pressBackTwice = false, 2000);
}
@ -109,8 +98,8 @@ public class SettingsActivity extends AppCompatActivity
intent.setData(data);
startActivity(intent);
} else if (item.getItemId() == R.id.about) {
Intent intent_about = new Intent(SettingsActivity.this, AboutUsActivity.class);
startActivity(intent_about);
Intent intentAboutUs = new Intent(SettingsActivity.this, AboutUsActivity.class);
startActivity(intentAboutUs);
}
DrawerLayout drawer = findViewById(R.id.drawer_layout);
@ -169,7 +158,7 @@ public class SettingsActivity extends AppCompatActivity
enableInputMethodNotificationDialog.getBuilder()
.onNeutral((dialog, which) -> {
showToast();
startActivityForResult(new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS),0);
startActivityForResult(new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0);
enableInputMethodNotificationDialog.dismiss();
});
@ -182,7 +171,7 @@ public class SettingsActivity extends AppCompatActivity
findViewById(R.id.toast_layout));
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.BOTTOM|Gravity.FILL_HORIZONTAL, 0, 0);
toast.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
@ -209,4 +198,4 @@ public class SettingsActivity extends AppCompatActivity
activateInputMethodNotificationDialog.show();
}
}
}

@ -60,7 +60,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
}
private static final int PICK_KEYBOARD_LAYOUT_FILE = 1;
private void askUserLoadCustomKeyboardLayout(){
private void askUserLoadCustomKeyboardLayout() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT)
.addCategory(Intent.CATEGORY_OPENABLE)
.setType("text/xml");
@ -75,7 +75,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit();
if(requestCode == PICK_KEYBOARD_LAYOUT_FILE && resultCode == RESULT_OK) {
if (requestCode == PICK_KEYBOARD_LAYOUT_FILE && resultCode == RESULT_OK) {
// TODO: Verify if the picked file is actually a valid layout file.
final int takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION;
Uri selectedCustomLayoutFile = data.getData();
@ -158,8 +158,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
private Map<String, String> findAllAvailableLayouts() {
Map<String, String> languagesAndLayouts = new TreeMap<>();
Field[] fields=R.raw.class.getFields();
for(int count=0; count < fields.length; count++){
Field[] fields = R.raw.class.getFields();
for (int count = 0; count < fields.length; count++) {
LayoutFileName file = new LayoutFileName(fields[count].getName());
if (file.isValidLayout()) {
languagesAndLayouts.put(file.getLayoutDisplayName(), file.getResourceName());

@ -8,7 +8,6 @@ import android.graphics.Typeface;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.util.AttributeSet;
import java.util.List;
import inc.flide.vim8.R;
import inc.flide.vim8.geometry.Dimension;
import inc.flide.vim8.keyboardHelpers.InputMethodViewHelper;
@ -72,8 +71,9 @@ public abstract class ButtonKeypadView extends KeyboardView {
@Override
public void onDraw(Canvas canvas) {
for (Keyboard.Key key : getKeyboard().getKeys()) {
if (key.label != null)
if (key.label != null) {
canvas.drawText(key.label.toString(), (key.x * 2 + key.width) / 2f, (key.y * 2 + key.height) / 2f, this.foregroundPaint);
}
if (key.icon != null) {
int side = key.height;
if (key.width < key.height) {

@ -4,9 +4,7 @@ import android.content.Context;
import android.content.res.Resources;
import android.inputmethodservice.Keyboard;
import android.util.AttributeSet;
import android.widget.Toast;
import java.util.List;
import inc.flide.vim8.MainInputMethodService;
import inc.flide.vim8.R;
import inc.flide.vim8.keyboardActionListners.ButtonKeypadActionListener;

@ -121,9 +121,11 @@ public class MainKeyboardView extends ConstraintLayout {
ImageButton switchToSelectionKeyboardButton = findViewById(R.id.switchToSelectionKeyboard);
switchToSelectionKeyboardButton.setOnClickListener(view -> {
KeyboardAction switchToSelectionKeyboard = new KeyboardAction(
KeyboardActionType.INPUT_KEY
, "", null
, CustomKeycode.SWITCH_TO_SELECTION_KEYPAD.getKeyCode(), 0);
KeyboardActionType.INPUT_KEY,
"",
null,
CustomKeycode.SWITCH_TO_SELECTION_KEYPAD.getKeyCode(),
0);
actionListener.handleInputKey(switchToSelectionKeyboard);
});
}
@ -132,9 +134,11 @@ public class MainKeyboardView extends ConstraintLayout {
ImageButton switchToEmojiKeyboardButton = findViewById(R.id.switchToEmojiKeyboard);
switchToEmojiKeyboardButton.setOnClickListener(view -> {
KeyboardAction switchToEmojiKeyboard = new KeyboardAction(
KeyboardActionType.INPUT_KEY
, "", null
, CustomKeycode.SWITCH_TO_EMOTICON_KEYBOARD.getKeyCode(), 0);
KeyboardActionType.INPUT_KEY,
"",
null,
CustomKeycode.SWITCH_TO_EMOTICON_KEYBOARD.getKeyCode(),
0);
actionListener.handleInputKey(switchToEmojiKeyboard);
});
}

@ -30,9 +30,9 @@ import inc.flide.vim8.structures.FingerPosition;
public class XpadView extends View {
private final Random rnd = new Random();
private final Path typingTrailPath = new Path();
Paint backgroundPaint = new Paint();
Paint foregroundPaint = new Paint();
Paint typingTrailPaint = new Paint();
private Paint backgroundPaint = new Paint();
private Paint foregroundPaint = new Paint();
private Paint typingTrailPaint = new Paint();
private MainKeypadActionListener actionListener;
private PointF circleCenter;
private Circle circle;
@ -41,7 +41,7 @@ public class XpadView extends View {
private final Matrix xformMatrix = new Matrix();
// There are 4 sectors, each has 4 letters above, and 4 below.
// Finally, each letter position has an x & y co-ordinate.
private final float[] letterPositions = new float[4*2*4*2];
private final float[] letterPositions = new float[4 * 2 * 4 * 2];
private final Path sectorLines = new Path();
private final RectF sectorLineBounds = new RectF();
@ -51,7 +51,7 @@ public class XpadView extends View {
private final float[] trialPathPos = new float[2];
private final PathMeasure pathMeasure = new PathMeasure();
boolean userPreferRandomTrailColor = false;
private boolean userPreferRandomTrailColor = false;
public XpadView(Context context) {
super(context);
@ -82,7 +82,7 @@ public class XpadView extends View {
userPreferRandomTrailColor = sharedPreferenceHelper.getBoolean(
resources.getString(R.string.pref_random_trail_color_key),
false );
false);
trailColor = sharedPreferenceHelper.getInt(
resources.getString(R.string.pref_trail_color_key),
@ -117,8 +117,8 @@ public class XpadView extends View {
// TODO: Store constant in .xml file (but where?)
float radius = (spRadiusValue / 40.f * keypadDimension.getWidth()) / 2;
int xOffset = ((pref.getInt(context.getString(R.string.pref_circle_x_offset_key), 0)) * 26);
int yOffset = ((pref.getInt(context.getString(R.string.pref_circle_y_offset_key), 0)) * 26);
int xOffset = (pref.getInt(context.getString(R.string.pref_circle_x_offset_key), 0)) * 26;
int yOffset = (pref.getInt(context.getString(R.string.pref_circle_y_offset_key), 0)) * 26;
circleCenter.x = (keypadDimension.getWidth() / 2f) + xOffset;
circleCenter.y = (keypadDimension.getHeight() / 2f) + yOffset;
@ -130,10 +130,10 @@ public class XpadView extends View {
// this introduces a bit of asymmetry which we have to compensate for here.
int keypadXOffset = fullWidth - keypadDimension.getWidth();
// If the xOffset is to the right, we can spread into the extra padding space.
int smallDim = Math.min(xOffset > 0? fullWidth/2 - xOffset + keypadXOffset
int smallDim = Math.min(xOffset > 0 ? fullWidth / 2 - xOffset + keypadXOffset
// If xOffset goes to the left, restrict to keypadDimension.
: keypadDimension.getWidth()/2 + xOffset,
fullHeight/2 - Math.abs(yOffset));
: keypadDimension.getWidth() / 2 + xOffset,
fullHeight / 2 - Math.abs(yOffset));
// Compute the length of sector lines, such that they stop a little before hitting the edge of the view.
float lengthOfLineDemarcatingSectors = (float) Math.hypot(smallDim, smallDim)
- radius - characterHeight;
@ -152,13 +152,13 @@ public class XpadView extends View {
// Compute the first set of points going straight to the "east" (aka, rightwards).
// Then apply repeated rotation (45, then 90 x4) to get the final positions.
float eastEdge = circleCenter.x + circle.getRadius() + characterHeight/2;
float eastEdge = circleCenter.x + circle.getRadius() + characterHeight / 2;
for (int i = 0; i < 4; i++) {
float dx = ( i * lengthOfLineDemarcatingSectors / 4f);
letterPositions[4*i] = eastEdge + dx;
letterPositions[4*i+1] = circleCenter.y - characterHeight/2; // upper letter
letterPositions[4*i+2] = eastEdge + dx;
letterPositions[4*i+3] = circleCenter.y + characterHeight/2; // lower letter
float dx = i * lengthOfLineDemarcatingSectors / 4f;
letterPositions[4 * i] = eastEdge + dx;
letterPositions[4 * i + 1] = circleCenter.y - characterHeight / 2; // upper letter
letterPositions[4 * i + 2] = eastEdge + dx;
letterPositions[4 * i + 3] = circleCenter.y + characterHeight / 2; // lower letter
}
xformMatrix.reset();
@ -169,13 +169,13 @@ public class XpadView extends View {
xformMatrix.reset();
xformMatrix.postRotate(90, circleCenter.x, circleCenter.y);
for (int i = 1; i < 4; i++) {
xformMatrix.mapPoints(letterPositions, 4*4*i, letterPositions, 4*4*(i-1), 8);
xformMatrix.mapPoints(letterPositions, 4 * 4 * i, letterPositions, 4 * 4 * (i - 1), 8);
}
// Canvas.drawPosText() draws from the bottom,
// so we need to offset downwards a bit to compensate.
xformMatrix.reset();
xformMatrix.postTranslate(0, 3*characterHeight/16);
xformMatrix.postTranslate(0, 3 * characterHeight / 16);
xformMatrix.mapPoints(letterPositions);
sectorLines.computeBounds(sectorLineBounds, false); // Used to position icons
@ -186,7 +186,7 @@ public class XpadView extends View {
int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
keypadDimension.setWidth((parentWidth/6) *5);
keypadDimension.setWidth((parentWidth / 6) * 5);
keypadDimension.setHeight(parentHeight);
setMeasuredDimension(keypadDimension.getWidth(), keypadDimension.getHeight());
@ -199,7 +199,11 @@ public class XpadView extends View {
canvas.drawColor(backgroundPaint.getColor());
boolean userPrefersTypingTrail = SharedPreferenceHelper.getInstance(getContext()).getBoolean(this.getContext().getString(R.string.pref_typing_trail_visibility_key), true);
boolean userPrefersTypingTrail = SharedPreferenceHelper
.getInstance(getContext())
.getBoolean(
this.getContext().getString(R.string.pref_typing_trail_visibility_key),
true);
if (userPrefersTypingTrail) {
paintTypingTrail(canvas);
}
@ -213,16 +217,24 @@ public class XpadView extends View {
canvas.drawPath(sectorLines, foregroundPaint); //The lines demarcating the sectors
// Converting float value to int
int centre_x_value = (int) circle.getCentre().x;
int centre_y_value = (int) circle.getCentre().y;
boolean userPrefersSectorIcons = SharedPreferenceHelper.getInstance(getContext()).getBoolean(this.getContext().getString(R.string.pref_display_sector_icons_key), true);
int centreXValue = (int) circle.getCentre().x;
int centreYValue = (int) circle.getCentre().y;
boolean userPrefersSectorIcons = SharedPreferenceHelper
.getInstance(getContext())
.getBoolean(
this.getContext().getString(R.string.pref_display_sector_icons_key),
true);
if (userPrefersSectorIcons) {
setupSectorIcons(centre_x_value, centre_y_value, canvas);
setupSectorIcons(centreXValue, centreYValue, canvas);
}
//the text along the lines
boolean userPreferWheelLetters = SharedPreferenceHelper.getInstance(getContext()).getBoolean(this.getContext().getString(R.string.pref_display_wheel_characters_key), true);
boolean userPreferWheelLetters = SharedPreferenceHelper
.getInstance(getContext())
.getBoolean(
this.getContext().getString(R.string.pref_display_wheel_characters_key),
true);
if (userPreferWheelLetters) {
foregroundPaint.setStrokeWidth(0.75f * density);
foregroundPaint.setStyle(Paint.Style.FILL);
@ -240,65 +252,65 @@ public class XpadView extends View {
foregroundPaint.setTypeface(font);
}
private void setupSectorIcons(int centre_x_value, int centre_y_value, Canvas canvas) {
private void setupSectorIcons(int centreXValue, int centreYValue, Canvas canvas) {
int icon_size = getResources().getDimensionPixelSize(R.dimen.icon_size);
int icon_half_width = icon_size / 2;
int icon_half_height = icon_size / 2;
int iconSize = getResources().getDimensionPixelSize(R.dimen.icon_size);
int iconHalfWidth = iconSize / 2;
int iconHalfHeight = iconSize / 2;
sectorLines.computeBounds(sectorLineBounds, false);
//Number pad icon (left side)
int icon_center_x = (int) Math.max(sectorLineBounds.left, 0);
int icon_center_y = centre_y_value;
drawIconInSector(icon_center_x - icon_half_width,
icon_center_y - icon_half_height,
int iconCenterX = (int) Math.max(sectorLineBounds.left, 0);
int iconCenterY = centreYValue;
drawIconInSector(iconCenterX - iconHalfWidth,
iconCenterY - iconHalfHeight,
canvas,
R.drawable.numericpad_vd_vector);
//for Backspace icon (right side)
icon_center_x = (int) Math.min(sectorLineBounds.right, canvas.getWidth());
icon_center_y = centre_y_value;
drawIconInSector(icon_center_x - icon_half_width,
icon_center_y - icon_half_height,
iconCenterX = (int) Math.min(sectorLineBounds.right, canvas.getWidth());
iconCenterY = centreYValue;
drawIconInSector(iconCenterX - iconHalfWidth,
iconCenterY - iconHalfHeight,
canvas,
R.drawable.ic_backspace);
//for Enter icon (bottom)
icon_center_x = centre_x_value;
icon_center_y = (int) Math.min(sectorLineBounds.bottom, canvas.getHeight());
drawIconInSector(icon_center_x - icon_half_width,
icon_center_y - icon_half_height,
iconCenterX = centreXValue;
iconCenterY = (int) Math.min(sectorLineBounds.bottom, canvas.getHeight());
drawIconInSector(iconCenterX - iconHalfWidth,
iconCenterY - iconHalfHeight,
canvas,
R.drawable.ic_keyboard_return);
//for caps lock and shift icon
icon_center_x = centre_x_value;
icon_center_y = (int) Math.max(sectorLineBounds.top, 0);
int shift_icon_to_display = R.drawable.ic_no_capslock;
iconCenterX = centreXValue;
iconCenterY = (int) Math.max(sectorLineBounds.top, 0);
int shiftIconToDisplay = R.drawable.ic_no_capslock;
if (actionListener.isShiftSet()) {
shift_icon_to_display = R.drawable.ic_shift_engaged;
shiftIconToDisplay = R.drawable.ic_shift_engaged;
}
if (actionListener.isCapsLockSet()) {
shift_icon_to_display = R.drawable.ic_capslock_engaged;
shiftIconToDisplay = R.drawable.ic_capslock_engaged;
}
drawIconInSector(icon_center_x - icon_half_width,
icon_center_y - icon_half_height,
drawIconInSector(iconCenterX - iconHalfWidth,
iconCenterY - iconHalfHeight,
canvas,
shift_icon_to_display);
shiftIconToDisplay);
}
private void drawIconInSector(int coordinateX, int coordinateY, Canvas canvas, int resourceId) {
int icon_size = getResources().getDimensionPixelSize(R.dimen.icon_size);
int iconSize = getResources().getDimensionPixelSize(R.dimen.icon_size);
VectorDrawableCompat icon_vectorDrawable = VectorDrawableCompat
VectorDrawableCompat iconVectorDrawable = VectorDrawableCompat
.create(getContext().getResources(), resourceId, null);
icon_vectorDrawable.setBounds(coordinateX,
iconVectorDrawable.setBounds(coordinateX,
coordinateY,
coordinateX + icon_size,
coordinateY + icon_size);
icon_vectorDrawable.setTint(foregroundColor);
coordinateX + iconSize,
coordinateY + iconSize);
iconVectorDrawable.setTint(foregroundColor);
// TODO: define in .xml (don't know in which file)
icon_vectorDrawable.setAlpha(85);
icon_vectorDrawable.draw(canvas);
iconVectorDrawable.setAlpha(85);
iconVectorDrawable.draw(canvas);
}
private void paintTypingTrail(Canvas canvas) {

@ -8,12 +8,10 @@
<module name="FileTabCharacter" />
<!-- Trailing spaces -->
<!--
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="message" value="Line has trailing spaces."/>
</module>
-->
<!-- Space after 'for' and 'if' -->
<module name="RegexpSingleline">
@ -48,7 +46,7 @@
<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<!--<module name="ConstantName" />-->
<module name="ConstantName" />
<module name="LocalFinalVariableName" />
<module name="LocalVariableName" />
<module name="MemberName">
@ -83,7 +81,7 @@
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="GenericWhitespace" />
<!--<module name="EmptyForIteratorPad"/>-->
<module name="EmptyForIteratorPad"/>
<module name="MethodParamPad" />
<module name="NoWhitespaceAfter">
<property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS, UNARY_PLUS" />
@ -101,14 +99,14 @@
<!-- Modifier Checks -->
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
<module name="ModifierOrder" />
<!--<module name="RedundantModifier" />-->
<module name="RedundantModifier" />
<!-- Checks for blocks. You know, those {
}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="AvoidNestedBlocks" />
<!--<module name="EmptyBlock" />-->
<module name="EmptyBlock" />
<module name="LeftCurly" />
<module name="NeedBraces" />
<module name="RightCurly" />
@ -116,18 +114,20 @@
<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<!--module name="AvoidInlineConditionals"/-->
<!--<module name="AvoidInlineConditionals"/>-->
<module name="CovariantEquals" />
<module name="EmptyStatement" />
<!--<module name="EqualsAvoidNull"/>-->
<!--<module name="EqualsHashCode" />-->
<module name="EqualsAvoidNull"/>
<module name="EqualsHashCode" />
<!--<module name="HiddenField"/>-->
<module name="IllegalInstantiation" />
<!--module name="InnerAssignment"/-->
<!--<module name="MagicNumber">-->
<!--<property name="ignoreNumbers" value="-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9" />-->
<!--</module>-->
<!--module name="MissingSwitchDefault"/-->
<module name="InnerAssignment"/>
<!--
<module name="MagicNumber">
<property name="ignoreNumbers" value="-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9" />
</module>
-->
<!--<module name="MissingSwitchDefault"/>-->
<!--<module name="RedundantThrows">-->
<!--<property name="allowUnchecked" value="true"/>-->
<!--<property name="allowSubclasses" value="true"/>-->
@ -135,24 +135,26 @@
<module name="SimplifyBooleanExpression" />
<module name="SimplifyBooleanReturn" />
<module name="StringLiteralEquality" />
<!--<module name="IllegalCatch" />-->
<!-- <module name="IllegalCatch" />-->
<module name="IllegalThrows" />
<module name="FallThrough" />
<!--<module name="MultipleStringLiterals" />-->
<!-- <module name="MultipleStringLiterals" />-->
<module name="UnnecessaryParentheses" />
<!--<module name="DeclarationOrder"/>-->
<!-- <module name="DeclarationOrder"/>-->
<!-- Checks for class design -->
<!-- See http://checkstyle.sf.net/config_design.html -->
<!--module name="DesignForExtension"/-->
<!--<module name="FinalClass"/>-->
<!-- <module name="DesignForExtension"/>-->
<module name="FinalClass"/>
<module name="HideUtilityClassConstructor" />
<module name="InterfaceIsType" />
<!--module name="VisibilityModifier"/-->
<!--<module name="MutableException">-->
<module name="VisibilityModifier">
<property name="protectedAllowed" value="true"/>
</module>
<module name="MutableException">
<!-- Extend MutableException to enforce immutable events as well -->
<!--<property name="format" value="^.*Exception$|^.*Error$|^.*Event$" />-->
<!--</module>-->
<property name="format" value="^.*Exception$|^.*Error$|^.*Event$" />
</module>
<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->

Loading…
Cancel
Save