Save 37% off PRO during our Black Friday Sale! »

Autofill Framework

2d855b951ff3160c55915821261432f9?s=47 uzzu
December 17, 2020

Autofill Framework

第2回Android知見共有会 @cookpad

2d855b951ff3160c55915821261432f9?s=128

uzzu

December 17, 2020
Tweet

Transcript

  1. Autofill framework uzzu @ user-payment dept

  2. Agenda ɾAutofill frameworkͬͯԿ ɾಋೖํ๏ ɾͲΜͳײ͡Ͱಈ͔͢ͷ ɾ·ͱΊ

  3. Autofill framework ɾΞϓϦ಺ͰҎԼͷೖྗ৘ใΛࣗಈೖྗ͢Δࣄ͕Ͱ͖Δ࢓૊Έ ɹΞΧ΢ϯτೝূ৘ใɺΫϨδοτΧʔυ৘ใɺॅॴɺਓ໊ɺి࿩൪߸ɺ ɹϫϯλΠϜύεϫʔυ ɾAutofill ServiceʹରԠͨ͠ύεϫʔυϚωʔδϟʔͱ࿈ܞͯ͠ೖྗ৘ใΛอଘ͢Δࣄ΋ ɹͰ͖Δ (ࠓճ͸লུ) ɹ৽͍͠ύεϫʔυΛύεϫʔυϚωʔδϟͰੜ੒্ͨ͠Ͱࣗಈೖྗ͢ΔͳͲ

    ɾWeb޲͚ʹDigital Asset LinksΛ༻ҙ͢Δ͜ͱͰWebͷಉαʔϏεͷೝূ৘ใΛ ɹΞϓϦͰར༻Ͱ͖Δ ɾminSdkVersion >= 26 (※)
  4. None
  5. ࢖͍ํ(1) - ୺຤ઃఆ • ઃఆ>γεςϜ>ݴޠͱೖྗ>ৄࡉઃఆ>ೖྗΞγελϯ τ>ࣗಈೖྗαʔϏε ͔ΒࣗಈೖྗαʔϏεΛ༗ޮʹ͢ Δ ↑ΤϛϡϨʔλͰಈ࡞֬ೝ͢Δ৔߹͸ཁ֬ೝ •

    ୺຤্ͰGoogleΞΧ΢ϯτͰϩάΠϯ͓ͯ͘͠ͷ΋๨Ε ͳ͍
  6. ࢖͍ํ(2) - Autofill༗ޮແޮͷ֬ೝ fun Context.isAutofillAvailable(): Boolean { if (Build.VERSION.SDK_INT <

    Build.VERSION_CODES.O) { return false } val manager = getSystemService(AutofillManager::class.java) return manager != null && manager.isEnabled }
  7. ࢖͍ํ(3) - ࣗಈೖྗͷͨΊͷHintͷઃఆ • ࢦఆจࣈྻ͸ View.AUTOFILL_HINT_* ͳఆ͕ٛ͋ΔͷͰͦͪΒΛࢀߟʹ • ෳ਺༩͑Δࣄ΋Ͱ͖Δ •

    ࣗલͷViewʹHintsΛઃఆ͢Δ৔߹͸ View#setAutofillHints(vararg String) • ٯʹɺೖྗิ׬ͨ͘͠ͳ͍৔߹͸ android:importantForAutofill=“no” “auto”, “no”, “yes”, “noExcludedDescendants”, “yesExcludeDescendants” <EditText android:id="@+id/password_field" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" android:autofillHints="password" />
  8. ࢖͍ํ(4) - ࣗಈೖྗͨ͠಺༰ͷऔಘ • EditText#getText() ͳͲɺݩͷViewͷ࣮૷ʹ߹ΘͤͯऔಘɺͰجຊతʹOK • View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE ͷ৔߹͸ɺೖྗ಺༰ͷᐆດ ͞ʹ஫ҙ

    (06/2022, 6/2022, June 2022, …) ->EditTextͳΓΛܧঝͯ͠AutofillValueΛ༻͍ΔࣄͰᐆດ͞Λճආ͢Δ
  9. override fun getAutofillType(): Int { return AUTOFILL_TYPE_DATE } override fun

    getAutofillValue(): AutofillValue { val calendar = Calendar.getInstance() calendar.clear() val (year, month) = sanitize(text?.toString()) calendar.set(Calendar.YEAR, year) calendar.set(Calendar.MONTH, month) val unixTime: Long = calendar.timeInMillis return AutofillValue.forDate(unixTime) } override fun autofill(value: AutofillValue) { if (!value.isDate) { return } val calendar = Calendar.getInstance() calendar.timeInMillis = value.dateValue setText(DateFormat.format("MM/yy", calendar)) }
  10. ࢖͍ํ(5) - ͋ͱ͸Advanced ɾࣗಈೖྗΛ࣮ࢪ͠ͳ͍৔߹͸AutofillManager#cancel ɾActivity1ͭʹର͠ෳ਺ͷFragmentͰը໘ભҠ͠ͳ͕Βೖ ྗ͢Δ৔߹͸ɺ࠷ޙʹ AutoFillManager#commit ͢Δ

  11. ط஌ͷ໰୊(1) - DialogͰͷར༻ • API Level 27ҎલͰ͸Dialog಺ͷϏϡʔΛදࣔޙʹαΠ ζมߋΛ͢Δͱࣗಈೖྗͷର৅ͱΈͳ͞Εͳ͘ͳΔ

  12. ط஌ͷ໰୊(1) - ճආࡦ • window token ΛৼΓ௚͢ class Dialog(context: Context)

    : Dialog(context) { private var token: IBinder? = null override fun onWindowAttributesChanged(params: WindowManager.LayoutParams) { if (params.token == null && token != null) { params.token = token } super.onWindowAttributesChanged(params) } override fun onAttachedToWindow() { if (context.isDialogResizedWorkAroundRequired() /* API 26ͩͬͨΒ */) { token = requireNotNull(ownerActivity).window.attributes.token } super.onAttachedToWindow() } }
  13. ط஌ͷ໰୊(2) - RecyclerViewͰͷར༻ • RecyclerViewͰͷར༻࣌ʹҙਤͤ͵ೖྗϑΟʔϧυʹ ࣗಈೖྗ͞Εͯ͠·͏ (View͕࠶ར༻͞ΕΔࣄ͕͋Δͷ͔ͩΒͳΜͱͳ͘ ؾ࣋ͪ͸෼͔Δ…)

  14. ط஌ͷ໰୊(2) - ղܾࡦ (minSdkVersion >= 28) • AutofillManager͕IdΛ࠾൪͍ͯ͠ΔͷͰɺ֤ΞΠςϜʹIdΛ࠾൪͢Δ data class

    Item( val text: String, // Viewදࣔͷҝͷͳʹ͔ // : val autofillId: Int // Autofill framework༻ͷId Λ௥Ճ ) // RecyclerViewʹ௥Ճ͢Δཁૉʹ1ͭͣͭ࠾൪ val autofillId = autofillManager.nextAutofillId • ͦͷޙonBindViewHolderͰViewHolder্Ͱ͍࣋ͬͯΔTextViewʹ View#setAutofillId(autofillId) ͢Δ
  15. ·ͱΊ • ϑΟʔϧυʹೖྗ͢Δ࣌ؒΛ࡟ݮͨ͠ΓɺೖྗϛεΛ࠷খݶʹ཈͑Δࣄ͕Ͱ͖Δ • Autofill ServiceʹରԠͨ͠ύεϫʔυϚωʔδϟʔͱ࿈ܞͯ͠ೖྗ৘ใΛอଘͰ͖Δ • ΢ΣϒαΠτͱͷؔ࿈෇͚Ͱ AndroidΞϓϦͰͷϩάΠϯ࣌ʹ WebͰͷϩάΠϯ৘ใΛࣗಈೖྗͰ͖Δ

    • minSdkVersion >=26 Ͱ͸͋Δ͕ɺط஌ͷ໰୊ʹखؒগͳ͘ରॲ͢ΔͳΒ minSdkVersion >= 28 • androidx.autofill Ͱ͸΋͏গ͠௥Ճػೳ͕࢖͑Δ (ιϑτ΢ΣΞΩʔϘʔυɺOTPपΓͷαϙʔτ͕खް͍)͕ ݱࡏ1.1.0-rc01 minSdkVersion >= 30