Android Open Source - BatteryFu I C S Switcher






From Project

Back to project page BatteryFu.

License

The source code is released under:

GNU General Public License

If you think the Android project BatteryFu listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tobykurien.batteryfu.data_switcher;
/*from   w ww. j  ava 2s  .c o  m*/
import java.lang.reflect.Method;

import android.content.Context;
import android.net.ConnectivityManager;
import android.util.Log;

import com.tobykurien.batteryfu.BatteryFu;
import com.tobykurien.batteryfu.R;

/**
 * An ICS-compatible data switcher
 * @author toby
 */
public class ICSSwitcher extends MobileDataSwitcher {
   private ConnectivityManager connMan;
   private Context context;
   private Method isEnabledMethod;
   private Method setEnabledMethod;

   @Override
   public void enableMobileData(Context context) {
      setMobileDataEnabled(context, true);
   }

   @Override
   public void disableMobileData(Context context) {
      setMobileDataEnabled(context, false);
   }

   @Override
   public int isToggleWorking(Context context) {
      init(context);
      
      if (setEnabledMethod != null) {
         return 0;
      }
      
      return R.string.apn_problem_text;
   }

   public void init(Context context) {
      this.context = context;
      this.connMan = ((ConnectivityManager) this.context.getSystemService("connectivity"));
      try {
         Class localClass = this.connMan.getClass();
         Class[] arrayOfClass = new Class[1];
         arrayOfClass[0] = Boolean.TYPE;
         this.setEnabledMethod = localClass.getMethod("setMobileDataEnabled", arrayOfClass);
         this.isEnabledMethod = this.connMan.getClass().getMethod("getMobileDataEnabled", new Class[0]);
      } catch (Exception localException) {
         Log.e(BatteryFu.LOG_TAG, localException.getMessage(), localException);
      }
   }

   public void setMobileDataEnabled(Context context, boolean enabled) {
      init(context);
      try {
         Method localMethod = this.setEnabledMethod;
         ConnectivityManager localConnectivityManager = this.connMan;
         Object[] arrayOfObject = new Object[1];
         arrayOfObject[0] = Boolean.valueOf(enabled);
         localMethod.invoke(localConnectivityManager, arrayOfObject);
      } catch (Exception localException) {
         Log.e(BatteryFu.LOG_TAG, localException.getMessage(), localException);
      }
   }

   public boolean isMobileDataEnabled() throws Exception {
      return ((Boolean) this.isEnabledMethod.invoke(this.connMan, new Object[0])).booleanValue();
   }
}




Java Source Code List

android.preference.TimePickerPreference.java
com.koushikdutta.widgets.ActivityBaseFragment.java
com.koushikdutta.widgets.ActivityBase.java
com.koushikdutta.widgets.AnimatedView.java
com.koushikdutta.widgets.ListContentAdapter.java
com.koushikdutta.widgets.ListContentFragment.java
com.koushikdutta.widgets.ListItem.java
com.koushikdutta.widgets.SeparatedListAdapter.java
com.tobykurien.android.UtilsConstants.java
com.tobykurien.android.UtilsDebug.java
com.tobykurien.android.Utils.java
com.tobykurien.batteryfu.BattServiceInfo.java
com.tobykurien.batteryfu.BatteryFu.java
com.tobykurien.batteryfu.BatteryMinder.java
com.tobykurien.batteryfu.DataToggler.java
com.tobykurien.batteryfu.GeneralReceiver.java
com.tobykurien.batteryfu.MainFunctions.java
com.tobykurien.batteryfu.ModeSelect.java
com.tobykurien.batteryfu.ScreenService.java
com.tobykurien.batteryfu.Settings.java
com.tobykurien.batteryfu.ToggleWidget.java
com.tobykurien.batteryfu.compat.Api17.java
com.tobykurien.batteryfu.compat.Api3.java
com.tobykurien.batteryfu.data_switcher.APNDroidSwitcher.java
com.tobykurien.batteryfu.data_switcher.APNSwitcher.java
com.tobykurien.batteryfu.data_switcher.GingerbreadSwitcher.java
com.tobykurien.batteryfu.data_switcher.ICSSwitcher.java
com.tobykurien.batteryfu.data_switcher.MobileDataSwitcher.java