Example usage for android.preference PreferenceManager setDefaultValues

List of usage examples for android.preference PreferenceManager setDefaultValues

Introduction

In this page you can find the example usage for android.preference PreferenceManager setDefaultValues.

Prototype

public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain) 

Source Link

Document

Sets the default values from an XML preference file by reading the values defined by each Preference item's android:defaultValue attribute.

Usage

From source file:cc.softwarefactory.lokki.android.MainApplication.java

private void loadSetting() {
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    visible = PreferenceUtils.getBoolean(getApplicationContext(), PreferenceUtils.KEY_SETTING_VISIBILITY);
    Log.e(TAG, "Visible: " + visible);
}

From source file:de.baumann.hhsmoodle.data_bookmarks.Bookmarks_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_screen_notes, container, false);

    PreferenceManager.setDefaultValues(getActivity(), R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    if (sharedPref.getString("default_bookmarks", "no").equals("no")) {
        Bookmarks_helper.insertDefaultBookmarks(getActivity());
        sharedPref.edit().putString("default_bookmarks", "yes").apply();
    }//  www .j a  v  a 2  s .c o m

    imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header);
    helper_main.setImageHeader(getActivity(), imgHeader);

    filter_layout = (RelativeLayout) rootView.findViewById(R.id.filter_layout);
    filter_layout.setVisibility(View.GONE);
    lv = (ListView) rootView.findViewById(R.id.listNotes);
    filter = (EditText) rootView.findViewById(R.id.myFilter);

    ImageButton ib_hideKeyboard = (ImageButton) rootView.findViewById(R.id.ib_hideKeyboard);
    ib_hideKeyboard.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (filter.getText().length() > 0) {
                filter.setText("");
            } else {
                setTitle();
                helper_main.hideFilter(getActivity(), filter_layout, imgHeader);
                setBookmarksList();
            }
        }
    });

    FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    fab.setVisibility(View.GONE);

    //calling Notes_DbAdapter
    db = new Bookmarks_DbAdapter(getActivity());
    db.open();

    setBookmarksList();
    setHasOptionsMenu(true);

    return rootView;
}

From source file:org.adblockplus.android.Preferences.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.serviceBinder = new ServiceBinder(this).setOnConnectHandler(new ServiceBinder.OnConnectHandler() {
        @Override//from  w w  w .j  a v  a 2s  .com
        public void onConnect(final ProxyService proxyService) {
            if (proxyService.isManual() && !proxyService.isRegistered()) {
                Preferences.this.showConfigurationMsg(Preferences.this.getString(R.string.msg_configuration));
            }
        }
    });

    PreferenceManager.setDefaultValues(this, R.xml.preferences, true);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_advanced, true);
    setContentView(R.layout.preferences);
    addPreferencesFromResource(R.xml.preferences);

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Check if we need to update assets
    final int lastVersion = prefs.getInt(getString(R.string.pref_version), 0);
    try {
        final int thisVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
        if (lastVersion != thisVersion) {
            copyAssets();
            final SharedPreferences.Editor editor = prefs.edit();
            editor.putInt(getString(R.string.pref_version), thisVersion);
            editor.commit();
        }
    } catch (final NameNotFoundException e) {
        copyAssets();
    }
}

From source file:io.rapidpro.androidchannel.RapidPro.java

@Override
public void onCreate() {
    super.onCreate();

    PreferenceManager.setDefaultValues(this, R.layout.settings, false);

    // earlier versions of android are allowed to have higher message throughput
    // before Build.VERSION_CODES.ICE_CREAM_SANDWICH which is 14
    if (Build.VERSION.SDK_INT < 14) {
        MESSAGE_THROTTLE = 100;/*w  w w. ja  v  a2s  .  c  o m*/
        MESSAGE_THROTTLE_MINUTES = 60;
        MESSAGE_THROTTLE_WINDOW = 1000 * 60 * (MESSAGE_THROTTLE_MINUTES + 2);
    }

    s_this = this;

    // register our sms modem
    m_modem = new SMSModem(this, new SMSListener());

    // register our Incoming SMS listener
    m_incomingSMSObserver = new IncomingSMSObserver();
    getContentResolver().registerContentObserver(Uri.parse("content://sms"), true, m_incomingSMSObserver);

    // register our call listener
    m_callObserver = new CallObserver();
    getContentResolver().registerContentObserver(Calls.CONTENT_URI, true, m_callObserver);

    // register for device details
    IntentFilter statusChanged = new IntentFilter();
    statusChanged.addAction(Intent.ACTION_BATTERY_CHANGED);
    statusChanged.addAction(ConnectivityManager.CONNECTIVITY_ACTION);

    StatusReceiver receiver = new StatusReceiver();
    getBaseContext().registerReceiver(receiver, statusChanged);

    WakefulIntentService.cancelAlarms(this);
    WakefulIntentService.scheduleAlarms(new RapidProAlarmListener(), this);

    refreshInstalledPacks();

    updateNotification();
}

