version:1.2
fix: update:快捷控制中心报错修复,完善闪光灯
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user