Java Code Examples for com.pixplicity.easyprefs.library.Prefs#putString()

The following examples show how to use com.pixplicity.easyprefs.library.Prefs#putString() . 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: SettingsManager.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
private JSONObject readSettings() {
    try {
        if (Prefs.getString(JS_SETTINGS, null) == null) {
            JSONObject settingsObject = new JSONObject();
            settingsObject.put(JS_START_SCREEN, DEFAULT_START_SCREEN);
            settingsObject.put(JS_NOTIFY_EPISODES, DEFAULT_NOTIFY_EPISODS);
            settingsObject.put(JS_PODCASTS_UPDATE_TIME, DEFAULT_PODCAST_UPDATE_TIME);
            settingsObject.put(JS_STREAM_QUALITY, DEFAULT_STREAM_QUALITY);
            settingsObject.put(JS_TOPS_LANGUAGE, Locale.getDefault().getLanguage());

            Prefs.putString(JS_TOPS_LANGUAGE, Locale.getDefault().getLanguage());
            Prefs.putString(JS_SETTINGS, settingsObject.toString());
        }
        return new JSONObject(Prefs.getString(JS_SETTINGS, null));
    } catch (JSONException e) {
        Logger.printInfo(TAG, "Can't read settings");
        e.printStackTrace();
    }
    return null;
}
 
Example 2
Source File: HTTPConnection.java    From faveo-helpdesk-android-app with Open Software License 3.0 6 votes vote down vote up
private String refreshToken() {
    String result = new Authenticate().postAuthenticateUser(Prefs.getString("USERNAME", null), Prefs.getString("PASSWORD", null));
    if (result == null)
        return null;
    try {
        JSONObject jsonObject = new JSONObject(result);
        String token = jsonObject.getString("token");
        Prefs.putString("TOKEN", token);
        // Preference.setToken(token);
        Authenticate.token = token;
        Helpdesk.token = token;
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }
    return "success";
}
 
Example 3
Source File: MainActivity.java    From EasyPrefs with Apache License 2.0 6 votes vote down vote up
@OnClick({R.id.bt_save_text, R.id.bt_save_number, R.id.bt_force_close})
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.bt_save_text:
            String text = mTextET.getText().toString();
            if (!TextUtils.isEmpty(text)) {
                // one liner to save the String.
                Prefs.putString(SAVED_TEXT, text);
                updateText(text);
            } else {
                Toast.makeText(this, "trying to save a text with lenght 0", Toast.LENGTH_SHORT).show();
            }
            break;
        case R.id.bt_save_number:
            double d = Double.parseDouble(mNumberET.getText().toString());
            Prefs.putDouble(SAVED_NUMBER, d);
            updateNumber(d, false);
            break;
        case R.id.bt_force_close:
            finish();
            break;
        default:
            throw new IllegalArgumentException(
                    "Did you add a new button forget to listen to view ID in the onclick?");
    }
}
 
Example 4
Source File: ConfigurationManagerImpl.java    From mirror with Apache License 2.0 5 votes vote down vote up
@Override
public void updateString(String preferenceKey, String preferenceValue) {
    final String value = trimToNull(preferenceValue);
    if (value != null) {
        Prefs.putString(preferenceKey, value);
    } else {
        Prefs.remove(preferenceKey);
    }
}
 
Example 5
Source File: SyncMaster.java    From uPods-android with Apache License 2.0 5 votes vote down vote up
private void pullUser(String link) throws Exception {

        //Start getting user (pull)
        RequestBody pullFormBody = new FormBody.Builder().
                add("secret", secret).
                add("token", token).
                add("type", type).
                add("task", "get_user").build();
        Request requestGetUser = new Request.Builder().url(link).post(pullFormBody).build();

        JSONObject getUserResult = BackendManager.getInstance().sendSynchronicRequest(requestGetUser);

        printMessage(getUserResult);

        if (getUserResult.has("result")) {
            if (getUserResult.getJSONObject("result").has("global_token")) {
                String globalToken = getUserResult.getJSONObject("result").getString("global_token");
                Prefs.putString(GLOBAL_TOKEN, globalToken);
                token = globalToken;
                type = TYPE_GLOBAL;
            }
            if (getUserResult.getJSONObject("result").has("profile")) {
                JSONObject profile = new JSONObject(getUserResult.getJSONObject("result").getString("profile"));
                if (task == Task.PULL) {
                    publishProgress(profile);
                }
            }
            if (getUserResult.getJSONObject("result").has("settings")) {
                JSONObject settings = new JSONObject(getUserResult.getJSONObject("result").getString("settings"));
                SettingsManager.getInstace().readSettings(settings);
                SettingsManager.getInstace().saveSettings(settings);
            }
        }
        profilePulled = true;
        Prefs.putString(SettingsManager.PREFS_LAST_CLOUD_SYNC, GlobalUtils.getCurrentDateTimeUS());
        //End getting user
    }
 
