Example usage for android.content SharedPreferences getBoolean

List of usage examples for android.content SharedPreferences getBoolean

Introduction

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

Prototype

boolean getBoolean(String key, boolean defValue);

Source Link

Document

Retrieve a boolean value from the preferences.

Usage

From source file:ac.robinson.mediaphone.activity.TemplateBrowserActivity.java

@Override
protected void configureInterfacePreferences(SharedPreferences mediaPhoneSettings) {
    // the soft back button (necessary in some circumstances)
    int newVisibility = View.VISIBLE;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
            || !mediaPhoneSettings.getBoolean(getString(R.string.key_show_back_button),
                    getResources().getBoolean(R.bool.default_show_back_button))) {
        newVisibility = View.GONE;
    }/*from   w w w .  j  a  v a  2  s  .co m*/
    findViewById(R.id.button_finished_templates).setVisibility(newVisibility);
}

From source file:uk.org.openseizuredetector.MainActivity.java

@Override
protected void onStart() {
    super.onStart();
    SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    boolean audibleAlarm = SP.getBoolean("AudibleAlarm", true);
    Log.v(TAG, "onStart - auidbleAlarm = " + audibleAlarm);

    TextView tv;//from   w w  w .j a  va  2  s . c om
    tv = (TextView) findViewById(R.id.versionTv);
    String versionName = "unknown";
    // From http://stackoverflow.com/questions/4471025/
    //         how-can-you-get-the-manifest-version-number-
    //         from-the-apps-layout-xml-variable
    final PackageManager packageManager = getPackageManager();
    if (packageManager != null) {
        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), 0);
            versionName = packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            Log.v(TAG, "failed to find versionName");
            versionName = null;
        }
    }
    tv.setText("OpenSeizureDetector Server Version " + versionName);

    if (!isServerRunning()) {
        Log.v(TAG, "Server not Running - Starting Server");
        startServer();
    } else {
        Log.v(TAG, "Server Already Running OK");
    }
    // and bind to it so we can see its data
    bindToServer();

}

From source file:com.github.vseguip.sweet.contacts.SweetConflictResolveActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "onCreate()");
    // getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.conflict_resolver);
    mAccountManager = AccountManager.get(this);
    final Map<String, ISweetContact> localContacts = new HashMap<String, ISweetContact>();
    final Map<String, ISweetContact> sugarContacts = new HashMap<String, ISweetContact>();
    try {/*from   ww  w  . j a  va  2 s  .  c  o  m*/
        retreiveConflicts(localContacts, sugarContacts);
    } catch (Exception ex) {
        Log.e(TAG, "This shouldn't happen " + ex.getMessage());
        ex.printStackTrace();
        quitResolver();
    }
    final TableLayout fieldTable = (TableLayout) findViewById(R.id.fieldTable);
    mButtonPrevConflict = (Button) findViewById(R.id.buttonPreviousConflict);
    mButtonNextConflict = (Button) findViewById(R.id.buttonNextConflict);
    Button buttonCancel = (Button) findViewById(R.id.buttonCancel);
    Button buttonResolve = (Button) findViewById(R.id.buttonResolve);
    mAccount = getIntent().getParcelableExtra("account");
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    mPreferServer = settings.getBoolean(this.getString(R.string.prefer_server_resolve), false);

    task = (SyncResolvedContactsTask) getLastNonConfigurationInstance();

    if (task == null) {
        task = new SyncResolvedContactsTask(this, mAccountManager, mAccount, getString(R.string.account_type));
    } else {
        task.attach(this);
    }

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

    buttonResolve.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            doResolve();

        }
    });
    if ((localContacts.size() >= 0) && (sugarContacts.size() == localContacts.size())) {
        mConflictSet = new ArrayList<String>(localContacts.keySet());
        createResolvedContactsArray(localContacts, sugarContacts);

        mPosResolved = 0;
        mCurrentId = mConflictSet.get(mPosResolved);

        displayConflict(localContacts, sugarContacts, fieldTable);

        mButtonNextConflict.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if ((mPosResolved < mConflictSet.size()) && (mPosResolved < resolvedContacts.length)) {
                    mPosResolved++;
                    mCurrentId = mConflictSet.get(mPosResolved);
                    displayConflict(localContacts, sugarContacts, fieldTable);

                }
            }
        });
        mButtonPrevConflict.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mPosResolved > 0) {
                    mPosResolved--;
                    mCurrentId = mConflictSet.get(mPosResolved);
                    displayConflict(localContacts, sugarContacts, fieldTable);
                }
            }
        });

    } else {
        quitResolver();
        return;
    }

}

From source file:com.baidu.android.voicedemo.ApiActivity.java

