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:org.catnut.ui.MainActivity.java

public void switch2Plugins(View view) {
    if (mDrawerLayout.isDrawerOpen(mQuickReturnDrawer)) {
        mDrawerLayout.closeDrawer(mQuickReturnDrawer);
    }/*from  ww  w  . j  ava  2s . c o m*/
    if (view != null) { // ?layout xml
        String key = (String) view.getTag();
        SharedPreferences pref = CatnutApp.getTingtingApp().getPreferences();
        if (!pref.contains(key)) { // fantasy salutation
            startActivity(new Intent(this, HelloActivity.class).putExtra(HelloActivity.TAG, HelloActivity.TAG));
            return; // stop here
        } else {
            boolean enable = pref.getBoolean(key, getResources().getBoolean(R.bool.default_plugin_status));
            if (!enable) {
                startActivity(SingleFragmentActivity.getIntent(this, SingleFragmentActivity.PLUGINS_PREF));
                return; // stop here
            }
        }
    }
    ArrayList<Integer> plugins = CatnutUtils.enabledPlugins();
    if (plugins != null) {
        Intent intent = new Intent(this, PluginsActivity.class);
        intent.putExtra(PluginsActivity.PLUGINS, plugins);
        startActivity(intent);
    } else {
        startActivity(SingleFragmentActivity.getIntent(this, SingleFragmentActivity.PLUGINS_PREF));
    }
}

From source file:com.amazon.appstream.sampleclient.SampleClientActivity.java

/**
 * Initialization. Sets up the app and spawns the connection
 * dialog.//from  w ww  .  j a  v  a 2s  .  com
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.v(TAG, "onCreate");
    mGestureDetector = new GestureDetector(this, this);

    mGestureDetector.setIsLongpressEnabled(false);

    mTouchscreenAvailable = getPackageManager().hasSystemFeature("android.hardware.touchscreen");
    Log.v(TAG, "Touch screen available: " + mTouchscreenAvailable);

    SharedPreferences prefs = getSharedPreferences("main", MODE_PRIVATE);
    if (prefs.contains(SERVER_ADDRESS)) {
        mServerAddress = prefs.getString(SERVER_ADDRESS, null);
    }
    if (prefs.contains(DES_SERVER_ADDRESS)) {
        mDESServerAddress = prefs.getString(DES_SERVER_ADDRESS, null);
    }
    if (prefs.contains(USE_APP_SERVER)) {
        mUseAppServer = prefs.getBoolean(USE_APP_SERVER, false);
    }
    if (prefs.contains(APP_ID)) {
        mAppId = prefs.getString(APP_ID, null);
    }
    if (prefs.contains(USER_ID)) {
        mUserId = prefs.getString(USER_ID, null);
    }

    requestWindowFeature(Window.FEATURE_NO_TITLE);
}

From source file:com.mindprotectionkit.freephone.RedPhoneService.java

private byte[] getZID() {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    if (preferences.contains("ZID")) {
        try {/*from  w w  w  .  j ava2 s  .  com*/
            return Base64.decode(preferences.getString("ZID", null));
        } catch (IOException e) {
            return setZID();
        }
    } else {
        return setZID();
    }
}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

private void setSaved(int index) {
    SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE);
    SharedPreferences.Editor prefsEditor = prefs.edit();
    Location location = new Location("POINT_LOCATION");
    location.setLatitude(0);/*  w w  w  . j  a va2  s. c om*/
    location.setLongitude(0);
    int setRad = 0;
    String setAddress = "";
    if (prefs.contains(POINT_LATITUDE_KEY + index)) {
        location.setLatitude(prefs.getFloat(POINT_LATITUDE_KEY + index, 0));
    }
    if (prefs.contains(POINT_LONGITUDE_KEY + index)) {
        location.setLongitude(prefs.getFloat(POINT_LONGITUDE_KEY + index, 0));
    }
    if (prefs.contains(POINT_RADIUS_KEY + index)) {
        setRad = prefs.getInt(POINT_RADIUS_KEY + index, 0);
    }
    if (prefs.contains(POINT_ADDRESS_KEY + index)) {
        setAddress = prefs.getString(POINT_ADDRESS_KEY + index, "");
    }

    touchSaveIndex(1);

    float setLat = (float) location.getLatitude();
    float setLong = (float) location.getLongitude();
    prefsEditor.putFloat(SAVED_LATITUDE_KEY + touchSaveIndex(0), setLat);
    prefsEditor.putFloat(SAVED_LONGITUDE_KEY + touchSaveIndex(0), setLong);
    prefsEditor.putInt(SAVED_RADIUS_KEY + touchSaveIndex(0), setRad);
    prefsEditor.putString(SAVED_ADDRESS_KEY + touchSaveIndex(0), setAddress);
    prefsEditor.commit();
}

