Android Open Source - Static-IP-Switcher Utils






From Project

Back to project page Static-IP-Switcher.

License

The source code is released under:

Apache License

If you think the Android project Static-IP-Switcher 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.htbest2000.staticipswitcher2;
//  w ww.j av  a2s.c o  m
import java.util.Iterator;
import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.provider.Settings.System;
import android.util.Log;

public class Utils {

  public static void setIpStat(Context context, int stat) {
    System.putInt(context.getContentResolver(), System.WIFI_USE_STATIC_IP,
        stat);
  }

  public static int getIpStat(Context context) {
    return System.getInt(context.getContentResolver(),
        System.WIFI_USE_STATIC_IP, 0);
  }
  
  public static boolean isServiceRunning(Context context, Object clazz) {
    ActivityManager mgr = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> N = mgr.getRunningServices(Integer.MAX_VALUE);
    for (Iterator<RunningServiceInfo> it = N.iterator(); it.hasNext();) {
      if (it.getClass().equals(clazz)) {
        Log.i("=ht=", "got running service:" + clazz);
        return true;
      }
    }
    return false;
  }
  
  public static int getNewStat(int old) {
    int new_stat;
    if (0 == old) {
      new_stat = 1;
    }
    else if (1 == old) {
      new_stat = 0;
    }
    else {
      new_stat = -1;
    }
    return new_stat;
  }
 

}




Java Source Code List

com.htbest2000.staticipswitcher2.ConfigActivity.java
com.htbest2000.staticipswitcher2.Receiver.java
com.htbest2000.staticipswitcher2.StaticIpSwitcherAppWidgetProvider.java
com.htbest2000.staticipswitcher2.Utils.java