自定义了com.github.QuadFlask:colorpicker:0.0.15调色盘库

优化修复BUG
This commit is contained in:
muqing 2024-01-27 17:23:51 +08:00
parent 70a2a4e8b1
commit 05a5fe918f
19 changed files with 337 additions and 55 deletions

View File

@ -18,7 +18,7 @@ android {
//noinspection OldTargetApi
targetSdk 31
versionCode 1
versionName "1.9.5"
versionName "1.9.6"
}
compileOptions {
@ -44,6 +44,7 @@ android {
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
@ -60,5 +61,5 @@ dependencies {
//
implementation 'com.mpatric:mp3agic:0.9.1'
implementation 'com.github.QuadFlask:colorpicker:0.0.15'
// implementation 'com.github.QuadFlask:colorpicker:0.0.15'
}

View File

@ -12,8 +12,8 @@
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.9.3",
"outputFile": "Cloud_music-debug-v1.9.3.apk"
"versionName": "1.9.5",
"outputFile": "Cloud_music-debug-v1.9.5.apk"
}
],
"elementType": "File"

View File

@ -0,0 +1,189 @@
package com.colorpicker.slider;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import androidx.annotation.DimenRes;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import com.muqingbfq.R;
public abstract class AbsCustomSlider extends View {
protected Bitmap bitmap;
protected Canvas bitmapCanvas;
protected Bitmap bar;
protected Canvas barCanvas;
protected OnValueChangedListener onValueChangedListener;
protected int barOffsetX;
protected int handleRadius = 20;
protected int barHeight = 5;
protected float value = 1;
protected boolean showBorder = false;
private boolean inVerticalOrientation = false;
public AbsCustomSlider(Context context) {
super(context);
init(context, null);
}
public AbsCustomSlider(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public AbsCustomSlider(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
TypedArray styledAttrs = context.getTheme().obtainStyledAttributes(
attrs, R.styleable.AbsCustomSlider, 0, 0);
try {
inVerticalOrientation = styledAttrs.getBoolean(
R.styleable.AbsCustomSlider_inVerticalOrientation, inVerticalOrientation);
} finally {
styledAttrs.recycle();
}
}
protected void updateBar() {
handleRadius = getDimension(R.dimen.default_slider_handler_radius);
barHeight = getDimension(R.dimen.default_slider_bar_height);
barOffsetX = handleRadius;
if (bar == null)
createBitmaps();
drawBar(barCanvas);
invalidate();
}
protected void createBitmaps() {
int width;
int height;
if (inVerticalOrientation) {
width = getHeight();
height = getWidth();
} else {
width = getWidth();
height = getHeight();
}
bar = Bitmap.createBitmap(Math.max(width - barOffsetX * 2, 1), barHeight, Bitmap.Config.ARGB_8888);
barCanvas = new Canvas(bar);
if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) {
if (bitmap != null) bitmap.recycle();
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmapCanvas = new Canvas(bitmap);
}
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int width;
int height;
if (inVerticalOrientation) {
width = getHeight();
height = getWidth();
canvas.rotate(-90);
canvas.translate(-width, 0);
} else {
width = getWidth();
height = getHeight();
}
if (bar != null && bitmapCanvas != null) {
bitmapCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
bitmapCanvas.drawBitmap(bar, barOffsetX, (height - bar.getHeight()) / 2, null);
float x = handleRadius + value * (width - handleRadius * 2);
float y = height / 2f;
drawHandle(bitmapCanvas, x, y);
canvas.drawBitmap(bitmap, 0, 0, null);
}
}
protected abstract void drawBar(Canvas barCanvas);
protected abstract void onValueChanged(float value);
protected abstract void drawHandle(Canvas canvas, float x, float y);
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
updateBar();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int width = 0;
if (widthMode == MeasureSpec.UNSPECIFIED)
width = widthMeasureSpec;
else if (widthMode == MeasureSpec.AT_MOST)
width = MeasureSpec.getSize(widthMeasureSpec);
else if (widthMode == MeasureSpec.EXACTLY)
width = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int height = 0;
if (heightMode == MeasureSpec.UNSPECIFIED)
height = heightMeasureSpec;
else if (heightMode == MeasureSpec.AT_MOST)
height = MeasureSpec.getSize(heightMeasureSpec);
else if (heightMode == MeasureSpec.EXACTLY)
height = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(width, height);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE: {
if (bar != null) {
if (inVerticalOrientation) {
value = 1 - (event.getY() - barOffsetX) / bar.getWidth();
} else {
value = (event.getX() - barOffsetX) / bar.getWidth();
}
value = Math.max(0, Math.min(value, 1));
onValueChanged(value);
invalidate();
}
break;
}
case MotionEvent.ACTION_UP: {
onValueChanged(value);
if (onValueChangedListener != null)
onValueChangedListener.onValueChanged(value);
invalidate();
}
}
return true;
}
protected int getDimension(@DimenRes int id) {
return getResources().getDimensionPixelSize(id);
}
public void setShowBorder(boolean showBorder) {
this.showBorder = showBorder;
}
public void setOnValueChangedListener(OnValueChangedListener onValueChangedListener) {
this.onValueChangedListener = onValueChangedListener;
}
}

