Hi, 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 { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub String action = intent.getAction(); if(AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)){ Bundle extras = intent.getExtras(); if (extras != null) { int[] appWidgetIds = extras.getIntArray (AppWidgetManager.EXTRA_APPWIDGET_IDS); if (appWidgetIds != null && appWidgetIds.length > 0) { this.onUpdate(context, AppWidgetManager.getInstance(context), appWidgetIds); } } } else if(AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)){ Bundle extras = intent.getExtras(); if (extras != null) { int[] appWidgetIds = extras.getIntArray (AppWidgetManager.EXTRA_APPWIDGET_IDS); if (appWidgetIds != null && appWidgetIds.length > 0) { this.onDeleted(context, appWidgetIds); } } } else if(AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)){ this.onDisabled(context); } else if(AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)){ this.onEnabled(context); } } @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[ ] appWidgetIds) { // TODO Auto-generated method stub context.startService(new Intent (context,UpdateServiceAnimation.class)); 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 }; @Override 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 ComponentName(this,TestAnimationWidget.class)); for(int i = 0 ; i < appWidgetIds.length ; i++){ mAWPInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetIds[i]); mAppWidgetHostViewList.add(i, mAppWidgetHost.createView(this, appWidgetIds[i], mAWPInfo)); } // TODO Auto-generated method stub super.onCreate(); } @Override public void onStart(Intent intent, int startId) { // TODO Auto-generated method stub ComponentName thisWidget = new ComponentName(this, TestAnimationWidget.class); RemoteViews updateViews = buildUpdate (this,appWidgetIds.length); // Push update for this widget to the home screen mAppWidgetManager.updateAppWidget(thisWidget, updateViews); super.onStart(intent, startId); } private RemoteViews buildUpdate(Context context, int widgetcount) { // TODO Auto-generated method stub RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.animation); MyViewGroup parent = new MyViewGroup(context); AnimationSet animation = setAnimationSet(); LinearLayout ll = (LinearLayout)views.apply(context, parent); ll.findViewById(R.id.ImageView_animation).setAnimation(animation); views.reapply(context, ll); // When user clicks on widget, Intent defineIntent = new Intent(Intent.ACTION_VIEW); PendingIntent pendingIntent = PendingIntent.getActivity(context,0 /* no requestCode */, defineIntent, 0 /* no flags */); views.setOnClickPendingIntent(R.id.layout_animation, pendingIntent); return views; } public AnimationSet setAnimationSet(){ AnimationSet mTestAnim = new AnimationSet(true); // fromDegrees , toDegrees, pivotX, pivotY defined RotateAnimation rotate = new RotateAnimation(0,360, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(1000); rotate.setFillAfter(true); // fromXscale , toXscale, fromYscale, toYscale, pivotX, pivotY defined ScaleAnimation scale = new ScaleAnimation(1,0, 1,0, ScaleAnimation.RELATIVE_TO_SELF, 1.0f, ScaleAnimation.RELATIVE_TO_SELF, 0.0f); scale.setFillAfter(true); scale.setStartOffset(500); scale.setDuration(500); // fromAlpha, toAlpha AlphaAnimation alpha = new AlphaAnimation(1,0); alpha.setFillAfter(true); alpha.setDuration(500); alpha.setStartOffset(500); mTestAnim.addAnimation(rotate); mTestAnim.addAnimation(scale); mTestAnim.addAnimation(alpha); mTestAnim.setRepeatMode(AnimationSet.RESTART); mTestAnim.setRepeatCount(AnimationSet.INFINITE); return mTestAnim; } @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } } public static class MyViewGroup extends ViewGroup{ public MyViewGroup(Context context) { super(context); // TODO Auto-generated constructor stub } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub } } } This is my major idea to implement animation. MyViewGroup parent = new MyViewGroup(context); AnimationSet animation = setAnimationSet(); LinearLayout ll = (LinearLayout)views.apply(context, parent); ll.findViewById(R.id.ImageView_animation).setAnimation(animation); views.reapply(context, ll); What is that I think wrong? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---