feat: 开关设置页面

This commit is contained in:
niushuai233 2022-10-20 11:41:40 +08:00
parent 60e971f233
commit 079695c664
12 changed files with 225 additions and 17 deletions

View File

@ -1,5 +1,10 @@
package cc.niushuai.project.devcontrol.base.ui; package cc.niushuai.project.devcontrol.base.ui;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import java.util.Map; import java.util.Map;
@ -8,6 +13,8 @@ import cc.niushuai.project.devcontrol.R;
import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo;
import cc.niushuai.project.devcontrol.base.util.ActivityUtil; import cc.niushuai.project.devcontrol.base.util.ActivityUtil;
import cc.niushuai.project.devcontrol.base.util.Keys; import cc.niushuai.project.devcontrol.base.util.Keys;
import cc.niushuai.project.devcontrol.base.util.UiUtil;
import cn.hutool.core.util.StrUtil;
/** /**
* Activity基类 * Activity基类
@ -31,6 +38,30 @@ public abstract class BaseActivity extends AppCompatActivity {
*/ */
protected abstract void init(); protected abstract void init();
/**
* 设置title
*
* @author niushuai
* @date: 2022/10/20 10:13
*/
protected void setTitle(String title, String subTitle) {
// 标题名称
TextView titleTextView = findViewById(R.id.activity_title_name);
titleTextView.setText(title);
// 副标题名称
TextView descTextView = findViewById(R.id.activity_title_description);
if (StrUtil.isNotEmpty(subTitle)) {
descTextView.setText(subTitle);
} else {
// 不显示副标题
descTextView.setVisibility(View.GONE);
// 主标题 修改高度为50dp
titleTextView.getLayoutParams().height = UiUtil.dip2px(this, 50);
}
}
/** /**
* 监听器事件统一设置入口 * 监听器事件统一设置入口
* *

View File

@ -0,0 +1,14 @@
package cc.niushuai.project.devcontrol.base.util;
import android.content.Context;
import android.content.res.Resources;
import android.util.TypedValue;
public class UiUtil {
public static int dip2px(Context context, float dipValue) {
Resources r = context.getResources();
return (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, dipValue, r.getDisplayMetrics());
}
}

View File

@ -44,21 +44,12 @@ public class PowerSwitchActivity extends BaseActivity {
@Override @Override
protected void init() { protected void init() {
DeviceInfo data = GlobalVariables.getDeviceInfo(getIntentDeviceId()); this.device = GlobalVariables.getDeviceInfo(getIntentDeviceId());
if (null != data) { // 标题名称
this.device = data; super.setTitle(this.device.getName(), this.device.getDescription());
// 标题名称 // 开关底部的名称
TextView titleTextView = findViewById(R.id.activity_title_name); TextView contentTextTextView = findViewById(R.id.power_switch_activity_content_text);
titleTextView.setText(device.getName()); contentTextTextView.setText(device.getName());
// 副标题名称
TextView descTextView = findViewById(R.id.activity_title_description);
descTextView.setText(device.getDescription());
// 开关底部的名称
TextView contentTextTextView = findViewById(R.id.power_switch_activity_content_text);
contentTextTextView.setText(device.getName());
}
} }
/** /**

View File

@ -1,13 +1,16 @@
package cc.niushuai.project.devcontrol.ui.powerswitch; package cc.niushuai.project.devcontrol.ui.powerswitch;
import android.os.Bundle; import android.os.Bundle;
import android.view.ViewGroup;
import cc.niushuai.project.devcontrol.R;
import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo;
import cc.niushuai.project.devcontrol.base.ui.BaseActivity; import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
import cc.niushuai.project.devcontrol.base.util.GlobalVariables; import cc.niushuai.project.devcontrol.base.util.GlobalVariables;
import cc.niushuai.project.devcontrol.base.util.Keys; import cc.niushuai.project.devcontrol.base.util.Keys;
import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchBinding; import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchBinding;
import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchSetBinding; import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchSetBinding;
import cn.hutool.core.util.StrUtil;
public class PowerSwitchSetActivity extends BaseActivity { public class PowerSwitchSetActivity extends BaseActivity {
@ -20,10 +23,19 @@ public class PowerSwitchSetActivity extends BaseActivity {
binding = ActivityPowerSwitchSetBinding.inflate(getLayoutInflater()); binding = ActivityPowerSwitchSetBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot()); setContentView(binding.getRoot());
this.init();
this.addListener();
} }
@Override @Override
protected void init() { protected void init() {
device = GlobalVariables.getDeviceInfo(getIntentDeviceId()); this.device = GlobalVariables.getDeviceInfo(getIntentDeviceId());
super.setTitle(getString(R.string.set), StrUtil.EMPTY);
}
@Override
protected void addListener() {
} }
} }

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/gray"/>
<size android:height="1dp"/>
</shape>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:fillColor="#FF000000"
android:pathData="M380,802.68c-7.78,0 -15.56,-3.01 -21.44,-9.01 -11.6,-11.84 -11.41,-30.84 0.43,-42.44l243.52,-238.67 -243.52,-238.67c-11.84,-11.6 -12.03,-30.6 -0.43,-42.44 11.6,-11.84 30.6,-12.03 42.44,-0.43l265.39,260.1c5.76,5.64 9.01,13.37 9.01,21.43s-3.24,15.79 -9.01,21.43L401.01,794.1C395.17,799.83 387.58,802.68 380,802.68z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="16dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:fillColor="#FF000000"
android:pathData="M380,802.68c-7.78,0 -15.56,-3.01 -21.44,-9.01 -11.6,-11.84 -11.41,-30.84 0.43,-42.44l243.52,-238.67 -243.52,-238.67c-11.84,-11.6 -12.03,-30.6 -0.43,-42.44 11.6,-11.84 30.6,-12.03 42.44,-0.43l265.39,260.1c5.76,5.64 9.01,13.37 9.01,21.43s-3.24,15.79 -9.01,21.43L401.01,794.1C395.17,799.83 387.58,802.68 380,802.68z"/>
</vector>

View File

@ -4,11 +4,107 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/main_bg_color"
tools:context=".ui.powerswitch.PowerSwitchSetActivity"> tools:context=".ui.powerswitch.PowerSwitchSetActivity">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
/> tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<include layout="@layout/activity_common_title" />
<LinearLayout
android:id="@+id/power_switch_set_activity_item_iconChange_outside"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/activity_layout_title"
android:layout_gravity="center_horizontal"
android:background="@color/main_bg_color"
android:orientation="horizontal">
<TextView
android:id="@id/power_switch_set_activity_item_iconChange_text"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_weight="6"
android:gravity="center_vertical"
android:text="@string/power_switch_set_iconChange"
android:textSize="16dp" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@id/power_switch_set_activity_item_iconChange_icon"
android:layout_width="25dp"
android:layout_height="match_parent"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_next_16" />
</LinearLayout>
<LinearLayout
android:id="@+id/power_switch_set_activity_item_paramSet_outside"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/power_switch_set_activity_item_iconChange_outside"
android:layout_gravity="center_horizontal"
android:background="@color/main_bg_color"
android:orientation="horizontal">
<TextView
android:id="@id/power_switch_set_activity_item_paramSet_text"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_weight="6"
android:gravity="center_vertical"
android:text="@string/power_switch_set_paramSet"
android:textSize="16dp" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@id/power_switch_set_activity_item_paramSet_icon"
android:layout_width="25dp"
android:layout_height="match_parent"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_next_16" />
</LinearLayout>
<LinearLayout
android:id="@+id/power_switch_set_activity_item_logView_outside"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/power_switch_set_activity_item_paramSet_outside"
android:layout_gravity="center_horizontal"
android:background="@color/main_bg_color"
android:orientation="horizontal">
<TextView
android:id="@id/power_switch_set_activity_item_logView_text"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_weight="6"
android:gravity="center_vertical"
android:text="@string/power_switch_set_logView"
android:textSize="16dp" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@id/power_switch_set_activity_item_logView_icon"
android:layout_width="25dp"
android:layout_height="match_parent"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_next_16" />
</LinearLayout>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -2,11 +2,13 @@
<resources> <resources>
<!--common start--> <!--common start-->
<item name="activity_layout_title" type="id"/> <item name="activity_layout_title" type="id"/>
<item name="activity_title_back" type="id"/> <item name="activity_title_back" type="id"/>
<item name="activity_title_name" type="id"/> <item name="activity_title_name" type="id"/>
<item name="activity_title_description" type="id"/> <item name="activity_title_description" type="id"/>
<item name="activity_title_more_set" type="id"/> <item name="activity_title_more_set" type="id"/>
<!--common end--> <!--common end-->
<!-- 首页 底部导航栏 start--> <!-- 首页 底部导航栏 start-->
@ -34,6 +36,24 @@
<item name="power_switch_activity_content_switch" type="id"/> <item name="power_switch_activity_content_switch" type="id"/>
<item name="power_switch_activity_content_text" type="id"/> <item name="power_switch_activity_content_text" type="id"/>
<!--开关操作页 end--> <!--开关操作页 end-->
<!--开关设置 start-->
<!--更换图标-->
<item name="power_switch_set_activity_item_iconChange_outside" type="id"/>
<item name="power_switch_set_activity_item_iconChange_text" type="id"/>
<item name="power_switch_set_activity_item_iconChange_icon" type="id"/>
<!--参数设置-->
<item name="power_switch_set_activity_item_paramSet_outside" type="id"/>
<item name="power_switch_set_activity_item_paramSet_text" type="id"/>
<item name="power_switch_set_activity_item_paramSet_icon" type="id"/>
<!--日志查看-->
<item name="power_switch_set_activity_item_logView_outside" type="id"/>
<item name="power_switch_set_activity_item_logView_text" type="id"/>
<item name="power_switch_set_activity_item_logView_icon" type="id"/>
<!--开关设置 end-->
<!--设备页 end--> <!--设备页 end-->
</resources> </resources>

View File

@ -1,6 +1,16 @@
<resources> <resources>
<!--应用名称--> <!--应用名称-->
<string name="app_name">终端控制器</string> <string name="app_name">终端控制器</string>
<!--common start-->
<string name="menu">菜单</string>
<string name="device">设备</string>
<string name="set">设置</string>
<string name="log">日志</string>
<string name="confirm">确定</string>
<string name="cancel">取消</string>
<!--common end-->
<!--测试字符串 start--> <!--测试字符串 start-->
<string name="hello_blank_fragment">Hello blank fragment</string> <string name="hello_blank_fragment">Hello blank fragment</string>
<string name="test_hello_blank_textview_1">Hello blank textview 1</string> <string name="test_hello_blank_textview_1">Hello blank textview 1</string>
@ -16,4 +26,13 @@
<string name="title_bottom_nav_menu_log">日志</string> <string name="title_bottom_nav_menu_log">日志</string>
<string name="title_bottom_nav_menu_set">设置</string> <string name="title_bottom_nav_menu_set">设置</string>
<!-- 首页 底部导航栏 end--> <!-- 首页 底部导航栏 end-->
<!--设备 start-->
<!--开关设置页面 start-->
<string name="power_switch_set_iconChange">更换图标</string>
<string name="power_switch_set_paramSet">参数设置</string>
<string name="power_switch_set_logView">日志</string>
<!--开关设置页面 end-->
<!--设备 end-->
</resources> </resources>

1
iconfront/下一步.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1666230148810" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2387" xmlns:xlink="http://www.w3.org/1999/xlink" width="32" height="32"><path d="M380.00271 802.681382c-7.782244 0-15.558347-3.007497-21.436218-9.005095-11.602246-11.836583-11.410887-30.838356 0.427742-42.439578l243.519246-238.665705-243.519246-238.665705c-11.838629-11.602246-12.029988-30.602995-0.427742-42.440601 11.602246-11.837606 30.602995-12.027941 42.439578-0.426719l265.388323 260.098853c5.760191 5.644557 9.005095 13.370519 9.005095 21.434172s-3.244904 15.789615-9.005095 21.434172L401.00607 794.103006C395.166061 799.826358 387.581316 802.681382 380.00271 802.681382z" p-id="2388"></path></svg>

After

Width:  |  Height:  |  Size: 855 B

View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1666231237382" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2541" width="16" height="16" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M380.00271 802.681382c-7.782244 0-15.558347-3.007497-21.436218-9.005095-11.602246-11.836583-11.410887-30.838356 0.427742-42.439578l243.519246-238.665705-243.519246-238.665705c-11.838629-11.602246-12.029988-30.602995-0.427742-42.440601 11.602246-11.837606 30.602995-12.027941 42.439578-0.426719l265.388323 260.098853c5.760191 5.644557 9.005095 13.370519 9.005095 21.434172s-3.244904 15.789615-9.005095 21.434172L401.00607 794.103006C395.166061 799.826358 387.581316 802.681382 380.00271 802.681382z" p-id="2542"></path></svg>

After

Width:  |  Height:  |  Size: 855 B