Merge remote-tracking branch 'upstream/master' into system-accent-alpha

This commit is contained in:
Trevor Terris 2021-11-22 12:02:46 -05:00
commit 0eae23062d
14 changed files with 113 additions and 28 deletions

View file

@ -52,6 +52,7 @@ public final class KeyboardIconsSet {
public static final String NAME_PREVIOUS_KEY = "previous_key";
public static final String NAME_TAB_KEY = "tab_key";
public static final String NAME_SHORTCUT_KEY = "shortcut_key";
public static final String NAME_CLIPBOARD_KEY = "clipboard_key";
public static final String NAME_INCOGNITO_KEY = "incognito_key";
public static final String NAME_SHORTCUT_KEY_DISABLED = "shortcut_key_disabled";
public static final String NAME_LANGUAGE_SWITCH_KEY = "language_switch_key";
@ -80,6 +81,7 @@ public final class KeyboardIconsSet {
NAME_PREVIOUS_KEY, R.styleable.Keyboard_iconPreviousKey,
NAME_TAB_KEY, R.styleable.Keyboard_iconTabKey,
NAME_SHORTCUT_KEY, R.styleable.Keyboard_iconShortcutKey,
NAME_CLIPBOARD_KEY, R.styleable.Keyboard_iconClipboardKey,
NAME_INCOGNITO_KEY, R.styleable.Keyboard_iconIncognitoKey,
NAME_SPACE_KEY_FOR_NUMBER_LAYOUT, R.styleable.Keyboard_iconSpaceKeyForNumberLayout,
NAME_SHIFT_KEY_SHIFTED, R.styleable.Keyboard_iconShiftKeyShifted,

View file

@ -1117,6 +1117,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
public CharSequence getSelection() {
return mInputLogic.mConnection.getSelectedText(0);
}
/**
* This is called when the user has clicked on the extracted text view,
* when running in fullscreen mode. The default implementation hides
@ -1584,10 +1588,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
currentSettingsValues.mInputAttributes.mShouldShowSuggestions
&& currentSettingsValues.isSuggestionsEnabledPerUserSettings();
final boolean shouldShowSuggestionsStripUnlessPassword = currentSettingsValues.mShowsVoiceInputKey
|| currentSettingsValues.mShowsClipboardKey
|| shouldShowSuggestionCandidates
|| currentSettingsValues.isApplicationSpecifiedCompletionsOn();
final boolean shouldShowSuggestionsStrip = shouldShowSuggestionsStripUnlessPassword
&& !currentSettingsValues.mInputAttributes.mIsPasswordField;
&& (!currentSettingsValues.mInputAttributes.mIsPasswordField || currentSettingsValues.mShowsClipboardKey);
mSuggestionStripView.updateVisibility(shouldShowSuggestionsStrip, isFullscreenMode());
if (!shouldShowSuggestionsStrip) {
return;

View file

@ -56,6 +56,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
// PREF_VOICE_MODE_OBSOLETE is obsolete. Use PREF_VOICE_INPUT_KEY instead.
public static final String PREF_VOICE_MODE_OBSOLETE = "voice_mode";
public static final String PREF_VOICE_INPUT_KEY = "pref_voice_input_key";
public static final String PREF_CLIPBOARD_CLIPBOARD_KEY = "pref_clipboard_clipboard_key";
public static final String PREF_EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary";
// PREF_AUTO_CORRECTION_THRESHOLD_OBSOLETE is obsolete. Use PREF_AUTO_CORRECTION instead.
public static final String PREF_AUTO_CORRECTION_THRESHOLD_OBSOLETE =
@ -77,6 +78,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
"pref_show_language_switch_key";
public static final String PREF_SHOW_EMOJI_KEY =
"pref_show_emoji_key";
public static final String PREF_SHOW_CLIPBOARD_KEY =
"pref_show_clipboard_key";
public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST =
"pref_include_other_imes_in_language_switch_list";
public static final String PREF_CUSTOM_INPUT_STYLES = "custom_input_styles";

View file

@ -73,6 +73,7 @@ public class SettingsValues {
public final boolean mShowsHints;
public final boolean mShowsLanguageSwitchKey;
public final boolean mShowsEmojiKey;
public final boolean mShowsClipboardKey;
public final boolean mUsePersonalizedDicts;
public final boolean mUseDoubleSpacePeriod;
public final boolean mBlockPotentiallyOffensive;
@ -149,6 +150,7 @@ public class SettingsValues {
mShowsHints = prefs.getBoolean(Settings.PREF_SHOW_HINTS, true);
mShowsLanguageSwitchKey = prefs.getBoolean(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, false);
mShowsEmojiKey = prefs.getBoolean(Settings.PREF_SHOW_EMOJI_KEY, false);
mShowsClipboardKey = prefs.getBoolean(Settings.PREF_SHOW_CLIPBOARD_KEY, false);
mUsePersonalizedDicts = prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true);
mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true)
&& inputAttributes.mIsGeneralTextInput;
@ -188,7 +190,8 @@ public class SettingsValues {
//&& !mInputAttributes.mInputTypeNoAutoCorrect;
mSuggestionsEnabledPerUserSettings = !mInputAttributes.mIsPasswordField &&
readSuggestionsEnabled(prefs);
mIncognitoModeEnabled = Settings.readAlwaysIncognitoMode(prefs) || mInputAttributes.mNoLearning;
mIncognitoModeEnabled = Settings.readAlwaysIncognitoMode(prefs) || mInputAttributes.mNoLearning
|| mInputAttributes.mIsPasswordField;
mIsInternal = Settings.isInternal(prefs);
mHasCustomKeyPreviewAnimationParams = prefs.getBoolean(
DebugSettings.PREF_HAS_CUSTOM_KEY_PREVIEW_ANIMATION_PARAMS, false);

View file

@ -16,6 +16,8 @@
package org.dslul.openboard.inputmethod.latin.suggestions;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
@ -59,6 +61,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
public interface Listener {
void pickSuggestionManually(SuggestedWordInfo word);
void onCodeInput(int primaryCode, int x, int y, boolean isKeyRepeat);
void onTextInput(final String rawText);
CharSequence getSelection();
}
static final boolean DBG = DebugFlags.DEBUG_ENABLED;
@ -66,6 +70,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
private final ViewGroup mSuggestionsStrip;
private final ImageButton mVoiceKey;
private final ImageButton mClipboardKey;
private final ImageButton mOtherKey;
MainKeyboardView mMainKeyboardView;
@ -126,6 +131,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mSuggestionsStrip = findViewById(R.id.suggestions_strip);
mVoiceKey = findViewById(R.id.suggestions_strip_voice_key);
mClipboardKey = findViewById(R.id.suggestions_strip_clipboard_key);
mOtherKey = findViewById(R.id.suggestions_strip_other_key);
mStripVisibilityGroup = new StripVisibilityGroup(this, mSuggestionsStrip);
@ -161,9 +167,13 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
R.styleable.Keyboard, defStyle, R.style.SuggestionStripView);
final Drawable iconVoice = keyboardAttr.getDrawable(R.styleable.Keyboard_iconShortcutKey);
final Drawable iconIncognito = keyboardAttr.getDrawable(R.styleable.Keyboard_iconIncognitoKey);
final Drawable iconClipboard = keyboardAttr.getDrawable(R.styleable.Keyboard_iconClipboardKey);
keyboardAttr.recycle();
mVoiceKey.setImageDrawable(iconVoice);
mVoiceKey.setOnClickListener(this);
mClipboardKey.setImageDrawable(iconClipboard);
mClipboardKey.setOnClickListener(this);
mClipboardKey.setOnLongClickListener(this);
mOtherKey.setImageDrawable(iconIncognito);
}
@ -181,7 +191,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
final int visibility = shouldBeVisible ? VISIBLE : (isFullscreenMode ? GONE : INVISIBLE);
setVisibility(visibility);
final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent();
mVoiceKey.setVisibility(currentSettingsValues.mShowsVoiceInputKey ? VISIBLE : INVISIBLE);
mVoiceKey.setVisibility(currentSettingsValues.mShowsVoiceInputKey ? VISIBLE : GONE);
mClipboardKey.setVisibility(currentSettingsValues.mShowsClipboardKey ? VISIBLE : (mVoiceKey.getVisibility() == GONE ? INVISIBLE : GONE));
mOtherKey.setVisibility(currentSettingsValues.mIncognitoModeEnabled ? VISIBLE : INVISIBLE);
}
@ -256,6 +267,23 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
@Override
public boolean onLongClick(final View view) {
if (view == mClipboardKey) {
ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = clipboardManager.getPrimaryClip();
if (clipData != null && clipData.getItemCount() > 0 && clipData.getItemAt(0) != null) {
String clipString = clipData.getItemAt(0).coerceToText(getContext()).toString();
if (clipString.length() == 1) {
mListener.onTextInput(clipString);
} else if (clipString.length() > 1) {
//awkward workaround
mListener.onTextInput(clipString.substring(0, clipString.length() - 1));
mListener.onTextInput(clipString.substring(clipString.length() - 1));
}
}
AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback(
Constants.NOT_A_CODE, this);
return true;
}
AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback(
Constants.NOT_A_CODE, this);
return showMoreSuggestions();
@ -413,6 +441,15 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
false /* isKeyRepeat */);
return;
}
if (view == mClipboardKey) {
CharSequence selectionSequence = mListener.getSelection();
if (selectionSequence != null && selectionSequence.length() > 0
&& !Settings.getInstance().getCurrent().mInputAttributes.mIsPasswordField) {
ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
clipboardManager.setPrimaryClip(ClipData.newPlainText(selectionSequence, selectionSequence));
}
return;
}
final Object tag = view.getTag();
// {@link Integer} tag is set at

