Example usage for android.content SharedPreferences contains

List of usage examples for android.content SharedPreferences contains

Introduction

In this page you can find the example usage for android.content SharedPreferences contains.

Prototype

boolean contains(String key);

Source Link

Document

Checks whether the preferences contains a preference.

Usage

From source file:com.xorcode.andtweet.net.ConnectionOAuth.java

/**
 * @see com.xorcode.andtweet.net.Connection#getCredentialsPresent()
 *//*from  w w w.  j av a  2s.  c o m*/
@Override
public boolean getCredentialsPresent(SharedPreferences sp) {
    boolean yes = false;
    if (sp.contains(ConnectionOAuth.USER_TOKEN) && sp.contains(ConnectionOAuth.USER_SECRET)) {
        mToken = sp.getString(ConnectionOAuth.USER_TOKEN, null);
        mSecret = sp.getString(ConnectionOAuth.USER_SECRET, null);
        if (!(mToken == null || mSecret == null)) {
            yes = true;
        }
    }
    return yes;
}

From source file:nya.miku.wishmaster.api.AbstractChanModule.java

public AbstractChanModule(SharedPreferences preferences, Resources resources) {
    if (!preferences.contains(getSharedKey(PREF_KEY_PASSWORD))) {
        preferences.edit().putString(getSharedKey(PREF_KEY_PASSWORD), CryptoUtils.genPassword()).commit();
    }//from  www.j  a  va  2  s . com
    this.preferences = preferences;
    this.resources = resources;
    updateHttpClient(preferences.getBoolean(getSharedKey(PREF_KEY_UNSAFE_SSL), false),
            preferences.getBoolean(getSharedKey(PREF_KEY_USE_PROXY), false),
            preferences.getString(getSharedKey(PREF_KEY_PROXY_HOST), DEFAULT_PROXY_HOST),
            preferences.getString(getSharedKey(PREF_KEY_PROXY_PORT), DEFAULT_PROXY_PORT));
}

From source file:com.xorcode.andtweet.net.ConnectionOAuth.java

private void loadSavedKeys(SharedPreferences sp) {
    // We look for saved user keys
    if (sp.contains(ConnectionOAuth.USER_TOKEN) && sp.contains(ConnectionOAuth.USER_SECRET)) {
        mToken = sp.getString(ConnectionOAuth.USER_TOKEN, null);
        mSecret = sp.getString(ConnectionOAuth.USER_SECRET, null);
        if (!(mToken == null || mSecret == null)) {
            mConsumer.setTokenWithSecret(mToken, mSecret);
        }/*w  w w.  j  a  v a 2s.  co  m*/
    }
}

From source file:eu.trentorise.smartcampus.jp.notifications.BroadcastNotificationsActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == SCAccessProvider.SC_AUTH_ACTIVITY_REQUEST_CODE) {

        try {//from  w w  w.j av a 2  s.co  m
            SharedPreferences sharedPref = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE);
            MobilityUserService userService = new MobilityUserService(
                    GlobalConfig.getAppUrl(this) + JPHelper.MOBILITY_URL);
            if (sharedPref.contains(JPHelper.MY_ITINERARIES)) {
                String mToken = data.getExtras().getString(AccountManager.KEY_AUTHTOKEN);
                if (mToken == null) {
                    Toast.makeText(this, getString(R.string.auth_failed), Toast.LENGTH_SHORT).show();
                } else {

                    JPHelper.setUserAnonymous(this, false);
                    invalidateOptionsMenu();
                    JPHelper.readAccountProfile(
                            new CopyTask(sharedPref, userService, resultCode, data, this, this));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.example.administrator.myapplication2._4_Detail.RightFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout._2_fragment_map, container, false);

    Intent myIntent = getActivity().getIntent();
    if (myIntent != null) {
        seq = myIntent.getStringExtra("seq");
    }//from  w  w w.  j  ava  2 s  . c o  m

    SharedPreferences myPrefs = this.getActivity().getSharedPreferences("login", Context.MODE_PRIVATE);
    if ((myPrefs != null) && (myPrefs.contains("id"))) {
        id = myPrefs.getString("id", "");
    }

    // ? ? 
    map = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map2)).getMap();

    // Setting a custom info window adapter for the google map
    map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        // Use default InfoWindow frame
        @Override
        public View getInfoWindow(Marker arg0) {
            return null;
        }

        // Defines the contents of the InfoWindow
        @Override
        public View getInfoContents(Marker arg0) {

            return null;

        }
    });

    map.setMyLocationEnabled(true);

    arrayPoints = new ArrayList<LatLng>();

    getRecentData();

    /*
            
    if(arrayPoints.size()>0){ showExrLocation(arrayPoints);}                           //Gps
    //if(arrayPoints_network.size()>0){ showExrLocation_network(arrayPoints_network); } //? Gps
    else{Log.i("boogil","? 0?");}
    */

    return rootView;
}

From source file:org.mobisocial.corral.ContentCorral.java

public static UUID getLocalBluetoothServiceUuid(Context c) {
    SharedPreferences prefs = c.getSharedPreferences("main", 0);
    if (!prefs.contains(PREF_CORRAL_BT_UUID)) {
        UUID btUuid = UUID.randomUUID();
        prefs.edit().putString(PREF_CORRAL_BT_UUID, btUuid.toString()).commit();
    }//from   w w w  .  j a  v a2  s.  c o  m
    String uuidStr = prefs.getString(PREF_CORRAL_BT_UUID, null);
    return (uuidStr == null) ? null : UUID.fromString(uuidStr);
}

