version:1.0.0
update:更换包名 bugfixes:
This commit is contained in:
@@ -0,0 +1,779 @@
|
||||
package com.xxpatx.os.activity.control;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.camera2.CameraAccessException;
|
||||
import android.hardware.camera2.CameraCharacteristics;
|
||||
import android.hardware.camera2.CameraManager;
|
||||
import android.media.AudioManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
import com.hjq.toast.Toaster;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.xxpatx.os.R;
|
||||
import com.xxpatx.os.base.mvvm.BaseMvvmActivity;
|
||||
import com.xxpatx.os.config.CommonConfig;
|
||||
import com.xxpatx.os.databinding.ActivityControlBinding;
|
||||
import com.xxpatx.os.manager.AmapManager;
|
||||
import com.xxpatx.os.manager.RemoteManager;
|
||||
import com.xxpatx.os.utils.BrightnessUtils;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ControlActivity extends BaseMvvmActivity<ControlViewModel, ActivityControlBinding> {
|
||||
private static final String TAG = ControlActivity.class.getSimpleName();
|
||||
|
||||
private static final String ACTION_FLASHLIGHT_CHANGED =
|
||||
"com.android.settings.flashlight.action.FLASHLIGHT_CHANGED";
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_control;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initDataBinding() {
|
||||
mViewModel.setCtx(this);
|
||||
mViewModel.setVDBinding(mViewDataBinding);
|
||||
mViewModel.setLifecycle(getLifecycleSubject());
|
||||
mViewDataBinding.setClick(new BtnClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
getWifi();
|
||||
registerReceivers();
|
||||
getBluetooth();
|
||||
registerBluetoothReceiver();
|
||||
getBattery();
|
||||
registerBatteryReceiver();
|
||||
getFlashlight();
|
||||
getFontSize();
|
||||
getLocation();
|
||||
getBrightness();
|
||||
getSound();
|
||||
mViewDataBinding.clFlashlight.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
try {
|
||||
startActivity(new Intent(Settings.ACTION_SETTINGS));
|
||||
} catch (Exception e) {
|
||||
Toaster.show("打开失败");
|
||||
Log.e(TAG, "onClick: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
mViewDataBinding.clBattery.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(Settings.ACTION_BATTERY_SAVER_SETTINGS));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
|
||||
}
|
||||
|
||||
private void getWifi() {
|
||||
mViewDataBinding.clWifi.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
|
||||
// startActivity(new Intent(ControlActivity.this, WiFiManagerActivity.class));
|
||||
}
|
||||
});
|
||||
if (isWifiEnabled()) {
|
||||
// tv_wifi_ssid.setText(getConnectWifiSsid());
|
||||
mViewDataBinding.clBattery.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
} else {
|
||||
// tv_wifi_ssid.setText("未连接");
|
||||
mViewDataBinding.clBattery.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWifiEnabled() {
|
||||
WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
if (wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
|
||||
ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo wifiInfo = connManager
|
||||
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
return wifiInfo.isConnected();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private WifiReceiver mWifiReceiver;
|
||||
|
||||
private void registerReceivers() {
|
||||
registerWiFiReceiver();
|
||||
}
|
||||
|
||||
private void registerWiFiReceiver() {
|
||||
if (mWifiReceiver == null) {
|
||||
mWifiReceiver = new WifiReceiver();
|
||||
}
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.RSSI_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
|
||||
filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
|
||||
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
registerReceiver(mWifiReceiver, filter);
|
||||
}
|
||||
|
||||
public class WifiReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "wifiReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
case WifiManager.RSSI_CHANGED_ACTION:
|
||||
Log.e(TAG, "wifi信号强度变化");
|
||||
break;
|
||||
//wifi连接上与否
|
||||
case WifiManager.NETWORK_STATE_CHANGED_ACTION:
|
||||
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||
if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) {
|
||||
Log.e(TAG, "wifi断开");
|
||||
// tv_wifi_ssid.setText("未连接");
|
||||
mViewDataBinding.clBattery.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
} else if (info.getState().equals(NetworkInfo.State.CONNECTED)) {
|
||||
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||
//获取当前wifi名称
|
||||
String newSSID = wifiInfo.getSSID();
|
||||
// tv_wifi_ssid.setText(getConnectWifiSsid());
|
||||
mViewDataBinding.clBattery.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
}
|
||||
break;
|
||||
//wifi打开与否
|
||||
case WifiManager.WIFI_STATE_CHANGED_ACTION:
|
||||
int wifistate = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED);
|
||||
if (wifistate == WifiManager.WIFI_STATE_DISABLED) {
|
||||
Log.e(TAG, "系统关闭wifi");
|
||||
// tv_wifi_ssid.setText("关");
|
||||
mViewDataBinding.clBattery.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
} else if (wifistate == WifiManager.WIFI_STATE_ENABLED) {
|
||||
Log.e(TAG, "系统开启wifi");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前连接WIFI的SSID
|
||||
*/
|
||||
public String getSSID() {
|
||||
WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
|
||||
if (wm != null) {
|
||||
WifiInfo winfo = wm.getConnectionInfo();
|
||||
if (winfo != null) {
|
||||
String s = winfo.getSSID();
|
||||
if (s.length() > 2 && s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"') {
|
||||
return s.substring(1, s.length() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private String getConnectWifiSsid() {
|
||||
// WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||
// WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||
//// //去掉带引号的字符串方法一
|
||||
//// String wifiInfo1 = wifiInfo.getSSID();
|
||||
//// if (wifiInfo1.contains("\"")) {
|
||||
//// wifiInfo1 = wifiInfo1.substring(1, wifiInfo1.length() - 1);
|
||||
//// }
|
||||
////去掉带引号的字符串方法二
|
||||
// String wifiSSID = wifiInfo.getSSID();
|
||||
// String wifiInfo1 = wifiSSID.replaceAll("\"", "");
|
||||
return RemoteManager.getInstance().getConnectWifiSsid();
|
||||
}
|
||||
|
||||
private BluetoothAdapter bluetoothAdapter;
|
||||
|
||||
private void getBluetooth() {
|
||||
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (bluetoothAdapter.isEnabled()) {
|
||||
// if (isConnected()) {
|
||||
// clBt.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
// tv_bt_ssid.setText(getBluetoothDeviceName());
|
||||
// } else {
|
||||
// clBt.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
// tv_bt_ssid.setText("未连接");
|
||||
// }
|
||||
} else {
|
||||
mViewDataBinding.clBt.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
// tv_bt_ssid.setText("已关闭");
|
||||
}
|
||||
getConnectedDevicesV1();
|
||||
mViewDataBinding.clBt.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// public boolean isConnected() {
|
||||
// Set<BluetoothDevice> bondedDevices = bluetoothAdapter.getBondedDevices();
|
||||
// List<BluetoothDevice> deviceList = bondedDevices.stream().filter(new Predicate<BluetoothDevice>() {
|
||||
// @Override
|
||||
// public boolean test(BluetoothDevice bluetoothDevice) {
|
||||
// return bluetoothDevice.isConnected();
|
||||
// }
|
||||
// }).collect(Collectors.toList());
|
||||
// return deviceList.size() > 0;
|
||||
// }
|
||||
|
||||
// public String getBluetoothDeviceName() {
|
||||
// Set<BluetoothDevice> bondedDevices = bluetoothAdapter.getBondedDevices();
|
||||
// List<BluetoothDevice> deviceList = bondedDevices.stream().filter(new Predicate<BluetoothDevice>() {
|
||||
// @Override
|
||||
// public boolean test(BluetoothDevice bluetoothDevice) {
|
||||
// return bluetoothDevice.isConnected();
|
||||
// }
|
||||
// }).collect(Collectors.toList());
|
||||
// if (deviceList.size() == 0) {
|
||||
// return "未连接";
|
||||
// } else {
|
||||
// return deviceList.get(0).getName();
|
||||
// }
|
||||
// }
|
||||
|
||||
//TODO 根据mac地址判断是否已连接(这里参数可以直接用BluetoothDevice对象)
|
||||
//但这么写其实更通用。
|
||||
public boolean isConnected(String macAddress) {
|
||||
if (!BluetoothAdapter.checkBluetoothAddress(macAddress)) {
|
||||
return false;
|
||||
}
|
||||
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(macAddress);
|
||||
|
||||
Method isConnectedMethod = null;
|
||||
boolean isConnected;
|
||||
try {
|
||||
isConnectedMethod = BluetoothDevice.class.getDeclaredMethod("isConnected", (Class[]) null);
|
||||
isConnectedMethod.setAccessible(true);
|
||||
isConnected = (boolean) isConnectedMethod.invoke(device, (Object[]) null);
|
||||
} catch (NoSuchMethodException e) {
|
||||
isConnected = false;
|
||||
} catch (IllegalAccessException e) {
|
||||
isConnected = false;
|
||||
} catch (InvocationTargetException e) {
|
||||
isConnected = false;
|
||||
}
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统中已连接的蓝牙设备
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<BluetoothDevice> getConnectedDevicesV1() {
|
||||
Class<BluetoothAdapter> bluetoothAdapterClass = BluetoothAdapter.class;//得到BluetoothAdapter的Class对象
|
||||
Set<BluetoothDevice> deviceSet = new HashSet<>();
|
||||
//是否存在连接的蓝牙设备
|
||||
try {
|
||||
Method method = bluetoothAdapterClass.getDeclaredMethod("getMostRecentlyConnectedDevices", (Class[]) null);
|
||||
//打开权限
|
||||
method.setAccessible(true);
|
||||
List<BluetoothDevice> list = (List<BluetoothDevice>) method.invoke(BluetoothAdapter.getDefaultAdapter(), (Object[]) null);
|
||||
Log.e("zbh", "最近连接过的设备:");
|
||||
for (BluetoothDevice dev : list
|
||||
) {
|
||||
String Type = "";
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
switch (dev.getType()) {
|
||||
case BluetoothDevice.DEVICE_TYPE_CLASSIC:
|
||||
Type = "经典";
|
||||
break;
|
||||
case BluetoothDevice.DEVICE_TYPE_LE:
|
||||
Type = "BLE";
|
||||
break;
|
||||
case BluetoothDevice.DEVICE_TYPE_DUAL:
|
||||
Type = "双模";
|
||||
break;
|
||||
default:
|
||||
Type = "未知";
|
||||
break;
|
||||
}
|
||||
}
|
||||
String connect = "设备未连接";
|
||||
if (isConnected(dev.getAddress())) {
|
||||
deviceSet.add(dev);
|
||||
connect = "设备已连接";
|
||||
}
|
||||
Log.e("zbh", connect + ", address = " + dev.getAddress() + "(" + Type + "), name --> " + dev.getName());
|
||||
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return deviceSet;
|
||||
}
|
||||
|
||||
private BluetoothMonitorReceiver bleListenerReceiver;
|
||||
|
||||
private void registerBluetoothReceiver() {
|
||||
bleListenerReceiver = new BluetoothMonitorReceiver();
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
// 监视蓝牙关闭和打开的状态
|
||||
intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
// 监视蓝牙设备与APP连接的状态
|
||||
intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
|
||||
intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
|
||||
// 注册广播
|
||||
registerReceiver(this.bleListenerReceiver, intentFilter);
|
||||
}
|
||||
|
||||
public class BluetoothMonitorReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Log.e("BluetoothMonitorReceiver", "onReceive: " + action);
|
||||
if (!TextUtils.isEmpty(action)) {
|
||||
switch (action) {
|
||||
case BluetoothAdapter.ACTION_STATE_CHANGED:
|
||||
int blueState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
|
||||
switch (blueState) {
|
||||
case BluetoothAdapter.STATE_TURNING_ON:
|
||||
// tv_bt_ssid.setText("正在打开");
|
||||
mViewDataBinding.clBt.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
break;
|
||||
case BluetoothAdapter.STATE_ON:
|
||||
// tv_bt_ssid.setText("已打开");
|
||||
mViewDataBinding.clBt.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
break;
|
||||
case BluetoothAdapter.STATE_TURNING_OFF:
|
||||
// tv_bt_ssid.setText("正在关闭");
|
||||
mViewDataBinding.clBt.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
break;
|
||||
case BluetoothAdapter.STATE_OFF:
|
||||
// tv_bt_ssid.setText("已关闭");
|
||||
mViewDataBinding.clBt.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
break;
|
||||
case BluetoothDevice.ACTION_ACL_CONNECTED:
|
||||
// tv_bt_ssid.setText(getBluetoothDeviceName());
|
||||
mViewDataBinding.clBt.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
break;
|
||||
case BluetoothDevice.ACTION_ACL_DISCONNECTED:
|
||||
// tv_bt_ssid.setText("未连接");
|
||||
mViewDataBinding.clBt.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getBattery() {
|
||||
// tv_electricity.setText(getBatteryCapacity() + "%");
|
||||
if (isBatteryCharging()) {
|
||||
mViewDataBinding.clBattery.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
} else {
|
||||
mViewDataBinding.clBattery.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主动获取当前电池是否在充电 , 即数据线是否插在手机上
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isBatteryCharging() {
|
||||
boolean isBatteryCharging = false;
|
||||
// 主动发送包含是否正在充电状态的广播 , 该广播会持续发送
|
||||
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||
// 注册广播接受者
|
||||
Intent intent = registerReceiver(null, intentFilter);
|
||||
// 获取充电状态
|
||||
int batteryChargeState = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
|
||||
// 判定是否是 AC 交流电充电
|
||||
boolean isAc = batteryChargeState == BatteryManager.BATTERY_PLUGGED_AC;
|
||||
// 判断是否是 USB 充电
|
||||
boolean isUsb = batteryChargeState == BatteryManager.BATTERY_PLUGGED_USB;
|
||||
// 判断是否是 无线充电
|
||||
boolean isWireless = batteryChargeState == BatteryManager.BATTERY_PLUGGED_WIRELESS;
|
||||
// 如何上述任意一种为 true , 说明当前正在充电
|
||||
isBatteryCharging = isAc || isUsb || isWireless;
|
||||
return isBatteryCharging;
|
||||
}
|
||||
|
||||
|
||||
public int getBatteryCapacity() {
|
||||
try {
|
||||
BatteryManager batteryManager = (BatteryManager) getSystemService(Context.BATTERY_SERVICE);
|
||||
return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
|
||||
} catch (Exception e) {
|
||||
Log.e("getBattery", "getBattery" + e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private BatteryReceiver mBatteryReceiver;
|
||||
|
||||
private void registerBatteryReceiver() {
|
||||
if (mBatteryReceiver == null) {
|
||||
mBatteryReceiver = new BatteryReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_POWER_CONNECTED);
|
||||
filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
|
||||
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||
// filter.addAction(Intent.ACTION_BATTERY_LEVEL_CHANGED);
|
||||
filter.addAction(Intent.ACTION_BATTERY_LOW);
|
||||
filter.addAction(Intent.ACTION_BATTERY_OKAY);
|
||||
registerReceiver(mBatteryReceiver, filter);
|
||||
}
|
||||
}
|
||||
|
||||
public class BatteryReceiver extends BroadcastReceiver {
|
||||
public static final String TAG = "BatteryReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// 获取广播事件
|
||||
String action = intent.getAction();
|
||||
if (TextUtils.isEmpty(action)) return;
|
||||
Log.e(TAG, "onReceive: " + action);
|
||||
switch (action) {
|
||||
case Intent.ACTION_POWER_CONNECTED:
|
||||
mViewDataBinding.clBattery.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
break;
|
||||
case Intent.ACTION_POWER_DISCONNECTED:
|
||||
mViewDataBinding.clBattery.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
break;
|
||||
// case Intent.ACTION_BATTERY_LEVEL_CHANGED:
|
||||
// tv_electricity.setText(getBatteryCapacity() + "%");
|
||||
// break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean flashing = false;
|
||||
private CameraManager cameraManager;
|
||||
|
||||
// private void getFlashlight() {
|
||||
// if (isFlashlightAvailable()) {
|
||||
// tv_flashlight_switch.setText("关");
|
||||
// clFlashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
// } else {
|
||||
// tv_flashlight_switch.setText("不可用");
|
||||
// clFlashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
// return;
|
||||
// }
|
||||
//// if (isFlashlightEnabled()) {
|
||||
//// tv_flashlight_switch.setText("开");
|
||||
//// clFlashlight.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
//// } else {
|
||||
//// tv_flashlight_switch.setText("关");
|
||||
//// clFlashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
//// }
|
||||
//
|
||||
// cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
|
||||
//
|
||||
// clFlashlight.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
// if (flashing) {
|
||||
// try {
|
||||
// String CameraId = cameraManager.getCameraIdList()[0];
|
||||
// cameraManager.setTorchMode(CameraId, false);
|
||||
// } catch (CameraAccessException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// flashing = false;
|
||||
// tv_flashlight_switch.setText("关");
|
||||
// clFlashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
// } else {
|
||||
// try {
|
||||
// String CameraId = cameraManager.getCameraIdList()[0];
|
||||
// cameraManager.setTorchMode(CameraId, true);
|
||||
// } catch (CameraAccessException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// tv_flashlight_switch.setText("开");
|
||||
// clFlashlight.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
// flashing = true;
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
BroadcastReceiver mTimeUpdateReceiver;
|
||||
|
||||
class TimeUpdateReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent == null) return;
|
||||
String action = intent.getAction();
|
||||
if (action == null || action.isEmpty()) return;
|
||||
|
||||
if (action.equals(Intent.ACTION_TIME_TICK)) {
|
||||
//系统每1分钟发送一次广播
|
||||
updateTimeUi();
|
||||
} else if (action.equals(Intent.ACTION_TIME_CHANGED)) {
|
||||
//系统手动更改时间发送广播
|
||||
updateTimeUi();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTimeUi() {
|
||||
// long time = System.currentTimeMillis();
|
||||
// SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
|
||||
// String timeText = timeFormat.format(time);
|
||||
// tv_flashlight.setText(timeText);
|
||||
// SimpleDateFormat format = new SimpleDateFormat("MM月dd日");
|
||||
// String dataText = format.format(time);
|
||||
// tv_flashlight_switch.setText(dataText);
|
||||
}
|
||||
|
||||
private void getFlashlight() {
|
||||
if (mTimeUpdateReceiver == null) {
|
||||
mTimeUpdateReceiver = new TimeUpdateReceiver();
|
||||
}
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_TIME_TICK);
|
||||
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
registerReceiver(mTimeUpdateReceiver, filter);
|
||||
updateTimeUi();
|
||||
// if (isFlashlightAvailable()) {
|
||||
// tv_flashlight_switch.setText("关");
|
||||
// clFlashlight.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
// } else {
|
||||
// tv_flashlight_switch.setText("不可用");
|
||||
// clFlashlight.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
// return;
|
||||
// }
|
||||
//// if (isFlashlightEnabled()) {
|
||||
//// tv_flashlight_switch.setText("开");
|
||||
//// clFlashlight.setBackground(getDrawable(R.drawable.control_background_item));
|
||||
//// } else {
|
||||
//// tv_flashlight_switch.setText("关");
|
||||
//// clFlashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
|
||||
//// }
|
||||
//
|
||||
// cameraManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
|
||||
//
|
||||
// clFlashlight.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
// if (flashing) {
|
||||
// try {
|
||||
// String CameraId = cameraManager.getCameraIdList()[0];
|
||||
// cameraManager.setTorchMode(CameraId, false);
|
||||
// } catch (CameraAccessException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// flashing = false;
|
||||
// tv_flashlight_switch.setText("关");
|
||||
// clFlashlight.setBackground(mContext.getDrawable(R.drawable.control_background_item_dis));
|
||||
// } else {
|
||||
// try {
|
||||
// String CameraId = cameraManager.getCameraIdList()[0];
|
||||
// cameraManager.setTorchMode(CameraId, true);
|
||||
// } catch (CameraAccessException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// tv_flashlight_switch.setText("开");
|
||||
// clFlashlight.setBackground(mContext.getDrawable(R.drawable.control_background_item));
|
||||
// flashing = true;
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
private boolean isFlashlightAvailable() {
|
||||
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
|
||||
}
|
||||
|
||||
private static String getCameraId(Context context) throws CameraAccessException {
|
||||
final CameraManager cameraManager = context.getSystemService(CameraManager.class);
|
||||
final String[] ids = cameraManager.getCameraIdList();
|
||||
for (String id : ids) {
|
||||
CameraCharacteristics c = cameraManager.getCameraCharacteristics(id);
|
||||
Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
|
||||
Integer lensFacing = c.get(CameraCharacteristics.LENS_FACING);
|
||||
if (flashAvailable != null && flashAvailable
|
||||
&& lensFacing != null && lensFacing == CameraCharacteristics.LENS_FACING_BACK) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// private boolean isFlashlightEnabled() {
|
||||
// return Settings.Secure.getInt(getContentResolver(), Settings.Secure.FLASHLIGHT_ENABLED, 0) == 1;
|
||||
// }
|
||||
|
||||
private void getFontSize() {
|
||||
float fontScale = Settings.System.getFloat(getContentResolver(), Settings.System.FONT_SCALE, 0.0f);
|
||||
Log.e(TAG, "getHardware: fontScale = " + fontScale);
|
||||
List<String> mEntries = Arrays.asList(getResources().getStringArray(R.array.entries_font_size));
|
||||
List<String> strEntryValues = Arrays.asList(getResources().getStringArray(R.array.entryvalues_font_size));
|
||||
mViewDataBinding.seekBar.setMax(mEntries.size() - 1);
|
||||
String font_size;
|
||||
int index = strEntryValues.indexOf(String.valueOf(fontScale));
|
||||
if (index == -1) {
|
||||
font_size = "默认";
|
||||
} else {
|
||||
font_size = mEntries.get(index);
|
||||
}
|
||||
// tv_font_size.setText(font_size);
|
||||
mViewDataBinding.seekBar.setProgress(index);
|
||||
mViewDataBinding.seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
||||
Settings.System.putFloat(getContentResolver(), Settings.System.FONT_SCALE, Float.parseFloat(strEntryValues.get(i)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getLocation() {
|
||||
String addr = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE).decodeString(CommonConfig.MAP_ADDRESS_KEY);
|
||||
|
||||
if (TextUtils.isEmpty(addr) || "nullnull".equals(addr) || "null".equals(addr)) {
|
||||
mViewDataBinding.tvLocation.setText("未能获取到位置信息");
|
||||
} else {
|
||||
mViewDataBinding.tvLocation.setText(addr);
|
||||
}
|
||||
mViewDataBinding.clLocation.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AmapManager.getInstance().startLocation();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getBrightness() {
|
||||
mViewDataBinding.seekbarBrightness.setMax(255);
|
||||
//亮度
|
||||
int brightness = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 1);
|
||||
mViewDataBinding.seekbarBrightness.setProgress(brightness);
|
||||
Log.e(TAG, "getHardware: brightness = " + brightness);
|
||||
int gamma = BrightnessUtils.convertLinearToGamma(brightness, 1, 255);
|
||||
Log.e(TAG, "getHardware: gamma = " + gamma);
|
||||
long percentage = Math.round((((double) gamma / 65535) * 100f));
|
||||
// tv_brightness.setText(percentage + "%");
|
||||
Log.e(TAG, "getHardware: percentage = " + percentage);
|
||||
mViewDataBinding.seekbarBrightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
||||
Log.e(TAG, "onProgressChanged: i = " + i);
|
||||
RemoteManager.getInstance().putSystemInt(Settings.System.SCREEN_BRIGHTNESS, i);
|
||||
int gamma = BrightnessUtils.convertLinearToGamma(i, 1, 255);
|
||||
Log.e(TAG, "onProgressChanged: gamma = " + gamma);
|
||||
long percentage = Math.round((((double) gamma / 65535) * 100f));
|
||||
Log.e(TAG, "onProgressChanged: percentage = " + percentage);
|
||||
// tv_brightness.setText(percentage + "%");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private AudioManager mAudioManager;
|
||||
|
||||
private void getSound() {
|
||||
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
||||
//最大音量
|
||||
int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
mViewDataBinding.seekbarSound.setMax(maxVolume);
|
||||
Log.e(TAG, "getHardware: maxVolume = " + maxVolume);
|
||||
//音量
|
||||
int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
mViewDataBinding.seekbarSound.setProgress(streamVolume);
|
||||
Log.e(TAG, "getHardware: streamVolume = " + streamVolume);
|
||||
int currentVolume = (int) (((double) streamVolume / (double) maxVolume) * 100f);
|
||||
Log.e(TAG, "getHardware: currentVolume = " + currentVolume);
|
||||
mViewDataBinding.tvSound.setText(currentVolume + "%");
|
||||
mViewDataBinding.seekbarSound.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
||||
int volume = (int) (((double) i / (double) maxVolume) * 100f);
|
||||
mViewDataBinding.tvSound.setText(volume + "%");
|
||||
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, i, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mWifiReceiver != null) unregisterReceiver(mWifiReceiver);
|
||||
if (mTimeUpdateReceiver != null) unregisterReceiver(mTimeUpdateReceiver);
|
||||
}
|
||||
|
||||
public class BtnClick {
|
||||
public void exit(View view) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.xxpatx.os.activity.control;
|
||||
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.xxpatx.os.base.mvvm.BaseViewModel;
|
||||
import com.xxpatx.os.databinding.ActivityControlBinding;
|
||||
|
||||
public class ControlViewModel extends BaseViewModel<ActivityControlBinding, ActivityEvent> {
|
||||
|
||||
@Override
|
||||
public ActivityControlBinding getVDBinding() {
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user