Java Code Examples for java.net.URL#substring()

The following examples show how to use java.net.URL#substring() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListAPI.java    From ShoppingList with Apache License 2.0 4 votes vote down vote up
public Boolean doInBackground(String... params) {
    prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String AUTHKEY = prefs.getString("authkey", "");
    String URL = prefs.getString("host", "");
     useSSL = prefs.getBoolean("useSSL", false);
     if(URL.isEmpty()){
         listener.onError(new ResponseHelper(CONSTS.APP_ERROR_CONFIG_NO_HOST, context.getResources().getString(R.string.error_no_host_configured)));
         this.cancel(true);
     }

     URL = URL.replace("https://", "");
     URL = URL.replace("http://", "");
     String lastChar = URL.substring(URL.length() - 1);
     if(!lastChar.equals("/") && !lastChar.equals("p")){
         URL = URL+"/";
     }

     if(useSSL) {
         URL = "https://" + URL;
     } else {
         URL = "http://" + URL;
     }
    HashMap<String,String> parameters = new HashMap<>();

    switch (chosenfunction){
        case FUNCTION_GETLIST:
            parameters.put("function", "listall");
            parameters.put("auth", AUTHKEY);
            performPostCall(URL, parameters);
            break;
        case FUNCTION_SAVEITEM:
            parameters.put("function", "save");
            parameters.put("auth", AUTHKEY);
            parameters.put("item",params[0]);
            parameters.put("count",params[1]);
            parameters.put("checked",params[2]);
            performPostCall(URL, parameters);
            break;
        case FUNCTION_DELETEITEM:
            parameters.put("function", "delete");
            parameters.put("auth", AUTHKEY);
            parameters.put("item",params[0]);
            performPostCall(URL, parameters);
            break;
        case FUNCTION_CLEARLIST:
            parameters.put("function", "clear");
            parameters.put("auth", AUTHKEY);
            performPostCall(URL, parameters);
            break;
        case FUNCTION_UPDATECOUNT:
            parameters.put("function", "update");
            parameters.put("auth", AUTHKEY);
            parameters.put("item",params[0]);
            parameters.put("count",params[1]);
            performPostCall(URL, parameters);
            break;
        case FUNCTION_DELETE_MULTIPLE:
            parameters.put("function", "deleteMultiple");
            parameters.put("auth", AUTHKEY);
            parameters.put("jsonArray",params[0]);
            performPostCall(URL, parameters);
            break;
        case FUNCTION_SAVE_MULTIPLE:
            parameters.put("function", "saveMultiple");
            parameters.put("auth", AUTHKEY);
            parameters.put("jsonArray",params[0]);
            Log.d("PARAMS", parameters.toString());
            performPostCall(URL, parameters);
            break;
        case FUNCTION_ADD_QRCODE_ITEM:
            parameters.put("function", "addQRcodeItem");
            parameters.put("auth", AUTHKEY);
            parameters.put("item",params[0]);
            Log.d("PARAMS", parameters.toString());
            performPostCall(URL, parameters);
            break;
    }

    return true;
}