aboutsummaryrefslogtreecommitdiffstats
path: root/ide_common/src/com/android/ide/common/resources/configuration
diff options
context:
space:
mode:
authorMichael Wright <michaelwr@google.com>2012-06-12 20:20:47 -0700
committerMichael Wright <michaelwr@google.com>2012-06-18 19:31:27 -0700
commit71da4451642194b53f40f7c4f6a3b983d53561a3 (patch)
treed7772ac881dfd750bcfd12ba07789db7ac49fd29 /ide_common/src/com/android/ide/common/resources/configuration
parent98632a6d99881504d049c9c72274760b462c9e6f (diff)
downloadsdk-71da4451642194b53f40f7c4f6a3b983d53561a3.zip
sdk-71da4451642194b53f40f7c4f6a3b983d53561a3.tar.gz
sdk-71da4451642194b53f40f7c4f6a3b983d53561a3.tar.bz2
Added FolderConfig creation and config loading for Devices
Change-Id: Iae7b32df991df946bba22aba5ab9b32ed2c094ea
Diffstat (limited to 'ide_common/src/com/android/ide/common/resources/configuration')
-rw-r--r--ide_common/src/com/android/ide/common/resources/configuration/DeviceConfigHelper.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/ide_common/src/com/android/ide/common/resources/configuration/DeviceConfigHelper.java b/ide_common/src/com/android/ide/common/resources/configuration/DeviceConfigHelper.java
new file mode 100644
index 0000000..7ed955f
--- /dev/null
+++ b/ide_common/src/com/android/ide/common/resources/configuration/DeviceConfigHelper.java
@@ -0,0 +1,101 @@
+/*
+ * 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.common.resources.configuration;
+
+import com.android.annotations.Nullable;
+import com.android.sdklib.devices.Device;
+import com.android.sdklib.devices.Hardware;
+import com.android.sdklib.devices.Screen;
+import com.android.sdklib.devices.State;
+
+public class DeviceConfigHelper {
+ /**
+ * Returns a {@link FolderConfiguration} based on the given state
+ *
+ * @param state
+ * The {@link State} of the {@link Device} to base the
+ * {@link FolderConfiguration} on. Can be null.
+ * @return A {@link FolderConfiguration} based on the given {@link State}.
+ * If the given {@link State} is null, the result is also null;
+ */
+ @Nullable
+ public static FolderConfiguration getFolderConfig(@Nullable State state) {
+ if (state == null) {
+ return null;
+ }
+
+ Hardware hw = state.getHardware();
+
+ FolderConfiguration config = new FolderConfiguration();
+ config.createDefault();
+ Screen screen = hw.getScreen();
+ config.setDensityQualifier(new DensityQualifier(screen.getPixelDensity()));
+ config.setNavigationMethodQualifier(new NavigationMethodQualifier(hw.getNav()));
+ ScreenDimensionQualifier sdq;
+ if (screen.getXDimension() > screen.getYDimension()) {
+ sdq = new ScreenDimensionQualifier(screen.getXDimension(), screen.getYDimension());
+ } else {
+ sdq = new ScreenDimensionQualifier(screen.getYDimension(), screen.getXDimension());
+ }
+ config.setScreenDimensionQualifier(sdq);
+ config.setScreenRatioQualifier(new ScreenRatioQualifier(screen.getRatio()));
+ config.setScreenSizeQualifier(new ScreenSizeQualifier(screen.getSize()));
+ config.setTextInputMethodQualifier(new TextInputMethodQualifier(hw.getKeyboard()));
+ config.setTouchTypeQualifier(new TouchScreenQualifier(screen.getMechanism()));
+
+ config.setKeyboardStateQualifier(new KeyboardStateQualifier(state.getKeyState()));
+ config.setNavigationStateQualifier(new NavigationStateQualifier(state.getNavState()));
+ config.setScreenOrientationQualifier(
+ new ScreenOrientationQualifier(state.getOrientation()));
+
+ config.updateScreenWidthAndHeight();
+
+ return config;
+ }
+
+ /**
+ * Returns a {@link FolderConfiguration} based on the {@link State} given by
+ * the {@link Device} and the state name.
+ *
+ * @param d
+ * The {@link Device} to base the {@link FolderConfiguration} on.
+ * @param stateName
+ * The name of the state to base the {@link FolderConfiguration}
+ * on.
+ * @return The {@link FolderConfiguration} based on the determined
+ * {@link State}. If there is no {@link State} with the given state
+ * name for the given device, null is returned.
+ */
+ @Nullable
+ public static FolderConfiguration getFolderConfig(Device d, String stateName) {
+ return getFolderConfig(d.getState(stateName));
+ }
+
+ /**
+ * Returns a {@link FolderConfiguration} based on the default {@link State}
+ * for the given {@link Device}.
+ *
+ * @param d
+ * The {@link Device} to generate the {@link FolderConfiguration}
+ * from.
+ * @return A {@link FolderConfiguration} based on the default {@link State}
+ * for the given {@link Device}
+ */
+ public static FolderConfiguration getFolderConfig(Device d) {
+ return getFolderConfig(d.getDefaultState());
+ }
+}