List of usage examples for android.preference PreferenceManager setDefaultValues
public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain)
From source file:de.baumann.hhsmoodle.data_count.Count_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()); 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/*w w w . j a v a 2 s. c o m*/ public void onClick(View view) { if (filter.getText().length() > 0) { filter.setText(""); } else { setTitle(); helper_main.hideFilter(getActivity(), filter_layout, imgHeader); setCountList(); } } }); fabLayout1 = (LinearLayout) rootView.findViewById(R.id.fabLayout1); fabLayout2 = (LinearLayout) rootView.findViewById(R.id.fabLayout2); fab = (FloatingActionButton) rootView.findViewById(R.id.fab); FloatingActionButton fab1 = (FloatingActionButton) rootView.findViewById(R.id.fab1); FloatingActionButton fab2 = (FloatingActionButton) rootView.findViewById(R.id.fab2); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (!isFABOpen) { showFABMenu(); } else { closeFABMenu(); } } }); fab1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { closeFABMenu(); final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); edit_title.setHint(R.string.bookmark_edit_title); builder.setTitle(R.string.count_title); builder.setView(dialogView); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.app.AlertDialog dialog2 = builder.create(); dialog2.show(); dialog2.getButton(android.app.AlertDialog.BUTTON_POSITIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Do stuff, possibly set wantToCloseDialog to true then... String inputTitle = edit_title.getText().toString().trim(); Count_DbAdapter db = new Count_DbAdapter(getActivity()); db.open(); if (db.isExist(inputTitle)) { Snackbar.make(edit_title, getActivity().getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { dialog2.dismiss(); db.insert(inputTitle, sharedPref.getString("count_content", ""), "3", "", helper_main.createDate()); sharedPref.edit().putString("count_content", "").apply(); setCountList(); } } }); helper_main.showKeyboard(getActivity(), edit_title); } }); fab2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { closeFABMenu(); Intent mainIntent = new Intent(getActivity(), Popup_courseList.class); mainIntent.setAction("courseList_count"); startActivity(mainIntent); } }); //calling Notes_DbAdapter db = new Count_DbAdapter(getActivity()); db.open(); setCountList(); setHasOptionsMenu(true); return rootView; }
From source file:de.baumann.hhsmoodle.data_courses.Courses_Fragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_screen_notes, container, false); ImageView imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header); helper_main.setImageHeader(getActivity(), imgHeader); PreferenceManager.setDefaultValues(getActivity(), R.xml.user_settings, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); RelativeLayout filter_layout = (RelativeLayout) rootView.findViewById(R.id.filter_layout); filter_layout.setVisibility(View.GONE); lv = (ListView) rootView.findViewById(R.id.listNotes); viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager); fabLayout1 = (LinearLayout) rootView.findViewById(R.id.fabLayout1); fabLayout2 = (LinearLayout) rootView.findViewById(R.id.fabLayout2); fab = (FloatingActionButton) rootView.findViewById(R.id.fab); TextView fab2_text = (TextView) rootView.findViewById(R.id.text_fab2); fab2_text.setText(getString(R.string.courseList_fromText)); FloatingActionButton fab1 = (FloatingActionButton) rootView.findViewById(R.id.fab1); FloatingActionButton fab2 = (FloatingActionButton) rootView.findViewById(R.id.fab2); fab.setOnClickListener(new View.OnClickListener() { @Override/*from www.j av a 2 s.c o m*/ public void onClick(View view) { if (!isFABOpen) { showFABMenu(); } else { closeFABMenu(); } } }); fab1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { closeFABMenu(); android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.note_title_input); edit_title.setHint(R.string.title_hint); final EditText edit_cont = (EditText) dialogView.findViewById(R.id.note_text_input); edit_cont.setHint(R.string.text_hint); builder.setView(dialogView); builder.setTitle(R.string.number_edit_entry); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTitle = edit_title.getText().toString().trim(); String inputCont = edit_cont.getText().toString().trim(); if (db.isExist(inputTitle)) { Snackbar.make(lv, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(inputTitle, inputCont, "", "", helper_main.createDate()); dialog.dismiss(); setCoursesList(); Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show(); } } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.app.AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(getActivity(), edit_title); } }); fab2.setImageResource(R.drawable.account_multiple_plus); fab2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { closeFABMenu(); Intent mainIntent = new Intent(getActivity(), Popup_files.class); mainIntent.setAction("file_chooseText"); startActivity(mainIntent); } }); //calling Notes_DbAdapter db = new Courses_DbAdapter(getActivity()); db.open(); setCoursesList(); setHasOptionsMenu(true); return rootView; }
From source file:com.teguholica.tetris.activities.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PreferenceManager.setDefaultValues(this, R.xml.simple_preferences, true); PreferenceManager.setDefaultValues(this, R.xml.advanced_preferences, true); /* Create Music */ sound = new Sound(this); sound.startMusic(Sound.MENU_MUSIC, 0); /* Database Management */ Cursor mc;/*from w w w . j a va 2 s. c om*/ datasource = new ScoreDataSource(this); datasource.open(); mc = datasource.getCursor(); // Use the SimpleCursorAdapter to show the // elements in a ListView adapter = new SimpleCursorAdapter((Context) this, R.layout.blockinger_list_item, mc, new String[] { HighscoreOpenHelper.COLUMN_SCORE, HighscoreOpenHelper.COLUMN_PLAYERNAME }, new int[] { R.id.text1, R.id.text2 }, SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(adapter); /* Create Startlevel Dialog */ startLevel = 0; startLevelDialog = new AlertDialog.Builder(this); startLevelDialog.setTitle(R.string.startLevelDialogTitle); startLevelDialog.setCancelable(false); startLevelDialog.setNegativeButton(R.string.startLevelDialogCancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); startLevelDialog.setPositiveButton(R.string.startLevelDialogStart, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { MainActivity.this.start(); } }); /* Create Donate Dialog */ donateDialog = new AlertDialog.Builder(this); donateDialog.setTitle(R.string.pref_donate_title); donateDialog.setMessage(R.string.pref_donate_summary); donateDialog.setNegativeButton(R.string.startLevelDialogCancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); donateDialog.setPositiveButton(R.string.donate_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String url = getResources().getString(R.string.donation_url); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } }); }
From source file:co.jlabs.cersei_retailer.zxingfragmentlib.BarCodeScannerFragment.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); hasSurface = false;/*from w w w . j ava2s . c o m*/ inactivityTimer = new InactivityTimer(this.getActivity()); beepManager = new BeepManager(this.getActivity()); ambientLightManager = new AmbientLightManager(this.getActivity()); PreferenceManager.setDefaultValues(this.getActivity(), R.xml.preferences, false); }
From source file:it.unicaradio.android.activities.MainActivity.java
/** * {@inheritDoc}// w w w. ja va 2s .co m */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_layout); initGcm(); initView(); setVolumeControlStream(AudioManager.STREAM_MUSIC); preferences = getPreferences(Context.MODE_PRIVATE); if (isFirstRun()) { PreferenceManager.setDefaultValues(this, R.xml.prefs, true); } if (hasBeenUpdated()) { showUpdatesDialog(); } setupUpdatesChecker(); }
From source file:com.readystatesoftware.ghostlog.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Switch mainSwitch = new Switch(this); mainSwitch.setChecked(LogService.isRunning()); mainSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override/* w w w . j a v a2s . c o m*/ public void onCheckedChanged(CompoundButton compoundButton, boolean b) { Intent intent = new Intent(MainActivity.this, LogService.class); if (b) { if (!LogService.isRunning()) { startService(intent); } } else { stopService(intent); } } }); final ActionBar bar = 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(this); if (!mPrefs.getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) { PreferenceManager.setDefaultValues(this, R.xml.pref_filters, true); PreferenceManager.setDefaultValues(this, R.xml.pref_appearance, true); SharedPreferences.Editor edit = mPrefs.edit(); edit.putBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, true); edit.apply(); } }
From source file:de.baumann.hhsmoodle.HHS_MainScreen.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_screen_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w w w.j a v a 2 s . c om*/ helper_security.checkPin(HHS_MainScreen.this); helper_security.grantPermissions(HHS_MainScreen.this); helper_main.onStart(HHS_MainScreen.this); PreferenceManager.setDefaultValues(this, R.xml.user_settings, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(this); sharedPref.edit().putString("browserLoad", "").apply(); class_SecurePreferences sharedPrefSec = new class_SecurePreferences(HHS_MainScreen.this, "sharedPrefSec", "Ywn-YM.XK$b:/:&CsL8;=L,y4", true); viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); View headerView = navigationView.getHeaderView(0); TextView nav_user = (TextView) headerView.findViewById(R.id.usernameNav); nav_user.setText(sharedPrefSec.getString("username")); TypedArray images = getResources().obtainTypedArray(R.array.splash_images); int choice = (int) (Math.random() * images.length()); headerView.setBackgroundResource(images.getResourceId(choice, R.drawable.splash1)); images.recycle(); if (!appDir().exists()) { if (android.os.Build.VERSION.SDK_INT >= 23) { int hasWRITE_EXTERNAL_STORAGE = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); if (hasWRITE_EXTERNAL_STORAGE == PackageManager.PERMISSION_GRANTED) { if (!appDir().exists()) { appDir().mkdirs(); } else { helper_security.grantPermissions(HHS_MainScreen.this); } } } else { appDir().mkdirs(); } } onNewIntent(getIntent()); if (sharedPref.getBoolean("silent_mode", true)) { final NotificationManager notificationManager = (NotificationManager) HHS_MainScreen.this .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && !notificationManager.isNotificationPolicyAccessGranted()) { if (sharedPref.getString("show_permission_disturb", "true").equals("true")) { new android.app.AlertDialog.Builder(this).setTitle(R.string.app_permissions_title_dist) .setMessage(helper_main.textSpannable(getString(R.string.app_permissions_dist))) .setNeutralButton(R.string.toast_notAgain, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); sharedPref.edit().putString("show_permission_disturb", "false").apply(); } }).setPositiveButton(getString(R.string.toast_yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && !notificationManager.isNotificationPolicyAccessGranted()) { Intent intent = new Intent( android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS); startActivity(intent); } } }) .setNegativeButton(getString(R.string.toast_cancel), null).show(); } } } }
From source file:net.eledge.android.europeana.gui.activity.HomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); getSupportActionBar().setDisplayHomeAsUpEnabled(true); NewBlogNotification.cancel(this); PreferenceManager.setDefaultValues(this, R.xml.settings, false); searchController.suggestionPageSize = getResources().getInteger(R.integer.home_suggestions_pagesize); isLandscape = getResources().getBoolean(R.bool.home_support_landscape); mSuggestionsAdaptor = new SuggestionAdapter(this, new ArrayList<Item>()); mGridViewSuggestions.setAdapter(mSuggestionsAdaptor); mGridViewSuggestions.setOnItemClickListener(this); mEditTextQuery.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override//from w w w .j av a2 s .c o m public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((actionId == EditorInfo.IME_ACTION_SEARCH) || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { performSearch(v.getText().toString()); return true; } return false; } }); mEditTextQuery.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (s.length() > 2) { if (mGridViewSuggestions.isShown()) { mSuggestionsAdaptor.clear(); mSuggestionsAdaptor.notifyDataSetChanged(); } searchController.suggestions(HomeActivity.this, s.toString()); } else { onTaskFinished(null); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // ignore } @Override public void afterTextChanged(Editable s) { // ignore } }); mProfilesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item); mSpinnerProfiles.setAdapter(mProfilesAdapter); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (mBlogFragment == null) { mBlogFragment = new HomeBlogFragment(); } fragmentTransaction.replace(R.id.activity_home_fragment_blog, mBlogFragment); fragmentTransaction.commit(); }
From source file:net.inbox.Pager.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Show first use help boolean show_help = false; // Init SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (!prefs.contains("initialized")) { PreferenceManager.setDefaultValues(this, R.xml.settings, false); prefs.edit().putBoolean("initialized", true).apply(); // Initial values that don't have a preference screen prefs.edit().putBoolean("imap_or_pop", true).apply(); prefs.edit().putBoolean("using_smtp", false).apply(); prefs.edit().putBoolean("enable_pw", false).apply(); show_help = true;//from w w w . ja va2s .co m } if (show_help || !prefs.getBoolean("enable_pw", false)) { init_db("cleartext"); // Initial entry view View v = View.inflate(this, R.layout.pager, null); v.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in)); setContentView(v); rv_main = (RelativeLayout) findViewById(R.id.app_main); rv_main.setVisibility(View.VISIBLE); rv_main.setAlpha(0.01f); rv_main.animate().alpha(1f).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); activity_load(); } }); } else { // Initial entry view View v = View.inflate(this, R.layout.pager, null); v.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in)); setContentView(v); // Entry text edit llay_pw = (LinearLayout) findViewById(R.id.llay_pw); llay_pw.setVisibility(View.VISIBLE); rv_main = (RelativeLayout) findViewById(R.id.app_main); et_pw = (EditText) findViewById(R.id.pw); et_pw.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int key, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && key == KeyEvent.KEYCODE_ENTER) { init_db(et_pw.getText().toString()); et_pw.setText(""); if (unlocked) { activity_load(); fade_in_ui(); } else { if (++over >= 3) finish(); } return true; } return false; } }); } // Helper dialog if (show_help) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCancelable(true); builder.setTitle(getString(R.string.helper_title)); builder.setMessage(getString(R.string.helper_msg)); builder.setPositiveButton(getString(android.R.string.ok), null); builder.setNegativeButton(getString(R.string.btn_pw), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(getApplicationContext(), Settings.class)); overridePendingTransition(R.anim.right_in, R.anim.right_out); } }); builder.show(); } }
From source file:de.baumann.hhsmoodle.data_notes.Notes_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()); 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/*w ww . jav a 2s. c om*/ public void onClick(View view) { if (filter.getText().length() > 0) { filter.setText(""); } else { setTitle(); helper_main.hideFilter(getActivity(), filter_layout, imgHeader); setNotesList(); } } }); fabLayout1 = (LinearLayout) rootView.findViewById(R.id.fabLayout1); fabLayout2 = (LinearLayout) rootView.findViewById(R.id.fabLayout2); fab = (FloatingActionButton) rootView.findViewById(R.id.fab); FloatingActionButton fab1 = (FloatingActionButton) rootView.findViewById(R.id.fab1); FloatingActionButton fab2 = (FloatingActionButton) rootView.findViewById(R.id.fab2); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (!isFABOpen) { showFABMenu(); } else { closeFABMenu(); } } }); fab1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { closeFABMenu(); sharedPref.edit().putString("handleTextCreate", helper_main.createDate()).apply(); helper_main.switchToActivity(getActivity(), Activity_EditNote.class, false); } }); fab2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { closeFABMenu(); sharedPref.edit().putString("handleTextCreate", helper_main.createDate()).apply(); Intent mainIntent = new Intent(getActivity(), Popup_courseList.class); mainIntent.setAction("courseList_note"); startActivity(mainIntent); } }); //calling Notes_DbAdapter db = new Notes_DbAdapter(getActivity()); db.open(); setNotesList(); setHasOptionsMenu(true); return rootView; }