Skip to content

Commit

Permalink
fix clear button
Browse files Browse the repository at this point in the history
  • Loading branch information
HITGIF committed Sep 16, 2017
1 parent c0cc61d commit eac3731
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 2 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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)">

Expand All @@ -125,6 +126,7 @@
app:maxCharacters="140">

<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/extendedEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unique and rare dress from 1952. Made out of washed cotton with front pockets. Sleeveless with button closures." />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit eac3731

Please sign in to comment.