From source file:com.cloudant.todo.TodoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d(LOG_TAG, "onCreate()");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_todo);
    //        EventsRepositories EventRepo = new EventsRepositories(this,"events",new String[]{"FWNHHMBRNUM","voided","providerId"});
    //        try {
    //            EventsProcessor eventsProcessor = new EventsProcessor(new JSONObject(getResources().getString(R.string.jsonmapconfig)),new JSONObject(getResources().getString(R.string.jsonevent)));
    //            EventRepo.insertValues(EventRepo.createValuesFor(eventsProcessor.createEventObject()));
    //        } catch (JSONException e) {
    //            e.printStackTrace();
    //        }/*from  w w w  .j a va2 s  .c o  m*/
    // Load default settings when we're first created.
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    // Register to listen to the setting changes because replicators
    // uses information managed by shared preference.
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.registerOnSharedPreferenceChangeListener(this);

    // Protect creation of static variable.
    if (sTasks == null) {
        // Model needs to stay in existence for lifetime of app.
        this.sTasks = new TasksModel(this.getApplicationContext());
    }

    // Register this activity as the listener to replication updates
    // while its active.
    this.sTasks.setReplicationListener(this);

    // Load the tasks from the model
    this.reloadTasksFromModel();
}

From source file:de.baumann.quitsmoking.fragments.FragmentNotes.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_screen_notes, container, false);

    PreferenceManager.setDefaultValues(getActivity(), R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
    setHasOptionsMenu(true);/*from ww w . j  a v  a 2  s.  com*/

    listView = (ListView) rootView.findViewById(R.id.notes);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            @SuppressWarnings("unchecked")
            HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position);

            final String title = map.get("title");
            final String cont = map.get("cont");
            final String seqnoStr = map.get("seqno");
            final String icon = map.get("icon");
            final String attachment = map.get("attachment");
            final String create = map.get("createDate");

            final Button attachment2;
            final TextView textInput;

            LayoutInflater inflater = getActivity().getLayoutInflater();

            final ViewGroup nullParent = null;
            View dialogView = inflater.inflate(R.layout.dialog_note_show, nullParent);

            final String attName = attachment.substring(attachment.lastIndexOf("/") + 1);
            final String att = getString(R.string.note_attachment) + ": " + attName;

            attachment2 = (Button) dialogView.findViewById(R.id.button_att);
            if (attName.equals("")) {
                attachment2.setVisibility(View.GONE);
            } else {
                attachment2.setText(att);
            }
            File file2 = new File(attachment);
            if (!file2.exists()) {
                attachment2.setVisibility(View.GONE);
            }

            textInput = (TextView) dialogView.findViewById(R.id.note_text_input);
            textInput.setText(cont);

            attachment2.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    openAtt(attachment);
                }
            });

            final ImageView be = (ImageView) dialogView.findViewById(R.id.imageButtonPri);
            assert be != null;

            switch (icon) {
            case "1":
                be.setImageResource(R.drawable.emoticon_neutral);
                sharedPref.edit().putString("handleTextIcon", "1").apply();
                break;
            case "2":
                be.setImageResource(R.drawable.emoticon_happy);
                sharedPref.edit().putString("handleTextIcon", "2").apply();
                break;
            case "3":
                be.setImageResource(R.drawable.emoticon_sad);
                sharedPref.edit().putString("handleTextIcon", "3").apply();
                break;
            case "4":
                be.setImageResource(R.drawable.emoticon);
                sharedPref.edit().putString("handleTextIcon", "4").apply();
                break;
            case "5":
                be.setImageResource(R.drawable.emoticon_cool);
                sharedPref.edit().putString("handleTextIcon", "5").apply();
                break;
            case "6":
                be.setImageResource(R.drawable.emoticon_dead);
                sharedPref.edit().putString("handleTextIcon", "6").apply();
                break;
            case "7":
                be.setImageResource(R.drawable.emoticon_excited);
                sharedPref.edit().putString("handleTextIcon", "7").apply();
                break;
            case "8":
                be.setImageResource(R.drawable.emoticon_tongue);
                sharedPref.edit().putString("handleTextIcon", "8").apply();
                break;
            case "9":
                be.setImageResource(R.drawable.emoticon_devil);
                sharedPref.edit().putString("handleTextIcon", "9").apply();
                break;
            case "":
                be.setImageResource(R.drawable.emoticon_neutral);
                sharedPref.edit().putString("handleTextIcon", "").apply();
                break;
            }

            android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(getActivity())
                    .setTitle(title).setView(dialogView)
                    .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setNegativeButton(R.string.note_edit, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            sharedPref.edit().putString("handleTextTitle", title)
                                    .putString("handleTextText", cont).putString("handleTextIcon", icon)
                                    .putString("handleTextSeqno", seqnoStr)
                                    .putString("handleTextAttachment", attachment)
                                    .putString("handleTextCreate", create).apply();
                            helper_notes.editNote(getActivity());
                        }
                    });
            dialog.show();
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            @SuppressWarnings("unchecked")
            HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position);

            final String seqnoStr = map.get("seqno");
            final String title = map.get("title");
            final String cont = map.get("cont");
            final String icon = map.get("icon");
            final String attachment = map.get("attachment");
            final String create = map.get("createDate");

            final CharSequence[] options = { getString(R.string.note_edit), getString(R.string.note_share),
                    getString(R.string.note_remove_note) };
            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.goal_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.dismiss();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.note_edit))) {
                                sharedPref.edit().putString("handleTextTitle", title)
                                        .putString("handleTextText", cont).putString("handleTextIcon", icon)
                                        .putString("handleTextSeqno", seqnoStr)
                                        .putString("handleTextAttachment", attachment)
                                        .putString("handleTextAttachment", create).apply();
                                helper_notes.editNote(getActivity());
                            }

                            if (options[item].equals(getString(R.string.note_share))) {
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, cont);
                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.note_remove_note))) {
                                try {
                                    Database_Notes db = new Database_Notes(getActivity());
                                    final int count = db.getRecordCount();
                                    db.close();

                                    if (count == 1) {
                                        Snackbar snackbar = Snackbar.make(listView, R.string.note_remove_cannot,
                                                Snackbar.LENGTH_LONG);
                                        snackbar.show();

                                    } else {
                                        Snackbar snackbar = Snackbar
                                                .make(listView, R.string.note_remove_confirmation,
                                                        Snackbar.LENGTH_LONG)
                                                .setAction(R.string.yes, new View.OnClickListener() {
                                                    @Override
                                                    public void onClick(View view) {
                                                        try {
                                                            Database_Notes db = new Database_Notes(
                                                                    getActivity());
                                                            db.deleteNote(Integer.parseInt(seqnoStr));
                                                            db.close();
                                                            setNotesList();
                                                        } catch (PackageManager.NameNotFoundException e) {
                                                            e.printStackTrace();
                                                        }
                                                    }
                                                });
                                        snackbar.show();
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }).show();

            return true;
        }
    });

    setHasOptionsMenu(true);
    setNotesList();
    return rootView;
}

