@Override protected View onCreateDialogView() { // Get current value from preferences mCurrentValue = getPersistedInt(mDefaultValue); // Inflate layout LayoutInflater inflater = ((PreferenceActivity) context).getLayoutInflater(); View view = inflater.inflate(R.layout.dialog_slider, null); // Setup minimum and maximum text labels ((TextView) view.findViewById(R.id.min_value)).setText(Integer.toString(mMinValue)); ((TextView) view.findViewById(R.id.max_value)).setText(Integer.toString(mMaxValue)); // Setup SeekBar mSeekBar = (SeekBar) view.findViewById(R.id.seek_bar); mSeekBar.setMax(mMaxValue - mMinValue); mSeekBar.setProgress(mCurrentValue - mMinValue); mSeekBar.setOnSeekBarChangeListener(this); // Setup text label for current value mValueText = (TextView) view.findViewById(R.id.current_value); mValueText.setText(Integer.toString(mCurrentValue)); return view; }
/** * Handle options menu */ @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == android.R.id.home) { // Do the same thing as the back button. onBackPressed(); return true; } else if (id == R.id.action_settings) { Intent intent = new Intent(this, SettingsActivity.class); intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.SlideshowPreferenceFragment.class.getName()); intent.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true); startActivity(intent); return true; } else if (id == R.id.action_credits) { startActivity(new Intent(this, CreditsActivity.class)); return true; } return super.onOptionsItemSelected(item); }
@Override protected void onResume() { super.onResume(); SharedPreferences sharedPreferences = getSharedPreferences("USERPASS", PreferenceActivity.MODE_PRIVATE); // System.out.println("name is " + sharedPreferences.getString("username", "whoami")); // System.out.println("password is " + sharedPreferences.getString("password", "password")); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (details != null) { details.clearList(); } details = fragmentFactory.createRecordListFragment(tabPosition2Enum(tabPosition)); fragmentTransaction.replace(R.id.list_fragment, details); fragmentTransaction.commit(); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.ui_prefs : startActivity(new Intent(this, LaunchActivity.class).putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, SettingsFrag.class.getName())); return true; case R.id.mnu_delete : new AlertDialog.Builder(this) .setTitle(R.string.qs_delete) .setMessage(R.string.qs_delete_msg) .setNegativeButton(R.string.act_cancel, null) .setPositiveButton(R.string.act_delete, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { deleteTile(); } }).show(); return true; default : return super.onOptionsItemSelected(item); } }
@Override public void onListItemClick(ListView l, View v, int position, long id) { String db = mFolderList.get(position); if (getActivity() instanceof PreferenceActivity) { Bundle extra = new Bundle(); extra.putString("id", db); ((PreferenceActivity) getActivity()).startPreferencePanel( CFolderFrag.class.getName(), extra, R.string.lbl_customize, "", null, 0); } else if (getActivity() instanceof FolderPick) { ((FolderPick) getActivity()).returnFolder(db, mAdapter.getItem(position)); } }
@Override @SuppressWarnings("deprecation") @SuppressLint("WorldReadableFiles") public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getPreferenceManager().setSharedPreferencesName(Common.PREFERENCE_MAIN_FILE); getPreferenceManager().setSharedPreferencesMode(PreferenceActivity.MODE_WORLD_READABLE); addPreferencesFromResource(R.xml.pref_general); // findPreference(Common.KEY_KEYBOARD_MODE).setOnPreferenceClickListener(this); // findPreference(Common.KEY_RESTART_SYSTEMUI).setOnPreferenceClickListener(this); // findPreference(Common.KEY_STATUSBAR_TASKBAR_RESTART_SYSTEMUI).setOnPreferenceClickListener(this); // findPreference(Common.KEY_BLACKLIST_APPS).setOnPreferenceClickListener(this); // findPreference(Common.KEY_WHITELIST_APPS).setOnPreferenceClickListener(this); // findPreference(Common.KEY_STATUSBAR_TASKBAR_PINNED_APPS).setOnPreferenceClickListener(this); // if (Build.VERSION.SDK_INT >= 20) { // Lollipop // Preference p = findPreference("system_notif_top"); // p.setEnabled(false); // p.setSummary(R.string.pref_systemui_top_summary_not_supported_lollipop); // } mPref = getActivity().getSharedPreferences(Common.PREFERENCE_MAIN_FILE, PreferenceActivity.MODE_WORLD_READABLE); }
@Override @SuppressWarnings("deprecation") @SuppressLint("WorldReadableFiles") public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getPreferenceManager().setSharedPreferencesName(Common.PREFERENCE_MAIN_FILE); getPreferenceManager().setSharedPreferencesMode(PreferenceActivity.MODE_WORLD_READABLE); addPreferencesFromResource(R.xml.pref_moving); // findPreference(Common.KEY_MOVABLE_WINDOW + "_titlebar_screen").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference preference) { // getActivity().startActivity(new Intent(getActivity(), TitleBarSettingsActivity.class)); // return false; // } // }); mPref = getActivity().getSharedPreferences(Common.PREFERENCE_MAIN_FILE, PreferenceActivity.MODE_WORLD_READABLE); }
@Override protected void onPostExecute(final Boolean success) { if (success) { String formatStr = activity.getString(R.string.imported_success); Toast.makeText(activity, String.format(formatStr, totNodes, tottyp), Toast.LENGTH_SHORT).show(); final Intent preferencesActivity = new Intent(activity, PreferencesActivity.class); preferencesActivity.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, DbSettingsFragment.class.getName()); // preferencesActivity.putExtra // (PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS,com); preferencesActivity.setAction("db_setup"); preferencesActivity.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); preferencesActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); activity.startActivity(preferencesActivity); } else { Toast.makeText(SoulissApp.getAppContext(), "Import failed", Toast.LENGTH_SHORT).show(); } }
private static Preference createGestureListPreference(final PreferenceActivity context) { Preference pref = new Preference(context); String name = context.getString(R.string.gesture_list_str); pref.setKey(name); pref.setTitle(name); pref.setDefaultValue(context.getString(R.string.gesture_list_description_str)); pref.setEnabled(true); pref.setSummary(context.getString(R.string.gesture_list_description_str)); pref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(context, tkj.android.homecontrol.mythmote.GestureBuilderActivity.class); context.startActivity(intent); return true; } }); return pref; }
/** * Taps the specified preference displayed by the provided Activity. */ public static void tapPreference(InstrumentationTestCase instrumentationTestCase, PreferenceActivity activity, Preference preference) { // IMPLEMENTATION NOTE: There's no obvious way to find out which View corresponds to the // preference because the Preference list in the adapter is flattened, whereas the View // hierarchy in the ListView is not. // Thus, we go for the Reflection-based invocation of Preference.performClick() which is as // close to the invocation stack of a normal tap as it gets. // Only perform the click if the preference is in the adapter to catch cases where the // preference is not part of the PreferenceActivity for some reason. ListView listView = activity.getListView(); ListAdapter listAdapter = listView.getAdapter(); for (int i = 0, len = listAdapter.getCount(); i < len; i++) { if (listAdapter.getItem(i) == preference) { invokePreferencePerformClickOnMainThread( instrumentationTestCase.getInstrumentation(), preference, activity.getPreferenceScreen()); return; } } throw new IllegalArgumentException("Preference " + preference + " not in list"); }
static Notification createSerivceNf(Context ctx) { @SuppressLint("InlinedApi") final Intent resultIntent = new Intent(ctx, MainActivity.class) .putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, "net.sf.aria2.MainActivity$Aria2Preferences") .putExtra(Config.EXTRA_FROM_NF, true); // note: using addParentStack results in hanging for some reason (confirmed on JellyBean) // there is only one activity in stack to handle up and back navigation differently final TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx) .addNextIntent(resultIntent); final PendingIntent contentIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); return new NotificationCompat.Builder(ctx) .setSmallIcon(R.drawable.ic_nf_icon) .setTicker("aria2 is running") .setContentTitle("aria2 is running") .setContentText("Touch to open settings") .setContentIntent(contentIntent) .setOnlyAlertOnce(true) .build(); }
private void updateTitle() { final String newTitle = getTitle(); if (newTitle == null) { Log.d(LOGTAG, "No new title to show."); return; } final PreferenceActivity activity = (PreferenceActivity) getActivity(); if (Versions.feature11Plus && activity.isMultiPane()) { // In a multi-pane activity, the title is "Settings", and the action // bar is along the top of the screen. We don't want to change those. activity.showBreadCrumbs(newTitle, newTitle); return; } Log.v(LOGTAG, "Setting activity title to " + newTitle); activity.setTitle(newTitle); if (Versions.feature14Plus) { final ActionBar actionBar = activity.getActionBar(); if (actionBar != null) { actionBar.setTitle(newTitle); } } }
private int getResource() { int resid = 0; final String resourceName = getArguments().getString("resource"); final Activity activity = getActivity(); if (resourceName != null) { // Fetch resource id by resource name. final Resources resources = activity.getResources(); final String packageName = activity.getPackageName(); resid = resources.getIdentifier(resourceName, "xml", packageName); } if (resid == 0) { // The resource was invalid. Use the default resource. Log.e(LOGTAG, "Failed to find resource: " + resourceName + ". Displaying default settings."); boolean isMultiPane = Versions.feature11Plus && ((PreferenceActivity) activity).isMultiPane(); resid = isMultiPane ? R.xml.preferences_customize_tablet : R.xml.preferences; } return resid; }
/** * Set intent to display top-level settings fragment, * and show the correct title. */ private void setupTopLevelFragmentIntent() { Intent intent = getIntent(); // Check intent to determine settings screen to display. Bundle intentExtras = intent.getExtras(); Bundle fragmentArgs = new Bundle(); // Add resource argument to fragment if it exists. if (intentExtras != null && intentExtras.containsKey(INTENT_EXTRA_RESOURCES)) { String resourceName = intentExtras.getString(INTENT_EXTRA_RESOURCES); fragmentArgs.putString(INTENT_EXTRA_RESOURCES, resourceName); } else { // Use top-level settings screen. if (!onIsMultiPane()) { fragmentArgs.putString(INTENT_EXTRA_RESOURCES, "preferences"); } else { fragmentArgs.putString(INTENT_EXTRA_RESOURCES, "preferences_customize_tablet"); } } // Build fragment intent. intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, GeckoPreferenceFragment.class.getName()); intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs); }
/** * Given an Intent instance, add extras to specify which settings section to * open. * * resource should be a valid Android XML resource identifier. * * The mechanism to open a section differs based on Android version. */ public static void setResourceToOpen(final Intent intent, final String resource) { if (intent == null) { throw new IllegalArgumentException("intent must not be null"); } if (resource == null) { return; } if (Versions.preHC) { intent.putExtra("resource", resource); } else { intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, GeckoPreferenceFragment.class.getName()); Bundle fragmentArgs = new Bundle(); fragmentArgs.putString("resource", resource); intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs); } }
public PrefRoot(PreferenceManager manager, PreferenceActivity activity,SharedPreferences sharedPrefs, int androidPreferenceLayoutChild, int chooseColorString, AdvancedColorPickerDialog.TextResources advancedColorPrefTextResources, ArrayList<Pref> listToAddAllPrefsTo){ this.manager = manager; this.activity=activity; this.sharedPrefs=sharedPrefs; this.listToAddAllPrefsTo = listToAddAllPrefsTo; PrefResources prefResources = new PrefResources(); prefResources.chooseColorString = chooseColorString; prefResources.androidPreferenceLayoutChild = androidPreferenceLayoutChild; prefResources.advancedColorPrefTextResources = advancedColorPrefTextResources; this.root = manager.createPreferenceScreen(activity); }
public SettingsElements(final PreferenceActivity activity, boolean firstRun) { this.activity = activity; setPrefs(); if (firstRun) { loadFactoryDefaults(); } else { loadSavedDefaults(); } setPrefValues(); setPrefListeners(); }
public static void prepareWindowSettings(Activity activity) { SharedPreferences prefs = getPrefs(activity); if(prefs.getBoolean("fullScreen", true)){ activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } int configOrientation = activity.getResources().getConfiguration().orientation; if(configOrientation == Configuration.ORIENTATION_LANDSCAPE) { if(false == activity instanceof PreferenceActivity) { activity.requestWindowFeature(Window.FEATURE_NO_TITLE); } } else { try { activity.getActionBar().setDisplayHomeAsUpEnabled(true); } catch(Exception ex){ } } }
@Override public void setListAdapter(ListAdapter adapter) { if (adapter == null) { super.setListAdapter(null); } else { List<Header> headers = null; try { Method method = PreferenceActivity.class.getDeclaredMethod("getHeaders"); method.setAccessible(true); headers = (List<Header>) method.invoke(this); } catch (Exception e) { e.printStackTrace(); } super.setListAdapter(new HeaderAdapter(this, headers)); } }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_settings: Intent preferencesActivity = new Intent(); if (!isConnected() || !mEngine.isEngineEnabled()) { if (!((ProgressBarActivity) getActivity()).isSessionClosed()) { Toast.makeText(getActivity(), R.string.session_close_first, Toast.LENGTH_SHORT).show(); return; } preferencesActivity.setClass(getActivity(), PreferencesActivity.class); preferencesActivity.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, SensorsPreferenceFragment.class.getName()); } else if (!((ArduinoEngine) mEngine).isBTEnabled()) preferencesActivity.setAction(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS); else { connect(); break; } startActivity(preferencesActivity); break; } }
public static boolean checkExtraStore(PreferenceActivity activity) { boolean flag = false; if(Integer.parseInt(Build.VERSION.SDK) >= 8) { // use Reflection to avoid errors (for cupcake 1.5) Method MethodList[] = activity.getClass().getMethods(); for(int checkMethod = 0; checkMethod < MethodList.length; checkMethod++) { if(MethodList[checkMethod].getName().indexOf("ApplicationInfo") != -1) { try{ if((((ApplicationInfo) MethodList[checkMethod].invoke(activity , new Object[]{})).flags & 0x40000 /* ApplicationInfo.FLAG_EXTERNAL_STORAGE*/ ) != 0 ) flag = true; } catch(Exception e) {} } } } return flag; }
@Override public void onClick( View view ) { switch( view.getId() ) { case R.id.banner_accountSync_button_remove: App.getPrefs().edit().setSyncConfirmed( true ).apply(); break; case R.id.banner_accountSync_button_settings: startActivity( new Intent( getActivity(), PrefsActivity.class ) .putExtra( PreferenceActivity.EXTRA_SHOW_FRAGMENT, "net.mangajunkie.activity.PrefsActivity$AccountSyncFragment" )); break; } banner_accountSync.setVisibility( View.GONE ); }
@Override public void setListAdapter(ListAdapter adapter) { if (adapter == null) { super.setListAdapter(null); } else { List<Header> headers = null; try { Method method = PreferenceActivity.class.getDeclaredMethod("getHeaders"); method.setAccessible(true); headers = (List<Header>) method.invoke(this); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); } super.setListAdapter(new HeaderAdapter(this, headers)); } }
public static Intent createAppOpsIntent(String packageName) { final Intent intent = new Intent(); intent.setClassName(AppOpsActivity.class.getPackage().getName(), AppOpsActivity.class.getName()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION); if(packageName != null) { final Bundle args = new Bundle(); args.putString(AppOpsDetails.ARG_PACKAGE_NAME, packageName); intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, AppOpsDetails.class.getName()); } return intent; }
/** * Determined installation location * @param PreferenceActivity activity * @return true == external storage, false == internal stroage */ public static boolean isExtraStroage(PreferenceActivity activity) { boolean flag = false; if(Integer.parseInt(Build.VERSION.SDK) >= 8) { // use Reflection to avoid errors (for cupcake 1.5) Method MethodList[] = activity.getClass().getMethods(); for(int checkMethod = 0; checkMethod < MethodList.length; checkMethod++) { if(MethodList[checkMethod].getName().indexOf("ApplicationInfo") != -1) { try{ if((((ApplicationInfo) MethodList[checkMethod].invoke(activity , new Object[]{})).flags & 0x40000 /* ApplicationInfo.FLAG_EXTERNAL_STORAGE*/ ) != 0 ) flag = true; } catch(Exception e) {} } } } return flag; }
private void showSettings(int itemId) { final Intent intent = new Intent(this, SettingsActivity.class); switch (itemId) { case R.id.navdraw_item_processing_options: intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, ProcessingOptions1Fragment.class.getName()); break; case R.id.navdraw_item_solution_options: intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, SolutionOutputSettingsFragment.class.getName()); break; default: throw new IllegalStateException(); } startActivity(intent); }
protected void launchSettings (Class<? extends PreferenceActivity> settingsClass) { handleClose(); Intent intent = new Intent(); intent.setClass(KP2AKeyboard.this, settingsClass); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); }
/** * Launches Settings Activity. * @param context context */ public static void launchSettingsActivity(final Context context) { Intent intent = new Intent(context, SettingsActivity.class); intent.putExtra( PreferenceActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.GeneralPreferenceFragment.class.getName() ); intent.putExtra( PreferenceActivity.EXTRA_NO_HEADERS, true ); intent.putExtra( PreferenceActivity.EXTRA_SHOW_FRAGMENT_TITLE, R.string.action_settings); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); }
@Nullable @Override public Intent getParentActivityIntent() { Intent intent = new Intent(this, SettingsActivity.class); intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.GeneralPreferenceFragment.class.getName()); intent.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true); return intent; }
@Override public void onItemSelected(final AdapterView<?> parent, final View view, final int pos, final long id) { final LocaleRenderer locale = (LocaleRenderer)parent.getItemAtPosition(pos); if (locale.isMoreLanguages()) { PreferenceActivity preferenceActivity = (PreferenceActivity)getActivity(); preferenceActivity.startPreferenceFragment(new UserDictionaryLocalePicker(), true); } else { mContents.updateLocale(locale.getLocaleString()); } }
@Override protected void onPause() { super.onPause(); SharedPreferences sharedPreferences = getSharedPreferences("USERPASS", PreferenceActivity.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("username", "shenyanfang"); editor.putString("password", "guess"); editor.commit(); }