Android动画效果Widget(wifi)
实现和飞行模式widget类似,只贴出不同代码:
public class WifiWidget extends AppWidgetProvider {
private final static String SET_WIFI_ACTION = "com.archermind.wifi.widget.set_wifi";
private static final int START_ANIMATION = 0;
private static final int END_ANIMATION = 1;
private static WifiManager mWifiManager;
private static int wifiState;
private static boolean mRunAnimation = false;
private static RemoteViews mRemoteViews;
private static Context mContext;
private int [] mDrawable = {
R.drawable.settings_icon_wifi_01,
R.drawable.settings_icon_wifi_02,
R.drawable.settings_icon_wifi_03
};
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
if(mContext == null){
mContext = context;
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
mWifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
mRemoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
wifiState = mWifiManager.getWifiState();
if(wifiState == WifiManager.WIFI_STATE_DISABLED){
mRemoteViews.setImageViewResource(R.id.settings_wifi_switch, R.drawable.settings_switch_off);
}else if(wifiState == WifiManager.WIFI_STATE_ENABLED){
mRemoteViews.setImageViewResource(R.id.settings_wifi_switch, R.drawable.settings_switch_on);
}
Intent intentClick = new Intent(SET_WIFI_ACTION);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
intentClick, 0);
mRemoteViews.setOnClickPendingIntent(R.id.settings_wifi, pendingIntent);
for(int i=0; i<appWidgetIds.length; i++){
appWidgetManager.updateAppWidget(appWidgetIds[i], mRemoteViews);
}
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
Log.e("method", "onReceive");
if(intent.getAction().equals(SET_WIFI_ACTION)){
wifiState = mWifiManager.getWifiState();
Log.e("==", "==");
Log.e("wifistate", ""+wifiState);
if(wifiState == WifiManager.WIFI_STATE_DISABLED){
mWifiManager.setWifiEnabled(true);
Log.i("open", "open");
}else if(wifiState == WifiManager.WIFI_STATE_ENABLED){
mWifiManager.setWifiEnabled(false);
Log.i("close", "close");
}
}else if(intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)){
Log.e("change", "change");
handleWifiStateChanged(intent.getIntExtra(
WifiManager.EXTRA_WIFI_STATE,WifiManager.WIFI_STATE_UNKNOWN));
}
}
//判断wifi状态
private void handleWifiStateChanged(int state){
Message msg = mHandler.obtainMessage(START_ANIMATION);
msg.arg1 = 0;
switch(state){
case WifiManager.WIFI_STATE_DISABLING:
Log.e("state", "WIFI_ST
- 发表评论
-
- 最新评论 更多>>