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:no.group09.ucsoftwarestore.MainFragmentActivity.java

/**
 * Takes state and creates the application view
 *//*from  w ww . j a va2s  .co m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Getting a reference to the ViewPager defined the layout file
    pager = (ViewPager) findViewById(R.id.pager);

    //Initializing the settings for the application
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    //Initializing the shared preferences
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);

    //Getting fragment manager
    FragmentManager fm = getSupportFragmentManager();

    //Instantiating FragmentPagerAdapter
    pagerAdapter = new MyFragmentPagerAdapter(fm, this);

    //Setting the pagerAdapter to the pager object
    pager.setAdapter(pagerAdapter);

    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();

    if (bundle != null) {
        String category = bundle.getString("category");
        pagerAdapter.page1 = Page.getType(category, 1);
        pagerAdapter.page2 = Page.getType(category, 2);
    }
}

From source file:com.luorrak.ouroboros.catalog.CatalogActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Util.onActivityCreateSetTheme(this, SettingsHelper.getTheme(this));
    super.onCreate(savedInstanceState);
    Ion.getDefault(getApplicationContext()).getCache().setMaxSize(150 * 1024 * 1024);

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    initPostPassword();/* w  w w .  j  a v a 2  s  .co  m*/
    initReplyChecker();

    infiniteDbHelper = new InfiniteDbHelper(getApplicationContext());
    setContentView(R.layout.activity_catalog);
    bindViews();

    board = getIntent().getStringExtra(Util.INTENT_BOARD_NAME);
    replyCheckerIntent = getIntent().getBooleanExtra(Util.INTENT_REPLY_CHECKER, false);
    if (savedInstanceState == null) {
        if (board != null) {
            CatalogFragment catalogFragment = new CatalogFragment().newInstance(board);
            android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager()
                    .beginTransaction();
            fragmentTransaction.replace(R.id.activity_catalog_fragment_container, catalogFragment).commit();
        } else if (replyCheckerIntent) {
            ReplyCheckerFragment replyCheckerFragment = new ReplyCheckerFragment();
            android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager()
                    .beginTransaction();
            fragmentTransaction.replace(R.id.activity_catalog_fragment_container, replyCheckerFragment)
                    .commit();
        } else {
            BoardListFragment boardListFragment = new BoardListFragment();
            android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager()
                    .beginTransaction();
            fragmentTransaction.replace(R.id.activity_catalog_fragment_container, boardListFragment).commit();
        }
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    navigationView.setNavigationItemSelectedListener(this);

    setupWatchlist();

    ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
            R.string.drawer_open, R.string.drawer_close);
    drawerLayout.setDrawerListener(drawerToggle);
    drawerToggle.syncState();
}

From source file:com.richtodd.android.quiltdesign.app.MainActivity.java

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

    PreferenceManager.setDefaultValues(this, R.xml.application_preferences, false);
    PreferenceManager.setDefaultValues(this, R.xml.block_preferences, false);
    PreferenceManager.setDefaultValues(this, R.xml.quilt_preferences, false);
    setContentView(R.layout.activity_main);

    FragmentManager fm = getFragmentManager();

    m_pagerAdapter = new HomeCollectionPagerAdapter(fm);

    m_viewPager = (ViewPager) findViewById(R.id.viewPager);
    m_viewPager.setAdapter(m_pagerAdapter);
    m_viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override/*from  w  w  w  .ja va  2s  .  c  o  m*/
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });

    m_actionBar = getActionBar();
    m_actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    ActionBar.TabListener actionBarTabListener = new TabListener() {

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
        }

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            m_viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        }
    };

    m_actionBar.addTab(m_actionBar.newTab().setText("Blocks").setTabListener(actionBarTabListener));
    m_actionBar.addTab(m_actionBar.newTab().setText("Quilts").setTabListener(actionBarTabListener));
    m_actionBar.addTab(m_actionBar.newTab().setText("Themes").setTabListener(actionBarTabListener));
}

From source file:uk.co.humbell.anoted.MainActivity.java

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

    /*  We setup theme before we call methods to view */
    PreferenceManager.setDefaultValues(this, R.xml.pref_general, false);
    setupTheme();/*from w  w  w .  ja  v  a 2 s .c  o  m*/

    setContentView(R.layout.activity_main);

    mDocumentDrawerFragment = (DocumentDrawerFragment) getFragmentManager()
            .findFragmentById(R.id.navigation_drawer);

    //Setting up DocumentRefs
    mDocumentStore = new AnotedDocumentStore(this);
    mDocumentStore.open();
    mDocumentStore.registerDocumentStoreObserver(this);
    mDocuments = mDocumentStore.getPageOfDocuments(0, 1, new int[] { AnotedDocumentStore.REQUEST_NAME });

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

    //Apply default screen
    getFragmentManager().beginTransaction().replace(R.id.container, new DefaultFragment()).commit();
}

