Skip to content

Commit

Permalink
Added multi color picker support
Browse files Browse the repository at this point in the history
  • Loading branch information
eltos committed Jul 26, 2017
1 parent c2265ab commit 19fa1f6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class SimpleColorDialog extends CustomListDialog<SimpleColorDialog> imple
private static final String TAG = "SimpleColorDialog";

public static final String COLOR = TAG + "color";
public static final String COLORS = TAG + "colors";
public static final int NONE = ColorView.NONE;
protected static final int PICKER = -2;

Expand All @@ -64,7 +65,6 @@ public class SimpleColorDialog extends CustomListDialog<SimpleColorDialog> imple
public static final @ArrayRes int COLORFUL_COLOR_PALLET = R.array.colorful_pallet;


protected static final String COLORS = TAG + "colors";
protected static final String CUSTOM = TAG + "custom";
protected static final String PICKER_DIALOG_TAG = TAG + "picker";
private static final String SELECTED = TAG + "selected";
Expand Down Expand Up @@ -231,6 +231,19 @@ protected Bundle onResult(int which) {
} else {
b.putInt(COLOR, color);
}

long[] ids = b.getLongArray(SELECTED_IDS);
if (ids != null) {
int[] colors = new int[ids.length];
for (int i = 0; i < ids.length; i++) {
if (ids[i] == PICKER) {
colors[i] = mCustomColor;
} else {
colors[i] = (int) ids[i];
}
}
b.putIntArray(COLORS, colors);
}
return b;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ public void showHsvWheel(View view){

}

public void showMultiColorPicker(View view){

SimpleColorDialog.build()
.title(R.string.pick_some_colors)
.choiceMode(SimpleColorDialog.MULTI_CHOICE)
.show(this, COLOR_DIALOG);

/** Results: {@link MainActivity#onResult} **/
}



// == I n p u t s a n d F o r m s ==
Expand Down Expand Up @@ -551,6 +561,19 @@ public boolean onResult(@NonNull String dialogTag, int which, @NonNull Bundle ex

case COLOR_DIALOG: /** {@link MainActivity#showColorPicker(View)} **/
newColor(extras.getInt(SimpleColorDialog.COLOR));
int[] colors = extras.getIntArray(SimpleColorDialog.COLORS);
if (colors != null) {
final Handler handler = new Handler();
for (int i = 0; i < colors.length; i++) {
@ColorInt final int color = colors[i];
handler.postDelayed(new Runnable() {
@Override
public void run() {
newColor(color);
}
}, 1000*i);
}
}
return true;

case COLOR_WHEEL_DIALOG: /** {@link MainActivity#showHsvWheel(View)} **/
Expand Down
3 changes: 2 additions & 1 deletion testApp/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@
android:layout_row="1"
android:layout_column="2"
android:layout_columnWeight="1"
android:visibility="invisible" />
android:text="Colors"
android:onClick="showMultiColorPicker" />

</GridLayout>

Expand Down
1 change: 1 addition & 0 deletions testApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<string name="select_any">Select any</string>
<string name="numers">Numbers</string>
<string name="pick_a_color">Pick a color</string>
<string name="pick_some_colors">Pick multiple colors</string>
<string name="popup">Popup</string>
<string name="disable">Disable</string>
<string name="not_found">Not found</string>
Expand Down

0 comments on commit 19fa1f6

Please sign in to comment.