aboutsummaryrefslogtreecommitdiffstats
path: root/sdkstats
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2009-04-27 14:58:09 -0700
committerXavier Ducrohet <xav@android.com>2009-04-27 15:05:06 -0700
commitff9c21ab084afbe147b0f7fff71cfb90f250e966 (patch)
tree512b9a03f425ceac3f6b258a5e4250697a490ac1 /sdkstats
parent43793c7bfa1589ea9c174c205e3dcf6f4e9b1704 (diff)
downloadsdk-ff9c21ab084afbe147b0f7fff71cfb90f250e966.zip
sdk-ff9c21ab084afbe147b0f7fff71cfb90f250e966.tar.gz
sdk-ff9c21ab084afbe147b0f7fff71cfb90f250e966.tar.bz2
Fix the opt-in window for usage stat so that it works when running from ADT.
Diffstat (limited to 'sdkstats')
-rw-r--r--sdkstats/src/com/android/sdkstats/SdkStatsService.java145
1 files changed, 80 insertions, 65 deletions
diff --git a/sdkstats/src/com/android/sdkstats/SdkStatsService.java b/sdkstats/src/com/android/sdkstats/SdkStatsService.java
index 0b3d41b..688474e 100644
--- a/sdkstats/src/com/android/sdkstats/SdkStatsService.java
+++ b/sdkstats/src/com/android/sdkstats/SdkStatsService.java
@@ -110,8 +110,10 @@ public class SdkStatsService {
*
* @param app name to report in the ping
* @param version to report in the ping
+ * @param display an optional {@link Display} object to use, or null, if a new one should be
+ * created.
*/
- public static void ping(final String app, final String version) {
+ public static void ping(final String app, final String version, final Display display) {
// Validate the application and version input.
final String normalVersion = normalizeVersion(app, version);
@@ -123,7 +125,7 @@ public class SdkStatsService {
prefs.setValue(PING_ID, new Random().nextLong());
// Also give them a chance to opt out.
- prefs.setValue(PING_OPT_IN, getUserPermission());
+ prefs.setValue(PING_OPT_IN, getUserPermission(display));
try {
prefs.save();
}
@@ -273,77 +275,90 @@ public class SdkStatsService {
* Prompt the user for whether they want to opt out of reporting.
* @return whether the user allows reporting (they do not opt out).
*/
- private static boolean getUserPermission() {
- // Use dialog trim for the shell, but without a close button.
- final Display display = new Display();
- final Shell shell = new Shell(display, 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);
+ private static boolean getUserPermission(Display display) {
+ // 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 };
+
+ boolean dispose = false;
+ if (display == null) {
+ display = new Display();
+ dispose = true;
}
- title.setFont(new Font(display, 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(display, 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 Display currentDisplay = display;
+ final boolean disposeDisplay = dispose;
- final Link footer = new Link(shell, SWT.WRAP);
- footer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- footer.setText(FOOTER_TEXT);
+ display.syncExec(new Runnable() {
+ public void run() {
+ final Shell shell = new Shell(currentDisplay, SWT.TITLE | SWT.BORDER);
+ shell.setText(WINDOW_TITLE_TEXT);
+ shell.setLayout(new GridLayout(1, false)); // 1 column
- // 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 };
+ // 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();
+ }
- 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();
+ if (disposeDisplay) {
+ currentDisplay.dispose();
+ }
}
});
- // Size the window to a fixed width, as high as necessary, centered.
- final Point size = shell.computeSize(450, SWT.DEFAULT, true);
- final Rectangle screen = display.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 (!display.readAndDispatch())
- display.sleep();
- }
-
- display.dispose(); // Otherwise ddms' own Display can't be created
return permission[0];
}