|
|
|
@ -20,6 +20,7 @@ package eu.faircode.email;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
@ -37,6 +38,7 @@ import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
|
import android.graphics.drawable.Icon;
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.os.ParcelFileDescriptor;
|
|
|
|
@ -781,7 +783,15 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|
|
|
|
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
new SimpleTask<List<ShortcutInfo>>() {
|
|
|
|
|
@Override
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.N_MR1)
|
|
|
|
|
protected List<ShortcutInfo> onExecute(Context context, Bundle args) {
|
|
|
|
|
ShortcutManager sm = (ShortcutManager) getSystemService(Context.SHORTCUT_SERVICE);
|
|
|
|
|
int count = sm.getMaxShortcutCountPerActivity() - sm.getManifestShortcuts().size();
|
|
|
|
|
Log.i("Shortcuts count=" + count +
|
|
|
|
|
" app=" + sm.getMaxShortcutCountPerActivity() +
|
|
|
|
|
" manifest=" + sm.getManifestShortcuts().size());
|
|
|
|
|
|
|
|
|
|
List<ShortcutInfo> shortcuts = new ArrayList<>();
|
|
|
|
|
|
|
|
|
@ -803,7 +813,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|
|
|
|
ContactsContract.Contacts.STARRED + " DESC" +
|
|
|
|
|
", " + ContactsContract.Contacts.TIMES_CONTACTED + " DESC" +
|
|
|
|
|
", " + ContactsContract.Contacts.LAST_TIME_CONTACTED + " DESC")) {
|
|
|
|
|
while (cursor != null && cursor.moveToNext())
|
|
|
|
|
while (cursor != null && cursor.moveToNext() && shortcuts.size() < count)
|
|
|
|
|
try {
|
|
|
|
|
long id = cursor.getLong(cursor.getColumnIndex(ContactsContract.RawContacts._ID));
|
|
|
|
|
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
|
|
|
|
@ -825,32 +835,43 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|
|
|
|
getContentResolver(), uri);
|
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeStream(is);
|
|
|
|
|
Icon icon = (bitmap == null
|
|
|
|
|
? Icon.createWithResource(this, R.drawable.ic_shortcut_email)
|
|
|
|
|
? Icon.createWithResource(context, R.drawable.ic_shortcut_email)
|
|
|
|
|
: Icon.createWithBitmap(bitmap));
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(this, ActivityCompose.class);
|
|
|
|
|
Intent intent = new Intent(context, ActivityCompose.class);
|
|
|
|
|
intent.setAction(Intent.ACTION_SEND);
|
|
|
|
|
intent.setData(Uri.parse("mailto:" + email));
|
|
|
|
|
|
|
|
|
|
shortcuts.add(
|
|
|
|
|
new ShortcutInfo.Builder(this, Long.toString(id))
|
|
|
|
|
new ShortcutInfo.Builder(context, Long.toString(id))
|
|
|
|
|
.setIcon(icon)
|
|
|
|
|
.setRank(shortcuts.size() + 1)
|
|
|
|
|
.setShortLabel(name)
|
|
|
|
|
.setIntent(intent)
|
|
|
|
|
.build());
|
|
|
|
|
|
|
|
|
|
if (sm.getManifestShortcuts().size() + shortcuts.size() >= sm.getMaxShortcutCountPerActivity())
|
|
|
|
|
break;
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return shortcuts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.N_MR1)
|
|
|
|
|
protected void onExecuted(Bundle args, List<ShortcutInfo> shortcuts) {
|
|
|
|
|
ShortcutManager sm = (ShortcutManager) getSystemService(Context.SHORTCUT_SERVICE);
|
|
|
|
|
sm.setDynamicShortcuts(shortcuts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
Helper.unexpectedError(ActivityView.this, ActivityView.this, ex);
|
|
|
|
|
}
|
|
|
|
|
}.execute(this, this, new Bundle(), "shortcuts:get");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Intent getIntentInvite() {
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.append(getString(R.string.title_try)).append("\n\n");
|
|
|
|
|