Skip to content

Commit 47cde77

Browse files
author
John Spurlock
committed
Fix camera bugs found overnight.
- Fix crash in CameraWidgetFrame after rotating to landscape - Fix pages drift to the left bug - Address Jim's comments on c/245706 - Disable camera widget if landscape Bug: 7419070 Bug: 7417798 Bug: 7418781 Change-Id: I5c730c7c1baf3c1872367b6392e6786578765298
1 parent 6f35209 commit 47cde77

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

core/res/res/values-land/bools.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
-->
1616

1717
<resources>
18+
<bool name="kg_enable_camera_default_widget">false</bool>
1819
<bool name="kg_share_status_area">false</bool>
1920
<bool name="kg_sim_puk_account_full_screen">false</bool>
2021
</resources>

policy/src/com/android/internal/policy/impl/keyguard/CameraWidgetFrame.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import android.widget.ImageView.ScaleType;
3232

3333
import com.android.internal.policy.impl.keyguard.KeyguardActivityLauncher.CameraWidgetInfo;
34-
import com.android.internal.R;
3534

3635
public class CameraWidgetFrame extends KeyguardWidgetFrame {
3736
private static final String TAG = CameraWidgetFrame.class.getSimpleName();
@@ -49,10 +48,12 @@ interface Callbacks {
4948

5049
private View mWidgetView;
5150
private long mLaunchCameraStart;
51+
private boolean mRendered;
5252

5353
private final Runnable mLaunchCameraRunnable = new Runnable() {
5454
@Override
5555
public void run() {
56+
mLaunchCameraStart = SystemClock.uptimeMillis();
5657
mActivityLauncher.launchCamera();
5758
}};
5859

@@ -85,7 +86,9 @@ public static CameraWidgetFrame create(Context context, Callbacks callbacks,
8586
return null;
8687

8788
ImageView preview = new ImageView(context);
88-
preview.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
89+
preview.setLayoutParams(new FrameLayout.LayoutParams(
90+
FrameLayout.LayoutParams.MATCH_PARENT,
91+
FrameLayout.LayoutParams.MATCH_PARENT));
8992
preview.setScaleType(ScaleType.FIT_CENTER);
9093
CameraWidgetFrame cameraWidgetFrame = new CameraWidgetFrame(context, callbacks, launcher);
9194
cameraWidgetFrame.addView(preview);
@@ -123,15 +126,31 @@ private static View inflateGenericWidgetView(Context context) {
123126
}
124127

125128
public void render() {
126-
int width = getRootView().getWidth();
127-
int height = getRootView().getHeight();
128-
if (DEBUG) Log.d(TAG, String.format("render [%sx%s]", width, height));
129-
Bitmap offscreen = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
130-
Canvas c = new Canvas(offscreen);
131-
mWidgetView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
132-
mWidgetView.layout(0, 0, width, height);
133-
mWidgetView.draw(c);
134-
((ImageView)getChildAt(0)).setImageBitmap(offscreen);
129+
if (mRendered) return;
130+
131+
try {
132+
int width = getRootView().getWidth();
133+
int height = getRootView().getHeight();
134+
if (DEBUG) Log.d(TAG, String.format("render [%sx%s] %s",
135+
width, height, Integer.toHexString(hashCode())));
136+
if (width == 0 || height == 0) {
137+
return;
138+
}
139+
Bitmap offscreen = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
140+
Canvas c = new Canvas(offscreen);
141+
mWidgetView.measure(
142+
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
143+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
144+
mWidgetView.layout(0, 0, width, height);
145+
mWidgetView.draw(c);
146+
((ImageView)getChildAt(0)).setImageBitmap(offscreen);
147+
mRendered = true;
148+
} catch (Throwable t) {
149+
Log.w(TAG, "Error rendering camera widget", t);
150+
removeAllViews();
151+
View genericView = inflateGenericWidgetView(mContext);
152+
addView(genericView);
153+
}
135154
}
136155

137156
private void transitionToCamera() {
@@ -161,10 +180,10 @@ public void onWindowFocusChanged(boolean hasWindowFocus) {
161180
if (!hasWindowFocus) {
162181
if (mLaunchCameraStart > 0) {
163182
long launchTime = SystemClock.uptimeMillis() - mLaunchCameraStart;
164-
if (DEBUG) Log.d(TAG, String.format("Camera took %s to launch", launchTime));
183+
if (DEBUG) Log.d(TAG, String.format("Camera took %sms to launch", launchTime));
165184
mLaunchCameraStart = 0;
185+
onCameraLaunched();
166186
}
167-
onCameraLaunched();
168187
}
169188
}
170189

policy/src/com/android/internal/policy/impl/keyguard/KeyguardActivityLauncher.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public void launchCamera() {
102102
launchActivity(SECURE_CAMERA_INTENT, true);
103103
}
104104
} else {
105-
// wouldLaunchResolverActivity(new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA));
106105
// Launch the normal camera
107106
launchActivity(INSECURE_CAMERA_INTENT, false);
108107
}

policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,10 @@ public void onCameraLaunched() {
850850
if (slider != null) {
851851
slider.showHandle(true);
852852
}
853-
mAppWidgetContainer.scrollLeft();
853+
View v = mAppWidgetContainer.getChildAt(mAppWidgetContainer.getCurrentPage());
854+
if (v instanceof CameraWidgetFrame) {
855+
mAppWidgetContainer.scrollLeft();
856+
}
854857
}
855858

856859
private SlidingChallengeLayout locateSlider() {

0 commit comments

Comments
 (0)