Merge "Convert calculator to use ViewPager for multi-page layouts."
diff --git a/Android.mk b/Android.mk
index 4008d8c..4e4f40e 100644
--- a/Android.mk
+++ b/Android.mk
@@ -19,7 +19,7 @@
LOCAL_MODULE_TAGS := optional
-LOCAL_STATIC_JAVA_LIBRARIES := libarity
+LOCAL_STATIC_JAVA_LIBRARIES := libarity android-support-v4
LOCAL_SRC_FILES := $(call all-java-files-under, src)
@@ -32,6 +32,7 @@
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libarity:arity-2.1.2.jar
+
include $(BUILD_MULTI_PREBUILT)
# Use the folloing include to make our test apk.
diff --git a/res/layout-land/advanced_pad.xml b/res/layout-land/advanced_pad.xml
new file mode 100644
index 0000000..55cef52
--- /dev/null
+++ b/res/layout-land/advanced_pad.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+/*
+* Copyright (C) 2011, 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.
+*/
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/advancedPad"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:orientation="vertical"
+ android:layout_gravity="center"
+ >
+
+ <LinearLayout
+ android:layout_weight="1"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ >
+ <com.android.calculator2.ColorButton
+ android:id="@+id/sin"
+ android:text="@string/sin"
+ style="@style/button_small_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/cos"
+ android:text="@string/cos"
+ style="@style/button_small_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/tan"
+ android:text="@string/tan"
+ style="@style/button_small_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/pi"
+ android:text="@string/pi"
+ style="@style/button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/factorial"
+ android:text="@string/factorial"
+ style="@style/button_style"
+ />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_weight="1"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ >
+ <com.android.calculator2.ColorButton
+ android:id="@+id/ln"
+ android:text="@string/ln"
+ style="@style/button_small_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/lg"
+ android:text="@string/lg"
+ style="@style/button_small_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/e"
+ android:text="@string/e"
+ style="@style/button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/power"
+ android:text="@string/power"
+ style="@style/button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/sqrt"
+ android:text="@string/sqrt"
+ style="@style/button_style"
+ />
+ </LinearLayout>
+</LinearLayout>
diff --git a/res/layout-land/main.xml b/res/layout-land/main.xml
index ac4f8af..f55db13 100644
--- a/res/layout-land/main.xml
+++ b/res/layout-land/main.xml
@@ -76,206 +76,11 @@
</FrameLayout>
</LinearLayout>
- <com.android.calculator2.PanelSwitcher
+ <android.support.v4.view.ViewPager
android:id="@+id/panelswitch"
android:layout_width="match_parent"
android:layout_height="0dp"
- android:layout_weight="5"
- >
+ android:layout_weight="4"
+ />
- <LinearLayout
- android:id="@+id/simplePad"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:layout_gravity="center"
- >
- <LinearLayout
- android:layout_weight="1"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- >
- <com.android.calculator2.ColorButton
- android:id="@+id/digit7"
- android:text="@string/digit7"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit8"
- android:text="@string/digit8"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit9"
- android:text="@string/digit9"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/leftParen"
- android:text="@string/leftParen"
- style="@style/button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/rightParen"
- android:text="@string/rightParen"
- style="@style/button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/mul"
- android:text="@string/mul"
- style="@style/button_style"
- />
- </LinearLayout>
-
- <LinearLayout
- android:layout_weight="1"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- >
- <com.android.calculator2.ColorButton
- android:id="@+id/digit4"
- android:text="@string/digit4"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit5"
- android:text="@string/digit5"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit6"
- android:text="@string/digit6"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/dot"
- android:text="@string/dot"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/div"
- android:text="@string/div"
- style="@style/button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/minus"
- android:text="@string/minus"
- style="@style/button_style"
- />
- </LinearLayout>
-
- <LinearLayout
- android:layout_weight="1"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- >
- <com.android.calculator2.ColorButton
- android:id="@+id/digit1"
- android:text="@string/digit1"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit2"
- android:text="@string/digit2"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit3"
- android:text="@string/digit3"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit0"
- android:text="@string/digit0"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/equal"
- android:text="@string/equal"
- style="@style/button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/plus"
- android:text="@string/plus"
- style="@style/button_style"
- />
- </LinearLayout>
- </LinearLayout>
-
- <LinearLayout
- android:id="@+id/advancedPad"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical"
- android:layout_gravity="center"
- android:layout_marginTop="5dp"
- android:layout_marginBottom="0dp"
- >
-
- <LinearLayout
- android:layout_weight="1"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- >
- <com.android.calculator2.ColorButton
- android:id="@+id/sin"
- android:text="@string/sin"
- style="@style/button_small_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/cos"
- android:text="@string/cos"
- style="@style/button_small_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/tan"
- android:text="@string/tan"
- style="@style/button_small_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/pi"
- android:text="@string/pi"
- style="@style/button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/factorial"
- android:text="@string/factorial"
- style="@style/button_style"
- />
- </LinearLayout>
-
- <LinearLayout
- android:layout_weight="1"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- >
- <com.android.calculator2.ColorButton
- android:id="@+id/ln"
- android:text="@string/ln"
- style="@style/button_small_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/lg"
- android:text="@string/lg"
- style="@style/button_small_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/e"
- android:text="@string/e"
- style="@style/button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/power"
- android:text="@string/power"
- style="@style/button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/sqrt"
- android:text="@string/sqrt"
- style="@style/button_style"
- />
- </LinearLayout>
- </LinearLayout>
- </com.android.calculator2.PanelSwitcher>
</LinearLayout>
diff --git a/res/layout-land/simple_pad.xml b/res/layout-land/simple_pad.xml
new file mode 100644
index 0000000..539bdfc
--- /dev/null
+++ b/res/layout-land/simple_pad.xml
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+/*
+* Copyright (C) 2011, 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.
+*/
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/simplePad"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:layout_gravity="center"
+ >
+ <LinearLayout
+ android:layout_weight="1"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ >
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit7"
+ android:text="@string/digit7"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit8"
+ android:text="@string/digit8"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit9"
+ android:text="@string/digit9"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/leftParen"
+ android:text="@string/leftParen"
+ style="@style/button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/rightParen"
+ android:text="@string/rightParen"
+ style="@style/button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/mul"
+ android:text="@string/mul"
+ style="@style/button_style"
+ />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_weight="1"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ >
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit4"
+ android:text="@string/digit4"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit5"
+ android:text="@string/digit5"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit6"
+ android:text="@string/digit6"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/dot"
+ android:text="@string/dot"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/div"
+ android:text="@string/div"
+ style="@style/button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/minus"
+ android:text="@string/minus"
+ style="@style/button_style"
+ />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_weight="1"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ >
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit1"
+ android:text="@string/digit1"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit2"
+ android:text="@string/digit2"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit3"
+ android:text="@string/digit3"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit0"
+ android:text="@string/digit0"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/equal"
+ android:text="@string/equal"
+ style="@style/button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/plus"
+ android:text="@string/plus"
+ style="@style/button_style"
+ />
+ </LinearLayout>
+</LinearLayout>
diff --git a/res/layout-port/advanced_pad.xml b/res/layout-port/advanced_pad.xml
new file mode 100644
index 0000000..8dd5d95
--- /dev/null
+++ b/res/layout-port/advanced_pad.xml
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+/*
+* Copyright (C) 2011, 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.
+*/
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/advancedPad"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:layout_gravity="center"
+ >
+
+ <LinearLayout
+ android:layout_weight="1"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ >
+ <com.android.calculator2.ColorButton
+ android:id="@+id/sin"
+ android:text="@string/sin"
+ style="@style/button_small_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/cos"
+ android:text="@string/cos"
+ style="@style/button_small_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/tan"
+ android:text="@string/tan"
+ style="@style/button_small_style"
+ />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_weight="1"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ >
+ <com.android.calculator2.ColorButton
+ android:id="@+id/ln"
+ android:text="@string/ln"
+ style="@style/button_small_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/lg"
+ android:text="@string/lg"
+ style="@style/button_small_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/factorial"
+ android:text="@string/factorial"
+ style="@style/button_style"
+ />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_weight="1"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ >
+ <com.android.calculator2.ColorButton
+ android:id="@+id/pi"
+ android:text="@string/pi"
+ style="@style/button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/e"
+ android:text="@string/e"
+ style="@style/button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/power"
+ android:text="@string/power"
+ style="@style/button_style"
+ />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_weight="1"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ >
+ <com.android.calculator2.ColorButton
+ android:id="@+id/leftParen"
+ android:text="@string/leftParen"
+ style="@style/button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/rightParen"
+ android:text="@string/rightParen"
+ style="@style/button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/sqrt"
+ android:text="@string/sqrt"
+ style="@style/button_style"
+ />
+ </LinearLayout>
+</LinearLayout>
diff --git a/res/layout-port/main.xml b/res/layout-port/main.xml
index 59795c1..929f18c 100644
--- a/res/layout-port/main.xml
+++ b/res/layout-port/main.xml
@@ -53,264 +53,10 @@
android:layout_marginLeft="8dip"
android:visibility="gone"/>
</LinearLayout>
- <com.android.calculator2.PanelSwitcher
+ <android.support.v4.view.ViewPager
android:id="@+id/panelswitch"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
- >
-
- <LinearLayout
- android:id="@+id/simplePad"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:layout_gravity="center"
- >
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="2"
- >
-
- <View
- android:background="@drawable/button"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="3"
- />
-
- <FrameLayout
- android:layout_width="0dp"
- android:layout_weight="1"
- android:layout_height="match_parent">
- <!-- marginRight has to be 0 to catch border-touch -->
- <com.android.calculator2.ColorButton
- android:id="@+id/clear"
- android:text="@string/clear"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginRight="0dp"
- android:textSize="15dp"
- style="@style/button_style"
- />
- <!-- marginRight has to be 0 to catch border-touch -->
- <com.android.calculator2.ColorButton
- android:id="@+id/del"
- android:text="@string/del"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginRight="0dp"
- android:textSize="15dp"
- style="@style/button_style"
- />
- </FrameLayout>
-
- </LinearLayout>
-
- <LinearLayout
- android:layout_weight="3"
- android:layout_width="match_parent"
- android:layout_height="0dp">
- <com.android.calculator2.ColorButton
- android:id="@+id/digit7"
- android:text="@string/digit7"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit8"
- android:text="@string/digit8"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit9"
- android:text="@string/digit9"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/div"
- android:text="@string/div"
- style="@style/button_style"
- />
- </LinearLayout>
-
- <LinearLayout
- android:layout_weight="3"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- >
- <com.android.calculator2.ColorButton
- android:id="@+id/digit4"
- android:text="@string/digit4"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit5"
- android:text="@string/digit5"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit6"
- android:text="@string/digit6"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/mul"
- android:text="@string/mul"
- style="@style/button_style"
- />
- </LinearLayout>
-
- <LinearLayout
- android:layout_weight="3"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- >
- <com.android.calculator2.ColorButton
- android:id="@+id/digit1"
- android:text="@string/digit1"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit2"
- android:text="@string/digit2"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit3"
- android:text="@string/digit3"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/minus"
- android:text="@string/minus"
- style="@style/button_style"
- />
- </LinearLayout>
-
- <LinearLayout
- android:layout_weight="3"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- >
- <com.android.calculator2.ColorButton
- android:id="@+id/dot"
- android:text="@string/dot"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/digit0"
- android:text="@string/digit0"
- style="@style/digit_button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/equal"
- android:text="@string/equal"
- style="@style/button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/plus"
- android:text="@string/plus"
- style="@style/button_style"
- />
- </LinearLayout>
- </LinearLayout>
-
- <LinearLayout android:id="@+id/advancedPad"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:layout_gravity="center"
- >
-
- <LinearLayout
- android:layout_weight="1"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- >
- <com.android.calculator2.ColorButton
- android:id="@+id/sin"
- android:text="@string/sin"
- style="@style/button_small_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/cos"
- android:text="@string/cos"
- style="@style/button_small_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/tan"
- android:text="@string/tan"
- style="@style/button_small_style"
- />
- </LinearLayout>
-
- <LinearLayout
- android:layout_weight="1"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- >
- <com.android.calculator2.ColorButton
- android:id="@+id/ln"
- android:text="@string/ln"
- style="@style/button_small_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/lg"
- android:text="@string/lg"
- style="@style/button_small_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/factorial"
- android:text="@string/factorial"
- style="@style/button_style"
- />
- </LinearLayout>
-
- <LinearLayout
- android:layout_weight="1"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- >
- <com.android.calculator2.ColorButton
- android:id="@+id/pi"
- android:text="@string/pi"
- style="@style/button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/e"
- android:text="@string/e"
- style="@style/button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/power"
- android:text="@string/power"
- style="@style/button_style"
- />
- </LinearLayout>
-
- <LinearLayout
- android:layout_weight="1"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- >
- <com.android.calculator2.ColorButton
- android:id="@+id/leftParen"
- android:text="@string/leftParen"
- style="@style/button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/rightParen"
- android:text="@string/rightParen"
- style="@style/button_style"
- />
- <com.android.calculator2.ColorButton
- android:id="@+id/sqrt"
- android:text="@string/sqrt"
- style="@style/button_style"
- />
- </LinearLayout>
- </LinearLayout>
- </com.android.calculator2.PanelSwitcher>
+ />
</LinearLayout>
diff --git a/res/layout-port/simple_pad.xml b/res/layout-port/simple_pad.xml
new file mode 100644
index 0000000..e426fbf
--- /dev/null
+++ b/res/layout-port/simple_pad.xml
@@ -0,0 +1,176 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+/*
+* Copyright (C) 2011, 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.
+*/
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/simplePad"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:layout_gravity="center"
+ >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="2"
+ >
+
+ <View
+ android:background="@drawable/button"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_weight="3"
+ />
+
+ <FrameLayout
+ android:layout_width="0dp"
+ android:layout_weight="1"
+ android:layout_height="match_parent">
+ <!-- marginRight has to be 0 to catch border-touch -->
+ <com.android.calculator2.ColorButton
+ android:id="@+id/clear"
+ android:text="@string/clear"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginRight="0dp"
+ android:textSize="15dp"
+ style="@style/button_style"
+ />
+ <!-- marginRight has to be 0 to catch border-touch -->
+ <com.android.calculator2.ColorButton
+ android:id="@+id/del"
+ android:text="@string/del"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginRight="0dp"
+ android:textSize="15dp"
+ style="@style/button_style"
+ />
+ </FrameLayout>
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_weight="3"
+ android:layout_width="match_parent"
+ android:layout_height="0dp">
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit7"
+ android:text="@string/digit7"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit8"
+ android:text="@string/digit8"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit9"
+ android:text="@string/digit9"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/div"
+ android:text="@string/div"
+ style="@style/button_style"
+ />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_weight="3"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ >
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit4"
+ android:text="@string/digit4"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit5"
+ android:text="@string/digit5"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit6"
+ android:text="@string/digit6"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/mul"
+ android:text="@string/mul"
+ style="@style/button_style"
+ />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_weight="3"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ >
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit1"
+ android:text="@string/digit1"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit2"
+ android:text="@string/digit2"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit3"
+ android:text="@string/digit3"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/minus"
+ android:text="@string/minus"
+ style="@style/button_style"
+ />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_weight="3"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ >
+ <com.android.calculator2.ColorButton
+ android:id="@+id/dot"
+ android:text="@string/dot"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/digit0"
+ android:text="@string/digit0"
+ style="@style/digit_button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/equal"
+ android:text="@string/equal"
+ style="@style/button_style"
+ />
+ <com.android.calculator2.ColorButton
+ android:id="@+id/plus"
+ android:text="@string/plus"
+ style="@style/button_style"
+ />
+ </LinearLayout>
+</LinearLayout>
diff --git a/res/values-land/arrays.xml b/res/values-land/arrays.xml
new file mode 100644
index 0000000..8c518d1
--- /dev/null
+++ b/res/values-land/arrays.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright 2011, 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.
+ */
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <array name="simple_buttons">
+ <item>@+id/digit0</item>
+ <item>@+id/digit1</item>
+ <item>@+id/digit2</item>
+ <item>@+id/digit3</item>
+ <item>@+id/digit4</item>
+ <item>@+id/digit5</item>
+ <item>@+id/digit6</item>
+ <item>@+id/digit7</item>
+ <item>@+id/digit8</item>
+ <item>@+id/digit9</item>
+ <item>@+id/dot</item>
+ <item>@+id/plus</item>
+ <item>@+id/minus</item>
+ <item>@+id/div</item>
+ <item>@+id/mul</item>
+ <item>@+id/equal</item>
+ <item>@+id/leftParen</item>
+ <item>@+id/rightParen</item>
+ </array>
+
+ <array name="advanced_buttons">
+ <item>@+id/sin</item>
+ <item>@+id/cos</item>
+ <item>@+id/tan</item>
+ <item>@+id/ln</item>
+ <item>@+id/lg</item>
+ <item>@+id/e</item>
+ <item>@+id/pi</item>
+ <item>@+id/power</item>
+ <item>@+id/factorial</item>
+ <item>@+id/sqrt</item>
+ </array>
+
+</resources>
\ No newline at end of file
diff --git a/res/values-port/arrays.xml b/res/values-port/arrays.xml
new file mode 100644
index 0000000..8bc888c
--- /dev/null
+++ b/res/values-port/arrays.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright 2011, 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.
+ */
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <array name="simple_buttons">
+ <item>@+id/digit0</item>
+ <item>@+id/digit1</item>
+ <item>@+id/digit2</item>
+ <item>@+id/digit3</item>
+ <item>@+id/digit4</item>
+ <item>@+id/digit5</item>
+ <item>@+id/digit6</item>
+ <item>@+id/digit7</item>
+ <item>@+id/digit8</item>
+ <item>@+id/digit9</item>
+ <item>@+id/dot</item>
+ <item>@+id/plus</item>
+ <item>@+id/minus</item>
+ <item>@+id/div</item>
+ <item>@+id/mul</item>
+ <item>@+id/equal</item>
+ </array>
+
+ <array name="advanced_buttons">
+ <item>@+id/leftParen</item>
+ <item>@+id/rightParen</item>
+ <item>@+id/sin</item>
+ <item>@+id/cos</item>
+ <item>@+id/tan</item>
+ <item>@+id/ln</item>
+ <item>@+id/lg</item>
+ <item>@+id/e</item>
+ <item>@+id/pi</item>
+ <item>@+id/power</item>
+ <item>@+id/factorial</item>
+ <item>@+id/sqrt</item>
+ </array>
+
+</resources>
\ No newline at end of file
diff --git a/res/values-sw600dp/arrays.xml b/res/values-sw600dp/arrays.xml
new file mode 100644
index 0000000..219b3e5
--- /dev/null
+++ b/res/values-sw600dp/arrays.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright 2011, 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.
+ */
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <array name="buttons">
+ <item>@+id/digit0</item>
+ <item>@+id/digit1</item>
+ <item>@+id/digit2</item>
+ <item>@+id/digit3</item>
+ <item>@+id/digit4</item>
+ <item>@+id/digit5</item>
+ <item>@+id/digit6</item>
+ <item>@+id/digit7</item>
+ <item>@+id/digit8</item>
+ <item>@+id/digit9</item>
+ <item>@+id/dot</item>
+ <item>@+id/plus</item>
+ <item>@+id/minus</item>
+ <item>@+id/div</item>
+ <item>@+id/mul</item>
+ <item>@+id/equal</item>
+ <item>@+id/leftParen</item>
+ <item>@+id/rightParen</item>
+ <item>@+id/sin</item>
+ <item>@+id/cos</item>
+ <item>@+id/tan</item>
+ <item>@+id/ln</item>
+ <item>@+id/lg</item>
+ <item>@+id/e</item>
+ <item>@+id/pi</item>
+ <item>@+id/power</item>
+ <item>@+id/factorial</item>
+ <item>@+id/sqrt</item>
+ </array>
+
+</resources>
\ No newline at end of file
diff --git a/src/com/android/calculator2/Calculator.java b/src/com/android/calculator2/Calculator.java
index b305661..97486a8 100644
--- a/src/com/android/calculator2/Calculator.java
+++ b/src/com/android/calculator2/Calculator.java
@@ -17,21 +17,25 @@
package com.android.calculator2;
import android.app.Activity;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
import android.os.Bundle;
+import android.os.Parcelable;
+import android.support.v4.view.PagerAdapter;
+import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.KeyEvent;
+import android.view.LayoutInflater;
import android.view.Menu;
-import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.view.ViewConfiguration;
-import android.view.WindowManager;
import android.view.View.OnClickListener;
+import android.view.ViewConfiguration;
+import android.view.ViewGroup;
+import android.view.WindowManager;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
-import java.util.ArrayList;
-
public class Calculator extends Activity implements PanelSwitcher.Listener, Logic.Listener,
OnClickListener, OnMenuItemClickListener {
EventListener mListener = new EventListener();
@@ -39,7 +43,7 @@
private Persist mPersist;
private History mHistory;
private Logic mLogic;
- private PanelSwitcher mPanelSwitcher;
+ private ViewPager mPager;
private View mClearButton;
private View mBackspaceButton;
private View mOverflowMenuButton;
@@ -61,6 +65,28 @@
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
setContentView(R.layout.main);
+ mPager = (ViewPager) findViewById(R.id.panelswitch);
+ if (mPager != null) {
+ mPager.setAdapter(new PageAdapter(mPager));
+ } else {
+ // Single page UI
+ final TypedArray buttons = getResources().obtainTypedArray(R.array.buttons);
+ for (int i = 0; i < buttons.length(); i++) {
+ setOnClickListener(null, buttons.getResourceId(i, 0));
+ }
+ buttons.recycle();
+ }
+
+ if (mClearButton == null) {
+ mClearButton = findViewById(R.id.clear);
+ mClearButton.setOnClickListener(mListener);
+ mClearButton.setOnLongClickListener(mListener);
+ }
+ if (mBackspaceButton == null) {
+ mBackspaceButton = findViewById(R.id.del);
+ mBackspaceButton.setOnClickListener(mListener);
+ mBackspaceButton.setOnLongClickListener(mListener);
+ }
mPersist = new Persist(this);
mPersist.load();
@@ -69,14 +95,6 @@
mDisplay = (CalculatorDisplay) findViewById(R.id.display);
- mClearButton = findViewById(R.id.clear);
- mClearButton.setOnClickListener(mListener);
- mClearButton.setOnLongClickListener(mListener);
-
- mBackspaceButton = findViewById(R.id.del);
- mBackspaceButton.setOnClickListener(mListener);
- mBackspaceButton.setOnLongClickListener(mListener);
-
mLogic = new Logic(this, mHistory, mDisplay);
mLogic.setListener(this);
@@ -86,48 +104,16 @@
HistoryAdapter historyAdapter = new HistoryAdapter(this, mHistory, mLogic);
mHistory.setObserver(historyAdapter);
- mPanelSwitcher = (PanelSwitcher) findViewById(R.id.panelswitch);
- if (mPanelSwitcher != null) {
- mPanelSwitcher.setCurrentIndex(state==null ? 0 : state.getInt(STATE_CURRENT_VIEW, 0));
- mPanelSwitcher.setListener(this);
+ if (mPager != null) {
+ mPager.setCurrentItem(state == null ? 0 : state.getInt(STATE_CURRENT_VIEW, 0));
}
- mListener.setHandler(mLogic, mPanelSwitcher);
+ mListener.setHandler(mLogic, mPager);
mDisplay.setOnKeyListener(mListener);
if (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
createFakeMenu();
}
- setOnClickListener(R.id.digit0);
- setOnClickListener(R.id.digit1);
- setOnClickListener(R.id.digit2);
- setOnClickListener(R.id.digit3);
- setOnClickListener(R.id.digit4);
- setOnClickListener(R.id.digit5);
- setOnClickListener(R.id.digit6);
- setOnClickListener(R.id.digit7);
- setOnClickListener(R.id.digit8);
- setOnClickListener(R.id.digit9);
- setOnClickListener(R.id.dot);
-
- setOnClickListener(R.id.plus);
- setOnClickListener(R.id.minus);
- setOnClickListener(R.id.div);
- setOnClickListener(R.id.mul);
- setOnClickListener(R.id.leftParen);
- setOnClickListener(R.id.rightParen);
- setOnClickListener(R.id.equal);
-
- setOnClickListener(R.id.sin);
- setOnClickListener(R.id.ln);
- setOnClickListener(R.id.cos);
- setOnClickListener(R.id.lg);
- setOnClickListener(R.id.tan);
- setOnClickListener(R.id.e);
- setOnClickListener(R.id.pi);
- setOnClickListener(R.id.power);
- setOnClickListener(R.id.factorial);
- setOnClickListener(R.id.sqrt);
mLogic.resumeWithHistory();
updateDeleteMode();
@@ -143,8 +129,9 @@
}
}
- private void setOnClickListener(int id) {
- findViewById(id).setOnClickListener(mListener);
+ void setOnClickListener(View root, int id) {
+ final View target = root != null ? root.findViewById(id) : findViewById(id);
+ target.setOnClickListener(mListener);
}
@Override
@@ -199,11 +186,11 @@
}
private boolean getBasicVisibility() {
- return mPanelSwitcher != null && mPanelSwitcher.getCurrentIndex() == ADVANCED_PANEL;
+ return mPager != null && mPager.getCurrentItem() == ADVANCED_PANEL;
}
private boolean getAdvancedVisibility() {
- return mPanelSwitcher != null && mPanelSwitcher.getCurrentIndex() == BASIC_PANEL;
+ return mPager != null && mPager.getCurrentItem() == BASIC_PANEL;
}
@Override
@@ -215,14 +202,14 @@
break;
case R.id.basic:
- if (mPanelSwitcher != null && mPanelSwitcher.getCurrentIndex() == ADVANCED_PANEL) {
- mPanelSwitcher.moveRight();
+ if (getAdvancedVisibility()) {
+ mPager.setCurrentItem(BASIC_PANEL);
}
break;
case R.id.advanced:
- if (mPanelSwitcher != null && mPanelSwitcher.getCurrentIndex() == BASIC_PANEL) {
- mPanelSwitcher.moveLeft();
+ if (getBasicVisibility()) {
+ mPager.setCurrentItem(ADVANCED_PANEL);
}
break;
}
@@ -232,8 +219,8 @@
@Override
protected void onSaveInstanceState(Bundle state) {
super.onSaveInstanceState(state);
- if (mPanelSwitcher != null) {
- state.putInt(STATE_CURRENT_VIEW, mPanelSwitcher.getCurrentIndex());
+ if (mPager != null) {
+ state.putInt(STATE_CURRENT_VIEW, mPager.getCurrentItem());
}
}
@@ -247,9 +234,8 @@
@Override
public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
- if (keyCode == KeyEvent.KEYCODE_BACK
- && mPanelSwitcher != null && mPanelSwitcher.getCurrentIndex() == ADVANCED_PANEL) {
- mPanelSwitcher.moveRight();
+ if (keyCode == KeyEvent.KEYCODE_BACK && getAdvancedVisibility()) {
+ mPager.setCurrentItem(BASIC_PANEL);
return true;
} else {
return super.onKeyDown(keyCode, keyEvent);
@@ -271,4 +257,79 @@
public void onDeleteModeChange() {
updateDeleteMode();
}
+
+ class PageAdapter extends PagerAdapter {
+ private View mSimplePage;
+ private View mAdvancedPage;
+
+ public PageAdapter(ViewPager parent) {
+ final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
+ final View simplePage = inflater.inflate(R.layout.simple_pad, parent, false);
+ final View advancedPage = inflater.inflate(R.layout.advanced_pad, parent, false);
+ mSimplePage = simplePage;
+ mAdvancedPage = advancedPage;
+
+ final Resources res = getResources();
+ final TypedArray simpleButtons = res.obtainTypedArray(R.array.simple_buttons);
+ for (int i = 0; i < simpleButtons.length(); i++) {
+ setOnClickListener(simplePage, simpleButtons.getResourceId(i, 0));
+ }
+ simpleButtons.recycle();
+
+ final TypedArray advancedButtons = res.obtainTypedArray(R.array.advanced_buttons);
+ for (int i = 0; i < advancedButtons.length(); i++) {
+ setOnClickListener(advancedPage, advancedButtons.getResourceId(i, 0));
+ }
+ advancedButtons.recycle();
+
+ final View clearButton = simplePage.findViewById(R.id.clear);
+ if (clearButton != null) {
+ mClearButton = clearButton;
+ }
+
+ final View backspaceButton = simplePage.findViewById(R.id.del);
+ if (backspaceButton != null) {
+ mBackspaceButton = backspaceButton;
+ }
+ }
+
+ @Override
+ public int getCount() {
+ return 2;
+ }
+
+ @Override
+ public void startUpdate(View container) {
+ }
+
+ @Override
+ public Object instantiateItem(View container, int position) {
+ final View page = position == 0 ? mSimplePage : mAdvancedPage;
+ ((ViewGroup) container).addView(page);
+ return page;
+ }
+
+ @Override
+ public void destroyItem(View container, int position, Object object) {
+ ((ViewGroup) container).removeView((View) object);
+ }
+
+ @Override
+ public void finishUpdate(View container) {
+ }
+
+ @Override
+ public boolean isViewFromObject(View view, Object object) {
+ return view == object;
+ }
+
+ @Override
+ public Parcelable saveState() {
+ return null;
+ }
+
+ @Override
+ public void restoreState(Parcelable state, ClassLoader loader) {
+ }
+ }
}
diff --git a/src/com/android/calculator2/EventListener.java b/src/com/android/calculator2/EventListener.java
index 78f3bab..0187d66 100644
--- a/src/com/android/calculator2/EventListener.java
+++ b/src/com/android/calculator2/EventListener.java
@@ -16,19 +16,20 @@
package com.android.calculator2;
-import android.view.View;
+import android.support.v4.view.ViewPager;
import android.view.KeyEvent;
+import android.view.View;
import android.widget.Button;
class EventListener implements View.OnKeyListener,
View.OnClickListener,
View.OnLongClickListener {
Logic mHandler;
- PanelSwitcher mPanelSwitcher;
+ ViewPager mPager;
- void setHandler(Logic handler, PanelSwitcher panelSwitcher) {
+ void setHandler(Logic handler, ViewPager pager) {
mHandler = handler;
- mPanelSwitcher = panelSwitcher;
+ mPager = pager;
}
@Override
@@ -55,9 +56,8 @@
text += '(';
}
mHandler.insert(text);
- if (mPanelSwitcher != null &&
- mPanelSwitcher.getCurrentIndex() == Calculator.ADVANCED_PANEL) {
- mPanelSwitcher.moveRight();
+ if (mPager != null && mPager.getCurrentItem() == Calculator.ADVANCED_PANEL) {
+ mPager.setCurrentItem(Calculator.BASIC_PANEL);
}
}
}