From source file:com.github.notizklotz.derbunddownloader.issuesgrid.DownloadedIssuesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (BuildConfig.DEBUG) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
    }/*from  w ww.j a  v  a  2s  .  c o  m*/

    PreferenceManager.setDefaultValues(getApplicationContext(), R.xml.preferences, false);

    if (!PreferenceManager.getDefaultSharedPreferences(this).contains(KEY_ALARM_MIGRATED)) {
        Log.i(getClass().getSimpleName(), "Migrating alarms");
        AutomaticIssueDownloadAlarmManager_.getInstance_(this).updateAlarm();
        PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(KEY_ALARM_MIGRATED, true).apply();
    }
}

From source file:paarmann.physikprofil.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    initTabs();/*from  w  w w  . j  a  v a 2s.c  om*/

    isPaused = false;

    findViewById(R.id.progressBar2).setVisibility(View.GONE);
    findViewById(R.id.txtUpdating).setVisibility(View.GONE);

    prefs = getSharedPreferences(PREF_NAME, 0);

    Calendar cal = Calendar.getInstance();

    //Set button texts according to days
    Button btnNextDay = (Button) findViewById(R.id.btnTomorrow);
    Button btnAfterNextDay = (Button) findViewById(R.id.btnAfterTomorrow);
    if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY) {
        btnAfterNextDay.setText("Hausaufgaben zu Montag");
    } else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY
            || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
        btnNextDay.setText("Hausaufgaben zu Montag");
        btnAfterNextDay.setText("Hausaufgaben zu Dienstag");
    }
    if (prefs.getBoolean(PREF_UPDATED, false)) {
        prefs.edit().putBoolean(PREF_UPDATED, false).apply();
        File file = new File(Environment.getExternalStorageDirectory().getPath() + "/physikbioapp-update.apk");
        file.delete();

        showChangelog();
    }

    checkForUpdates(false);
}

