feat: 设备操作页面

This commit is contained in:
niushuai233 2022-10-17 18:02:56 +08:00
parent d0e2652ef0
commit cf354a8c02
5 changed files with 64 additions and 2 deletions

View File

@ -0,0 +1,32 @@
package cc.niushuai.project.devcontrol.ui.device;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import cc.niushuai.project.devcontrol.databinding.DeviceOperateBinding;
/**
* 设备操作页面
*
* @author niushuai
* @date: 2022/10/17 17:41
* @return: {@link }
*/
public class DeviceOperate extends Fragment {
private DeviceOperateBinding thisBinding;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
thisBinding = DeviceOperateBinding.inflate(inflater, container, false);
CharSequence text = thisBinding.deviceOperateFullInfo.getText();
System.out.println(text);
return thisBinding.getRoot();
}
}

View File

@ -1,5 +1,6 @@
package cc.niushuai.project.devcontrol.ui.nav.device; package cc.niushuai.project.devcontrol.ui.nav.device;
import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
@ -23,6 +24,7 @@ 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.databinding.DeviceItemBinding; import cc.niushuai.project.devcontrol.databinding.DeviceItemBinding;
import cc.niushuai.project.devcontrol.databinding.MainNavFragmentDeviceBinding; import cc.niushuai.project.devcontrol.databinding.MainNavFragmentDeviceBinding;
import cc.niushuai.project.devcontrol.ui.device.DeviceOperate;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
/** /**
@ -64,12 +66,14 @@ public class NavDeviceFragment extends Fragment {
deviceGv.setOnItemClickListener(new AdapterView.OnItemClickListener() { deviceGv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
View text = view.findViewById(R.id.device_item_cardView_text); View text = view.findViewById(R.id.device_item_cardView_id);
String x = ";"; String x = ";";
if (text != null) { if (text != null) {
x = ((TextView) text).getText().toString(); x = ((TextView) text).getText().toString();
} }
Toast.makeText(getContext(), "Item Clicked" + x, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Item Clicked" + x, Toast.LENGTH_SHORT).show();
startActivity(new Intent(getActivity(), DeviceOperate.class));
} }
}); });
@ -77,7 +81,8 @@ public class NavDeviceFragment extends Fragment {
// new String[]{"device_item_cardView_text"}, new int[]{R.id.device_item_cardView_text}); // new String[]{"device_item_cardView_text"}, new int[]{R.id.device_item_cardView_text});
SimpleAdapter gvAdapter = new SimpleAdapter(getContext(), loadDeviceInfo(), R.layout.device_item, SimpleAdapter gvAdapter = new SimpleAdapter(getContext(), loadDeviceInfo(), R.layout.device_item,
new String[]{"device_item_cardView_image", "device_item_cardView_text"}, new int[]{R.id.device_item_cardView_image, R.id.device_item_cardView_text}); new String[]{"device_item_cardView_id", "device_item_cardView_image", "device_item_cardView_text"},
new int[]{R.id.device_item_cardView_id, R.id.device_item_cardView_image, R.id.device_item_cardView_text});
deviceGv.setAdapter(gvAdapter); deviceGv.setAdapter(gvAdapter);
} }
@ -100,6 +105,7 @@ public class NavDeviceFragment extends Fragment {
HashMap<String, Object> m1 = new HashMap<>(); HashMap<String, Object> m1 = new HashMap<>();
// 设置当前设备的图标和名称 // 设置当前设备的图标和名称
m1.put("device_item_cardView_id", deviceInfo.getId());
m1.put("device_item_cardView_image", deviceInfo.getIconId()); m1.put("device_item_cardView_image", deviceInfo.getIconId());
m1.put("device_item_cardView_text", deviceInfo.getName()); m1.put("device_item_cardView_text", deviceInfo.getName());

View File

@ -25,6 +25,13 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="10dp"> android:layout_marginLeft="10dp">
<TextView
android:id="@id/device_item_cardView_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
/>
<ImageView <ImageView
android:id="@id/device_item_cardView_image" android:id="@id/device_item_cardView_image"
android:layout_width="55dp" android:layout_width="55dp"

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ui.device.DeviceOperate">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@id/device_operate_fullInfo"/>
</RelativeLayout>

View File

@ -11,8 +11,11 @@
<item name="device_item" type="id"/> <item name="device_item" type="id"/>
<item name="device_item_cardView" type="id"/> <item name="device_item_cardView" type="id"/>
<item name="device_item_cardView_content" type="id"/> <item name="device_item_cardView_content" type="id"/>
<item name="device_item_cardView_id" type="id"/>
<item name="device_item_cardView_image" type="id"/> <item name="device_item_cardView_image" type="id"/>
<item name="device_item_cardView_text" type="id"/> <item name="device_item_cardView_text" type="id"/>
<item name="device_operate_fullInfo" type="id"/>
<!--设备页 end--> <!--设备页 end-->
</resources> </resources>