diff --git a/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/NumberFormatUtil.java b/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/NumberFormatUtil.java index 4f8e8db05e..4394f081b8 100644 --- a/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/NumberFormatUtil.java +++ b/OCH/common/common/src/main/java/com/mogo/och/common/module/utils/NumberFormatUtil.java @@ -38,4 +38,10 @@ public class NumberFormatUtil { } return ""; } + + public static String percentage(float numver,int decimal){ + float newNumber = numver*100; + return String.format("%."+decimal+"f",newNumber); + } + } diff --git a/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/TaxiPassengerBaseFragment.kt b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/TaxiPassengerBaseFragment.kt index f83dcf93d3..fee30133ba 100644 --- a/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/TaxiPassengerBaseFragment.kt +++ b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/TaxiPassengerBaseFragment.kt @@ -34,10 +34,13 @@ import com.mogo.och.unmanned.passenger.ui.statusview.StatusBarView import io.reactivex.disposables.Disposable import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.arrivedView import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.bottom +import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.cb_setting_light +import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.cb_setting_voice import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.chekAndStartAutopilotView import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.infoVideoView import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.itinerary import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.lbv_go2_center +import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.light_setting import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.mapBizView import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.mv_music_info import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.overMapView @@ -45,6 +48,7 @@ import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.pcnActionView import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.romaDistanceView import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.romaPView import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.speedView +import kotlinx.android.synthetic.main.taxt_u_p_base_fragment.voice_setting /** * 网约车基础Fragment,主要负责布局通用界面,处理站点面板和通话面板互斥情况 @@ -93,6 +97,24 @@ class TaxiPassengerBaseFragment : } private fun settingAndMusicListener() { + cb_setting_light.setOnCheckedChangeListener { buttonView, isChecked -> + if(buttonView.id==cb_setting_light.id){ + if(isChecked){ + light_setting.visibility = View.VISIBLE + }else{ + light_setting.visibility = View.GONE + } + } + } + cb_setting_voice.setOnCheckedChangeListener { buttonView, isChecked -> + if(buttonView.id==cb_setting_voice.id){ + if(isChecked){ + voice_setting.visibility = View.VISIBLE + }else{ + voice_setting.visibility = View.GONE + } + } + } lbv_go2_center.setOrderIdCallback(object : LeftBarView.LeftBarCallback{ override fun setGo2CenterClick() { when (bottom.getCurrentPage()) { diff --git a/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/setting/LightSetting.kt b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/setting/LightSetting.kt index 5dc84eb39b..78d8da0587 100644 --- a/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/setting/LightSetting.kt +++ b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/setting/LightSetting.kt @@ -4,121 +4,21 @@ import android.animation.ObjectAnimator import android.content.Context import android.provider.Settings import android.util.AttributeSet -import android.view.LayoutInflater -import android.view.MotionEvent -import android.view.View -import android.widget.ImageView -import androidx.constraintlayout.widget.ConstraintLayout -import androidx.constraintlayout.widget.ConstraintSet -import androidx.core.view.marginBottom -import androidx.core.view.marginTop import com.mogo.eagle.core.function.call.setting.CallerRequestActivityHandleManager -import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger import com.mogo.eagle.core.utilcode.util.BrightnessUtils -import com.mogo.och.common.module.utils.RxUtils -import com.mogo.och.common.module.wigets.map.switchvisual.VisualViewModel -import com.mogo.och.unmanned.passenger.ui.setting.TaxiPSettingView.Companion -import com.mogo.och.unmanned.taxi.passenger.R +import com.mogo.och.common.module.utils.NumberFormatUtil import kotlinx.android.synthetic.main.taxi_p_setting_light_view.view.tv_current_value -import kotlinx.android.synthetic.main.taxi_p_setting_view.view.sb_light_bar -import kotlin.properties.Delegates class LightSetting @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 -) : ConstraintLayout(context, attrs, defStyleAttr) { - - private lateinit var draggableButton: ImageView - private var marginTop:Int = 0 - private var marginBottom:Int = 0 - private var maxHeight = 0 +) : VerticalSeekBar(context, attrs, defStyleAttr) { private val TAG = "LightSetting" - - init { - LayoutInflater.from(context).inflate(R.layout.taxi_p_setting_light_view, this, true) - background = resources.getDrawable(R.drawable.taxi_p_voice_bg) - initView() - } - - override fun onVisibilityAggregated(isVisible: Boolean) { - super.onVisibilityAggregated(isVisible) - if(isVisible){ - - } - } - - private fun initView() { - draggableButton = findViewById(R.id.aciv_voice_thum) - marginTop = draggableButton.marginTop - marginBottom = draggableButton.marginBottom - post { - maxHeight = height-marginBottom-marginTop-draggableButton.height - initLightAndVoice() - } - } - - - - - private var initialX = 0f - private var initialY = 0f - private val tempSet = ConstraintSet() - - /** - * 为该组件的触碰事件重写事件处理方法 - */ - override fun onTouchEvent(event: MotionEvent?): Boolean { - when (event?.action) { - MotionEvent.ACTION_DOWN -> { - initialX = event.rawX; - initialY = event.rawY; - } - MotionEvent.ACTION_MOVE -> { - - if(draggableButton.translationY<0){ - draggableButton.translationY = 0f - return true - }else if (draggableButton.translationY+marginTop>(height)){ - tempSet.clone(this) - tempSet.setTranslationY(draggableButton.id,(height-marginTop).toFloat()) - tempSet.applyTo(this) - return true - } - - val dx = event.rawX - initialX; - val dy = event.rawY - initialY; - initialX = event.rawX; - initialY = event.rawY; - if(draggableButton.translationY+dy<0){ - return true - } - if(draggableButton.translationY+dy+marginBottom+marginTop+draggableButton.height>height){ - return true - } - CallerLogger.d(TAG,"旧的dy:${draggableButton.translationY}") - - tempSet.clone(this) - tempSet.setTranslationY(draggableButton.id,draggableButton.translationY+dy) - tempSet.applyTo(this) - CallerLogger.d(TAG,"新的dy:${draggableButton.translationY}") - - - upDateLight() - - } - MotionEvent.ACTION_UP -> { - - } - else -> {} - } - return true - } - - private fun upDateLight() { + override fun upDateLight(percentaget: Float) { if (!Settings.System.canWrite(context)) { CallerRequestActivityHandleManager.requestPermission( TaxiPSettingView.TAG, @@ -126,41 +26,25 @@ class LightSetting @JvmOverloads constructor( ) return } + if (BrightnessUtils.isAutoBrightnessEnabled()) { - BrightnessUtils.setBrightness((draggableButton.translationY/maxHeight*255).toInt()) + BrightnessUtils.setBrightness((percentaget*255).toInt()) } else { BrightnessUtils.setAutoBrightnessEnabled(true) } + setTextValue(NumberFormatUtil.percentage(percentaget,0)) } - /** - * - */ - private fun initLightAndVoice(){ - CallerLogger.d(TAG,"最大值${maxHeight}---height:${height}---marginBottom:${marginBottom}---marginTop:${marginTop}-----draggableButton.height:${draggableButton.height}") - val currentLight = BrightnessUtils.getBrightness().toFloat() / 255 * maxHeight - CallerLogger.d(TAG,"当前的亮度:${currentLight}") + override fun initLightAndVoice(){ + val percentaget = BrightnessUtils.getBrightness().toFloat() / 255 + val currentLight = percentaget * maxHeightValue ObjectAnimator.ofFloat( draggableButton, "translationY", draggableButton.translationY, currentLight ).apply { duration = 500 }.start() - tv_current_value.text = "${(BrightnessUtils.getBrightness() * 100) / 255}" - } - - override fun onWindowVisibilityChanged(visibility: Int) { - super.onWindowVisibilityChanged(visibility) - if (visibility == View.VISIBLE) { - initLightAndVoice() - } - } - - override fun onWindowFocusChanged(hasWindowFocus: Boolean) { - super.onWindowFocusChanged(hasWindowFocus) - if (hasWindowFocus) { - initLightAndVoice() - } + setTextValue(NumberFormatUtil.percentage(percentaget,0)) } } \ No newline at end of file diff --git a/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/setting/SettingGradientDrawable.kt b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/setting/SettingGradientDrawable.kt deleted file mode 100644 index 3ed7fba1df..0000000000 --- a/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/setting/SettingGradientDrawable.kt +++ /dev/null @@ -1,94 +0,0 @@ -package com.mogo.och.unmanned.passenger.ui.setting - -import android.graphics.* -import android.graphics.drawable.Drawable -import androidx.core.graphics.toRectF - -/** - * 进度条drawable - */ -class SettingGradientDrawable(colorStart: Int = Color.BLUE, colorEnd:Int = Color.RED, height:Int) : Drawable() { - - private var mPaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG) - - private var colorStart:Int = Color.BLUE - private var colorEnd:Int = Color.RED - - private var colorWith = 4f - private var transparentWidth = 4f - - private var index = doubleArrayOf(0.53,0.76,0.92) - private var tartHeight = 0 - - private var heightDex = 0 - - private var currendDex = mutableListOf() - - init { - this.colorStart = colorStart - this.colorEnd = colorEnd - this.tartHeight = height - mPaint.isAntiAlias = true - index.forEachIndexed { _, d -> - currendDex += (1-d)/2 - } - } - - override fun draw(canvas: Canvas) { - val rect = bounds - mPaint.shader = LinearGradient(0f, 0f, rect.right.toFloat(), rect.bottom.toFloat(), intArrayOf(colorStart,colorEnd), floatArrayOf(0f,1f), Shader.TileMode.CLAMP) - var size = (rect.width() / (colorWith + transparentWidth)).toInt() - if((colorWith+transparentWidth)*size+colorWith>rect.right){ - size -= 1 - } - if(rect.height()>tartHeight){ - //实际高度大于目标高度 上增加高度差 下减去高度差 - heightDex = (rect.height() - tartHeight) / 2 - } - - var countstep = 0 - while (true){ - val rectF = rect.toRectF() - val height: Float = if(rect.height()>tartHeight){ - tartHeight.toFloat() - }else{ - rectF.bottom - rectF.top - } - // 计算前几个和后几个特殊高度递增和递减 - var dex = 0f - if(countstepcurrendDex.size) { - if (size >= countstep && (size - countstep) < currendDex.size) { - dex = (height * currendDex[size - countstep]).toFloat() - } - } - rectF.top = dex+heightDex - rectF.bottom = rectF.bottom-dex-heightDex - rectF.left = (colorWith+transparentWidth)*countstep - rectF.right = colorWith+(colorWith+transparentWidth)*countstep - if(rectF.right>= rect.right){ - break - } - countstep++ - canvas.drawRoundRect(rectF,48f,48f,mPaint) - } - } - - override fun setAlpha(alpha: Int) { - mPaint.alpha = alpha - invalidateSelf() - } - - override fun setColorFilter(colorFilter: ColorFilter?) { - mPaint.colorFilter = colorFilter - invalidateSelf() - } - - override fun getOpacity(): Int { - return PixelFormat.TRANSLUCENT - } - - -} \ No newline at end of file diff --git a/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/setting/VerticalSeekBar.kt b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/setting/VerticalSeekBar.kt new file mode 100644 index 0000000000..0105325215 --- /dev/null +++ b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/setting/VerticalSeekBar.kt @@ -0,0 +1,146 @@ +package com.mogo.och.unmanned.passenger.ui.setting + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.MotionEvent +import android.view.View +import android.widget.ImageView +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.constraintlayout.widget.ConstraintSet +import androidx.core.view.marginBottom +import androidx.core.view.marginTop +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger +import com.mogo.och.common.module.utils.NumberFormatUtil +import com.mogo.och.unmanned.taxi.passenger.R +import kotlinx.android.synthetic.main.taxi_p_setting_light_view.view.tv_current_value + +open class VerticalSeekBar @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : ConstraintLayout(context, attrs, defStyleAttr) { + + lateinit var draggableButton: ImageView + var maxHeightValue = 0 + + private var marginTop:Int = 0 + private var marginBottom:Int = 0 + + private val TAG = "VerticalSeekBar" + + + init { + LayoutInflater.from(context).inflate(R.layout.taxi_p_setting_light_view, this, true) + background = resources.getDrawable(R.drawable.taxi_p_voice_bg) + initView() + } + + private fun initView() { + draggableButton = findViewById(R.id.aciv_voice_thum) + marginTop = draggableButton.marginTop + marginBottom = draggableButton.marginBottom + } + + override fun onVisibilityAggregated(isVisible: Boolean) { + super.onVisibilityAggregated(isVisible) + if(isVisible){ + post { + maxHeightValue = height-marginBottom-marginTop-draggableButton.height + initLightAndVoice() + } + } + } + + private var initialX = 0f + private var initialY = 0f + private val tempSet = ConstraintSet() + + /** + * 为该组件的触碰事件重写事件处理方法 + */ + override fun onTouchEvent(event: MotionEvent?): Boolean { + when (event?.action) { + MotionEvent.ACTION_DOWN -> { + initialX = event.rawX; + initialY = event.rawY; + } + MotionEvent.ACTION_MOVE -> { + + if(draggableButton.translationY<0){ + draggableButton.translationY = 0f + return true + }else if (draggableButton.translationY+marginTop>(height)){ + tempSet.clone(this) + tempSet.setTranslationY(draggableButton.id,(height-marginTop).toFloat()) + tempSet.applyTo(this) + return true + } + + val dx = event.rawX - initialX; + val dy = event.rawY - initialY; + initialX = event.rawX; + initialY = event.rawY; + if(draggableButton.translationY+dy<0){ + return true + } + if(draggableButton.translationY+dy+marginBottom+marginTop+draggableButton.height>height){ + return true + } + CallerLogger.d(TAG,"旧的dy:${draggableButton.translationY}") + + tempSet.clone(this) + tempSet.setTranslationY(draggableButton.id,draggableButton.translationY+dy) + tempSet.applyTo(this) + CallerLogger.d(TAG,"新的dy:${draggableButton.translationY}") + + var percentaget = draggableButton.translationY/maxHeightValue + if(percentaget>0.99){ + percentaget = 1.0f + draggableButton.translationY = maxHeightValue.toFloat() + }else if(percentaget<0.01){ + percentaget = 0.0f + draggableButton.translationY = 0f + } + + upDateLight(percentaget) + + } + MotionEvent.ACTION_UP -> { + + } + else -> {} + } + return true + } + + open fun upDateLight(percentaget: Float) { + + } + + /** + * + */ + open fun initLightAndVoice(){ + + } + + fun setTextValue(value:String){ + tv_current_value.text = value + } + + override fun onWindowVisibilityChanged(visibility: Int) { + super.onWindowVisibilityChanged(visibility) + if (visibility == View.VISIBLE) { + initLightAndVoice() + } + } + + override fun onWindowFocusChanged(hasWindowFocus: Boolean) { + super.onWindowFocusChanged(hasWindowFocus) + if (hasWindowFocus) { + initLightAndVoice() + } + } + +} \ No newline at end of file diff --git a/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/setting/VoiceSetting.kt b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/setting/VoiceSetting.kt new file mode 100644 index 0000000000..1677e0458f --- /dev/null +++ b/OCH/taxi/unmanned-passenger/src/main/java/com/mogo/och/unmanned/passenger/ui/setting/VoiceSetting.kt @@ -0,0 +1,98 @@ +package com.mogo.och.unmanned.passenger.ui.setting + +import android.animation.ObjectAnimator +import android.content.Context +import android.content.Intent +import android.media.AudioManager +import android.provider.Settings +import android.text.TextUtils +import android.util.AttributeSet +import androidx.core.view.isVisible +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.call.setting.CallerRequestActivityHandleManager +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger +import com.mogo.eagle.core.utilcode.util.BrightnessUtils +import com.mogo.eagle.core.utilcode.util.ThreadUtils +import com.mogo.och.common.module.utils.NumberFormatUtil +import kotlinx.android.synthetic.main.taxi_p_setting_light_view.view.tv_current_value +import kotlinx.android.synthetic.main.taxi_p_setting_view.view.sb_voice_bar +import kotlinx.android.synthetic.main.taxi_p_setting_view.view.tvVoicePer + + +class VoiceSetting @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : VerticalSeekBar(context, attrs, defStyleAttr), IMogoIntentListener { + + private val TAG = "VoiceSetting" + + private var mAudioManager: AudioManager? = null + private var mMaxVolume: Int = -1 + + + override fun upDateLight(percentaget: Float) { + context?.let { ctx -> + if (mAudioManager == null) { + mAudioManager = ctx.getSystemService(Context.AUDIO_SERVICE) as AudioManager + } + mAudioManager?.let { + if (mMaxVolume < 0) { + mMaxVolume = it.getStreamMaxVolume(AudioManager.STREAM_MUSIC) + } + val currentValue = (percentaget * mMaxVolume).toInt() + mAudioManager?.setStreamVolume( + AudioManager.STREAM_MUSIC, + currentValue, + AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE + ) + setTextValue(NumberFormatUtil.percentage(percentaget,0)) + } + } + + } + + override fun initLightAndVoice(){ + context?.let {ctx-> + if(mAudioManager==null) { + mAudioManager = ctx.getSystemService(Context.AUDIO_SERVICE) as AudioManager + } + mAudioManager?.let { + if(mMaxVolume<0) { + mMaxVolume = it.getStreamMaxVolume(AudioManager.STREAM_MUSIC) + } + val mCurrentVolume = it.getStreamVolume(AudioManager.STREAM_MUSIC) + val per = mCurrentVolume.toFloat() / mMaxVolume + val currentVolume = per * maxHeightValue + CallerLogger.d(TAG,"当前的声音:${mCurrentVolume}") + ObjectAnimator.ofFloat( + draggableButton, "translationY", draggableButton.translationY, + currentVolume + ).apply { + duration = 500 + }.start() + tv_current_value.text = "${(BrightnessUtils.getBrightness() * 100) / 255}" + setTextValue(NumberFormatUtil.percentage(per,0)) + } + + } + } + + 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 +// ) { +// CallerLogger.d(TAG,"收到信息变更") +// ThreadUtils.runOnUiThread { +// initLightAndVoice() +// } +// } +// } + } + +} \ No newline at end of file diff --git a/OCH/taxi/unmanned-passenger/src/main/res/layout/taxi_p_setting_view.xml b/OCH/taxi/unmanned-passenger/src/main/res/layout/taxi_p_setting_view.xml index e83b88ef1c..5d5f65f440 100644 --- a/OCH/taxi/unmanned-passenger/src/main/res/layout/taxi_p_setting_view.xml +++ b/OCH/taxi/unmanned-passenger/src/main/res/layout/taxi_p_setting_view.xml @@ -34,6 +34,7 @@ android:layout_marginStart="@dimen/dp_141" android:layout_marginTop="@dimen/dp_24" android:splitTrack="false" + android:orientation="vertical" android:thumb="@drawable/taxi_p_function_voice_right_process_humb" android:thumbOffset="@dimen/dp_2" app:layout_constraintLeft_toLeftOf="parent" diff --git a/OCH/taxi/unmanned-passenger/src/main/res/layout/taxt_p_bottom_bar.xml b/OCH/taxi/unmanned-passenger/src/main/res/layout/taxt_p_bottom_bar.xml index 2dad0ba67d..e453b0981c 100644 --- a/OCH/taxi/unmanned-passenger/src/main/res/layout/taxt_p_bottom_bar.xml +++ b/OCH/taxi/unmanned-passenger/src/main/res/layout/taxt_p_bottom_bar.xml @@ -115,29 +115,4 @@ app:normalDrawable="@drawable/taxt_p_bottom_music_normal" app:selectedDrawable="@drawable/taxt_p_bottom_music_normal" /> - - - - - \ No newline at end of file diff --git a/OCH/taxi/unmanned-passenger/src/main/res/layout/taxt_u_p_base_fragment.xml b/OCH/taxi/unmanned-passenger/src/main/res/layout/taxt_u_p_base_fragment.xml index 1eca784c13..2eed9a7bf0 100644 --- a/OCH/taxi/unmanned-passenger/src/main/res/layout/taxt_u_p_base_fragment.xml +++ b/OCH/taxi/unmanned-passenger/src/main/res/layout/taxt_u_p_base_fragment.xml @@ -80,14 +80,6 @@ app:layout_constraintTop_toTopOf="parent" app:roma_change_dis_color="true" /> - - + + + + + + + + + +