From source file:org.opendatakit.common.android.logic.PropertiesSingleton.java

public boolean containsKey(String propertyName) {
    if (isSecureProperty(propertyName)) {
        // this needs to be stored in a protected area
        SharedPreferences sharedPreferences = getSharedPreferences(mBaseContext);
        return (sharedPreferences == null) ? false : sharedPreferences.contains(mAppName + "_" + propertyName);
    } else if (isDeviceProperty(propertyName)) {
        return mDeviceProps.containsKey(propertyName);
    } else {/*  w  w w .  j a  v a 2  s  . c  om*/
        return mGeneralProps.containsKey(propertyName);
    }
}

From source file:com.awadev.itslearningautologin.MainActivity.java

public void checkAnalytics() {
    SharedPreferences sharedPref = getSharedPreferences(LoginActivity.PREFS_NAME, Context.MODE_PRIVATE);
    final SharedPreferences.Editor editor = sharedPref.edit();

    if (!sharedPref.contains("com.awa.itslearning.ENABLE_ANALYTICS")) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setTitle(getString(R.string.allow_analytics_title))
                .setMessage(getString(R.string.allow_analytics_message)).setPositiveButton(
                        getString(R.string.allow_analytics_yes), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                editor.putBoolean("com.awa.itslearning.ENABLE_ANALYTICS", true);
                                editor.apply();
                            }//from  w  w  w. java  2 s .c o m
                        })
                .setNegativeButton(getString(R.string.allow_analytics_no),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                editor.putBoolean("com.awa.itslearning.ENABLE_ANALYTICS", false);
                                editor.apply();
                            }
                        });

        AlertDialog dialog = builder.create();
        dialog.show();
    }
}

From source file:im.neon.contacts.ContactsManager.java

/**
 * Tells if the contacts book access has been requested.
 * For android > M devices, it only tells if the permission has been granted.
 * @return true it was requested once// w w w.  j av a 2s. c  o m
 */
public boolean isContactBookAccessRequested() {
    if (Build.VERSION.SDK_INT >= 23) {
        return (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(mContext,
                Manifest.permission.READ_CONTACTS));
    } else {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
        return preferences.contains(CONTACTS_BOOK_ACCESS_KEY);
    }
}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

private void recent() {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE);

    for (int i = 1; i <= 5; i++) {
        Location location = new Location("POINT_LOCATION");
        String address = prefs.getString(POINT_ADDRESS_KEY + i, "");
        location.setLatitude(0);/* w  w w . j  a  va 2  s. c o  m*/
        location.setLongitude(0);
        if (prefs.contains(POINT_LATITUDE_KEY + i)) {
            location.setLatitude(prefs.getFloat(POINT_LATITUDE_KEY + i, 0));
        }
        if (prefs.contains(POINT_LONGITUDE_KEY + i)) {
            location.setLongitude(prefs.getFloat(POINT_LONGITUDE_KEY + i, 0));
        }

        LinearLayout RecentParent = (LinearLayout) V.findViewById(R.id.group_recent);
        View Recent = inflater.inflate(R.layout.saved_item, null);
        Recent.setOnClickListener(this);

        CharSequence name;
        if (!address.equals("")) {
            name = address;
            ((TextView) Recent.findViewById(R.id.savedLabel)).setTextColor(0xDDFFFFFF);
            ((CompoundButton) Recent.findViewById(R.id.saveCB)).setOnCheckedChangeListener(this);
        } else {
            name = "No Recent Alarms";
            ((TextView) Recent.findViewById(R.id.savedLabel)).setTextColor(0xDD999999);
            Recent.findViewById(R.id.saveCB).setEnabled(false);
        }

        ((TextView) Recent.findViewById(R.id.savedLabel)).setText(name);
        ((TextView) Recent.findViewById(R.id.savedLabel)).setTextSize(14);
        Recent.findViewById(R.id.saveCB).setTag(i);
        Recent.setId(i);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        RecentParent.setLayoutParams(params);
        RecentParent.addView(Recent);
    }
}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