View file

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#CACACA"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19,2h-4.18C14.4,0.84 13.3,0 12,0c-1.3,0 -2.4,0.84 -2.82,2L5,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM12,2c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM19,20L5,20L5,4h2v3h10L17,4h2v16z"/>
</vector>

View file

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#414141"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19,2h-4.18C14.4,0.84 13.3,0 12,0c-1.3,0 -2.4,0.84 -2.82,2L5,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM12,2c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM19,20L5,20L5,4h2v3h10L17,4h2v16z"/>
</vector>

View file

@ -20,34 +20,45 @@
<merge
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's audio and haptic feedback settings. -->
<LinearLayout
android:id="@+id/suggestions_strip"
android:id="@+id/suggestions_strip_wrapper"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/config_suggestions_strip_horizontal_margin"
android:layout_marginRight="@dimen/config_suggestions_strip_horizontal_margin"
android:hapticFeedbackEnabled="false"
android:soundEffectsEnabled="false" />
<!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's audio and haptic feedback settings. -->
<ImageButton
android:id="@+id/suggestions_strip_other_key"
android:layout_width="@dimen/config_suggestions_strip_edge_key_width"
android:layout_height="fill_parent"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
style="?attr/suggestionWordStyle"
android:contentDescription="@string/more_keys_strip_description" />
<ImageButton
android:id="@+id/suggestions_strip_voice_key"
android:layout_width="@dimen/config_suggestions_strip_edge_key_width"
android:layout_height="fill_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:contentDescription="@string/spoken_description_mic"
style="?attr/suggestionWordStyle" />
android:soundEffectsEnabled="false">
<!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's audio and haptic feedback settings. -->
<ImageButton
android:id="@+id/suggestions_strip_other_key"
android:layout_width="@dimen/config_suggestions_strip_edge_key_width"
android:layout_height="fill_parent"
android:layout_weight="0"
style="?attr/suggestionWordStyle"
android:contentDescription="@string/more_keys_strip_description" />
<!-- Provide audio and haptic feedback by ourselves based on the keyboard settings.
We just need to ignore the system's audio and haptic feedback settings. -->
<LinearLayout
android:id="@+id/suggestions_strip"
android:orientation="horizontal"
android:maxWidth="100dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:hapticFeedbackEnabled="false"
android:soundEffectsEnabled="false" />
<ImageButton
android:id="@+id/suggestions_strip_voice_key"
android:layout_width="@dimen/config_suggestions_strip_edge_key_width"
android:layout_height="fill_parent"
android:contentDescription="@string/spoken_description_mic"
style="?attr/suggestionWordStyle" />
<ImageButton
android:id="@+id/suggestions_strip_clipboard_key"
android:layout_width="@dimen/config_suggestions_strip_edge_key_width"
android:scaleType="fitCenter"
android:layout_height="fill_parent"
android:contentDescription="@string/spoken_description_mic"
style="?attr/suggestionWordStyle" />
</LinearLayout>
</merge>