From source file:edu.csh.coursebrowser.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    this.setTitle("Settings");
    final SharedPreferences sp = SchoolActivity.sp;
    LinearLayout ll = (LinearLayout) this.findViewById(R.id.settings_layout);
    ll.setGravity(Gravity.CENTER);//from  w w  w.j  ava  2 s .  c o  m
    final TextView tv = new TextView(this);
    if (!sp.contains("quarter")) {
        SharedPreferences.Editor e = sp.edit();
        e.putString("quarter", "20122");
        e.commit();
    }
    tv.setText("Current Quarter: " + sp.getString("quarter", "20122"));
    Button b = new Button(this);
    b.setText("Change Quarter");
    ll.addView(tv);
    ll.addView(b);
    ll.setPadding(10, 10, 10, 10);
    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            AlertDialog.Builder changeQuarter = new AlertDialog.Builder(SettingsActivity.this);
            changeQuarter.setTitle("Change Quarter");
            changeQuarter.setMessage("Select New Quarter");
            final RadioButton ld = new RadioButton(SettingsActivity.this);
            ld.setText("20121");
            ld.setId(1);
            final RadioButton s = new RadioButton(SettingsActivity.this);
            s.setText("20122 (Current)");
            s.setId(2);
            final RadioButton d = new RadioButton(SettingsActivity.this);
            d.setText("20123");
            d.setId(3);
            final RadioGroup rg = new RadioGroup(SettingsActivity.this);
            rg.addView(ld);
            rg.addView(s);
            rg.addView(d);
            changeQuarter.setView(rg);

            changeQuarter.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                }

            });
            changeQuarter.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String q;
                    int n = rg.getCheckedRadioButtonId();
                    if (n == 1)
                        q = "20121";
                    else if (n == 2)
                        q = "20122";
                    else
                        q = "20123";
                    SharedPreferences.Editor edit = sp.edit();
                    edit.putString("quarter", q);
                    edit.commit();
                    SettingsActivity.this.finish();
                }
            });

            changeQuarter.show();
        }

    });

}

From source file:com.mtomczak.nausicaa.MainActivity.java

/** Called when the activity is first created. */
@Override//from   www  . j a  v  a  2  s.  c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().requestFeature(WindowUtils.FEATURE_VOICE_COMMANDS);
    setContentView(R.layout.main);

    // Wire up the views
    alertView = (AlertView) findViewById(R.id.alertview);
    statusView = (StatusView) findViewById(R.id.statusview);
    dockingView = (DockingView) findViewById(R.id.dockingview);
    statusView.setAlertOutput(alertView);
    dockingView.setAlertOutput(alertView);
    telemetryViewers.add(alertView);
    telemetryViewers.add(statusView);
    telemetryViewers.add(dockingView);

    telemachus = new Telemachus();
    tts = new SpeechOutput(this);
    timeWarpHalt = new TimeWarpHaltOutput(telemachus);

    SharedPreferences prefs = getPreferences(MODE_PRIVATE);
    if (prefs.contains(ADDRESS_PREF)) {
        try {
            telemachusAddress = DataSource.fromPath(prefs.getString(ADDRESS_PREF, ""));
        } catch (DataSource.ParseError e) {
            Log.e("Nausicaa", "Corrupt prefs: " + prefs.getString(ADDRESS_PREF, "<none>"));
            // ignore; the preference is corrupt and the default will take over.
        }
    }
    if (prefs.contains(TIME_SCALE_PREF)) {
        try {
            timeWarpHalt.setEnabled(prefs.getBoolean(TIME_SCALE_PREF, true));
        } catch (ClassCastException e) {
            Log.e("Nausicaa", "Corrupt prefs: " + TIME_SCALE_PREF + "\n" + e.toString());
            timeWarpHalt.setEnabled(true);
        }
    }
    if (telemachusAddress == null) {
        telemachusAddress = new DataSource("192.168.1.4", 8085);
    }

    initStateNotifiers();
}

From source file:withings.apiaccess.WithingsAPI.java

private void loadUser() {
    SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE);
    if (!preferences.contains("name")) {
        user = null;/*from   ww  w .  j  a v a 2 s .  com*/
        return;
    }

    long id = preferences.getLong("id", 0);
    String name = preferences.getString("name", null);
    String publicKey = preferences.getString("publicKey", null);
    callbackId = preferences.getLong("callbackId", -1);
    user = new WithingsUser(id, name, publicKey, 0);
}

From source file:org.gdgsp.fragment.PeopleFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    view = inflater.inflate(R.layout.fragment_people, container, false);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);

    gson = new Gson();
    if (preferences.contains("member_profile")) {
        Type datasetListType = new TypeToken<Person>() {
        }.getType();// ww  w.  j  a v a  2  s. com
        person = gson.fromJson(preferences.getString("member_profile", ""), datasetListType);
    }

    list = (RecyclerView) view.findViewById(R.id.list);
    progress = (ProgressBar) view.findViewById(R.id.progress);

    list.setVisibility(View.VISIBLE);
    progress.setVisibility(View.GONE);

    Type datasetListType = new TypeToken<List<Person>>() {
    }.getType();
    listPeople = gson.fromJson(getArguments().getString("peopleJson"), datasetListType);

    if (getArguments().getInt("position") == 0) {
        for (Person p : listPeople) {
            if (p.isHas_app()) {
                hasAppPeople.add(p);
            }
        }
    }

    selectedList.clear();
    selectedList.addAll(listPeople);

    adapter = new PeopleAdapter(activity, selectedList);
    list.setLayoutManager(new LinearLayoutManager(activity));
    list.setAdapter(adapter);

    return view;
}