Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Autofill Framework

uzzu
December 17, 2020

Autofill Framework

第2回Android知見共有会 @cookpad

uzzu

December 17, 2020
Tweet

More Decks by uzzu

Other Decks in Technology

Transcript

  1. ࢖͍ํ(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 }
  2. ࢖͍ํ(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" />
  3. 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)) }
  4. ط஌ͷ໰୊(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() } }
  5. ط஌ͷ໰୊(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) ͢Δ
  6. ·ͱΊ • ϑΟʔϧυʹೖྗ͢Δ࣌ؒΛ࡟ݮͨ͠ΓɺೖྗϛεΛ࠷খݶʹ཈͑Δࣄ͕Ͱ͖Δ • Autofill ServiceʹରԠͨ͠ύεϫʔυϚωʔδϟʔͱ࿈ܞͯ͠ೖྗ৘ใΛอଘͰ͖Δ • ΢ΣϒαΠτͱͷؔ࿈෇͚Ͱ AndroidΞϓϦͰͷϩάΠϯ࣌ʹ WebͰͷϩάΠϯ৘ใΛࣗಈೖྗͰ͖Δ

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