|
@@ -0,0 +1,195 @@
|
|
|
+package com.xplora.xpsettings.Activity;
|
|
|
+
|
|
|
+import android.content.ComponentName;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.graphics.drawable.ColorDrawable;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Looper;
|
|
|
+import android.os.Message;
|
|
|
+import android.os.PowerManager;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.WindowManager;
|
|
|
+import android.widget.ListView;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+
|
|
|
+import com.xplora.xpsettings.Adapter.BaseListAdapter;
|
|
|
+import com.xplora.xpsettings.Data.DataManager;
|
|
|
+import com.xplora.xpsettings.Fragment.SelectFragment;
|
|
|
+import com.xplora.xpsettings.Fragment.ShutdownningFragment;
|
|
|
+import com.xplora.xpsettings.Model.IconProgressModel;
|
|
|
+import com.xplora.xpsettings.Observer.Listener;
|
|
|
+import com.xplora.xpsettings.R;
|
|
|
+import com.xplora.xpsettings.Utils.Constant;
|
|
|
+import com.xplora.xpsettings.Utils.Macros;
|
|
|
+import com.xplora.xpsettings.Utils.ResUtils;
|
|
|
+
|
|
|
+import java.lang.reflect.Method;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+public class SystemActivity extends BaseActivity implements Listener.SelectFragmentListener {
|
|
|
+ private final List<IconProgressModel> mDataList = new ArrayList<>();
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ setContentView(R.layout.activity_list);
|
|
|
+ initView();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+
|
|
|
+ mDataList.clear();
|
|
|
+ initData();
|
|
|
+
|
|
|
+ mAdapter.setBaseObjects(mDataList);
|
|
|
+ mAdapter.notifyDataSetInvalidated();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initData() {
|
|
|
+ String[] stringList = ResUtils.getStringArray("system_title_array_", 5);
|
|
|
+ for (int i = 0; i < stringList.length; i++) {
|
|
|
+ IconProgressModel model = new IconProgressModel();
|
|
|
+ model.title = stringList[i].trim();
|
|
|
+ model.isShowArrow = false;
|
|
|
+ model.cellType = Constant.CellType.TITLE;
|
|
|
+ mDataList.add(model);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initView() {
|
|
|
+ ListView listView = findViewById(R.id.activity_listview);
|
|
|
+ mAdapter = new BaseListAdapter(this, R.layout.item_xpstyle, mDataList);
|
|
|
+ listView.setAdapter(mAdapter);
|
|
|
+ listView.setDivider(new ColorDrawable(Color.TRANSPARENT));
|
|
|
+ listView.setDividerHeight(1);
|
|
|
+ listView.setOnItemClickListener((adapterView, view, i, l) -> {
|
|
|
+ Intent intent;
|
|
|
+ switch (i) {
|
|
|
+ case 0:
|
|
|
+ gotoUpdate();
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ intent = new Intent(this, AboutActivity.class);
|
|
|
+ startActivity(intent);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ //Monkey测试时,屏蔽关机
|
|
|
+ if (DataManager.getLockShutDown() == 1)
|
|
|
+ break;
|
|
|
+ SelectFragment fragment7 = SelectFragment.newInstance(this);
|
|
|
+ fragment7.setItemInfo(101, getString(R.string.shut_down), getString(R.string.confirm_to_shut_down));
|
|
|
+ fragment7.show(this.getFragmentManager(), Constant.PACKAGE_NAME);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ //Monkey测试时,屏蔽关机
|
|
|
+ if (DataManager.getLockShutDown() == 1)
|
|
|
+ break;
|
|
|
+ SelectFragment fragment6 = SelectFragment.newInstance(this);
|
|
|
+ fragment6.setItemInfo(100, getString(R.string.restart), getString(R.string.confirm_to_restart));
|
|
|
+ fragment6.show(this.getFragmentManager(), Constant.PACKAGE_NAME);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSelectFragment(int type) {
|
|
|
+ if (type == 100) {
|
|
|
+ restart();
|
|
|
+ } else if (type == 101) {
|
|
|
+ shutdown();
|
|
|
+ }
|
|
|
+
|
|
|
+ //状态栏不显示
|
|
|
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
+
|
|
|
+ //黑背景,防止关机中看到setting界面
|
|
|
+ ShutdownningFragment fragment = ShutdownningFragment.newInstance(this);
|
|
|
+ fragment.show(this.getFragmentManager(), Constant.PACKAGE_NAME);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCancelFragment() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void restart() {
|
|
|
+ if (Macros.DEBUG_RESTART) {
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ PowerManager pManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
|
|
+ pManager.reboot("userrequested");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ } else {
|
|
|
+ String pkg = "com.sikey.commonservice";
|
|
|
+ String cls = pkg + ".modules.callbacks.LocalReceiver";
|
|
|
+ ComponentName componet = new ComponentName(pkg, cls);
|
|
|
+
|
|
|
+ Intent intent = new Intent("com.xplora.action.POWER_STATUS");
|
|
|
+ intent.putExtra("type", 1); //0:power off 1:reboot 2:factory reset
|
|
|
+ intent.setComponent(componet);
|
|
|
+ sendBroadcast(intent, "com.xplora.receiver");
|
|
|
+ Log.d(TAG, "restart: ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void shutdown() {
|
|
|
+ if (Macros.DEBUG_RESTART) {
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ PowerManager pManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
|
|
|
+ if (pManager != null) {
|
|
|
+ Method method = pManager.getClass().getMethod("shutdown", boolean.class, String.class, boolean.class);
|
|
|
+ method.invoke(pManager, false, "userrequested", false);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ } else {
|
|
|
+ String pkg = "com.sikey.commonservice";
|
|
|
+ String cls = pkg + ".modules.callbacks.LocalReceiver";
|
|
|
+ ComponentName componet = new ComponentName(pkg, cls);
|
|
|
+
|
|
|
+ Intent intent = new Intent("com.xplora.action.POWER_STATUS");
|
|
|
+ intent.putExtra("type", 0); //0:power off 1:reboot 2:factory reset
|
|
|
+ intent.setComponent(componet);
|
|
|
+ sendBroadcast(intent, "com.xplora.receiver");
|
|
|
+ Log.d(TAG, "shutdown: ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void gotoUpdate() {
|
|
|
+ //该应用的包名
|
|
|
+ String pkg = "com.sikey.commonservice";
|
|
|
+ //应用的主activity类
|
|
|
+ String cls = pkg + ".ui.activity.OtaCheckActivity";
|
|
|
+ ComponentName componet = new ComponentName(pkg, cls);
|
|
|
+
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("intent_from", 1);
|
|
|
+ intent.setComponent(componet);
|
|
|
+ startActivity(intent);
|
|
|
+ }
|
|
|
+}
|