From source file:name.gumartinm.weather.information.activity.MainTabsActivity.java

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

    this.mPager = (ViewPager) this.findViewById(R.id.pager);
    this.mPager.setAdapter(new TabsAdapter(this.getSupportFragmentManager()));

    this.mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from  w w  w . jav a  2s. c om
        public void onPageSelected(final int position) {
            MainTabsActivity.this.getActionBar().setSelectedNavigationItem(position);
        }
    });

    final ActionBar actionBar = this.getActionBar();

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

    // Specify that tabs should be displayed in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Create a tab listener that is called when the user changes tabs.
    final ActionBar.TabListener tabListener = new ActionBar.TabListener() {

        @Override
        public void onTabSelected(final Tab tab, final FragmentTransaction ft) {
            MainTabsActivity.this.mPager.setCurrentItem(tab.getPosition());

        }

        @Override
        public void onTabUnselected(final Tab tab, final FragmentTransaction ft) {

        }

        @Override
        public void onTabReselected(final Tab tab, final FragmentTransaction ft) {

        }

    };

    actionBar.addTab(actionBar.newTab().setText(this.getString(R.string.text_tab_currently))
            .setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(this.getString(R.string.text_tab_five_days_forecast))
            .setTabListener(tabListener));
}

From source file:com.davidmiguel.gobees.apiaries.ApiariesActivity.java

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

    // Set up the toolbar
    AndroidUtils.setUpToolbar(this, true);

    // Set up the navigation drawer.
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerLayout.setStatusBarBackground(R.color.colorPrimaryDark);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }//from w w w .j av  a  2 s. c o  m

    // Add fragment to the activity
    ApiariesFragment apiariesFragment = (ApiariesFragment) getSupportFragmentManager()
            .findFragmentById(R.id.contentFrame);
    if (apiariesFragment == null) {
        // Create the fragment
        apiariesFragment = ApiariesFragment.newInstance();
        AndroidUtils.addFragmentToActivity(getSupportFragmentManager(), apiariesFragment, R.id.contentFrame);
    }

    // Set default preferences values
    PreferenceManager.setDefaultValues(this, R.xml.general_settings, false);

    // Create the presenter
    new ApiariesPresenter(goBeesRepository, apiariesFragment);
}

From source file:net.sf.diningout.app.AppApplication.java

@Override
public void onVersionChanged(int oldCode, String oldName, int newCode, String newName) {
    PreferenceManager.setDefaultValues(this, R.xml.preferences, true);
    if (oldCode > 0 && oldCode < 110) { // first so that prefs are moved to right location
        HashSet<String> notifs = new HashSet<>(Prefs.getStringSet(this, SHOW_NOTIFICATIONS));
        notifs.add(getString(R.string.at_restaurant_notifications_value));
        Prefs.putStringSet(this, SHOW_NOTIFICATIONS, notifs);
        migrateAppPrefs();//w w w. j  a  v  a  2s.c o m
    }
    TokenService.refreshTokens(this);
    if (oldCode < 100) { // delete pre-1.0.0 restaurant images
        File file = getExternalFilesDir(null);
        if (file != null) {
            FileUtils.deleteQuietly(new File(file, "images"));
        }
    }
    if (oldCode == 0) { // nothing else to do if run for the first time
        return;
    }
    if (oldCode < 107) { // get colors of existing photos
        startService(new Intent(this, RestaurantColorService.class));
        startService(new Intent(this, FriendColorService.class));
    }
    if (oldCode < 109) {
        startService(new Intent(this, RestaurantsRefreshService.class));
    }
    if (oldCode < 112) {
        startService(new Intent(this, ContactNormalisedNameService.class));
    }
    if (oldCode < 113 && TextUtils.isEmpty(Prefs.getString(this, DISTANCE_UNIT))) {
        Prefs.putString(this, DISTANCE_UNIT, getString(R.string.automatic_value));
    }
}

From source file:com.rsatyavolu.nanodegree.popularmovies.MainActivityFragment.java

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

    GridView gridView = (GridView) rootView.findViewById(R.id.gridview);
    gridView.setColumnWidth(200);// ww w .  j a v a 2 s. c o m

    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (parent.getItemAtPosition(position) != null) {
                ((Callback) getActivity()).onItemSelected(movieListAdapter.getItem(position));
            }
        }
    });

    if (savedInstanceState != null) {
        data = (List<MovieItemModel>) savedInstanceState.getSerializable(MOVIE_SEARCH_RESULTS);
    } else {
        data = new ArrayList<MovieItemModel>();
    }

    movieListAdapter = new MovieIconViewAdapter(getActivity(), data);
    gridView.setAdapter(movieListAdapter);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    PreferenceManager.setDefaultValues(getActivity(), R.xml.pref_settings, false);
    String apiToken = prefs.getString(getString(R.string.pref_api_token_key), "");
    String sortOption = prefs.getString(getString(R.string.pref_sort_key), "");

    if (apiToken.length() <= 25) {
        Intent settings = new Intent(getActivity(), SettingsActivity.class);
        startActivity(settings);

        return rootView;
    }

    if (data.size() == 0) {
        DiscoverMoviesTask discoverMoviesTask = new DiscoverMoviesTask();
        discoverMoviesTask.execute(DISCOVER_MOVIES_URL, apiToken, sortOption);
    }

    return rootView;
}

