Android Open Source - BatteryFu Gingerbread 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   www . j  a  v a2s .  c o  m
import java.lang.reflect.Method;

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

public class GingerbreadSwitcher extends MobileDataSwitcher {
   private static boolean DEBUG = true;

   @Override
   public void enableMobileData(Context context) {
      try {
         ConnectivityManager connService = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         Method setMobileDataEnabledMethod = getDataMethod(context);
         if (setMobileDataEnabledMethod != null) setMobileDataEnabledMethod.invoke(connService, true);
      } catch (Exception e) {
         Log.e("BatteryFu", "Error enabling data", e);
      }
   }

   @Override
   public void disableMobileData(Context context) {
      try {
         ConnectivityManager connService = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         Method setMobileDataEnabledMethod = getDataMethod(context);
         if (setMobileDataEnabledMethod != null) setMobileDataEnabledMethod.invoke(connService, false);
      } catch (Exception e) {
         Log.e("BatteryFu", "Error disabling data", e);
      }
   }

   @Override
   public int isToggleWorking(Context context) {
      if (getDataMethod(context) != null) {
         return 0;
      } else {
         // return id of error message
         return com.tobykurien.batteryfu.R.string.apn_problem_text; 
      }
   }

   private Method getDataMethod(Context context) {
      ConnectivityManager connService = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
      if (null != connService) {
         Method[] methods = connService.getClass().getMethods();
         for (Method m : methods) {
            if ("setMobileDataEnabled".equals(m.getName())) { return m; }
         }
      }

      return null;
   }
}




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