Skip to content

Commit

Permalink
Merge pull request #93
Browse files Browse the repository at this point in the history
Allow to unset color (closes #92)
  • Loading branch information
eltos authored Feb 10, 2024
2 parents c16808a + 97d7430 commit 3d9fd3f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import eltos.simpledialogfragment.R;
Expand All @@ -44,6 +45,8 @@ class ColorViewHolder extends FormElementViewHolder<ColorField> implements Simpl
private TextView label;
private ColorView colorView;

private ImageView clearButton;

public ColorViewHolder(ColorField field) {
super(field);
}
Expand All @@ -59,6 +62,7 @@ protected void setUpView(View view, final Context context, Bundle savedInstanceS

label = (TextView) view.findViewById(R.id.label);
colorView = (ColorView) view.findViewById(R.id.color);
clearButton = (ImageView) view.findViewById(R.id.clear_color);

// Label
String text = field.getText(context);
Expand Down Expand Up @@ -97,6 +101,15 @@ public void onClick(View v) {
}
});

if (!field.required) {
clearButton.setVisibility(View.VISIBLE);
clearButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
colorView.setColor(ColorView.NONE);
}
});
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,30 @@

<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="4dp"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
tools:text="Favourite color" />


<Space
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />

<ImageView
style="?actionButtonStyle"
android:id="@+id/clear_color"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="6dp"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:visibility="gone"
android:src="@drawable/ic_clear_search" />



</LinearLayout>

0 comments on commit 3d9fd3f

Please sign in to comment.