feat(android/app): Add menu to adjust keyboard height
|
|
@ -294,6 +294,11 @@
|
|||
android:parentActivityName=".SelectPackageActivity"
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@style/AppTheme.Base" />
|
||||
<activity
|
||||
android:name=".AdjustKeyboardHeightActivity"
|
||||
android:configChanges="orientation"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme.Base" />
|
||||
|
||||
<!-- Put other WebViewActivities in a separate process so the Keyboard WebView doesn't lag.
|
||||
Ref https://stackoverflow.com/questions/40650643/timed-out-waiting-on-iinputcontextcallback-with-custom-keyboard-on-android -->
|
||||
|
|
|
|||
|
|
@ -0,0 +1,147 @@
|
|||
/**
|
||||
* Copyright (C) SIL International. All rights reserved.
|
||||
*/
|
||||
package com.tavultesoft.kmapro;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.tavultesoft.kmea.BaseActivity;
|
||||
import com.tavultesoft.kmea.KMManager;
|
||||
|
||||
/**
|
||||
* Settings menu for adjusting the keyboard height. The value for the current device orientation
|
||||
* is saved in shared preferences.
|
||||
*/
|
||||
public class AdjustKeyboardHeightActivity extends BaseActivity {
|
||||
private static final String TAG = "AdjustKbdHeight";
|
||||
public static final String adjustKeyboardHeightKey = "AdjustKeyboardHeight";
|
||||
|
||||
private static Button resetButton = null;
|
||||
private static ImageView sampleKeyboard = null;
|
||||
|
||||
// Keeps track of the adjusted keyboard height for saving
|
||||
private static SharedPreferences.Editor editor = null;
|
||||
private static int currentHeight = 0;
|
||||
private static ViewGroup.LayoutParams layoutParams;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
final Context context = this;
|
||||
|
||||
setContentView(R.layout.activity_adjust_keyboard_height);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.titlebar);
|
||||
setSupportActionBar(toolbar);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle(null);
|
||||
actionBar.setDisplayUseLogoEnabled(false);
|
||||
actionBar.setDisplayShowHomeEnabled(false);
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
actionBar.setDisplayShowCustomEnabled(true);
|
||||
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.keyman_blue)));
|
||||
}
|
||||
|
||||
TextView adjustKeyboardHeightActivityTitle = (TextView) findViewById(R.id.bar_title);
|
||||
adjustKeyboardHeightActivityTitle.setWidth((int) getResources().getDimension(R.dimen.package_label_width));
|
||||
|
||||
String titleStr = getString(R.string.adjust_keyboard_height);
|
||||
adjustKeyboardHeightActivityTitle.setTextColor(ContextCompat.getColor(this, R.color.ms_white));
|
||||
adjustKeyboardHeightActivityTitle.setText(titleStr);
|
||||
|
||||
SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE);
|
||||
editor = prefs.edit();
|
||||
|
||||
sampleKeyboard = (ImageView) findViewById(R.id.sample_keyboard);
|
||||
layoutParams = sampleKeyboard.getLayoutParams();
|
||||
refreshSampleKeyboard(context, true);
|
||||
|
||||
resetButton = (Button) findViewById(R.id.reset_to_defaults);
|
||||
resetButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
// Clear the keyboard height preferences to reset
|
||||
editor.remove(KMManager.KMKey_KeyboardHeightPortrait);
|
||||
editor.remove(KMManager.KMKey_KeyboardHeightLandscape);
|
||||
editor.commit();
|
||||
|
||||
// Restore default height
|
||||
refreshSampleKeyboard(context, true);
|
||||
}
|
||||
});
|
||||
|
||||
sampleKeyboard.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
int y = (int)event.getY();
|
||||
|
||||
switch(event.getAction()) {
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
// Update currentHeight as the user drags (moves)
|
||||
// Increasing the keyboard height is a negative y
|
||||
currentHeight -= y;
|
||||
|
||||
refreshSampleKeyboard(context, false);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
// Save the currentHeight when the user releases
|
||||
int orientation = context.getResources().getConfiguration().orientation;
|
||||
String keyboardHeightKey = (orientation == Configuration.ORIENTATION_LANDSCAPE) ?
|
||||
KMManager.KMKey_KeyboardHeightLandscape : KMManager.KMKey_KeyboardHeightPortrait;
|
||||
editor.putInt(keyboardHeightKey, currentHeight);
|
||||
editor.commit();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the layout for the sample keyboard
|
||||
* @param context
|
||||
* @param updateCurrentHeight - boolean if true, updates currentHeight
|
||||
*/
|
||||
private void refreshSampleKeyboard(Context context, boolean updateCurrentHeight) {
|
||||
if (updateCurrentHeight) {
|
||||
currentHeight = KMManager.getKeyboardHeight(context);
|
||||
}
|
||||
|
||||
layoutParams.height = currentHeight;
|
||||
sampleKeyboard.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
layoutParams = sampleKeyboard.getLayoutParams();
|
||||
|
||||
// When the user rotates the device, restore currentHeight
|
||||
refreshSampleKeyboard(this,true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// Apply the adjusted height on exit
|
||||
KMManager.setKeyboardHeight(this, currentHeight);
|
||||
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -27,7 +27,8 @@ public class KeymanSettingsFragment extends PreferenceFragmentCompat {
|
|||
private static final String TAG = "SettingsFragment";
|
||||
private static Context context;
|
||||
|
||||
private Preference languagesPreference, installKeyboardOrDictionary, displayLanguagePreference;
|
||||
private Preference languagesPreference, installKeyboardOrDictionary, displayLanguagePreference,
|
||||
adjustKeyboardHeight;
|
||||
private ListPreference spacebarTextPreference;
|
||||
private CheckBoxPreference setSystemKeyboardPreference;
|
||||
private CheckBoxPreference setDefaultKeyboardPreference;
|
||||
|
|
@ -62,6 +63,13 @@ public class KeymanSettingsFragment extends PreferenceFragmentCompat {
|
|||
Intent displayLanguageIntent = new Intent(context, KeymanSettingsLocalizeActivity.class);
|
||||
displayLanguagePreference.setIntent(displayLanguageIntent);
|
||||
|
||||
adjustKeyboardHeight = new Preference(context);
|
||||
adjustKeyboardHeight.setKey(AdjustKeyboardHeightActivity.adjustKeyboardHeightKey);
|
||||
adjustKeyboardHeight.setTitle(getString(R.string.adjust_keyboard_height));
|
||||
adjustKeyboardHeight.setWidgetLayoutResource(R.layout.preference_height_icon_layout);
|
||||
Intent adjustKeyboardHeightIntent = new Intent(context, AdjustKeyboardHeightActivity.class);
|
||||
adjustKeyboardHeight.setIntent(adjustKeyboardHeightIntent);
|
||||
|
||||
/* Spacebar Caption Preference */
|
||||
|
||||
spacebarTextPreference = new ListPreference(context);
|
||||
|
|
@ -168,6 +176,7 @@ public class KeymanSettingsFragment extends PreferenceFragmentCompat {
|
|||
screen.addPreference(languagesPreference);
|
||||
screen.addPreference(installKeyboardOrDictionary);
|
||||
screen.addPreference(displayLanguagePreference);
|
||||
screen.addPreference(adjustKeyboardHeight);
|
||||
screen.addPreference(spacebarTextPreference);
|
||||
|
||||
screen.addPreference(setSystemKeyboardPreference);
|
||||
|
|
|
|||
|
|
@ -260,6 +260,7 @@ public class MainActivity extends BaseActivity implements OnKeyboardEventListene
|
|||
super.onResume();
|
||||
KMManager.onResume();
|
||||
KMManager.hideSystemKeyboard();
|
||||
resizeTextView(textView.isKeyboardVisible());
|
||||
|
||||
KMManager.addKeyboardEventListener(this);
|
||||
KMKeyboardDownloaderActivity.addKeyboardDownloadEventListener(this);
|
||||
|
|
@ -576,7 +577,7 @@ public class MainActivity extends BaseActivity implements OnKeyboardEventListene
|
|||
}
|
||||
}
|
||||
|
||||
private void resizeTextView(boolean isKeyboardVisible) {
|
||||
public void resizeTextView(boolean isKeyboardVisible) {
|
||||
int bannerHeight = 0;
|
||||
int keyboardHeight = 0;
|
||||
if (isKeyboardVisible) {
|
||||
|
|
|
|||
BIN
android/KMAPro/kMAPro/src/main/res/drawable-hdpi/ic_height.png
Normal file
|
After Width: | Height: | Size: 159 B |
BIN
android/KMAPro/kMAPro/src/main/res/drawable-hdpi/ic_keyboard.png
Normal file
|
After Width: | Height: | Size: 201 B |
BIN
android/KMAPro/kMAPro/src/main/res/drawable-mdpi/ic_height.png
Normal file
|
After Width: | Height: | Size: 159 B |
BIN
android/KMAPro/kMAPro/src/main/res/drawable-mdpi/ic_keyboard.png
Normal file
|
After Width: | Height: | Size: 201 B |
BIN
android/KMAPro/kMAPro/src/main/res/drawable-xhdpi/ic_height.png
Normal file
|
After Width: | Height: | Size: 164 B |
|
After Width: | Height: | Size: 189 B |
BIN
android/KMAPro/kMAPro/src/main/res/drawable-xxhdpi/ic_height.png
Normal file
|
After Width: | Height: | Size: 336 B |
|
After Width: | Height: | Size: 392 B |
|
After Width: | Height: | Size: 396 B |
|
After Width: | Height: | Size: 494 B |
11
android/KMAPro/kMAPro/src/main/res/drawable/dash_border.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Dash border from https://www.android-examples.com/add-dash-dotted-border-around-to-button-in-android/ -->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/keyman_red"/>
|
||||
<corners android:radius="10dp" />
|
||||
<stroke android:width="3dp" android:dashWidth="12dp" android:color="@color/ms_black" android:dashGap="5dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<include layout="@layout/titlebar" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/drag_the_keyboard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/titlebar"
|
||||
android:layout_marginStart="@dimen/activity_horizontal_margin"
|
||||
android:text="@string/drag_the_keyboard"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/rotate_the_device"
|
||||
android:layout_below="@id/drag_the_keyboard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/activity_horizontal_margin"
|
||||
android:text="@string/rotate_the_device"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/reset_to_defaults"
|
||||
style="@style/Widget.AppCompat.Button.Colored"
|
||||
android:background="@color/keyman_blue"
|
||||
android:textColor="@color/ms_white"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/rotate_the_device"
|
||||
android:layout_centerInParent="true"
|
||||
android:singleLine="true"
|
||||
android:layout_marginTop="8dp"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="@string/reset_to_defaults" />
|
||||
|
||||
<!-- Resizable keyboard "image -->
|
||||
<ImageView
|
||||
android:id="@+id/sample_keyboard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/keyboard_height"
|
||||
android:contentDescription="@string/adjust_keyboard_height"
|
||||
android:background="@drawable/dash_border"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:paddingStart="@dimen/close_button_margin"
|
||||
android:paddingEnd="@dimen/close_button_margin"
|
||||
android:src="@drawable/keyman_logo"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:layout_width="@dimen/preference_icon"
|
||||
android:layout_height="@dimen/preference_icon"
|
||||
android:src="@drawable/ic_height" />
|
||||
<ImageView
|
||||
android:layout_width="@dimen/preference_icon"
|
||||
android:layout_height="@dimen/preference_icon"
|
||||
android:src="@drawable/ic_keyboard" />
|
||||
</LinearLayout>
|
||||
|
|
@ -104,6 +104,9 @@
|
|||
<!-- Context: Keyman Settings menu -->
|
||||
<string name="change_display_language" comment="Menu action to change interface language">Display language</string>
|
||||
|
||||
<!-- Context: Keyman Settings menu -->
|
||||
<string name="adjust_keyboard_height" comment="Menu action to adjust keyboard height">Adjust keyboard height</string>
|
||||
|
||||
<!-- Context: Keyman Settings menu -->
|
||||
<string name="spacebar_caption" comment="Menu action to set the spacebar caption">Spacebar caption</string>
|
||||
|
||||
|
|
@ -177,6 +180,15 @@
|
|||
<!-- Context: Select Package and Select Languages menu -->
|
||||
<string name="all_languages_installed" comment="Text when all languages from a keyboard package have been installed">All languages already installed</string>
|
||||
|
||||
<!-- Context: Adjust Keyboard Height menu -->
|
||||
<string name="drag_the_keyboard" comment="First line of adjusting keyboard height">Drag the keyboard to resize the height</string>
|
||||
|
||||
<!-- Context: Adjust Keyboard Height menu -->
|
||||
<string name="rotate_the_device" comment="Second line of adjusting keyboard height">Rotate the device to adjust portrait and landscape</string>
|
||||
|
||||
<!-- Context: Adjust Keyboard Height menu -->
|
||||
<string name="reset_to_defaults" comment="Button to reset to default heights">Reset to Defaults</string>
|
||||
|
||||
|
||||
<!-- Context: Keyman Web Browser -->
|
||||
<string name="hint_text" comment="Prompt to type in the browser search bar">Search or type URL</string>
|
||||
|
|
|
|||
|
|
@ -230,6 +230,8 @@ public final class KMManager {
|
|||
public static final String KMKey_FontFamily = "family";
|
||||
public static final String KMKey_KeyboardModified = "lastModified";
|
||||
public static final String KMKey_KeyboardRTL = "rtl";
|
||||
public static final String KMKey_KeyboardHeightPortrait = "keyboardHeightPortrait";
|
||||
public static final String KMKey_KeyboardHeightLandscape = "keyboardHeightLandscape";
|
||||
|
||||
public static final String KMKey_CustomHelpLink = "CustomHelpLink";
|
||||
public static final String KMKey_KMPLink = "kmp";
|
||||
|
|
@ -1650,7 +1652,29 @@ public final class KMManager {
|
|||
}
|
||||
|
||||
public static int getKeyboardHeight(Context context) {
|
||||
return (int) context.getResources().getDimension(R.dimen.keyboard_height);
|
||||
int defaultHeight = (int) context.getResources().getDimension(R.dimen.keyboard_height);
|
||||
SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE);
|
||||
int orientation = context.getResources().getConfiguration().orientation;
|
||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, defaultHeight);
|
||||
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, defaultHeight);
|
||||
}
|
||||
|
||||
return defaultHeight;
|
||||
}
|
||||
|
||||
public static void setKeyboardHeight(Context context, int height) {
|
||||
if (InAppKeyboard != null && InAppKeyboardLoaded) {
|
||||
InAppKeyboard.loadJavascript(KMString.format("setOskHeight('%s')", height));
|
||||
RelativeLayout.LayoutParams params = getKeyboardLayoutParams();
|
||||
InAppKeyboard.setLayoutParams(params);
|
||||
}
|
||||
if (SystemKeyboard != null && SystemKeyboardLoaded) {
|
||||
SystemKeyboard.loadJavascript(KMString.format("setOskHeight('%s')", height));
|
||||
RelativeLayout.LayoutParams params = getKeyboardLayoutParams();
|
||||
SystemKeyboard.setLayoutParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setDebugMode(boolean value) {
|
||||
|
|
|
|||