Example 6
Source File: Helper.java    From faveo-helpdesk-android-app with Open Software License 3.0 5 votes vote down vote up
/**
     * Tickets Page.
     * @param jsonArray refers to the array of JSON elements.
     * @param i position of the element in array.
     * @return object for ticket overview.
     */
    public static TicketOverview parseTicketOverview(JSONArray jsonArray, int i) {
        try {
            //Date updated_at = null;
            String firstName = jsonArray.getJSONObject(i).getString("first_name");
            String lastName = jsonArray.getJSONObject(i).getString("last_name");
            String username = jsonArray.getJSONObject(i).getString("user_name");
            // String email = jsonArray.getJSONObject(i).getString("email");
            String profilePic = jsonArray.getJSONObject(i).getString("profile_pic");
            String ticketNumber = jsonArray.getJSONObject(i).getString("ticket_number");
            String ID = jsonArray.getJSONObject(i).getString("id");
            String title = jsonArray.getJSONObject(i).getString("title");
            Prefs.putString("ticket_subject",title);
//            String createdAt = jsonArray.getJSONObject(i).getString("created_at");
//            String departmentName = jsonArray.getJSONObject(i).getString("department_name");
//            String priorityName = jsonArray.getJSONObject(i).getString("priotity_name");
//            String slaPlanName = jsonArray.getJSONObject(i).getString("sla_plan_name");
//            String helpTopicName = jsonArray.getJSONObject(i).getString("help_topic_name");
            String ticketStatusName = jsonArray.getJSONObject(i).getString("ticket_status_name");
            String updatedAt = jsonArray.getJSONObject(i).getString("updated_at");
            String dueDate = jsonArray.getJSONObject(i).getString("overdue_date");
            String priorityColor = jsonArray.getJSONObject(i).getString("priority_color");
            String attachment = jsonArray.getJSONObject(i).getString("attachment");
            String clientname;
            if (firstName == null || firstName.equals(""))
                clientname = username;
            else
                clientname = firstName + " " + lastName;
            return new TicketOverview(Integer.parseInt(ID), profilePic,
                    ticketNumber, clientname, title, updatedAt, priorityColor, ticketStatusName, i + "", attachment, dueDate, clientname);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
 
Example 7
Source File: ConnectPlayerNameFragment.java    From tilt-game-android with MIT License 5 votes vote down vote up
@OnClick(R.id.next_button)
protected void onNextButtonClick() {
    String playerName = _playerNameInput.getText().toString().trim();

    if (!TextUtils.isEmpty(playerName)) {
        // store name in preferences
        Prefs.putString(PrefKeys.PLAYER_NAME, playerName);
        Prefs.putInt(PrefKeys.MULTIPLAYER_PROTOCOL, MultiplayerProtocol.BLUETOOTH.ordinal());

        // go to connection selection
        navigateTo(Fragments.CONNECT_CLIENTSERVER);
    } else {
        Toast.makeText(getActivity(), "Please fill in your name", Toast.LENGTH_SHORT).show();
    }
}
 
Example 8
Source File: PreferenceManagerImpl.java    From mirror with Apache License 2.0 4 votes vote down vote up
public void setUserName(String userName) {
    Prefs.putString(PREFERENCE_USER_NAME, userName);
}
 
Example 9
Source File: SettingsManager.java    From uPods-android with Apache License 2.0 4 votes vote down vote up
public void readSettings(JSONObject jsonObject) {
    Prefs.putString(JS_SETTINGS, jsonObject.toString());
    readSettings();
}
 
Example 10
Source File: SettingsManager.java    From uPods-android with Apache License 2.0 4 votes vote down vote up
public void saveSettings(JSONObject settingsObject) {
    if (settingsObject != null) {
        Prefs.putString(JS_SETTINGS, settingsObject.toString());
    }
}
 
Example 11
Source File: LoginActivity.java    From faveo-helpdesk-android-app with Open Software License 3.0 4 votes vote down vote up
protected void onPostExecute(String result) {
            progressDialogVerifyURL.dismiss();
            if (result == null) {
                count++;
//                if (count==0){
//                    Toasty.warning(context, getString(R.string.invalid_url), Toast.LENGTH_LONG).show();
//                    count--;
//                    return;
//                }
                if (result == null) {
                    count++;
                    //progressBar.setVisibility(View.GONE);
                    buttonVerifyURL.setEnabled(true);
                    Toasty.warning(context, getString(R.string.invalid_url), Toast.LENGTH_LONG).show();
                    return;
                }

                //new VerifyURLSecure(LoginActivity.this,companyURL1).execute();
                return;
            }
                //String status=jsonObject.getString("status");
              else  if (result.contains("success")){
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
                        dynamicShortcut();
                    }
                    Prefs.putString("BASE_URL", baseURL);
                    Log.d("BASEurl",baseURL);
                    Prefs.putString("COMPANY_URL", companyURL + "api/v1/");
                    Constants.URL = Prefs.getString("COMPANY_URL", "");
                    if (BuildConfig.DEBUG) {
                        viewflipper.showNext();
                        imageBackButton.setVisibility(View.VISIBLE);
                        url.setText(baseURL);
                        url.setVisibility(View.VISIBLE);
                        flipColor.setBackgroundColor(ContextCompat.getColor(LoginActivity.this, R.color.faveo));
                    } else {
                        viewflipper.showNext();
                        imageBackButton.setVisibility(View.VISIBLE);
                        url.setText(baseURL);
                        url.setVisibility(View.VISIBLE);
                        flipColor.setBackgroundColor(ContextCompat.getColor(context, R.color.faveo));
                    }

                } else {
                    linearLayout.startAnimation(animation);
                    urlError.setVisibility(View.VISIBLE);
                    urlError.setText(getString(R.string.error_verifying_url));
                    urlError.setTextColor(Color.parseColor("#ff0000"));
                    urlError.postDelayed(new Runnable() {
                        public void run() {
                            urlError.setVisibility(View.INVISIBLE);
                        }
                    }, 5000);

                }



            }