OSDN Git Service

Landscape layout for DeskClock.
authorDaniel Sandler <dsandler@google.com>
Tue, 27 Oct 2009 13:46:05 +0000 (09:46 -0400)
committerDaniel Sandler <dsandler@google.com>
Tue, 27 Oct 2009 13:46:05 +0000 (09:46 -0400)
Created several new sub-layouts that are shared between the
two orientations.

Known issue: the activity currently re-starts (forgetting
the dim state) between orientations.

AndroidManifest.xml
res/layout-land/desk_clock.xml [new file with mode: 0644]
res/layout/desk_clock.xml
res/layout/desk_clock_battery.xml [new file with mode: 0644]
res/layout/desk_clock_buttons.xml [new file with mode: 0644]
res/layout/desk_clock_time_date.xml [new file with mode: 0644]
src/com/android/deskclock/DeskClock.java

index cb250c5..0a89f0f 100644 (file)
@@ -17,7 +17,7 @@
                 android:label="@string/app_label"
                 android:theme="@android:style/Theme.Wallpaper.NoTitleBar"
                 android:icon="@drawable/ic_widget_analog_clock"
-                android:configChanges="orientation|keyboardHidden|keyboard|navigation">
+                >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.DEFAULT" />
diff --git a/res/layout-land/desk_clock.xml b/res/layout-land/desk_clock.xml
new file mode 100644 (file)
index 0000000..477c18b
--- /dev/null
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<!-- This is the alarm clock in LANDSCAPE desk dock mode.
+     -->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+    <LinearLayout
+        android:id="@+id/desk_clock"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:orientation="vertical"
+        >
+
+        <!-- Entire display region (everything but bottom buttons) -->
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_gravity="left"
+            android:layout_weight="1"
+            android:layout_width="fill_parent"
+            android:layout_height="fill_parent"
+            android:layout_marginLeft="20dip"
+            android:layout_marginTop="20dip"
+            android:layout_marginRight="14dip"
+            android:layout_marginBottom="14dip"
+            >
+
+            <!-- across the top: next alarm, battery, nightmode button -->
+            <LinearLayout
+                android:orientation="horizontal"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_weight="0"
+                android:layout_marginBottom="6dip"
+                android:gravity="center_vertical"
+                >
+                <TextView android:id="@+id/nextAlarm"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:gravity="left"
+                    android:textSize="18sp"
+                    android:textColor="#FFFFFFFF"
+                    android:drawablePadding="6dip"
+                    android:drawableLeft="@android:drawable/ic_lock_idle_alarm"
+                    android:shadowColor="#C0000000"
+                    android:shadowDx="0"
+                    android:shadowDy="0"
+                    android:shadowRadius="3.0"                        
+                    />
+
+                <include layout="@layout/desk_clock_battery"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginRight="8dip"
+                    android:layout_weight="0"
+                    />
+
+                <Button android:id="@+id/nightmode_button"
+                    android:layout_weight="0"
+                    android:layout_height="wrap_content"
+                    android:layout_width="wrap_content"
+                    android:text="@string/nightmode_button_title_placeholder"
+                    />
+            </LinearLayout>
+
+            <!-- second row: date/time on the left, weather on the right -->
+            <LinearLayout
+                android:orientation="horizontal"
+                android:layout_weight="1"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:gravity="center_vertical"
+                >
+
+                <include layout="@layout/desk_clock_time_date"
+                    android:layout_width="fill_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1" />
+
+                <View android:id="@+id/weather" xmlns:android="http://schemas.android.com/apk/res/android"
+                    android:layout_height="100dip"
+                    android:layout_width="wrap_content"
+                    android:background="#C0CC00CC"
+                    android:layout_marginBottom="12dip"
+                    android:layout_weight="1"
+                    android:layout_marginLeft="12dip"
+                    />
+
+
+            </LinearLayout>
+
+        </LinearLayout>
+
+        <include layout="@layout/desk_clock_buttons" />
+
+    </LinearLayout>
+
+    <View android:id="@+id/window_tint"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:background="#D0000000"
+        android:visibility="visible"
+        android:clickable="false"
+        />
+
+</FrameLayout>
index 6031e45..c688a08 100644 (file)
                     />
             </LinearLayout>
 
