[1.0.0]
[m1] [温度页面]
This commit is contained in:
@@ -9,12 +9,20 @@ import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.widget.SeekBar
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.LinearSnapHelper
|
||||
import androidx.recyclerview.widget.SnapHelper
|
||||
import com.mogo.commons.mvp.MvpFragment
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import com.mogo.och.bus.passenger.R
|
||||
import com.mogo.och.bus.passenger.presenter.BusPassengerFunctionSoftPresenter
|
||||
import com.mogo.och.bus.passenger.ui.adapter.TemperatureAdapter
|
||||
import com.mogo.och.bus.passenger.view.HorizontalDecoration
|
||||
import com.mogo.och.bus.passenger.view.PickerLayoutManager
|
||||
import com.mogo.och.common.module.utils.SoundPoolHelper
|
||||
import com.yangyakun.main.ui.loading.drawable.MineGradientDrawable
|
||||
import com.zhidao.support.adas.high.AdasManager
|
||||
@@ -112,6 +120,43 @@ class BusPassengerFunctionSoftFragment :
|
||||
openAircondition()
|
||||
}
|
||||
}
|
||||
|
||||
val pickerLayoutManager = PickerLayoutManager(requireContext(), PickerLayoutManager.HORIZONTAL, false)
|
||||
pickerLayoutManager.isChangeAlpha = true
|
||||
pickerLayoutManager.scaleDownBy = 0.99f
|
||||
pickerLayoutManager.scaleDownDistance = 0.8f
|
||||
|
||||
val adapter = TemperatureAdapter(requireContext(), getData(), rv_aircondition_temperature)
|
||||
val snapHelper: SnapHelper = LinearSnapHelper()
|
||||
snapHelper.attachToRecyclerView(rv_aircondition_temperature)
|
||||
rv_aircondition_temperature.layoutManager = pickerLayoutManager
|
||||
rv_aircondition_temperature.adapter = adapter
|
||||
rv_aircondition_temperature.addItemDecoration(HorizontalDecoration(0))
|
||||
|
||||
|
||||
pickerLayoutManager.setOnScrollStopListener(object : PickerLayoutManager.onScrollStopListener {
|
||||
override fun selectedView(view: View) {
|
||||
if(view is TextView) {
|
||||
ToastUtils.showShort(view.text)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun getData(): MutableList<String> {
|
||||
val mutableListOf = mutableListOf<String>()
|
||||
mutableListOf.add("16°")
|
||||
mutableListOf.add("17°")
|
||||
mutableListOf.add("18°")
|
||||
mutableListOf.add("19°")
|
||||
mutableListOf.add("20°")
|
||||
mutableListOf.add("21°")
|
||||
mutableListOf.add("22°")
|
||||
mutableListOf.add("23°")
|
||||
mutableListOf.add("24°")
|
||||
mutableListOf.add("25°")
|
||||
mutableListOf.add("26°")
|
||||
return mutableListOf
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,7 +254,7 @@ class BusPassengerFunctionSoftFragment :
|
||||
|
||||
private fun heaterAirEnable(enable:Boolean){
|
||||
tv_temperature_title.isEnabled = enable
|
||||
v_temp.isEnabled = enable
|
||||
rv_aircondition_temperature.isEnabled = enable
|
||||
rb_wind_speed_low.isEnabled = enable
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.mogo.och.bus.passenger.ui.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.mogo.och.bus.passenger.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by adityagohad on 06/06/17.
|
||||
*/
|
||||
|
||||
public class TemperatureAdapter extends RecyclerView.Adapter<TemperatureAdapter.TextVH> {
|
||||
|
||||
private Context context;
|
||||
private List<String> dataList;
|
||||
private RecyclerView recyclerView;
|
||||
|
||||
public TemperatureAdapter(Context context, List<String> dataList, RecyclerView recyclerView) {
|
||||
this.context = context;
|
||||
this.dataList = dataList;
|
||||
this.recyclerView = recyclerView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextVH onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view;
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
view = inflater.inflate(R.layout.bus_p_temperature_item, parent, false);
|
||||
return new TextVH(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(TextVH holder, final int position) {
|
||||
TextVH textVH = holder;
|
||||
textVH.pickerTxt.setText(dataList.get(position));
|
||||
textVH.pickerTxt.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (recyclerView != null) {
|
||||
recyclerView.smoothScrollToPosition(position);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return dataList.size();
|
||||
}
|
||||
|
||||
public void swapData(List<String> newData) {
|
||||
dataList = newData;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
class TextVH extends RecyclerView.ViewHolder {
|
||||
TextView pickerTxt;
|
||||
|
||||
public TextVH(View itemView) {
|
||||
super(itemView);
|
||||
pickerTxt = (TextView) itemView.findViewById(R.id.tv_aircondition_temperature_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.mogo.och.bus.passenger.view;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class HorizontalDecoration extends RecyclerView.ItemDecoration {
|
||||
private int space = 0;
|
||||
/**
|
||||
* 第一个视图和最后一个视图偏移的距离
|
||||
*/
|
||||
private int distance = 0;
|
||||
private static final String TAG = "HorizontalDecoration";
|
||||
|
||||
/**
|
||||
* 设置RecyclerView子视图的边距,本示例仅用于定义两个子视图之间的边距,为space*2
|
||||
* @param space 设置的边距
|
||||
*/
|
||||
public HorizontalDecoration(int space) {
|
||||
this.space = space;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子视图的边距
|
||||
* @param view 子视图
|
||||
* @param parent RecyclerView对象
|
||||
*/
|
||||
@Override
|
||||
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
|
||||
int pos = parent.getChildAdapterPosition(view);
|
||||
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams)view.getLayoutParams();
|
||||
/**
|
||||
* 仅计算一次偏移边距即可,无需重复计算<P/>
|
||||
* 由于此时View并未完成测量,无法基于测量获取其宽度;思路是在view绘制完成后再进行测量,并设置第一个的左边距
|
||||
*/
|
||||
if(distance <= 0){
|
||||
view.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
distance = dtDistance(parent,view);
|
||||
//设置第一个视图的左边距
|
||||
View childView = parent.getChildAt(0);
|
||||
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams)childView.getLayoutParams();
|
||||
layoutParams.setMargins(distance,0,space,0);
|
||||
childView.setLayoutParams(layoutParams);
|
||||
//打开后默认显示第一个(居中显示)
|
||||
parent.scrollToPosition(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 通过设置Item左右边距实现第一个左侧和最后一个右侧设置边距,确保显示的视图位于屏幕中间
|
||||
*/
|
||||
int itemCount = parent.getAdapter().getItemCount();
|
||||
if(pos == 0){
|
||||
layoutParams.setMargins(distance,0,space,0);
|
||||
}else if(pos == itemCount-1){
|
||||
layoutParams.setMargins(space,0,distance,0);
|
||||
}else {
|
||||
layoutParams.setMargins(space,0,space,0);
|
||||
}
|
||||
/**
|
||||
* 更新子视图的边距
|
||||
*/
|
||||
view.setLayoutParams(layoutParams);
|
||||
super.getItemOffsets(outRect, view, parent, state);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为了使第一个和最后一个item居中,需要设置相应偏移,偏移量为RecyclerView布局宽度减去子视图的一半<P/>
|
||||
* 注意此处由于子视图并未实例化完成,无法通过测量得知其宽度,故需要直接获取布局宽度参数得知<P/>
|
||||
*/
|
||||
public int dtDistance(RecyclerView recyclerView , View childView){
|
||||
int width = recyclerView.getWidth() != 0 ? recyclerView.getWidth():recyclerView.getMeasuredWidth();
|
||||
//此处需要获取子视图布局的宽度,注意此处由于子视图并未实例化完成,无法通过测量得知其宽度
|
||||
childView.getMeasuredWidth();
|
||||
int childWidth = childView.getWidth();
|
||||
//第一个视图左侧偏移量,最后一个视图右侧偏移量
|
||||
return width/2 -childWidth/2;
|
||||
}
|
||||
}
|
||||
@@ -109,12 +109,12 @@
|
||||
android:text="@string/bus_p_m1_temperature"
|
||||
android:textColor="@color/bus_p_m1_47576E"
|
||||
android:textSize="@dimen/dp_24"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/v_temp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/rv_aircondition_temperature"
|
||||
app:layout_constraintStart_toStartOf="@+id/tv_aircondition_switch"
|
||||
app:layout_constraintTop_toTopOf="@+id/v_temp" />
|
||||
app:layout_constraintTop_toTopOf="@+id/rv_aircondition_temperature" />
|
||||
|
||||
<View
|
||||
android:id="@+id/v_temp"
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_aircondition_temperature"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/dp_60"
|
||||
android:layout_marginTop="@dimen/dp_41"
|
||||
@@ -143,7 +143,7 @@
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintEnd_toEndOf="@+id/tv_aircondition_switch"
|
||||
app:layout_constraintTop_toBottomOf="@+id/v_temp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/rv_aircondition_temperature"
|
||||
app:layout_constraintWidth_percent="0.244">
|
||||
|
||||
<RadioButton
|
||||
@@ -261,7 +261,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="visible"
|
||||
app:constraint_referenced_ids="tv_aircondition_switch,tv_temperature_title,v_temp,tv_aircondition_pattern_title,rg_setting_pattern,tv_aircondition_wind_speed_title,rg_setting_windspeed" />
|
||||
app:constraint_referenced_ids="tv_aircondition_switch,tv_temperature_title,rv_aircondition_temperature,tv_aircondition_pattern_title,rg_setting_pattern,tv_aircondition_wind_speed_title,rg_setting_windspeed" />
|
||||
<!--endregion-->
|
||||
|
||||
<!--region 灯光调整-->
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/tv_aircondition_temperature_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:text="22°"
|
||||
android:textColor="@color/bus_p_m1_47576E"
|
||||
android:textSize="@dimen/dp_30" />
|
||||
Reference in New Issue
Block a user