[3.4.0] add func of audio manager invoke biz
This commit is contained in:
@@ -2,11 +2,13 @@ package com.mogo.och.taxi.passenger.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.ClipDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.LayerDrawable
|
||||
import android.media.AudioManager
|
||||
import android.provider.Settings
|
||||
import android.text.TextUtils
|
||||
import android.util.AttributeSet
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
@@ -14,9 +16,14 @@ import android.view.View
|
||||
import android.widget.SeekBar
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.mogo.commons.module.intent.IMogoIntentListener
|
||||
import com.mogo.commons.module.intent.IntentManager
|
||||
import com.mogo.commons.module.receiver.MogoReceiver
|
||||
import com.mogo.commons.module.receiver.MogoReceiver.ACTION_VOLUME_CHANGE
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
|
||||
import com.mogo.eagle.core.function.call.setting.CallerRequestActivityHandleManager
|
||||
import com.mogo.eagle.core.utilcode.util.BrightnessUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.och.common.module.wigets.MineGradientDrawable
|
||||
import com.mogo.och.taxi.passenger.R
|
||||
import kotlinx.android.synthetic.main.taxi_p_setting_view.view.*
|
||||
@@ -26,7 +33,8 @@ class TaxiPSettingView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : ConstraintLayout(context, attrs, defStyleAttr), IMoGoAutopilotStatusListener {
|
||||
) : ConstraintLayout(context, attrs, defStyleAttr), IMoGoAutopilotStatusListener,
|
||||
IMogoIntentListener {
|
||||
|
||||
companion object {
|
||||
const val TAG = "TaxiPSettingView"
|
||||
@@ -49,17 +57,21 @@ class TaxiPSettingView @JvmOverloads constructor(
|
||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||
tvSoundPer.text = "$progress%"
|
||||
if (fromUser) {
|
||||
if(!Settings.System.canWrite(context)){
|
||||
CallerRequestActivityHandleManager.requestPermission(TAG,Settings.ACTION_MANAGE_WRITE_SETTINGS)
|
||||
if (!Settings.System.canWrite(context)) {
|
||||
CallerRequestActivityHandleManager.requestPermission(
|
||||
TAG,
|
||||
Settings.ACTION_MANAGE_WRITE_SETTINGS
|
||||
)
|
||||
return
|
||||
}
|
||||
if(BrightnessUtils.isAutoBrightnessEnabled()){
|
||||
BrightnessUtils.setBrightness(((progress.toFloat() / 100) * 255).toInt())
|
||||
}else{
|
||||
if (BrightnessUtils.isAutoBrightnessEnabled()) {
|
||||
BrightnessUtils.setBrightness(((progress.toFloat() / 100) * 255).toInt())
|
||||
} else {
|
||||
BrightnessUtils.setAutoBrightnessEnabled(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
||||
})
|
||||
@@ -93,20 +105,23 @@ class TaxiPSettingView @JvmOverloads constructor(
|
||||
context?.let {
|
||||
mAudioManager = it.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
mMaxVolume = mAudioManager?.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
|
||||
val mCurrentVolume = mAudioManager?.getStreamVolume(AudioManager.STREAM_MUSIC)
|
||||
mMaxVolume?.let { max ->
|
||||
mCurrentVolume?.let { current ->
|
||||
if (current == 1) {
|
||||
sb_voice_bar.progress = 5
|
||||
tvVoicePer.text = "5%"
|
||||
} else {
|
||||
val fl = current.toFloat() / max * 100
|
||||
sb_voice_bar.progress = fl.toInt()
|
||||
tvVoicePer.text = "${fl.toInt()}%"
|
||||
}
|
||||
updateVolume()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateVolume() {
|
||||
val mCurrentVolume = mAudioManager?.getStreamVolume(AudioManager.STREAM_MUSIC)
|
||||
mMaxVolume?.let { max ->
|
||||
mCurrentVolume?.let { current ->
|
||||
if (current == 1) {
|
||||
sb_voice_bar.progress = 5
|
||||
tvVoicePer.text = "5%"
|
||||
} else {
|
||||
val fl = current.toFloat() / max * 100
|
||||
sb_voice_bar.progress = fl.toInt()
|
||||
tvVoicePer.text = "${fl.toInt()}%"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,18 +140,41 @@ class TaxiPSettingView @JvmOverloads constructor(
|
||||
return ld
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
IntentManager.getInstance().registerIntentListener(ACTION_VOLUME_CHANGE, this)
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
IntentManager.getInstance().unregisterIntentListener(ACTION_VOLUME_CHANGE, this)
|
||||
}
|
||||
|
||||
override fun onWindowVisibilityChanged(visibility: Int) {
|
||||
super.onWindowVisibilityChanged(visibility)
|
||||
if(visibility == View.VISIBLE){
|
||||
if (visibility == View.VISIBLE) {
|
||||
sb_light_bar.progress = (BrightnessUtils.getBrightness() * 100) / 255
|
||||
}
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasWindowFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasWindowFocus)
|
||||
if(hasWindowFocus){
|
||||
if (hasWindowFocus) {
|
||||
sb_light_bar.progress = (BrightnessUtils.getBrightness() * 100) / 255
|
||||
}
|
||||
}
|
||||
|
||||
override fun onIntentReceived(intentStr: String?, intent: Intent?) {
|
||||
if (TextUtils.equals(ACTION_VOLUME_CHANGE, intentStr)) {
|
||||
if (intent!!.getIntExtra(
|
||||
MogoReceiver.EXTRA_VOLUME_STREAM_TYPE, -1
|
||||
) == AudioManager.STREAM_MUSIC
|
||||
) {
|
||||
ThreadUtils.runOnUiThread {
|
||||
updateVolume()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,6 +44,7 @@ public class MogoServices implements IMogoIntentListener {
|
||||
mIntentManager.registerIntentListener(MogoReceiver.ACTION_VOICE_UI, this);
|
||||
mIntentManager.registerIntentListener(MogoReceiver.ACTION_VOICE_READY, this);
|
||||
mIntentManager.registerIntentListener(ConnectivityManager.CONNECTIVITY_ACTION, this);
|
||||
mIntentManager.registerIntentListener(MogoReceiver.ACTION_VOLUME_CHANGE, this);
|
||||
}
|
||||
|
||||
private void registerMogoReceiver(Context context) {
|
||||
@@ -59,6 +60,7 @@ public class MogoServices implements IMogoIntentListener {
|
||||
filter.addAction(MogoReceiver.ACTION_VOICE_READY);
|
||||
filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
||||
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
filter.addAction(MogoReceiver.ACTION_VOLUME_CHANGE);
|
||||
try {
|
||||
context.getApplicationContext().registerReceiver(receiver, filter);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mogo.commons.module.receiver;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mogo.commons.module.intent.IntentManager;
|
||||
@@ -28,6 +29,10 @@ public class MogoReceiver extends BroadcastReceiver {
|
||||
public static final String VALUE_DISMISS = "dismiss";
|
||||
public static final String VALUE_SHOW = "show";
|
||||
|
||||
//音量变化
|
||||
public static final String ACTION_VOLUME_CHANGE = "android.media.VOLUME_CHANGED_ACTION";
|
||||
public static final String EXTRA_VOLUME_STREAM_TYPE = "android.media.EXTRA_VOLUME_STREAM_TYPE";
|
||||
|
||||
/**
|
||||
* 小智语音准备就绪
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user