Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a1837d2 authored by Kiran Kumar H N's avatar Kiran Kumar H N Committed by Steve Kondik
Browse files

Gallery2: camera: Invoke camera UI functions only after initialization.

When switching from Panorama mode to Camera mode, the CameraActivity
invokes two functions openModule and onOrientationChanged.
openModule initializes PhotoModule. As part of the PhotoModule
initialization, the PhotoUI and PhotoMenu are initialized.
But this is acheived by posting a message to the handler. When the
message is read by the Handler, the PhotoUI's onCameraOpen is invoked
which initializes the PhotoMenu. But sometimes before this message
is read by the Handler, the onOrientationChanged is invoked, which
invokes couple of functions from PhotoUI class acting on the PhotoMenu.
But since the PhotoMenu is still not initialized, it throws up error in
the form of NullPointerExceptions.
Fix this by checking if the PhotoUI and PhotoMenu have been initialized.
If they have not yet been initialized, send a message to the Handler to
invoke these PhotoUI functionalities after the PhotoUI has been
initialized completely.

CRs-Fixed: 519055
Change-Id: I06ea54aa56da96459db6cacea92b02d0f8c23bcd
parent 41bdd69d
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ public class PhotoModule
    private static final int OPEN_CAMERA_FAIL = 11;
    private static final int CAMERA_DISABLED = 12;
    private static final int CAPTURE_ANIMATION_DONE = 13;
    private static final int SET_PHOTO_UI_PARAMS = 15;

    // The subset of parameters we need to update in setCameraParameters().
    private static final int UPDATE_PARAM_INITIALIZE = 1;
@@ -411,6 +412,13 @@ public class PhotoModule
                    mUI.enablePreviewThumb(false);
                    break;
                }
                case SET_PHOTO_UI_PARAMS: {
                    setCameraParametersWhenIdle(UPDATE_PARAM_PREFERENCE);
                    resizeForPreviewAspectRatio();
                    mUI.updateOnScreenIndicators(mParameters, mPreferenceGroup,
                        mPreferences);
                    break;
                }
            }
        }
    }
@@ -2100,10 +2108,19 @@ public class PhotoModule
            mActivity.updateStorageSpaceAndHint();
            mActivity.reuseCameraScreenNail(!mIsImageCaptureIntent);
        }

        /* Check if the PhotoUI Menu is initialized or not. This
         * should be initialized during onCameraOpen() which should
         * have been called by now. But for some reason that is not
         * executed till now, then schedule these functionality for
         * later by posting a message to the handler */
        if (mUI.mMenuInitialized) {
            setCameraParametersWhenIdle(UPDATE_PARAM_PREFERENCE);
            resizeForPreviewAspectRatio();
        mUI.updateOnScreenIndicators(mParameters, mPreferenceGroup, mPreferences);
            mUI.updateOnScreenIndicators(mParameters, mPreferenceGroup,
                mPreferences);
        } else {
            mHandler.sendEmptyMessage(SET_PHOTO_UI_PARAMS);
        }
    }

    @Override
+4 −1
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ public class PhotoUI implements PieListener,
    private int mPreviewWidth = 0;
    private int mPreviewHeight = 0;
    private View mPreviewThumb;
    public boolean mMenuInitialized = false;

    private OnLayoutChangeListener mLayoutListener = new OnLayoutChangeListener() {
        @Override
@@ -162,6 +163,7 @@ public class PhotoUI implements PieListener,
            mMenu.setListener(listener);
        }
        mMenu.initialize(prefGroup);
        mMenuInitialized = true;

        if (mZoomRenderer == null) {
            mZoomRenderer = new ZoomRenderer(mActivity);
@@ -305,12 +307,13 @@ public class PhotoUI implements PieListener,
    public void hideGpsOnScreenIndicator() { }

    public void overrideSettings(final String ... keyvalues) {
        if (mMenu == null) return;
        mMenu.overrideSettings(keyvalues);
    }

    public void updateOnScreenIndicators(Camera.Parameters params,
            PreferenceGroup group, ComboPreferences prefs) {
        if (params == null) return;
        if (params == null || group == null) return;
        mOnScreenIndicators.updateSceneOnScreenIndicator(params.getSceneMode());
        mOnScreenIndicators.updateExposureOnScreenIndicator(params,
                CameraSettings.readExposure(prefs));