Android 11.0 修复Camera 使用闪光灯拍照后,查看图片时详细信息为“未使用闪光灯”状态

packages/apps/Camera2 / src/com/android/camera/ButtonManager.java

    // wangrui Get AppController as a global object, we need it in SettingsManager
++    public static  AppController appController;

 /**
     * Get a new global ButtonManager.
     */
    public ButtonManager(AppController app) {
    
    
        mAppController = app;
        // wangrui Get AppController as a global object, we need it in SettingsManager
++        appController = mAppController;

        Context context = app.getAndroidContext();
        sGcamIndex = context.getResources().getInteger(R.integer.camera_mode_gcam);

        mSettingsManager = app.getSettingsManager();
        mSettingsManager.addListener(this);
    }

packages/apps/Camera2 / src/com/android/camera/CameraActivity.java

    // wangrui Get whether the current camera is front or back, 0-back shot 1-front shot
    public static int mCameraId = 0;
    // wangrui Get the global context, we will use it in ExifUtil
    public static Context myContext;

 @Override
    public String getCameraScope() {
    
    
        CameraId cameraId =  mCameraController.getCurrentCameraId();
        //wangrui Get whether the current camera is front or back, 0-back shot 1-front shot
++        try {
    
    
++            mCameraId = Integer.parseInt(cameraId.getValue());
++        }catch (Exception e){
    
    
++            e.printStackTrace();
++        }

        if(cameraId == null) {
    
    
            Log.e(TAG,  "Retrieving Camera Setting Scope with -1");
            return SettingsManager.getCameraSettingScope("-1");
        }

        return SettingsManager.getCameraSettingScope(cameraId.getValue());
    }

packages/apps/Camera2 / src/com/android/camera/settings/SettingsManager.java

++ import com.android.camera.ButtonManager;
++ import static android.content.Context.MODE_PRIVATE;

private OnSharedPreferenceChangeListener getSharedPreferenceListener(
            final OnSettingChangedListener listener) {
    
    
        return new OnSharedPreferenceChangeListener() {
    
    
            @Override
            public void onSharedPreferenceChanged(
                    SharedPreferences sharedPreferences, String key) {
    
    
                // wangrui Get the flash status and store the value in the database
++                if (ButtonManager.appController!= null){
    
    
++                    if (key.equals(Keys.KEY_FLASH_MODE)){
    
    
++                        int index = SettingsManager.this.getIndexOfCurrentValue(ButtonManager.appController.getCameraScope(),
                                Keys.KEY_FLASH_MODE);
++                        SharedPreferences.Editor editor = mContext.getSharedPreferences("camera_flash_state",MODE_PRIVATE).edit();
++                        editor.putInt("state",index);
++                       editor.apply();
++                    }
++                }
                listener.onSettingChanged(SettingsManager.this, key);
            }
        };
    }

packages/apps/Camera2 / src/com/android/camera/util/ExifUtil.java

++ import android.content.SharedPreferences;
++ import com.android.camera.CameraActivity;
++ import static android.content.Context.MODE_PRIVATE;

  private void addCaptureResultToExif(CaptureResultProxy result) {
    
    
  
++        // wangrui If the camera is switched to the front, then the flash must not be turned on
++        if (CameraActivity.mCameraId==1){
    
    
++            addExifTag(ExifInterface.TAG_FLASH, ExifInterface.Flash.DID_NOT_FIRE);
++        }else{
    
      // wangrui Retrieve flash status from database Close-0, open-1, open-2
++            SharedPreferences pref = CameraActivity.myContext.getSharedPreferences("camera_flash_state",MODE_PRIVATE);
++            int index = pref.getInt("state",1);
++            switch (index){
    
    
++                case 0:
 ++                   addExifTag(ExifInterface.TAG_FLASH, ExifInterface.Flash.DID_NOT_FIRE);break;
++              case 1:
++                case 2:
++                    addExifTag(ExifInterface.TAG_FLASH, ExifInterface.Flash.FIRED);break;
++            }
++        }

//        // Flash mode
//        Integer flashMode = result.get(CaptureResult.FLASH_MODE);
//        if (flashMode == CaptureResult.FLASH_MODE_OFF) {
    
    
//            addExifTag(ExifInterface.TAG_FLASH, ExifInterface.Flash.DID_NOT_FIRE);
//        } else {
    
    
//            addExifTag(ExifInterface.TAG_FLASH, ExifInterface.Flash.FIRED);
//        }

我是王睿丶,加入我的Q群:901440630,欢迎一起讨论安卓技术!

猜你喜欢

转载自blog.csdn.net/qq_27494201/article/details/124998400