Skip to content

Commit eac3731

Browse files
committed
fix clear button
1 parent c0cc61d commit eac3731

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

sample/src/main/java/studio/carbonylgroup/textfieldboxestest/MainActivity.java

+7-20
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,22 @@ protected void onCreate(Bundle savedInstanceState) {
1616

1717
final SharedPreferences sharedPreferences = this.getSharedPreferences("theme", Context.MODE_PRIVATE);
1818
final boolean dark = sharedPreferences.getBoolean("dark", false);
19-
if (dark) setTheme(R.style.AppThemeDark);
20-
else setTheme(R.style.AppTheme);
19+
setTheme(dark ? R.style.AppThemeDark : R.style.AppTheme);
2120

2221
super.onCreate(savedInstanceState);
2322
setContentView(R.layout.activity_main);
2423

2524
final Button darkButton = findViewById(R.id.dark_button);
26-
if (dark) darkButton.setText("LIGHT SIDE");
27-
else darkButton.setText("DARK SIDE");
25+
darkButton.setText(dark ? "LIGHT SIDE" : "DARK SIDE");
2826
darkButton.setOnClickListener(new View.OnClickListener() {
2927
@Override
3028
public void onClick(View view) {
31-
if (dark) {
32-
sharedPreferences.edit().putBoolean("dark", false).apply();
33-
restart();
34-
}
35-
else {
36-
sharedPreferences.edit().putBoolean("dark", true).apply();
37-
restart();
38-
}
29+
sharedPreferences.edit().putBoolean("dark", !dark).apply();
30+
Intent i = getBaseContext().getPackageManager()
31+
.getLaunchIntentForPackage( getBaseContext().getPackageName() );
32+
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
33+
startActivity(i);
3934
}
4035
});
4136
}
42-
43-
public void restart() {
44-
45-
Intent i = getBaseContext().getPackageManager()
46-
.getLaunchIntentForPackage( getBaseContext().getPackageName() );
47-
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
48-
startActivity(i);
49-
}
5037
}

sample/src/main/res/layout/activity_main.xml

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
android:layout_weight="2"
102102
app:hasFocus="true"
103103
app:helperText=" "
104+
app:endIcon="@drawable/ic_mic_black_24dp"
104105
app:iconSignifier="@drawable/ic_location_on_black_24dp"
105106
app:labelText="Location (optional)">
106107

@@ -125,6 +126,7 @@
125126
app:maxCharacters="140">
126127

127128
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
129+
android:id="@+id/extendedEditText"
128130
android:layout_width="wrap_content"
129131
android:layout_height="wrap_content"
130132
android:text="Unique and rare dress from 1952. Made out of washed cotton with front pockets. Sleeveless with button closures." />

textfieldboxes/src/main/java/studio/carbonylgroup/textfieldboxes/TextFieldBoxes.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
309309
if (widthMode == MeasureSpec.EXACTLY) {
310310

311311
/* match_parent or specific value */
312-
this.editText.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
312+
this.inputLayout.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
313313
this.upperPanel.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
314314
this.editTextLayout.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
315315

@@ -359,14 +359,14 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
359359
.addRule(RelativeLayout.ALIGN_PARENT_END);
360360
}
361361

362-
((RelativeLayout.LayoutParams) this.editText.getLayoutParams())
362+
((RelativeLayout.LayoutParams) this.inputLayout.getLayoutParams())
363363
.addRule(RelativeLayout.LEFT_OF, R.id.text_field_boxes_clear_button);
364364
}
365365

366366
} else if (widthMode == MeasureSpec.AT_MOST) {
367367

368368
/* wrap_content */
369-
this.editText.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
369+
this.inputLayout.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
370370
this.upperPanel.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
371371
this.editTextLayout.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
372372
}

0 commit comments

Comments
 (0)