version:1.2

fix:
update:快捷控制中心报错修复,完善闪光灯
This commit is contained in:
2022-11-04 22:56:05 +08:00
parent 1fdc7ba314
commit 4d7c623876
4 changed files with 63 additions and 40 deletions

View File

@@ -17,7 +17,8 @@
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<!-- 允许访问网络,必选权限 -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- 允许获取精确位置,精准定位必选 -->

View File

@@ -7,6 +7,7 @@ import android.content.ContentResolver;
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;
@@ -35,12 +36,10 @@ import com.baidu.location.LocationClient;
import com.uiuios.aios.R;
import com.uiuios.aios.manager.AmapManager;
import com.uiuios.aios.utils.BrightnessUtils;
import com.uiuios.aios.view.CustomSeekbar;
import com.uiuios.aios.view.RulerSeekBar;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@@ -536,27 +535,51 @@ public class ControlActivity extends AppCompatActivity {
}
}
private boolean flashing = false;
private CameraManager cameraManager;
private void getFlashlight() {
if (isFlashlightEnabled()) {
tv_flashlight_switch.setText("");
cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item));
} else {
if (isFlashlightAvailable()) {
tv_flashlight_switch.setText("");
cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
} else {
tv_flashlight_switch.setText("不可用");
cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
return;
}
// if (isFlashlightEnabled()) {
// tv_flashlight_switch.setText("开");
// cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item));
// } else {
// tv_flashlight_switch.setText("关");
// cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
// }
cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
cl_flashlight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isFlashlightEnabled()) {
Settings.Secure.putInt(crv, Settings.Secure.FLASHLIGHT_ENABLED, 0);
sendBroadcast(new Intent(ACTION_FLASHLIGHT_CHANGED));
if (flashing) {
try {
String CameraId = cameraManager.getCameraIdList()[0];
cameraManager.setTorchMode(CameraId, false);
} catch (CameraAccessException e) {
e.printStackTrace();
}
flashing = false;
tv_flashlight_switch.setText("");
cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item_dis));
} else {
Settings.Secure.putInt(crv, Settings.Secure.FLASHLIGHT_ENABLED, 1);
sendBroadcast(new Intent(ACTION_FLASHLIGHT_CHANGED));
try {
String CameraId = cameraManager.getCameraIdList()[0];
cameraManager.setTorchMode(CameraId, true);
} catch (CameraAccessException e) {
e.printStackTrace();
}
tv_flashlight_switch.setText("");
cl_flashlight.setBackground(getDrawable(R.drawable.control_background_item));
flashing = true;
}
}
});
@@ -564,16 +587,7 @@ public class ControlActivity extends AppCompatActivity {
private boolean isFlashlightAvailable() {
int defaultAvailability = 0;
try {
// check if there is a flash unit
if (getCameraId(this) != null) {
defaultAvailability = 1;
}
} catch (CameraAccessException e) {
Log.e(TAG, "Error getting camera id.", e);
}
return Settings.Secure.getInt(crv, Settings.Secure.FLASHLIGHT_AVAILABLE, defaultAvailability) == 1;
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
}
private static String getCameraId(Context context) throws CameraAccessException {
@@ -600,7 +614,7 @@ public class ControlActivity extends AppCompatActivity {
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));
seekBar.setMax(mEntries.size()-1);
seekBar.setMax(mEntries.size() - 1);
String font_size;
int index = strEntryValues.indexOf(String.valueOf(fontScale));
if (index == -1) {

View File

@@ -97,9 +97,9 @@ public class EmergencyActivity extends AppCompatActivity {
Log.e(TAG, "accept: " + (time - aLong - 1));
} else {
MMKV mmkv = MMKV.defaultMMKV();
String longitude = mmkv.decodeString(AmapManager.LONGITUDE_KEY, "未知");
String latitude = mmkv.decodeString(AmapManager.LATITUDE_KEY, "未知");
String address = mmkv.decodeString(AmapManager.ADDRESS_KEY, "未知");
String longitude = mCacheHelper.getAsString(AmapManager.LONGITUDE_KEY);
String latitude = mCacheHelper.getAsString(AmapManager.LATITUDE_KEY);
String address = mCacheHelper.getAsString(AmapManager.ADDRESS_KEY);
NetInterfaceManager.getInstance()
.getSOSRecordObservable(longitude, latitude, address)
.subscribe(new Observer<BaseResponse>() {
@@ -164,7 +164,9 @@ public class EmergencyActivity extends AppCompatActivity {
Log.e(TAG, "onResume: ");
Log.e(TAG, "onResume: " + phoneListSet);
if (needDial) {
if (phoneListSet == null || phoneListSet.size() == 0) return;
if (phoneListSet == null || phoneListSet.size() == 0) {
return;
}
Handler.getMain().postDelayed(new Runnable() {
@Override
public void run() {

View File

@@ -2,6 +2,7 @@ package com.uiuios.aios.manager;
import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import com.baidu.location.BDAbstractLocationListener;
@@ -11,6 +12,7 @@ import com.baidu.location.LocationClientOption;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.tencent.mmkv.MMKV;
import com.uiuios.aios.disklrucache.CacheHelper;
import com.uiuios.aios.utils.GsonUtils;
import java.lang.reflect.Type;
@@ -24,7 +26,7 @@ public class AmapManager {
private LocationClient mLocationClient = null;
private LocationClientOption mOption;
private BDLocation mLocation;
private MMKV mMMKV = MMKV.defaultMMKV();
private CacheHelper mCacheHelper;
private static final String AMAPLOCATION_JSON_KEY = "MAPLOCATION_JSON_STRING";
public static final String LONGITUDE_KEY = "map_longitude_key";
@@ -34,6 +36,7 @@ public class AmapManager {
private AmapManager(Context context) {
this.mContext = context;
this.mCacheHelper = new CacheHelper(context);
initAmap();
}
@@ -71,7 +74,10 @@ public class AmapManager {
public BDLocation getNowMapLocation() {
if (mLocation == null) {
String aMapLocationjson = mMMKV.decodeString(AMAPLOCATION_JSON_KEY, "");
String aMapLocationjson = mCacheHelper.getAsString(AMAPLOCATION_JSON_KEY);
if (TextUtils.isEmpty(aMapLocationjson)) {
return null;
}
Type type = new TypeToken<BDLocation>() {
}.getType();
try {
@@ -141,27 +147,27 @@ public class AmapManager {
case BDLocation.TypeGpsLocation:// GPS定位结果
case BDLocation.TypeNetWorkLocation:// 网络定位结果
case BDLocation.TypeOffLineLocation:// 离线定位结果
mMMKV.encode(AMAPLOCATION_JSON_KEY, GsonUtils.toJsonString(location));
mCacheHelper.put(AMAPLOCATION_JSON_KEY, GsonUtils.toJsonString(location));
Log.e(TAG, "onLocationChanged: " + "定位成功");
Log.e(TAG, "onLocationChanged: longitude = " + location.getLongitude());
Log.e(TAG, "onLocationChanged: latitude = " + location.getLatitude());
Log.e(TAG, "onLocationChanged: " + location.getAddrStr() + location.getLocationDescribe());
mMMKV.encode(ADDRESS_KEY, location.getAddrStr() + location.getLocationDescribe());
mMMKV.encode(LONGITUDE_KEY, location.getLongitude());
mMMKV.encode(LATITUDE_KEY, location.getLatitude());
mMMKV.encode(ERROR_KEY, "-");
mCacheHelper.put(ADDRESS_KEY, location.getAddrStr() + location.getLocationDescribe());
mCacheHelper.put(LONGITUDE_KEY, location.getLongitude());
mCacheHelper.put(LATITUDE_KEY, location.getLatitude());
mCacheHelper.put(ERROR_KEY, "-");
break;
case BDLocation.TypeServerError:
Log.e(TAG, "onReceiveLocation: " + "服务端网络定位失败");
mMMKV.encode(ERROR_KEY, "服务端网络定位失败可以反馈IMEI号和大体定位时间到loc-bugs@baidu.com会有人追查原因");
mCacheHelper.put(ERROR_KEY, "服务端网络定位失败可以反馈IMEI号和大体定位时间到loc-bugs@baidu.com会有人追查原因");
break;
case BDLocation.TypeNetWorkException:
Log.e(TAG, "onReceiveLocation: " + "网络不同导致定位失败,请检查网络是否通畅");
mMMKV.encode(ERROR_KEY, "网络不同导致定位失败,请检查网络是否通畅");
mCacheHelper.put(ERROR_KEY, "网络不同导致定位失败,请检查网络是否通畅");
break;
case BDLocation.TypeCriteriaException:
Log.e(TAG, "onReceiveLocation: " + "无法获取有效定位依据导致定位失败");
mMMKV.encode(ERROR_KEY, "无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
mCacheHelper.put(ERROR_KEY, "无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
break;
default:
}
@@ -273,8 +279,8 @@ public class AmapManager {
//// logMsg(sb.toString(), tag);
// Log.e(TAG, "onReceiveLocation: " + sb);
// }
Log.e(TAG, "AmapAddress: " + mMMKV.decodeString(ADDRESS_KEY, "-"));
Log.e(TAG, "AmapError: " + mMMKV.decodeString(ERROR_KEY, "-"));
Log.e(TAG, "AmapAddress: " + mCacheHelper.getAsString(ADDRESS_KEY));
Log.e(TAG, "AmapError: " + mCacheHelper.getAsString(ERROR_KEY));
}
@Override
@@ -331,7 +337,7 @@ public class AmapManager {
}
}
Log.e(TAG, "onLocationChanged: " + "定位失败");
mMMKV.encode(ERROR_KEY, sb.toString());
mCacheHelper.put(ERROR_KEY, sb.toString());
Log.e(TAG, "onLocDiagnosticMessage: " + sb);
// logMsg(sb.toString(), tag);
}