Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply resource prefix for Android resources #111

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.skydoves.colorpickerview.AlphaTileView;
import com.skydoves.colorpickerview.ColorEnvelope;
import com.skydoves.colorpickerview.ColorPickerDialog;
Expand All @@ -40,8 +42,10 @@
import com.skydoves.powermenu.OnMenuItemClickListener;
import com.skydoves.powermenu.PowerMenu;
import com.skydoves.powermenu.PowerMenuItem;

import java.io.FileNotFoundException;
import java.io.InputStream;

import timber.log.Timber;

public class MainActivity extends AppCompatActivity {
Expand All @@ -53,30 +57,28 @@ public class MainActivity extends AppCompatActivity {

private PowerMenu powerMenu;
private final OnMenuItemClickListener<PowerMenuItem> powerMenuItemClickListener =
new OnMenuItemClickListener<>() {
@Override
public void onItemClick(int position, PowerMenuItem item) {
switch (position) {
case 0:
{
palette();
break;
}
case 1:
{
paletteFromGallery();
break;
}
case 2:
selector();
break;
case 3:
dialog();
break;
new OnMenuItemClickListener<>() {
@Override
public void onItemClick(int position, PowerMenuItem item) {
switch (position) {
case 0: {
palette();
break;
}
powerMenu.dismiss();
case 1: {
paletteFromGallery();
break;
}
case 2:
selector();
break;
case 3:
dialog();
break;
}
};
powerMenu.dismiss();
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -90,11 +92,11 @@ protected void onCreate(Bundle savedInstanceState) {
bubbleFlag.setFlagMode(FlagMode.FADE);
colorPickerView.setFlagView(bubbleFlag);
colorPickerView.setColorListener(
(ColorEnvelopeListener)
(envelope, fromUser) -> {
Timber.d("color: %s", envelope.getHexCode());
setLayoutColor(envelope);
});
(ColorEnvelopeListener)
(envelope, fromUser) -> {
Timber.d("color: %s", envelope.getHexCode());
setLayoutColor(envelope);
});

// attach alphaSlideBar
final AlphaSlideBar alphaSlideBar = findViewById(R.id.alphaSlideBar);
Expand All @@ -120,12 +122,16 @@ private void setLayoutColor(ColorEnvelope envelope) {
alphaTileView.setPaintColor(envelope.getColor());
}

/** shows the popup menu for changing options.. */
/**
* shows the popup menu for changing options..
*/
public void overflowMenu(View view) {
powerMenu.showAsAnchorLeftTop(view);
}

/** changes palette image using drawable resource. */
/**
* changes palette image using drawable resource.
*/
private void palette() {
if (FLAG_PALETTE) {
colorPickerView.setHsvPaletteDrawable();
Expand All @@ -135,34 +141,40 @@ private void palette() {
FLAG_PALETTE = !FLAG_PALETTE;
}

/** changes palette image from a gallery image. */
/**
* changes palette image from a gallery image.
*/
private void paletteFromGallery() {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1000);
}

/** changes selector image using drawable resource. */
/**
* changes selector image using drawable resource.
*/
private void selector() {
if (FLAG_SELECTOR) {
colorPickerView.setSelectorDrawable(ContextCompat.getDrawable(this, R.drawable.wheel));
colorPickerView.setSelectorDrawable(ContextCompat.getDrawable(this, com.skydoves.colorpickerview.R.drawable.colorpickerview_wheel));
} else {
colorPickerView.setSelectorDrawable(ContextCompat.getDrawable(this, R.drawable.wheel_dark));
}
FLAG_SELECTOR = !FLAG_SELECTOR;
}

/** shows ColorPickerDialog */
/**
* shows ColorPickerDialog
*/
private void dialog() {
ColorPickerDialog.Builder builder =
new ColorPickerDialog.Builder(this)
.setTitle("ColorPicker Dialog")
.setPreferenceName("Test")
.setPositiveButton(
getString(R.string.confirm),
(ColorEnvelopeListener) (envelope, fromUser) -> setLayoutColor(envelope))
.setNegativeButton(
getString(R.string.cancel), (dialogInterface, i) -> dialogInterface.dismiss());
new ColorPickerDialog.Builder(this)
.setTitle("ColorPicker Dialog")
.setPreferenceName("Test")
.setPositiveButton(
getString(R.string.confirm),
(ColorEnvelopeListener) (envelope, fromUser) -> setLayoutColor(envelope))
.setNegativeButton(
getString(R.string.cancel), (dialogInterface, i) -> dialogInterface.dismiss());
builder.getColorPickerView().setFlagView(new BubbleFlag(this));
builder.show();
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
android:layout_weight="6"
app:initialColor="@color/colorPrimary"
app:preferenceName="Test2"
app:selector="@drawable/wheel" />
app:selector="@drawable/colorpickerview_wheel" />

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -85,7 +85,7 @@
android:layout_gravity="center"
app:borderColor_AlphaSlideBar="@android:color/darker_gray"
app:borderSize_AlphaSlideBar="5"
app:selector_AlphaSlideBar="@drawable/wheel" />
app:selector_AlphaSlideBar="@drawable/colorpickerview_wheel" />
</LinearLayout>

<LinearLayout
Expand All @@ -101,7 +101,7 @@
android:layout_height="wrap_content"
app:borderColor_BrightnessSlider="@android:color/darker_gray"
app:borderSize_BrightnessSlider="5"
app:selector_BrightnessSlider="@drawable/wheel" />
app:selector_BrightnessSlider="@drawable/colorpickerview_wheel" />
</LinearLayout>

<LinearLayout
Expand Down
16 changes: 8 additions & 8 deletions colorpickerview/api/colorpickerview.api
Original file line number Diff line number Diff line change
Expand Up @@ -193,29 +193,29 @@ public class com/skydoves/colorpickerview/FadeUtils {
public static fun fadeOut (Landroid/view/View;)V
}

public final class com/skydoves/colorpickerview/databinding/DialogColorpickerColorpickerviewSkydovesBinding : androidx/viewbinding/ViewBinding {
public final class com/skydoves/colorpickerview/databinding/ColorpickerviewDialogColorpickerBinding : androidx/viewbinding/ViewBinding {
public final field alphaSlideBar Lcom/skydoves/colorpickerview/sliders/AlphaSlideBar;
public final field alphaSlideBarFrame Landroid/widget/FrameLayout;
public final field brightnessSlideBar Lcom/skydoves/colorpickerview/sliders/BrightnessSlideBar;
public final field brightnessSlideBarFrame Landroid/widget/FrameLayout;
public final field colorPickerView Lcom/skydoves/colorpickerview/ColorPickerView;
public final field colorPickerViewFrame Landroid/widget/FrameLayout;
public final field spaceBottom Landroid/widget/Space;
public static fun bind (Landroid/view/View;)Lcom/skydoves/colorpickerview/databinding/DialogColorpickerColorpickerviewSkydovesBinding;
public static fun bind (Landroid/view/View;)Lcom/skydoves/colorpickerview/databinding/ColorpickerviewDialogColorpickerBinding;
public synthetic fun getRoot ()Landroid/view/View;
public fun getRoot ()Landroid/widget/ScrollView;
public static fun inflate (Landroid/view/LayoutInflater;)Lcom/skydoves/colorpickerview/databinding/DialogColorpickerColorpickerviewSkydovesBinding;
public static fun inflate (Landroid/view/LayoutInflater;Landroid/view/ViewGroup;Z)Lcom/skydoves/colorpickerview/databinding/DialogColorpickerColorpickerviewSkydovesBinding;
public static fun inflate (Landroid/view/LayoutInflater;)Lcom/skydoves/colorpickerview/databinding/ColorpickerviewDialogColorpickerBinding;
public static fun inflate (Landroid/view/LayoutInflater;Landroid/view/ViewGroup;Z)Lcom/skydoves/colorpickerview/databinding/ColorpickerviewDialogColorpickerBinding;
}

public final class com/skydoves/colorpickerview/databinding/FlagBubbleColorpickerviewSkydovesBinding : androidx/viewbinding/ViewBinding {
public final class com/skydoves/colorpickerview/databinding/ColorpickerviewFlagBubbleBinding : androidx/viewbinding/ViewBinding {
public final field bubble Landroidx/appcompat/widget/AppCompatImageView;
public final field layout Landroid/widget/FrameLayout;
public static fun bind (Landroid/view/View;)Lcom/skydoves/colorpickerview/databinding/FlagBubbleColorpickerviewSkydovesBinding;
public static fun bind (Landroid/view/View;)Lcom/skydoves/colorpickerview/databinding/ColorpickerviewFlagBubbleBinding;
public synthetic fun getRoot ()Landroid/view/View;
public fun getRoot ()Landroid/widget/FrameLayout;
public static fun inflate (Landroid/view/LayoutInflater;)Lcom/skydoves/colorpickerview/databinding/FlagBubbleColorpickerviewSkydovesBinding;
public static fun inflate (Landroid/view/LayoutInflater;Landroid/view/ViewGroup;Z)Lcom/skydoves/colorpickerview/databinding/FlagBubbleColorpickerviewSkydovesBinding;
public static fun inflate (Landroid/view/LayoutInflater;)Lcom/skydoves/colorpickerview/databinding/ColorpickerviewFlagBubbleBinding;
public static fun inflate (Landroid/view/LayoutInflater;Landroid/view/ViewGroup;Z)Lcom/skydoves/colorpickerview/databinding/ColorpickerviewFlagBubbleBinding;
}

public class com/skydoves/colorpickerview/flag/BubbleFlag : com/skydoves/colorpickerview/flag/FlagView {
Expand Down
2 changes: 2 additions & 0 deletions colorpickerview/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ android {
kotlinOptions {
jvmTarget = libs.versions.jvmTarget.get()
}

resourcePrefix = "colorpickerview"
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import com.skydoves.colorpickerview.databinding.DialogColorpickerColorpickerviewSkydovesBinding;

import com.skydoves.colorpickerview.databinding.ColorpickerviewDialogColorpickerBinding;
import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener;
import com.skydoves.colorpickerview.listeners.ColorListener;
import com.skydoves.colorpickerview.listeners.ColorPickerViewListener;
Expand All @@ -47,9 +49,11 @@ public ColorPickerDialog(Context context) {
super(context);
}

/** Builder class for create {@link ColorPickerDialog}. */
/**
* Builder class for create {@link ColorPickerDialog}.
*/
public static class Builder extends AlertDialog.Builder {
private DialogColorpickerColorpickerviewSkydovesBinding dialogBinding;
private ColorpickerviewDialogColorpickerBinding dialogBinding;
private ColorPickerView colorPickerView;
private boolean shouldAttachAlphaSlideBar = true;
private boolean shouldAttachBrightnessSlideBar = true;
Expand All @@ -68,17 +72,17 @@ public Builder(Context context, int themeResId) {
private void onCreate() {
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
this.dialogBinding =
DialogColorpickerColorpickerviewSkydovesBinding.inflate(layoutInflater, null, false);
ColorpickerviewDialogColorpickerBinding.inflate(layoutInflater, null, false);
this.colorPickerView = dialogBinding.colorPickerView;
this.colorPickerView.attachAlphaSlider(dialogBinding.alphaSlideBar);
this.colorPickerView.attachBrightnessSlider(dialogBinding.brightnessSlideBar);
this.colorPickerView.setColorListener(
new ColorEnvelopeListener() {
@Override
public void onColorSelected(ColorEnvelope envelope, boolean fromUser) {
// no stubs
}
});
new ColorEnvelopeListener() {
@Override
public void onColorSelected(ColorEnvelope envelope, boolean fromUser) {
// no stubs
}
});
super.setView(dialogBinding.getRoot());
}

Expand Down Expand Up @@ -153,7 +157,7 @@ public Builder setBottomSpace(int bottomSpace) {
/**
* sets positive button with {@link ColorPickerViewListener} on the {@link ColorPickerDialog}.
*
* @param textId string resource integer id.
* @param textId string resource integer id.
* @param colorListener {@link ColorListener}.
* @return {@link Builder}.
*/
Expand All @@ -165,12 +169,12 @@ public Builder setPositiveButton(int textId, final ColorPickerViewListener color
/**
* sets positive button with {@link ColorPickerViewListener} on the {@link ColorPickerDialog}.
*
* @param text string text value.
* @param text string text value.
* @param colorListener {@link ColorListener}.
* @return {@link Builder}.
*/
public Builder setPositiveButton(
CharSequence text, final ColorPickerViewListener colorListener) {
CharSequence text, final ColorPickerViewListener colorListener) {
super.setPositiveButton(text, getOnClickListener(colorListener));
return this;
}
Expand All @@ -195,11 +199,11 @@ public void onClick(DialogInterface dialogInterface, int i) {
((ColorListener) colorListener).onColorSelected(getColorPickerView().getColor(), true);
} else if (colorListener instanceof ColorEnvelopeListener) {
((ColorEnvelopeListener) colorListener)
.onColorSelected(getColorPickerView().getColorEnvelope(), true);
.onColorSelected(getColorPickerView().getColorEnvelope(), true);
}
if (getColorPickerView() != null) {
ColorPickerPreferenceManager.getInstance(getContext())
.saveColorPickerData(getColorPickerView());
.saveColorPickerData(getColorPickerView());
}
}
};
Expand Down Expand Up @@ -369,24 +373,24 @@ public Builder setCursor(Cursor cursor, OnClickListener listener, String labelCo

@Override
public Builder setMultiChoiceItems(
int itemsId, boolean[] checkedItems, OnMultiChoiceClickListener listener) {
int itemsId, boolean[] checkedItems, OnMultiChoiceClickListener listener) {
super.setMultiChoiceItems(itemsId, checkedItems, listener);
return this;
}

@Override
public Builder setMultiChoiceItems(
CharSequence[] items, boolean[] checkedItems, OnMultiChoiceClickListener listener) {
CharSequence[] items, boolean[] checkedItems, OnMultiChoiceClickListener listener) {
super.setMultiChoiceItems(items, checkedItems, listener);
return this;
}

@Override
public Builder setMultiChoiceItems(
Cursor cursor,
String isCheckedColumn,
String labelColumn,
OnMultiChoiceClickListener listener) {
Cursor cursor,
String isCheckedColumn,
String labelColumn,
OnMultiChoiceClickListener listener) {
super.setMultiChoiceItems(cursor, isCheckedColumn, labelColumn, listener);
return this;
}
Expand All @@ -399,21 +403,21 @@ public Builder setSingleChoiceItems(int itemsId, int checkedItem, OnClickListene

@Override
public Builder setSingleChoiceItems(
Cursor cursor, int checkedItem, String labelColumn, OnClickListener listener) {
Cursor cursor, int checkedItem, String labelColumn, OnClickListener listener) {
super.setSingleChoiceItems(cursor, checkedItem, labelColumn, listener);
return this;
}

@Override
public Builder setSingleChoiceItems(
CharSequence[] items, int checkedItem, OnClickListener listener) {
CharSequence[] items, int checkedItem, OnClickListener listener) {
super.setSingleChoiceItems(items, checkedItem, listener);
return this;
}

@Override
public Builder setSingleChoiceItems(
ListAdapter adapter, int checkedItem, OnClickListener listener) {
ListAdapter adapter, int checkedItem, OnClickListener listener) {
super.setSingleChoiceItems(adapter, checkedItem, listener);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private void onCreate() {
if (selectorDrawable != null) {
selector.setImageDrawable(selectorDrawable);
} else {
selector.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.wheel));
selector.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.colorpickerview_wheel));
}
FrameLayout.LayoutParams selectorParam =
new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
Expand Down
Loading