aboutsummaryrefslogtreecommitdiff
path: root/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app
diff options
context:
space:
mode:
authorDouglas Sigelbaum <sigelbaum@google.com>2017-06-15 11:56:24 -0700
committerDouglas Sigelbaum <sigelbaum@google.com>2017-07-08 11:03:50 -0700
commit34f6bf753c7979a3e60ff4ec70d8831eef06b645 (patch)
tree05e3019750e97e8cdc5cf363907fb8e0d6e4d1fd /input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app
parent8e4f496dd1b41d0fe2b30496dd473e168daf95fe (diff)
downloadandroid-34f6bf753c7979a3e60ff4ec70d8831eef06b645.tar.gz
Autofill sample: make UI nicer.
Also add info dialogs in the app explaining what each client page is showcasing. Bug: 38182790 Test: manual Change-Id: I779f8152ce8f13a1bac28b6964bc7edbd85760af
Diffstat (limited to 'input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app')
-rw-r--r--input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/InfoButton.kt41
-rw-r--r--input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/MainActivity.kt9
-rw-r--r--input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/NavigationItem.kt58
-rw-r--r--input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/WelcomeActivity.kt20
4 files changed, 124 insertions, 4 deletions
diff --git a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/InfoButton.kt b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/InfoButton.kt
new file mode 100644
index 00000000..3a2c0e3d
--- /dev/null
+++ b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/InfoButton.kt
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 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.example.android.autofillframework.app
+
+import android.content.Context
+import android.support.v7.app.AlertDialog
+import android.support.v7.widget.AppCompatImageButton
+import android.util.AttributeSet
+import com.example.android.autofillframework.R
+
+class InfoButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0) : AppCompatImageButton(context, attrs, defStyleAttr) {
+
+ init {
+ val typedArray = context.obtainStyledAttributes(attrs, R.styleable.InfoButton,
+ defStyleAttr, 0)
+ val infoText = typedArray.getString(R.styleable.InfoButton_dialogText)
+ typedArray.recycle()
+ setInfoText(infoText)
+ }
+
+ fun setInfoText(infoText: String) {
+ setOnClickListener {
+ AlertDialog.Builder(this@InfoButton.context)
+ .setMessage(infoText).create().show()
+ }
+ }
+} \ No newline at end of file
diff --git a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/MainActivity.kt b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/MainActivity.kt
index c7c458d4..3ab4f389 100644
--- a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/MainActivity.kt
+++ b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/MainActivity.kt
@@ -17,6 +17,7 @@ package com.example.android.autofillframework.app
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
+import android.view.View
import com.example.android.autofillframework.R
import kotlinx.android.synthetic.main.activity_main.creditCardCheckoutButton
import kotlinx.android.synthetic.main.activity_main.standardLoginWithAutoCompleteButton
@@ -31,10 +32,10 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
- standardViewSignInButton.setOnClickListener { standardViewSignIn() }
- virtualViewSignInButton.setOnClickListener { virtualViewSignIn() }
- creditCardCheckoutButton.setOnClickListener { creditCardCheckout() }
- standardLoginWithAutoCompleteButton.setOnClickListener { standardAutoCompleteSignIn() }
+ standardViewSignInButton.setNavigationButtonClickListener(View.OnClickListener { standardViewSignIn() })
+ virtualViewSignInButton.setNavigationButtonClickListener(View.OnClickListener { virtualViewSignIn() })
+ creditCardCheckoutButton.setNavigationButtonClickListener(View.OnClickListener { creditCardCheckout() })
+ standardLoginWithAutoCompleteButton.setNavigationButtonClickListener(View.OnClickListener { standardAutoCompleteSignIn() })
}
private fun creditCardCheckout() {
diff --git a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/NavigationItem.kt b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/NavigationItem.kt
new file mode 100644
index 00000000..0701e146
--- /dev/null
+++ b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/NavigationItem.kt
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2017 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.example.android.autofillframework.app
+
+import android.content.Context
+import android.graphics.PorterDuff
+import android.support.annotation.ColorRes
+import android.support.v4.content.ContextCompat
+import android.support.v7.app.AlertDialog
+import android.util.AttributeSet
+import android.view.LayoutInflater
+import android.view.View
+import android.widget.FrameLayout
+import com.example.android.autofillframework.R
+import kotlinx.android.synthetic.main.navigation_item.view.buttonLabel
+import kotlinx.android.synthetic.main.navigation_item.view.cardView
+import kotlinx.android.synthetic.main.navigation_item.view.infoButton
+
+class NavigationItem @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr) {
+
+ init {
+ val typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationItem,
+ defStyleAttr, 0)
+ val labelText = typedArray.getString(R.styleable.NavigationItem_labelText)
+ val infoText = typedArray.getString(R.styleable.NavigationItem_infoText)
+ val logoDrawable = typedArray.getDrawable(R.styleable.NavigationItem_itemLogo)
+ @ColorRes val colorRes = typedArray.getResourceId(R.styleable.NavigationItem_imageColor, 0)
+ val imageColor = ContextCompat.getColor(getContext(), colorRes)
+ typedArray.recycle()
+ LayoutInflater.from(context).inflate(R.layout.navigation_item, this)
+ logoDrawable?.setColorFilter(imageColor, PorterDuff.Mode.SRC_IN)
+ buttonLabel.text = labelText
+ buttonLabel.setCompoundDrawablesRelativeWithIntrinsicBounds(logoDrawable, null, null, null)
+ infoButton.setOnClickListener {
+ AlertDialog.Builder(this@NavigationItem.context)
+ .setMessage(infoText).create().show()
+ }
+ infoButton.setColorFilter(imageColor)
+ }
+
+ fun setNavigationButtonClickListener(l: View.OnClickListener?) {
+ cardView.setOnClickListener(l)
+ }
+}
diff --git a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/WelcomeActivity.kt b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/WelcomeActivity.kt
index bdcfef2e..db8bf679 100644
--- a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/WelcomeActivity.kt
+++ b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/app/WelcomeActivity.kt
@@ -18,14 +18,34 @@ package com.example.android.autofillframework.app
import android.content.Context
import android.content.Intent
import android.os.Bundle
+import android.os.CountDownTimer
import android.support.v7.app.AppCompatActivity
import com.example.android.autofillframework.R
+import kotlinx.android.synthetic.main.welcome_activity.countdownText
+import java.lang.Math.toIntExact
+
class WelcomeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.welcome_activity)
+ object : CountDownTimer(5000, 1000) {
+
+ override fun onTick(millisUntilFinished: Long) {
+ val secondsRemaining = toIntExact(millisUntilFinished / 1000)
+ countdownText.text = getResources()
+ .getQuantityString(R.plurals.welcome_page_countdown, secondsRemaining,
+ secondsRemaining)
+ }
+
+ override fun onFinish() {
+ if (!this@WelcomeActivity.isFinishing) {
+ finish()
+ }
+ }
+
+ }.start()
}
companion object {