Use dedicated layout for "touch to save word" feature
Change-Id: Ie8c948476740a645d8b2d9a9d821236941d27adfmain
parent
7fb04fe007
commit
717a8f50ae
|
@ -22,42 +22,10 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
|
||||
>
|
||||
<RelativeLayout
|
||||
android:layout_weight="1.0"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
>
|
||||
<include
|
||||
android:id="@+id/word_left"
|
||||
layout="@layout/candidate_word" />
|
||||
<include
|
||||
android:id="@+id/info_left"
|
||||
layout="@layout/candidate_info" />
|
||||
</RelativeLayout>
|
||||
<include
|
||||
layout="@layout/candidate_divider" />
|
||||
<RelativeLayout
|
||||
android:layout_weight="1.0"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
>
|
||||
<include
|
||||
android:id="@+id/word_center"
|
||||
layout="@layout/candidate_word" />
|
||||
<include
|
||||
android:id="@+id/info_center"
|
||||
layout="@layout/candidate_info" />
|
||||
</RelativeLayout>
|
||||
<include
|
||||
layout="@layout/candidate_divider" />
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_weight="1.0"
|
||||
android:layout_width="0dp"
|
||||
android:id="@+id/candidates_strip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
>
|
||||
<RelativeLayout
|
||||
android:layout_weight="1.0"
|
||||
|
@ -66,24 +34,89 @@
|
|||
android:gravity="center"
|
||||
>
|
||||
<include
|
||||
android:id="@+id/word_right"
|
||||
android:id="@+id/word_left"
|
||||
layout="@layout/candidate_word" />
|
||||
<include
|
||||
android:id="@+id/info_right"
|
||||
android:id="@+id/info_left"
|
||||
layout="@layout/candidate_info" />
|
||||
</RelativeLayout>
|
||||
<!-- Image drawables are set in CandidateView constructor -->
|
||||
<ImageButton
|
||||
android:id="@+id/expand_candidates_pane"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
style="?attr/suggestionsStripBackgroundStyle" />
|
||||
<ImageButton
|
||||
android:id="@+id/close_candidates_pane"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
style="?attr/suggestionsStripBackgroundStyle" />
|
||||
<include
|
||||
layout="@layout/candidate_divider" />
|
||||
<RelativeLayout
|
||||
android:layout_weight="1.0"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
>
|
||||
<include
|
||||
android:id="@+id/word_center"
|
||||
layout="@layout/candidate_word" />
|
||||
<include
|
||||
android:id="@+id/info_center"
|
||||
layout="@layout/candidate_info" />
|
||||
</RelativeLayout>
|
||||
<include
|
||||
layout="@layout/candidate_divider" />
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_weight="1.0"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
>
|
||||
<RelativeLayout
|
||||
android:layout_weight="1.0"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
>
|
||||
<include
|
||||
android:id="@+id/word_right"
|
||||
layout="@layout/candidate_word" />
|
||||
<include
|
||||
android:id="@+id/info_right"
|
||||
layout="@layout/candidate_info" />
|
||||
</RelativeLayout>
|
||||
<!-- Image drawables are set in CandidateView constructor -->
|
||||
<ImageButton
|
||||
android:id="@+id/expand_candidates_pane"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
style="?attr/suggestionsStripBackgroundStyle" />
|
||||
<ImageButton
|
||||
android:id="@+id/close_candidates_pane"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
style="?attr/suggestionsStripBackgroundStyle" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/touch_to_save"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone"
|
||||
>
|
||||
<Button
|
||||
android:id="@+id/word_to_save"
|
||||
android:layout_weight="1.0"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:textSize="@dimen/candidate_text_size"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="middle"
|
||||
style="?attr/suggestionBackgroundStyle" />
|
||||
<include
|
||||
layout="@layout/candidate_divider" />
|
||||
<TextView
|
||||
android:layout_weight="2.0"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="left|center_vertical"
|
||||
android:text="@string/hint_add_to_dictionary"
|
||||
android:textSize="@dimen/candidate_text_size"
|
||||
android:background="@null" />
|
||||
</LinearLayout>
|
||||
</merge>
|
||||
|
|
|
@ -66,6 +66,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
|
||||
private static final boolean DBG = LatinImeLogger.sDBG;
|
||||
|
||||
private final View mCandidatesStrip;
|
||||
private static final int NUM_CANDIDATES_IN_STRIP = 3;
|
||||
private final ImageView mExpandCandidatesPane;
|
||||
private final ImageView mCloseCandidatesPane;
|
||||
|
@ -88,6 +89,9 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
private final PopupWindow mPreviewPopup;
|
||||
private final TextView mPreviewText;
|
||||
|
||||
private final View mTouchToSave;
|
||||
private final TextView mWordToSave;
|
||||
|
||||
private Listener mListener;
|
||||
private SuggestedWords mSuggestions = SuggestedWords.EMPTY;
|
||||
private boolean mShowingAutoCorrectionInverted;
|
||||
|
@ -178,6 +182,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
mPreviewPopup.setContentView(mPreviewText);
|
||||
mPreviewPopup.setBackgroundDrawable(null);
|
||||
|
||||
mCandidatesStrip = findViewById(R.id.candidates_strip);
|
||||
mCandidateStripHeight = res.getDimensionPixelOffset(R.dimen.candidate_strip_height);
|
||||
for (int i = 0; i < MAX_SUGGESTIONS; i++) {
|
||||
final TextView word, info;
|
||||
|
@ -213,6 +218,10 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
}
|
||||
}
|
||||
|
||||
mTouchToSave = findViewById(R.id.touch_to_save);
|
||||
mWordToSave = (TextView)findViewById(R.id.word_to_save);
|
||||
mWordToSave.setOnClickListener(this);
|
||||
|
||||
final TypedArray a = context.obtainStyledAttributes(
|
||||
attrs, R.styleable.CandidateView, defStyle, R.style.CandidateViewStyle);
|
||||
mAutoCorrectHighlight = a.getInt(R.styleable.CandidateView_autoCorrectHighlight, 0);
|
||||
|
@ -448,14 +457,10 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
}
|
||||
|
||||
public void showAddToDictionaryHint(CharSequence word) {
|
||||
SuggestedWords.Builder builder = new SuggestedWords.Builder()
|
||||
.addWord(word)
|
||||
.addWord(getContext().getText(R.string.hint_add_to_dictionary));
|
||||
setSuggestions(builder.build());
|
||||
mWordToSave.setText(word);
|
||||
mShowingAddToDictionary = true;
|
||||
// Disable R.string.hint_add_to_dictionary button
|
||||
TextView tv = mWords.get(1);
|
||||
tv.setClickable(false);
|
||||
mCandidatesStrip.setVisibility(View.GONE);
|
||||
mTouchToSave.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public boolean dismissAddToDictionaryHint() {
|
||||
|
@ -475,6 +480,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
mWords.get(i).setText(null);
|
||||
mInfos.get(i).setVisibility(View.GONE);
|
||||
}
|
||||
mTouchToSave.setVisibility(View.GONE);
|
||||
mCandidatesStrip.setVisibility(View.VISIBLE);
|
||||
mCandidatesPane.removeAllViews();
|
||||
}
|
||||
|
||||
|
@ -530,6 +537,12 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (view == mWordToSave) {
|
||||
addToDictionary(((TextView)view).getText());
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
final Object tag = view.getTag();
|
||||
if (!(tag instanceof Integer))
|
||||
return;
|
||||
|
@ -538,11 +551,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
|
|||
return;
|
||||
|
||||
final CharSequence word = mSuggestions.getWord(index);
|
||||
if (mShowingAddToDictionary && index == 0) {
|
||||
addToDictionary(word);
|
||||
} else {
|
||||
mListener.pickSuggestionManually(index, word);
|
||||
}
|
||||
mListener.pickSuggestionManually(index, word);
|
||||
// Because some punctuation letters are not treated as word separator depending on locale,
|
||||
// {@link #setSuggestions} might not be called and candidates pane left opened.
|
||||
closeCandidatesPane();
|
||||
|
|
Loading…
Reference in New Issue