diff options
author | Raphael <raphael@google.com> | 2009-06-11 18:10:08 -0700 |
---|---|---|
committer | Raphael <raphael@google.com> | 2009-06-11 18:14:11 -0700 |
commit | 0c63ade252ea194324b3da9a390cf383b2a6bfa7 (patch) | |
tree | e8b9eeb7bcfb6077bb1ceced8bfce9718af80721 /sdkmanager | |
parent | c72990965751f79b5b6d2e7542f4092df5d70b6d (diff) | |
download | sdk-0c63ade252ea194324b3da9a390cf383b2a6bfa7.zip sdk-0c63ade252ea194324b3da9a390cf383b2a6bfa7.tar.gz sdk-0c63ade252ea194324b3da9a390cf383b2a6bfa7.tar.bz2 |
SDK Updater: SettingsController that handles the settings.
There is not any longer any logic in the SettingsPage,
it is handled now by a "SettingsControllers" which is
available via UpdaterData. The page only takes care of
notifying the controller via a callback when settings
have changed in the UI.
Diffstat (limited to 'sdkmanager')
6 files changed, 211 insertions, 94 deletions
diff --git a/sdkmanager/app/src/com/android/sdkmanager/internal/repository/SettingsPage.java b/sdkmanager/app/src/com/android/sdkmanager/internal/repository/SettingsPage.java index b07617f..ac7c4e4 100755 --- a/sdkmanager/app/src/com/android/sdkmanager/internal/repository/SettingsPage.java +++ b/sdkmanager/app/src/com/android/sdkmanager/internal/repository/SettingsPage.java @@ -16,8 +16,6 @@ package com.android.sdkmanager.internal.repository;
-import com.android.prefs.AndroidLocation;
-import com.android.prefs.AndroidLocation.AndroidLocationException;
import com.android.sdkuilib.internal.repository.ISettingsPage;
import org.eclipse.swt.SWT;
@@ -31,28 +29,15 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.net.URL;
import java.util.Properties;
-/*
- * TODO list
- * - The window should probably set a callback to be notified when settings are changed.
- * - Actually use the settings.
- */
public class SettingsPage extends Composite implements ISettingsPage {
- private static final String SETTINGS_FILENAME = "androidtool.cfg"; //$NON-NLS-1$
-
- /** Java system setting picked up by {@link URL} for http proxy port */
- private static final String JAVA_HTTP_PROXY_PORT = "http.proxyPort"; //$NON-NLS-1$
- /** Java system setting picked up by {@link URL} for http proxy host */
- private static final String JAVA_HTTP_PROXY_HOST = "http.proxyHost"; //$NON-NLS-1$
+ // data members
+ private SettingsChangedCallback mSettingsChangedCallback;
+ // UI widgets
private Group mProxySettingsGroup;
private Group mPlaceholderGroup;
private Button mApplyButton;
@@ -130,85 +115,37 @@ public class SettingsPage extends Composite implements ISettingsPage { private void postCreate() {
}
- private void onApplySelected() {
- applySettings();
- saveSettings();
+ /** Loads settings from the given {@link Properties} container and update the page UI. */
+ public void loadSettings(Properties in_settings) {
+ mProxyServerText.setText(in_settings.getProperty(JAVA_HTTP_PROXY_HOST, "")); //$NON-NLS-1$
+ mProxyPortText.setText(in_settings.getProperty(JAVA_HTTP_PROXY_PORT, "")); //$NON-NLS-1$
}
- /**
- * Update Java system properties for the HTTP proxy.
- */
- public void applySettings() {
- Properties props = System.getProperties();
- props.put(JAVA_HTTP_PROXY_HOST, mProxyServerText.getText());
- props.put(JAVA_HTTP_PROXY_PORT, mProxyPortText.getText());
+ /** Called by the application to retrieve settings from the UI and store them in
+ * the given {@link Properties} container. */
+ public void retrieveSettings(Properties out_settings) {
+ out_settings.put(JAVA_HTTP_PROXY_HOST, mProxyServerText.getText());
+ out_settings.put(JAVA_HTTP_PROXY_PORT, mProxyPortText.getText());
}
/**
- * Saves settings.
+ * Called by the application to give a callback that the page should invoke when
+ * settings must be applied. The page does not apply the settings itself, instead
+ * it notifies the application.
*/
- private void saveSettings() {
- Properties props = new Properties();
- props.put(JAVA_HTTP_PROXY_HOST, mProxyServerText.getText());
- props.put(JAVA_HTTP_PROXY_PORT, mProxyPortText.getText());
-
-
- FileOutputStream fos = null;
- try {
- String folder = AndroidLocation.getFolder();
- File f = new File(folder, SETTINGS_FILENAME);
-
- fos = new FileOutputStream(f);
-
- props.store( fos, "## Settings for Android Tool"); //$NON-NLS-1$
-
- } catch (AndroidLocationException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (fos != null) {
- try {
- fos.close();
- } catch (IOException e) {
- }
- }
- }
+ public void setOnSettingsChanged(SettingsChangedCallback settingsChangedCallback) {
+ mSettingsChangedCallback = settingsChangedCallback;
}
/**
- * Load settings and puts them in the UI.
+ * Notify the application that settings have changed.
*/
- public void loadSettings() {
- FileInputStream fis = null;
- try {
- String folder = AndroidLocation.getFolder();
- File f = new File(folder, SETTINGS_FILENAME);
- if (f.exists()) {
- fis = new FileInputStream(f);
-
- Properties props = new Properties();
- props.load(fis);
-
- mProxyServerText.setText(props.getProperty(JAVA_HTTP_PROXY_HOST, "")); //$NON-NLS-1$
- mProxyPortText.setText(props.getProperty(JAVA_HTTP_PROXY_PORT, "")); //$NON-NLS-1$
- }
-
- } catch (AndroidLocationException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (fis != null) {
- try {
- fis.close();
- } catch (IOException e) {
- }
- }
+ private void onApplySelected() {
+ if (mSettingsChangedCallback != null) {
+ mSettingsChangedCallback.onSettingsChanged(this);
}
}
-
// End of hiding from SWT Designer
//$hide<<$
}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepository.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepository.java index d3dfb25..cd6d45b 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepository.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepository.java @@ -26,7 +26,7 @@ public class SdkRepository { /** The URL of the official Google sdk-repository site. */
public static final String URL_GOOGLE_SDK_REPO_SITE =
- "https://dl.google.com/android/eclipse/repository/repository.xml"; //$NON-NLS-1$
+ "https://dl.google.com/android/repository/repository.xml"; //$NON-NLS-1$
/** The XML namespace of the sdk-repository XML. */
public static final String NS_SDK_REPOSITORY =
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ISettingsPage.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ISettingsPage.java index bf2471d..02d0b6e 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ISettingsPage.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ISettingsPage.java @@ -16,15 +16,42 @@ package com.android.sdkuilib.internal.repository;
+import java.net.URL;
+import java.util.Properties;
+
/**
* Interface that a settings page must implement.
*/
public interface ISettingsPage {
- /** Loads settings. Does not apply them. */
- public abstract void loadSettings();
+ /** Java system setting picked up by {@link URL} for http proxy port */
+ public static final String JAVA_HTTP_PROXY_PORT = "http.proxyPort"; //$NON-NLS-1$
+ /** Java system setting picked up by {@link URL} for http proxy host */
+ public static final String JAVA_HTTP_PROXY_HOST = "http.proxyHost"; //$NON-NLS-1$
+
+ /** Loads settings from the given {@link Properties} container and update the page UI. */
+ public abstract void loadSettings(Properties in_settings);
+
+ /** Called by the application to retrieve settings from the UI and store them in
+ * the given {@link Properties} container. */
+ public abstract void retrieveSettings(Properties out_settings);
- /** Applies current settings. */
- public abstract void applySettings();
+ /**
+ * Called by the application to give a callback that the page should invoke when
+ * settings have changed.
+ */
+ public abstract void setOnSettingsChanged(SettingsChangedCallback settingsChangedCallback);
+ /**
+ * Callback used to notify the application that settings have changed and need to be
+ * applied.
+ */
+ public interface SettingsChangedCallback {
+ /**
+ * Invoked by the settings page when settings have changed and need to be
+ * applied. The application will call {@link ISettingsPage#retrieveSettings(Properties)}
+ * and apply the new settings.
+ */
+ public abstract void onSettingsChanged(ISettingsPage page);
+ }
}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SettingsController.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SettingsController.java new file mode 100755 index 0000000..06a69d1 --- /dev/null +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SettingsController.java @@ -0,0 +1,142 @@ +/*
+ * Copyright (C) 2009 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.sdkuilib.internal.repository;
+
+import com.android.prefs.AndroidLocation;
+import com.android.prefs.AndroidLocation.AndroidLocationException;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ *
+ */
+public class SettingsController {
+
+ private static final String SETTINGS_FILENAME = "androidtool.cfg"; //$NON-NLS-1$
+
+ private final Properties mProperties = new Properties();
+
+ private ISettingsPage mSettingsPage;
+
+ public SettingsController() {
+ }
+
+ /**
+ * Associate the given {@link ISettingsPage} with this {@link SettingsController}.
+ *
+ * This loads the current properties into the setting page UI.
+ * It then associates the SettingsChanged callback with this controller.
+ */
+ public void setSettingsPage(ISettingsPage settingsPage) {
+
+ mSettingsPage = settingsPage;
+ mSettingsPage.loadSettings(mProperties);
+
+ settingsPage.setOnSettingsChanged(new ISettingsPage.SettingsChangedCallback() {
+ public void onSettingsChanged(ISettingsPage page) {
+ SettingsController.this.onSettingsChanged();
+ }
+ });
+ }
+
+ /**
+ * Load settings from the settings file.
+ */
+ public void loadSettings() {
+ FileInputStream fis = null;
+ try {
+ String folder = AndroidLocation.getFolder();
+ File f = new File(folder, SETTINGS_FILENAME);
+ if (f.exists()) {
+ fis = new FileInputStream(f);
+
+ mProperties.load(fis);
+ }
+
+ } catch (AndroidLocationException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ }
+
+ /**
+ * Saves settings to the settings file.
+ */
+ public void saveSettings() {
+
+ FileOutputStream fos = null;
+ try {
+ String folder = AndroidLocation.getFolder();
+ File f = new File(folder, SETTINGS_FILENAME);
+
+ fos = new FileOutputStream(f);
+
+ mProperties.store( fos, "## Settings for Android Tool"); //$NON-NLS-1$
+
+ } catch (AndroidLocationException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ }
+
+ /**
+ * When settings have changed: retrieve the new settings, apply them and save them.
+ *
+ * This updats Java system properties for the HTTP proxy.
+ */
+ private void onSettingsChanged() {
+ if (mSettingsPage == null) {
+ return;
+ }
+
+ mSettingsPage.retrieveSettings(mProperties);
+ applySettings();
+ saveSettings();
+ }
+
+ /**
+ * Applies the current settings.
+ */
+ public void applySettings() {
+ Properties props = System.getProperties();
+ props.put(ISettingsPage.JAVA_HTTP_PROXY_HOST,
+ mProperties.getProperty(ISettingsPage.JAVA_HTTP_PROXY_HOST, "")); //$NON-NLS-1$
+ props.put(ISettingsPage.JAVA_HTTP_PROXY_PORT,
+ mProperties.getProperty(ISettingsPage.JAVA_HTTP_PROXY_PORT, "")); //$NON-NLS-1$
+ }
+
+}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java index 28d8694..0342e6e 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java @@ -55,6 +55,8 @@ class UpdaterData { private ImageFactory mImageFactory;
+ private final SettingsController mSettingsController = new SettingsController();
+
private final ArrayList<ISdkListener> mListeners = new ArrayList<ISdkListener>();
public interface ISdkListener {
@@ -128,6 +130,10 @@ class UpdaterData { return mAvdManager;
}
+ public SettingsController getSettingsController() {
+ return mSettingsController;
+ }
+
public void addListeners(ISdkListener listener) {
if (mListeners.contains(listener) == false) {
mListeners.add(listener);
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterWindowImpl.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterWindowImpl.java index d63efb6..2c3d75c 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterWindowImpl.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterWindowImpl.java @@ -321,16 +321,21 @@ public class UpdaterWindowImpl { /**
* Initializes settings.
- * Thist must be called after addExtraPages(), which created a settings page.
- * Iterate through all the pages and it one is a setting page, load and apply these
- * settings.
+ * This must be called after addExtraPages(), which created a settings page.
+ * Iterate through all the pages to find the first (and supposedly unique) setting page,
+ * and use it to load and apply these settings.
*/
private void initializeSettings() {
+ SettingsController c = mUpdaterData.getSettingsController();
+ c.loadSettings();
+ c.applySettings();
+
for (Object page : mPages) {
if (page instanceof ISettingsPage) {
ISettingsPage settingsPage = (ISettingsPage) page;
- settingsPage.loadSettings();
- settingsPage.applySettings();
+
+ c.setSettingsPage(settingsPage);
+ break;
}
}
}
|