Android Open Source - PreCTS Proxy Settings






From Project

Back to project page PreCTS.

License

The source code is released under:

Apache License

If you think the Android project PreCTS 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.androidhuman.ctsprepare.data;
/* w ww .  j  a  va2 s  . c  o m*/
import java.util.regex.Pattern;

import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

public class ProxySettings {
  public String ip;
  public String port;
  
  public static final String IPV4_REGEX = "\\A(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\z";
  
  public static ProxySettings fromJson(String json){
    JSONObject obj = (JSONObject)JSONValue.parse(json);
    ProxySettings proxy = new ProxySettings();
    
    proxy.ip = (String)obj.get("ip");
    proxy.port = (String)obj.get("port");
    
    if(proxy.ip==null || proxy.port==null){
      return null;
    }
    
    return proxy;
  }
  
  @SuppressWarnings("unchecked")
  public String toJson(){
    // Check all instance is not null
    if(this.ip==null || this.port==null){
      throw new IllegalStateException("Invalid Proxy information");
    }
    JSONObject obj = new JSONObject();
    obj.put("ip", this.ip);
    obj.put("port", this.port);
    return obj.toJSONString();
  }
  
  public boolean isValid(){
    if(!Pattern.matches(IPV4_REGEX, this.ip)){
      return false;
    }
    try{
      int port = Integer.parseInt(this.port);
      if(port> 65535 || port < 0){
        return false;
      }
    }catch(NumberFormatException e){
      return false;
    }
    return true;
  }
  
  

}




Java Source Code List

com.androidhuman.ctsprepare.automator.GoogleAccount.java
com.androidhuman.ctsprepare.automator.PreCTSAutomate.java
com.androidhuman.ctsprepare.automator.WifiAp.java
com.androidhuman.ctsprepare.data.BasicDeviceInfo.java
com.androidhuman.ctsprepare.data.Event.java
com.androidhuman.ctsprepare.data.GoogleAccount.java
com.androidhuman.ctsprepare.data.Model.java
com.androidhuman.ctsprepare.data.ProxySettings.java
com.androidhuman.ctsprepare.data.Task.java
com.androidhuman.ctsprepare.data.Waiver.java
com.androidhuman.ctsprepare.data.WifiAp.java
com.androidhuman.ctsprepare.dialog.CtsMediaDownloadDialog.java
com.androidhuman.ctsprepare.dialog.EditGoogleAccountDialog.java
com.androidhuman.ctsprepare.dialog.EditMacroDialog.java
com.androidhuman.ctsprepare.dialog.EditProxyDialog.java
com.androidhuman.ctsprepare.dialog.EditSdkPathDialog.java
com.androidhuman.ctsprepare.dialog.EditWifiApDialog.java
com.androidhuman.ctsprepare.dialog.TargetSelectionDialog.java
com.androidhuman.ctsprepare.shell.ConfigureMacroShell.java
com.androidhuman.ctsprepare.shell.Main.java
com.androidhuman.ctsprepare.util.AdbCommand.java
com.androidhuman.ctsprepare.util.AdbWrapper.java
com.androidhuman.ctsprepare.util.AsyncTask.java
com.androidhuman.ctsprepare.util.Download.java
com.androidhuman.ctsprepare.util.Utils.java
com.androidhuman.ctsprepare.util.Worker.java
com.androidhuman.prectsandroidsettingsapp.EnableSyncActivity.java
com.androidhuman.prectsandroidsettingsapp.FinishHandler.java
com.androidhuman.prectsandroidsettingsapp.MainActivity.java