View File

@ -2,10 +2,7 @@ package com.muqingbfq.fragment;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
@ -19,7 +16,7 @@ import com.muqingbfq.R;
import com.muqingbfq.api.url;
import com.muqingbfq.bfqkz;
import com.muqingbfq.databinding.FragmentBflbDbBinding;
import com.muqingbfq.databinding.ListMp3Binding;
import com.muqingbfq.databinding.ListMp3ABinding;
import com.muqingbfq.list.MyViewHoder;
import com.muqingbfq.main;
import com.muqingbfq.yc;
@ -45,16 +42,14 @@ public class bflb_db extends BottomSheetDialog {
binding.lb.smoothScrollToPosition(getI());
}
});
binding.sc.setOnClickListener(view -> {
new MaterialAlertDialogBuilder(getContext())
.setTitle("清空播放列表")
.setPositiveButton("确定", (dialogInterface, i) -> {
bfqkz.list.clear();
adapter.notifyDataSetChanged();
})
.setNegativeButton("取消", null)
.show();
});
binding.sc.setOnClickListener(view -> new MaterialAlertDialogBuilder(getContext())
.setTitle("清空播放列表")
.setPositiveButton("确定", (dialogInterface, i) -> {
bfqkz.list.clear();
adapter.notifyDataSetChanged();
})
.setNegativeButton("取消", null)
.show());
} catch (Exception e) {
yc.start(getContext(), e);
}
@ -84,21 +79,21 @@ public class bflb_db extends BottomSheetDialog {
@Override
public MyViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
// View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_mp3, parent, false);
return new MyViewHoder(ListMp3Binding.
return new MyViewHoder(ListMp3ABinding.
inflate(getLayoutInflater(),parent,false));
}
@Override
public void onBindViewHolder(@NonNull MyViewHoder holder, int position) {
MP3 x = bfqkz.list.get(position);
holder.binding.name.setText(x.name);
holder.binding.zz.setText(x.zz);
holder.bindingA.name.setText(x.name);
holder.bindingA.zz.setText(x.zz);
int color = ContextCompat.getColor(holder.getContext(), R.color.text);
if (bfqkz.xm != null && x.id.equals(bfqkz.xm.id)) {
color = ContextCompat.getColor(holder.getContext(), R.color.text_cz);
}
holder.binding.name.setTextColor(color);
holder.binding.zz.setTextColor(color);
holder.bindingA.name.setTextColor(color);
holder.bindingA.zz.setTextColor(color);
holder.itemView.setOnClickListener(view -> {
if (bfqkz.xm != x) {
bfqkz.xm = x;

View File

@ -118,6 +118,12 @@ public class bfq_db extends Fragment implements GestureDetector.OnGestureListene
textView.setText(str);
}
}
public static TextView getname() {
if (view != null) {
return findViewById(R.id.name);
}
return null;
}
@Override
public boolean onDown(@NonNull MotionEvent motionEvent) {
@ -140,6 +146,7 @@ public class bfq_db extends Fragment implements GestureDetector.OnGestureListene
@Override
public boolean onScroll(@Nullable MotionEvent motionEvent, @NonNull MotionEvent motionEvent1,
float v, float v1) {
getname().setTranslationX(view.getTranslationX() - v);
view.setBackgroundColor(ContextCompat.getColor(getContext(),R.color.bj));
return false;
}
@ -165,6 +172,8 @@ public class bfq_db extends Fragment implements GestureDetector.OnGestureListene
// 在这里添加你的逻辑代码
bfq_an.syq();
}
getname().setTranslationX(0);
return true;
}
}

View File

@ -149,6 +149,7 @@ public class home extends AppCompatActivity {
}
});
}
@Override
protected void onPause() {
super.onPause();
@ -168,23 +169,9 @@ public class home extends AppCompatActivity {
.replace(R.id.bfq_db, new bfq_db())
.commit();
}
private long time;
@Override
public void onBackPressed() {
if (bfqkz.mt.isPlaying()) {
Intent home = new Intent(Intent.ACTION_MAIN);
home.addCategory(Intent.CATEGORY_HOME);
startActivity(home);
} else {
if (time < System.currentTimeMillis() - 1000) {
time = System.currentTimeMillis();
gj.ts(this, "再按一次退出软件");
} else {
finish();
}
}
moveTaskToBack(true);
}
@Override
@ -201,8 +188,6 @@ public class home extends AppCompatActivity {
}
return super.onOptionsItemSelected(item);
}
/**
* 连接状态的回调接口连接成功时会调用onConnected()方法
*/

View File

