Skip to content

Commit

Permalink
ColorPickerDialog using Fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
piclabsstudio committed Jan 31, 2020
1 parent 470f96a commit 54a4de9
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 6 deletions.
24 changes: 24 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,60 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.dvinfosys.WidgetsExample.R;
import com.dvinfosys.widgets.Button.CustomButton;
import com.dvinfosys.widgets.ColorPicker.ColorPanelView;
import com.dvinfosys.widgets.ColorPicker.ColorPickerDialog;
import com.dvinfosys.widgets.ColorPicker.ColorPickerDialogListener;
import com.dvinfosys.widgets.ColorPicker.ColorPickerView;

public class ColorPickerFragment extends Fragment implements ColorPickerView.OnColorChangedListener{
public class ColorPickerFragment extends Fragment implements ColorPickerView.OnColorChangedListener, ColorPickerDialogListener {

private static final int DIALOG_ID = 0;
private ColorPickerView colorPickerView;
private ColorPanelView newColorPanelView;
private CustomButton btnPickColor;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_color_picker, container, false);
colorPickerView = view.findViewById(R.id.cpv_color_picker_view);
btnPickColor = view.findViewById(R.id.btn_pic_color);
ColorPanelView colorPanelView = view.findViewById(R.id.cpv_color_panel_old);
newColorPanelView = view.findViewById(R.id.cpv_color_panel_new);

colorPickerView.setOnColorChangedListener(this);
colorPickerView.setColor(Color.BLUE, true);
colorPanelView.setColor(Color.RED);

btnPickColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ColorPickerDialog pickerDialog = ColorPickerDialog.newBuilder()
.setDialogType(ColorPickerDialog.TYPE_CUSTOM)
.setAllowPresets(true)
.setDialogId(DIALOG_ID)
.setColor(Color.BLACK)
.setShowAlphaSlider(true)
.create();
pickerDialog.setColorPickerDialogListener(ColorPickerFragment.this);
pickerDialog.show(getFragmentManager(),"ColorPicker");
/*ColorPickerDialog.newBuilder()
.setDialogType(ColorPickerDialog.TYPE_CUSTOM)
.setAllowPresets(true)
.setDialogId(DIALOG_ID)
.setColor(Color.BLACK)
.setShowAlphaSlider(true)
.show(getActivity());*/
}
});

return view;
}

Expand All @@ -43,4 +72,20 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
public void onColorChanged(int newColor) {
newColorPanelView.setColor(colorPickerView.getColor());
}

@Override
public void onColorSelected(int dialogId, int color) {
switch (dialogId) {
case DIALOG_ID:
Log.e("ColorPicker","Selected color->"+color);
String hexColor = String.format("#%06X", (0xFFFFFF & color));
Toast.makeText(getContext(), "Select Color :" + hexColor, Toast.LENGTH_LONG).show();
break;
}
}

@Override
public void onDialogDismissed(int dialogId) {

}
}
11 changes: 11 additions & 0 deletions app/src/main/res/layout/fragment_color_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
android:showDividers="middle"
tools:context=".Fragments.ColorPickerFragment">

<com.dvinfosys.widgets.Button.CustomButton
android:id="@+id/btn_pic_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:text="Pick Color"
android:textStyle="bold"
android:textSize="12sp"
android:textAllCaps="false"
android:textColor="@color/defaultTextColor" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import com.dvinfosys.widgets.EditText.CustomEditText;
import com.dvinfosys.widgets.R;

import java.util.Arrays;
Expand Down Expand Up @@ -102,7 +102,7 @@ public class ColorPickerDialog extends DialogFragment implements ColorPickerView
// -- CUSTOM ---------------------------
ColorPickerView colorPicker;
ColorPanelView newColorPanel;
EditText hexEditText;
CustomEditText hexEditText;
private final OnTouchListener onPickerTouchListener = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Expand Down
4 changes: 2 additions & 2 deletions libraries/src/main/res/layout/dialog_color_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
android:orientation="horizontal"
tools:ignore="RtlHardcoded">

<com.dvinfosys.widgets.TextView.NormalTextView
<com.dvinfosys.widgets.TextView.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#"
android:typeface="monospace"
tools:ignore="HardcodedText" />

<com.dvinfosys.widgets.EditText.NormalEditText
<com.dvinfosys.widgets.EditText.CustomEditText
android:id="@+id/cpv_hex"
android:layout_width="110dp"
android:layout_height="wrap_content"
Expand Down

0 comments on commit 54a4de9

Please sign in to comment.