-
-            <!-- digital clock & date, together -->
-            <LinearLayout
-                android:orientation="vertical"
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content"
+            <include layout="@layout/desk_clock_time_date"
                 android:layout_weight="1"
-                android:gravity="left|center_vertical"
-                android:layout_marginBottom="12dip"
-                >
-
-                <com.android.deskclock.DigitalClock android:id="@+id/time"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:layout_marginBottom="12dip"
-                    android:layout_marginLeft="-8dip"
-                    >
-                    <!-- negative left margin above accounts for Clockopia's
-                         generous glyph padding -->
-
-                    <TextView android:id="@+id/timeDisplay"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:gravity="center"
-                        android:textSize="100sp"
-                        android:textColor="#FFFFFFFF"
-                        android:shadowColor="#C0000000"
-                        android:shadowDx="0"
-                        android:shadowDy="0"
-                        android:shadowRadius="3.0"                        
-                        />
-
-
-                    <TextView android:id="@+id/am_pm"
-                        android:layout_width="wrap_content"
-                        android:layout_height="fill_parent"
-                        android:gravity="bottom"
-                        android:textSize="28sp"
-                        android:singleLine="true"
-                        android:layout_marginLeft="3dip"
-                        android:textColor="#FFFFFFFF"
-                        android:shadowColor="#C0000000"
-                        android:shadowDx="0"
-                        android:shadowDy="0"
-                        android:shadowRadius="3.0"                        
-                        />
-
-                </com.android.deskclock.DigitalClock>
-
-                <TextView android:id="@+id/date"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:gravity="left"
-                    android:textSize="18sp"
-                    android:textColor="#FFFFFFFF"
-                    android:shadowColor="#C0000000"
-                    android:shadowDx="0"
-                    android:shadowDy="0"
-                    android:shadowRadius="3.0"                        
-                    />
-            
-            </LinearLayout>
+                />
 
-            <!-- TODO: weather -->
-            <View android:id="@+id/weather"
-                android:layout_width="wrap_content"
+            <View android:id="@+id/weather" xmlns:android="http://schemas.android.com/apk/res/android"
                 android:layout_height="100dip"
-                android:layout_weight="0"
-                android:background="#C0FF8000"
+                android:layout_width="wrap_content"
+                android:background="#C0CC00CC"
                 android:layout_marginBottom="12dip"
-                />
-
-            <!-- battery/charge status -->
-            <TextView android:id="@+id/battery"
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content"
                 android:layout_weight="0"
-                android:gravity="right"
-                android:textSize="18sp"
-                android:textColor="#FFFFFFFF"
-                android:drawablePadding="6dip"
-                android:shadowColor="#C0000000"
-                android:shadowDx="0"
-                android:shadowDy="0"
-                android:shadowRadius="3.0"                        
                 />
 
-        </LinearLayout>
 
-        <!-- buttons -->
-        <LinearLayout
-            android:orientation="horizontal"
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content"
-            android:layout_weight="0"
-            >
-            <!--
-                android:background="@null"
-                android:textAppearance="@android:style/TextAppearance.Small.Inverse"
-                -->
-            <Button android:id="@+id/alarm_button"
-                android:layout_height="wrap_content"
-                android:layout_width="fill_parent"
-                android:layout_weight=".25"
-                android:text="@string/alarm_button_title_placeholder"
-                />
-            <Button android:id="@+id/gallery_button"
-                android:layout_height="wrap_content"
-                android:layout_width="fill_parent"
-                android:layout_weight=".25"
-                android:text="@string/gallery_button_title_placeholder"
-                />
-            <Button android:id="@+id/music_button"
-                android:layout_height="wrap_content"
-                android:layout_width="fill_parent"
-                android:layout_weight=".25"
-                android:text="@string/music_button_title_placeholder"
-                />
-            <Button android:id="@+id/home_button"
+            <include layout="@layout/desk_clock_battery"
                 android:layout_height="wrap_content"
                 android:layout_width="fill_parent"
-                android:layout_weight=".25"
-                android:text="@string/home_button_title_placeholder"
+                android:layout_weight="0"
                 />
 
         </LinearLayout>
 
+        <include layout="@layout/desk_clock_buttons" />
+
     </LinearLayout>
 
     <View android:id="@+id/window_tint"
