Skip to content

Commit

Permalink
Hide s/w keyboard when h/w keyboard exists on L+
Browse files Browse the repository at this point in the history
With this CL, software keyboard will be completely hidden when at least
one physical keyboard is available on Android L and later since we can
rely on CursorAnchorInfo API to show the mode indicator for those
devices.

BUG=
TEST=compile
REF_BUG=18078423
REF_CL=83479761,83912272
  • Loading branch information
sumita12 committed Jan 7, 2015
1 parent 0ccaad3 commit bf51ad0
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -587,11 +587,6 @@ public void handleMessage(Message msg) {
@VisibleForTesting KeyboardSpecification currentKeyboardSpecification =
KeyboardSpecification.TWELVE_KEY_TOGGLE_KANA;

// Current HardKeyboardHidden configuration value.
// This is updated only when onConfigurationChanged is called and
// Configuration.HARDKEYBOARDHIDDEN_* differs to this.
private int currentHardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_UNDEFINED;

@VisibleForTesting boolean inputBound = false;

private ApplicationCompatibility applicationCompatibility =
Expand Down Expand Up @@ -726,8 +721,6 @@ private void prepareEveryTime(
sessionExecutor.setConfig(ConfigUtil.toConfig(sharedPreferences));
sessionExecutor.preferenceUsageStatsEvent(sharedPreferences, getResources());
}

maybeSetNarrowMode(deviceConfiguration);
}

/**
Expand Down Expand Up @@ -1619,31 +1612,6 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}
}

@VisibleForTesting void maybeSetNarrowMode(Configuration configuration) {
// If given hardKeyboardHidden is equal to current one, skip updating narrow mode.
// In other words, only hardKeyboardHidden flag changes narrow mode automatically.
// This behavior is beneficial for a user who want to change narrow/full mode manually
// because this method keeps current narrow mode unless hardware keyboard connection is changed.
if (viewManager != null && configuration.hardKeyboardHidden != currentHardKeyboardHidden) {
currentHardKeyboardHidden = configuration.hardKeyboardHidden;
switch (currentHardKeyboardHidden) {
case Configuration.HARDKEYBOARDHIDDEN_NO:
if (!viewManager.isNarrowMode()) {
viewManager.hideSubInputView();
viewManager.setNarrowMode(true);
}
break;
case Configuration.HARDKEYBOARDHIDDEN_YES:
if (viewManager.isNarrowMode()) {
viewManager.setNarrowMode(false);
}
break;
case Configuration.HARDKEYBOARDHIDDEN_UNDEFINED:
break;
}
}
}

@VisibleForTesting void onConfigurationChangedInternal(Configuration newConfig) {
InputConnection inputConnection = getCurrentInputConnection();
if (inputConnection != null) {
Expand Down Expand Up @@ -1680,7 +1648,6 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
propagateClientSidePreference(new ClientSidePreference(
Preconditions.checkNotNull(PreferenceManager.getDefaultSharedPreferences(this)),
getResources(), newConfig.orientation));
maybeSetNarrowMode(newConfig);
viewManager.onConfigurationChanged(newConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.inputmethodservice.InputMethodService.Insets;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
Expand Down Expand Up @@ -101,8 +103,10 @@ public DimensionPixelSize(Resources resources) {
imeWindowPartialWidth = resources.getDimensionPixelSize(R.dimen.ime_window_partial_width);
imeWindowRegionInsetThreshold = resources.getDimensionPixelSize(
R.dimen.ime_window_region_inset_threshold);
narrowFrameHeight = resources.getDimensionPixelSize(R.dimen.narrow_frame_height);
narrowImeWindowHeight = resources.getDimensionPixelSize(R.dimen.narrow_ime_window_height);
narrowFrameHeight = getNarrowFrameHeight(resources);
narrowImeWindowHeight =
resources.getDimensionPixelSize(R.dimen.narrow_candidate_window_height)
+ narrowFrameHeight;
sideFrameWidth = resources.getDimensionPixelSize(R.dimen.side_frame_width);
buttonFrameHeight = resources.getDimensionPixelSize(R.dimen.button_frame_height);
}
Expand Down Expand Up @@ -200,6 +204,12 @@ public void onVisibilityChange() {
}
};

/**
* Narrow frame is disabled on API 21 or later to respect
* {@link Configuration#hardKeyboardHidden}.
*/
@VisibleForTesting static final boolean IS_NARROW_FRAME_ENABLED = Build.VERSION.SDK_INT < 21;

