List of usage examples for android.preference PreferenceManager setDefaultValues
public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain)
From source file:com.nextgis.mobile.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mMap = new MapView(this); //mMap.initMap(nTileSize, nZoom, nScrollX, nScrollY); //mMap.showInfoPane(bInfoOn); //mMap.showCompass(bCompassOn); setContentView(R.layout.activity_main); // initialize the default settings PreferenceManager.setDefaultValues(this, R.xml.preferences, false); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // boolean bInfoOn = prefs.getBoolean(Constants.PREFS_SHOW_INFO, false); mbGpxRecord = prefs.getBoolean(Constants.KEY_PREF_SW_TRACKGPX_SRV, false); boolean bCompassOn = prefs.getBoolean(Constants.PREFS_SHOW_COMPASS, false); int nTileSize = 256;//prefs.getInt(NGMConstants.KEY_PREF_TILE_SIZE + "_int", 256); int nZoom = prefs.getInt(Constants.PREFS_ZOOM_LEVEL, 1); int nScrollX = prefs.getInt(Constants.PREFS_SCROLL_X, 0); int nScrollY = prefs.getInt(Constants.PREFS_SCROLL_Y, 0); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayShowTitleEnabled(true); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); mLayersFragment = (LayersFragment) getSupportFragmentManager().findFragmentById(R.id.layers); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); mMapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag("MAP"); if (mMapFragment == null) { mMapFragment = new MapFragment(); fragmentTransaction.add(R.id.map, mMapFragment, "MAP").commit(); }// w w w. jav a 2s . c o m getSupportFragmentManager().executePendingTransactions(); LayersFragment layersFragment = (LayersFragment) getSupportFragmentManager().findFragmentById(R.id.layers); // Set up the drawer. layersFragment.setUp(R.id.layers, (DrawerLayout) findViewById(R.id.drawer_layout)); /* showLayersList(m_bShowLayersList); */ }
From source file:me.acristoffers.tracker.fragments.PackageListFragment.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final Activity activity = getActivity(); final View view = getView(); if (view == null || activity == null) { return;/* w w w .j av a 2 s.c o m*/ } PreferenceManager.setDefaultValues(activity, R.xml.preferences, false); AlarmReceiver.setAlarm(activity); recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView); if (recyclerView == null) { activity.finish(); System.exit(0); } final RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(activity); recyclerView.setLayoutManager(layoutManager); final PackageListAdapter recyclerViewAdapter = new PackageListAdapter(activity, (PackageListActivity) activity); recyclerView.setAdapter(recyclerViewAdapter); swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container); if (swipeRefreshLayout == null) { activity.finish(); System.exit(0); } swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { if (updating == 0) { checkForUpdates(); } } }); final Button button = (Button) view.findViewById(R.id.addButton); if (button != null) { button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final View view = View.inflate(activity, R.layout.search_package, null); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(R.string.search_for_package); builder.setView(view); final EditText code = (EditText) view.findViewById(R.id.code); if (code != null) { code.addTextChangedListener(new TrackCodeFormattingTextWatcher(code)); } builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { final EditText code = (EditText) view.findViewById(R.id.code); final EditText name = (EditText) view.findViewById(R.id.name); Package p = null; if (code != null) { Editable editable = code.getText(); if (editable != null) { String s = editable.toString(); p = new Package(s, getActivity(), null); } } if (name != null && p != null) { final Editable editable = name.getText(); if (editable != null) { final String s = editable.toString(); p.setName(s); p.setActive(true); p.save(); checkForUpdates(); } } dialogInterface.dismiss(); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }); final AlertDialog dialog = builder.create(); dialog.show(); } }); } }
From source file:com.tassadar.multirommgr.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT == 20) { showDeprecatedLAlert();/*from ww w.jav a2 s . c o m*/ return; } setContentView(R.layout.activity_main); // This activity is using different background color, which would cause overdraw // of the whole area, so disable the default background getWindow().setBackgroundDrawable(null); Utils.installHttpCache(this); PreferenceManager.setDefaultValues(this, R.xml.settings, false); m_srLayout = (MultiROMSwipeRefreshLayout) findViewById(R.id.refresh_layout); m_srLayout.setOnRefreshListener(this); m_curFragment = -1; m_fragmentTitles = getResources().getStringArray(R.array.main_fragment_titles); m_drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); m_drawerList = (ListView) findViewById(R.id.left_drawer); String[] fragmentClsNames = new String[MainFragment.MAIN_FRAG_CNT]; for (int i = 0; i < fragmentClsNames.length; ++i) fragmentClsNames[i] = MainFragment.getFragmentClass(i).getName(); m_fragments = new MainFragment[MainFragment.MAIN_FRAG_CNT]; FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction t = fragmentManager.beginTransaction(); for (int i = 0; i < m_fragments.length; ++i) { m_fragments[i] = (MainFragment) fragmentManager.findFragmentByTag(fragmentClsNames[i]); if (m_fragments[i] == null) { m_fragments[i] = MainFragment.newFragment(i); t.add(R.id.content_frame, m_fragments[i], fragmentClsNames[i]); } t.hide(m_fragments[i]); } t.commit(); // Set the adapter for the list view m_drawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, m_fragmentTitles)); // Set the list's click listener m_drawerList.setOnItemClickListener(new DrawerItemClickListener()); m_drawerTitle = getText(R.string.app_name); m_drawerToggle = new ActionBarDrawerToggle(this, m_drawerLayout, R.string.drawer_open, R.string.drawer_close) { public void onDrawerClosed(View view) { getSupportActionBar().setTitle(m_title); } public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle(m_drawerTitle); } }; m_drawerLayout.setDrawerListener(m_drawerToggle); final ActionBar bar = getSupportActionBar(); if (bar != null) { bar.setDisplayHomeAsUpEnabled(true); bar.setHomeButtonEnabled(true); } if (getIntent().hasExtra(INTENT_EXTRA_SHOW_ROM_LIST) && getIntent().getBooleanExtra(INTENT_EXTRA_SHOW_ROM_LIST, false)) { getIntent().removeExtra(INTENT_EXTRA_SHOW_ROM_LIST); selectItem(1); } else if (savedInstanceState != null) { selectItem(savedInstanceState.getInt("curFragment", 0)); } else { selectItem(0); } }
From source file:io.github.romankl.bitcoinvalue.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PreferenceManager.setDefaultValues(this, R.xml.prefs_general, false); if (savedInstanceState == null) { OverViewFragment fragment = new OverViewFragment(); fragment.setContext(this); getSupportFragmentManager().beginTransaction().add(R.id.container, fragment).commit(); }//from www. j a v a 2 s .c om }
From source file:com.zachrohde.gpsautodash.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (mThemeId != -1) setTheme(mThemeId); // If app was stopped, but mThemeId has a value on restore. super.onCreate(savedInstanceState); // Check to see if there is a saved theme; we cannot use onRestoreInstanceState because // onCreate is called first. if (savedInstanceState != null) { if (savedInstanceState.getInt("theme", -1) != -1) { mThemeId = savedInstanceState.getInt("theme"); setTheme(mThemeId);/*from w ww. j a va 2 s . com*/ } } getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // Keep the screen on. setContentView(R.layout.activity_main); mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager() .findFragmentById(R.id.navigation_drawer); mTitle = getTitle(); // Set up the drawer. mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); // Load the default preferences. PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Create a new instance of LightService to enable auto-theme-switching based on light. lightServiceInst = new LightService(this); }
From source file:dentex.youtube.downloader.menu.AboutActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); BugSenseHandler.leaveBreadcrumb("AboutActivity_onCreate"); this.setTitle(R.string.title_activity_about); getWindow().requestFeature(Window.FEATURE_ACTION_BAR); // Theme init Utils.themeInit(this); // Language init Utils.langInit(this); // Load default preferences values PreferenceManager.setDefaultValues(this, R.xml.about, false); // Display the fragment as the main content. getFragmentManager().beginTransaction().replace(android.R.id.content, new AboutFragment()).commit(); setupActionBar();/*w w w .j a v a 2s . co m*/ }
From source file:com.github.jvanhie.discogsscrobbler.ReleaseListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.pref_discogs, false); setContentView(R.layout.activity_release_list); mReleaseProgressBar = (ProgressBar) findViewById(R.id.release_list_progressBar); mRefreshProgressBar = (ProgressBar) findViewById(R.id.release_list_refresh); mReleaseList = ((ReleaseListFragment) getSupportFragmentManager().findFragmentById(R.id.release_list)); if (mReleaseProgressBar != null && mLoaded) mReleaseProgressBar.setVisibility(View.INVISIBLE); if (mRefreshProgressBar != null && mRefresh) mRefreshProgressBar.setVisibility(View.VISIBLE); //check if we're in tablet mode -> two or tripane layout (hide details fields first, for a nice collection view) if (findViewById(R.id.release_pager_container) != null) { mPanes = 2;/* ww w . j av a 2s. co m*/ findViewById(R.id.release_pager_container).setVisibility(View.GONE); } else if (findViewById(R.id.release_tracklist_container) != null) { mPanes = 3; findViewById(R.id.release_detail_container).setVisibility(View.GONE); findViewById(R.id.release_tracklist_container).setVisibility(View.GONE); } // Restore the previously serialized activated release if (savedInstanceState != null && savedInstanceState.containsKey(STATE_RELEASE_SELECTED)) { if (savedInstanceState.getInt(STATE_PANES) != mPanes) { //if the panelayout has changed, forcibly reload the fragments onItemSelected(savedInstanceState.getLong(STATE_RELEASE_SELECTED)); } } if (mDiscogs == null) mDiscogs = Discogs.getInstance(this); //create navigation drawer setDrawer(R.id.list_drawer_layout, R.id.list_drawer, getTitle().toString(), getTitle().toString(), true); }
From source file:com.ardnezar.lookapp.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); roomEditText = (EditText) findViewById(R.id.room_edittext); roomEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override/*from w w w . j a va 2 s . c om*/ public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_DONE) { addRoomButton.performClick(); return true; } return false; } }); roomEditText.requestFocus(); roomListView = (ListView) findViewById(R.id.room_listview); roomListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); addRoomButton = (ImageButton) findViewById(R.id.add_room_button); addRoomButton.setOnClickListener(addRoomListener); removeRoomButton = (ImageButton) findViewById(R.id.remove_room_button); removeRoomButton.setOnClickListener(removeRoomListener); connectButton = (ImageButton) findViewById(R.id.connect_button); connectButton.setOnClickListener(connectListener); connectLoopbackButton = (ImageButton) findViewById(R.id.connect_loopback_button); connectLoopbackButton.setOnClickListener(connectListener); // If an implicit VIEW intent is launching the app, go directly to that URL. // final Intent intent = getIntent(); // if ("android.intent.action.VIEW".equals(intent.getAction()) // && !commandLineRun) { // commandLineRun = true; // boolean loopback = intent.getBooleanExtra( // CallActivity.EXTRA_LOOPBACK, false); // int runTimeMs = intent.getIntExtra( // CallActivity.EXTRA_RUNTIME, 0); // String room = sharedPref.getString(keyprefRoom, ""); // roomEditText.setText(room); // connectToRoom(loopback, runTimeMs); // return; // } }
From source file:eu.e43.impeller.activity.MainActivity.java
@Override protected void onCreateEx(Bundle savedInstanceState) { PreferenceManager.setDefaultValues(this, R.xml.pref_general, false); PreferenceManager.setDefaultValues(this, R.xml.pref_data_sync, false); setContentView(R.layout.activity_main); m_toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(m_toolbar);// www. j ava 2s . c o m m_toolbar.inflateMenu(R.menu.main); m_drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); m_drawerFragment = (DrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); m_drawerToggle = new ActionBarDrawerToggle(this, m_drawerLayout, R.string.drawer_open, R.string.drawer_close); m_drawerLayout.setDrawerListener(m_drawerToggle); m_isTablet = "two_pane".equals(findViewById(R.id.main_activity).getTag()); Log.v(TAG, "isTwoPane? " + (m_isTablet ? "YES" : "NO")); if (savedInstanceState == null) { getSupportActionBar().hide(); getSupportFragmentManager().beginTransaction().add(R.id.feed_fragment, new SplashFragment()) .setTransition(FragmentTransaction.TRANSIT_NONE).commit(); } else { m_feedFragment = (FeedFragment) getSupportFragmentManager().getFragment(savedInstanceState, "feedFragment"); m_objectFragment = (ObjectContainerFragment) getSupportFragmentManager().getFragment(savedInstanceState, "objectFragment"); setDisplayMode((Mode) savedInstanceState.getSerializable("displayMode")); Log.i(TAG, "Restoring in display mode " + m_displayMode.toString()); } }
From source file:com.projectgoth.mywebrtcdemo.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); roomEditText = (EditText) findViewById(R.id.room_edittext); roomEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override//from ww w . j a va 2 s .c o m public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_DONE) { addRoomButton.performClick(); return true; } return false; } }); roomEditText.requestFocus(); roomListView = (ListView) findViewById(R.id.room_listview); roomListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); addRoomButton = (ImageButton) findViewById(R.id.add_room_button); addRoomButton.setOnClickListener(addRoomListener); removeRoomButton = (ImageButton) findViewById(R.id.remove_room_button); removeRoomButton.setOnClickListener(removeRoomListener); connectButton = (ImageButton) findViewById(R.id.connect_button); connectButton.setOnClickListener(connectListener); connectLoopbackButton = (ImageButton) findViewById(R.id.connect_loopback_button); connectLoopbackButton.setOnClickListener(connectListener); // If an implicit VIEW intent is launching the app, go directly to that URL. final Intent intent = getIntent(); if ("android.intent.action.VIEW".equals(intent.getAction()) && !commandLineRun) { commandLineRun = true; boolean loopback = intent.getBooleanExtra(CallActivity.EXTRA_LOOPBACK, false); int runTimeMs = intent.getIntExtra(CallActivity.EXTRA_RUNTIME, 0); String room = sharedPref.getString(keyprefRoom, ""); roomEditText.setText(room); connectToRoom(loopback, runTimeMs); return; } }