Android 删除/定制桌面电量控制插件

这个插件是属于设置的一部分,可以在

packages\apps\Settings\res\drawable-hdpi

这个文件夹里面查看,呵呵,有没有看到上面目录的斜杠方向,懂吧。

这里找到一个文件名为:“ic_appwidget_settings_mobile_off” 的PNG文件。

而相关的文件是:

vim packages/apps/Settings/src/com/android/settings/widget/SettingsAppWidgetProvider.java

代码要修改有几个部分,可以搜索“BUTTON_MOBILE”,进行修改。

1. 是否显示这个部件

/**
 * Provides control of power-related settings from a widget.
 */
public class SettingsAppWidgetProvider extends AppWidgetProvider {
    static final String TAG = "SettingsAppWidgetProvider";

    static final ComponentName THIS_APPWIDGET =
            new ComponentName("com.android.settings",
                    "com.android.settings.widget.SettingsAppWidgetProvider");

    private static LocalBluetoothManager sLocalBluetoothManager = null;
    private static TelephonyManager mTelephonyManager = null;

    private static final int BUTTON_WIFI = 0;
    private static final int BUTTON_BRIGHTNESS = 1;
    private static final int BUTTON_SYNC = 2;
    private static final int BUTTON_GPS = 3;
    private static final int BUTTON_BLUETOOTH = 4;
//  private static final int BUTTON_MOBILE = 5; /* 该产品没有通话功能。 */

2. 点击之后的事件处理

 /**
  * Receives and processes a button pressed intent or state change.
  *
  * @param context
  * @param intent  Indicates the pressed button.
  */
 @Override
 public void onReceive(Context context, Intent intent) {
     super.onReceive(context, intent);
     if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {
         sWifiState.onActualStateChange(context, intent);
     } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
         sBluetoothState.onActualStateChange(context, intent);
     } else if (intent.hasCategory(Intent.CATEGORY_ALTERNATIVE)) {
         Uri data = intent.getData();
         int buttonId = Integer.parseInt(data.getSchemeSpecificPart());
         if (buttonId == BUTTON_WIFI) {
             sWifiState.toggleState(context);
         } else if (buttonId == BUTTON_BRIGHTNESS) {
             toggleBrightness(context);
         } else if (buttonId == BUTTON_SYNC) {
             toggleSync(context);
           } else if (buttonId == BUTTON_GPS) {
               toggleGps(context);
         } else if (buttonId == BUTTON_BLUETOOTH) {
             sBluetoothState.toggleState(context);
         } 
/* 删去相应的事件处理代码。 
   else if (buttonId == BUTTON_MOBILE) {
             toggleMobile(context);
         }*/
               } else if (TelephonyIntents.ACTION_MODEM_POWER_STATE_CHANGED.equals(intent.getAction())) {
     } else {
         // Don't fall-through to updating the widget.  The Intent
         // was something unrelated or that our super class took
         // care of.
         return;
     }

3. 重新载入图片
 /**
  * Load image for given widget and build {@link RemoteViews} for it.
  */
 static RemoteViews buildUpdate(Context context, int appWidgetId) {
     RemoteViews views = new RemoteViews(context.getPackageName(),
             R.layout.widget);
     views.setOnClickPendingIntent(R.id.btn_wifi, getLaunchPendingIntent(context, appWidgetId,
             BUTTON_WIFI));
     views.setOnClickPendingIntent(R.id.btn_brightness,
             getLaunchPendingIntent(context,
                     appWidgetId, BUTTON_BRIGHTNESS));
     views.setOnClickPendingIntent(R.id.btn_sync,
             getLaunchPendingIntent(context,
                     appWidgetId, BUTTON_SYNC));
     views.setOnClickPendingIntent(R.id.btn_bluetooth,
             getLaunchPendingIntent(context,
                     appWidgetId, BUTTON_BLUETOOTH));

/*   views.setOnClickPendingIntent(R.id.btn_mobile,
             getLaunchPendingIntent(context,
                     appWidgetId, BUTTON_MOBILE)); */

     updateButtons(views, context);
     return views;
 }

  4. 还有这个,全注释掉吧。

 switch (getMobileState(context)) {
     case STATE_DISABLED:
         views.setImageViewResource(R.id.img_mobile, R.drawable.ic_appwidget_settings_mobile_off);
         views.setImageViewResource(R.id.ind_mobile, R.drawable.appwidget_settings_ind_off_c);
         break;
     case STATE_ENABLED:
         views.setImageViewResource(R.id.img_mobile, R.drawable.ic_appwidget_settings_mobile_on);
         views.setImageViewResource(R.id.ind_mobile, R.drawable.appwidget_settings_ind_on_c);
         break;
     case STATE_INTERMEDIATE:
         views.setImageViewResource(R.id.img_mobile, R.drawable.ic_appwidget_settings_mobile_off);
         views.setImageViewResource(R.id.ind_mobile, R.drawable.appwidget_settings_ind_mid_c);
         break;
 }

你可能感兴趣的:(android,插件,桌面小部件,电量控制)