private final DimensionPixelSize dimensionPixelSize = new DimensionPixelSize(getResources());
private final SideFrameStubProxy leftFrameStubProxy = new SideFrameStubProxy();
private final SideFrameStubProxy rightFrameStubProxy = new SideFrameStubProxy();
Expand Down Expand Up @@ -698,7 +708,7 @@ public void setLayoutAdjustmentAndNarrowMode(LayoutAdjustment layoutAdjustment,
rightFrameStubProxy.setFrameVisibility(
temporaryAdjustment == LayoutAdjustment.LEFT ? VISIBLE : GONE);

// Set candidate and desciption text size.
// Set candidate and description text size.
float candidateTextSize = layoutAdjustment == LayoutAdjustment.FILL
? resources.getDimension(R.dimen.candidate_text_size)
: resources.getDimension(R.dimen.candidate_text_size_aligned_layout);
Expand All @@ -713,7 +723,7 @@ public void setLayoutAdjustmentAndNarrowMode(LayoutAdjustment layoutAdjustment,
if (narrowMode) {
getKeyboardFrame().setVisibility(GONE);
getButtonFrame().setVisibility(GONE);
getNarrowFrame().setVisibility(VISIBLE);
getNarrowFrame().setVisibility(IS_NARROW_FRAME_ENABLED ? VISIBLE : GONE);
} else {
getKeyboardFrame().setVisibility(VISIBLE);
getButtonFrame().setVisibility(buttonFrameVisible ? VISIBLE : GONE);
Expand Down Expand Up @@ -935,6 +945,12 @@ MozcImageView getMicrophoneButton() {
return MozcImageView.class.cast(findViewById(R.id.microphone_button));
}

@VisibleForTesting
static int getNarrowFrameHeight(Resources resources) {
return IS_NARROW_FRAME_ENABLED
? resources.getDimensionPixelSize(R.dimen.narrow_frame_height) : 0;
}

@Override
public void trimMemory() {
getKeyboardView().trimMemory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,15 @@ public void invoke() {
isEmojiInvoking = false;
if (mozcView != null) {
if (isSymbolInputViewVisible) {
mozcView.hideSymbolInputView();
if (!isNarrowMode()) {
hideSubInputView();
if (!narrowMode) {
setNarrowMode(true);
}
} else {
isSymbolInputViewShownByEmojiKey = true;
if (isNarrowMode()) {
setNarrowMode(false);
if (narrowMode) {
// Turned narrow mode off on all devices for Emoji palette.
setNarrowModeWithoutVersionCheck(false);
}
mozcView.showSymbolInputView(Optional.of(SymbolMajorCategory.EMOJI));
}
Expand Down Expand Up @@ -351,6 +352,9 @@ public void reset() {
/** Current narrow mode */
private boolean narrowMode = false;

/** Current narrow mode */
private boolean narrowModeByConfiguration = false;

/** Current popup enabled state. */
private boolean popupEnabled = true;

Expand Down Expand Up @@ -656,13 +660,6 @@ public boolean hideSubInputView() {
if (mozcView == null) {
return false;
}
MozcView mozcView = this.mozcView;

if (isSymbolInputViewShownByEmojiKey) {
setNarrowMode(true);
mozcView.hideSymbolInputView();
return true;
}

// Try to hide a sub view from front to back.
if (mozcView.hideSymbolInputView()) {
Expand Down Expand Up @@ -839,19 +836,35 @@ public void updateMicrophoneButtonEnabled() {
}

/**
* @param newNarrowMode Whether mozc view shows in narrow mode or normal.
* Sets narrow mode.
* <p>
* The behavior of this method depends on API level.
* We decided to respect the configuration on API 21 or later, so this method ignores the argument
* in such case. If you really want to bypass the version check, please use
* {@link #setNarrowModeWithoutVersionCheck(boolean)} instead.
*/
@Override
public void setNarrowMode(boolean newNarrowMode) {
boolean previousNarrowMode = this.narrowMode;
this.narrowMode = newNarrowMode;
private void setNarrowMode(boolean isNarrowMode) {
if (Build.VERSION.SDK_INT >= 21) {
// Always respects configuration on Lollipop or later.
setNarrowModeWithoutVersionCheck(narrowModeByConfiguration);
} else {
setNarrowModeWithoutVersionCheck(isNarrowMode);
}
}

private void setNarrowModeWithoutVersionCheck(boolean newNarrowMode) {
if (narrowMode == newNarrowMode) {
return;
}
narrowMode = newNarrowMode;
if (newNarrowMode) {
hideSubInputView();
}
if (mozcView != null) {
mozcView.setLayoutAdjustmentAndNarrowMode(layoutAdjustment, newNarrowMode);
}
updateMicrophoneButtonEnabled();
if (previousNarrowMode != newNarrowMode) {
eventListener.onNarrowModeChanged(newNarrowMode);
}
eventListener.onNarrowModeChanged(newNarrowMode);
}

/**
Expand All @@ -868,7 +881,7 @@ public void setNarrowMode(boolean newNarrowMode) {
public void maybeTransitToNarrowMode(Command command, KeyEventInterface keyEventInterface) {
Preconditions.checkNotNull(command);
// Surely we don't anything when on narrow mode already.
if (isNarrowMode()) {
if (narrowMode) {
return;
}
// Do nothing for the input from software keyboard.
Expand All @@ -881,7 +894,6 @@ public void maybeTransitToNarrowMode(Command command, KeyEventInterface keyEvent
}

// Passed all the check. Transit to narrow mode.
hideSubInputView();
setNarrowMode(true);
}

Expand Down Expand Up @@ -1024,6 +1036,11 @@ public void computeInsets(Context context, InputMethodService.Insets outInsets,
public void onConfigurationChanged(Configuration newConfig) {
primaryKeyCodeConverter.setConfiguration(newConfig);
hardwareKeyboardExist = newConfig.keyboard != Configuration.KEYBOARD_NOKEYS;
if (newConfig.hardKeyboardHidden != Configuration.HARDKEYBOARDHIDDEN_UNDEFINED){
narrowModeByConfiguration =
newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO;
setNarrowMode(narrowModeByConfiguration);
}
}

@Override
Expand Down Expand Up @@ -1165,6 +1182,9 @@ public void onShowSymbolInputView() {

@Override
public void onCloseSymbolInputView() {
if (isSymbolInputViewShownByEmojiKey) {
setNarrowMode(true);
}
isSymbolInputViewVisible = false;
isSymbolInputViewShownByEmojiKey = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ public enum LayoutAdjustment {

public void setEmojiProviderType(EmojiProviderType emojiProviderType);

/**
* @param isNarrowMode Whether mozc view shows in narrow mode or normal.
*/
public void setNarrowMode(boolean isNarrowMode);

public void maybeTransitToNarrowMode(Command command, KeyEventInterface keyEvent);

public boolean isNarrowMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@
<dimen name="firsttime_padding_height">28dip</dimen>
<dimen name="firsttime_padding_width">40dip</dimen>

<!-- 3.5 Rows of candidates -->
<!-- (candidate_text_size + candidate_vertical_padding_size * 2) * 3.5
+ narrow_frame_height -->
<dimen name="narrow_ime_window_height">221dip</dimen>
<!-- 2 rows of candidates -->
<!-- (candidate_text_size + candidate_vertical_padding_size * 2) * 2 -->
<dimen name="narrow_candidate_window_height">100dip</dimen>
<dimen name="narrow_frame_height">46dip</dimen>
<!-- symbol_view_height = input_frame_height + (candidate_text_size + candidate_vertical_padding_size * 2) -->
<dimen name="symbol_view_height">305dip</dimen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@
<dimen name="firsttime_padding_height">28dip</dimen>
<dimen name="firsttime_padding_width">40dip</dimen>

<!-- 3.5 Rows of candidates -->
<!-- (candidate_text_size + candidate_vertical_padding_size * 2) * 3.5
+ narrow_frame_height -->
<dimen name="narrow_ime_window_height">221dip</dimen>
<!-- 3 rows of candidates -->
<!-- (candidate_text_size + candidate_vertical_padding_size * 2) * 3 -->
<dimen name="narrow_candidate_window_height">150dip</dimen>
<!-- symbol_view_height = input_frame_height + (candidate_text_size + candidate_vertical_padding_size * 2) -->
<dimen name="symbol_view_height">352.4dip</dimen>
<!-- symbol_view_number_keyboard_height = input_frame_height - symbol_view_major_category_height -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@
<dimen name="firsttime_description_text_size">14dip</dimen>
<dimen name="firsttime_padding_height">14dip</dimen>
<dimen name="firsttime_padding_width">20dip</dimen>
<dimen name="narrow_ime_window_height">126dip</dimen>
<!-- 2 rows of candidates -->
<!-- (candidate_text_size + candidate_vertical_padding_size * 2) * 2 -->
<dimen name="narrow_candidate_window_height">80dip</dimen>
<dimen name="narrow_frame_height">41dip</dimen>


Expand Down
Loading

0 comments on commit bf51ad0

Please sign in to comment.