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:de.baumann.browser.popups.Popup_history.java

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

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    getWindow().setStatusBarColor(ContextCompat.getColor(Popup_history.this, R.color.colorThreeDark));

    setContentView(R.layout.activity_popup);
    helper_main.onStart(Popup_history.this);

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

    if (sharedPref.getBoolean("isOpened", false)) {
        helper_main.checkPin(Popup_history.this);
    }// w  w w .ja v  a2s .co  m

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    editText = (EditText) findViewById(R.id.editText);
    editText.setVisibility(View.GONE);
    editText.setHint(R.string.app_search_hint);
    editText.clearFocus();
    urlBar = (TextView) findViewById(R.id.urlBar);
    setTitle();

    listView = (ListView) findViewById(R.id.list);

    //calling Notes_DbAdapter
    db = new DbAdapter_History(this);
    db.open();

    setHistoryList();
}

From source file:de.baumann.browser.popups.Popup_readLater.java

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

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    getWindow().setStatusBarColor(ContextCompat.getColor(Popup_readLater.this, R.color.colorThreeDark));

    setContentView(R.layout.activity_popup);
    helper_main.onStart(Popup_readLater.this);

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

    if (sharedPref.getBoolean("isOpened", false)) {
        helper_main.checkPin(Popup_readLater.this);
    }/*from  w w  w . j a  v  a  2 s . com*/

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    editText = (EditText) findViewById(R.id.editText);
    editText.setVisibility(View.GONE);
    editText.setHint(R.string.app_search_hint);
    editText.clearFocus();
    urlBar = (TextView) findViewById(R.id.urlBar);
    setTitle();

    listView = (ListView) findViewById(R.id.list);

    //calling Notes_DbAdapter
    db = new DbAdapter_ReadLater(this);
    db.open();

    setReadLaterList();
    onNewIntent(getIntent());
}

From source file:com.doplgangr.secrecy.views.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    int versionNumber = PreferenceManager.getDefaultSharedPreferences(context).getInt(Config.APP_VERSION_NUMBER,
            1);/*  w  ww.j  av a2  s. c o m*/
    mNavigation = (NavListView) findViewById(R.id.left_drawer_list);
    mDrawer = findViewById(R.id.left_drawer);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);

    Storage.deleteTemp(); //Start clean
    VaultHolder.getInstance().clear();
    fragmentManager = getSupportFragmentManager();
    switchFragment(0);
    setSupportActionBar(mToolbar);
    if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(Config.SHOW_STEALTH_MODE_TUTORIAL,
            false)) {
        onFirstLaunch();
    }
    PackageInfo pInfo;
    try {
        pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        Util.log("Cannot get package info, abort.");
        return;
    }
    if (pInfo != null) {
        if (pInfo.versionCode != versionNumber)
            addFragment(new UpdateManager(), R.anim.slide_in_right, R.anim.fadeout);
    }
    mNavigation.addNavigationItem(CustomApp.context.getString(R.string.Page_header__vaults),
            R.drawable.ic_vault, false);

    mNavigation.addNavigationItem(CustomApp.context.getString(R.string.Page_header__settings),
            R.drawable.ic_setting, false);
    mNavigation.addNavigationItem(CustomApp.context.getString(R.string.action__donate), R.drawable.ic_love,
            false);
    mNavigation.addNavigationItem(CustomApp.context.getString(R.string.action__support), R.drawable.ic_help,
            false);
    mNavigation.setNavigationItemClickListener(new NavListView.NavigationItemClickListener() {
        @Override
        public void onNavigationItemSelected(String item, ArrayList<NavItem> items, int position) {
            Util.log(position, "Clicked");
            switchFragment(position);
            mDrawerLayout.closeDrawers();
        }
    });

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, 0, 0) {

        /**
         * Called when a drawer has settled in a completely closed state.
         */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        /**
         * Called when a drawer has settled in a completely open state.
         */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    Util.loadSelectedImageSize(PreferenceManager.getDefaultSharedPreferences(context)
            .getString(Config.IMAGE_SIZE, Config.IMAGE_SIZE_DEFAULT));
    showHelpDeskTutorial();
}

From source file:ai.api.lejossample.MainActivity.java

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

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

    commandText = (TextView) findViewById(R.id.commandText);
    connectButton = (Button) findViewById(R.id.connectButton);
    addressEdit = (EditText) findViewById(R.id.addressEdit);

    aiButton = (AIButton) findViewById(R.id.micButton);

    handler = new Handler(Looper.getMainLooper());

    initTTS();/*from www  .  j  av  a2 s .  com*/
}