From source file:de.baumann.hhsmoodle.activities.Activity_todo.java

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

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    toDo_title = sharedPref.getString("toDo_title", "");
    String toDo_text = sharedPref.getString("toDo_text", "");
    toDo_icon = sharedPref.getString("toDo_icon", "");
    toDo_create = sharedPref.getString("toDo_create", "");
    todo_attachment = sharedPref.getString("toDo_attachment", "");
    if (!sharedPref.getString("toDo_seqno", "").isEmpty()) {
        toDo_seqno = Integer.parseInt(sharedPref.getString("toDo_seqno", ""));
    }//from  w ww  .  j  av a 2 s  . c o m

    setContentView(R.layout.activity_todo);
    setTitle(toDo_title);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    helper_main.onStart(Activity_todo.this);

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    try {
        FileOutputStream fOut = new FileOutputStream(newFile());
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
        myOutWriter.append(toDo_text);
        myOutWriter.close();

        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        Log.e("Exception", "File write failed: " + e.toString());
    }

    lvItems = (ListView) findViewById(R.id.lvItems);
    items = new ArrayList<>();
    readItems();
    itemsAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, items);
    lvItems.setAdapter(itemsAdapter);
    lvItems.post(new Runnable() {
        public void run() {
            lvItems.setSelection(lvItems.getCount() - 1);
        }
    });

    setupListViewListener();

    final EditText etNewItem = (EditText) findViewById(R.id.etNewItem);
    ImageButton ib_paste = (ImageButton) findViewById(R.id.imageButtonPaste);
    final ImageButton ib_not = (ImageButton) findViewById(R.id.imageButtonNot);

    switch (todo_attachment) {
    case "true":
        ib_not.setImageResource(R.drawable.alert_circle);
        break;
    case "":
        ib_not.setImageResource(R.drawable.alert_circle_red);
        break;
    }

    ib_not.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            switch (todo_attachment) {
            case "true":
                ib_not.setImageResource(R.drawable.alert_circle_red);
                sharedPref.edit().putString("toDo_attachment", "").apply();
                todo_attachment = sharedPref.getString("toDo_attachment", "");
                break;
            case "":
                ib_not.setImageResource(R.drawable.alert_circle);
                sharedPref.edit().putString("toDo_attachment", "true").apply();
                todo_attachment = sharedPref.getString("toDo_attachment", "");
                break;
            }

        }
    });

    ib_paste.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            final CharSequence[] options = { getString(R.string.paste_date), getString(R.string.paste_time) };
            new android.app.AlertDialog.Builder(Activity_todo.this)
                    .setPositiveButton(R.string.toast_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.paste_date))) {
                                Date date = new Date();
                                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",
                                        Locale.getDefault());
                                String dateNow = format.format(date);
                                etNewItem.getText().insert(etNewItem.getSelectionStart(), dateNow);
                            }

                            if (options[item].equals(getString(R.string.paste_time))) {
                                Date date = new Date();
                                SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault());
                                String timeNow = format.format(date);
                                etNewItem.getText().insert(etNewItem.getSelectionStart(), timeNow);
                            }
                        }
                    }).show();
        }
    });

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String itemText = etNewItem.getText().toString();

            if (itemText.isEmpty()) {
                Snackbar.make(lvItems, R.string.todo_enter, Snackbar.LENGTH_LONG).show();
            } else {
                itemsAdapter.add(itemText);
                etNewItem.setText("");
                writeItems();
                lvItems.post(new Runnable() {
                    public void run() {
                        lvItems.setSelection(lvItems.getCount() - 1);
                    }
                });
            }
        }
    });
}

From source file:com.mikecorrigan.trainscorekeeper.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.vc(VERBOSE, TAG, "onCreate: savedInstanceState=" + savedInstanceState);
    super.onCreate(savedInstanceState);

    // Set up the content and get references to the views.
    setContentView(R.layout.activity_tab);
    playersLayout = (LinearLayout) findViewById(R.id.linear_layout_players);
    viewPager = (ViewPager) findViewById(R.id.view_pager);

    // Set up preferences.
    PreferenceManager.setDefaultValues(this /* context */, R.xml.preferences, true);
    PreferenceManager.getDefaultSharedPreferences(this /* context */)
            .registerOnSharedPreferenceChangeListener(mPrefsListener);

    // Get the game spec.
    final String spec = getSpecFromIntent(getIntent(), Game.DEFAULT_GAME_SPEC);

    create(spec);//from   w  w w  .  ja  v a2 s.  c  o m

    restoreUi(savedInstanceState);
}