Search in sources :

Example 51 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project orgzly-android by orgzly.

the class TemplateChooserActivity method onBookClicked.

@Override
public void onBookClicked(long bookId) {
    if (action == null) {
        return;
    }
    if (!action.equals(Intent.ACTION_CREATE_SHORTCUT)) {
        return;
    }
    Book book = dataRepository.getBook(bookId);
    if (book == null) {
        Toast.makeText(this, R.string.book_does_not_exist_anymore, Toast.LENGTH_SHORT).show();
        setResult(RESULT_CANCELED);
        finish();
        return;
    }
    String id = "template-" + bookId;
    String name = book.getName();
    String title = BookUtils.getFragmentTitleForBook(book);
    Intent launchIntent = ShareActivity.createNewNoteInNotebookIntent(this, bookId);
    IconCompat icon = createIcon();
    ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(this, id).setShortLabel(name).setLongLabel(title).setIcon(icon).setIntent(launchIntent).build();
    setResult(RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(this, shortcut));
    finish();
}
Also used : Book(com.orgzly.android.db.entity.Book) IconCompat(androidx.core.graphics.drawable.IconCompat) Intent(android.content.Intent) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat)

Example 52 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project orgzly-android by orgzly.

the class BookChooserActivity method onBookClicked.

@Override
public void onBookClicked(long bookId) {
    if (BuildConfig.LOG_DEBUG)
        LogUtils.d(TAG, bookId, action);
    if (action != null && action.equals(Intent.ACTION_CREATE_SHORTCUT)) {
        // Get Book by its ID
        Book book = dataRepository.getBook(bookId);
        if (book == null) {
            Toast.makeText(this, R.string.book_does_not_exist_anymore, Toast.LENGTH_SHORT).show();
            setResult(RESULT_CANCELED);
            finish();
            return;
        }
        String id = "notebook-" + bookId;
        String name = book.getName();
        String title = BookUtils.getFragmentTitleForBook(book);
        Intent launchIntent = createLaunchIntent(book);
        IconCompat icon = createIcon();
        ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(this, id).setShortLabel(name).setLongLabel(title).setIcon(icon).setIntent(launchIntent).build();
        setResult(RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(this, shortcut));
        finish();
    }
}
Also used : Book(com.orgzly.android.db.entity.Book) IconCompat(androidx.core.graphics.drawable.IconCompat) Intent(android.content.Intent) AppIntent(com.orgzly.android.AppIntent) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat)

Example 53 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ContextualCardFeatureProviderImplTest method buildSlice.

private Slice buildSlice(Uri sliceUri, String packageName) {
    final Bundle args = new Bundle();
    args.putString(AppInfoBase.ARG_PACKAGE_NAME, packageName);
    final Intent intent = new Intent("action");
    intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
    final PendingIntent pendingIntent = spy(PendingIntent.getActivity(mContext, 0, /* requestCode */
    intent, 0));
    doReturn(intent).when(pendingIntent).getIntent();
    final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.empty_icon);
    final SliceAction action = SliceAction.createDeeplink(pendingIntent, icon, ListBuilder.SMALL_IMAGE, "title");
    return new ListBuilder(mContext, sliceUri, ListBuilder.INFINITY).addRow(new ListBuilder.RowBuilder().addEndItem(icon, ListBuilder.ICON_IMAGE).setTitle("title").setPrimaryAction(action)).build();
}
Also used : Bundle(android.os.Bundle) IconCompat(androidx.core.graphics.drawable.IconCompat) SliceAction(androidx.slice.builders.SliceAction) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ListBuilder(androidx.slice.builders.ListBuilder) PendingIntent(android.app.PendingIntent)

Example 54 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DataUsageSliceTest method getSlice_hasSim_shouldBeCorrectSliceContent.

@Test
public void getSlice_hasSim_shouldBeCorrectSliceContent() {
    ShadowDataUsageUtils.HAS_SIM = true;
    doReturn(DATA_USAGE_TITLE).when(mDataUsageSlice).getDataUsageText(any());
    doReturn(DATA_USAGE_SUMMARY).when(mDataUsageSlice).getCycleTime(any());
    final Slice slice = mDataUsageSlice.getSlice();
    final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
    assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.data_usage_summary_title));
    final SliceAction primaryAction = metadata.getPrimaryAction();
    final IconCompat expectedIcon = IconCompat.createWithResource(mContext, R.drawable.ic_settings_data_usage);
    assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedIcon.toString());
}
Also used : Slice(androidx.slice.Slice) IconCompat(androidx.core.graphics.drawable.IconCompat) SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) Test(org.junit.Test)

Example 55 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class StorageSliceTest method getSlice_shouldBeCorrectSliceContent.

@Test
public void getSlice_shouldBeCorrectSliceContent() {
    final PrivateStorageInfo info = new PrivateStorageInfo(100L, 600L);
    doReturn(info).when(mStorageSlice).getPrivateStorageInfo();
    doReturn(USED_BYTES_TEXT).when(mStorageSlice).getStorageUsedText(any());
    doReturn(SUMMARY_TEXT).when(mStorageSlice).getStorageSummaryText(any());
    final Slice slice = mStorageSlice.getSlice();
    final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
    assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.storage_label));
    final SliceAction primaryAction = metadata.getPrimaryAction();
    final IconCompat expectedIcon = IconCompat.createWithResource(mContext, R.drawable.ic_homepage_storage);
    assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedIcon.toString());
}
Also used : PrivateStorageInfo(com.android.settingslib.deviceinfo.PrivateStorageInfo) Slice(androidx.slice.Slice) IconCompat(androidx.core.graphics.drawable.IconCompat) SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) Test(org.junit.Test)

Aggregations

IconCompat (androidx.core.graphics.drawable.IconCompat)103 ListBuilder (androidx.slice.builders.ListBuilder)55 PendingIntent (android.app.PendingIntent)42 SliceAction (androidx.slice.builders.SliceAction)39 Test (org.junit.Test)25 ColorInt (android.annotation.ColorInt)22 RowBuilder (androidx.slice.builders.ListBuilder.RowBuilder)21 SliceMetadata (androidx.slice.SliceMetadata)18 SliceAction (androidx.slice.core.SliceAction)18 Intent (android.content.Intent)15 Slice (androidx.slice.Slice)14 Drawable (android.graphics.drawable.Drawable)7 ShortcutInfoCompat (androidx.core.content.pm.ShortcutInfoCompat)7 SliceItem (androidx.slice.SliceItem)6 ColorDrawable (android.graphics.drawable.ColorDrawable)5 Bitmap (android.graphics.Bitmap)4 SpannableString (android.text.SpannableString)4 PrivateStorageInfo (com.android.settingslib.deviceinfo.PrivateStorageInfo)4 Resources (android.content.res.Resources)3 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)3