/** * Share the provided photo through other android apps * * <p>Will share the image as a image/jpg content type and include title and description as extra * * @param slideshowPhoto */ public void actionSharePhoto(SlideshowPhoto slideshowPhoto) { Log.i(LOG_PREFIX, "Attempting to share photo " + slideshowPhoto); // TODO: Refactor this code.. rather ugly due to some GoogleTV related hacks if (slideshowPhoto != null) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); // we assume the type is image/jpg shareIntent.setType("image/jpg"); String sharedText = slideshowPhoto.getTitle() + ": " + slideshowPhoto.getDescription() + "\n\n" + getResources().getString(R.string.share_footer); // if we have a cached file, add the stream and the sharedText // if not, add the url and the sharedText if (slideshowPhoto.isCacheExisting(rootFileDirectory)) { String path = "file://" + rootFileDirectory.getAbsolutePath() + "/" + slideshowPhoto.getFileName(); Log.i(LOG_PREFIX, "Attempting to pass stream url " + path); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path)); shareIntent.putExtra(Intent.EXTRA_TEXT, sharedText); } else { shareIntent.putExtra( Intent.EXTRA_TEXT, slideshowPhoto.getLargePhoto() + "\n\n" + sharedText); } shareIntent.putExtra(Intent.EXTRA_SUBJECT, slideshowPhoto.getTitle()); // Start the actual sharing activity try { List<ResolveInfo> relevantActivities = getPackageManager().queryIntentActivities(shareIntent, 0); if (AndroidUtils.isGoogleTV(getApplicationContext()) || relevantActivities == null || relevantActivities.size() == 0) { Log.i( LOG_PREFIX, "No activity found that can handle image/jpg. Performing simple text share"); Intent backupShareIntent = new Intent(); backupShareIntent.setAction(Intent.ACTION_SEND); backupShareIntent.setType("text/plain"); String backupSharedText = slideshowPhoto.getLargePhoto() + "\n\n" + sharedText; backupShareIntent.putExtra(Intent.EXTRA_TEXT, backupSharedText); startActivity(backupShareIntent); } else { startActivity(shareIntent); } } catch (ActivityNotFoundException e) { notifyUser("Unable to share current photo"); } } else { notifyUser("Unable to share current photo"); } }
public View getView(int position, View convertView, ViewGroup parent) { View slideshowView = convertView; if (position >= getCount()) { return null; } SlideshowPhoto slideshowPhoto = getItem(position); Log.d(LOG_PREFIX, position + " title:" + slideshowPhoto.getTitle()); boolean copyDrawableFromCachedView = false; View cachedView = null; Integer mapKey = new Integer(position); if (slideshowView == null) { // let's check the weak references for this View if (mapWeakRefViews.containsKey(mapKey)) { // we have a key, but the View may be garbage collected WeakReference<View> weakRefView = mapWeakRefViews.get(mapKey); cachedView = weakRefView.get(); if (cachedView == null) { // view was cached, but has been deleted. // it will be replaced later in this method, so don't bother deleting it from the // hashmap } else if (cachedView.getParent() != null) { // Log.i(LOG_PREFIX,position + " was cached, but had a parent. So close!"); copyDrawableFromCachedView = true; } else { Log.d(LOG_PREFIX, position + " returned through weak reference caching. Yeah!"); return cachedView; } } // if no cached value, create it from the resource definition LayoutInflater viewInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); slideshowView = viewInflater.inflate(R.layout.slideshow_item, null); } ImageView slideshowImageView = (ImageView) slideshowView.findViewById(R.id.slideshow_photo); slideshowImageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); slideshowImageView.setAdjustViewBounds(true); // make sure we do not exceed the opengl hardware accl max size slideshowImageView.setMaxHeight(2048); slideshowImageView.setMaxWidth(2048); // The preferred Gallery item background slideshowImageView.setBackgroundResource(mGalleryItemBackground); slideshowImageView.setBackgroundColor(Color.TRANSPARENT); slideshowImageView.setTag(LOADING_TAG); slideshowImageView.setImageResource(R.drawable.loading); // OLD METHOD // These lines of code are in a separate async task in order to not block the UI thread for // approx 300 ms // Drawable drawable = slideshowPhoto.getLargePhotoDrawable(rootPhotoFolder); // slideshowImageView.setImageDrawable(drawable); // new ReadPhotoFromFileTask(slideshowImageView,slideshowPhoto,rootPhotoFolder).execute(); // This section applies if we have a cached view, but it cannot be reuse directly since it has // a parent // let us copy the drawable boolean slideShowImageDrawableMissing = true; if (copyDrawableFromCachedView == true && cachedView != null) { // reusing the drawable from a cached view ImageView cachedSlideshowImageView = (ImageView) cachedView.findViewById(R.id.slideshow_photo); String cachedTag = (String) cachedSlideshowImageView.getTag(); if (cachedSlideshowImageView != null && cachedTag != null && cachedTag.equals(LOADED_TAG)) { slideshowImageView.setImageDrawable(cachedSlideshowImageView.getDrawable()); slideShowImageDrawableMissing = false; Log.d(LOG_PREFIX, position + " Cached photo drawable reused. Yeah!"); } else { Log.i( LOG_PREFIX, position + " Cached Photo is not loaded yet, so could not use cache. Doh!"); } } if (slideShowImageDrawableMissing) { // NEW METHOD // Add to a last-in/first-out queue AsyncQueueableObject queueablePhotoObject = null; queueablePhotoObject = new QueueablePhotoObject( slideshowPhoto, slideshowView, rootPhotoFolder, LOADED_TAG, screenWidthPx, screenHeightPx); asyncReadQueue.add(queueablePhotoObject); Log.d(LOG_PREFIX, position + " is being loaded in a background async task"); } TextView slideshowTitle = (TextView) slideshowView.findViewById(R.id.slideshow_title); slideshowTitle.setText(slideshowPhoto.getTitle()); TextView slideshowDescription = (TextView) slideshowView.findViewById(R.id.slideshow_description); slideshowDescription.setText(slideshowPhoto.getDescription()); // add scrolling to TextView // slideshowDescription.setMovementMethod(new ScrollingMovementMethod()); // find out if we should hide the text descriptions boolean isEmptyTitle = false; if (slideshowPhoto.getTitle() == null || "".equals(slideshowPhoto.getTitle().trim())) { isEmptyTitle = true; } if (doDisplayPhotoTitle == false || slideshowPhoto.isPromotion() || isEmptyTitle) { slideshowTitle.setVisibility(View.INVISIBLE); slideshowDescription.setVisibility(View.INVISIBLE); View layout = slideshowView.findViewById(R.id.slideshow_text_background); layout.setVisibility(View.INVISIBLE); } // lastView = slideshowView; // lastFileName=slideshowPhoto.getFileName(); // add the view to our weak reference caching WeakReference<View> weakRefView = new WeakReference<View>(slideshowView); mapWeakRefViews.put(mapKey, weakRefView); // DEBUG String classLayoutParam = null; Object objectLayoutParam = slideshowView.getLayoutParams(); if (objectLayoutParam != null) { classLayoutParam = objectLayoutParam.getClass().getName(); } Log.d(LOG_PREFIX, "Layout params class=" + classLayoutParam + " value=" + objectLayoutParam); return slideshowView; }