From 4d7c623876baa82b54c3de041d1165ee929a03d1 Mon Sep 17 00:00:00 2001 From: tongtongstudio Date: Fri, 4 Nov 2022 22:56:05 +0800 Subject: [PATCH] =?UTF-8?q?version:1.2=20fix:=20update:=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E4=B8=AD=E5=BF=83=E6=8A=A5=E9=94=99=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=EF=BC=8C=E5=AE=8C=E5=96=84=E9=97=AA=E5=85=89=E7=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 3 +- .../uiuios/aios/activity/ControlActivity.java | 58 ++++++++++++------- .../aios/activity/EmergencyActivity.java | 10 ++-- .../com/uiuios/aios/manager/AmapManager.java | 32 +++++----- 4 files changed, 63 insertions(+), 40 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index df6e876..64a78f7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,7 +17,8 @@ - + + diff --git a/app/src/main/java/com/uiuios/aios/activity/ControlActivity.java b/app/src/main/java/com/uiuios/aios/activity/ControlActivity.java index 2da0f53..0caa9d2 100644 --- a/app/src/main/java/com/uiuios/aios/activity/ControlActivity.java +++ b/app/src/main/java/com/uiuios/aios/activity/ControlActivity.java @@ -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 mEntries = Arrays.asList(getResources().getStringArray(R.array.entries_font_size)); List 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) { diff --git a/app/src/main/java/com/uiuios/aios/activity/EmergencyActivity.java b/app/src/main/java/com/uiuios/aios/activity/EmergencyActivity.java index 7ffce97..f89baf5 100644 --- a/app/src/main/java/com/uiuios/aios/activity/EmergencyActivity.java +++ b/app/src/main/java/com/uiuios/aios/activity/EmergencyActivity.java @@ -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() { @@ -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() { diff --git a/app/src/main/java/com/uiuios/aios/manager/AmapManager.java b/app/src/main/java/com/uiuios/aios/manager/AmapManager.java index 87f6c28..4383657 100644 --- a/app/src/main/java/com/uiuios/aios/manager/AmapManager.java +++ b/app/src/main/java/com/uiuios/aios/manager/AmapManager.java @@ -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() { }.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); }