diff options
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.base/src/com/android')
2 files changed, 164 insertions, 0 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.base/src/com/android/ide/eclipse/base/InstallDetails.java b/eclipse/plugins/com.android.ide.eclipse.base/src/com/android/ide/eclipse/base/InstallDetails.java new file mode 100644 index 000000000..8c4a4a71e --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.base/src/com/android/ide/eclipse/base/InstallDetails.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ide.eclipse.base; + +import org.eclipse.core.runtime.Platform; +import org.osgi.framework.Bundle; +import org.osgi.framework.Version; + +public class InstallDetails { + private static final String ADT_PLUGIN_ID = "com.android.ide.eclipse.adt"; //$NON-NLS-1$ + private static final String ECLIPSE_PLATFORM_PLUGIN_ID = "org.eclipse.platform"; //$NON-NLS-1$ + + /** + * Returns true if the ADT plugin is available in the current platform. This is useful + * for distinguishing between specific RCP applications vs. ADT + Eclipse. + */ + public static boolean isAdtInstalled() { + Bundle b = Platform.getBundle(ADT_PLUGIN_ID); + return b != null; + } + + /** Returns the version of current eclipse platform. */ + public static Version getPlatformVersion() { + Bundle b = Platform.getBundle(ECLIPSE_PLATFORM_PLUGIN_ID); + return b == null ? Version.emptyVersion : b.getVersion(); + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.base/src/com/android/ide/eclipse/base/internal/preferences/UsagePreferencePage.java b/eclipse/plugins/com.android.ide.eclipse.base/src/com/android/ide/eclipse/base/internal/preferences/UsagePreferencePage.java new file mode 100644 index 000000000..c8b70e1a3 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.base/src/com/android/ide/eclipse/base/internal/preferences/UsagePreferencePage.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ide.eclipse.base.internal.preferences; + +import com.android.sdkstats.DdmsPreferenceStore; +import com.android.sdkstats.SdkStatsPermissionDialog; + +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +public class UsagePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + private static final int WRAP_WIDTH_PX = 200; + + private BooleanFieldEditor mOptInCheckBox; + private DdmsPreferenceStore mStore = new DdmsPreferenceStore(); + + public UsagePreferencePage() { + } + + @Override + public void init(IWorkbench workbench) { + // pass + } + + @Override + protected Control createContents(Composite parent) { + Composite top = new Composite(parent, SWT.NONE); + top.setLayout(new GridLayout(1, false)); + top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label l = new Label(top, SWT.WRAP); + l.setText(SdkStatsPermissionDialog.BODY_TEXT); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.widthHint = WRAP_WIDTH_PX; + l.setLayoutData(gd); + + Link privacyPolicyLink = new Link(top, SWT.WRAP); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.widthHint = WRAP_WIDTH_PX; + privacyPolicyLink.setLayoutData(gd); + privacyPolicyLink.setText(SdkStatsPermissionDialog.PRIVACY_POLICY_LINK_TEXT); + + privacyPolicyLink.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + SdkStatsPermissionDialog.openUrl(event.text); + } + }); + + mOptInCheckBox = new BooleanFieldEditor(DdmsPreferenceStore.PING_OPT_IN, + SdkStatsPermissionDialog.CHECKBOX_TEXT, top); + mOptInCheckBox.setPage(this); + mOptInCheckBox.setPreferenceStore(mStore.getPreferenceStore()); + mOptInCheckBox.load(); + + return top; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#performCancel() + */ + @Override + public boolean performCancel() { + mOptInCheckBox.load(); + return super.performCancel(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#performDefaults() + */ + @Override + protected void performDefaults() { + mOptInCheckBox.loadDefault(); + super.performDefaults(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#performOk() + */ + @Override + public boolean performOk() { + save(); + return super.performOk(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#performApply() + */ + @Override + protected void performApply() { + save(); + super.performApply(); + } + + private void save() { + mStore.setPingOptIn(mOptInCheckBox.getBooleanValue()); + } +} |