Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 717a8f50 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Use dedicated layout for "touch to save word" feature

Change-Id: Ie8c948476740a645d8b2d9a9d821236941d27adf
parent 7fb04fe0
Loading
Loading
Loading
Loading
+82 −49
Original line number Diff line number Diff line
@@ -21,6 +21,11 @@
<merge
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
>
    <LinearLayout
        android:id="@+id/candidates_strip"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    >
        <RelativeLayout
            android:layout_weight="1.0"
@@ -86,4 +91,32 @@
                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>
+21 −12
Original line number Diff line number Diff line
@@ -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);
        }
        // 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();