From eac3731233e462451b6ef4ded63b7ea2a25cafae Mon Sep 17 00:00:00 2001 From: HITGIF Date: Sat, 16 Sep 2017 16:31:24 +0800 Subject: [PATCH] fix clear button --- .../textfieldboxestest/MainActivity.java | 27 +++++-------------- sample/src/main/res/layout/activity_main.xml | 2 ++ .../textfieldboxes/TextFieldBoxes.java | 6 ++--- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/sample/src/main/java/studio/carbonylgroup/textfieldboxestest/MainActivity.java b/sample/src/main/java/studio/carbonylgroup/textfieldboxestest/MainActivity.java index d4e052c..c1d5a8b 100644 --- a/sample/src/main/java/studio/carbonylgroup/textfieldboxestest/MainActivity.java +++ b/sample/src/main/java/studio/carbonylgroup/textfieldboxestest/MainActivity.java @@ -16,35 +16,22 @@ protected void onCreate(Bundle savedInstanceState) { final SharedPreferences sharedPreferences = this.getSharedPreferences("theme", Context.MODE_PRIVATE); final boolean dark = sharedPreferences.getBoolean("dark", false); - if (dark) setTheme(R.style.AppThemeDark); - else setTheme(R.style.AppTheme); + setTheme(dark ? R.style.AppThemeDark : R.style.AppTheme); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Button darkButton = findViewById(R.id.dark_button); - if (dark) darkButton.setText("LIGHT SIDE"); - else darkButton.setText("DARK SIDE"); + darkButton.setText(dark ? "LIGHT SIDE" : "DARK SIDE"); darkButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (dark) { - sharedPreferences.edit().putBoolean("dark", false).apply(); - restart(); - } - else { - sharedPreferences.edit().putBoolean("dark", true).apply(); - restart(); - } + sharedPreferences.edit().putBoolean("dark", !dark).apply(); + Intent i = getBaseContext().getPackageManager() + .getLaunchIntentForPackage( getBaseContext().getPackageName() ); + i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(i); } }); } - - public void restart() { - - Intent i = getBaseContext().getPackageManager() - .getLaunchIntentForPackage( getBaseContext().getPackageName() ); - i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(i); - } } diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 0a2b0a7..26808fe 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -101,6 +101,7 @@ android:layout_weight="2" app:hasFocus="true" app:helperText=" " + app:endIcon="@drawable/ic_mic_black_24dp" app:iconSignifier="@drawable/ic_location_on_black_24dp" app:labelText="Location (optional)"> @@ -125,6 +126,7 @@ app:maxCharacters="140"> diff --git a/textfieldboxes/src/main/java/studio/carbonylgroup/textfieldboxes/TextFieldBoxes.java b/textfieldboxes/src/main/java/studio/carbonylgroup/textfieldboxes/TextFieldBoxes.java index 14b064f..ecbe5e6 100644 --- a/textfieldboxes/src/main/java/studio/carbonylgroup/textfieldboxes/TextFieldBoxes.java +++ b/textfieldboxes/src/main/java/studio/carbonylgroup/textfieldboxes/TextFieldBoxes.java @@ -309,7 +309,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (widthMode == MeasureSpec.EXACTLY) { /* match_parent or specific value */ - this.editText.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT; + this.inputLayout.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT; this.upperPanel.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT; this.editTextLayout.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT; @@ -359,14 +359,14 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { .addRule(RelativeLayout.ALIGN_PARENT_END); } - ((RelativeLayout.LayoutParams) this.editText.getLayoutParams()) + ((RelativeLayout.LayoutParams) this.inputLayout.getLayoutParams()) .addRule(RelativeLayout.LEFT_OF, R.id.text_field_boxes_clear_button); } } else if (widthMode == MeasureSpec.AT_MOST) { /* wrap_content */ - this.editText.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT; + this.inputLayout.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT; this.upperPanel.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT; this.editTextLayout.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT; }