@ -8,14 +8,20 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.muqingbfq.R;
import com.muqingbfq.databinding.ListMp3ABinding;
import com.muqingbfq.databinding.ListMp3Binding;
public class MyViewHoder extends RecyclerView.ViewHolder {
public ListMp3Binding binding;
public ListMp3ABinding bindingA;
public MyViewHoder(@NonNull ListMp3Binding itemView) {
super(itemView.getRoot());
binding = itemView;
}
public MyViewHoder(@NonNull ListMp3ABinding itemView) {
super(itemView.getRoot());
bindingA = itemView;
}
public Context getContext() {
return itemView.getContext();
}

View File

@ -22,15 +22,14 @@ import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import com.flask.colorpicker.ColorPickerView;
import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
import com.colorpicker.ColorPickerView;
import com.colorpicker.builder.ColorPickerDialogBuilder;
import com.google.android.material.materialswitch.MaterialSwitch;
import com.google.android.material.slider.Slider;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.muqingbfq.databinding.ActivitySzSetlrcBinding;
import com.muqingbfq.mq.FloatingLyricsService;
import com.muqingbfq.mq.gj;
import com.muqingbfq.mq.wj;
import com.muqingbfq.view.LrcView;
@ -198,7 +197,7 @@ public class sz extends AppCompatActivity {
.setTitle("调色盘")
.initialColor(Color.parseColor(setup.Color))
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(12)
.density(6)
.setOnColorSelectedListener(selectedColor -> {
})
.setPositiveButton("确定", (dialog, selectedColor, allColors) -> {

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/PickerEditText"
android:hint="Color Value"
android:inputType="textNoSuggestions" />

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="@dimen/default_preview_height"
android:background="@android:color/transparent"
android:gravity="center"
android:orientation="horizontal" />

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/default_preview_height"
android:layout_height="@dimen/default_preview_height"
android:background="@android:color/transparent"
android:padding="2dp">
<ImageView
android:layout_width="@dimen/default_preview_image_height"
android:layout_height="@dimen/default_preview_image_height"
android:src="@android:color/transparent"
android:id="@+id/image_preview"/>
</LinearLayout>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/color_indicator"
android:layout_width="32dp"
android:layout_height="32dp"
tools:ignore="ContentDescription" />

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="?android:attr/selectableItemBackground"
android:padding="10dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
tools:ignore="UselessParent">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/name"
android:singleLine="true"
android:textColor="@color/text"
android:textSize="16sp" />
<TextView
android:id="@+id/zz"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/text"
android:singleLine="true"
android:text="@string/zz" />
</LinearLayout>
</LinearLayout>

View File

@ -7,14 +7,5 @@
&lt;!&ndash; Secondary brand color. &ndash;&gt;
<item name="colorOnSecondary">@color/text</item>-->
<item name="android:windowLightStatusBar">false</item>
<item name="android:colorPrimary">@color/bj_tint</item>
<item name="colorPrimaryDark">@color/bj_tint</item>
<item name="tabStyle">@style/Widget.App.TabLayout</item>
<item name="toolbarStyle">@style/Widget.App.Toolbar</item>
</style>
<!--
<style name="ThemeOverlay.App.TabLayout" parent="">
<item name="colorPrimary">@color/bj_tint</item>
</style>-->
</resources>

View File

@ -6,4 +6,26 @@
<attr name="Lrcline" format="boolean" />
<attr name="addOnGlobalLayoutListener" format="boolean" />
</declare-styleable>
<declare-styleable name="ColorPickerPreference">
<attr name="alphaSlider" format="boolean"/>
<attr name="lightnessSlider" format="boolean"/>
<attr name="border" format="boolean"/>
<attr name="density" format="integer"/>
<attr name="initialColor" format="integer"/>
<attr name="wheelType" format="enum">
<enum name="FLOWER" value="0"/>
<enum name="CIRCLE" value="1"/>
</attr>
<attr name="lightnessSliderView" format="reference"/>
<attr name="alphaSliderView" format="reference"/>
<attr name="pickerColorEdit" format="boolean"/>
<attr name="pickerColorEditTextColor" format="integer"/>
<attr name="pickerTitle" format="reference|string"/>
<attr name="pickerButtonOk" format="reference|string"/>
<attr name="pickerButtonCancel" format="reference|string"/>
</declare-styleable>
<declare-styleable name="AbsCustomSlider">
<attr name="inVerticalOrientation" format="boolean"/>
</declare-styleable>
</resources>

View File

@ -11,4 +11,13 @@
<dimen name="lrc_timeline_height">1dp</dimen>
<dimen name="lrc_drawable_width">30dp</dimen>
<dimen name="lrc_time_width">40dp</dimen>
<dimen name="default_slider_height">36dp</dimen>
<dimen name="default_slider_margin">24dp</dimen>
<dimen name="default_slider_bar_height">4dp</dimen>
<dimen name="default_slider_handler_radius">10dp</dimen>
<dimen name="default_padding_side">24dp</dimen>
<dimen name="default_preview_height">40dp</dimen>
<dimen name="default_preview_image_height">36dp</dimen>
<dimen name="default_margin_top">20dp</dimen>
</resources>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="PickerEditText">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">4dp</item>
<item name="android:imeOptions">actionNext</item>
<item name="android:singleLine">true</item>
<item name="android:textSize">22sp</item>
</style>
</resources>

View File

@ -1,4 +1,4 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.1.0' apply false
}
}

View File

@ -15,4 +15,4 @@ dependencyResolutionManagement {
}
rootProject.name = "Cloud_music"
include ':app'
include ':app'