@Override public void onBindViewHolder(PhotoHolder photoHolder, int position) { GalleryItem galleryItem = mGalleryItems.get(position); Drawable placeholder = getResources().getDrawable(R.drawable.bill_up_close); photoHolder.bindDrawable(placeholder); mThumbnailDownloader.queueThumbnail(photoHolder, galleryItem.getUrl()); }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = getActivity().getLayoutInflater().inflate(R.layout.gallery_item, parent, false); } ImageView imageView = (ImageView) convertView.findViewById(R.id.gallery_item_imageView); imageView.setImageResource(R.drawable.brian_up_close); GalleryItem galleryItem = getItem(position); mThumbnailThread.queueThumbnail(imageView, galleryItem.getUrl()); return convertView; }
@Override public void onClick(View v) { Intent intent = new Intent(getActivity(), DetailView.class); intent.putExtra(DETAIL_VIEW_ID, mGalleryItem.getUrl()); // startActivityForResult(intent, 0); startActivity(intent); // Toast.makeText(getActivity(), mGalleryItem.getUrl(), Toast.LENGTH_SHORT).show(); }
void parseItems(ArrayList<GalleryItem> items, XmlPullParser parser) throws XmlPullParserException, IOException { int eventType = parser.next(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG && XML_PHOTO.equals(parser.getName())) { String id = parser.getAttributeValue(null, "id"); String caption = parser.getAttributeValue(null, "title"); String smallUrl = parser.getAttributeValue(null, EXTRA_SMALL_URL); String owner = parser.getAttributeValue(null, "owner"); GalleryItem item = new GalleryItem(); item.setmId(id); item.setCaption(caption); item.setUrl(smallUrl); item.setOwner(owner); items.add(item); } eventType = parser.next(); } }
private void parseItemsByGson(List<GalleryItem> items, String jsonString) { JsonObject jsonBody = new JsonParser().parse(jsonString).getAsJsonObject(); JsonObject photosJsonObject = jsonBody.get("photos").getAsJsonObject(); JsonArray photosJsonArray = photosJsonObject.get("photo").getAsJsonArray(); for (int i = 0; i < photosJsonArray.size(); i++) { JsonObject photoJsonObject = photosJsonArray.get(i).getAsJsonObject(); GalleryItem item = new GalleryItem(); item.setId(photoJsonObject.get("id").getAsString()); item.setCaption(photoJsonObject.get("title").getAsString()); if (!photoJsonObject.has("url_s")) { continue; } item.setUrl(photoJsonObject.get("url_s").getAsString()); item.setOwner(photoJsonObject.get("owner").getAsString()); items.add(item); } }
private void parseItems(List<GalleryItem> items, String jsonString) throws IOException, JSONException { JSONObject jsonBody = new JSONObject(jsonString); JSONObject photosJsonObject = jsonBody.getJSONObject("photos"); JSONArray photosJsonArray = photosJsonObject.getJSONArray("photo"); for (int i = 0; i < photosJsonArray.length(); i++) { JSONObject photoJsonObject = photosJsonArray.getJSONObject(i); GalleryItem item = new GalleryItem(); item.setId(photoJsonObject.getString("id")); item.setCaption(photoJsonObject.getString("title")); if (!photoJsonObject.has("url_s")) { continue; } item.setUrl(photoJsonObject.getString("url_s")); items.add(item); } }
public void bindGalleryItem(GalleryItem galleryItem) { mGalleryItem = galleryItem; // Picasso.with(getActivity()) // .load(mGalleryItem.getUrl()) // .placeholder(R.drawable.nice) // .into(mItemImageView); Glide.with(getActivity()) .load(mGalleryItem.getUrl()) // .diskCacheStrategy(DiskCacheStrategy.ALL) .placeholder(R.drawable.nice) .into(mItemImageView); /* Bitmap img = Picasso.with(this).load("http://").get(); int w = img.getWidth(); int h = img.getHeight(); */ }
@Override public void onClick(View v) { Intent i = PhotoPageActivity.newIntent(getActivity(), mGalleryItem.getPhotoPageUri()); startActivity(i); }
/* * (non-Javadoc) * * @see * org.eclipse.nebula.widgets.gallery.AbstractGalleryItemRenderer#draw(org * .eclipse.swt.graphics.GC, org.eclipse.nebula.widgets.gallery.GalleryItem, * int, int, int, int, int) */ public void draw(GC gc, GalleryItem item, int index, int x, int y, int width, int height) { Image itemImage = item.getImage(); Color itemBackgroundColor = item.getBackground(); Color itemForegroundColor = item.getForeground(); int useableHeight = height; int imageWidth = 0; int imageHeight = 0; int xShift = 0; int yShift = 0; Point size = null; if (itemImage != null) { Rectangle itemImageBounds = itemImage.getBounds(); imageWidth = itemImageBounds.width; imageHeight = itemImageBounds.height; size = RendererHelper.getBestSize( imageWidth, imageHeight, useableHeight - 4 - this.dropShadowsSize, useableHeight - 4 - this.dropShadowsSize); xShift = ((useableHeight - size.x) >> 1) + 2; yShift = (useableHeight - size.y) >> 1; if (dropShadows) { Color c = null; for (int i = this.dropShadowsSize - 1; i >= 0; i--) { c = dropShadowsColors.get(i); gc.setForeground(c); gc.drawLine( x + useableHeight + i - xShift - 1, y + dropShadowsSize + yShift, x + useableHeight + i - xShift - 1, y + useableHeight + i - yShift); gc.drawLine( x + xShift + dropShadowsSize, y + useableHeight + i - yShift - 1, x + useableHeight + i - xShift, y - 1 + useableHeight + i - yShift); } } } // Draw selection background (rounded rectangles) if (selected || RendererHelper.isColorsEquals(itemBackgroundColor, gallery.getBackground())) { if (selected) { gc.setBackground(selectionBackgroundColor); gc.setForeground(selectionBackgroundColor); } else if (itemBackgroundColor != null) { gc.setBackground(itemBackgroundColor); } if (showRoundedSelectionCorners) gc.fillRoundRectangle(x, y, width, useableHeight, selectionRadius, selectionRadius); else gc.fillRectangle(x, y, width, useableHeight); } if (itemImage != null && size != null) { if (size.x > 0 && size.y > 0) { gc.drawImage( itemImage, 0, 0, imageWidth, imageHeight, x + xShift, y + yShift, size.x, size.y); drawAllOverlays(gc, item, x, y, size, xShift, yShift); } } if (item.getText() != null && !EMPTY_STRING.equals(item.getText()) && showLabels) { // Calculate font height (text and description) gc.setFont(textFont); String text = RendererHelper.createLabel(item.getText(), gc, width - useableHeight - 10); int textFontHeight = gc.getFontMetrics().getHeight(); String description = null; int descriptionFontHeight = 0; if (item.getText(1) != null && !EMPTY_STRING.equals(item.getText(1))) { gc.setFont(descriptionFont); description = RendererHelper.createLabel(item.getText(1), gc, width - useableHeight - 10); descriptionFontHeight = gc.getFontMetrics().getHeight(); } boolean displayText = false; boolean displayDescription = false; int remainingHeight = height - 2 - textFontHeight; if (remainingHeight > 0) displayText = true; remainingHeight -= descriptionFontHeight; if (remainingHeight > 0) displayDescription = true; // Background color gc.setBackground(selected ? selectionBackgroundColor : backgroundColor); // Draw text if (displayText) { int transY = (height - textFontHeight - 2); if (displayDescription) transY -= descriptionFontHeight; transY = transY >> 1; if (selected) { gc.setForeground(this.selectionForegroundColor); } else if (itemForegroundColor != null) { gc.setForeground(itemForegroundColor); } else { gc.setForeground(this.foregroundColor); } gc.setFont(textFont); gc.drawText(text, x + useableHeight + 5, y + transY, true); } // Draw description if (description != null && displayDescription) { gc.setForeground(this.descriptionColor); gc.setFont(descriptionFont); gc.drawText( description, x + useableHeight + 5, y + ((height - descriptionFontHeight - textFontHeight - 2) >> 1) + textFontHeight + 1, true); } } }