|  | @@ -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();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |