forked from gzu-liyujiang/AndroidPicker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18fb051
commit 7a6704f
Showing
82 changed files
with
3,918 additions
and
1,932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 颜色选择器 | ||
|
||
颜色选择面板,改自[AndroidColorPicker](https://github.com/jbruchanov/AndroidColorPicker) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2016-present 贵州纳雍穿青人李裕江<[email protected]> | ||
* | ||
* The software is licensed under the Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR | ||
* PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
apply from: "${rootDir}/gradle/library.gradle" | ||
apply from: "${rootDir}/gradle/publish.gradle" | ||
|
||
dependencies { | ||
implementation androidxLibrary.annotation | ||
implementation project(':BasePicker') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# 本库模块专用的混淆规则 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!-- | ||
~ Copyright (c) 2016-present 贵州纳雍穿青人李裕江<[email protected]> | ||
~ | ||
~ The software is licensed under the Mulan PSL v2. | ||
~ You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
~ You may obtain a copy of Mulan PSL v2 at: | ||
~ http://license.coscl.org.cn/MulanPSL2 | ||
~ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR | ||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR | ||
~ PURPOSE. | ||
~ See the Mulan PSL v2 for more details. | ||
--> | ||
|
||
<manifest package="com.github.gzuliyujiang.colorpicker" /> |
40 changes: 40 additions & 0 deletions
40
ColorPicker/src/main/java/com/github/gzuliyujiang/colorpicker/BrightnessGradientView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2016-present 贵州纳雍穿青人李裕江<[email protected]> | ||
* | ||
* The software is licensed under the Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR | ||
* PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
package com.github.gzuliyujiang.colorpicker; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
|
||
/** | ||
* @author 贵州山野羡民([email protected]) | ||
* @since 2021/6/10 12:59 | ||
*/ | ||
public class BrightnessGradientView extends ColorGradientView { | ||
|
||
public BrightnessGradientView(Context context) { | ||
super(context); | ||
asBrightnessGradient(); | ||
} | ||
|
||
public BrightnessGradientView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
asBrightnessGradient(); | ||
} | ||
|
||
public BrightnessGradientView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
asBrightnessGradient(); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
ColorPicker/src/main/java/com/github/gzuliyujiang/colorpicker/ColorGradientView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2016-present 贵州纳雍穿青人李裕江<[email protected]> | ||
* | ||
* The software is licensed under the Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR | ||
* PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
package com.github.gzuliyujiang.colorpicker; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
|
||
/** | ||
* @author 贵州山野羡民([email protected]) | ||
* @since 2015/7/20 | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class ColorGradientView extends GradientView { | ||
|
||
public ColorGradientView(Context context) { | ||
super(context); | ||
} | ||
|
||
public ColorGradientView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public ColorGradientView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
} |
171 changes: 171 additions & 0 deletions
171
ColorPicker/src/main/java/com/github/gzuliyujiang/colorpicker/ColorPicker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/* | ||
* Copyright (c) 2016-present 贵州纳雍穿青人李裕江<[email protected]> | ||
* | ||
* The software is licensed under the Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR | ||
* PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
package com.github.gzuliyujiang.colorpicker; | ||
|
||
import android.app.Activity; | ||
import android.graphics.Color; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.CallSuper; | ||
import androidx.annotation.ColorInt; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.StyleRes; | ||
|
||
import com.github.gzuliyujiang.basepicker.BottomPicker; | ||
import com.github.gzuliyujiang.basepicker.PickerLog; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* @author 贵州山野羡民([email protected]) | ||
* @since 2021/6/10 10:54 | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class ColorPicker extends BottomPicker implements View.OnClickListener, OnColorChangedListener { | ||
protected TextView cancelView; | ||
protected TextView hexView; | ||
protected TextView okView; | ||
protected ColorGradientView colorGradientView; | ||
protected BrightnessGradientView brightnessGradientView; | ||
private boolean initialized = false; | ||
private int initColor = Color.YELLOW; | ||
private OnColorPickedListener onColorPickedListener; | ||
|
||
public ColorPicker(@NonNull Activity activity) { | ||
super(activity); | ||
} | ||
|
||
public ColorPicker(@NonNull Activity activity, @StyleRes int themeResId) { | ||
super(activity, themeResId); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected View createContentView(@NonNull Activity activity) { | ||
return View.inflate(activity, R.layout.color_picker_content, null); | ||
} | ||
|
||
@CallSuper | ||
@Override | ||
protected void initView(@NonNull View contentView) { | ||
cancelView = contentView.findViewById(R.id.color_picker_cancel); | ||
hexView = contentView.findViewById(R.id.color_picker_hex); | ||
okView = contentView.findViewById(R.id.color_picker_ok); | ||
colorGradientView = contentView.findViewById(R.id.color_picker_panel); | ||
brightnessGradientView = contentView.findViewById(R.id.color_picker_bright); | ||
} | ||
|
||
@CallSuper | ||
@Override | ||
protected void initData() { | ||
initialized = true; | ||
if (cancelView != null) { | ||
cancelView.setOnClickListener(this); | ||
} | ||
if (okView != null) { | ||
okView.setOnClickListener(this); | ||
} | ||
hexView.getPaint().setStrokeWidth(hexView.getResources().getDisplayMetrics().density * 3); | ||
colorGradientView.setOnColorChangedListener(this); | ||
brightnessGradientView.setOnColorChangedListener(this); | ||
colorGradientView.setBrightnessGradientView(brightnessGradientView); | ||
//将触发onColorChanged,故必须先待其他控件初始化完成后才能调用 | ||
colorGradientView.setColor(initColor); | ||
} | ||
|
||
@CallSuper | ||
@Override | ||
public void onClick(View v) { | ||
int id = v.getId(); | ||
if (id == R.id.color_picker_cancel) { | ||
PickerLog.print("cancel clicked"); | ||
onCancel(); | ||
dismiss(); | ||
} else if (id == R.id.color_picker_ok) { | ||
PickerLog.print("ok clicked"); | ||
onOk(); | ||
dismiss(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onColorChanged(@ColorInt int color) { | ||
updateCurrentColor(color); | ||
} | ||
|
||
protected void onCancel() { | ||
|
||
} | ||
|
||
protected void onOk() { | ||
if (onColorPickedListener != null) { | ||
onColorPickedListener.onColorPicked(getCurrentColor()); | ||
} | ||
} | ||
|
||
private void updateCurrentColor(@ColorInt int color) { | ||
String hexString = Utils.toHexString(color, false).toUpperCase(Locale.PRC); | ||
hexView.setText(hexString); | ||
hexView.setTextColor(Utils.reverseColor(color)); | ||
hexView.setBackgroundColor(color); | ||
} | ||
|
||
/** | ||
* 设置初始默认颜色 | ||
* | ||
* @param initColor 颜色值,如:0xFFFF00FF | ||
*/ | ||
public void setInitColor(@ColorInt int initColor) { | ||
this.initColor = initColor; | ||
if (initialized) { | ||
colorGradientView.setColor(initColor); | ||
} | ||
} | ||
|
||
public void setOnColorPickListener(OnColorPickedListener onColorPickedListener) { | ||
this.onColorPickedListener = onColorPickedListener; | ||
} | ||
|
||
@ColorInt | ||
public final int getCurrentColor() { | ||
try { | ||
return Color.parseColor("#" + hexView.getText()); | ||
} catch (Exception e) { | ||
PickerLog.print(e); | ||
return initColor; | ||
} | ||
} | ||
|
||
public final TextView getOkView() { | ||
return okView; | ||
} | ||
|
||
public final TextView getHexView() { | ||
return hexView; | ||
} | ||
|
||
public final TextView getCancelView() { | ||
return cancelView; | ||
} | ||
|
||
public final ColorGradientView getColorGradientView() { | ||
return colorGradientView; | ||
} | ||
|
||
public final BrightnessGradientView getBrightnessGradientView() { | ||
return brightnessGradientView; | ||
} | ||
|
||
} |
Oops, something went wrong.