From 31604fb84c10feafe1234043767513f94f576a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B5=E5=BC=98?= Date: Fri, 7 Sep 2018 09:56:59 +0800 Subject: [PATCH] Fix #2, view parent is unnecessary --- .../main/java/top/defaults/colorpickerapp/MainActivity.java | 2 +- .../main/java/top/defaults/colorpicker/ColorPickerPopup.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/top/defaults/colorpickerapp/MainActivity.java b/app/src/main/java/top/defaults/colorpickerapp/MainActivity.java index 5132b27..f9ddc04 100644 --- a/app/src/main/java/top/defaults/colorpickerapp/MainActivity.java +++ b/app/src/main/java/top/defaults/colorpickerapp/MainActivity.java @@ -38,7 +38,7 @@ void popup(View v) { .showIndicator(true) .showValue(true) .build() - .show(v, new ColorPickerPopup.ColorPickerObserver() { + .show(new ColorPickerPopup.ColorPickerObserver() { @Override public void onColorPicked(int color) { v.setBackgroundColor(color); diff --git a/colorpicker/src/main/java/top/defaults/colorpicker/ColorPickerPopup.java b/colorpicker/src/main/java/top/defaults/colorpicker/ColorPickerPopup.java index ee62372..27c3018 100644 --- a/colorpicker/src/main/java/top/defaults/colorpicker/ColorPickerPopup.java +++ b/colorpicker/src/main/java/top/defaults/colorpicker/ColorPickerPopup.java @@ -36,6 +36,10 @@ private ColorPickerPopup(Builder builder) { this.showValue = builder.showValue; } + public void show(final ColorPickerObserver observer) { + show(null, observer); + } + public void show(View parent, final ColorPickerObserver observer) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); if (inflater == null) return; @@ -93,6 +97,7 @@ public void onColor(int color, boolean fromUser) { } popupWindow.setAnimationStyle(R.style.TopDefaultsViewColorPickerPopupAnimation); + if (parent == null) parent = layout; popupWindow.showAtLocation(parent, Gravity.CENTER, 0, 0); }