aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com/zeapo
diff options
context:
space:
mode:
authorMatthew Wong <wongma@protonmail.ch>2015-07-31 09:00:06 -0400
committerMatthew Wong <wongma@protonmail.ch>2015-08-14 17:36:47 -0400
commit2d7c37d379ae48fa3ff464032ad4cb1759b1dc31 (patch)
tree3ecaabc58ace429db6fe67d64c2b7a8252baabe4 /app/src/main/java/com/zeapo
parent4b15ea3ae90fa870c622192cbf89eb5e02db97b6 (diff)
Add per-app settings page
Diffstat (limited to 'app/src/main/java/com/zeapo')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/AutofillActivity.java35
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.java10
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java84
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java62
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java (renamed from app/src/main/java/com/zeapo/pwdstore/AutofillService.java)10
5 files changed, 165 insertions, 36 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/AutofillActivity.java b/app/src/main/java/com/zeapo/pwdstore/AutofillActivity.java
deleted file mode 100644
index 2a1227b9..00000000
--- a/app/src/main/java/com/zeapo/pwdstore/AutofillActivity.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.zeapo.pwdstore;
-
-import android.app.PendingIntent;
-import android.content.Intent;
-import android.content.IntentSender;
-import android.os.Bundle;
-import android.support.v7.app.AppCompatActivity;
-import android.util.Log;
-
-// blank activity started by service for calling startIntentSenderForResult
-public class AutofillActivity extends AppCompatActivity {
- public static final int REQUEST_CODE_DECRYPT_AND_VERIFY = 9913;
- private boolean bound = false;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Intent intent = getIntent();
- PendingIntent pi = intent.getExtras().getParcelable("pending_intent");
- try {
- startIntentSenderForResult(pi.getIntentSender()
- , REQUEST_CODE_DECRYPT_AND_VERIFY, null, 0, 0, 0);
- } catch (IntentSender.SendIntentException e) {
- Log.e(AutofillService.Constants.TAG, "SendIntentException", e);
- }
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- finish(); // go back to the password field app
- if (resultCode == RESULT_OK) {
- AutofillService.setUnlockOK(); // report the result to service
- }
- }
-}
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
index 9a5c83d4..e2a9e5a7 100644
--- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
+++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
@@ -17,6 +17,7 @@ import android.widget.Toast;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Iterables;
+import com.zeapo.pwdstore.autofill.AutofillActivity;
import com.zeapo.pwdstore.crypto.PgpHandler;
import com.zeapo.pwdstore.git.GitActivity;
import com.zeapo.pwdstore.utils.PasswordRepository;
@@ -182,6 +183,15 @@ public class UserPreference extends AppCompatActivity {
findPreference("pref_select_external").setOnPreferenceChangeListener(resetRepo);
findPreference("git_external").setOnPreferenceChangeListener(resetRepo);
+
+ findPreference("autofill_apps").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ Intent intent = new Intent(callingActivity, AutofillActivity.class);
+ startActivity(intent);
+ return false;
+ }
+ });
}
@Override
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java
new file mode 100644
index 00000000..5d8fac5e
--- /dev/null
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java
@@ -0,0 +1,84 @@
+package com.zeapo.pwdstore.autofill;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentSender;
+import android.content.SharedPreferences;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+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 com.zeapo.pwdstore.R;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+// blank activity started by service for calling startIntentSenderForResult
+public class AutofillActivity extends AppCompatActivity {
+ public static final int REQUEST_CODE_DECRYPT_AND_VERIFY = 9913;
+ private boolean bound = false;
+
+ private RecyclerView recyclerView;
+ private AutofillRecyclerAdapter recyclerAdapter;
+ private RecyclerView.LayoutManager layoutManager;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Intent intent = getIntent();
+ Bundle extras = intent.getExtras();
+ // if called by service just for startIntentSenderForResult
+ if (extras != null) {
+ try {
+ PendingIntent pi = intent.getExtras().getParcelable("pending_intent");
+ if (pi == null) {
+ return;
+ }
+ startIntentSenderForResult(pi.getIntentSender()
+ , REQUEST_CODE_DECRYPT_AND_VERIFY, null, 0, 0, 0);
+ } catch (IntentSender.SendIntentException e) {
+ Log.e(AutofillService.Constants.TAG, "SendIntentException", e);
+ }
+ return;
+ }
+ // otherwise if called from settings
+ final PackageManager pm = getPackageManager();
+ List<ApplicationInfo> allApps = pm.getInstalledApplications(0);
+
+ SharedPreferences prefs
+ = getSharedPreferences("autofill", Context.MODE_PRIVATE);
+ Map<String, ?> prefApps = prefs.getAll();
+ ArrayList<ApplicationInfo> apps = new ArrayList<>();
+ for (ApplicationInfo applicationInfo : allApps) {
+ if (prefApps.containsKey(applicationInfo.packageName)) {
+ apps.add(applicationInfo);
+ }
+ }
+
+ setContentView(R.layout.autofill_recycler_view);
+ recyclerView = (RecyclerView) findViewById(R.id.autofill_recycler);
+
+ layoutManager = new LinearLayoutManager(this);
+ recyclerView.setLayoutManager(layoutManager);
+
+ recyclerAdapter = new AutofillRecyclerAdapter(apps, pm);
+ recyclerView.setAdapter(recyclerAdapter);
+
+ setTitle("Autofill Apps");
+
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ finish(); // go back to the password field app
+ if (resultCode == RESULT_OK) {
+ AutofillService.setUnlockOK(); // report the result to service
+ }
+ }
+}
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
new file mode 100644
index 00000000..b59223bd
--- /dev/null
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
@@ -0,0 +1,62 @@
+package com.zeapo.pwdstore.autofill;
+
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.zeapo.pwdstore.R;
+
+import java.util.ArrayList;
+
+public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecyclerAdapter.ViewHolder> {
+ private ArrayList<ApplicationInfo> apps;
+ private PackageManager pm;
+
+ public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
+ public View view;
+ public TextView name;
+ public ImageView icon;
+
+ public ViewHolder(View view) {
+ super(view);
+ this.view = view;
+ name = (TextView) view.findViewById(R.id.app_name);
+ icon = (ImageView) view.findViewById(R.id.app_icon);
+ view.setOnClickListener(this);
+ }
+
+ @Override
+ public void onClick(View v) {
+
+ }
+ }
+
+ public AutofillRecyclerAdapter(ArrayList<ApplicationInfo> apps, PackageManager pm) {
+ this.apps = apps;
+ this.pm = pm;
+ }
+
+ @Override
+ public AutofillRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ View v = LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.autofill_row_layout, parent, false);
+ return new ViewHolder(v);
+ }
+
+ @Override
+ public void onBindViewHolder(AutofillRecyclerAdapter.ViewHolder holder, int position) {
+ ApplicationInfo app = apps.get(position);
+ holder.name.setText(pm.getApplicationLabel(app));
+ holder.icon.setImageDrawable(pm.getApplicationIcon(app));
+ }
+
+ @Override
+ public int getItemCount() {
+ return apps.size();
+ }
+}
diff --git a/app/src/main/java/com/zeapo/pwdstore/AutofillService.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
index 887e100e..6188ef6d 100644
--- a/app/src/main/java/com/zeapo/pwdstore/AutofillService.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
@@ -1,4 +1,4 @@
-package com.zeapo.pwdstore;
+package com.zeapo.pwdstore.autofill;
import android.accessibilityservice.AccessibilityService;
import android.app.PendingIntent;
@@ -20,6 +20,8 @@ import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.Toast;
+import com.zeapo.pwdstore.R;
+import com.zeapo.pwdstore.UserPreference;
import com.zeapo.pwdstore.utils.PasswordItem;
import com.zeapo.pwdstore.utils.PasswordRepository;
@@ -107,6 +109,12 @@ public class AutofillService extends AccessibilityService {
decryptAndVerify();
}
});
+ builder.setNeutralButton("Match", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+
+ }
+ });
dialog = builder.create();
dialog.setIcon(R.drawable.ic_launcher);
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);