*
It has multiple partitions, but only accepts autofill on each partition at time. */ /* * TODO list * * - Fix top margin. * - Use a combo box to select if credit card expiration date is expressed as date or text. * - Use a dedicated TextView (instead of Toast) for error messages. * - Use wrap_context to CustomView container. * - Use different background color (or borders) for each partition. * - Add more partitions (like address) - should match same partitions from service. * - Add more hints (like w3c ones) - should match same hints from service. */ public class MultiplePartitionsActivity extends AppCompatActivity { private ScrollableCustomVirtualView mCustomVirtualView; private AutofillManager mAutofillManager; private CustomVirtualView.Partition mCredentialsPartition; private CustomVirtualView.Partition mCcPartition; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.multiple_partitions_activity); mCustomVirtualView = findViewById(R.id.custom_view); mCredentialsPartition = mCustomVirtualView.addPartition(getString(R.string.partition_credentials)); mCredentialsPartition.addLine("username", View.AUTOFILL_TYPE_TEXT, getString(R.string.username_label), " ", false, View.AUTOFILL_HINT_USERNAME); mCredentialsPartition.addLine("password", View.AUTOFILL_TYPE_TEXT, getString(R.string.password_label), " ", true, View.AUTOFILL_HINT_PASSWORD); int ccExpirationType = View.AUTOFILL_TYPE_DATE; // TODO: add a checkbox to switch between text / date instead Intent intent = getIntent(); if (intent != null) { int newType = intent.getIntExtra("dateType", -1); if (newType != -1) { ccExpirationType = newType; String typeMessage = getString(R.string.message_credit_card_expiration_type, Util.getAutofillTypeAsString(ccExpirationType)); // TODO: display type in a header or proper status widget Toast.makeText(getApplicationContext(), typeMessage, Toast.LENGTH_LONG).show(); } } mCcPartition = mCustomVirtualView.addPartition(getString(R.string.partition_credit_card)); mCcPartition.addLine("ccNumber", View.AUTOFILL_TYPE_TEXT, getString(R.string.credit_card_number_label), " ", true, View.AUTOFILL_HINT_CREDIT_CARD_NUMBER); mCcPartition.addLine("ccDay", View.AUTOFILL_TYPE_TEXT, getString(R.string.credit_card_expiration_day_label), " ", true, View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY); mCcPartition.addLine("ccMonth", ccExpirationType, getString(R.string.credit_card_expiration_month_label), " ", true, View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH); mCcPartition.addLine("ccYear", View.AUTOFILL_TYPE_TEXT, getString(R.string.credit_card_expiration_year_label), " ", true, View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR); mCcPartition.addLine("ccDate", ccExpirationType, getString(R.string.credit_card_expiration_date_label), " ", true, View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE); mCcPartition.addLine("ccSecurityCode", View.AUTOFILL_TYPE_TEXT, getString(R.string.credit_card_security_code_label), " ", true, View.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE); findViewById(R.id.clear).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { resetFields(); mCustomVirtualView.resetPositions(); mAutofillManager.cancel(); } }); mAutofillManager = getSystemService(AutofillManager.class); } private void resetFields() { mCredentialsPartition.reset(); mCcPartition.reset(); mCustomVirtualView.postInvalidate(); } }