From 4f7f99c6ea914bcd38de78bd8371be566026b905 Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期三, 26 二月 2025 15:54:14 +0800 Subject: [PATCH] -为按钮和列表项添加波纹效果,以获得更好的视觉反馈 -改进MapFragment中的底部布局动画 -在MapFragment中添加设备状态和RTU地址显示 -更新BaseListResult以支持泛型类型 -为设备数据添加IntakeListResult和IntakeResult -通过数据库支持增强标记位置更新功能 -添加电话拨号意图以分隔标记详细信息 -通过过期检查改进磁贴缓存 -添加问题报告的确认对话框 -更新登录活动以限制用户名长度 -为波纹效果和UI元素添加新颜色 -重构XML布局以使用新的波纹图 -改进MapFragment中的错误处理和用户反馈 --- app/src/main/java/com/dayu/pipirrapp/activity/MainActivity.java | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 107 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/dayu/pipirrapp/activity/MainActivity.java b/app/src/main/java/com/dayu/pipirrapp/activity/MainActivity.java index d04a7d7..641aecb 100644 --- a/app/src/main/java/com/dayu/pipirrapp/activity/MainActivity.java +++ b/app/src/main/java/com/dayu/pipirrapp/activity/MainActivity.java @@ -1,11 +1,22 @@ package com.dayu.pipirrapp.activity; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.os.Build; import android.os.Bundle; +import android.os.VibrationEffect; +import android.os.Vibrator; import android.view.KeyEvent; import android.view.LayoutInflater; +import android.view.View; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.NotificationCompat; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.lifecycle.Observer; @@ -14,6 +25,7 @@ import com.dayu.pipirrapp.R; import com.dayu.pipirrapp.adapter.TabAdapter; import com.dayu.pipirrapp.bean.db.TagBean; +import com.dayu.pipirrapp.bean.net.OrderDetailResult; import com.dayu.pipirrapp.dao.DaoSingleton; import com.dayu.pipirrapp.databinding.ActivityMainBinding; import com.dayu.pipirrapp.fragment.MapFragment; @@ -27,16 +39,21 @@ import com.jeremyliao.liveeventbus.LiveEventBus; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 棣栭〉 */ public class MainActivity extends AppCompatActivity { + private static final String CHANNEL_ID = "order_channel"; private ActivityMainBinding binding; private List<Fragment> fragments = new ArrayList<>(); private long mExitTime; MqttManager mqttManager; + public volatile static Map<String, String> workerIddata = new HashMap<>(); + private enum Tab { ORDER, MAP, MY @@ -47,7 +64,6 @@ super.onCreate(savedInstanceState); binding = ActivityMainBinding.inflate(LayoutInflater.from(this)); setContentView(binding.getRoot()); - setupFragments(); initView(); initTab(); @@ -58,8 +74,7 @@ } catch (Exception e) { e.printStackTrace(); } - mqttManager = new MqttManager(this); - mqttManager.connect(); + mqttManager = new MqttManager(this, this); LiveEventBus.get(CommonKeyName.NetworkCallback).observeForever(new Observer<Object>() { @Override public void onChanged(Object o) { @@ -72,6 +87,36 @@ break; } + } + }); + LiveEventBus.get(CommonKeyName.RedLotRefresh).observeForever(new Observer<Object>() { + @Override + public void onChanged(Object o) { + if (o instanceof Boolean) { + if ((boolean) o) { + binding.redDotImg.setVisibility(View.GONE); + workerIddata.clear(); + } + } else if (o instanceof String) { + workerIddata.remove(o); + if (workerIddata.size() == 0) { + binding.redDotImg.setVisibility(View.GONE); + } + } + + } + }); + LiveEventBus.get(CommonKeyName.CreateNotification).observeForever(new Observer<Object>() { + @Override + public void onChanged(Object o) { + if (o instanceof OrderDetailResult) { + OrderDetailResult orderDetailResult = ((OrderDetailResult) o); + workerIddata.put(orderDetailResult.getWorkOrderId(), orderDetailResult.getWorkOrderId()); + binding.redDotImg.setVisibility(View.VISIBLE); + creatOrderNotification(orderDetailResult.getWorkOrderId().hashCode(), orderDetailResult.getTaskType(), orderDetailResult.getWorkOrderId()); + } + + } }); registNetCallBack(); @@ -96,11 +141,11 @@ } private void initTab() { - TabAdapter adapter = new TabAdapter(getSupportFragmentManager(), fragments); + TabAdapter adapter = new TabAdapter(this, fragments); binding.viewPager.setAdapter(adapter); - binding.viewPager.setPagingEnabled(false); + binding.viewPager.setCurrentItem(1, false); // 榛樿鏄剧ず鍦板浘椤� binding.viewPager.setOffscreenPageLimit(fragments.size()); - binding.viewPager.setCurrentItem(1); // 榛樿鏄剧ず鍦板浘椤� + binding.viewPager.setUserInputEnabled(false); } @Override @@ -120,8 +165,9 @@ @Override protected void onDestroy() { super.onDestroy(); - //鍏抽棴MQ + try { + //鍏抽棴MQ mqttManager.disconnect(); unregisterNetworkCallback(); } catch (Exception e) { @@ -151,7 +197,12 @@ * 鏇存柊鏌愪釜 Tab 鐨� UI 鐘舵�� */ private void updateTabUI(int position, int iconResId, int textColorResId) { - binding.viewPager.setCurrentItem(position); + if (position == 1) { + binding.viewPager.setCurrentItem(position, true); + } else { + binding.viewPager.setCurrentItem(position, false); + } + switch (position) { case 0: binding.orderImg.setImageDrawable(ContextCompat.getDrawable(this, iconResId)); @@ -191,7 +242,55 @@ NetUtils.unregisterReceiver(this); } + /** + * 鍒涘缓宸ュ崟鎻愮ず閫氱煡 + * + * @param notifucId + * @param data + */ + private void creatOrderNotification(int notifucId, String data, String workOrderId) { + NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + // 鍒涘缓NotificationChannel锛堜粎閽堝Android O鍙婁互涓婄増鏈級 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + CharSequence name = getString(R.string.channel_name); + String description = getString(R.string.channel_description); + int importance = NotificationManager.IMPORTANCE_DEFAULT; + NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance); + channel.setDescription(description); + // 娉ㄥ唽閫氶亾 + notificationManager.createNotificationChannel(channel); + } + Intent notificationIntent = new Intent(this, OrderDetailActivity.class); + notificationIntent.putExtra("workOrderId", workOrderId); + int requestCode = workOrderId.hashCode(); // 浣跨敤workOrderId鐨勫搱甯岀爜浣滀负requestCode + PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, notificationIntent, PendingIntent.FLAG_MUTABLE); + // 鍒涘缓闇囧姩鏁堟灉 + // 鑾峰彇 Vibrator 绯荤粺鏈嶅姟 + Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); + long[] vibrationPattern = {0, 1000, 500, 1000}; // 闇囧姩妯″紡锛氱瓑寰�0ms锛岄渿鍔�1000ms锛岀瓑寰�500ms锛岄渿鍔�1000ms + int repeat = -1; // 涓嶉噸澶� + + // 瀵逛簬Android 26鍙婁互涓婄増鏈紝浣跨敤VibrationEffect + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + VibrationEffect effect = VibrationEffect.createWaveform(vibrationPattern, repeat); + vibrator.vibrate(effect); + } else { + // 瀵逛簬Android 25鍙婁互涓嬬増鏈紝浣跨敤鏃х殑vibrate鏂规硶 + vibrator.vibrate(vibrationPattern, repeat); + } + Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID) + .setContentTitle("鏂板伐鍗�") + .setContentText(data) + .setSmallIcon(R.mipmap.ic_launcher) + .setContentIntent(pendingIntent) + .setAutoCancel(true) // 鐐瑰嚮閫氱煡鍚庤嚜鍔ㄦ秷澶� + .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)// 浣跨敤榛樿鐨勯煶鏁堝拰闇囧姩 + .setVibrate(vibrationPattern) + .build(); + notificationManager.notify(notifucId, notification); + + } } -- Gitblit v1.8.0