mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-18 06:45:03 -05:00
fixes for OpenPgpListPreference
This commit is contained in:
parent
4a13f70a88
commit
8c6017e890
@ -46,7 +46,9 @@ public class OpenPgpListPreference extends DialogPreference {
|
|||||||
private static final Intent MARKET_INTENT = new Intent(Intent.ACTION_VIEW, Uri.parse(
|
private static final Intent MARKET_INTENT = new Intent(Intent.ACTION_VIEW, Uri.parse(
|
||||||
String.format(MARKET_INTENT_URI_BASE, OPENKEYCHAIN_PACKAGE)));
|
String.format(MARKET_INTENT_URI_BASE, OPENKEYCHAIN_PACKAGE)));
|
||||||
|
|
||||||
private ArrayList<OpenPgpProviderEntry> mProviderList = new ArrayList<OpenPgpProviderEntry>();
|
private ArrayList<OpenPgpProviderEntry> mLegacyList = new ArrayList<OpenPgpProviderEntry>();
|
||||||
|
private ArrayList<OpenPgpProviderEntry> mList = new ArrayList<OpenPgpProviderEntry>();
|
||||||
|
|
||||||
private String mSelectedPackage;
|
private String mSelectedPackage;
|
||||||
|
|
||||||
public OpenPgpListPreference(Context context, AttributeSet attrs) {
|
public OpenPgpListPreference(Context context, AttributeSet attrs) {
|
||||||
@ -64,15 +66,24 @@ public class OpenPgpListPreference extends DialogPreference {
|
|||||||
* @param simpleName
|
* @param simpleName
|
||||||
* @param icon
|
* @param icon
|
||||||
*/
|
*/
|
||||||
public void addProvider(int position, String packageName, String simpleName, Drawable icon) {
|
public void addLegacyProvider(int position, String packageName, String simpleName, Drawable icon) {
|
||||||
mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon));
|
mLegacyList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPrepareDialogBuilder(Builder builder) {
|
protected void onPrepareDialogBuilder(Builder builder) {
|
||||||
|
mList.clear();
|
||||||
|
|
||||||
// get providers
|
// add "none"-entry
|
||||||
mProviderList.clear();
|
mList.add(0, new OpenPgpProviderEntry("",
|
||||||
|
getContext().getString(R.string.openpgp_list_preference_none),
|
||||||
|
getContext().getResources().getDrawable(R.drawable.ic_action_cancel_launchersize)));
|
||||||
|
|
||||||
|
// add all additional (legacy) providers
|
||||||
|
mList.addAll(mLegacyList);
|
||||||
|
|
||||||
|
// search for OpenPGP providers...
|
||||||
|
ArrayList<OpenPgpProviderEntry> providerList = new ArrayList<OpenPgpProviderEntry>();
|
||||||
Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT);
|
Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT);
|
||||||
List<ResolveInfo> resInfo = getContext().getPackageManager().queryIntentServices(intent, 0);
|
List<ResolveInfo> resInfo = getContext().getPackageManager().queryIntentServices(intent, 0);
|
||||||
if (!resInfo.isEmpty()) {
|
if (!resInfo.isEmpty()) {
|
||||||
@ -85,12 +96,12 @@ public class OpenPgpListPreference extends DialogPreference {
|
|||||||
.getPackageManager()));
|
.getPackageManager()));
|
||||||
Drawable icon = resolveInfo.serviceInfo.loadIcon(getContext().getPackageManager());
|
Drawable icon = resolveInfo.serviceInfo.loadIcon(getContext().getPackageManager());
|
||||||
|
|
||||||
mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon));
|
providerList.add(new OpenPgpProviderEntry(packageName, simpleName, icon));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add install links if empty
|
if (providerList.isEmpty()) {
|
||||||
if (mProviderList.isEmpty()) {
|
// add install links if provider list is empty
|
||||||
resInfo = getContext().getPackageManager().queryIntentActivities
|
resInfo = getContext().getPackageManager().queryIntentActivities
|
||||||
(MARKET_INTENT, 0);
|
(MARKET_INTENT, 0);
|
||||||
for (ResolveInfo resolveInfo : resInfo) {
|
for (ResolveInfo resolveInfo : resInfo) {
|
||||||
@ -101,26 +112,24 @@ public class OpenPgpListPreference extends DialogPreference {
|
|||||||
.loadLabel(getContext().getPackageManager()));
|
.loadLabel(getContext().getPackageManager()));
|
||||||
String simpleName = String.format(getContext().getString(R.string
|
String simpleName = String.format(getContext().getString(R.string
|
||||||
.openpgp_install_openkeychain_via), marketName);
|
.openpgp_install_openkeychain_via), marketName);
|
||||||
mProviderList.add(new OpenPgpProviderEntry(OPENKEYCHAIN_PACKAGE, simpleName,
|
mList.add(new OpenPgpProviderEntry(OPENKEYCHAIN_PACKAGE, simpleName,
|
||||||
icon, marketIntent));
|
icon, marketIntent));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// add provider
|
||||||
|
mList.addAll(providerList);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add "none"-entry
|
|
||||||
mProviderList.add(0, new OpenPgpProviderEntry("",
|
|
||||||
getContext().getString(R.string.openpgp_list_preference_none),
|
|
||||||
getContext().getResources().getDrawable(R.drawable.ic_action_cancel_launchersize)));
|
|
||||||
|
|
||||||
// Init ArrayAdapter with OpenPGP Providers
|
// Init ArrayAdapter with OpenPGP Providers
|
||||||
ListAdapter adapter = new ArrayAdapter<OpenPgpProviderEntry>(getContext(),
|
ListAdapter adapter = new ArrayAdapter<OpenPgpProviderEntry>(getContext(),
|
||||||
android.R.layout.select_dialog_singlechoice, android.R.id.text1, mProviderList) {
|
android.R.layout.select_dialog_singlechoice, android.R.id.text1, mList) {
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
// User super class to create the View
|
// User super class to create the View
|
||||||
View v = super.getView(position, convertView, parent);
|
View v = super.getView(position, convertView, parent);
|
||||||
TextView tv = (TextView) v.findViewById(android.R.id.text1);
|
TextView tv = (TextView) v.findViewById(android.R.id.text1);
|
||||||
|
|
||||||
// Put the image on the TextView
|
// Put the image on the TextView
|
||||||
tv.setCompoundDrawablesWithIntrinsicBounds(mProviderList.get(position).icon, null,
|
tv.setCompoundDrawablesWithIntrinsicBounds(mList.get(position).icon, null,
|
||||||
null, null);
|
null, null);
|
||||||
|
|
||||||
// Add margin between image and text (support various screen densities)
|
// Add margin between image and text (support various screen densities)
|
||||||
@ -136,7 +145,7 @@ public class OpenPgpListPreference extends DialogPreference {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
OpenPgpProviderEntry entry = mProviderList.get(which);
|
OpenPgpProviderEntry entry = mList.get(which);
|
||||||
|
|
||||||
if (entry.intent != null) {
|
if (entry.intent != null) {
|
||||||
/*
|
/*
|
||||||
@ -181,9 +190,9 @@ public class OpenPgpListPreference extends DialogPreference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getIndexOfProviderList(String packageName) {
|
private int getIndexOfProviderList(String packageName) {
|
||||||
for (OpenPgpProviderEntry app : mProviderList) {
|
for (OpenPgpProviderEntry app : mList) {
|
||||||
if (app.packageName.equals(packageName)) {
|
if (app.packageName.equals(packageName)) {
|
||||||
return mProviderList.indexOf(app);
|
return mList.indexOf(app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,7 +223,7 @@ public class OpenPgpListPreference extends DialogPreference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getEntryByValue(String packageName) {
|
public String getEntryByValue(String packageName) {
|
||||||
for (OpenPgpProviderEntry app : mProviderList) {
|
for (OpenPgpProviderEntry app : mList) {
|
||||||
if (app.packageName.equals(packageName)) {
|
if (app.packageName.equals(packageName)) {
|
||||||
return app.simpleName;
|
return app.simpleName;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user