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