List of usage examples for org.eclipse.jface.preference PreferenceStore save
@Override public void save() throws IOException
From source file:com.android.ddms.PrefsDialog.java
License:Apache License
/** * Create and display the dialog.//from w w w . j ava 2 s . c o m */ public static void run(Shell shell) { PreferenceStore prefStore = mStore.getPreferenceStore(); assert prefStore != null; PreferenceManager prefMgr = new PreferenceManager(); PreferenceNode node, subNode; // this didn't work -- got NPE, possibly from class lookup: //PreferenceNode app = new PreferenceNode("app", "Application", null, // AppPrefs.class.getName()); node = new PreferenceNode("debugger", new DebuggerPrefs()); prefMgr.addToRoot(node); subNode = new PreferenceNode("panel", new PanelPrefs()); //prefMgr.addTo(node.getId(), subNode); prefMgr.addToRoot(subNode); node = new PreferenceNode("LogCat", new LogCatPrefs()); prefMgr.addToRoot(node); node = new PreferenceNode("misc", new MiscPrefs()); prefMgr.addToRoot(node); node = new PreferenceNode("stats", new UsageStatsPrefs()); prefMgr.addToRoot(node); PreferenceDialog dlg = new PreferenceDialog(shell, prefMgr); dlg.setPreferenceStore(prefStore); // run it try { dlg.open(); } catch (Throwable t) { Log.e("ddms", t); } // save prefs try { prefStore.save(); } catch (IOException ioe) { } // discard the stuff we created //prefMgr.dispose(); //dlg.dispose(); }
From source file:com.android.ide.eclipse.common.preferences.UsagePreferencePage.java
License:Open Source License
private void save() { try {// w w w. ja v a2 s . c o m PreferenceStore store = SdkStatsService.getPreferenceStore(); if (store != null) { store.setValue(SdkStatsService.PING_OPT_IN, mOptInCheckBox.getBooleanValue()); store.save(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.android.sdkstats.DdmsPreferenceStore.java
License:Apache License
/** * Save the prefs to the config file./*from w ww . j a v a 2 s . c o m*/ */ public void save() { PreferenceStore prefs = getPreferenceStore(); synchronized (DdmsPreferenceStore.class) { try { prefs.save(); } catch (IOException ioe) { // FIXME com.android.dmmlib.Log.w("ddms", "Failed saving prefs file: " + ioe.getMessage()); } } }
From source file:com.android.sdkstats.DdmsPreferenceStore.java
License:Apache License
/** * Generates a new random ping ID and saves it in the preference store. * * @return The new ping ID./*w w w . java 2 s. c om*/ */ public long generateNewPingId() { PreferenceStore prefs = getPreferenceStore(); Random rnd = new Random(); long id = rnd.nextLong(); synchronized (DdmsPreferenceStore.class) { prefs.setValue(PING_ID, id); try { prefs.save(); } catch (IOException e) { /* ignore exceptions while saving preferences */ } } return id; }
From source file:com.android.sdkstats.DdmsPreferenceStore.java
License:Apache License
/** * Saves the "ping opt in" value in the preference store. * * @param optIn The new user opt-in value. *///from ww w . j a v a2 s .c o m public void setPingOptIn(boolean optIn) { PreferenceStore prefs = getPreferenceStore(); synchronized (DdmsPreferenceStore.class) { prefs.setValue(PING_OPT_IN, optIn); try { prefs.save(); } catch (IOException e) { /* ignore exceptions while saving preferences */ } } }
From source file:com.android.sdkstats.DdmsPreferenceStore.java
License:Apache License
/** * Sets the ping time for the given app from the preference store. * Callers should use {@link System#currentTimeMillis()} for time stamps. * * @param app The app name identifier.// www .java 2s . c o m * @param timeStamp The time stamp from the store. * 0L is a special value that should not be used. */ public void setPingTime(String app, long timeStamp) { PreferenceStore prefs = getPreferenceStore(); String timePref = PING_TIME + "." + app; //$NON-NLS-1$ synchronized (DdmsPreferenceStore.class) { prefs.setValue(timePref, timeStamp); try { prefs.save(); } catch (IOException ioe) { /* ignore exceptions while saving preferences */ } } }
From source file:com.android.sdkstats.DdmsPreferenceStore.java
License:Apache License
/** * Sets whether the ADT startup wizard has been shown. * ADT sets first to false once the welcome wizard has been shown once. * * @param used true if ADT has been used *///from w w w . ja v a 2 s .c om public void setAdtUsed(boolean used) { PreferenceStore prefs = getPreferenceStore(); synchronized (DdmsPreferenceStore.class) { prefs.setValue(ADT_USED, used); try { prefs.save(); } catch (IOException ioe) { /* ignore exceptions while saving preferences */ } } }
From source file:com.android.sdkstats.DdmsPreferenceStore.java
License:Apache License
/** * Sets the last SDK OS path./*from w ww.jav a 2s . c o m*/ * * @param osSdkPath The SDK OS Path. Can be null or empty. */ public void setLastSdkPath(String osSdkPath) { PreferenceStore prefs = getPreferenceStore(); synchronized (DdmsPreferenceStore.class) { prefs.setValue(LAST_SDK_PATH, osSdkPath); try { prefs.save(); } catch (IOException ioe) { /* ignore exceptions while saving preferences */ } } }
From source file:com.android.sdkstats.SdkStatsService.java
License:Apache License
/** * Pings the usage stats server, as long as the prefs contain the opt-in boolean * @param app name to report in the ping * @param version to report in the ping//from ww w. j a v a 2s . com * @param prefs the preference store where the opt-in value and ping times are store */ private static void doPing(final String app, String version, PreferenceStore prefs) { // Validate the application and version input. final String normalVersion = normalizeVersion(app, version); // If the user has not opted in, do nothing and quietly return. if (!prefs.getBoolean(PING_OPT_IN)) { // user opted out. return; } // If the last ping *for this app* was too recent, do nothing. String timePref = PING_TIME + "." + app; //$NON-NLS-1$ long now = System.currentTimeMillis(); long then = prefs.getLong(timePref); if (now - then < PING_INTERVAL_MSEC) { // too soon after a ping. return; } // Record the time of the attempt, whether or not it succeeds. prefs.setValue(timePref, now); try { prefs.save(); } catch (IOException ioe) { } // Send the ping itself in the background (don't block if the // network is down or slow or confused). final long id = prefs.getLong(PING_ID); new Thread() { @Override public void run() { try { actuallySendPing(app, normalVersion, id); } catch (IOException e) { e.printStackTrace(); } } }.start(); }
From source file:com.android.sdkstats.SdkStatsService.java
License:Apache License
/** * Prompt the user for whether they want to opt out of reporting, and then calls * {@link #doPing(String, String, PreferenceStore)} *//*from www . ja va2 s. c om*/ private static void getUserPermissionAndPing(final String app, final String version, final PreferenceStore prefs, Display display) { boolean dispose = false; if (display == null) { display = new Display(); dispose = true; } final Display currentDisplay = display; final boolean disposeDisplay = dispose; display.asyncExec(new Runnable() { public void run() { // Whether the user gave permission (size-1 array for writing to). // Initialize to false, set when the user clicks the button. final boolean[] permission = new boolean[] { false }; final Shell shell = new Shell(currentDisplay, SWT.TITLE | SWT.BORDER); shell.setText(WINDOW_TITLE_TEXT); shell.setLayout(new GridLayout(1, false)); // 1 column // Take the default font and scale it up for the title. final Label title = new Label(shell, SWT.CENTER | SWT.WRAP); final FontData[] fontdata = title.getFont().getFontData(); for (int i = 0; i < fontdata.length; i++) { fontdata[i].setHeight(fontdata[i].getHeight() * 4 / 3); } title.setFont(new Font(currentDisplay, fontdata)); title.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); title.setText(HEADER_TEXT); final Label notice = new Label(shell, SWT.WRAP); notice.setFont(title.getFont()); notice.setForeground(new Color(currentDisplay, 255, 0, 0)); notice.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); notice.setText(NOTICE_TEXT); final Link text = new Link(shell, SWT.WRAP); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); text.setText(BODY_TEXT); text.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { openUrl(event.text); } }); final Button checkbox = new Button(shell, SWT.CHECK); checkbox.setSelection(true); // Opt-in by default. checkbox.setText(CHECKBOX_TEXT); final Link footer = new Link(shell, SWT.WRAP); footer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); footer.setText(FOOTER_TEXT); final Button button = new Button(shell, SWT.PUSH); button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); button.setText(BUTTON_TEXT); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { permission[0] = checkbox.getSelection(); shell.close(); } }); // Size the window to a fixed width, as high as necessary, // centered. final Point size = shell.computeSize(450, SWT.DEFAULT, true); final Rectangle screen = currentDisplay.getClientArea(); shell.setBounds(screen.x + screen.width / 2 - size.x / 2, screen.y + screen.height / 2 - size.y / 2, size.x, size.y); shell.open(); while (!shell.isDisposed()) { if (!currentDisplay.readAndDispatch()) currentDisplay.sleep(); } // the dialog has closed, take care of storing the user preference // and do the ping (in a different thread) prefs.setValue(PING_OPT_IN, permission[0]); try { prefs.save(); doPing(app, version, prefs); } catch (IOException ioe) { } if (disposeDisplay) { currentDisplay.dispose(); } } }); }