From source file:com.galois.qrstream.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setupUI();/*from ww w .  j  a  v a  2  s.c  o m*/
    hideUI();

    fragmentManager = getFragmentManager();
    transmitFragment = new TransmitFragment();
    receiveFragment = new ReceiveFragment();
    settingsFragment = new SettingsFragment();

    // Load application's default settings before user opens settings
    // screen because we want Rx and Tx to run with defaults.
    PreferenceManager.setDefaultValues(this, com.galois.qrstream.lib.R.xml.settings, false);

    if (savedInstanceState == null) {
        Intent startingIntent = getIntent();
        Log.d(Constants.APP_TAG, "startingIntent  " + startingIntent.getAction());
        if (startingIntent.getAction().equals(Intent.ACTION_SEND)) {
            try {
                Job job = buildJobFromIntent(startingIntent);
                Bundle bundle = new Bundle();
                bundle.putSerializable("job", job);
                transmitFragment.setArguments(bundle);
                showFragment(transmitFragment);
            } catch (IllegalArgumentException e) {
                Toast.makeText(this, "Unsupported media type.", Toast.LENGTH_LONG).show();
                finish();
            }
        } else {
            showFragment(receiveFragment);
        }
    }
}

From source file:edu.usf.cutr.siri.android.ui.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    setTheme(com.actionbarsherlock.R.style.Theme_Sherlock);
    super.onCreate(savedInstanceState);

    // Set the default values from the XML file if this is the first
    // execution of the app
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    // Get whether or not to cache Jackson objects
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    boolean cacheJacksonObjects = sharedPref.getBoolean(Preferences.KEY_CACHE_JACKSON_OBJECTS, false);

    if (cacheJacksonObjects) {
        Log.d(TAG, "Preference is set to cache Jackson objects, forcing a cache read now in "
                + "MainActivity.onCreate() to hide latency from user...");
        /**/* w  ww . ja va 2s.  c  om*/
         * Tell Jackson to retrieve any cached objects now, in an attempt to
         * hide the initialization latency from the user. Caching allows the
         * re-use of Jackson ObjectMapper, ObjectReader, and XmlReader
         * objects from previous VM executions to reduce cold-start times.
         */
        SiriJacksonConfig.setUsingCache(true, getApplicationContext());
        SiriJacksonConfig.forceCacheRead();
    }

    // Request use of spinner for showing indeterminate progress, to show
    // the user somethings going on during long-running operations
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_main);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final com.actionbarsherlock.app.ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setTitle(getApplicationContext().getText(R.string.app_name));

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have a
    // reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the listener for when this tab is
        // selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    //Fix bug in HTTP connection pool for Android 2.1 and lower
    disableConnectionReuseIfNecessary();

    // Hide the indeterminate progress bar on the activity until we need it
    setProgressBarIndeterminateVisibility(Boolean.FALSE);
}

From source file:sp.esolz.connex.admin.apprtc.ConnectActivity.java

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

    // Get setting keys.
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    keyprefVideoCallEnabled = getString(R.string.pref_videocall_key);
    keyprefResolution = getString(R.string.pref_resolution_key);
    keyprefFps = getString(R.string.pref_fps_key);
    keyprefCaptureQualitySlider = getString(R.string.pref_capturequalityslider_key);
    keyprefVideoBitrateType = getString(R.string.pref_startvideobitrate_key);
    keyprefVideoBitrateValue = getString(R.string.pref_startvideobitratevalue_key);
    keyprefVideoCodec = getString(R.string.pref_videocodec_key);
    keyprefHwCodecAcceleration = getString(R.string.pref_hwcodec_key);
    keyprefCaptureToTexture = getString(R.string.pref_capturetotexture_key);
    keyprefAudioBitrateType = getString(R.string.pref_startaudiobitrate_key);
    keyprefAudioBitrateValue = getString(R.string.pref_startaudiobitratevalue_key);
    keyprefAudioCodec = getString(R.string.pref_audiocodec_key);
    keyprefNoAudioProcessingPipeline = getString(R.string.pref_noaudioprocessing_key);
    keyprefAecDump = getString(R.string.pref_aecdump_key);
    keyprefOpenSLES = getString(R.string.pref_opensles_key);
    keyprefDisplayHud = getString(R.string.pref_displayhud_key);
    keyprefTracing = getString(R.string.pref_tracing_key);
    keyprefRoomServerUrl = getString(R.string.pref_room_server_url_key);
    keyprefRoom = getString(R.string.pref_room_key);
    keyprefRoomList = getString(R.string.pref_room_list_key);

    setContentView(R.layout.activity_connect);

    //=============permission management

    permissionChk();/*from ww w. j  a va  2  s .c o  m*/

}