private void start() {
    txtLog.setText("");
    print("?");/*from ww  w . jav  a  2 s .  com*/
    Intent intent = new Intent();
    bindParams(intent);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    {

        String args = sp.getString("args", "");
        if (null != args) {
            print("?" + args);
            intent.putExtra("args", args);
        }
    }
    boolean api = sp.getBoolean("api", false);
    if (api) {
        speechEndTime = -1;
        speechRecognizer.startListening(intent);
    } else {
        intent.setAction("com.baidu.action.RECOGNIZE_SPEECH");
        startActivityForResult(intent, REQUEST_UI);
    }

    txtResult.setText("");
}

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

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

    View rootView = inflater.inflate(R.layout._5_community_right, container, false);
    switchBtn = (Switch) rootView.findViewById(R.id.switchBtn);

    SharedPreferences myPrefs = this.getActivity().getSharedPreferences("switch", Context.MODE_PRIVATE);
    if ((myPrefs != null) && (myPrefs.contains("switch"))) {
        switchbool = myPrefs.getBoolean("switch", false);
    }//from ww  w.j  a  v a 2 s  .  com

    switchBtn.setChecked(switchbool);
    listItem = new ArrayList<HashMap<String, String>>();

    switchBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences myPrefs = getActivity().getSharedPreferences("switch", Context.MODE_PRIVATE);
            SharedPreferences.Editor myEditor = myPrefs.edit();
            if (isChecked == true) {
                /*switch  ?*/
                myEditor.putBoolean("switch", true);
                myEditor.commit();
                /*??*/
            } else if (isChecked == false) {
                setGpsNull();
                myEditor.putBoolean("switch", false);
                myEditor.commit();
            }
        }

    });

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

    getGroupName();

    // ? ? 
    map = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map2)).getMap();
    map.setMyLocationEnabled(true);
    map.setOnMarkerClickListener(onMarkerClickedListener); // ? 
    /*gps*/
    //  ? ?  -   
    mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);

    if (switchbool == true) {
        //  ?   
        startLocationService();
    }

    return rootView;
}

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   ww w  . j a  v  a 2s  . c  o  m
    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.android.nobadgift.DashboardActivity.java

protected void displayInfoDialog() {
    if (wishlistClick) {
        urlContent = null;/*from   w w w .j ava  2  s.  co  m*/
        new AlertDialog.Builder(this).setIcon(android.R.drawable.star_big_on)
                .setMessage("Would you like to add \"" + itemName + "\" to this wishlist?")
                .setTitle("Wishlist: " + wishlist_name)
                .setNegativeButton("Add to this Wishlist", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        addToWishlist(wishlist_id);
                    }
                }).setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        urlContent = null;
                    }
                }).show();
    } else {
        SharedPreferences appSharedPrefs = PreferenceManager
                .getDefaultSharedPreferences(this.getApplicationContext());
        Boolean forgetMenu = appSharedPrefs.getBoolean("forgetTipMenu", false);
        if (!forgetMenu) {
            new AlertDialog.Builder(this).setIcon(android.R.drawable.star_big_on).setMessage(
                    "To add this item to a wishlist, simply select one of your available wishlist and accept the confirmation.")
                    .setTitle("Tip: Add To Wishlist")
                    .setNegativeButton("Don't Show Again", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            forgetTipMenu();
                        }
                    }).setPositiveButton("Close", null).show();
        }
    }
}

From source file:com.fairmichael.fintan.websms.connector.fishtext.ConnectorFishtext.java

private void examineSuccessSendResponse(final Context context, final String response,
        final Map<String, String> recipientMap) {
    boolean sentToAll = response.contains("Your message was successfully sent to all recipients");
    String cost, costUnit;//from   w  w  w .  j a  v a 2s  .com
    boolean free = response.contains("sent free") || response.contains(", free.");
    if (free) {
        cost = COST_FREE;
    }
    Matcher matcher = COST_PATTERN.matcher(response);
    if (matcher.find()) {
        cost = matcher.group(2);
        costUnit = FishtextUtil.currencyFix(matcher.group(1));
    } else {
        cost = COST_UNKNOWN;
        costUnit = "";
    }

    if (sentToAll) {
        // Sent to all successfully, just notify with the price
        final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
        final boolean notifySend = p.getBoolean(SUCCESSFUL_SEND_NOTIFICATION_PREFERENCE_ID, true);
        if (notifySend) {
            final String notification = context
                    .getString(R.string.successful_send_notification_fishtext_notification, costUnit + cost);
            Log.d(TAG, "Notifying on successful send: " + notification);
            FishtextUtil.toastNotifyOnMain(context, notification, Toast.LENGTH_SHORT);
        } else {
            Log.d(TAG, "Not notifying on successful send");
        }
    } else {
        // Process invalids
        String invalids = "";
        int invalidCount = 0;
        Matcher invalidMatcher = INVALID_NUMBERS_PATTERN.matcher(response);
        if (invalidMatcher.find()) {
            Log.d(TAG, "Matched invalids " + invalidMatcher.group() + " - " + invalidMatcher.group(1));
            invalids = invalidMatcher.group(1);

            String[] parts = invalids.split(",");
            for (int i = 0; i < parts.length; i++) {
                parts[i] = recipientMap.get(parts[i].trim());
            }

            invalids = FishtextUtil.appendWithSeparator(parts, ", ");
            invalidCount = parts.length;
        }
        int successfulCount = recipientMap.size() - invalidCount;

        if (successfulCount > 0) {
            // Sent to some
            String errorMessage = context.getString(R.string.unsuccessful_send_some_fishtext, successfulCount,
                    costUnit + cost, invalids);
            throw new WebSMSException(errorMessage);
        } else {
            // Sent to none
            String errorMessage = context.getString(R.string.unsuccessful_send_all_fishtext,
                    recipientMap.size(), invalids);
            throw new WebSMSException(errorMessage);
        }

    }
}

