Small ui improvements to OpenPGP app select
This commit is contained in:
parent
382d46a7cb
commit
732993b4ad
7 changed files with 77 additions and 37 deletions
|
@ -786,6 +786,7 @@ public class AccountSettings extends K9PreferenceActivity {
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
long value = (Long) newValue;
|
long value = (Long) newValue;
|
||||||
pgpCryptoKey.setValue(value);
|
pgpCryptoKey.setValue(value);
|
||||||
|
setupCryptoStuff();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,14 +22,14 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.CheckedTextView;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.ListAdapter;
|
import android.widget.ListAdapter;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.fsck.k9.Account;
|
import com.fsck.k9.Account;
|
||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.Preferences;
|
import com.fsck.k9.Preferences;
|
||||||
import com.fsck.k9.R;
|
import com.fsck.k9.R;
|
||||||
import com.fsck.k9.preferences.StorageEditor;
|
|
||||||
import com.fsck.k9.ui.dialog.ApgDeprecationWarningDialog;
|
import com.fsck.k9.ui.dialog.ApgDeprecationWarningDialog;
|
||||||
import org.openintents.openpgp.util.OpenPgpApi;
|
import org.openintents.openpgp.util.OpenPgpApi;
|
||||||
import org.openintents.openpgp.util.OpenPgpAppPreference;
|
import org.openintents.openpgp.util.OpenPgpAppPreference;
|
||||||
|
@ -42,26 +42,19 @@ public class OpenPgpAppSelectDialog extends Activity {
|
||||||
|
|
||||||
private static final String OPENKEYCHAIN_PACKAGE = "org.sufficientlysecure.keychain";
|
private static final String OPENKEYCHAIN_PACKAGE = "org.sufficientlysecure.keychain";
|
||||||
private static final String APG_PROVIDER_PLACEHOLDER = "apg-placeholder";
|
private static final String APG_PROVIDER_PLACEHOLDER = "apg-placeholder";
|
||||||
private static final String PACKAGE_NAME_APG = "org.thialfihar.android.apg";
|
|
||||||
|
|
||||||
public static final String FRAG_OPENPGP_SELECT = "openpgp_select";
|
public static final String FRAG_OPENPGP_SELECT = "openpgp_select";
|
||||||
public static final String FRAG_APG_DEPRECATE = "apg_deprecate";
|
public static final String FRAG_APG_DEPRECATE = "apg_deprecate";
|
||||||
public static final String FRAG_OPENKEYCHAIN_INFO = "openkeychain_info";
|
public static final String FRAG_OPENKEYCHAIN_INFO = "openkeychain_info";
|
||||||
|
|
||||||
private static final String MARKET_INTENT_URI_BASE = "market://details?id=%s";
|
|
||||||
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://details?id=%s", OPENKEYCHAIN_PACKAGE)));
|
||||||
|
private static final Intent MARKET_INTENT_FALLBACK = new Intent(Intent.ACTION_VIEW, Uri.parse(
|
||||||
private static final ArrayList<String> PROVIDER_BLACKLIST = new ArrayList<>();
|
String.format("https://play.google.com/store/apps/details?id=%s", OPENKEYCHAIN_PACKAGE)));
|
||||||
|
|
||||||
private boolean isStopped;
|
private boolean isStopped;
|
||||||
private Account account;
|
private Account account;
|
||||||
|
|
||||||
static {
|
|
||||||
// Unfortunately, the current released version of APG includes a broken version of the API
|
|
||||||
PROVIDER_BLACKLIST.add(PACKAGE_NAME_APG);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void startOpenPgpChooserActivity(Context context, Account account) {
|
public static void startOpenPgpChooserActivity(Context context, Account account) {
|
||||||
Intent i = new Intent(context, OpenPgpAppSelectDialog.class);
|
Intent i = new Intent(context, OpenPgpAppSelectDialog.class);
|
||||||
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
|
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
|
||||||
|
@ -126,6 +119,11 @@ public class OpenPgpAppSelectDialog extends Activity {
|
||||||
|
|
||||||
Context context = getActivity();
|
Context context = getActivity();
|
||||||
|
|
||||||
|
OpenPgpProviderEntry noneEntry = new OpenPgpProviderEntry(null,
|
||||||
|
context.getString(R.string.openpgp_list_preference_none),
|
||||||
|
getResources().getDrawable(R.drawable.ic_action_cancel_launchersize_light));
|
||||||
|
openPgpProviderList.add(noneEntry);
|
||||||
|
|
||||||
if (OpenPgpAppPreference.isApgInstalled(getActivity())) {
|
if (OpenPgpAppPreference.isApgInstalled(getActivity())) {
|
||||||
Drawable icon = getResources().getDrawable(R.drawable.ic_apg_small);
|
Drawable icon = getResources().getDrawable(R.drawable.ic_apg_small);
|
||||||
openPgpProviderList.add(new OpenPgpProviderEntry(
|
openPgpProviderList.add(new OpenPgpProviderEntry(
|
||||||
|
@ -146,7 +144,7 @@ public class OpenPgpAppSelectDialog extends Activity {
|
||||||
String simpleName = String.valueOf(resolveInfo.serviceInfo.loadLabel(context.getPackageManager()));
|
String simpleName = String.valueOf(resolveInfo.serviceInfo.loadLabel(context.getPackageManager()));
|
||||||
Drawable icon = resolveInfo.serviceInfo.loadIcon(context.getPackageManager());
|
Drawable icon = resolveInfo.serviceInfo.loadIcon(context.getPackageManager());
|
||||||
|
|
||||||
if (!PROVIDER_BLACKLIST.contains(packageName)) {
|
if (!OpenPgpProviderUtil.isBlacklisted(packageName)) {
|
||||||
openPgpProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon));
|
openPgpProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon));
|
||||||
hasNonBlacklistedChoices = true;
|
hasNonBlacklistedChoices = true;
|
||||||
}
|
}
|
||||||
|
@ -183,37 +181,30 @@ public class OpenPgpAppSelectDialog extends Activity {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
|
||||||
builder.setTitle(R.string.account_settings_crypto_app_select_title);
|
builder.setTitle(R.string.account_settings_crypto_app_select_title);
|
||||||
builder.setNegativeButton("Cancel", new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// do again, maybe an app has now been installed
|
// do again, maybe an app has now been installed
|
||||||
populateAppList();
|
populateAppList();
|
||||||
|
|
||||||
// Init ArrayAdapter with OpenPGP Providers
|
// Init ArrayAdapter with OpenPGP Providers
|
||||||
ListAdapter adapter = new ArrayAdapter<OpenPgpProviderEntry>(getActivity(),
|
ListAdapter adapter = new ArrayAdapter<OpenPgpProviderEntry>(getActivity(),
|
||||||
android.R.layout.select_dialog_item, android.R.id.text1, openPgpProviderList) {
|
R.layout.select_openpgp_app_item, android.R.id.text1, openPgpProviderList) {
|
||||||
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);
|
|
||||||
|
|
||||||
// Put the image on the TextView
|
Drawable icon = openPgpProviderList.get(position).icon;
|
||||||
tv.setCompoundDrawablesWithIntrinsicBounds(openPgpProviderList.get(position).icon, null,
|
ImageView iconView = v.findViewById(android.R.id.icon1);
|
||||||
null, null);
|
iconView.setImageDrawable(icon);
|
||||||
|
|
||||||
// Add margin between image and text (support various screen densities)
|
if (position == 0) {
|
||||||
int dp10 = (int) (10 * getContext().getResources().getDisplayMetrics().density + 0.5f);
|
((CheckedTextView) v.findViewById(android.R.id.text1)).setChecked(true);
|
||||||
tv.setCompoundDrawablePadding(dp10);
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
builder.setSingleChoiceItems(adapter, 0,
|
builder.setSingleChoiceItems(adapter, -1,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -278,17 +269,17 @@ public class OpenPgpAppSelectDialog extends Activity {
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
|
||||||
builder.setTitle("No OpenPGP app installed");
|
builder.setTitle(R.string.dialog_openkeychain_info_title);
|
||||||
builder.setView(LayoutInflater.from(getActivity()).inflate(
|
builder.setView(LayoutInflater.from(getActivity()).inflate(
|
||||||
R.layout.dialog_openkeychain_info, null, false));
|
R.layout.dialog_openkeychain_info, null, false));
|
||||||
|
|
||||||
builder.setNegativeButton("Cancel", new OnClickListener() {
|
builder.setNegativeButton(R.string.cancel_action, new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setPositiveButton("Install", new OnClickListener() {
|
builder.setPositiveButton(R.string.dialog_openkeychain_info_install, new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
startOpenKeychainInstallActivity();
|
startOpenKeychainInstallActivity();
|
||||||
|
@ -301,11 +292,9 @@ public class OpenPgpAppSelectDialog extends Activity {
|
||||||
|
|
||||||
private void startOpenKeychainInstallActivity() {
|
private void startOpenKeychainInstallActivity() {
|
||||||
try {
|
try {
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW,
|
startActivity(MARKET_INTENT);
|
||||||
Uri.parse("market://details?id=org.sufficientlysecure.keychain")));
|
|
||||||
} catch (ActivityNotFoundException anfe) {
|
} catch (ActivityNotFoundException anfe) {
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW,
|
startActivity(MARKET_INTENT_FALLBACK);
|
||||||
Uri.parse("https://play.google.com/store/apps/details?id=org.sufficientlysecure.keychain")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class AutocryptPreferEncryptDialog extends AlertDialog implements OnClick
|
||||||
// TODO add autocrypt logo?
|
// TODO add autocrypt logo?
|
||||||
// setIcon(R.drawable.autocrypt);
|
// setIcon(R.drawable.autocrypt);
|
||||||
setView(contentView);
|
setView(contentView);
|
||||||
setButton(Dialog.BUTTON_NEUTRAL, context.getString(R.string.done_action), new OnClickListener() {
|
setButton(Dialog.BUTTON_POSITIVE, context.getString(R.string.done_action), new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
cancel();
|
cancel();
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="K-9 Mail requires OpenKeychain for end-to-end encryption."
|
android:text="@string/dialog_openkeychain_info_text"
|
||||||
style="?android:textAppearanceMedium"
|
style="?android:textAppearanceMedium"
|
||||||
android:id="@+id/textView" />
|
android:id="@+id/textView" />
|
||||||
|
|
||||||
|
|
36
k9mail/src/main/res/layout/select_openpgp_app_item.xml
Normal file
36
k9mail/src/main/res/layout/select_openpgp_app_item.xml
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingLeft="12dp"
|
||||||
|
android:paddingRight="7dp"
|
||||||
|
android:paddingStart="12dip"
|
||||||
|
android:paddingEnd="7dip"
|
||||||
|
>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:id="@android:id/icon1"
|
||||||
|
tools:src="@drawable/ic_action_cancel_launchersize_light"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<CheckedTextView
|
||||||
|
android:id="@android:id/text1"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
|
android:textColor="?android:attr/textColorAlertDialogListItem"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:checkMark="?android:attr/listChoiceIndicatorSingle"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
tools:text="None"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -1298,4 +1298,8 @@ Please submit bug reports, contribute new features and ask questions at
|
||||||
<string name="dialog_autocrypt_mutual_learn_more">You can <a href="https://k9mail.github.io/2018/02/26/OpenPGP-Considerations-Part-III-Autocrypt.html">click here</a> to learn more.</string>
|
<string name="dialog_autocrypt_mutual_learn_more">You can <a href="https://k9mail.github.io/2018/02/26/OpenPGP-Considerations-Part-III-Autocrypt.html">click here</a> to learn more.</string>
|
||||||
|
|
||||||
<string name="general_settings_title">General settings</string>
|
<string name="general_settings_title">General settings</string>
|
||||||
|
|
||||||
|
<string name="dialog_openkeychain_info_title">No OpenPGP app installed</string>
|
||||||
|
<string name="dialog_openkeychain_info_install">Install</string>
|
||||||
|
<string name="dialog_openkeychain_info_text">K-9 Mail requires OpenKeychain for end-to-end encryption.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -11,6 +11,12 @@ import android.content.pm.ResolveInfo;
|
||||||
|
|
||||||
|
|
||||||
public class OpenPgpProviderUtil {
|
public class OpenPgpProviderUtil {
|
||||||
|
private static final String PACKAGE_NAME_APG = "org.thialfihar.android.apg";
|
||||||
|
private static final ArrayList<String> PROVIDER_BLACKLIST = new ArrayList<>();
|
||||||
|
static {
|
||||||
|
PROVIDER_BLACKLIST.add(PACKAGE_NAME_APG);
|
||||||
|
}
|
||||||
|
|
||||||
public static List<String> getOpenPgpProviderPackages(Context context) {
|
public static List<String> getOpenPgpProviderPackages(Context context) {
|
||||||
ArrayList<String> result = new ArrayList<>();
|
ArrayList<String> result = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -49,4 +55,8 @@ public class OpenPgpProviderUtil {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isBlacklisted(String packageName) {
|
||||||
|
return PROVIDER_BLACKLIST.contains(packageName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue