diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-01-22 00:13:42 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-01-22 00:13:42 -0800 |
commit | f1e484acb594a726fb57ad0ae4cfe902c7f35858 (patch) | |
tree | 99d2b34512f0dc2ae67666e756c1cfcd331e5fe3 /core/java/android/widget | |
parent | 22f7dfd23490a3de2f21ff96949ba47003aac8f8 (diff) | |
download | frameworks_base-f1e484acb594a726fb57ad0ae4cfe902c7f35858.zip frameworks_base-f1e484acb594a726fb57ad0ae4cfe902c7f35858.tar.gz frameworks_base-f1e484acb594a726fb57ad0ae4cfe902c7f35858.tar.bz2 |
auto import from //branches/cupcake/...@127436
Diffstat (limited to 'core/java/android/widget')
-rw-r--r-- | core/java/android/widget/Button.java | 2 | ||||
-rw-r--r-- | core/java/android/widget/ImageButton.java | 2 | ||||
-rw-r--r-- | core/java/android/widget/RemoteViews.java | 66 | ||||
-rw-r--r-- | core/java/android/widget/TextView.java | 40 |
4 files changed, 107 insertions, 3 deletions
diff --git a/core/java/android/widget/Button.java b/core/java/android/widget/Button.java index f2868af..5e692d4 100644 --- a/core/java/android/widget/Button.java +++ b/core/java/android/widget/Button.java @@ -21,6 +21,7 @@ import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; import android.view.KeyEvent; +import android.widget.RemoteViews.RemoteView; /** @@ -54,6 +55,7 @@ import android.view.KeyEvent; * {@link android.R.styleable#View View Attributes} * </p> */ +@RemoteView public class Button extends TextView { public Button(Context context) { this(context, null); diff --git a/core/java/android/widget/ImageButton.java b/core/java/android/widget/ImageButton.java index 5c56428..4c1cbf6 100644 --- a/core/java/android/widget/ImageButton.java +++ b/core/java/android/widget/ImageButton.java @@ -21,6 +21,7 @@ import android.os.Handler; import android.os.Message; import android.util.AttributeSet; import android.view.MotionEvent; +import android.widget.RemoteViews.RemoteView; import java.util.Map; @@ -36,6 +37,7 @@ import java.util.Map; * {@link android.R.styleable#View View Attributes} * </p> */ +@RemoteView public class ImageButton extends ImageView { public ImageButton(Context context) { this(context, null); diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index 54951b7..5721095 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -16,6 +16,8 @@ package android.widget; +import android.app.PendingIntent; +import android.app.PendingIntent.CanceledException; import android.content.Context; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; @@ -31,6 +33,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.LayoutInflater.Filter; +import android.view.View.OnClickListener; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -371,6 +374,52 @@ public class RemoteViews implements Parcelable, Filter { public final static int TAG = 6; } + + /** + * Equivalent to calling + * {@link android.view.View#setOnClickListener(android.view.View.OnClickListener)} + * to launch the provided {@link PendingIntent}. + */ + private class SetOnClickPendingIntent extends Action { + public SetOnClickPendingIntent(int id, PendingIntent pendingIntent) { + this.viewId = id; + this.pendingIntent = pendingIntent; + } + + public SetOnClickPendingIntent(Parcel parcel) { + viewId = parcel.readInt(); + pendingIntent = PendingIntent.readPendingIntentOrNullFromParcel(parcel); + } + + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(TAG); + dest.writeInt(viewId); + pendingIntent.writeToParcel(dest, 0 /* no flags */); + } + + @Override + public void apply(View root) { + final View target = root.findViewById(viewId); + if (target != null && pendingIntent != null) { + OnClickListener listener = new OnClickListener() { + public void onClick(View v) { + try { + // TODO: Unregister this handler if PendingIntent.FLAG_ONE_SHOT? + pendingIntent.send(); + } catch (CanceledException e) { + throw new ActionException(e.toString()); + } + } + }; + target.setOnClickListener(listener); + } + } + + int viewId; + PendingIntent pendingIntent; + + public final static int TAG = 7; + } /** * Create a new RemoteViews object that will display the views contained @@ -419,6 +468,9 @@ public class RemoteViews implements Parcelable, Filter { case SetProgressBar.TAG: mActions.add(new SetProgressBar(parcel)); break; + case SetOnClickPendingIntent.TAG: + mActions.add(new SetOnClickPendingIntent(parcel)); + break; default: throw new ActionException("Tag " + tag + "not found"); } @@ -491,8 +543,6 @@ public class RemoteViews implements Parcelable, Filter { * * @param viewId The id of the view whose drawable should change * @param bitmap The new Bitmap for the drawable - * - * @hide pending API Council approval to extend the public API */ public void setImageViewBitmap(int viewId, Bitmap bitmap) { addAction(new SetImageViewBitmap(viewId, bitmap)); @@ -533,6 +583,18 @@ public class RemoteViews implements Parcelable, Filter { } /** + * Equivalent to calling + * {@link android.view.View#setOnClickListener(android.view.View.OnClickListener)} + * to launch the provided {@link PendingIntent}. + * + * @param viewId The id of the view that will trigger the {@link PendingIntent} when clicked + * @param pendingIntent The {@link PendingIntent} to send when user clicks + */ + public void setOnClickPendingIntent(int viewId, PendingIntent pendingIntent) { + addAction(new SetOnClickPendingIntent(viewId, pendingIntent)); + } + + /** * Inflates the view hierarchy represented by this object and applies * all of the actions. * diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 8baed7d..aa70663 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -235,6 +235,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener float[] mTmpOffset = new float[2]; ExtractedTextRequest mExtracting; final ExtractedText mTmpExtracted = new ExtractedText(); + boolean mBatchEditing; } InputMethodState mInputMethodState; @@ -3505,7 +3506,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener */ InputMethodManager imm = InputMethodManager.peekInstance(); - if (highlight != null && mInputMethodState != null && imm != null) { + if (highlight != null && mInputMethodState != null + && !mInputMethodState.mBatchEditing && imm != null) { if (imm.isActive(this)) { int candStart = -1; int candEnd = -1; @@ -3865,6 +3867,38 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** + * Called by the framework in response to a request to begin a batch + * of edit operations from the current input method, as a result of + * it calling {@link InputConnection#beginBatchEdit + * InputConnection.beginBatchEdit()}. The default implementation sets + * up the TextView's internal state to take care of this; if overriding + * you should call through to the super class. + */ + public void onBeginBatchEdit() { + if (mInputMethodState != null) { + // XXX we should be smarter here, such as not doing invalidates + // until all edits are done. + mInputMethodState.mBatchEditing = true; + } + } + + /** + * Called by the framework in response to a request to end a batch + * of edit operations from the current input method, as a result of + * it calling {@link InputConnection#endBatchEdit + * InputConnection.endBatchEdit()}. The default implementation sets + * up the TextView's internal state to take care of this; if overriding + * you should call through to the super class. + */ + public void onEndBatchEdit() { + if (mInputMethodState != null) { + mInputMethodState.mBatchEditing = false; + // Cheezy way to get us to report the current cursor location. + invalidateCursor(); + } + } + + /** * Called by the framework in response to a private command from the * current method, provided by it calling * {@link InputConnection#performPrivateCommand @@ -5271,6 +5305,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (mError != null) { hideError(); } + // Don't leave us in the middle of a batch edit. + onEndBatchEdit(); } startStopMarquee(focused); @@ -5300,6 +5336,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (mBlink != null) { mBlink.cancel(); } + // Don't leave us in the middle of a batch edit. + onEndBatchEdit(); } startStopMarquee(hasWindowFocus); |