下面列出了android.view.View#AUTOFILL_TYPE_DATE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static String getTypeAsString(int type) {
switch (type) {
case View.AUTOFILL_TYPE_TEXT:
return "TYPE_TEXT";
case View.AUTOFILL_TYPE_LIST:
return "TYPE_LIST";
case View.AUTOFILL_TYPE_NONE:
return "TYPE_NONE";
case View.AUTOFILL_TYPE_TOGGLE:
return "TYPE_TOGGLE";
case View.AUTOFILL_TYPE_DATE:
return "TYPE_DATE";
}
return "UNKNOWN_TYPE";
}
public static String getAutofillTypeAsString(int type) {
switch (type) {
case View.AUTOFILL_TYPE_TEXT:
return "TYPE_TEXT";
case View.AUTOFILL_TYPE_LIST:
return "TYPE_LIST";
case View.AUTOFILL_TYPE_NONE:
return "TYPE_NONE";
case View.AUTOFILL_TYPE_TOGGLE:
return "TYPE_TOGGLE";
case View.AUTOFILL_TYPE_DATE:
return "TYPE_DATE";
}
return "UNKNOWN_TYPE";
}
public static String getTypeAsString(int type) {
switch (type) {
case View.AUTOFILL_TYPE_TEXT:
return "TYPE_TEXT";
case View.AUTOFILL_TYPE_LIST:
return "TYPE_LIST";
case View.AUTOFILL_TYPE_NONE:
return "TYPE_NONE";
case View.AUTOFILL_TYPE_TOGGLE:
return "TYPE_TOGGLE";
case View.AUTOFILL_TYPE_DATE:
return "TYPE_DATE";
}
return "UNKNOWN_TYPE";
}
public static String getAutofillTypeAsString(int type) {
switch (type) {
case View.AUTOFILL_TYPE_TEXT:
return "TYPE_TEXT";
case View.AUTOFILL_TYPE_LIST:
return "TYPE_LIST";
case View.AUTOFILL_TYPE_NONE:
return "TYPE_NONE";
case View.AUTOFILL_TYPE_TOGGLE:
return "TYPE_TOGGLE";
case View.AUTOFILL_TYPE_DATE:
return "TYPE_DATE";
}
return "UNKNOWN_TYPE";
}
void bindValueToNode(AssistStructure.ViewNode viewNode,
FilledAutofillField field, Dataset.Builder builder,
MutableBoolean setValueAtLeastOnce) {
AutofillId autofillId = viewNode.getAutofillId();
if (autofillId == null) {
logw("Autofill ID null for %s", viewNode.toString());
return;
}
int autofillType = viewNode.getAutofillType();
switch (autofillType) {
case View.AUTOFILL_TYPE_LIST:
CharSequence[] options = viewNode.getAutofillOptions();
int listValue = -1;
if (options != null) {
listValue = indexOf(viewNode.getAutofillOptions(), field.getTextValue());
}
if (listValue != -1) {
builder.setValue(autofillId, AutofillValue.forList(listValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_DATE:
Long dateValue = field.getDateValue();
if (dateValue != null) {
builder.setValue(autofillId, AutofillValue.forDate(dateValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_TEXT:
String textValue = field.getTextValue();
if (textValue != null) {
builder.setValue(autofillId, AutofillValue.forText(textValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_TOGGLE:
Boolean toggleValue = field.getToggleValue();
if (toggleValue != null) {
builder.setValue(autofillId, AutofillValue.forToggle(toggleValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_NONE:
default:
logw("Invalid autofill type - %d", autofillType);
break;
}
}
@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);
mAutofillManager = getSystemService(AutofillManager.class);
findViewById(R.id.clear).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
resetFields();
mCustomVirtualView.resetPositions();
mAutofillManager.cancel();
}
});
}
void bindValueToNode(AssistStructure.ViewNode viewNode,
FilledAutofillField field, Dataset.Builder builder,
MutableBoolean setValueAtLeastOnce) {
AutofillId autofillId = viewNode.getAutofillId();
if (autofillId == null) {
logw("Autofill ID null for %s", viewNode.toString());
return;
}
int autofillType = viewNode.getAutofillType();
switch (autofillType) {
case View.AUTOFILL_TYPE_LIST:
CharSequence[] options = viewNode.getAutofillOptions();
int listValue = -1;
if (options != null) {
listValue = indexOf(viewNode.getAutofillOptions(), field.getTextValue());
}
if (listValue != -1) {
builder.setValue(autofillId, AutofillValue.forList(listValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_DATE:
Long dateValue = field.getDateValue();
if (dateValue != null) {
builder.setValue(autofillId, AutofillValue.forDate(dateValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_TEXT:
String textValue = field.getTextValue();
if (textValue != null) {
builder.setValue(autofillId, AutofillValue.forText(textValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_TOGGLE:
Boolean toggleValue = field.getToggleValue();
if (toggleValue != null) {
builder.setValue(autofillId, AutofillValue.forToggle(toggleValue));
setValueAtLeastOnce.value = true;
}
break;
case View.AUTOFILL_TYPE_NONE:
default:
logw("Invalid autofill type - %d", autofillType);
break;
}
}
@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);
mAutofillManager = getSystemService(AutofillManager.class);
findViewById(R.id.clear).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
resetFields();
mCustomVirtualView.resetPositions();
mAutofillManager.cancel();
}
});
}