diff options
author | Douglas Sigelbaum <sigelbaum@google.com> | 2017-06-15 11:56:24 -0700 |
---|---|---|
committer | Douglas Sigelbaum <sigelbaum@google.com> | 2017-07-08 11:03:50 -0700 |
commit | 34f6bf753c7979a3e60ff4ec70d8831eef06b645 (patch) | |
tree | 05e3019750e97e8cdc5cf363907fb8e0d6e4d1fd /input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android | |
parent | 8e4f496dd1b41d0fe2b30496dd473e168daf95fe (diff) | |
download | android-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')
6 files changed, 125 insertions, 6 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 { diff --git a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/StructureParser.kt b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/StructureParser.kt index d1bbc9c1..f185b8ea 100644 --- a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/StructureParser.kt +++ b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/StructureParser.kt @@ -19,8 +19,8 @@ import android.app.assist.AssistStructure import android.app.assist.AssistStructure.ViewNode import android.util.Log import com.example.android.autofillframework.CommonUtil.TAG -import com.example.android.autofillframework.multidatasetservice.model.FilledAutofillFieldCollection import com.example.android.autofillframework.multidatasetservice.model.FilledAutofillField +import com.example.android.autofillframework.multidatasetservice.model.FilledAutofillFieldCollection /** * Parser for an AssistStructure object. This is invoked when the Autofill Service receives an diff --git a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/FilledAutofillFieldCollection.kt b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/FilledAutofillFieldCollection.kt index 032e1251..2de46809 100644 --- a/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/FilledAutofillFieldCollection.kt +++ b/input/autofill/AutofillFramework/kotlinApp/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/FilledAutofillFieldCollection.kt @@ -22,7 +22,6 @@ import android.view.autofill.AutofillId import android.view.autofill.AutofillValue import com.example.android.autofillframework.CommonUtil.TAG import com.example.android.autofillframework.multidatasetservice.AutofillFieldMetadataCollection -import com.example.android.autofillframework.multidatasetservice.AutofillHelper import com.google.gson.annotations.Expose import java.util.HashMap |