diff --git a/modules/mogo-module-search/build.gradle b/modules/mogo-module-search/build.gradle index e54035ab88..af33a5d520 100644 --- a/modules/mogo-module-search/build.gradle +++ b/modules/mogo-module-search/build.gradle @@ -35,7 +35,6 @@ android { } } - } dependencies { @@ -74,6 +73,7 @@ dependencies { // implementation project(':modules:mogo-module-map') } implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + implementation 'com.zhidaoauto.voice.controller:api:1.0.2' } diff --git a/modules/mogo-module-search/libs/carmanager.jar b/modules/mogo-module-search/libs/carmanager.jar new file mode 100644 index 0000000000..673dda0aac Binary files /dev/null and b/modules/mogo-module-search/libs/carmanager.jar differ diff --git a/modules/mogo-module-search/src/main/java/com/mogo/module/navi/manager/VolumeManager.java b/modules/mogo-module-search/src/main/java/com/mogo/module/navi/manager/VolumeManager.java new file mode 100644 index 0000000000..26bbada2d3 --- /dev/null +++ b/modules/mogo-module-search/src/main/java/com/mogo/module/navi/manager/VolumeManager.java @@ -0,0 +1,196 @@ +package com.mogo.module.navi.manager; + +import android.content.Context; +import android.media.AudioManager; +import android.text.TextUtils; +import android.util.Log; +import com.mogo.module.navi.BuildConfig; +import com.zhidao.manager.audio.ZDAudioManager; +import com.zhidao.manager.listener.OnListener; +import com.zhidao.manager.system.CarSettingManager; +import com.zhidao.manager.system.volume.IVolumeModel; +import com.zhidao.manager.system.volume.VolumeModel; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + +/** + * 音量管理 + */ + +public class VolumeManager { + + private final String TAG = "VolumeManager"; + private final int MAX_VOLUME = 100; + private final int MIN_VOLUME = 0; + private static Object lock = new Object(); + private static VolumeManager volumeManager; + private Context mContext; + private VolumeModel mVolumeModel; + private final static int MAX_VOL = 100; + private final static int MIN_VOL = 0; + private AudioManager mAudioManager; + private final int mStreamType = AudioManager.STREAM_MUSIC; + + + public static VolumeManager getInstance(Context context) { + if (volumeManager == null) { + synchronized (lock) { + if (volumeManager == null) { + volumeManager = new VolumeManager(context.getApplicationContext()); + } + } + } + return volumeManager; + } + + private VolumeManager(Context context) { + mContext = context.getApplicationContext(); + mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + mVolumeModel = (VolumeModel) CarSettingManager.getInstance(mContext).getModel( + CarSettingManager.VOLUME_MODEL); + mVolumeModel.registerOnChangedListener(new OnListener.OnChangedListener() { + @Override + public void onChanged(Integer arg0) { + Log.d(TAG, "当前音量:" + arg0); + } + }); + } + + /** + * 增大音量 + */ + public void incVolume() { + if (isFuture()) { + mAudioManager.adjustStreamVolume(mStreamType, AudioManager.ADJUST_RAISE, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE); + Log.d(TAG, "当前音量:" + mAudioManager.getStreamVolume(mStreamType)); + } else { + setSysVolume(mVolumeModel.getVolume() + 10); + } + } + + + public int getMaxVol(){ + if (isFuture()) { + return MAX_VOLUME; + } + return MAX_VOL; + + } + + /** + * 减小音量 + */ + public void decVolume() { + if (isFuture()) { + mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE); + Log.d(TAG, "当前音量:" + getSysVolume()); + } else { + setSysVolume(mVolumeModel.getVolume() - 10); + } + } + + /** + * 设置最大音量 + */ + public void maxVolume() { + if (isFuture()) { + mAudioManager.setStreamVolume(mStreamType, MAX_VOL, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE); + Log.d(TAG, "当前音量:" + getSysVolume()); + } else { + setSysVolume(MAX_VOLUME); + } + } + + /** + * 设置最小音量 + */ + public void minVolume() { + if (isFuture()) { + mAudioManager.setStreamVolume(mStreamType, MIN_VOL, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE); + Log.d(TAG, "当前音量:" + getSysVolume()); + } else { + setSysVolume(MIN_VOLUME); + } + } + + /** + * 获取当前音量 + */ + public int getSysVolume() { + if (isFuture()) { + return mAudioManager.getStreamVolume(mStreamType); + } else { + return mVolumeModel.getVolume(); + } + } + + /** + * 设置音量 + */ + public void setSysVolume(int volume) { + if (isFuture()) { + mAudioManager.setStreamVolume(mStreamType, volume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE); + } else { + mVolumeModel.setVolume(volume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE); + Log.d(TAG, "future->当前音量:" + mVolumeModel.getVolume()); + } + } + + /** + * 是否是最大音量 + * + * @return + */ + public boolean isMaxVolume() { + if (isFuture()) { + return mAudioManager.getStreamVolume(mStreamType) >= MAX_VOL; + } else { + return mVolumeModel.getVolume() >= MAX_VOLUME; + } + } + + /** + * 是否是最小音量 + * + * @return + */ + public boolean isMinVolume() { + if (isFuture()) { + return mAudioManager.getStreamVolume(mStreamType) <= MIN_VOL; + } else { + return mVolumeModel.getVolume() <= MIN_VOLUME; + } + } + + /** + * 是否打开静音 + * + * @param mute + */ + public void innerMute(boolean mute) { + ZDAudioManager.getInstance().setMute(mute); + } + + /* + 判断是否future渠道 + */ + private boolean isFuture() { + + //return false; + try { + Class buildConfig = Class.forName("com.mogo.launcher.BuildConfig"); + Field flavor = buildConfig.getDeclaredField("FLAVOR"); + //String descriptor= Modifier.toString(flavor.getModifiers()); + return TextUtils.equals((CharSequence) flavor.get(null),"zhidao"); + + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + return false; + } +} diff --git a/modules/mogo-module-search/src/main/java/com/mogo/module/navi/ui/setting/NaviSettingFragment.kt b/modules/mogo-module-search/src/main/java/com/mogo/module/navi/ui/setting/NaviSettingFragment.kt index 2149aa2620..08bbc985f5 100644 --- a/modules/mogo-module-search/src/main/java/com/mogo/module/navi/ui/setting/NaviSettingFragment.kt +++ b/modules/mogo-module-search/src/main/java/com/mogo/module/navi/ui/setting/NaviSettingFragment.kt @@ -19,6 +19,7 @@ import com.mogo.module.navi.constants.DataConstants import com.mogo.module.navi.constants.SearchServiceHolder import com.mogo.module.navi.manager.AddressManager import com.mogo.module.navi.manager.SettingManager +import com.mogo.module.navi.manager.VolumeManager import com.mogo.module.navi.ui.base.BaseFragment import com.mogo.service.MogoServicePaths import com.mogo.service.module.IMogoSettingManager @@ -136,11 +137,15 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener { private fun initEvent() { iv_sound_plus.setOnClickListener { - sb_navi_volume_progress.progress = ++sb_navi_volume_progress.progress + VolumeManager.getInstance(context) + .incVolume() + sb_navi_volume_progress.progress = sb_navi_volume_progress.progress.plus(10) SettingManager.volume = sb_navi_volume_progress.progress } iv_sound_minus.setOnClickListener { - sb_navi_volume_progress.progress = --sb_navi_volume_progress.progress + VolumeManager.getInstance(context) + .decVolume() + sb_navi_volume_progress.progress = sb_navi_volume_progress.progress.minus(10) SettingManager.volume = sb_navi_volume_progress.progress } @@ -149,9 +154,10 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener { rb_navi_no_high_way.setOnCheckedChangeListener(this) rb_navi_fee.setOnCheckedChangeListener(this) - var audioManager = activity?.getSystemService(Context.AUDIO_SERVICE) as AudioManager - sb_navi_volume_progress.max = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) - sb_navi_volume_progress.progress = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) + sb_navi_volume_progress.max = VolumeManager.getInstance(context) + .getMaxVol() + sb_navi_volume_progress.progress = VolumeManager.getInstance(context) + .sysVolume sb_navi_volume_progress.setOnSeekBarChangeListener(object : OnSeekBarChangeListener { @@ -160,9 +166,17 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener { progress: Int, fromUser: Boolean ) { - audioManager.setStreamVolume( - AudioManager.STREAM_MUSIC, progress, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE - ) + if (fromUser) { + VolumeManager.getInstance(context) + .setSysVolume(progress) + SettingManager.volume = sb_navi_volume_progress.progress + + } + +// audioManager.setStreamVolume( +// AudioManager.STREAM_MUSIC, progress, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE +// ) + } override fun onStartTrackingTouch(seekBar: SeekBar?) { @@ -240,15 +254,14 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener { } } - private fun clearHome(){ + private fun clearHome() { tv_navi_clear_home_address.visibility = View.GONE - tv_navi_home_address.text=getString(R.string.navi_set_home) + tv_navi_home_address.text = getString(R.string.navi_set_home) } - - private fun clearCompany(){ + private fun clearCompany() { tv_navi_clear_company_address.visibility = View.GONE - tv_navi_company_address.text=getString(R.string.navi_set_company) + tv_navi_company_address.text = getString(R.string.navi_set_company) } @@ -271,17 +284,18 @@ class NaviSettingFragment : BaseFragment(), OnCheckedChangeListener { return } if (searchPoi?.type == DataConstants.TYPE_COMPANY_ADDRESS) { - tv_navi_company_address.text=searchPoi.address - tv_navi_clear_company_address.visibility=View.VISIBLE + tv_navi_company_address.text = searchPoi.address + tv_navi_clear_company_address.visibility = View.VISIBLE } else { - tv_navi_home_address.text=searchPoi.address - tv_navi_clear_home_address.visibility=View.VISIBLE + tv_navi_home_address.text = searchPoi.address + tv_navi_clear_home_address.visibility = View.VISIBLE } } override fun onDestroyView() { super.onDestroyView() - EventBus.getDefault().unregister(this) + EventBus.getDefault() + .unregister(this) } }