blob: 485ef2887476d467cc50feb424d119484caaa4fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
package com.zeapo.pwdstore.autofill;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
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<ResolveInfo> apps;
private PackageManager pm;
private AutofillPreferenceActivity activity;
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public View view;
public TextView name;
public TextView secondary;
public ImageView icon;
public String packageName;
public ViewHolder(View view) {
super(view);
this.view = view;
name = (TextView) view.findViewById(R.id.app_name);
secondary = (TextView) view.findViewById(R.id.secondary_text);
icon = (ImageView) view.findViewById(R.id.app_icon);
view.setOnClickListener(this);
}
@Override
public void onClick(View v) {
activity.showDialog(packageName, name.getText().toString());
}
}
public AutofillRecyclerAdapter(ArrayList<ResolveInfo> apps, PackageManager pm, AutofillPreferenceActivity activity) {
this.apps = apps;
this.pm = pm;
this.activity = activity;
}
@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) {
ResolveInfo app = apps.get(position);
holder.name.setText(app.loadLabel(pm)); // 'No package identifier when getting value for resource number 0x00000000' 5+
holder.icon.setImageDrawable(app.loadIcon(pm));
holder.packageName = app.activityInfo.packageName;
holder.secondary.setVisibility(View.VISIBLE);
holder.view.setBackgroundResource(R.color.grey_white_1000);
SharedPreferences prefs
= activity.getApplicationContext().getSharedPreferences("autofill", Context.MODE_PRIVATE);
String preference = prefs.getString(holder.packageName, "");
switch (preference) {
case "":
holder.secondary.setVisibility(View.GONE);
// "android:windowBackground"
holder.view.setBackgroundResource(R.color.indigo_50);
break;
case "first":
holder.secondary.setText("Automatically match");
break;
case "never":
holder.secondary.setText("Never match");
break;
default:
holder.secondary.setText("Match with " + preference);
break;
}
}
@Override
public int getItemCount() {
return apps.size();
}
public int getPosition(String packageName) {
for (int i = 0; i < apps.size(); i++) {
if (apps.get(i).activityInfo.packageName.equals(packageName)) {
return i;
}
}
return -1;
}
public void filter(String s) {
}
}
|