Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.sdklib.internal.repository.updater;
import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.annotations.VisibleForTesting;
import com.android.annotations.VisibleForTesting.Visibility;
import com.android.prefs.AndroidLocation;
import com.android.prefs.AndroidLocation.AndroidLocationException;
import com.android.sdklib.io.FileOp;
import com.android.sdklib.io.IFileOp;
import com.android.utils.ILogger;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;
/**
* Controller class to get settings values. Settings are kept in-memory.
* Users of this class must first load the settings before changing them and save
* them when modified.
*
* Settings are enumerated by constants in {@link ISettingsPage}.
*/
public class SettingsController {
private static final String SETTINGS_FILENAME = "androidtool.cfg"; //$NON-NLS-1$
private final IFileOp mFileOp;
private final ILogger mSdkLog;
private final Settings mSettings;
public interface OnChangedListener {
public void onSettingsChanged(@NonNull SettingsController controller,
@NonNull Settings oldSettings);
}
private final List mChangedListeners = new ArrayList(1);
/** The currently associated {@link ISettingsPage}. Can be null. */
private ISettingsPage mSettingsPage;
/**
* Constructs a new default {@link SettingsController}.
*
* @param sdkLog A non-null logger to use.
*/
public SettingsController(@NonNull ILogger sdkLog) {
this(new FileOp(), sdkLog);
}
/**
* Constructs a new default {@link SettingsController}.
*
* @param fileOp A non-null {@link FileOp} to perform file operations (to load/save settings.)
* @param sdkLog A non-null logger to use.
*/
public SettingsController(@NonNull IFileOp fileOp, @NonNull ILogger sdkLog) {
this(fileOp, sdkLog, new Settings());
}
/**
* Specialized constructor that wraps an existing {@link Settings} instance.
* This is mostly used in unit-tests to override settings that are being used.
* Normal usage should NOT need to call this constructor.
*
* @param fileOp A non-null {@link FileOp} to perform file operations (to load/save settings)
* @param sdkLog A non-null logger to use.
* @param settings A non-null {@link Settings} to use as-is. It is not duplicated.
*/
@VisibleForTesting(visibility=Visibility.PRIVATE)
protected SettingsController(@NonNull IFileOp fileOp,
@NonNull ILogger sdkLog,
@NonNull Settings settings) {
mFileOp = fileOp;
mSdkLog = sdkLog;
mSettings = settings;
}
@NonNull
public Settings getSettings() {
return mSettings;
}
public void registerOnChangedListener(@Nullable OnChangedListener listener) {
if (listener != null && !mChangedListeners.contains(listener)) {
mChangedListeners.add(listener);
}
}
public void unregisterOnChangedListener(@Nullable OnChangedListener listener) {
if (listener != null) {
mChangedListeners.remove(listener);
}
}
//--- Access to settings ------------
public static class Settings {
private final Properties mProperties;
/** Initialize an empty set of settings. */
public Settings() {
mProperties = new Properties();
}
/** Duplicates a set of settings. */
public Settings(@NonNull Settings settings) {
this();
for (Entry