Bladeren bron

增加进入系统设置按钮,增加启动三代系统app方式

weizhengliang 2 jaren geleden
bovenliggende
commit
5b115b7253

+ 16 - 0
app/src/main/java/com/wdkl/callingbed2/ui/CallingBedActivity.java

@@ -38,6 +38,7 @@ import android.widget.LinearLayout;
 import android.widget.RelativeLayout;
 import android.widget.SeekBar;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.google.gson.Gson;
 import com.squareup.picasso.MemoryPolicy;
@@ -641,6 +642,21 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
         disableStatusBar();
 
         setCallStatus(serialPortUtil, "0");
+
+        tvBedNum.setOnLongClickListener(new View.OnLongClickListener() {
+            @Override
+            public boolean onLongClick(View view) {
+                Intent intent = AutoRebootUtil.getNewAppIntent(CallingBedActivity.this);
+                if (intent != null) {
+                    Toast.makeText(CallingBedActivity.this, "新V3系统app已安装,即将启动...", Toast.LENGTH_SHORT).show();
+                    startActivity(intent);
+                } else {
+                    Toast.makeText(CallingBedActivity.this, "新V3系统app未安装,请先安装新系统app...", Toast.LENGTH_SHORT).show();
+                }
+
+                return true;
+            }
+        });
     }
 
     @Override

+ 24 - 0
app/src/main/java/com/wdkl/callingbed2/util/AutoRebootUtil.java

@@ -6,6 +6,8 @@ import android.app.AlarmManager;
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
 import android.os.SystemProperties;
 
 import com.wdkl.callingbed2.MyApplication;
@@ -13,6 +15,7 @@ import com.wdkl.callingbed2.common.Constants;
 import com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand;
 
 import java.util.Calendar;
+import java.util.List;
 
 import static com.wdkl.callingbed2.common.Constants.NET_ERROR_FIVE_AFTER_TOAST;
 import static com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand.closeHeart;
@@ -182,4 +185,25 @@ public class AutoRebootUtil {
             CallingBedSendCommand.setNetStatus(MyApplication.serialPortUtil, "1");
         }
     }
+
+    public static Intent getNewAppIntent(Context context) {
+        Intent intent = null;
+        try {
+            String newAppName = "com.wdkl.app.ncs.callingbed2";
+            List<PackageInfo> packageInfos = context.getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES |
+                    PackageManager.GET_SERVICES);
+            for (PackageInfo info : packageInfos) {
+                String pkg = info.packageName;
+                if (newAppName.equals(pkg)) {
+                    intent = context.getPackageManager().getLaunchIntentForPackage(pkg);
+                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                    return intent;
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return intent;
+    }
 }

+ 29 - 1
app/src/main/java/com/wdkl/callingbed2/widget/loading/VaryViewHelperController.java

@@ -1,17 +1,22 @@
 package com.wdkl.callingbed2.widget.loading;
 
 
+import android.content.Intent;
 import android.graphics.drawable.AnimationDrawable;
+import android.provider.Settings;
 import android.text.TextUtils;
 import android.view.View;
 import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.TextView;
+import android.widget.Toast;
 
+import com.wdkl.callingbed2.MyApplication;
 import com.wdkl.callingbed2.R;
+import com.wdkl.callingbed2.util.AutoRebootUtil;
 
 
-public class VaryViewHelperController {
+public class VaryViewHelperController implements View.OnLongClickListener, View.OnClickListener {
 
     private IVaryViewHelper helper;
 
@@ -36,6 +41,7 @@ public class VaryViewHelperController {
             againBtn.setOnClickListener(onClickListener);
         }
         helper.showLayout(layout);
+        layout.setOnLongClickListener(this);
     }
 
     public void showNetworkError(View.OnClickListener onClickListener,String str) {
@@ -47,6 +53,8 @@ public class VaryViewHelperController {
             againBtn.setOnClickListener(onClickListener);
         }
         helper.showLayout(layout);
+        layout.setOnLongClickListener(this);
+        tvMac.setOnClickListener(this);
     }
 
     public void showEmpty(String emptyMsg) {
@@ -56,14 +64,34 @@ public class VaryViewHelperController {
             textView.setText(emptyMsg);
         }
         helper.showLayout(layout);
+        layout.setOnLongClickListener(this);
+        textView.setOnClickListener(this);
     }
 
     public void showLoading() {
         View layout = helper.inflate(R.layout.view_loading_loading);
         helper.showLayout(layout);
+        layout.setOnLongClickListener(this);
     }
 
     public void restore() {
         helper.restoreView();
     }
+
+    @Override
+    public boolean onLongClick(View view) {
+        MyApplication.getAppContext().startActivity(new Intent(Settings.ACTION_SETTINGS));
+        return true;
+    }
+
+    @Override
+    public void onClick(View view) {
+        Intent intent = AutoRebootUtil.getNewAppIntent(MyApplication.getAppContext());
+        if (intent != null) {
+            Toast.makeText(MyApplication.getAppContext(), "新V3系统app已安装,即将启动...", Toast.LENGTH_SHORT).show();
+            MyApplication.getAppContext().startActivity(intent);
+        } else {
+            Toast.makeText(MyApplication.getAppContext(), "新V3系统app未安装,请先安装新系统app...", Toast.LENGTH_SHORT).show();
+        }
+    }
 }