Android Open Source - BatteryFu Mobile Data 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;
//  w w  w.  j ava 2  s.  c o m
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.widget.Toast;

import com.tobykurien.batteryfu.Settings;

public abstract class MobileDataSwitcher {
  public static MobileDataSwitcher apn = new APNSwitcher();
  public static MobileDataSwitcher apndroid = new APNDroidSwitcher();
   public static MobileDataSwitcher gb = new GingerbreadSwitcher();
   public static MobileDataSwitcher ics = new ICSSwitcher();
  
  /**
   * Get the right mobile data switcher
   * @param pref
   * @return
   */
  public static MobileDataSwitcher getSwitcher(Context context, Settings settings) {
      if (Integer.parseInt(Build.VERSION.SDK) >= 14) {
         if (ics.isToggleWorking(context) == 0) {
            //Toast.makeText(context, "Using ICS switcher", Toast.LENGTH_LONG).show();
            return ics;
         }
      }
      
     if (Integer.parseInt(Build.VERSION.SDK) >= 9) {
        if (gb.isToggleWorking(context) == 0) {
            //Toast.makeText(context, "Using Gingerbread switcher", Toast.LENGTH_LONG).show();
           return gb;
        }
     }
     
    if (settings.isUseApndroid()) {
      return apndroid;
    } else {
      return apn;
    }
  }
  
  /**
   * Used to restore all APN settings on startup to avoid conflicts between them
   * @param context
   */
  public static void enableAll(Context context) {
    if (apn == null) apn = new APNSwitcher();
    apn.enableMobileData(context);
    
    if (apndroid == null) apndroid = new APNDroidSwitcher();
    apndroid.enableMobileData(context);
    
    if (gb == null) gb = new GingerbreadSwitcher();
    gb.enableMobileData(context);
  }
  
  public static void disableMobileData(Context context, Settings settings) {
    getSwitcher(context, settings).disableMobileData(context);
  }
  
  public static void enableMobileData(Context context, Settings settings) {
    getSwitcher(context, settings).enableMobileData(context);
  }

  /**
   * Method to be implemented that will switch on mobile data
   * @param context
   */
  public abstract void enableMobileData(Context context);
  
  /**
   * Method to be implemented that will switch off mobile data
   * @param context
   */
  public abstract void disableMobileData(Context context);
  
  /**
   * Test to see if APN toggling will work. Returns the ID of the string message
   * to display in the dialog box, or 0 if all is well. The id of the dialog title 
   * will be assumed to be return value - 1
   * @param context
   * @return
   */
  public abstract int isToggleWorking(Context context);  
}




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