2012-01-20 10 views
0

私はWiFiに簡単にアクセスできるWiFiウィジェットを作成しました。 ウィジェットの機能がうまく機能しています。 今、ウィジェットにアニメーションを表示したいと思います。信号バーを接続している間は、Wi-Fiが有効になるまで定期的に点灯して上に移動します。 私は、異なる信号レベルのイメージアレイを作成しました。AndroidでAppWidgetアニメーション

私はメソッドstartAnimationを呼び出していますが。

public void StartAnimation() 
{ 
    System.out.println("start"); 
    frame = 0; 
    animationFlag = true; 
    if(!handler.hasMessages(0)) 
    handler.postDelayed(AnimateRunnable, FRAME_RATE); 



} 

satrtAnimationから、私はanimationFlagをtrueにしています。

その後、状態はEnbaledまたはNot connectedになります。そのとき、私はstopAnimationメソッドを呼び出しています。

public void StopAnimation() 
{ 
    System.out.println("Stop Animation Before:"+animationFlag); 
    animationFlag = false; 
    System.out.println("Stop Animation:After:"+animationFlag); 
    if(!handler.hasMessages(0)) { 
     System.out.println("handler.hasmessage0"); 
     handler.removeCallbacks(AnimateRunnable); 
    } 


} 

ここでは、animationFlagをfalseにしています。前後の値を印字する。正しく表示されます。

しかし、「My Runnable」アニメーションフラグはtrueのままです。だから私のウィジェットアプリウィジェットのレイアウトは、アプリケーションで定義されているという事実にもかかわらず

final Runnable AnimateRunnable =new Runnable(){ 
    public void run() 
    { 
     System.out.println("run:"+animationFlag); 
     if(animationFlag) 
     { 
      System.out.println("Animation Flag:"+animationFlag); 
      AppWidgetManager ap =AppWidgetManager.getInstance(mContext); 
      frame = ++frame%5; 
      remoteViews.setImageViewResource(R.id.wifi_signal_strength,rangeImages[frame]); 
      ap.updateAppWidget(thisWidget, remoteViews); 

       handler.postDelayed(AnimateRunnable, FRAME_RATE); 



     } 
    } 
}; 

答えて

0

を絞首刑になっ、それはあなたのビューではありません、あなたはそれを直接操作することはできません。また、すべてのビューがアプリウィジェットのレイアウトに入ることはできません。このビューはランチャーによって管理され、わかりにくい方法でレイアウトに渡されます(ここでは議論することはできません)

アプリウィジェットのコンテンツを変更したい場合は、マネージャーとリモートビューのオブジェクトを使用してください。

private static void updateWidgetState(Context context, CharSequence amountCameras, String locationCity, String locationStatus) { 
    AppWidgetManager manager = AppWidgetManager.getInstance(context); 
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.camera_widget_layout); 
    views.setOnClickPendingIntent(R.id.camerawidget, PendingIntent.getActivity(context, 0, new Intent(context, CameraWatch.class), PendingIntent.FLAG_UPDATE_CURRENT)); 
    views.setTextViewText(R.id.widget_amount_cameras, amountCameras); 
    views.setTextViewText(R.id.widget_location, locationCity); 
    // views.setTextViewText(R.id.widget_security, securityStatus); 
    views.setTextViewText(R.id.locationStatus, locationStatus); 

    final int[] appWidgetIds = manager.getAppWidgetIds(new ComponentName(CameraWidgetProvider.class.getPackage().getName(), CameraWidgetProvider.class.getName())); 

    manager.updateAppWidget(appWidgetIds, views); 

    Log.d(LOG_TAG, "widget state changed"); 
} 

RemoteViewsのドキュメントを参照してください。これは、取得できるすべての機能です。アニメーションなし

関連する問題