1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.camera.util; 17 18 import android.content.ComponentName; 19 import android.content.Context; 20 import android.content.Intent; 21 import android.content.pm.PackageManager; 22 import android.graphics.drawable.Drawable; 23 import android.net.Uri; 24 25 import com.android.camera2.R; 26 27 /** 28 * A helper class to provide Gallery related info. 29 */ 30 public class GalleryHelper { 31 private static final String GALLERY_PACKAGE_NAME = "com.android.gallery3d"; 32 private static final String GALLERY_ACTIVITY_CLASS = 33 "com.android.gallery3d.app.GalleryActivity"; 34 private static final int GALLERY_APP_NAME_ID = R.string.gallery_app_name; 35 setGalleryIntentClassName(Intent intent)36 public static void setGalleryIntentClassName(Intent intent) { 37 intent.setClassName(GALLERY_PACKAGE_NAME, GALLERY_ACTIVITY_CLASS); 38 } 39 getGalleryIcon(Context context, Intent galleryIntent)40 public static Drawable getGalleryIcon(Context context, Intent galleryIntent) { 41 if (galleryIntent != null) { 42 try { 43 return context.getPackageManager().getActivityIcon(galleryIntent); 44 } catch (PackageManager.NameNotFoundException e) { 45 // Do nothing. 46 } 47 } 48 return null; 49 } 50 getGalleryAppName(Context context, Intent galleryIntent)51 public static CharSequence getGalleryAppName(Context context, Intent galleryIntent) { 52 ComponentName componentName = galleryIntent.getComponent(); 53 if (componentName != null 54 && GALLERY_PACKAGE_NAME.equals(componentName.getPackageName()) 55 && GALLERY_ACTIVITY_CLASS.equals(componentName.getClassName())) { 56 return context.getResources().getString(GALLERY_APP_NAME_ID); 57 } else { 58 return null; 59 } 60 } 61 setContentUri(Intent intent, Uri uri)62 public static void setContentUri(Intent intent, Uri uri) { 63 // Do nothing. 64 } 65 } 66