Pq 2 роки тому
батько
коміт
20dd738d7f

+ 32 - 0
musictuner/src/main/java/com/cooleshow/musictuner/bean/MusicTransposingDataBean.java

@@ -0,0 +1,32 @@
+package com.cooleshow.musictuner.bean;
+
+import com.contrarywind.interfaces.IPickerViewData;
+
+/**
+ * Author by pq, Date on 2022/10/25.
+ */
+public class MusicTransposingDataBean implements IPickerViewData {
+    private int value;//移调的值 负数为降调 正数为升调
+    private String title;//显示名称
+
+    public int getValue() {
+        return value;
+    }
+
+    public void setValue(int value) {
+        this.value = value;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    @Override
+    public String getPickerViewText() {
+        return getTitle();
+    }
+}

+ 13 - 0
musictuner/src/main/java/com/cooleshow/musictuner/constants/MusicTunerConstants.java

@@ -0,0 +1,13 @@
+package com.cooleshow.musictuner.constants;
+
+/**
+ * Author by pq, Date on 2022/10/25.
+ */
+public class MusicTunerConstants {
+    public final static String[] TITLES = new String[]{"没有移调",
+            "长笛:C大调", "高音萨克斯:降B大调", "中音萨克斯:降E大调",
+            "单簧管:降B大调", "双簧管:C大调", "竖笛:C调大调",
+            "小号:降B大调", "长号:C大调", "圆号:F大调",
+            "大号:降B大调", "上低音号:C大调", "上低音号:降B大调"};
+    public final static int[] TRANSPOSING_VALUES = new int[]{0, 0, -2, -9, -2, 0, 12, -2, 0, 5, -2, 0, -2};
+}

+ 27 - 4
musictuner/src/main/java/com/cooleshow/musictuner/utils/VoiceDataUtils.java

@@ -95,19 +95,35 @@ public class VoiceDataUtils {
         return voiceToneBean;
     }
 
+    private int currentTransposingValue = 0;
+
     private VoiceToneBean buildBean(int pos, int beforePos, int afterPos) {
+        int namePos = correctPosition(pos);
+        int beforeNamePos = correctPosition(beforePos);
+        int nameAfterPos = correctPosition(afterPos);
         VoiceToneBean voiceToneBean = new VoiceToneBean();
-        voiceToneBean.name = countName(pos);
+        voiceToneBean.name = countName(namePos);
         voiceToneBean.voiceFrequencyValue = countWithMusicHzStandard2(ALL_VOICE_SAMPLES[pos]);
-        voiceToneBean.beforeName = countName(beforePos);
+        voiceToneBean.beforeName = countName(beforeNamePos);
         voiceToneBean.beforeVoiceFrequencyValue = countWithMusicHzStandard2(ALL_VOICE_SAMPLES[beforePos]);
-        voiceToneBean.afterName = countName(afterPos);
+        voiceToneBean.afterName = countName(nameAfterPos);
         voiceToneBean.afterVoiceFrequencyValue = countWithMusicHzStandard2(ALL_VOICE_SAMPLES[afterPos]);
         Log.i("qaz", "result name:" + voiceToneBean.name +
                 "\nvalue:" + voiceToneBean.voiceFrequencyValue);
         return voiceToneBean;
     }
 
+    private int correctPosition(int pos) {
+        pos += currentTransposingValue;
+        if (pos < 0) {
+            pos = 0;
+        }
+        if (pos > ALL_VOICE_SAMPLES.length - 1) {
+            pos = ALL_VOICE_SAMPLES.length - 1;
+        }
+        return pos;
+    }
+
     private String countName(int pos) {
         int row = pos / 12;
         int frequencyValuePosition = (pos % 12);
@@ -145,7 +161,6 @@ public class VoiceDataUtils {
 
     public int getCurrentMusicHzStandard() {
         return currentMusicHzStandard;
-
     }
 
     public void reduceCurrentMusicHzStandard() {
@@ -167,4 +182,12 @@ public class VoiceDataUtils {
         double value = target / DEFAULT_MUSIC_HZ_STANDARD_440_HZ * currentMusicHzStandard;
         return value;
     }
+
+    /**
+     * 设置移调值
+     * @param value
+     */
+    public void setTransposingValue(int value) {
+        this.currentTransposingValue = value;
+    }
 }

+ 84 - 1
musictuner/src/main/java/com/cooleshow/musictuner/widget/MusicTunerSettingDialog.java

@@ -3,12 +3,22 @@ package com.cooleshow.musictuner.widget;
 import android.app.Dialog;
 import android.content.Context;
 import android.os.Bundle;
+import android.view.Gravity;
 import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
 import android.widget.TextView;
 
+import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
+import com.bigkoo.pickerview.view.OptionsPickerView;
 import com.cooleshow.musictuner.R;
+import com.cooleshow.musictuner.bean.MusicTransposingDataBean;
+import com.cooleshow.musictuner.constants.MusicTunerConstants;
 import com.cooleshow.musictuner.utils.VoiceDataUtils;
 
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+
 import androidx.annotation.NonNull;
 
 /**
@@ -17,22 +27,43 @@ import androidx.annotation.NonNull;
 public class MusicTunerSettingDialog extends Dialog implements View.OnClickListener {
     private OnEventListener onEventListener;
     private TextView mTvCurrentMusicHzStandard;
+    private ArrayList<MusicTransposingDataBean> mList;
+    private OptionsPickerView pvOptions;
+    private TextView mTvCurrentTransposing;
+    private MusicTransposingDataBean currentTransposingDataBean;
+    private Context mContext;
 
     public MusicTunerSettingDialog(@NonNull Context context) {
         super(context, com.cooleshow.base.R.style.DialogStyle);
+        this.mContext = context;
     }
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.dialog_setting_layout);
+        mTvCurrentTransposing = findViewById(R.id.tv_current_transposing);
         mTvCurrentMusicHzStandard = findViewById(R.id.tv_current_music_hz_standard);
         findViewById(R.id.view_add_hz).setOnClickListener(this);
         findViewById(R.id.view_reduce_hz).setOnClickListener(this);
         findViewById(R.id.tv_reset).setOnClickListener(this);
+        findViewById(R.id.view_transposing_bg).setOnClickListener(this);
+        findViewById(R.id.tv_confirm).setOnClickListener(this);
+        buildSample();
         updateCurrentHzStandardText();
     }
 
+    private void buildSample() {
+        mList = new ArrayList<>();
+        for (int i = 0; i < MusicTunerConstants.TITLES.length; i++) {
+            String title = MusicTunerConstants.TITLES[i];
+            MusicTransposingDataBean musicTransposingDataBean = new MusicTransposingDataBean();
+            musicTransposingDataBean.setTitle(title);
+            musicTransposingDataBean.setValue(MusicTunerConstants.TRANSPOSING_VALUES[i]);
+            mList.add(musicTransposingDataBean);
+        }
+    }
+
     public void setOnEventListener(OnEventListener onEventListener) {
         this.onEventListener = onEventListener;
     }
@@ -55,13 +86,23 @@ public class MusicTunerSettingDialog extends Dialog implements View.OnClickListe
             return;
         }
 
-        if(id == R.id.tv_reset){
+        if (id == R.id.tv_reset) {
             if (onEventListener != null) {
                 onEventListener.onReset();
                 updateCurrentHzStandardText();
             }
             return;
         }
+        if (id == R.id.view_transposing_bg) {
+            selectMode();
+            return;
+        }
+        if (id == R.id.tv_confirm) {
+            if (currentTransposingDataBean != null) {
+                VoiceDataUtils.getInstance().setTransposingValue(currentTransposingDataBean.getValue());
+            }
+            dismiss();
+        }
     }
 
     public interface OnEventListener {
@@ -84,4 +125,46 @@ public class MusicTunerSettingDialog extends Dialog implements View.OnClickListe
         super.show();
         updateCurrentHzStandardText();
     }
+
+    private void selectMode() {
+        pvOptions = new OptionsPickerBuilder(mContext, (options1, options2, options3, v) -> {
+            if (options1 < mList.size()) {
+                MusicTransposingDataBean musicTransposingDataBean = mList.get(options1);
+                this.currentTransposingDataBean = musicTransposingDataBean;
+                mTvCurrentTransposing.setText(musicTransposingDataBean.getTitle());
+            }
+        }).setLayoutRes(R.layout.pickerview_transposing_mode_select_layout, v -> {
+            //自定义布局中的控件初始化及事件处理
+            final TextView tvSubmit = (TextView) v.findViewById(com.cooleshow.base.R.id.tv_finish);
+            TextView ivCancel = (TextView) v.findViewById(com.cooleshow.base.R.id.tv_cancel);
+            tvSubmit.setOnClickListener(v12 -> {
+                pvOptions.returnData();
+                pvOptions.dismiss();
+            });
+            ivCancel.setOnClickListener(v1 -> pvOptions.dismiss());
+
+        }).isDialog(true).build();
+        Dialog dialog = pvOptions.getDialog();
+//        if (dialog != null) {
+//            Window window = dialog.getWindow();
+//            //设置dialog在屏幕底部
+//            window.setGravity(Gravity.BOTTOM);
+//            //设置dialog弹出时的动画效果,从屏幕底部向上弹出
+//            window.setWindowAnimations(com.cooleshow.base.R.style.BottomAnimation);
+//            window.getDecorView().setPadding(0, 0, 0, 0);
+//            //获得window窗口的属性
+//            WindowManager.LayoutParams lp = window.getAttributes();
+//            //设置窗口宽度为充满全屏
+//            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
+//            //设置窗口高度为包裹内容
+//            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
+//            lp.horizontalMargin = 0;
+//            lp.verticalMargin = 0;
+//            //将设置好的属性set回去
+//            window.setAttributes(lp);
+//        }
+        pvOptions.setPicker(mList);
+        pvOptions.show();
+
+    }
 }

+ 1 - 0
musictuner/src/main/res/layout/dialog_setting_layout.xml

@@ -125,6 +125,7 @@
         app:layout_constraintTop_toBottomOf="@+id/view_add_hz" />
 
     <TextView
+        android:id="@+id/tv_confirm"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintLeft_toLeftOf="parent"
         android:layout_width="0dp"

+ 76 - 0
musictuner/src/main/res/layout/pickerview_transposing_mode_select_layout.xml

@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:paddingBottom="10dp"
+    android:background="@drawable/bg_white_10dp"
+    android:orientation="vertical">
+
+    <RelativeLayout
+        android:layout_width="match_parent"
+        android:layout_height="50dp">
+
+
+        <TextView
+            android:id="@+id/tv_cancel"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerVertical="true"
+            android:layout_marginLeft="17dp"
+            android:text="取消"
+            android:textColor="@color/color_999999"
+            android:textSize="@dimen/dp_16" />
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerInParent="true"
+            android:text=""
+            android:textColor="@color/color_1a1a1a"
+            android:textSize="18dp" />
+
+        <TextView
+            android:id="@+id/tv_finish"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentRight="true"
+            android:layout_centerVertical="true"
+            android:layout_marginRight="17dp"
+            android:padding="8dp"
+            android:text="确定"
+            android:textColor="@color/colorPrimary"
+            android:textSize="@dimen/dp_16" />
+
+    </RelativeLayout>
+
+    <View style="@style/line_style" />
+    <!--此部分需要完整复制过去,删减或者更改ID会导致初始化找不到内容而报空-->
+    <LinearLayout
+        android:id="@+id/optionspicker"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/dp_200"
+        android:gravity="center"
+        android:minHeight="150dp"
+        android:orientation="horizontal">
+
+        <com.contrarywind.view.WheelView
+            android:id="@+id/options1"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1" />
+
+        <com.contrarywind.view.WheelView
+            android:id="@+id/options2"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1" />
+
+        <com.contrarywind.view.WheelView
+            android:id="@+id/options3"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1" />
+    </LinearLayout>
+
+
+</LinearLayout>