show trust id activity button only if available
This commit is contained in:
@@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui.adapter;
|
|||||||
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
@@ -26,6 +27,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@@ -74,26 +76,43 @@ public class TrustIdsAdapter extends CursorAdapter {
|
|||||||
Drawable drawable = getDrawableForPackageName(packageName);
|
Drawable drawable = getDrawableForPackageName(packageName);
|
||||||
vTrustId.setText(trustId);
|
vTrustId.setText(trustId);
|
||||||
vAppIcon.setImageDrawable(drawable);
|
vAppIcon.setImageDrawable(drawable);
|
||||||
vActionIcon.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
if (isTrustIdActivityAvailable(packageName, trustId, context)) {
|
||||||
public void onClick(View view) {
|
vActionIcon.setVisibility(View.VISIBLE);
|
||||||
launchTrustIdActivity(packageName, trustId, context);
|
vActionIcon.setOnClickListener(new OnClickListener() {
|
||||||
}
|
@Override
|
||||||
});
|
public void onClick(View view) {
|
||||||
|
launchTrustIdActivity(packageName, trustId, context);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
vActionIcon.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launchTrustIdActivity(String packageName, String trustId, Context context) {
|
private void launchTrustIdActivity(String packageName, String trustId, Context context) {
|
||||||
try {
|
try {
|
||||||
Intent intent = new Intent();
|
Intent intent = createTrustIdActivityIntent(packageName, trustId);
|
||||||
intent.setAction(packageName + ".TRUST_ID_ACTION");
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
intent.putExtra(OpenPgpApi.EXTRA_TRUST_IDENTITY, trustId);
|
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
// can't help it
|
// can't help it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Intent createTrustIdActivityIntent(String packageName, String trustId) {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setAction(packageName + ".TRUST_ID_ACTION");
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.putExtra(OpenPgpApi.EXTRA_TRUST_IDENTITY, trustId);
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTrustIdActivityAvailable(String packageName, String trustId, Context context) {
|
||||||
|
Intent intent = createTrustIdActivityIntent(packageName, trustId);
|
||||||
|
List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities(intent, 0);
|
||||||
|
return resolveInfos != null && !resolveInfos.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
private Drawable getDrawableForPackageName(String packageName) {
|
private Drawable getDrawableForPackageName(String packageName) {
|
||||||
if (appIconCache.containsKey(packageName)) {
|
if (appIconCache.containsKey(packageName)) {
|
||||||
return appIconCache.get(packageName);
|
return appIconCache.get(packageName);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="?attr/listPreferredItemHeight"
|
android:minHeight="?attr/listPreferredItemHeight"
|
||||||
|
|||||||
@@ -35,6 +35,8 @@
|
|||||||
android:id="@+id/trust_id_action"
|
android:id="@+id/trust_id_action"
|
||||||
android:background="?selectableItemBackground"
|
android:background="?selectableItemBackground"
|
||||||
android:src="@drawable/ic_chat_black_24dp"
|
android:src="@drawable/ic_chat_black_24dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user