diff --git a/res/layout/desk_clock_battery.xml b/res/layout/desk_clock_battery.xml
new file mode 100644 (file)
index 0000000..ded2ffc
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<!-- battery/charge status -->
+<TextView android:id="@+id/battery" xmlns:android="http://schemas.android.com/apk/res/android"
+    android:gravity="right"
+    android:textSize="18sp"
+    android:textColor="#FFFFFFFF"
+    android:drawablePadding="6dip"
+    android:shadowColor="#C0000000"
+    android:shadowDx="0"
+    android:shadowDy="0"
+    android:shadowRadius="3.0"                        
+    />
diff --git a/res/layout/desk_clock_buttons.xml b/res/layout/desk_clock_buttons.xml
new file mode 100644 (file)
index 0000000..ad11cbe
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<!-- Buttons for the desk-mode alarm clock. -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="horizontal"
+    android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    android:layout_weight="0"
+    >
+    <Button android:id="@+id/alarm_button"
+        android:layout_height="wrap_content"
+        android:layout_width="fill_parent"
+        android:layout_weight=".25"
+        android:text="@string/alarm_button_title_placeholder"
+        />
+    <Button android:id="@+id/gallery_button"
+        android:layout_height="wrap_content"
+        android:layout_width="fill_parent"
+        android:layout_weight=".25"
+        android:text="@string/gallery_button_title_placeholder"
+        />
+    <Button android:id="@+id/music_button"
+        android:layout_height="wrap_content"
+        android:layout_width="fill_parent"
+        android:layout_weight=".25"
+        android:text="@string/music_button_title_placeholder"
+        />
+    <Button android:id="@+id/home_button"
+        android:layout_height="wrap_content"
+        android:layout_width="fill_parent"
+        android:layout_weight=".25"
+        android:text="@string/home_button_title_placeholder"
+        />
+</LinearLayout>
diff --git a/res/layout/desk_clock_time_date.xml b/res/layout/desk_clock_time_date.xml
new file mode 100644 (file)
index 0000000..abd55cf
--- /dev/null
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<!-- digital clock & date, together -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:gravity="left|center_vertical"
+    android:layout_marginBottom="12dip"
+    android:layout_weight="1"
+    >
+
+    <com.android.deskclock.DigitalClock android:id="@+id/time"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginBottom="12dip"
+        android:layout_marginLeft="-8dip"
+        >
+        <!-- negative left margin above accounts for Clockopia's
+             generous glyph padding -->
+
+        <TextView android:id="@+id/timeDisplay"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:gravity="center"
+            android:textSize="100sp"
+            android:textColor="#FFFFFFFF"
+            android:shadowColor="#C0000000"
+            android:shadowDx="0"
+            android:shadowDy="0"
+            android:shadowRadius="3.0"                        
+            />
+
+
+        <TextView android:id="@+id/am_pm"
+            android:layout_width="wrap_content"
+            android:layout_height="fill_parent"
+            android:gravity="bottom"
+            android:textSize="28sp"
+            android:singleLine="true"
+            android:layout_marginLeft="3dip"
+            android:textColor="#FFFFFFFF"
+            android:shadowColor="#C0000000"
+            android:shadowDx="0"
+            android:shadowDy="0"
+            android:shadowRadius="3.0"                        
+            />
+
+    </com.android.deskclock.DigitalClock>
+
+    <TextView android:id="@+id/date"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:gravity="left"
+        android:textSize="18sp"
+        android:textColor="#FFFFFFFF"
+        android:shadowColor="#C0000000"
+        android:shadowDx="0"
+        android:shadowDy="0"
+        android:shadowRadius="3.0"                        
+        />
+
+</LinearLayout>
index 6770aa9..a451372 100644 (file)
@@ -187,10 +187,8 @@ public class DeskClock extends Activity {
         unregisterReceiver(mIntentReceiver);
     }
 
-    @Override
-    protected void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
 
+    private void initViews() {
         setContentView(R.layout.desk_clock);
 
         mTime = (DigitalClock) findViewById(R.id.time);
@@ -247,6 +245,20 @@ public class DeskClock extends Activity {
             }
         });
 
+        doDim();
+    }
+
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+        initViews();
+    }
+
+
+    @Override
+    protected void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+        initViews();
     }
 
 }