Android动画效果Widget(wifi)

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 22:03 点击:

实现和飞行模式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

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • Android 完全退出程序
    • 原创:Android应用开发-Andorid歌词秀,含源码
    • android 屏幕保护
    • Android手机软件汉化教程---第四课 dex文件汉化
    • 众多Android 开源项目推荐,给力工作给力学习
    • Android Audio代码分析4
    • Android得到已安装的应用程序信息!
    • Android开发者指南(29) —— USB Host and Accessory
    • Android成长的幕后推手:工程师鲁宾
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1