From source file:com.intel.xdk.camera.Camera.java

void cameraActivityResult(int resultCode, Intent intent) {
    if (resultCode == Activity.RESULT_OK) {
        //get info from shared prefs
        SharedPreferences prefs = activity.getSharedPreferences(cameraPrefsKey, 0);
        String outputFile = prefs.getString(cameraPrefsFileName, "");
        boolean isPNG = prefs.getBoolean(cameraPrefsIsPNG, false);
        int quality = prefs.getInt(cameraPrefsQuality, 100);
        savePicture(outputFile, quality, isPNG);
    } else {/*from w w  w  . j  a  v  a  2  s  .c om*/
        pictureCancelled();
    }
}

From source file:de.grobox.blitzmail.SendActivity.java

private Properties getPrefs() {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    Crypto crypto = new Crypto(this);

    String recipients = pref.getString("pref_recipient", null);
    String sender = pref.getString("pref_sender", null);

    String server = pref.getString("pref_smtp_server", null);
    String port = pref.getString("pref_smtp_port", null);
    Boolean auth = pref.getBoolean("pref_smtp_auth", false);
    String user = pref.getString("pref_smtp_user", null);
    String password = pref.getString("pref_smtp_pass", null);

    if (recipients == null)
        throw new RuntimeException(
                getString(R.string.error_option_not_set) + " " + getString(R.string.pref_recipient));
    if (sender == null)
        throw new RuntimeException(
                getString(R.string.error_option_not_set) + " " + getString(R.string.pref_sender));
    if (server == null)
        throw new RuntimeException(
                getString(R.string.error_option_not_set) + " " + getString(R.string.pref_smtp_server));
    if (port == null)
        throw new RuntimeException(
                getString(R.string.error_option_not_set) + " " + getString(R.string.pref_smtp_port));
    if (auth) {/*w  w  w . j  ava2  s.c o m*/
        if (user == null)
            throw new RuntimeException(
                    getString(R.string.error_option_not_set) + " " + getString(R.string.pref_smtp_user));
        if (password == null)
            throw new RuntimeException(
                    getString(R.string.error_option_not_set) + " " + getString(R.string.pref_smtp_pass));

        // Decrypt password
        password = crypto.decrypt(password);
    }

    Properties props = new Properties();
    props.setProperty("mail.transport.protocol", "smtp");
    props.setProperty("mail.host", server);
    props.setProperty("mail.user",
            pref.getString("pref_sender_name", getString(R.string.app_name)) + " <" + sender + ">");
    props.setProperty("mail.smtp.auth", String.valueOf(auth));
    props.setProperty("mail.smtp.port", port);
    props.setProperty("mail.smtp.recipients", recipients);
    props.setProperty("mail.smtp.quitwait", "false");

    if (auth) {
        // set username and password
        props.setProperty("mail.smtp.user", user);
        props.setProperty("mail.smtp.pass", password);

        // set encryption properties
        if (pref.getString("pref_smtp_encryption", "").equals("ssl")) {
            Log.i("SendActivity", "Using SSL Encryption...");
            props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
            props.setProperty("mail.smtp.socketFactory.port", port);
            props.setProperty("mail.smtp.socketFactory.fallback", "false");
            props.setProperty("mail.smtp.ssl.checkserveridentity", "true");
        } else if (pref.getString("pref_smtp_encryption", "").equals("tls")) {
            Log.i("SendActivity", "Using TLS Encryption...");
            props.setProperty("mail.smtp.starttls.enable", "true");
        }
    } else {
        // set some hostname for proper HELO greeting
        props.setProperty("mail.smtp.localhost", "android.com");
    }

    return props;
}