Merge change 25212 into eclair
* changes:
revert to black video background, since we don't need the color-key anylonger
diff --git a/api/current.xml b/api/current.xml
index 6121c43..6174bff 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -10659,6 +10659,17 @@
visibility="public"
>
</field>
+<field name="screen_background_light_transparent"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="17301674"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="spinner_background"
type="int"
transient="false"
@@ -12714,6 +12725,17 @@
visibility="public"
>
</field>
+<field name="Theme_Light_WallpaperSettings"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16973922"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="Theme_NoDisplay"
type="int"
transient="false"
@@ -12802,6 +12824,17 @@
visibility="public"
>
</field>
+<field name="Theme_WallpaperSettings"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16973921"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="Theme_Wallpaper_NoTitleBar"
type="int"
transient="false"
@@ -117496,6 +117529,37 @@
</implements>
</interface>
</package>
+<package name="android.service.wallpaper"
+>
+<class name="WallpaperSettingsActivity"
+ extends="android.preference.PreferenceActivity"
+ abstract="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<constructor name="WallpaperSettingsActivity"
+ type="android.service.wallpaper.WallpaperSettingsActivity"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</constructor>
+<field name="EXTRA_PREVIEW_MODE"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value=""android.service.wallpaper.PREVIEW_MODE""
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+</class>
+</package>
<package name="android.speech"
>
<class name="RecognizerIntent"
diff --git a/core/java/android/service/wallpaper/WallpaperSettingsActivity.java b/core/java/android/service/wallpaper/WallpaperSettingsActivity.java
new file mode 100644
index 0000000..501947da
--- /dev/null
+++ b/core/java/android/service/wallpaper/WallpaperSettingsActivity.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package android.service.wallpaper;
+
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+
+/**
+ * Base class for activities that will be used to configure the settings of
+ * a wallpaper. You should derive from this class to allow it to select the
+ * proper theme of the activity depending on how it is being used.
+ */
+public class WallpaperSettingsActivity extends PreferenceActivity {
+ /**
+ * This boolean extra in the launch intent indicates that the settings
+ * are being used while the wallpaper is in preview mode.
+ */
+ final public static String EXTRA_PREVIEW_MODE
+ = "android.service.wallpaper.PREVIEW_MODE";
+
+ @Override
+ protected void onCreate(Bundle icicle) {
+ if (false) {
+ Resources.Theme theme = getTheme();
+ if (getIntent().getBooleanExtra(EXTRA_PREVIEW_MODE, false)) {
+ theme.applyStyle(com.android.internal.R.style.PreviewWallpaperSettings, true);
+ } else {
+ theme.applyStyle(com.android.internal.R.style.ActiveWallpaperSettings, true);
+ }
+ }
+ super.onCreate(icicle);
+ }
+}
diff --git a/core/java/android/widget/ZoomButtonsController.java b/core/java/android/widget/ZoomButtonsController.java
index 760b8ff..e55fbb8 100644
--- a/core/java/android/widget/ZoomButtonsController.java
+++ b/core/java/android/widget/ZoomButtonsController.java
@@ -249,7 +249,7 @@
lp.height = LayoutParams.WRAP_CONTENT;
lp.width = LayoutParams.FILL_PARENT;
lp.type = LayoutParams.TYPE_APPLICATION_PANEL;
- lp.format = PixelFormat.TRANSPARENT;
+ lp.format = PixelFormat.TRANSLUCENT;
lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons;
mContainerLayoutParams = lp;
diff --git a/core/java/com/android/internal/widget/RotarySelector.java b/core/java/com/android/internal/widget/RotarySelector.java
new file mode 100644
index 0000000..7b940c9
--- /dev/null
+++ b/core/java/com/android/internal/widget/RotarySelector.java
@@ -0,0 +1,542 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.widget;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Color;
+import android.graphics.drawable.Drawable;
+import android.os.Vibrator;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.animation.AccelerateInterpolator;
+
+import com.android.internal.R;
+
+
+/**
+ * Custom view that presents up to two items that are selectable by rotating a semi-circle from
+ * left to right, or right to left. Used by incoming call screen, and the lock screen when no
+ * security pattern is set.
+ */
+public class RotarySelector extends View {
+ private static final String LOG_TAG = "RotarySelector";
+ private static final boolean DBG = false;
+
+ // Listener for onDialTrigger() callbacks.
+ private OnDialTriggerListener mOnDialTriggerListener;
+
+ private float mDensity;
+
+ // UI elements
+ private Drawable mBackground;
+ private Drawable mDimple;
+
+ private Drawable mLeftHandleIcon;
+ private Drawable mRightHandleIcon;
+
+ private Drawable mArrowShortLeftAndRight;
+ private Drawable mArrowLongLeft; // Long arrow starting on the left, pointing clockwise
+ private Drawable mArrowLongRight; // Long arrow starting on the right, pointing CCW
+
+ // positions of the left and right handle
+ private int mLeftHandleX;
+ private int mRightHandleX;
+
+ // current offset of user's dragging
+ private int mTouchDragOffset = 0;
+
+ // state of the animation used to bring the handle back to its start position when
+ // the user lets go before triggering an action
+ private boolean mAnimating = false;
+ private long mAnimationEndTime;
+ private int mAnimatingDelta;
+ AccelerateInterpolator mInterpolator;
+
+ /**
+ * True after triggering an action if the user of {@link OnDialTriggerListener} wants to
+ * freeze the UI (until they transition to another screen).
+ */
+ private boolean mFrozen = false;
+
+ /**
+ * If the user is currently dragging something.
+ */
+ private int mGrabbedState = NOTHING_GRABBED;
+ private static final int NOTHING_GRABBED = 0;
+ private static final int LEFT_HANDLE_GRABBED = 1;
+ private static final int RIGHT_HANDLE_GRABBED = 2;
+
+ /**
+ * Whether the user has triggered something (e.g dragging the left handle all the way over to
+ * the right).
+ */
+ private boolean mTriggered = false;
+
+ // Vibration (haptic feedback)
+ private Vibrator mVibrator;
+ private static final long VIBRATE_SHORT = 60; // msec
+ private static final long VIBRATE_LONG = 100; // msec
+
+ // Various tweakable layout or behavior parameters:
+
+ // How close to the edge of the screen, we let the handle get before
+ // triggering an action:
+ private static final int EDGE_THRESHOLD_DIP = 70;
+
+ /**
+ * The drawable for the arrows need to be scrunched this many dips towards the rotary bg below
+ * it.
+ */
+ private static final int ARROW_SCRUNCH_DIP = 6;
+
+ /**
+ * How far inset the left and right circles should be
+ */
+ private static final int EDGE_PADDING_DIP = 9;
+
+ /**
+ * Dimensions of arc in background drawable.
+ */
+ static final int OUTER_ROTARY_RADIUS_DIP = 390;
+ static final int ROTARY_STROKE_WIDTH_DIP = 83;
+ private static final int ANIMATION_DURATION_MILLIS = 300;
+
+ private static final boolean DRAW_CENTER_DIMPLE = false;
+
+ /**
+ * Constructor used when this widget is created from a layout file.
+ */
+ public RotarySelector(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ if (DBG) log("IncomingCallDialWidget constructor...");
+
+ Resources r = getResources();
+ mDensity = r.getDisplayMetrics().density;
+ if (DBG) log("- Density: " + mDensity);
+ // Density is 1.0 on HVGA (like Dream), and 1.5 on WVGA.
+ // Usage: raw_pixel_value = (int) (dpi_value * mDensity + 0.5f)
+
+ // Assets (all are BitmapDrawables).
+ mBackground = r.getDrawable(R.drawable.jog_dial_bg_cropped);
+ mDimple = r.getDrawable(R.drawable.jog_dial_dimple);
+
+ mArrowLongLeft = r.getDrawable(R.drawable.jog_dial_arrow_long_left_green);
+ mArrowLongRight = r.getDrawable(R.drawable.jog_dial_arrow_long_right_red);
+ mArrowShortLeftAndRight = r.getDrawable(R.drawable.jog_dial_arrow_short_left_and_right);
+
+ mInterpolator = new AccelerateInterpolator();
+ }
+
+ /**
+ * Sets the left handle icon to a given resource.
+ *
+ * The resource should refer to a Drawable object, or use 0 to remove
+ * the icon.
+ *
+ * @param resId the resource ID.
+ */
+ public void setLeftHandleResource(int resId) {
+ Drawable d = null;
+ if (resId != 0) {
+ d = getResources().getDrawable(resId);
+ }
+ setLeftHandleDrawable(d);
+ }
+
+ /**
+ * Sets the left handle icon to a given Drawable.
+ *
+ * @param d the Drawable to use as the icon, or null to remove the icon.
+ */
+ public void setLeftHandleDrawable(Drawable d) {
+ mLeftHandleIcon = d;
+ invalidate();
+ }
+
+ /**
+ * Sets the right handle icon to a given resource.
+ *
+ * The resource should refer to a Drawable object, or use 0 to remove
+ * the icon.
+ *
+ * @param resId the resource ID.
+ */
+ public void setRightHandleResource(int resId) {
+ Drawable d = null;
+ if (resId != 0) {
+ d = getResources().getDrawable(resId);
+ }
+ setRightHandleDrawable(d);
+ }
+
+ /**
+ * Sets the right handle icon to a given Drawable.
+ *
+ * @param d the Drawable to use as the icon, or null to remove the icon.
+ */
+ public void setRightHandleDrawable(Drawable d) {
+ mRightHandleIcon = d;
+ invalidate();
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ final int width = MeasureSpec.getSize(widthMeasureSpec); // screen width
+
+ final int arrowH = mArrowShortLeftAndRight.getIntrinsicHeight();
+ final int backgroundH = mBackground.getIntrinsicHeight();
+
+ // by making the height less than arrow + bg, arrow and bg will be scrunched together,
+ // overlaying somewhat (though on transparent portions of the drawable).
+ // this works because the arrows are drawn from the top, and the rotary bg is drawn
+ // from the bottom.
+ final int arrowScrunch = (int) (ARROW_SCRUNCH_DIP * mDensity);
+ setMeasuredDimension(width, backgroundH + arrowH - arrowScrunch);
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+
+ mLeftHandleX = (int) (EDGE_PADDING_DIP * mDensity) + mDimple.getIntrinsicWidth() / 2;
+ mRightHandleX =
+ getWidth() - (int) (EDGE_PADDING_DIP * mDensity) - mDimple.getIntrinsicWidth() / 2;
+ }
+
+// private Paint mPaint = new Paint();
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ if (DBG) {
+ log(String.format("onDraw: mAnimating=%s, mTouchDragOffset=%d, mGrabbedState=%d," +
+ "mFrozen=%s",
+ mAnimating, mTouchDragOffset, mGrabbedState, mFrozen));
+ }
+
+ final int height = getHeight();
+
+ // update animating state before we draw anything
+ if (mAnimating && !mFrozen) {
+ long millisLeft = mAnimationEndTime - System.currentTimeMillis();
+ if (DBG) log("millisleft for animating: " + millisLeft);
+ if (millisLeft <= 0) {
+ reset();
+ } else {
+ float interpolation = mInterpolator.getInterpolation(
+ (float) millisLeft / ANIMATION_DURATION_MILLIS);
+ mTouchDragOffset = (int) (mAnimatingDelta * interpolation);
+ }
+ }
+
+
+ // Background:
+ final int backgroundW = mBackground.getIntrinsicWidth();
+ final int backgroundH = mBackground.getIntrinsicHeight();
+ final int backgroundY = height - backgroundH;
+ if (DBG) log("- Background INTRINSIC: " + backgroundW + " x " + backgroundH);
+ mBackground.setBounds(0, backgroundY,
+ backgroundW, backgroundY + backgroundH);
+ if (DBG) log(" Background BOUNDS: " + mBackground.getBounds());
+ mBackground.draw(canvas);
+
+ // Arrows:
+ // All arrow assets are the same size (they're the full width of
+ // the screen) regardless of which arrows are actually visible.
+ int arrowW = mArrowShortLeftAndRight.getIntrinsicWidth();
+ int arrowH = mArrowShortLeftAndRight.getIntrinsicHeight();
+
+ // Draw the correct arrow(s) depending on the current state:
+ Drawable currentArrow;
+ switch (mGrabbedState) {
+ case NOTHING_GRABBED:
+ currentArrow = mArrowShortLeftAndRight;
+ break;
+ case LEFT_HANDLE_GRABBED:
+ currentArrow = mArrowLongLeft;
+ break;
+ case RIGHT_HANDLE_GRABBED:
+ currentArrow = mArrowLongRight;
+ break;
+ default:
+ throw new IllegalStateException("invalid mGrabbedState: " + mGrabbedState);
+ }
+ currentArrow.setBounds(0, 0, arrowW, arrowH);
+ currentArrow.draw(canvas);
+
+ // debug: draw circle that should match the outer arc (good sanity check)
+// mPaint.setColor(Color.RED);
+// mPaint.setStyle(Paint.Style.STROKE);
+// float or = OUTER_ROTARY_RADIUS_DIP * mDensity;
+// canvas.drawCircle(getWidth() / 2, or + mBackground.getBounds().top, or, mPaint);
+
+ final int outerRadius = (int) (mDensity * OUTER_ROTARY_RADIUS_DIP);
+ final int innerRadius =
+ (int) ((OUTER_ROTARY_RADIUS_DIP - ROTARY_STROKE_WIDTH_DIP) * mDensity);
+ final int bgTop = mBackground.getBounds().top;
+ {
+ final int xOffset = mLeftHandleX + mTouchDragOffset;
+ final int drawableY = getYOnArc(
+ mBackground,
+ innerRadius,
+ outerRadius,
+ xOffset);
+
+ drawCentered(mDimple, canvas, xOffset, drawableY + bgTop);
+ drawCentered(mLeftHandleIcon, canvas, xOffset, drawableY + bgTop);
+ }
+
+ if (DRAW_CENTER_DIMPLE) {
+ final int xOffset = getWidth() / 2 + mTouchDragOffset;
+ final int drawableY = getYOnArc(
+ mBackground,
+ innerRadius,
+ outerRadius,
+ xOffset);
+
+ drawCentered(mDimple, canvas, xOffset, drawableY + bgTop);
+ }
+
+ {
+ final int xOffset = mRightHandleX + mTouchDragOffset;
+ final int drawableY = getYOnArc(
+ mBackground,
+ innerRadius,
+ outerRadius,
+ xOffset);
+
+ drawCentered(mDimple, canvas, xOffset, drawableY + bgTop);
+ drawCentered(mRightHandleIcon, canvas, xOffset, drawableY + bgTop);
+ }
+
+ if (mAnimating) invalidate();
+ }
+
+ /**
+ * Assuming drawable is a bounding box around a piece of an arc drawn by two concentric circles
+ * (as the background drawable for the rotary widget is), and given an x coordinate along the
+ * drawable, return the y coordinate of a point on the arc that is between the two concentric
+ * circles. The resulting y combined with the incoming x is a point along the circle in
+ * between the two concentric circles.
+ *
+ * @param drawable The drawable.
+ * @param innerRadius The radius of the circle that intersects the drawable at the bottom two
+ * corders of the drawable (top two corners in terms of drawing coordinates).
+ * @param outerRadius The radius of the circle who's top most point is the top center of the
+ * drawable (bottom center in terms of drawing coordinates).
+ * @param x The distance along the x axis of the desired point.
+ * @return The y coordinate, in drawing coordinates, that will place (x, y) along the circle
+ * in between the two concentric circles.
+ */
+ private int getYOnArc(Drawable drawable, int innerRadius, int outerRadius, int x) {
+
+ // the hypotenuse
+ final int halfWidth = (outerRadius - innerRadius) / 2;
+ final int middleRadius = innerRadius + halfWidth;
+
+ // the bottom leg of the triangle
+ final int triangleBottom = (drawable.getIntrinsicWidth() / 2) - x;
+
+ // "Our offense is like the pythagorean theorem: There is no answer!" - Shaquille O'Neal
+ final int triangleY =
+ (int) Math.sqrt(middleRadius * middleRadius - triangleBottom * triangleBottom);
+
+ // convert to drawing coordinates:
+ // middleRadius - triangleY =
+ // the vertical distance from the outer edge of the circle to the desired point
+ // from there we add the distance from the top of the drawable to the middle circle
+ return middleRadius - triangleY + halfWidth;
+ }
+
+ /**
+ * Handle touch screen events.
+ *
+ * @param event The motion event.
+ * @return True if the event was handled, false otherwise.
+ */
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ if (mAnimating || mFrozen) {
+ return true;
+ }
+
+ final int eventX = (int) event.getX();
+ final int hitWindow = mDimple.getIntrinsicWidth();
+
+ if (event.getAction() == MotionEvent.ACTION_DOWN) {
+ if (DBG) log("touch-down");
+ mTriggered = false;
+ if (mGrabbedState != RotarySelector.NOTHING_GRABBED) {
+ reset();
+ invalidate();
+ }
+ if (eventX < mLeftHandleX + hitWindow) {
+ mTouchDragOffset = eventX - mLeftHandleX;
+ mGrabbedState = RotarySelector.LEFT_HANDLE_GRABBED;
+ invalidate();
+ vibrate(VIBRATE_SHORT);
+ } else if (eventX > mRightHandleX - hitWindow) {
+ mTouchDragOffset = eventX - mRightHandleX;
+ mGrabbedState = RotarySelector.RIGHT_HANDLE_GRABBED;
+ invalidate();
+ vibrate(VIBRATE_SHORT);
+ }
+ } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
+ if (DBG) log("touch-move");
+ if (mGrabbedState == RotarySelector.LEFT_HANDLE_GRABBED) {
+ mTouchDragOffset = eventX - mLeftHandleX;
+ invalidate();
+ if (eventX >= mRightHandleX - EDGE_PADDING_DIP && !mTriggered) {
+ mTriggered = true;
+ mFrozen = dispatchTriggerEvent(OnDialTriggerListener.LEFT_HANDLE);
+ }
+ } else if (mGrabbedState == RotarySelector.RIGHT_HANDLE_GRABBED) {
+ mTouchDragOffset = eventX - mRightHandleX;
+ invalidate();
+ if (eventX <= mLeftHandleX + EDGE_PADDING_DIP && !mTriggered) {
+ mTriggered = true;
+ mFrozen = dispatchTriggerEvent(OnDialTriggerListener.RIGHT_HANDLE);
+ }
+ }
+ } else if ((event.getAction() == MotionEvent.ACTION_UP)) {
+ if (DBG) log("touch-up");
+ // handle animating back to start if they didn't trigger
+ if (mGrabbedState == RotarySelector.LEFT_HANDLE_GRABBED
+ && Math.abs(eventX - mLeftHandleX) > 5) {
+ mAnimating = true;
+ mAnimationEndTime = System.currentTimeMillis() + ANIMATION_DURATION_MILLIS;
+ mAnimatingDelta = eventX - mLeftHandleX;
+ } else if (mGrabbedState == RotarySelector.RIGHT_HANDLE_GRABBED
+ && Math.abs(eventX - mRightHandleX) > 5) {
+ mAnimating = true;
+ mAnimationEndTime = System.currentTimeMillis() + ANIMATION_DURATION_MILLIS;
+ mAnimatingDelta = eventX - mRightHandleX;
+ }
+
+ mTouchDragOffset = 0;
+ mGrabbedState = RotarySelector.NOTHING_GRABBED;
+ invalidate();
+ } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
+ if (DBG) log("touch-cancel");
+ reset();
+ invalidate();
+ }
+ return true;
+ }
+
+ private void reset() {
+ mAnimating = false;
+ mTouchDragOffset = 0;
+ mGrabbedState = RotarySelector.NOTHING_GRABBED;
+ mTriggered = false;
+ }
+
+ /**
+ * Triggers haptic feedback.
+ */
+ private synchronized void vibrate(long duration) {
+ if (mVibrator == null) {
+ mVibrator = (android.os.Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
+ }
+ mVibrator.vibrate(duration);
+ }
+
+ /**
+ * Sets the bounds of the specified Drawable so that it's centered
+ * on the point (x,y), then draws it onto the specified canvas.
+ * TODO: is there already a utility method somewhere for this?
+ */
+ private static void drawCentered(Drawable d, Canvas c, int x, int y) {
+ int w = d.getIntrinsicWidth();
+ int h = d.getIntrinsicHeight();
+
+ // if (DBG) log("--> drawCentered: " + x + " , " + y + "; intrinsic " + w + " x " + h);
+ d.setBounds(x - (w / 2), y - (h / 2),
+ x + (w / 2), y + (h / 2));
+ d.draw(c);
+ }
+
+
+ /**
+ * Registers a callback to be invoked when the dial
+ * is "triggered" by rotating it one way or the other.
+ *
+ * @param l the OnDialTriggerListener to attach to this view
+ */
+ public void setOnDialTriggerListener(OnDialTriggerListener l) {
+ mOnDialTriggerListener = l;
+ }
+
+ /**
+ * Dispatches a trigger event to our listener.
+ */
+ private boolean dispatchTriggerEvent(int whichHandle) {
+ vibrate(VIBRATE_LONG);
+ if (mOnDialTriggerListener != null) {
+ return mOnDialTriggerListener.onDialTrigger(this, whichHandle);
+ }
+ return false;
+ }
+
+ /**
+ * Interface definition for a callback to be invoked when the dial
+ * is "triggered" by rotating it one way or the other.
+ */
+ public interface OnDialTriggerListener {
+ /**
+ * The dial was triggered because the user grabbed the left handle,
+ * and rotated the dial clockwise.
+ */
+ public static final int LEFT_HANDLE = 1;
+
+ /**
+ * The dial was triggered because the user grabbed the right handle,
+ * and rotated the dial counterclockwise.
+ */
+ public static final int RIGHT_HANDLE = 2;
+
+ /**
+ * @hide
+ * The center handle is currently unused.
+ */
+ public static final int CENTER_HANDLE = 3;
+
+ /**
+ * Called when the dial is triggered.
+ *
+ * @param v The view that was triggered
+ * @param whichHandle Which "dial handle" the user grabbed,
+ * either {@link #LEFT_HANDLE}, {@link #RIGHT_HANDLE}, or
+ * {@link #CENTER_HANDLE}.
+ * @return Whether the widget should freeze (e.g when the action goes to another screen,
+ * you want the UI to stay put until the transition occurs).
+ */
+ boolean onDialTrigger(View v, int whichHandle);
+ }
+
+
+ // Debugging / testing code
+
+ private void log(String msg) {
+ Log.d(LOG_TAG, msg);
+ }
+}
diff --git a/core/res/res/drawable/ic_jog_dial_answer.png b/core/res/res/drawable/ic_jog_dial_answer.png
new file mode 100644
index 0000000..e2bc483
--- /dev/null
+++ b/core/res/res/drawable/ic_jog_dial_answer.png
Binary files differ
diff --git a/core/res/res/drawable/ic_jog_dial_decline.png b/core/res/res/drawable/ic_jog_dial_decline.png
new file mode 100644
index 0000000..81c76b5
--- /dev/null
+++ b/core/res/res/drawable/ic_jog_dial_decline.png
Binary files differ
diff --git a/core/res/res/drawable/ic_jog_dial_silence_ringer.png b/core/res/res/drawable/ic_jog_dial_silence_ringer.png
new file mode 100644
index 0000000..6d573e6
--- /dev/null
+++ b/core/res/res/drawable/ic_jog_dial_silence_ringer.png
Binary files differ
diff --git a/core/res/res/drawable/ic_jog_dial_turn_ring_vol_off.png b/core/res/res/drawable/ic_jog_dial_turn_ring_vol_off.png
new file mode 100644
index 0000000..3804c25
--- /dev/null
+++ b/core/res/res/drawable/ic_jog_dial_turn_ring_vol_off.png
Binary files differ
diff --git a/core/res/res/drawable/ic_jog_dial_turn_ring_vol_on.png b/core/res/res/drawable/ic_jog_dial_turn_ring_vol_on.png
new file mode 100644
index 0000000..62f8e15
--- /dev/null
+++ b/core/res/res/drawable/ic_jog_dial_turn_ring_vol_on.png
Binary files differ
diff --git a/core/res/res/drawable/ic_jog_dial_unlock.png b/core/res/res/drawable/ic_jog_dial_unlock.png
new file mode 100644
index 0000000..e697d91
--- /dev/null
+++ b/core/res/res/drawable/ic_jog_dial_unlock.png
Binary files differ
diff --git a/core/res/res/drawable/jog_dial_arrow_long_left_green.png b/core/res/res/drawable/jog_dial_arrow_long_left_green.png
new file mode 100644
index 0000000..334a8e0
--- /dev/null
+++ b/core/res/res/drawable/jog_dial_arrow_long_left_green.png
Binary files differ
diff --git a/core/res/res/drawable/jog_dial_arrow_long_left_yellow.png b/core/res/res/drawable/jog_dial_arrow_long_left_yellow.png
new file mode 100644
index 0000000..2e011ca3
--- /dev/null
+++ b/core/res/res/drawable/jog_dial_arrow_long_left_yellow.png
Binary files differ
diff --git a/core/res/res/drawable/jog_dial_arrow_long_middle_yellow.png b/core/res/res/drawable/jog_dial_arrow_long_middle_yellow.png
new file mode 100644
index 0000000..323745e
--- /dev/null
+++ b/core/res/res/drawable/jog_dial_arrow_long_middle_yellow.png
Binary files differ
diff --git a/core/res/res/drawable/jog_dial_arrow_long_right_red.png b/core/res/res/drawable/jog_dial_arrow_long_right_red.png
new file mode 100644
index 0000000..1e97c9a
--- /dev/null
+++ b/core/res/res/drawable/jog_dial_arrow_long_right_red.png
Binary files differ
diff --git a/core/res/res/drawable/jog_dial_arrow_long_right_yellow.png b/core/res/res/drawable/jog_dial_arrow_long_right_yellow.png
new file mode 100644
index 0000000..3536e58
--- /dev/null
+++ b/core/res/res/drawable/jog_dial_arrow_long_right_yellow.png
Binary files differ
diff --git a/core/res/res/drawable/jog_dial_arrow_short_left.png b/core/res/res/drawable/jog_dial_arrow_short_left.png
new file mode 100644
index 0000000..4a4ab3ae
--- /dev/null
+++ b/core/res/res/drawable/jog_dial_arrow_short_left.png
Binary files differ
diff --git a/core/res/res/drawable/jog_dial_arrow_short_left_and_right.png b/core/res/res/drawable/jog_dial_arrow_short_left_and_right.png
new file mode 100644
index 0000000..987cfa7
--- /dev/null
+++ b/core/res/res/drawable/jog_dial_arrow_short_left_and_right.png
Binary files differ
diff --git a/core/res/res/drawable/jog_dial_arrow_short_right.png b/core/res/res/drawable/jog_dial_arrow_short_right.png
new file mode 100644
index 0000000..ee79875
--- /dev/null
+++ b/core/res/res/drawable/jog_dial_arrow_short_right.png
Binary files differ
diff --git a/core/res/res/drawable/jog_dial_bg_cropped.png b/core/res/res/drawable/jog_dial_bg_cropped.png
new file mode 100644
index 0000000..60d93d2
--- /dev/null
+++ b/core/res/res/drawable/jog_dial_bg_cropped.png
Binary files differ
diff --git a/core/res/res/drawable/jog_dial_dimple.png b/core/res/res/drawable/jog_dial_dimple.png
new file mode 100644
index 0000000..85d3a43
--- /dev/null
+++ b/core/res/res/drawable/jog_dial_dimple.png
Binary files differ
diff --git a/core/res/res/layout/keyguard_screen_rotary_unlock.xml b/core/res/res/layout/keyguard_screen_rotary_unlock.xml
new file mode 100644
index 0000000..cf97d04
--- /dev/null
+++ b/core/res/res/layout/keyguard_screen_rotary_unlock.xml
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 2009, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License")
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<!-- This is the general lock screen which shows information about the
+ state of the device, as well as instructions on how to get past it
+ depending on the state of the device. It is the same for landscape
+ and portrait.-->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:id="@+id/root"
+ >
+
+<RelativeLayout
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:background="#A0000000"
+ >
+
+ <TextView
+ android:id="@+id/carrier"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="20dip"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textColor="?android:attr/textColorSecondary"
+ />
+
+ <TextView
+ android:id="@+id/time"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/carrier"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="25dip"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:textSize="55sp"
+ />
+
+ <TextView
+ android:id="@+id/date"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/time"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="-12dip"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ />
+
+ <View
+ android:id="@+id/divider"
+ android:layout_width="fill_parent"
+ android:layout_height="1dip"
+ android:layout_marginTop="10dip"
+ android:layout_below="@id/date"
+ android:background="@android:drawable/divider_horizontal_dark"
+ />
+
+ <TextView
+ android:id="@+id/status1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/divider"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="6dip"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textColor="?android:attr/textColorSecondary"
+ />
+
+ <TextView
+ android:id="@+id/status2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/status1"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="6dip"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textColor="?android:attr/textColorSecondary"
+ />
+
+ <TextView
+ android:id="@+id/screenLocked"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/status2"
+ android:layout_centerHorizontal="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textColor="?android:attr/textColorSecondary"
+ android:gravity="center"
+ android:layout_marginTop="12dip"
+ />
+
+ <!-- By having the rotary selector hang below "screen locked" text, we get a layout more
+ robust for different screen sizes. On wvga, the widget should be flush with the bottom.-->
+ <com.android.internal.widget.RotarySelector
+ android:id="@+id/rotary"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/screenLocked"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="24dip"
+ />
+
+ <!-- emergency call button shown when sim is missing or PUKd -->
+ <Button
+ android:id="@+id/emergencyCallButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/screenLocked"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="24dip"
+ android:drawableLeft="@drawable/ic_emergency"
+ android:drawablePadding="8dip"
+ />
+
+</RelativeLayout>
+
+</FrameLayout>
\ No newline at end of file
diff --git a/core/res/res/values/colors.xml b/core/res/res/values/colors.xml
index 560796a..62a230c 100644
--- a/core/res/res/values/colors.xml
+++ b/core/res/res/values/colors.xml
@@ -24,7 +24,14 @@
<drawable name="status_bar_opened_default_background">#ff000000</drawable>
<drawable name="search_bar_default_color">#ff000000</drawable>
<drawable name="safe_mode_background">#60000000</drawable>
+ <!-- Background drawable that can be used for a transparent activity to
+ be able to display a dark UI: this darkens its background to make
+ a dark (default theme) UI more visible. -->
<drawable name="screen_background_dark_transparent">#80000000</drawable>
+ <!-- Background drawable that can be used for a transparent activity to
+ be able to display a light UI: this lightens its background to make
+ a light UI more visible. -->
+ <drawable name="screen_background_light_transparent">#80ffffff</drawable>
<color name="safe_mode_text">#80ffffff</color>
<color name="white">#ffffffff</color>
<color name="black">#ff000000</color>
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index c4636f3..2bc2a0f 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1168,10 +1168,13 @@
<public type="style" name="Theme.Wallpaper" />
<public type="style" name="Theme.Wallpaper.NoTitleBar" />
<public type="style" name="Theme.Wallpaper.NoTitleBar.Fullscreen" />
+ <public type="style" name="Theme.WallpaperSettings" />
+ <public type="style" name="Theme.Light.WallpaperSettings" />
<!-- Semi-transparent background that can be used when placing a dark
themed UI on top of some arbitrary background (such as the
wallpaper). This darkens the background sufficiently that the UI
can be seen. -->
<public type="drawable" name="screen_background_dark_transparent" />
+ <public type="drawable" name="screen_background_light_transparent" />
</resources>
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index fae612c..69612e9 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -458,7 +458,6 @@
<style name="Widget.ListView.White" parent="Widget.AbsListView">
<item name="android:listSelector">@android:drawable/list_selector_background</item>
- <item name="android:background">@android:color/white</item>
<item name="android:divider">@android:drawable/divider_horizontal_bright_opaque</item>
</style>
diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml
index 4f76c56..1aa48ee 100644
--- a/core/res/res/values/themes.xml
+++ b/core/res/res/values/themes.xml
@@ -303,6 +303,32 @@
<item name="android:windowContentOverlay">@null</item>
</style>
+ <!-- Theme for a wallpaper's setting activity that is designed to be on
+ top of a dark background. -->
+ <style name="Theme.WallpaperSettings">
+ <item name="android:windowBackground">@android:drawable/screen_background_dark_transparent</item>
+ <item name="android:windowIsTranslucent">true</item>
+ <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
+ </style>
+
+ <!-- Theme for a wallpaper's setting activity that is designed to be on
+ top of a light background. -->
+ <style name="Theme.Light.WallpaperSettings">
+ <item name="android:windowBackground">@android:drawable/screen_background_light_transparent</item>
+ <item name="android:windowIsTranslucent">true</item>
+ <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
+ </style>
+
+ <!-- Style to apply on top of a wallpaper settings theme when it is being
+ shown on top of the real wallpaper -->
+ <style name="ActiveWallpaperSettings">
+ </style>
+
+ <!-- Style to apply on top of a wallpaper settings theme when it is being
+ shown on top of the real wallpaper -->
+ <style name="PreviewWallpaperSettings">
+ </style>
+
<!-- Default theme for translucent activities, that is windows that allow you
to see through them to the windows behind. This sets up the translucent
flag and appropriate animations for your windows. -->
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index 8e85a6a..bd2c3ed 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -1244,12 +1244,6 @@
"Skipping hidden or animating token: " + w);
continue;
}
- // If this window's app token is ot fullscreen, also irrelevant.
- if (!w.mAppToken.appFullscreen) {
- if (DEBUG_WALLPAPER) Log.v(TAG,
- "Skipping non-fullscreen token: " + w);
- continue;
- }
}
if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w + ": readyfordisplay="
+ w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
diff --git a/telephony/java/com/android/internal/telephony/CallerInfo.java b/telephony/java/com/android/internal/telephony/CallerInfo.java
index e1bd1db..c8490e9 100644
--- a/telephony/java/com/android/internal/telephony/CallerInfo.java
+++ b/telephony/java/com/android/internal/telephony/CallerInfo.java
@@ -100,10 +100,14 @@
public Drawable cachedPhoto;
public boolean isCachedPhotoCurrent;
+ private boolean mIsEmergency;
+
// Don't keep checking VM if it's going to throw an exception for this proc.
private static boolean sSkipVmCheck = false;
public CallerInfo() {
+ // TODO: Move all the basic initialization here?
+ mIsEmergency = false;
}
/**
@@ -221,13 +225,7 @@
// or if it is the voicemail number. If it is either, take a
// shortcut and skip the query.
if (PhoneNumberUtils.isEmergencyNumber(number)) {
- CallerInfo ci = new CallerInfo();
-
- // Note we're setting the phone number here (refer to javadoc
- // comments at the top of CallerInfo class).
- ci.phoneNumber = context.getString(
- com.android.internal.R.string.emergency_call_dialog_number_for_display);
- return ci;
+ return new CallerInfo().markAsEmergency(context);
} else {
try {
if (!sSkipVmCheck && PhoneNumberUtils.compare(number,
@@ -296,6 +294,35 @@
return callerID;
}
+ // Accessors
+
+ /**
+ * @return true if the caller info is an emergency number.
+ */
+ public boolean isEmergencyNumber() {
+ return mIsEmergency;
+ }
+
+ /**
+ * Mark this CallerInfo as an emergency call.
+ * @param context To lookup the localized 'Emergency Number' string.
+ * @return this instance.
+ */
+ // TODO: Note we're setting the phone number here (refer to
+ // javadoc comments at the top of CallerInfo class) to a localized
+ // string 'Emergency Number'. This is pretty bad because we are
+ // making UI work here instead of just packaging the data. We
+ // should set the phone number to the dialed number and name to
+ // 'Emergency Number' and let the UI make the decision about what
+ // should be displayed.
+ /* package */ CallerInfo markAsEmergency(Context context) {
+ phoneNumber = context.getString(
+ com.android.internal.R.string.emergency_call_dialog_number_for_display);
+ photoResource = com.android.internal.R.drawable.picture_emergency;
+ mIsEmergency = true;
+ return this;
+ }
+
private static String normalize(String s) {
if (s == null || s.length() > 0) {
return s;
diff --git a/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java b/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java
index 3d4f78c..4227a84 100644
--- a/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java
+++ b/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java
@@ -37,7 +37,7 @@
public class CallerInfoAsyncQuery {
private static final boolean DBG = false;
- private static final String LOG_TAG = "PHONE";
+ private static final String LOG_TAG = "CallerInfoAsyncQuery";
private static final int EVENT_NEW_QUERY = 1;
private static final int EVENT_ADD_LISTENER = 2;
@@ -223,13 +223,9 @@
// voicemail number, and adjust other data (including photoResource)
// accordingly.
if (cw.event == EVENT_EMERGENCY_NUMBER) {
- mCallerInfo = new CallerInfo();
// Note we're setting the phone number here (refer to javadoc
// comments at the top of CallerInfo class).
- mCallerInfo.phoneNumber = mQueryContext.getString(com.android.internal
- .R.string.emergency_call_dialog_number_for_display);
- mCallerInfo.photoResource = com.android.internal.R.drawable.picture_emergency;
-
+ mCallerInfo = new CallerInfo().markAsEmergency(mQueryContext);
} else if (cw.event == EVENT_VOICEMAIL_NUMBER) {
mCallerInfo = new CallerInfo();
try {
@@ -390,4 +386,3 @@
Log.d(LOG_TAG, msg);
}
}
-
diff --git a/telephony/tests/TelephonyTest/Android.mk b/telephony/tests/TelephonyTest/Android.mk
new file mode 100644
index 0000000..1ef8448
--- /dev/null
+++ b/telephony/tests/TelephonyTest/Android.mk
@@ -0,0 +1,12 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_PACKAGE_NAME := telephonytest
+
+include $(BUILD_PACKAGE)
diff --git a/telephony/tests/TelephonyTest/AndroidManifest.xml b/telephony/tests/TelephonyTest/AndroidManifest.xml
new file mode 100644
index 0000000..c0cc0d5
--- /dev/null
+++ b/telephony/tests/TelephonyTest/AndroidManifest.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.telephonytest">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ <activity android:label="TelephonyTest"
+ android:name="TelephonyTest">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ </application>
+ <instrumentation android:name=".TelephonyUnitTestRunner"
+ android:targetPackage="com.android.telephonytest"
+ android:label="Telephony unit tests InstrumentationRunner">
+ </instrumentation>
+</manifest>
diff --git a/telephony/tests/TelephonyTest/src/com/android/telephonytest/TelephonyUnitTestRunner.java b/telephony/tests/TelephonyTest/src/com/android/telephonytest/TelephonyUnitTestRunner.java
new file mode 100644
index 0000000..5da940d
--- /dev/null
+++ b/telephony/tests/TelephonyTest/src/com/android/telephonytest/TelephonyUnitTestRunner.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.telephonytest;
+
+import junit.framework.TestSuite;
+
+import android.test.InstrumentationTestRunner;
+import android.test.InstrumentationTestSuite;
+
+/**
+ * Instrumentation Test Runner for all Telephony unit tests.
+ *
+ * Running all tests:
+ *
+ * runtest telephony-unit
+ * or
+ * adb shell am instrument -w com.android.telephonytest/.TelephonyUnitTestRunner
+ */
+
+public class TelephonyUnitTestRunner extends InstrumentationTestRunner {
+
+ @Override
+ public TestSuite getAllTests() {
+ TestSuite suite = new InstrumentationTestSuite(this);
+ suite.addTestSuite(com.android.telephonytest.unit.CallerInfoUnitTest.class);
+ return suite;
+ }
+
+ @Override
+ public ClassLoader getLoader() {
+ return TelephonyUnitTestRunner.class.getClassLoader();
+ }
+}
diff --git a/telephony/tests/TelephonyTest/src/com/android/telephonytest/unit/CallerInfoUnitTest.java b/telephony/tests/TelephonyTest/src/com/android/telephonytest/unit/CallerInfoUnitTest.java
new file mode 100644
index 0000000..4cd0266
--- /dev/null
+++ b/telephony/tests/TelephonyTest/src/com/android/telephonytest/unit/CallerInfoUnitTest.java
@@ -0,0 +1,230 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.telephonytest.unit;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.res.Resources;
+import com.android.internal.telephony.CallerInfo;
+import com.android.internal.telephony.CallerInfoAsyncQuery;
+import android.util.Log;
+import android.os.Looper;
+import android.test.ActivityInstrumentationTestCase;
+import android.util.StringBuilderPrinter;
+
+/*
+ * Check the CallerInfo utility class works as expected.
+ *
+ */
+
+public class CallerInfoUnitTest extends AndroidTestCase {
+ private CallerInfo mInfo;
+ private Context mContext;
+
+ private static final String kEmergencyNumber = "Emergency Number";
+ private static final int kToken = 0xdeadbeef;
+ private static final String TAG = "CallerInfoUnitTest";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mContext = new MockContext();
+ mInfo = new CallerInfo();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Checks the caller info instance is flagged as an emergency if
+ * the number is an emergency one. There is no test for the
+ * contact based constructors because emergency number are not in
+ * the contact DB.
+ */
+ @SmallTest
+ public void testEmergencyIsProperlySet() throws Exception {
+ assertFalse(mInfo.isEmergencyNumber());
+
+ mInfo = CallerInfo.getCallerInfo(mContext, "911");
+ assertIsValidEmergencyCallerInfo();
+
+ mInfo = CallerInfo.getCallerInfo(mContext, "tel:911");
+ assertIsValidEmergencyCallerInfo();
+
+
+ // This one hits the content resolver.
+ mInfo = CallerInfo.getCallerInfo(mContext, "18001234567");
+ assertFalse(mInfo.isEmergencyNumber());
+ }
+
+ /**
+ * Same as testEmergencyIsProperlySet but uses the async query api.
+ */
+ @SmallTest
+ public void testEmergencyIsProperlySetUsingAsyncQuery() throws Exception {
+ QueryRunner query;
+
+ query = new QueryRunner("911");
+ query.runAndCheckCompletion();
+ assertIsValidEmergencyCallerInfo();
+
+ query = new QueryRunner("tel:911");
+ query.runAndCheckCompletion();
+ assertIsValidEmergencyCallerInfo();
+
+ query = new QueryRunner("18001234567");
+ query.runAndCheckCompletion();
+ assertFalse(mInfo.isEmergencyNumber());
+ }
+
+ /**
+ * For emergency caller info, phoneNumber should be set to the
+ * string emergency_call_dialog_number_for_display and the
+ * photoResource should be set to the picture_emergency drawable.
+ */
+ @SmallTest
+ public void testEmergencyNumberAndPhotoAreSet() throws Exception {
+ mInfo = CallerInfo.getCallerInfo(mContext, "911");
+
+ assertIsValidEmergencyCallerInfo();
+ }
+
+ //
+ // Helpers
+ //
+
+ // Partial implementation of MockResources.
+ public class MockResources extends android.test.mock.MockResources
+ {
+ @Override
+ public String getString(int resId) throws Resources.NotFoundException {
+ switch (resId) {
+ case com.android.internal.R.string.emergency_call_dialog_number_for_display:
+ return kEmergencyNumber;
+ default:
+ throw new UnsupportedOperationException("Missing handling for resid " + resId);
+ }
+ }
+ }
+
+ // Partial implementation of MockContext.
+ public class MockContext extends android.test.mock.MockContext {
+ private ContentResolver mResolver;
+ private Resources mResources;
+
+ public MockContext() {
+ mResolver = new android.test.mock.MockContentResolver();
+ mResources = new MockResources();
+ }
+
+ @Override
+ public ContentResolver getContentResolver() {
+ return mResolver;
+ }
+
+ @Override
+ public Resources getResources() {
+ return mResources;
+ }
+ }
+
+ /**
+ * Class to run a CallerInfoAsyncQuery in a separate thread, with
+ * its own Looper. We cannot use the main Looper because on the
+ * 1st quit the thread is maked dead, ie no further test can use
+ * it. Also there is not way to inject a Looper instance in the
+ * query, so we have to use a thread with its own looper.
+ */
+ private class QueryRunner extends Thread
+ implements CallerInfoAsyncQuery.OnQueryCompleteListener {
+ private Looper mLooper;
+ private String mNumber;
+ private boolean mAsyncCompleted;
+
+ public QueryRunner(String number) {
+ super();
+ mNumber = number;
+ }
+
+ // Run the query in the thread, wait for completion.
+ public void runAndCheckCompletion() throws InterruptedException {
+ start();
+ join();
+ assertTrue(mAsyncCompleted);
+ }
+
+ @Override
+ public void run() {
+ Looper.prepare();
+ mLooper = Looper.myLooper();
+ mAsyncCompleted = false;
+ // The query will pick the thread local looper we've just prepared.
+ CallerInfoAsyncQuery.startQuery(kToken, mContext, mNumber, this, null);
+ mLooper.loop();
+ }
+
+ // Quit the Looper on the 1st callback
+ // (EVENT_EMERGENCY_NUMBER). There is another message
+ // (EVENT_END_OF_QUEUE) that will never be delivered because
+ // the test has exited. The corresponding stack trace
+ // "Handler{xxxxx} sending message to a Handler on a dead
+ // thread" can be ignored.
+ public void onQueryComplete(int token, Object cookie, CallerInfo info) {
+ mAsyncCompleted = true;
+ mInfo = info;
+ mLooper.quit();
+ }
+ }
+
+ /**
+ * Fail if mInfo does not contain a valid emergency CallerInfo instance.
+ */
+ private void assertIsValidEmergencyCallerInfo() throws Exception {
+ assertTrue(mInfo.isEmergencyNumber());
+
+ // For emergency caller info, phoneNumber should be set to the
+ // string emergency_call_dialog_number_for_display and the
+ // photoResource should be set to the picture_emergency drawable.
+ assertEquals(kEmergencyNumber, mInfo.phoneNumber);
+ assertEquals(com.android.internal.R.drawable.picture_emergency, mInfo.photoResource);
+
+ // The name should be null
+ assertNull(mInfo.name);
+ assertEquals(0, mInfo.namePresentation);
+ assertNull(mInfo.cnapName);
+ assertEquals(0, mInfo.numberPresentation);
+
+ assertFalse(mInfo.contactExists);
+ assertEquals(0, mInfo.person_id);
+ assertFalse(mInfo.needUpdate);
+ assertNull(mInfo.contactRefUri);
+
+ assertNull(mInfo.phoneLabel);
+ assertEquals(0, mInfo.numberType);
+ assertNull(mInfo.numberLabel);
+
+ assertNull(mInfo.contactRingtoneUri);
+ assertFalse(mInfo.shouldSendToVoicemail);
+
+ assertNull(mInfo.cachedPhoto);
+ assertFalse(mInfo.isCachedPhotoCurrent);
+ }
+}