how to implement tween animation with AppWidget using RemoteViews?

by shleeforandroid » Thu, 30 Apr 2009 17:17:52 GMT

Sponsored Links
 i, guys

I'm testing AppWidget to play animation on the homescreen.

This is my testing source using Service and RemoteViews.

I confirmed the modification of the image of layout's ImageView.

I thought it possible to implement the animation using RemoteViews or
AppWidgetHostView ...
But I failed. I didn't see any change of the image.

How to adapt the animation to RemoteViews?

I tried like this.

Some Imports
import android.appwidget.AppWidgetHostView;

public class TestAnimationWidget extends AppWidgetProvider {

public void onReceive(Context context, Intent intent) {

// TODO Auto-generated method stub
String action = intent.getAction();
Bundle extras = intent.getExtras();
if (extras != null) {
int[] appWidgetIds = extras.getIntArray
if (appWidgetIds != null && appWidgetIds.length > 0) {
this.onUpdate(context, AppWidgetManager.getInstance(context),
else if(AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)){
Bundle extras = intent.getExtras();
if (extras != null) {
int[] appWidgetIds = extras.getIntArray
if (appWidgetIds != null && appWidgetIds.length > 0) {
this.onDeleted(context, appWidgetIds);
else if(AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)){
else if(AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)){

public void onUpdate(Context context, AppWidgetManager
appWidgetManager, int[ ] appWidgetIds) {
// TODO Auto-generated method stub
context.startService(new Intent
super.onUpdate(context, appWidgetManager, appWidgetIds);

public static class UpdateServiceAnimation extends Service {
private SensingMovement mSensingMove;
private AppWidgetManager mAppWidgetManager;
public AppWidgetProviderInfo mAWPInfo;
private AppWidgetHost mAppWidgetHost;
private List<AppWidgetHostView> mAppWidgetHostViewList;
public static int HOSTID = 0;
static public int count = 0;

int[] mAnim_img_IDs = new int[]{
R.drawable.gallery_photo_1, R.drawable.gallery_photo_2,
R.drawable.gallery_photo_3, R.drawable.gallery_photo_4

public void onCreate() {
mSensingMove = new SensingMovement(this);
mAppWidgetHost = new AppWidgetHost(this,HOSTID);
mAppWidgetManager = AppWidgetManager.getInstance(this);
mAppWidgetHostViewList = new ArrayList<AppWidgetHostView>();
int[ ] appWidgetIds = mAppWidgetManager.getAppWidgetIds(new

for(int i = 0 ; i < appWidgetIds.length ; i++){
mAWPInfo =
appWidgetIds[i], mAWPInfo));

// TODO Auto-generated method stub

Other Threads

1. startActivityForResult/onActivityResult question

Hello all,
I'm new to Android development, and am a bit confused here.  I'm
hoping someone can help me out.  I hope I've got the correct list.
Anyway, I've got a very simple Activity, one EditText and one Button.
Lets call it MyActivity.  Now, when I click on the button on
MyActivity, I want to take a picture using the camera.  For the sake
of this e-mail, lets call the activity that gets spawned when I click
on the button CameraActivity.

Here is how I've setup my button:

                Button takePictureButton = (Button)
                takePictureButton.setOnClickListener(new View.OnClickListener() 
                        public void onClick(View v) {
                                ContentValues values = new ContentValues();
                                values.put(Media.TITLE, "IMAGE");
                                values.put(Media.DESCRIPTION, "Image Captured 
by Camera");
                                Uri uri = 
getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
                                Intent i = new 
                                i.putExtra("output", uri);
As I understand it, click the button will cause MyActivity to start up
CameraActivity, which is just the default camera application, to take
a picture.  Because I've used startActivityForResult, when
CameraActivity finishes, MyActivity should be notified via it's
onActivityResult.  Below is how I've coded it up:

I've defined my onActivityResult as follows:

        protected void onActivityResult(int requestCode, int resultCode, Intent 
data) {
                super.onActivityResult(requestCode, resultCode, data);
                switch (requestCode) {
                        case (ACTIVITY_TAKE_PICTURE_WITH_INTENT):
                                Log.d(TAG, "WOW!");

So, what has me confused is this:  I would expect onActivityResult to
be called AFTER I take a picture, i.e. when I click on the picture
button.  Instead, it seems to get called immediately:  I click on the
takeAPictureButton, the camera activity starts up at about the same
time the code in onActivityResult gets fired.  Am I missing something



2. Puzzled by soft keyboard


I have a regular EditText that nicely pops up the soft keyboard when
the hardware keyboard is closed. Entering data also works fine and
gets preserved by my app. However, when I try to track individual key
presses using the following code,

   EditText myedit;

   // Only gets number keys??
   myedit.setOnKeyListener(new EditText.OnKeyListener() {
      public boolean onKey(View v, int keyCode, KeyEvent event) {
         Log.i("OIC","keycode "+keyCode);
         KeyCharacterMap kmap = KeyCharacterMap.load(event.getDeviceId
         if (kmap.isPrintingKey(keyCode) && event.getAction() ==
            // Blah, blah
         return false;

no key presses show up in LogCat *except* for number key presses
(0-9). No letters, punctuation, or anything other than numeric digits
and a few special keys such as Del and Return. Is this a bug or a
feature? In this particular case I am only interested in individual
alphabetic key presses, but the listener fails to report them. What's

I'm using the official Android 1.5 on my ADP.



3. Android 1.5 and cupcake 1.5

4. how to register keypressed button?

5. How can I clone a View and its children

6. AppWidgets: Reusing RemoteViews instance leaks memory?

7. Log in to an application?