upload android base code part8
This commit is contained in:
parent
841ae54672
commit
5425409085
57075 changed files with 9846578 additions and 0 deletions
13
android/packages/experimental/FilledApp/Android.mk
Normal file
13
android/packages/experimental/FilledApp/Android.mk
Normal file
|
@ -0,0 +1,13 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
|
||||
LOCAL_PACKAGE_NAME := FilledApp
|
||||
|
||||
LOCAL_PROGUARD_ENABLED := disabled
|
||||
|
||||
include $(BUILD_PACKAGE)
|
18
android/packages/experimental/FilledApp/AndroidManifest.xml
Normal file
18
android/packages/experimental/FilledApp/AndroidManifest.xml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="foo.bar.filled" >
|
||||
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:allowBackup="false" >
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
|
@ -0,0 +1,107 @@
|
|||
<foo.bar.filled.CustomLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="500dip">
|
||||
</View>
|
||||
|
||||
<HorizontalScrollView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<View
|
||||
android:layout_width="500dip"
|
||||
android:layout_height="fill_parent">
|
||||
</View>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/username_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/username">
|
||||
</TextView>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/username"
|
||||
android:layout_width="200dip"
|
||||
android:layout_height="wrap_content">
|
||||
</EditText>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/password_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/password">
|
||||
</TextView>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="200dip"
|
||||
android:layout_height="wrap_content">
|
||||
</EditText>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="500dip"
|
||||
android:layout_height="fill_parent">
|
||||
</View>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
||||
<Button
|
||||
android:id="@+id/finish"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Finish">
|
||||
</Button>
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="500dip">
|
||||
</View>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</foo.bar.filled.CustomLinearLayout>
|
|
@ -0,0 +1,8 @@
|
|||
<resources>
|
||||
|
||||
<string name="app_name">Filled App</string>
|
||||
<string name="title_activity_main">MainActivity</string>
|
||||
<string name="username">Username</string>
|
||||
<string name="password">Password</string>
|
||||
|
||||
</resources>
|
|
@ -0,0 +1,143 @@
|
|||
package foo.bar.filled;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Rect;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewStructure;
|
||||
import android.view.autofill.AutofillManager;
|
||||
import android.view.autofill.AutofillValue;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class CustomLinearLayout extends LinearLayout {
|
||||
static final boolean VIRTUAL = false;
|
||||
|
||||
public CustomLinearLayout(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
if (VIRTUAL) {
|
||||
getViewTreeObserver().addOnGlobalFocusChangeListener((oldFocus, newFocus) -> {
|
||||
AutofillManager autofillManager = getContext().getSystemService(
|
||||
AutofillManager.class);
|
||||
if (oldFocus != null) {
|
||||
autofillManager.notifyViewExited(CustomLinearLayout.this,
|
||||
oldFocus.getAccessibilityViewId());
|
||||
}
|
||||
if (newFocus != null) {
|
||||
Rect bounds = new Rect();
|
||||
newFocus.getBoundsOnScreen(bounds);
|
||||
autofillManager.notifyViewEntered(CustomLinearLayout.this,
|
||||
newFocus.getAccessibilityViewId(), bounds);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchProvideAutofillStructure(ViewStructure structure, int flags) {
|
||||
if (!VIRTUAL) {
|
||||
super.dispatchProvideAutofillStructure(structure, flags);
|
||||
} else {
|
||||
onProvideAutofillVirtualStructure(structure, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags) {
|
||||
if (!VIRTUAL) {
|
||||
return;
|
||||
}
|
||||
populateViewStructure(this, structure);
|
||||
onProvideAutofillVirtualStructureRecursive(this, structure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autofill(SparseArray<AutofillValue> values) {
|
||||
final int valueCount = values.size();
|
||||
for (int i = 0; i < valueCount; i++) {
|
||||
final int virtualId = values.keyAt(i);
|
||||
final AutofillValue value = values.valueAt(i);
|
||||
View view = findViewByAccessibilityIdTraversal(virtualId);
|
||||
if (view instanceof EditText && !TextUtils.isEmpty(value.getTextValue())) {
|
||||
EditText editText = (EditText) view;
|
||||
editText.setText(value.getTextValue());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onProvideAutofillVirtualStructureRecursive(View view, ViewStructure node) {
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
if (view instanceof ViewGroup) {
|
||||
ViewGroup viewGroup = (ViewGroup) view;
|
||||
final int childCount = viewGroup.getChildCount();
|
||||
node.setChildCount(childCount);
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
View child = viewGroup.getChildAt(i);
|
||||
ViewStructure chlidNode = node.newChild(i);
|
||||
chlidNode.setAutofillId(node, child.getAccessibilityViewId());
|
||||
populateViewStructure(child, chlidNode);
|
||||
onProvideAutofillVirtualStructureRecursive(child, chlidNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void populateViewStructure(View view, ViewStructure structure) {
|
||||
if (view.getId() != NO_ID) {
|
||||
String pkg, type, entry;
|
||||
try {
|
||||
final Resources res = getResources();
|
||||
entry = res.getResourceEntryName(view.getId());
|
||||
type = res.getResourceTypeName(view.getId());
|
||||
pkg = res.getResourcePackageName(view.getId());
|
||||
} catch (Resources.NotFoundException e) {
|
||||
entry = type = pkg = null;
|
||||
}
|
||||
structure.setId(view.getId(), pkg, type, entry);
|
||||
} else {
|
||||
structure.setId(view.getId(), null, null, null);
|
||||
}
|
||||
Rect rect = structure.getTempRect();
|
||||
view.getDrawingRect(rect);
|
||||
structure.setDimens(rect.left, rect.top, 0, 0, rect.width(), rect.height());
|
||||
structure.setVisibility(VISIBLE);
|
||||
structure.setEnabled(view.isEnabled());
|
||||
if (view.isClickable()) {
|
||||
structure.setClickable(true);
|
||||
}
|
||||
if (view.isFocusable()) {
|
||||
structure.setFocusable(true);
|
||||
}
|
||||
if (view.isFocused()) {
|
||||
structure.setFocused(true);
|
||||
}
|
||||
if (view.isAccessibilityFocused()) {
|
||||
structure.setAccessibilityFocused(true);
|
||||
}
|
||||
if (view.isSelected()) {
|
||||
structure.setSelected(true);
|
||||
}
|
||||
if (view.isLongClickable()) {
|
||||
structure.setLongClickable(true);
|
||||
}
|
||||
CharSequence cname = view.getClass().getName();
|
||||
structure.setClassName(cname != null ? cname.toString() : null);
|
||||
structure.setContentDescription(view.getContentDescription());
|
||||
if (view instanceof TextView) {
|
||||
TextView textView = (TextView) view;
|
||||
structure.setText(textView.getText(), textView.getSelectionStart(),
|
||||
textView.getSelectionEnd());
|
||||
}
|
||||
structure.setAutofillHints(view.getAutofillHints());
|
||||
structure.setAutofillType(view.getAutofillType());
|
||||
structure.setAutofillValue(view.getAutofillValue());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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 foo.bar.filled;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.autofill.AutofillManager;
|
||||
import android.widget.Button;
|
||||
|
||||
import foo.bar.filled.R;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
public static final String LOG_TAG = "PrintActivity";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
if (!CustomLinearLayout.VIRTUAL) {
|
||||
findViewById(R.id.username).setImportantForAutofill(
|
||||
View.IMPORTANT_FOR_AUTOFILL_AUTO);
|
||||
findViewById(R.id.password).setImportantForAutofill(
|
||||
View.IMPORTANT_FOR_AUTOFILL_AUTO);
|
||||
}
|
||||
|
||||
Button finishButton = findViewById(R.id.finish);
|
||||
finishButton.setOnClickListener((view) -> finish());
|
||||
|
||||
AutofillManager autofillManager = getSystemService(AutofillManager.class);
|
||||
autofillManager.registerCallback(new AutofillManager.AutofillCallback() {
|
||||
@Override
|
||||
public void onAutofillEvent(@NonNull View view, int event) {
|
||||
super.onAutofillEvent(view, event);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue