2015-11-26 42 views
1

我是Android開發新手,並且遇到問題。 我希望你們能幫助我;) 我正在一個Appwidget,一個包含多個圖像的線性佈局 的遠程視圖。 我通過一些教程和示例工作, 我能夠構建第一個應用程序,檢測點擊的圖像視圖以打開特定的已安裝的應用程序,或者更改某些Imageviews的圖像資源。如何多次改變一個appwidget(remoteview)的imageview,並在之間進行短暫的休息?

現在我的問題是,我想單擊按鈕時動畫的圖像。 我做了一個drawableAnimation,但後來我讀了遠程視圖不支持這些。

所以我的想法是與 之間稍微休息一下對於實例手動更改圖片:

變化imageview的

0.1秒等待

變化imageview的

0.1秒等待

更改圖片視圖

0.1秒等待

變化imageview的

所以現在我讀了一些有關睡眠(),處理程序和adapterviewflipper(沒有它我能實現的),我真的不知道該往哪個方向走。

這裏是我的AppWidgetProvider

public class MyWidgetProvider extends AppWidgetProvider { 

@Override 
public void onUpdate(Context context, AppWidgetManager appWidgetManager, 
     int[] appWidgetIds) { 

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_demo); 

    // Button To Change Imageview 
    remoteViews.setOnClickPendingIntent(R.id.B1, buildButtonPendingIntent(context)); 
    //Buttons to open some installed apps 
    remoteViews.setOnClickPendingIntent(R.id.T1, getPendingIntent(context, 1)); 
    remoteViews.setOnClickPendingIntent(R.id.T2, getPendingIntent(context, 2)); 

    pushWidgetUpdate(context, remoteViews); 
} 




public static PendingIntent buildButtonPendingIntent(Context context) { 
    Intent intent = new Intent(); 
    intent.setAction("com.appwidgettest.intent.action.UPDATEUI"); 
    return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
} 


public static PendingIntent getPendingIntent(Context context, int btnId) { 

// starts a htc radio app as standart and if button 2 is clicked it starts 
// chrome browser just did this for testing the packagemanager 
    PackageManager pm = context.getPackageManager(); 
    String gg = "com.htc.fm"; 
    if (btnId==2){gg = "com.android.chrome"; 
    } 

    Intent intentt= pm.getLaunchIntentForPackage(gg); 
    PendingIntent pi = PendingIntent.getActivity(context, 0, intentt, 0); 

    return pi; 
} 



public static void pushWidgetUpdate(Context context, RemoteViews remoteViews) { 
    ComponentName myWidget = new ComponentName(context, MyWidgetProvider.class); 
    AppWidgetManager manager = AppWidgetManager.getInstance(context); 
    manager.updateAppWidget(myWidget, remoteViews);  
} 

}

和工作至今Broadcastreciever的代碼。

public class MyWidgetIntentReceiver extends BroadcastReceiver { 




@Override 
public void onReceive(Context context, Intent intent) { 
    if(intent.getAction().equals("com.appwidgettest.intent.action.UPDATEUI")){ 
     updateWidgetPictureAndButtonListener(context); 
    } 
} 

private void updateWidgetPictureAndButtonListener(Context context) { 
    final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_demo); 


    // Here i Change The Imageviews! 
    remoteViews.setImageViewResource(R.id.M3, R.drawable.image1); 
    //here i need a short time sleep of 0.2 seconds for example 
    remoteViews.setImageViewResource(R.id.M2, R.drawable.image2); 
    //here too 
    remoteViews.setImageViewResource(R.id.M1, R.drawable.image3); 





    // Here to set the Button Listeners 
    remoteViews.setOnClickPendingIntent(R.id.B1, MyWidgetProvider.buildButtonPendingIntent(context)); 
    remoteViews.setOnClickPendingIntent(R.id.T2, MyWidgetProvider.getPendingIntent(context,2)); 
    remoteViews.setOnClickPendingIntent(R.id.T1, MyWidgetProvider.getPendingIntent(context,1)); 


    MyWidgetProvider.pushWidgetUpdate(context.getApplicationContext(), remoteViews); 
} 

}

我爲我的英語不好真的很抱歉^^,我希望你能理解大部分:P

如果你有更好的想法爲標題請告訴我

請幫我看看!

問候T.R.Salvatore

回答

相關問題