Search in sources :

Example 1 with IpConfigBeen

use of httploglib.lib.been.IpConfigBeen in project LibTest by liudao01.

the class IpSwitchNavigatorContent method setListSelect.

private void setListSelect(int position) {
    for (int i = 0; i < dataList.size(); i++) {
        IpConfigBeen ipConfigBeen = dataList.get(i);
        if (i == position) {
            ipConfigBeen.setSelect(true);
        } else {
            ipConfigBeen.setSelect(false);
        }
        dataList.set(i, ipConfigBeen);
    }
    for (IpConfigBeen ipConfigBeen : dataList) {
        Logger.d("打印 " + ipConfigBeen.toString());
    }
    ipSwitchAdapter.notifyDataSetChanged();
    // 保存
    TestLibUtil.getInstance().setDataList(dataList);
}
Also used : IpConfigBeen(httploglib.lib.been.IpConfigBeen)

Example 2 with IpConfigBeen

use of httploglib.lib.been.IpConfigBeen in project LibTest by liudao01.

the class ListDataSave method changeArrayDateToJson.

// /**
// * 获取lIst
// *
// * @param tag
// * @return
// */
// public <T> List<T> getList(String tag) {
// List<T> datalist = new ArrayList<T>();
// String strJson = preferences.getString(tag, null);
// if (null == strJson) {
// return datalist;
// }
// Gson gson = new Gson();
// datalist = gson.fromJson(strJson, new TypeToken<List<T>>() {
// }.getType());
// return datalist;
// 
// }
/**
 * 将数组转换为JSON格式的数据。
 *
 * @param stoneList 数据源
 * @return JSON格式的数据
 */
public static String changeArrayDateToJson(ArrayList<IpConfigBeen> stoneList) {
    try {
        JSONArray array = new JSONArray();
        JSONObject object = new JSONObject();
        int length = stoneList.size();
        for (int i = 0; i < length; i++) {
            IpConfigBeen stone = stoneList.get(i);
            String name = stone.getUrlName();
            String url = stone.getUrl();
            boolean select = stone.isSelect();
            JSONObject stoneObject = new JSONObject();
            stoneObject.put("name", name);
            stoneObject.put("url", url);
            stoneObject.put("select", select);
            array.put(stoneObject);
        }
        object.put("stones", array);
        return object.toString();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IpConfigBeen(httploglib.lib.been.IpConfigBeen)

Example 3 with IpConfigBeen

use of httploglib.lib.been.IpConfigBeen in project LibTest by liudao01.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;
    // TestLibUtil.getInstance().startUtil(getApplication());
    setContentView(R.layout.activity_main);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (!Settings.canDrawOverlays(context)) {
            Intent drawOverlaysSettingsIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
            drawOverlaysSettingsIntent.setData(Uri.parse("package:" + context.getPackageName()));
            context.startActivity(drawOverlaysSettingsIntent);
        }
    }
    btStart = (Button) findViewById(R.id.bt_start);
    tvIpList = (TextView) findViewById(R.id.tv_ip_list);
    btCrash = (Button) findViewById(R.id.bt_crash);
    btStart.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            doHttpActivity();
        }
    });
    btCrash.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int x = 1 / 0;
        }
    });
    // 网络测试
    final String url = "www.baidu.com";
    final String json = "{\n" + "    \"result\": \"success\",\n" + "    \"arr\": [\n" + "        {\n" + "            \"examid\": 11,\n" + "            \"class\": \"情感测试\",\n" + "            \"subclass\": \"家庭关系\",\n" + "            \"title\": \"家庭情感表达测试\",\n" + "            \"updatetime\": \"2013-12-04 17:14:17\"\n" + "        },\n" + "        {\n" + "            \"examid\": 12,\n" + "            \"class\": \"情感测试\",\n" + "            \"subclass\": \"亲子关系\",\n" + "            \"title\": \"亲子关系测试\",\n" + "            \"updatetime\": \"2013-12-04 17:14:17\"\n" + "        }\n" + "    ]\n" + "}";
    btStartOne = findViewById(R.id.bt_start_one);
    HttpTransaction httpTransaction = new HttpTransaction();
    httpTransaction.setUrl(url);
    httpTransaction.setResponseBody(json);
    TestLibUtil.getInstance().sendmessage(httpTransaction);
    btStartOne.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            HttpTransaction httpTransaction = new HttpTransaction();
            httpTransaction.setUrl("www.google.com__" + (count++));
            httpTransaction.setResponseBody(json);
            TestLibUtil.getInstance().sendmessage(httpTransaction);
        }
    });
    // tvIpList.setOnClickListener(new View.OnClickListener() {
    // @Override
    // public void onClick(View v) {
    // TestLibUtil.getInstance().sendmessage("", url, json);
    // }
    // });
    // ip 测试
    IPinit();
    List<IpConfigBeen> ipList = TestLibUtil.getInstance().getIpList();
    String list = "";
    for (IpConfigBeen ipConfigBeen : ipList) {
        list = list + ipConfigBeen.toString() + "\n";
    }
    tvIpList.setText(list);
}
Also used : HttpTransaction(lib.data.HttpTransaction) Intent(android.content.Intent) IpConfigBeen(httploglib.lib.been.IpConfigBeen) TextView(android.widget.TextView) View(android.view.View)

Example 4 with IpConfigBeen

use of httploglib.lib.been.IpConfigBeen in project LibTest by liudao01.

the class ListDataSave method changeJsonToArray.

/**
 * 将JSON转化为数组并返回。
 *
 * @param Json
 * @return ArrayList<Stone>
 */
public static ArrayList<IpConfigBeen> changeJsonToArray(String Json) {
    ArrayList<IpConfigBeen> gameList = new ArrayList<IpConfigBeen>();
    try {
        JSONObject jsonObject = new JSONObject(Json);
        if (!jsonObject.isNull("stones")) {
            String aString = jsonObject.getString("stones");
            JSONArray aJsonArray = new JSONArray(aString);
            int length = aJsonArray.length();
            for (int i = 0; i < length; i++) {
                JSONObject stoneJson = aJsonArray.getJSONObject(i);
                String name = stoneJson.getString("name");
                String url = stoneJson.getString("url");
                boolean select = stoneJson.getBoolean("select");
                IpConfigBeen stone = new IpConfigBeen(url, name, select);
                gameList.add(stone);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return gameList;
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) IpConfigBeen(httploglib.lib.been.IpConfigBeen) JSONException(org.json.JSONException)

Example 5 with IpConfigBeen

use of httploglib.lib.been.IpConfigBeen in project LibTest by liudao01.

the class TestLibUtil method getSwitchs.

/**
 * 获取当前ip
 *
 * @param context
 * @return
 */
public String getSwitchs(Context context) {
    String url = null;
    // 切换服务器ip 地址 测试
    instance = ListDataSave.getInstance(context, ListDataSave.ListDataSave);
    List<IpConfigBeen> list = instance.getDataList(ListDataSave.listTag);
    for (IpConfigBeen ipConfigBeen : list) {
        if (ipConfigBeen.isSelect()) {
            url = ipConfigBeen.getUrl();
        }
    }
    return url;
}
Also used : IpConfigBeen(httploglib.lib.been.IpConfigBeen)

Aggregations

IpConfigBeen (httploglib.lib.been.IpConfigBeen)6 ArrayList (java.util.ArrayList)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 Intent (android.content.Intent)1 View (android.view.View)1 TextView (android.widget.TextView)1 HttpTransaction (lib.data.HttpTransaction)1