private void saved() {
    ////////S-A-V-E-D///////////
    LinearLayout SavedParent = (LinearLayout) V.findViewById(R.id.group_pinned);
    LayoutInflater inflater = getActivity().getLayoutInflater();
    //If there are no pinned alarms
    if (touchSaveIndex(0) < 1) {
        View Saved = inflater.inflate(R.layout.saved_item, null);
        Saved.setOnClickListener(this);

        ((TextView) Saved.findViewById(R.id.savedLabel)).setText("No Pinned Alarms");
        ((TextView) Saved.findViewById(R.id.savedLabel)).setTextColor(0xDD999999);
        ((CheckBox) Saved.findViewById(R.id.saveCB)).setChecked(true);
        Saved.findViewById(R.id.saveCB).setEnabled(false);

        ((CompoundButton) Saved.findViewById(R.id.saveCB)).setOnCheckedChangeListener(this);

        LinearLayout.LayoutParams sparams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        SavedParent.setLayoutParams(sparams);
        SavedParent.addView(Saved);/*  w  ww .  j a  va2  s. com*/
    } else {
        for (int i = 1; i <= touchSaveIndex(0); i++) {

            //                View Saved = new View(getApplicationContext());
            View Saved = inflater.inflate(R.layout.saved_item, null);
            Saved.setOnClickListener(this);

            SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet",
                    Context.MODE_WORLD_WRITEABLE);
            Location location = new Location("POINT_LOCATION");
            location.setLatitude(0);
            location.setLongitude(0);
            String address = "No Pinned Alarms";
            if (prefs.contains(SAVED_LATITUDE_KEY + i)) {
                location.setLatitude(prefs.getFloat(SAVED_LATITUDE_KEY + i, 0));
            }
            if (prefs.contains(SAVED_LONGITUDE_KEY + i)) {
                location.setLongitude(prefs.getFloat(SAVED_LONGITUDE_KEY + i, 0));
            }
            if (prefs.contains(SAVED_ADDRESS_KEY + i)) {
                address = (prefs.getString(SAVED_ADDRESS_KEY + i, ""));
            }

            CharSequence name;
            if (!address.equals("")) {
                name = address;
                ((TextView) Saved.findViewById(R.id.savedLabel)).setTextColor(0xDDFFFFFF);
                ((CheckBox) Saved.findViewById(R.id.saveCB)).setChecked(true);
                Saved.findViewById(R.id.saveCB).setTag(i);
                ((CompoundButton) Saved.findViewById(R.id.saveCB)).setOnCheckedChangeListener(this);
            } else {
                name = "Error";
                ((TextView) Saved.findViewById(R.id.savedLabel)).setTextColor(0xDD999999);
                ((CheckBox) Saved.findViewById(R.id.saveCB)).setChecked(true);
                Saved.findViewById(R.id.saveCB).setEnabled(false);
            }

            ((CompoundButton) Saved.findViewById(R.id.saveCB)).setOnCheckedChangeListener(this);
            ((TextView) Saved.findViewById(R.id.savedLabel)).setText(name);
            ((TextView) Saved.findViewById(R.id.savedLabel)).setTextSize(14);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            SavedParent.setLayoutParams(params);
            SavedParent.addView(Saved);

        }
    }
}

From source file:com.amazon.appstream.fireclient.FireClientActivity.java

/**
 * Initialization. Sets up the app and spawns the connection
 * dialog.//w ww.  java2  s .c  o  m
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.v(TAG, "onCreate");
    mGestureDetector = new GestureDetector(this, this);

    mGestureDetector.setIsLongpressEnabled(false);

    mTouchscreenAvailable = getPackageManager().hasSystemFeature("android.hardware.touchscreen");

    SharedPreferences prefs = getSharedPreferences("main", MODE_PRIVATE);
    if (prefs.contains(SERVER_ADDRESS)) {
        mServerAddress = prefs.getString(SERVER_ADDRESS, null);
    }
    if (prefs.contains(DES_SERVER_ADDRESS)) {
        mDESServerAddress = prefs.getString(DES_SERVER_ADDRESS, null);
    }
    if (prefs.contains(USE_APP_SERVER)) {
        mUseAppServer = prefs.getBoolean(USE_APP_SERVER, false);
    }
    if (prefs.contains(APP_ID)) {
        mAppId = prefs.getString(APP_ID, null);
    }
    if (prefs.contains(USER_ID)) {
        mUserId = prefs.getString(USER_ID, null);
    }

    requestWindowFeature(Window.FEATURE_NO_TITLE);
}