From source file:de.baumann.hhsmoodle.data_files.Files_Fragment.java

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

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

    PreferenceManager.setDefaultValues(getActivity(), R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
    sharedPref.edit().putString("files_startFolder", helper_main.appDir().getAbsolutePath()).apply();

    imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header);
    helper_main.setImageHeader(getActivity(), imgHeader);

    filter_layout = (RelativeLayout) rootView.findViewById(R.id.filter_layout);
    filter_layout.setVisibility(View.GONE);
    lv = (ListView) rootView.findViewById(R.id.listNotes);
    filter = (EditText) rootView.findViewById(R.id.myFilter);
    viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);

    ImageButton ib_hideKeyboard = (ImageButton) rootView.findViewById(R.id.ib_hideKeyboard);
    ib_hideKeyboard.setOnClickListener(new View.OnClickListener() {
        @Override/*from  w ww.j a va  2s .co  m*/
        public void onClick(View view) {
            if (filter.getText().length() > 0) {
                filter.setText("");
            } else {
                setTitle();
                helper_main.hideFilter(getActivity(), filter_layout, imgHeader);
                fillFileList();
            }
        }
    });

    FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    fab.setImageResource(R.drawable.home);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            sharedPref.edit().putString("files_startFolder", helper_main.appDir().getAbsolutePath()).apply();
            fillFileList();
        }
    });

    //calling Notes_DbAdapter
    db = new Files_DbAdapter(getActivity());
    db.open();

    fillFileList();
    setHasOptionsMenu(true);

    return rootView;
}

From source file:com.readystatesoftware.ghostlog.GhostLogSettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.mContext = this.getActivity();

    //        Switch mainSwitch = new Switch(mContext);
    //        mainSwitch.setChecked(LogService.isRunning());
    //        mainSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    //            @Override
    //            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
    //                Intent intent = new Intent(mContext, LogService.class);
    //                if (b) {
    //                    if (!LogService.isRunning()) {
    //                        mContext.startService(intent);
    //                    }
    //                } else {
    //                    mContext.stopService(intent);
    //                }
    //            }
    //        });
    ///*from  www.  j a va  2s .  c  o  m*/
    //        final ActionBar bar = mContext.getActionBar();
    //        final ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    //        lp.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
    //        lp.rightMargin = getResources().getDimensionPixelSize(R.dimen.main_switch_margin_right);
    //        bar.setCustomView(mainSwitch, lp);
    //        bar.setDisplayShowCustomEnabled(true);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    if (!mPrefs.getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) {
        PreferenceManager.setDefaultValues(mContext, R.xml.pref_filters, true);
        PreferenceManager.setDefaultValues(mContext, R.xml.pref_appearance, true);
        SharedPreferences.Editor edit = mPrefs.edit();
        edit.putBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, true);
        edit.apply();
    }

    setupSimplePreferencesScreen();
}