本文整理汇总了Java中org.chromium.chrome.browser.download.ui.DownloadFilter类的典型用法代码示例。如果您正苦于以下问题:Java DownloadFilter类的具体用法?Java DownloadFilter怎么用?Java DownloadFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DownloadFilter类属于org.chromium.chrome.browser.download.ui包,在下文中一共展示了DownloadFilter类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIconResId
import org.chromium.chrome.browser.download.ui.DownloadFilter; //导入依赖的package包/类
/**
* Return an icon for a given file type.
* @param fileType Type of the file as returned by DownloadFilter.
* @param iconSize Size of the returned icon.
* @return Resource ID of the corresponding icon.
*/
public static int getIconResId(int fileType, @IconSize int iconSize) {
switch (fileType) {
case DownloadFilter.FILTER_PAGE:
return iconSize == ICON_SIZE_24_DP ? R.drawable.ic_drive_site_white_24dp
: R.drawable.ic_drive_site_white_36dp;
case DownloadFilter.FILTER_VIDEO:
return iconSize == ICON_SIZE_24_DP ? R.drawable.ic_play_arrow_white_24dp
: R.drawable.ic_play_arrow_white_36dp;
case DownloadFilter.FILTER_AUDIO:
return iconSize == ICON_SIZE_24_DP ? R.drawable.ic_music_note_white_24dp
: R.drawable.ic_music_note_white_36dp;
case DownloadFilter.FILTER_IMAGE:
return iconSize == ICON_SIZE_24_DP ? R.drawable.ic_image_white_24dp
: R.drawable.ic_image_white_36dp;
case DownloadFilter.FILTER_DOCUMENT:
return iconSize == ICON_SIZE_24_DP ? R.drawable.ic_drive_text_white_24dp
: R.drawable.ic_drive_text_white_36dp;
default:
return iconSize == ICON_SIZE_24_DP ? R.drawable.ic_drive_file_white_24dp
: R.drawable.ic_drive_text_white_36dp;
}
}
示例2: recordShareHistograms
import org.chromium.chrome.browser.download.ui.DownloadFilter; //导入依赖的package包/类
private static void recordShareHistograms(int count, int filterType) {
RecordHistogram.recordEnumeratedHistogram("Android.DownloadManager.Share.FileTypes",
filterType, DownloadFilter.FILTER_BOUNDARY);
RecordHistogram.recordLinearCountHistogram("Android.DownloadManager.Share.Count",
count, 1, 20, 20);
}
示例3: onFilterChanged
import org.chromium.chrome.browser.download.ui.DownloadFilter; //导入依赖的package包/类
@Override
public void onFilterChanged(int filter) {
String url = DownloadFilter.getUrlForFilter(filter);
if (mBackStack.isEmpty() || !mBackStack.peek().equals(url)) {
mBackStack.push(url);
}
}
示例4: getMediaViewerIntentForDownloadItem
import org.chromium.chrome.browser.download.ui.DownloadFilter; //导入依赖的package包/类
/**
* Creates an Intent that allows viewing the given file in an internal media viewer.
* @param fileUri URI pointing at the file, ideally in file:// form.
* @param shareUri URI pointing at the file, ideally in content:// form.
* @param mimeType MIME type of the file.
* @return Intent that can be fired to open the file.
*/
public static Intent getMediaViewerIntentForDownloadItem(
Uri fileUri, Uri shareUri, String mimeType) {
Context context = ContextUtils.getApplicationContext();
Intent viewIntent = createViewIntentForDownloadItem(fileUri, mimeType);
Bitmap closeIcon = BitmapFactory.decodeResource(
context.getResources(), R.drawable.ic_arrow_back_white_24dp);
Bitmap shareIcon = BitmapFactory.decodeResource(
context.getResources(), R.drawable.ic_share_white_24dp);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(Color.BLACK);
builder.setCloseButtonIcon(closeIcon);
builder.setShowTitle(true);
// Create a PendingIntent that can be used to view the file externally.
// TODO(dfalcantara): Check if this is problematic in multi-window mode, where two
// different viewers could be visible at the same time.
Intent chooserIntent = Intent.createChooser(viewIntent, null);
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String openWithStr = context.getString(R.string.download_manager_open_with);
PendingIntent pendingViewIntent = PendingIntent.getActivity(
context, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT);
builder.addMenuItem(openWithStr, pendingViewIntent);
// Create a PendingIntent that shares the file with external apps.
PendingIntent pendingShareIntent = PendingIntent.getActivity(
context, 0, createShareIntent(shareUri, mimeType), 0);
builder.setActionButton(
shareIcon, context.getString(R.string.share), pendingShareIntent, true);
// The color of the media viewer is dependent on the file type.
int backgroundRes;
if (DownloadFilter.fromMimeType(mimeType) == DownloadFilter.FILTER_IMAGE) {
backgroundRes = R.color.image_viewer_bg;
} else {
backgroundRes = R.color.media_viewer_bg;
}
int mediaColor = ApiCompatibilityUtils.getColor(context.getResources(), backgroundRes);
// Build up the Intent further.
Intent intent = builder.build().intent;
intent.setPackage(context.getPackageName());
intent.setData(fileUri);
intent.putExtra(CustomTabIntentDataProvider.EXTRA_IS_MEDIA_VIEWER, true);
intent.putExtra(
CustomTabIntentDataProvider.EXTRA_INITIAL_BACKGROUND_COLOR, mediaColor);
intent.putExtra(
CustomTabsIntent.EXTRA_TOOLBAR_COLOR, mediaColor);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
IntentHandler.addTrustedIntentExtras(intent, context);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(context, CustomTabActivity.class);
return intent;
}
示例5: getMediaViewerIntentForDownloadItem
import org.chromium.chrome.browser.download.ui.DownloadFilter; //导入依赖的package包/类
/**
* Creates an Intent that allows viewing the given file in an internal media viewer.
* @param fileUri URI pointing at the file, ideally in file:// form. Used only when
* the media viewer is trying to locate the file on disk.
* @param contentUri content:// URI pointing at the file.
* @param mimeType MIME type of the file.
* @return Intent that can be fired to open the file.
*/
public static Intent getMediaViewerIntentForDownloadItem(
Uri fileUri, Uri contentUri, String mimeType) {
Context context = ContextUtils.getApplicationContext();
Intent viewIntent = createViewIntentForDownloadItem(contentUri, mimeType);
Bitmap closeIcon = BitmapFactory.decodeResource(
context.getResources(), R.drawable.ic_arrow_back_white_24dp);
Bitmap shareIcon = BitmapFactory.decodeResource(
context.getResources(), R.drawable.ic_share_white_24dp);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(Color.BLACK);
builder.setCloseButtonIcon(closeIcon);
builder.setShowTitle(true);
// Create a PendingIntent that can be used to view the file externally.
// TODO(dfalcantara): Check if this is problematic in multi-window mode, where two
// different viewers could be visible at the same time.
Intent chooserIntent = Intent.createChooser(viewIntent, null);
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String openWithStr = context.getString(R.string.download_manager_open_with);
PendingIntent pendingViewIntent = PendingIntent.getActivity(
context, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT);
builder.addMenuItem(openWithStr, pendingViewIntent);
// Create a PendingIntent that shares the file with external apps.
PendingIntent pendingShareIntent = PendingIntent.getActivity(
context, 0, createShareIntent(contentUri, mimeType), 0);
builder.setActionButton(
shareIcon, context.getString(R.string.share), pendingShareIntent, true);
// The color of the media viewer is dependent on the file type.
int backgroundRes;
if (DownloadFilter.fromMimeType(mimeType) == DownloadFilter.FILTER_IMAGE) {
backgroundRes = R.color.image_viewer_bg;
} else {
backgroundRes = R.color.media_viewer_bg;
}
int mediaColor = ApiCompatibilityUtils.getColor(context.getResources(), backgroundRes);
// Build up the Intent further.
Intent intent = builder.build().intent;
intent.setPackage(context.getPackageName());
intent.setData(contentUri);
intent.putExtra(CustomTabIntentDataProvider.EXTRA_IS_MEDIA_VIEWER, true);
intent.putExtra(CustomTabIntentDataProvider.EXTRA_MEDIA_VIEWER_URL, fileUri.toString());
intent.putExtra(CustomTabIntentDataProvider.EXTRA_ENABLE_EMBEDDED_MEDIA_EXPERIENCE, true);
intent.putExtra(
CustomTabIntentDataProvider.EXTRA_INITIAL_BACKGROUND_COLOR, mediaColor);
intent.putExtra(
CustomTabsIntent.EXTRA_TOOLBAR_COLOR, mediaColor);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
IntentHandler.addTrustedIntentExtras(intent);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(context, ChromeLauncherActivity.class);
return intent;
}