/** * Selects the saved item in the tree of preference pages. If it cannot do this it saves the first * one. */ protected void selectSavedItem() { IPreferenceNode node = findNodeMatching(getSelectedNodePreference()); if (node == null) { IPreferenceNode[] nodes = preferenceManager.getRootSubNodes(); ViewerComparator comparator = getTreeViewer().getComparator(); if (comparator != null) { comparator.sort(null, nodes); } ViewerFilter[] filters = getTreeViewer().getFilters(); for (int i = 0; i < nodes.length; i++) { IPreferenceNode selectedNode = nodes[i]; // See if it passes all filters for (int j = 0; j < filters.length; j++) { if (!filters[j].select(this.treeViewer, preferenceManager.getRoot(), selectedNode)) { selectedNode = null; break; } } // if it passes all filters select it if (selectedNode != null) { node = selectedNode; break; } } } if (node != null) { getTreeViewer().setSelection(new StructuredSelection(node), true); // Keep focus in tree. See bugs 2692, 2621, and 6775. getTreeViewer().getControl().setFocus(); } }
private StackFileInfo postSTackFile( StackFileInfo stackFileInfo, ParserConfig config, String filter, boolean isRecent) { if (stackFileInfo.getTotalWorkingCount() <= 0) { MessageBox messageBox = new MessageBox( m_parentComposite.getShell(), SWT.ICON_ERROR | SWT.YES | SWT.APPLICATION_MODAL); messageBox.setText("File open error"); messageBox.setMessage( new StringBuilder(200) .append("A working thread is not exists in ") .append(stackFileInfo.getFilename()) .append(". configure a ") .append(config.getConfigFilename()) .append(". ") .toString()); messageBox.open(); return null; } if (!isRecent) { PreferenceManager prefManager = PreferenceManager.get(); if (filter == null) { prefManager.addToStackFiles(stackFileInfo.getFilename()); } prefManager.addToAnalyzedStackFiles(stackFileInfo.getFilename()); } return stackFileInfo; }
private ParserConfig selectAdoptiveParserConfig() { PreferenceManager prefManager = PreferenceManager.get(); String configFile = prefManager.getCurrentParserConfig(); if (m_isDefaultConfiguration) { configFile = XMLReader.DEFAULT_XMLCONFIG; } if (configFile == null) { MessageBox messageBox = new MessageBox( m_parentComposite.getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO | SWT.APPLICATION_MODAL); messageBox.setText("Check Setting selection"); messageBox.setMessage( "The configuration file is not selected.\r\nDo you want to use the default configuration?"); int result = messageBox.open(); if (result == SWT.YES) { configFile = XMLReader.DEFAULT_XMLCONFIG; } else { configFile = selectCurrentParserConfig(); if (configFile == null) { throw new RuntimeException("Parser config file is not selected!"); } } } ParserConfigReader reader = new ParserConfigReader(configFile); return reader.read(); }
@Override protected void onAttachedToHierarchy(PreferenceManager preferenceManager) { super.onAttachedToHierarchy(preferenceManager); preferenceManager.registerOnActivityResultListener(this); mRequestCode = preferenceManager.getNextRequestCode(); }
/** * @param m the risk method to use * @param toDefault if true, than the default value is returned * @return an array containing the limits (or null). */ protected Number[] getLimits(final RiskMethod m, final boolean toDefault) { Number[] limits; if (m == PreferenceManager.getRiskMethod(owner, toDefault)) { limits = PreferenceManager.getLimits(owner, toDefault); } else { limits = new Number[] {0, 0}; } return limits; }
/** * Inflates the given XML resource and adds the preference hierarchy to the current preference * hierarchy. * * @param preferencesResId The XML resource ID to inflate. */ public void addPreferencesFromResource(@XmlRes int preferencesResId) { requirePreferenceManager(); setPreferenceScreen( mPreferenceManager.inflateFromResource( mStyledContext, preferencesResId, getPreferenceScreen())); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = getActivity(); mPreferences = PreferenceManager.getDefaultSharedPreferences(context); mPreferences.registerOnSharedPreferenceChangeListener(this); addPreferencesFromResource(R.layout.tools); mResidualFiles = findPreference(RESIDUAL_FILES); mOptimDB = findPreference(PREF_OPTIM_DB); long mStartTime = mPreferences.getLong(RESIDUAL_FILES, 0); mResidualFiles.setSummary(""); if (mStartTime > 0) mResidualFiles.setSummary(DateUtils.getRelativeTimeSpanString(mStartTime)); mStartTime = mPreferences.getLong(PREF_OPTIM_DB, 0); mOptimDB.setSummary(""); if (mStartTime > 0) mOptimDB.setSummary(DateUtils.getRelativeTimeSpanString(mStartTime)); if (Helpers.binExist("dd").equals(NOT_FOUND) || NO_FLASH) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("category_flash_img"); getPreferenceScreen().removePreference(hideCat); } if (Helpers.binExist("pm").equals(NOT_FOUND)) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("category_freezer"); getPreferenceScreen().removePreference(hideCat); } setRetainInstance(true); setHasOptionsMenu(true); }
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.menu_layout); Intent update = new Intent(context, MenuProvider.class); update.setAction(CLICK_UPDATE); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, update_code, update, 0); remoteViews.setOnClickPendingIntent(R.id.update, pendingIntent); Intent nextDate = new Intent(context, MenuProvider.class); nextDate.setAction(CLICK_NEXT); pendingIntent = PendingIntent.getBroadcast(context, right_code, nextDate, 0); remoteViews.setOnClickPendingIntent(R.id.arrow_right, pendingIntent); Intent previousDate = new Intent(context, MenuProvider.class); previousDate.setAction(CLICK_PREVIOUS); pendingIntent = PendingIntent.getBroadcast(context, left_code, previousDate, 0); remoteViews.setOnClickPendingIntent(R.id.arrow_left, pendingIntent); remoteViews.setRemoteAdapter(R.id.dish_list, new Intent(context, DishListService.class)); updateDate(remoteViews, R.id.date_text, PreferenceManager.getCalendar(context)); appWidgetManager.updateAppWidget(appWidgetIds, remoteViews); }
public MessageAdapter(Context context, int TextViewResourceID, ArrayList<Message> items) { super(context, TextViewResourceID, items); this.items = items; SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); isMonospaced = sharedPrefs.getBoolean("monospacePref", true); mContext = context; }
/** * Inflates the given XML resource and adds the preference hierarchy to the current preference * hierarchy. * * @param preferencesResId The XML resource ID to inflate. */ public void addPreferencesFromResource(@XmlRes int preferencesResId) { requirePreferenceManager(); setPreferenceScreen( mPreferenceManager.inflateFromResource( getActivity(), preferencesResId, getPreferenceScreen())); }
/** * Inflates the given XML resource and adds the preference hierarchy to the current preference * hierarchy. * * @param preferencesResId The XML resource ID to inflate. * @deprecated This function is not relevant for a modern fragment-based PreferenceActivity. */ @Deprecated public void addPreferencesFromResource(int preferencesResId) { requirePreferenceManager(); setPreferenceScreen( mPreferenceManager.inflateFromResource(this, preferencesResId, getPreferenceScreen())); }
@Override protected void cancelPressed() { // Inform all pages that we are cancelling Iterator<IPreferenceNode> nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER).iterator(); final boolean[] cancelOK = new boolean[] {true}; while (nodes.hasNext()) { final IPreferenceNode node = nodes.next(); if (getPage(node) != null) { SafeRunnable.run( new SafeRunnable() { @Override public void run() { if (!getPage(node).performCancel()) { cancelOK[0] = false; } } }); if (!cancelOK[0]) return; } } // Give subclasses the choice to save the state of the preference pages if needed handleSave(); setReturnCode(CANCEL); close(); }
@Override public void onDestroy() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.unregisterOnSharedPreferenceChangeListener(this); super.onDestroy(); SettingsManager.save(); }
/** * Save the values specified in the pages. * * <p>The default implementation of this framework method saves all pages of type <code> * PreferencePage</code> (if their store needs saving and is a <code>PreferenceStore</code>). * * <p>Subclasses may override. */ protected void handleSave() { Iterator<IPreferenceNode> nodes = preferenceManager.getElements(PreferenceManager.PRE_ORDER).iterator(); while (nodes.hasNext()) { IPreferenceNode node = nodes.next(); IPreferencePage page = node.getPage(); if (page instanceof PreferencePage) { // Save now in case tbe workbench does not shutdown cleanly IPreferenceStore store = ((PreferencePage) page).getPreferenceStore(); if (store != null && store.needsSaving() && store instanceof IPersistentPreferenceStore) { try { ((IPersistentPreferenceStore) store).save(); } catch (IOException e) { String message = JFaceResources.format( "PreferenceDialog.saveErrorMessage", page.getTitle(), // $NON-NLS-1$ e.getMessage()); Policy.getStatusHandler() .show( new Status(IStatus.ERROR, Policy.JFACE, message, e), JFaceResources.getString("PreferenceDialog.saveErrorTitle")); // $NON-NLS-1$ } } } } }
/** * Gets the root of the preference hierarchy that this activity is showing. * * @return The {@link PreferenceScreen} that is the root of the preference hierarchy. * @deprecated This function is not relevant for a modern fragment-based PreferenceActivity. */ @Deprecated public PreferenceScreen getPreferenceScreen() { if (mPreferenceManager != null) { return mPreferenceManager.getPreferenceScreen(); } return null; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPreferenceManager = new PreferenceManager(getSupportActivity(), PreferenceFragment.FIRST_REQUEST_CODE); mPreferenceManager.setFragment(this); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initViews(); init(); mPreferenceManager = PreferenceManager.getInstance(); }
/** * onCreate * * <p>adds the preferences from the ressourcefile */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); prefs.registerOnSharedPreferenceChangeListener(this); }
/** * Finds a {@link Preference} based on its key. * * @param key The key of the preference to retrieve. * @return The {@link Preference} with the key, or null. * @see PreferenceGroup#findPreference(CharSequence) */ public Preference findPreference(CharSequence key) { if (mPreferenceManager == null) { return null; } return mPreferenceManager.findPreference(key); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (mPreferenceManager != null) { mPreferenceManager.dispatchActivityResult(requestCode, resultCode, data); } }
public void setPreferenceScreen(PreferenceScreen preferenceScreen) { if (mPreferenceManager.setPreferences(preferenceScreen) && preferenceScreen != null) { mHavePrefs = true; if (mInitDone) { postBindPreferences(); } } }
@Override public void store() { final Number[] n = new Number[spinners.length]; for (int i = 0; i < spinners.length; ++i) { n[i] = spinners[i].getSelection(); } PreferenceManager.storeRisk(owner, old, n); }
@Override protected void onDestroy() { super.onDestroy(); if (mPreferenceManager != null) { mPreferenceManager.dispatchActivityDestroy(); } }
@Override public void onCreate(Bundle savedInstanceState) { c = this; preferences = PreferenceManager.getDefaultSharedPreferences(c); super.onCreate(savedInstanceState); setContentView(R.layout.gpu_sgx540); gpuCurrent = readFile(Constants.GPU_SGX540); seekGpu = (SeekBar) findViewById(R.id.seek_gpu); gpu = Arrays.asList(153, 307, 384); seekBar(gpu.size() - 1, gpu.indexOf(gpuCurrent)); /*else{ seekGpu.setEnabled(false); seekIva.setEnabled(false); TextView ns = (TextView)findViewById(R.id.not_supported); ns.setVisibility(View.VISIBLE); }*/ preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); curGpuTxt = (TextView) findViewById(R.id.current_gpu); maxGpuTxt = (TextView) findViewById(R.id.max_gpu); minGpuTxt = (TextView) findViewById(R.id.min_gpu); mhz = getResources().getString(R.string.mhz); current = getResources().getString(R.string.current); max = getResources().getString(R.string._max); min = getResources().getString(R.string._min); curGpuTxt.setText(current + ": " + (gpuCurrent) + mhz); maxGpuTxt.setText(max + ": " + gpu.get(2) + mhz); minGpuTxt.setText(min + ": " + gpu.get(0) + mhz); Button cancel = (Button) findViewById(R.id.cancel); cancel.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { finish(); } }); }
private void startPayHelpActivity() { Intent intent = new Intent(this, PayUpdateHelpActivity.class); intent.putExtra( PayUpdateHelpActivity.EXTRA_PURCHASE_REQUEST_SOURCE, StatisticsKey.PURCHASE_FROM_BACKUP_SIZE_LIMIT); startActivity(intent); mPreferenceManager.putBoolean(this, PreferenceManager.KEY_HAS_SHOWN_PAY_HELP_PAGE, true); }
private void chooseStackFile() { PreferenceManager prefManager = PreferenceManager.get(); String fileName = ResourceUtils.selectFileDialog( m_parentComposite, "Stack Log File", new String[] {"Stack Log Files", "All Files"}, new String[] {"*.log;*.txt;*.gz;*.stack", "*.*"}); if (fileName == null) { return; } File file = new File(fileName); prefManager.setSelectedPath(file.getParentFile()); openFile(file, false); }
/** * Find the <code>IPreferenceNode</code> that has data the same id as the supplied value. * * @param nodeId the id to search for. * @return <code>IPreferenceNode</code> or <code>null</code> if not found. */ protected IPreferenceNode findNodeMatching(String nodeId) { List<IPreferenceNode> nodes = preferenceManager.getElements(PreferenceManager.POST_ORDER); for (Iterator<IPreferenceNode> i = nodes.iterator(); i.hasNext(); ) { IPreferenceNode node = i.next(); if (node.getId().equals(nodeId)) { return node; } } return null; }
/** * Sets the root of the preference hierarchy that this activity is showing. * * @param preferenceScreen The root {@link PreferenceScreen} of the preference hierarchy. */ public void setPreferenceScreen(PreferenceScreen preferenceScreen) { if (mPreferenceManager.setPreferences(preferenceScreen) && preferenceScreen != null) { postBindPreferences(); CharSequence title = getPreferenceScreen().getTitle(); // Set the title of the activity if (title != null) { setTitle(title); } } }
public boolean getSettingMsgSound() { Object val = valueCache.get(Key.PlayToneOn); if (val == null) { val = PreferenceManager.getInstance().getSettingMsgSound(); valueCache.put(Key.PlayToneOn, val); } return (Boolean) (val != null ? val : true); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.settings); this.setTitle(R.string.setting); sp = PreferenceManager.getDefaultSharedPreferences(this); edit = sp.edit(); Button widgettheme = (Button) findViewById(R.id.widgettheme); Button settime = (Button) findViewById(R.id.settime); Button save = (Button) findViewById(R.id.set_save); nc = (CheckBox) findViewById(R.id.nightcheck); rs = (CheckBox) findViewById(R.id.ringswitch); widgettheme.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View Button) { AlertDialog.Builder ad = new AlertDialog.Builder(Settings.this) .setTitle("选择颜色?") .setItems( color, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface p1, int p2) { edit.putInt("widgetTextColor", colori[p2]); edit.commit(); } }); ad.show(); } }); settime.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View Button) { Intent set = new Intent(Settings.this, Settime.class); startActivity(set); return; } }); save.setOnClickListener( new View.OnClickListener() { public void onClick(View Button) { save(); return; } }); nc.setChecked(sp.getBoolean("nightmode", false)); if (sp.getBoolean("timewrong", false) == true) { rs.setChecked(false); rs.setClickable(false); } }