From source file:de.baumann.browser.popups.Popup_bookmarks.java

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

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    getWindow().setStatusBarColor(ContextCompat.getColor(Popup_bookmarks.this, R.color.colorThreeDark));

    setContentView(R.layout.activity_popup);
    helper_main.onStart(Popup_bookmarks.this);

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

    if (sharedPref.getBoolean("isOpened", false)) {
        helper_main.checkPin(Popup_bookmarks.this);
    }/*from  www  .  j  a  v  a2s.  co m*/

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    editText = (EditText) findViewById(R.id.editText);
    editText.setVisibility(View.GONE);
    editText.setHint(R.string.app_search_hint);
    editText.clearFocus();
    urlBar = (TextView) findViewById(R.id.urlBar);
    setTitle();

    listView = (ListView) findViewById(R.id.list);

    //calling Notes_DbAdapter
    db = new DbAdapter_Bookmarks(this);
    db.open();

    setBookmarksList();
}

From source file:com.ternup.caddisfly.activity.MainActivity.java

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

    MainApp mainApp = (MainApp) getApplicationContext();
    assert getApplicationContext() != null;

    // Set theme according to preference
    mainApp.CurrentTheme = PreferencesUtils.getInt(this, R.string.currentTheme, R.style.AppTheme_Light);

    this.setTheme(mainApp.CurrentTheme);

    setContentView(R.layout.activity_main);

    mTitle = getTitle();//from w w  w.  j  a  va2  s.c  om

    mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager()
            .findFragmentById(R.id.navigation_drawer);

    // Set up the drawer.
    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));

    // Set default values for preference settings
    PreferenceManager.setDefaultValues(this, R.xml.fragmented_preferences, false);

    if (savedInstanceState == null) {
        displayView(Globals.HOME_SCREEN_INDEX, false);
    }

    // last update check date
    Calendar lastCheckDate = Calendar.getInstance();
    lastCheckDate.setTimeInMillis(updateLastCheck);

    Calendar currentDate = Calendar.getInstance();

    if (DateUtils.getDaysDifference(lastCheckDate, currentDate) > 0) {
        checkUpdate(true);
    }

    // enable ActionBar app icon to behave as action to toggle nav drawer
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
    }

    int index = getCurrentFragmentIndex();
    showCheckUpdateOption = index == Globals.SETTINGS_SCREEN_INDEX;
    showCheckUpdateOption = index == Globals.ABOUT_SCREEN_INDEX;
}

From source file:com.abhijitvalluri.android.fitnotifications.HomeActivity.java

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

    // Set a Toolbar to replace the ActionBar.
    mToolbar = (Toolbar) findViewById(R.id.home_toolbar);
    setSupportActionBar(mToolbar);/*from www .  ja v  a  2  s  .  co  m*/

    LAUNCH_ACTIVITY_ANIM_BUNDLE = ActivityOptions
            .makeCustomAnimation(HomeActivity.this, R.transition.left_in, R.transition.left_out).toBundle();

    // Initialize settings to defaults

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new SmoothDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open,
            R.string.drawer_close);

    mDrawerLayout.addDrawerListener(mDrawerToggle);

    mNavDrawer = (NavigationView) findViewById(R.id.navDrawer);
    setupDrawerContent(mNavDrawer);

    PreferenceManager.setDefaultValues(this, R.xml.main_settings, false);
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    Fragment frag = new HomeFragment();

    // Add a new fragment to the appropriate view element
    FragmentManager fragmentManager = getSupportFragmentManager();
    if (fragmentManager.findFragmentById(R.id.flContent) == null) {
        fragmentManager.beginTransaction().add(R.id.flContent, frag).commit();
    }

    if (mPreferences.getInt(getString(R.string.version_key), 0) < Constants.VERSION_CODE
            && mPreferences.getBoolean(getString(R.string.done_first_launch_key), false)) {
        // App has been updated
        AppSelectionsStore store = AppSelectionsStore.get(this);
        List<AppSelection> appSelections = store.getAppSelections();

        for (AppSelection selection : appSelections) {
            if (selection.getStartTime() == 0 && (selection.getStopTime() == 1439)
                    || selection.getStopTime() == 0) {
                // Default setting should be 11:59pm for end time.
                selection.setStopTimeHour(23);
                selection.setStopTimeMinute(59);
                store.updateAppSelection(selection);
            }
        }

        mNavDrawer.setCheckedItem(R.id.nav_whats_new);
        setTitle(R.string.whats_new);
        frag = InfoFragment.newInstance(getString(R.string.whats_new_text));
        fragmentManager.beginTransaction().replace(R.id.flContent, frag).commit();

        mPreferences.edit().putInt(getString(R.string.version_key), Constants.VERSION_CODE).apply();
    }

    if (!mPreferences.getBoolean(getString(R.string.done_first_launch_key), false)) { // This is the first launch
        startActivityForResult(new Intent(HomeActivity.this, AppIntroActivity.class),
                APP_INTRO_FIRST_LAUNCH_INTENT, LAUNCH_ACTIVITY_ANIM_BUNDLE);
    }

}