summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorMatthew Wong <wongma@protonmail.ch>2015-08-03 08:31:23 -0400
committerMatthew Wong <wongma@protonmail.ch>2015-08-14 17:36:47 -0400
commit51a05087e5a349afa3f4e0febdc3a339179e9bbd (patch)
treeb485de2203fb3d11af285b18d7c894c672bc6bb9 /app
parent2d7c37d379ae48fa3ff464032ad4cb1759b1dc31 (diff)
Add searching for apps in autofill settings page
Diffstat (limited to 'app')
-rw-r--r--app/src/main/AndroidManifest.xml3
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java68
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java2
-rw-r--r--app/src/main/res/layout/app_list_item.xml23
-rw-r--r--app/src/main/res/layout/autofill_recycler_view.xml7
5 files changed, 93 insertions, 10 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index b3600c53..3ddc04e8 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -55,7 +55,10 @@
</service>
<activity android:name=".autofill.AutofillActivity">
+ android:parentActivityName=".PasswordStore">
+ <meta-data android:name="android.support.PARENT_ACTIVITY"
+ android:value="com.zeapo.pwdstore.PasswordStore" />
</activity>
<activity android:name="net.rdrei.android.dirchooser.DirectoryChooserActivity" />
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java
index 5d8fac5e..5c42ab8d 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java
@@ -7,11 +7,19 @@ import android.content.IntentSender;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.database.Cursor;
+import android.database.MatrixCursor;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.ImageView;
+import android.widget.SearchView;
+import android.widget.SimpleCursorAdapter;
+import android.widget.TextView;
import com.zeapo.pwdstore.R;
@@ -48,9 +56,15 @@ public class AutofillActivity extends AppCompatActivity {
return;
}
// otherwise if called from settings
- final PackageManager pm = getPackageManager();
- List<ApplicationInfo> allApps = pm.getInstalledApplications(0);
+ setContentView(R.layout.autofill_recycler_view);
+ recyclerView = (RecyclerView) findViewById(R.id.autofill_recycler);
+
+ layoutManager = new LinearLayoutManager(this);
+ recyclerView.setLayoutManager(layoutManager);
+ // apps for which the user has custom settings should be in the recycler
+ final PackageManager pm = getPackageManager();
+ final List<ApplicationInfo> allApps = pm.getInstalledApplications(0);
SharedPreferences prefs
= getSharedPreferences("autofill", Context.MODE_PRIVATE);
Map<String, ?> prefApps = prefs.getAll();
@@ -60,18 +74,54 @@ public class AutofillActivity extends AppCompatActivity {
apps.add(applicationInfo);
}
}
+ recyclerAdapter = new AutofillRecyclerAdapter(apps, pm);
+ recyclerView.setAdapter(recyclerAdapter);
- setContentView(R.layout.autofill_recycler_view);
- recyclerView = (RecyclerView) findViewById(R.id.autofill_recycler);
+ getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
+ final SearchView searchView = (SearchView) findViewById(R.id.app_search);
- layoutManager = new LinearLayoutManager(this);
- recyclerView.setLayoutManager(layoutManager);
+ // create search suggestions of apps with icons & names
+ final SimpleCursorAdapter.ViewBinder viewBinder = new SimpleCursorAdapter.ViewBinder() {
+ @Override
+ public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
+ if (view instanceof TextView) {
+ ((TextView) view).setText(cursor.getString(columnIndex));
+ } else if (view instanceof ImageView) {
+ try {
+ ((ImageView) view).setImageDrawable(pm.getApplicationIcon(cursor.getString(columnIndex)));
+ } catch (PackageManager.NameNotFoundException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ return true;
+ }
+ };
+ searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
+ @Override
+ public boolean onQueryTextSubmit(String query) {
+ return false;
+ }
- recyclerAdapter = new AutofillRecyclerAdapter(apps, pm);
- recyclerView.setAdapter(recyclerAdapter);
+ @Override
+ public boolean onQueryTextChange(String newText) {
+ // should be a better/faster way to do this?
+ MatrixCursor matrixCursor = new MatrixCursor(new String[]{"_id", "package", "label"});
+ for (ApplicationInfo applicationInfo : allApps) {
+ if (applicationInfo.loadLabel(pm).toString().toLowerCase().contains(newText.toLowerCase())) {
+ matrixCursor.addRow(new Object[]{0, applicationInfo.packageName, applicationInfo.loadLabel(pm)});
+ }
+ }
+ SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(AutofillActivity.this
+ , R.layout.app_list_item, matrixCursor, new String[]{"package", "label"}
+ , new int[]{android.R.id.icon1, android.R.id.text1}, 0);
+ simpleCursorAdapter.setViewBinder(viewBinder);
+ searchView.setSuggestionsAdapter(simpleCursorAdapter);
+ return false;
+ }
+ });
setTitle("Autofill Apps");
-
}
@Override
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
index 6188ef6d..f3108733 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
@@ -60,7 +60,7 @@ public class AutofillService extends AccessibilityService {
serviceConnection.bindToService();
settings = PreferenceManager.getDefaultSharedPreferences(this);
}
-
+ // TODO handle CLICKS and change search/search results (just use first result)
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
// if returning to the source app from a successful AutofillActivity
diff --git a/app/src/main/res/layout/app_list_item.xml b/app/src/main/res/layout/app_list_item.xml
new file mode 100644
index 00000000..7df28cc6
--- /dev/null
+++ b/app/src/main/res/layout/app_list_item.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="horizontal"
+ android:paddingLeft="8dp"
+ android:paddingRight="8dp">
+
+ <ImageView
+ android:id="@android:id/icon1"
+ android:layout_width="48dp"
+ android:layout_height="48dp"/>
+
+ <TextView android:id="@android:id/text1"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center_vertical"
+ android:minHeight="?android:attr/listPreferredItemHeightSmall"
+ android:textAppearance="?android:attr/textAppearanceListItemSmall"
+ android:layout_marginLeft="8dp"/>
+
+</LinearLayout> \ No newline at end of file
diff --git a/app/src/main/res/layout/autofill_recycler_view.xml b/app/src/main/res/layout/autofill_recycler_view.xml
index 27afa77d..98ff779d 100644
--- a/app/src/main/res/layout/autofill_recycler_view.xml
+++ b/app/src/main/res/layout/autofill_recycler_view.xml
@@ -4,6 +4,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
+ <SearchView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/app_search"
+ android:queryHint="Add an app to configure"
+ android:iconifiedByDefault="false"/>
+
<android.support.v7.widget.RecyclerView
android:id="@+id/autofill_recycler"
android:scrollbars="vertical"