View file

@ -270,6 +270,7 @@
<attr name="iconPreviousKey" format="reference" />
<attr name="iconTabKey" format="reference" />
<attr name="iconShortcutKey" format="reference" />
<attr name="iconClipboardKey" format="reference" />
<attr name="iconIncognitoKey" format="reference" />
<attr name="iconSpaceKeyForNumberLayout" format="reference" />
<attr name="iconShiftKeyShifted" format="reference" />

View file

@ -29,6 +29,7 @@
<item name="iconSearchKey">@drawable/sym_keyboard_search_holo_dark</item>
<item name="iconTabKey">@drawable/sym_keyboard_tab_holo_dark</item>
<item name="iconShortcutKey">@drawable/sym_keyboard_voice_holo_dark</item>
<item name="iconClipboardKey">@drawable/sym_keyboard_clipboard_dark</item>
<item name="iconIncognitoKey">@drawable/sym_keyboard_incognito_dark</item>
<item name="iconSpaceKeyForNumberLayout">@drawable/sym_keyboard_space_holo_dark</item>
<item name="iconShiftKeyShifted">@drawable/sym_keyboard_shift_locked_holo_dark</item>

View file

@ -36,6 +36,7 @@
<item name="iconPreviousKey">@drawable/sym_keyboard_previous_lxx_dark</item>
<item name="iconShortcutKey">@drawable/sym_keyboard_voice_lxx_dark</item>
<item name="iconShortcutKeyDisabled">@drawable/sym_keyboard_voice_off_lxx_dark</item>
<item name="iconClipboardKey">@drawable/sym_keyboard_clipboard_dark</item>
<item name="iconIncognitoKey">@drawable/sym_keyboard_incognito_lxx_dark</item>
<item name="iconSpaceKeyForNumberLayout">@drawable/sym_keyboard_space_lxx_dark</item>
<item name="iconLanguageSwitchKey">@drawable/sym_keyboard_language_switch_lxx_dark</item>

View file

@ -36,6 +36,7 @@
<item name="iconPreviousKey">@drawable/sym_keyboard_previous_lxx_light</item>
<item name="iconShortcutKey">@drawable/sym_keyboard_voice_lxx_light</item>
<item name="iconShortcutKeyDisabled">@drawable/sym_keyboard_voice_off_lxx_light</item>
<item name="iconClipboardKey">@drawable/sym_keyboard_clipboard_light</item>
<item name="iconIncognitoKey">@drawable/sym_keyboard_incognito_lxx_light</item>
<item name="iconSpaceKeyForNumberLayout">@drawable/sym_keyboard_space_lxx_light</item>
<item name="iconLanguageSwitchKey">@drawable/sym_keyboard_language_switch_lxx_light</item>

View file

@ -179,6 +179,10 @@
<!-- The summary text to describe the reason why the "Voice input key" option is disabled. [CHAR LIMIT=100] -->
<string name="voice_input_disabled_summary">No voice input methods enabled. Check Languages&#160;&amp; input settings.</string>
<!-- Preferences item for enabling pasting from keyboard -->
<string name="show_clipboard_key">Clipboard key</string>
<string name="show_clipboard_key_summary">Press to copy, long-press to paste.</string>
<!-- Title for configuring input method settings [CHAR LIMIT=35] -->
<string name="configure_input_method">Configure input methods</string>

View file

@ -71,4 +71,10 @@
android:title="@string/voice_input"
android:defaultValue="true"
android:persistent="true" />
<CheckBoxPreference
android:key="pref_show_clipboard_key"
android:title="@string/show_clipboard_key"
android:summary="@string/show_clipboard_key_summary"
android:defaultValue="false"
android:persistent="true" />
</PreferenceScreen>