diff options
author | Yoshiaki Naka <yoshiaki.naka@sony.com> | 2019-02-21 17:13:38 +0900 |
---|---|---|
committer | Jack Yu <jackyu@google.com> | 2019-10-28 22:07:11 +0000 |
commit | c1efd35ac402a57d9a3c0c17e67737af30429c8e (patch) | |
tree | f47ae5eaf6eb26eb9afc3115bb8ef52eb78dc6b7 | |
parent | 7667af5220177cbce1df9c564365f5479517ccc1 (diff) | |
download | Stk-c1efd35ac402a57d9a3c0c17e67737af30429c8e.tar.gz |
Improve the UI layout of the input screen
TextInputLayout should be introduced to have a modern user interface
design. The helper text and the maximum length of the response are moved
under the edit box.
Bug: 128890104
Test: Confirmed the expected behavior in manual test cases.
Change-Id: If281bd7c914469270b60d8b49d43cf46b2d77742
-rw-r--r-- | AndroidManifest.xml | 2 | ||||
-rw-r--r-- | res/layout/stk_input.xml | 50 | ||||
-rw-r--r-- | src/com/android/stk/StkInputActivity.java | 41 |
3 files changed, 39 insertions, 54 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2695f51..c49ff86 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -83,7 +83,7 @@ <activity android:name="StkInputActivity" android:label="@string/app_name" android:icon="@drawable/ic_launcher_sim_toolkit" - android:theme="@android:style/Theme.DeviceDefault.DayNight" + android:theme="@style/Theme.AppCompat.DayNight.NoActionBar" android:configChanges="orientation|locale|screenSize|keyboardHidden" android:exported="false" android:autoRemoveFromRecents="true" diff --git a/res/layout/stk_input.xml b/res/layout/stk_input.xml index 7f8f96d..427ad42 100644 --- a/res/layout/stk_input.xml +++ b/res/layout/stk_input.xml @@ -19,8 +19,15 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + android:background="?android:attr/colorBackground" + android:elevation="4dp" + android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/> <ImageButton - style="@android:style/Widget.Material.ActionButton.Overflow" + style="@style/Widget.AppCompat.ActionButton.Overflow" android:id="@+id/more" android:layout_width="wrap_content" android:layout_height="wrap_content" @@ -62,32 +69,17 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> - <LinearLayout - android:id="@+id/input_restriction_info" - android:layout_width="wrap_content" + <com.google.android.material.textfield.TextInputLayout + android:id="@+id/text_input_layout" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginLeft="4dip" - android:orientation="vertical"> - <TextView - android:id="@+id/input_type" - android:gravity="start" - android:textAppearance="?android:attr/textAppearanceMedium" - android:textColor="?android:attr/textColorSecondary" - android:layout_width="wrap_content" - android:layout_height="wrap_content" /> - <TextView - android:id="@+id/num_of_chars" - android:textAppearance="?android:attr/textAppearanceMedium" - android:textColor="?android:attr/textColorSecondary" - android:layout_width="wrap_content" - android:layout_height="wrap_content" /> - </LinearLayout> - <EditText - android:id="@+id/in_text" - android:layout_gravity="center_horizontal" android:layout_marginBottom="16dip" - android:layout_width="match_parent" - android:layout_height="wrap_content" /> + android:orientation="vertical"> + <com.google.android.material.textfield.TextInputEditText + android:id="@+id/in_text" + android:layout_width="match_parent" + android:layout_height="wrap_content"/> + </com.google.android.material.textfield.TextInputLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" @@ -102,13 +94,13 @@ android:layout_weight="1" android:gravity="center_vertical" android:paddingStart="0dip" - style="@android:style/Widget.Material.Button.Borderless.Colored" + style="@style/Widget.AppCompat.Button.Borderless.Colored" android:text="@string/button_cancel" /> <Button android:id="@+id/button_ok" android:layout_height="48dip" android:layout_width="wrap_content" - style="@android:style/Widget.Material.Button.Colored" + style="@style/Widget.AppCompat.Button.Colored" android:text="@string/button_ok" /> </LinearLayout> </LinearLayout> @@ -123,13 +115,13 @@ android:id="@+id/button_no" android:layout_height="wrap_content" android:layout_width="wrap_content" - style="@android:style/Widget.Material.Button.Borderless.Colored" + style="@style/Widget.AppCompat.Button.Borderless.Colored" android:text="@string/button_no" /> <Button android:id="@+id/button_yes" android:layout_height="wrap_content" android:layout_width="wrap_content" - style="@android:style/Widget.Material.Button.Colored" + style="@style/Widget.AppCompat.Button.Colored" android:text="@string/button_yes" /> </LinearLayout> </LinearLayout> diff --git a/src/com/android/stk/StkInputActivity.java b/src/com/android/stk/StkInputActivity.java index 356bcfc..da80f9a 100644 --- a/src/com/android/stk/StkInputActivity.java +++ b/src/com/android/stk/StkInputActivity.java @@ -42,13 +42,18 @@ import android.widget.PopupMenu; import android.widget.TextView; import android.widget.TextView.BufferType; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + import com.android.internal.telephony.cat.CatLog; import com.android.internal.telephony.cat.Input; +import com.google.android.material.textfield.TextInputLayout; + /** * Display a request for a text input a long with a text edit form. */ -public class StkInputActivity extends Activity implements View.OnClickListener, +public class StkInputActivity extends AppCompatActivity implements View.OnClickListener, TextWatcher { // Members @@ -158,18 +163,13 @@ public class StkInputActivity extends Activity implements View.OnClickListener, return; } - ActionBar actionBar = null; - if (getResources().getBoolean(R.bool.show_menu_title_only_on_menu)) { - actionBar = getActionBar(); - if (actionBar != null) { - actionBar.hide(); - } - } - // Set the layout for this activity. setContentView(R.layout.stk_input); + setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); + + if (getResources().getBoolean(R.bool.show_menu_title_only_on_menu)) { + getSupportActionBar().hide(); - if (actionBar != null) { mMoreOptions = findViewById(R.id.more); mMoreOptions.setVisibility(View.VISIBLE); mMoreOptions.setOnClickListener(this); @@ -476,8 +476,7 @@ public class StkInputActivity extends Activity implements View.OnClickListener, } private void configInputDisplay() { - TextView numOfCharsView = (TextView) findViewById(R.id.num_of_chars); - TextView inTypeView = (TextView) findViewById(R.id.input_type); + TextInputLayout textInput = (TextInputLayout) findViewById(R.id.text_input_layout); int inTypeId = R.string.alphabet; @@ -493,7 +492,8 @@ public class StkInputActivity extends Activity implements View.OnClickListener, mTextIn.setKeyListener(StkDigitsKeyListener.getInstance()); inTypeId = R.string.digits; } - inTypeView.setText(inTypeId); + textInput.setHelperText(getResources().getString(inTypeId)); + textInput.setHelperTextEnabled(true); setTitle(R.string.app_name); @@ -506,17 +506,10 @@ public class StkInputActivity extends Activity implements View.OnClickListener, // Handle specific global and text attributes. switch (mState) { case STATE_TEXT: - int maxLen = mStkInput.maxLen; - int minLen = mStkInput.minLen; - mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter( - maxLen)}); - - // Set number of chars info. - String lengthLimit = String.valueOf(minLen); - if (maxLen != minLen) { - lengthLimit = minLen + " - " + maxLen; - } - numOfCharsView.setText(lengthLimit); + mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter(mStkInput.maxLen)}); + + textInput.setCounterMaxLength(mStkInput.maxLen); + textInput.setCounterEnabled(true); if (!mStkInput.echo) { mTextIn.setTransformationMethod(PasswordTransformationMethod |