use of uk.co.senab.bitmapcache.CacheableBitmapDrawable in project Talon-for-Twitter by klinker24.
the class ArrayListLoader method loadItem.
@Override
public CacheableBitmapDrawable loadItem(String url) {
CacheableBitmapDrawable wrapper = mCache.get(url);
if (wrapper == null) {
try {
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
InputStream is = new BufferedInputStream(conn.getInputStream());
Bitmap image = decodeSampledBitmapFromResourceMemOpt(is, 500, 500);
try {
is.close();
} catch (Exception e) {
}
try {
conn.disconnect();
} catch (Exception e) {
}
if (circleImages) {
image = ImageUtils.getCircle(image, context);
}
wrapper = mCache.put(url, image);
} catch (Exception e) {
}
}
return wrapper;
}
use of uk.co.senab.bitmapcache.CacheableBitmapDrawable in project Talon-for-Twitter by klinker24.
the class MultiplePicsGridAdapter method getView.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.picture, null);
AbsListView.LayoutParams params = new AbsListView.LayoutParams(gridWidth, gridWidth);
convertView.setLayoutParams(params);
ViewHolder holder = new ViewHolder();
holder.iv = (NetworkedCacheableImageView) convertView.findViewById(R.id.picture);
convertView.setTag(holder);
}
final ViewHolder holder = (ViewHolder) convertView.getTag();
holder.iv.loadImage(text.get(position), false, new NetworkedCacheableImageView.OnImageLoadedListener() {
@Override
public void onImageLoaded(CacheableBitmapDrawable result) {
holder.iv.setBackgroundDrawable(null);
}
});
holder.iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent viewImage = new Intent(context, PhotoPagerActivity.class);
viewImage.putExtra("url", pics);
viewImage.putExtra("start_page", position);
context.startActivity(viewImage);
}
});
return convertView;
}
use of uk.co.senab.bitmapcache.CacheableBitmapDrawable in project Talon-for-Twitter by klinker24.
the class WidgetViewsFactory method getCachedPic.
public Bitmap getCachedPic(String url) {
CacheableBitmapDrawable wrapper = mCache.get(url);
if (wrapper == null) {
try {
URL mUrl = new URL(url);
Bitmap image = BitmapFactory.decodeStream(mUrl.openConnection().getInputStream());
if (settings.roundContactImages) {
image = ImageUtils.getCircle(image, mContext);
}
wrapper = mCache.put(url, image);
} catch (Exception e) {
}
}
return wrapper.getBitmap();
}
use of uk.co.senab.bitmapcache.CacheableBitmapDrawable in project Talon-for-Twitter by klinker24.
the class TalonPullNotificationService method downloadImages.
public void downloadImages(Status status) {
String profilePic = status.getUser().getBiggerProfileImageURL();
String imageUrl = TweetLinkUtils.getLinksInStatus(status)[1];
CacheableBitmapDrawable wrapper = null;
try {
wrapper = mCache.get(profilePic);
} catch (OutOfMemoryError e) {
}
if (wrapper == null) {
try {
HttpURLConnection conn = (HttpURLConnection) new URL(profilePic).openConnection();
InputStream is = new BufferedInputStream(conn.getInputStream());
Bitmap image = decodeSampledBitmapFromResourceMemOpt(is, 500, 500);
try {
is.close();
} catch (Exception e) {
}
try {
conn.disconnect();
} catch (Exception e) {
}
if (settings.roundContactImages) {
image = ImageUtils.getCircle(image, this);
}
mCache.put(profilePic, image);
} catch (Throwable e) {
}
}
if (!imageUrl.equals("")) {
try {
wrapper = mCache.get(imageUrl);
} catch (OutOfMemoryError e) {
wrapper = null;
}
if (wrapper == null) {
try {
if (!imageUrl.contains(" ")) {
HttpURLConnection conn = (HttpURLConnection) new URL(imageUrl).openConnection();
InputStream is = new BufferedInputStream(conn.getInputStream());
Bitmap image = decodeSampledBitmapFromResourceMemOpt(is, 1000, 1000);
try {
is.close();
} catch (Exception e) {
}
try {
conn.disconnect();
} catch (Exception e) {
}
mCache.put(imageUrl, image);
} else {
String[] pics = imageUrl.split(" ");
Bitmap[] bitmaps = new Bitmap[pics.length];
// need to download all of them, then combine them
for (int i = 0; i < pics.length; i++) {
String s = pics[i];
// The bitmap isn't cached so download from the web
HttpURLConnection conn = (HttpURLConnection) new URL(s).openConnection();
InputStream is = new BufferedInputStream(conn.getInputStream());
Bitmap b = decodeSampledBitmapFromResourceMemOpt(is, 1000, 1000);
try {
is.close();
} catch (Exception e) {
}
try {
conn.disconnect();
} catch (Exception e) {
}
// Add to cache
try {
mCache.put(s, b);
// throw it into our bitmap array for later
bitmaps[i] = b;
} catch (Exception e) {
}
}
// now that we have all of them, we need to put them together
Bitmap combined = ImageUtils.combineBitmaps(this, bitmaps);
try {
mCache.put(imageUrl, combined);
} catch (Exception e) {
}
}
} catch (Throwable e) {
}
}
}
}
use of uk.co.senab.bitmapcache.CacheableBitmapDrawable in project Talon-for-Twitter by klinker24.
the class TimeLineCursorAdapter method bindView.
@Override
public void bindView(final View view, Context mContext, final Cursor cursor) {
final ViewHolder holder = (ViewHolder) view.getTag();
if (holder.expandArea.getVisibility() == View.VISIBLE) {
removeExpansionNoAnimation(holder);
}
final long id = cursor.getLong(TWEET_COL);
holder.tweetId = id;
final String profilePic = cursor.getString(PRO_PIC_COL);
holder.proPicUrl = profilePic;
String tweetTexts = cursor.getString(TEXT_COL);
final String name = cursor.getString(NAME_COL);
final String screenname = cursor.getString(SCREEN_NAME_COL);
final String picUrl = cursor.getString(PIC_COL);
holder.picUrl = picUrl;
final long longTime = cursor.getLong(TIME_COL);
final String otherUrl = cursor.getString(URL_COL);
final String users = cursor.getString(USER_COL);
final String hashtags = cursor.getString(HASHTAG_COL);
holder.gifUrl = cursor.getString(GIF_COL);
boolean inAConversation;
if (hasConvo) {
inAConversation = cursor.getInt(CONVO_COL) == 1;
} else {
inAConversation = false;
}
String retweeter;
try {
retweeter = cursor.getString(RETWEETER_COL);
} catch (Exception e) {
retweeter = "";
}
if (holder.isAConversation != null) {
if (inAConversation) {
if (holder.isAConversation.getVisibility() != View.VISIBLE) {
holder.isAConversation.setVisibility(View.VISIBLE);
}
} else {
if (holder.isAConversation.getVisibility() != View.GONE) {
holder.isAConversation.setVisibility(View.GONE);
}
}
}
final String tweetText = tweetTexts;
if (!settings.reverseClickActions) {
final String fRetweeter = retweeter;
if (!isDM) {
View.OnLongClickListener click = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
String link;
boolean hasGif = holder.gifUrl != null && !holder.gifUrl.isEmpty();
boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube") && !(hasGif);
if (displayPic) {
link = holder.picUrl;
} else {
link = otherUrl.split(" ")[0];
}
Intent viewTweet = new Intent(context, TweetPager.class);
viewTweet.putExtra("name", name);
viewTweet.putExtra("screenname", screenname);
viewTweet.putExtra("time", longTime);
viewTweet.putExtra("tweet", tweetText);
viewTweet.putExtra("retweeter", fRetweeter);
viewTweet.putExtra("webpage", link);
viewTweet.putExtra("other_links", otherUrl);
viewTweet.putExtra("picture", displayPic);
viewTweet.putExtra("tweetid", holder.tweetId);
viewTweet.putExtra("proPic", profilePic);
viewTweet.putExtra("users", users);
viewTweet.putExtra("hashtags", hashtags);
viewTweet.putExtra("animated_gif", holder.gifUrl);
if (isHomeTimeline) {
sharedPrefs.edit().putLong("current_position_" + settings.currentAccount, holder.tweetId).commit();
}
if (secondAcc) {
String text = context.getString(R.string.using_second_account).replace("%s", "@" + settings.secondScreenName);
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
viewTweet.putExtra("second_account", true);
}
context.startActivity(viewTweet);
return true;
}
};
holder.background.setOnLongClickListener(click);
// holder.tweet.setOnLongClickListener(click);
}
if (!isDM) {
View.OnClickListener click = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (holder.preventNextClick) {
holder.preventNextClick = false;
return;
}
if (holder.expandArea.getVisibility() == View.GONE) {
if (secondAcc) {
String text = context.getString(R.string.using_second_account).replace("%s", "@" + settings.secondScreenName);
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}
addExpansion(holder, screenname, users, otherUrl.split(" "), holder.picUrl, id, hashtags.split(" "));
} else {
removeExpansionWithAnimation(holder);
removeKeyboard(holder);
}
}
};
holder.background.setOnClickListener(click);
// holder.tweet.setOnClickListener(click);
}
} else {
final String fRetweeter = retweeter;
if (!isDM) {
View.OnClickListener click = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (holder.preventNextClick) {
holder.preventNextClick = false;
return;
}
String link = "";
boolean hasGif = holder.gifUrl != null && !holder.gifUrl.isEmpty();
boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube") && !(hasGif);
if (displayPic) {
link = holder.picUrl;
} else {
link = otherUrl.split(" ")[0];
}
Intent viewTweet = new Intent(context, TweetPager.class);
viewTweet.putExtra("name", name);
viewTweet.putExtra("screenname", screenname);
viewTweet.putExtra("time", longTime);
viewTweet.putExtra("tweet", tweetText);
viewTweet.putExtra("retweeter", fRetweeter);
viewTweet.putExtra("webpage", link);
viewTweet.putExtra("picture", displayPic);
viewTweet.putExtra("other_links", otherUrl);
viewTweet.putExtra("tweetid", holder.tweetId);
viewTweet.putExtra("proPic", profilePic);
viewTweet.putExtra("users", users);
viewTweet.putExtra("hashtags", hashtags);
viewTweet.putExtra("animated_gif", holder.gifUrl);
if (isHomeTimeline) {
sharedPrefs.edit().putLong("current_position_" + settings.currentAccount, holder.tweetId).commit();
}
if (secondAcc) {
String text = context.getString(R.string.using_second_account).replace("%s", "@" + settings.secondScreenName);
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
viewTweet.putExtra("second_account", true);
}
context.startActivity(viewTweet);
}
};
holder.background.setOnClickListener(click);
// holder.tweet.setOnClickListener(click);
}
if (!isDM) {
View.OnLongClickListener click = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (holder.expandArea.getVisibility() != View.VISIBLE) {
if (secondAcc) {
String text = context.getString(R.string.using_second_account).replace("%s", "@" + settings.secondScreenName);
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}
addExpansion(holder, screenname, users, otherUrl.split(" "), holder.picUrl, id, hashtags.split(" "));
} else {
removeExpansionWithAnimation(holder);
removeKeyboard(holder);
}
return true;
}
};
holder.background.setOnLongClickListener(click);
// holder.tweet.setOnLongClickListener(click);
}
}
if (isDM) {
holder.background.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
new DeleteTweet().execute("" + holder.tweetId);
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
builder.setTitle(R.string.delete_direct_message);
AlertDialog dialog = builder.create();
dialog.show();
return true;
}
});
if (otherUrl != null && !otherUrl.equals("")) {
holder.tweet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent browser = new Intent(context, BrowserActivity.class);
browser.putExtra("url", otherUrl);
context.startActivity(browser);
}
});
}
}
holder.profilePic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent viewProfile = new Intent(context, ProfilePager.class);
viewProfile.putExtra("name", name);
viewProfile.putExtra("screenname", screenname);
viewProfile.putExtra("proPic", profilePic);
viewProfile.putExtra("tweetid", holder.tweetId);
viewProfile.putExtra("retweet", holder.retweeter.getVisibility() == View.VISIBLE);
viewProfile.putExtra("long_click", false);
if (isHomeTimeline) {
sharedPrefs.edit().putLong("current_position_" + settings.currentAccount, holder.tweetId).commit();
}
context.startActivity(viewProfile);
}
});
holder.profilePic.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
Intent viewProfile = new Intent(context, ProfilePager.class);
viewProfile.putExtra("name", name);
viewProfile.putExtra("screenname", screenname);
viewProfile.putExtra("proPic", profilePic);
viewProfile.putExtra("tweetid", holder.tweetId);
viewProfile.putExtra("retweet", holder.retweeter.getVisibility() == View.VISIBLE);
viewProfile.putExtra("long_click", true);
if (isHomeTimeline) {
sharedPrefs.edit().putLong("current_position_" + settings.currentAccount, holder.tweetId).commit();
}
context.startActivity(viewProfile);
return false;
}
});
if (!settings.addonTheme && talonLayout == AppSettings.LAYOUT_FULL_SCREEN || (settings.nameAndHandleOnTweet && settings.addonTheme)) {
if (holder.screenTV.getVisibility() == View.GONE) {
holder.screenTV.setVisibility(View.VISIBLE);
}
holder.screenTV.setText("@" + screenname);
holder.name.setText(name);
} else {
if (!settings.showBoth) {
holder.name.setText(settings.displayScreenName ? "@" + screenname : name);
} else {
if (holder.screenTV.getVisibility() == View.GONE) {
holder.screenTV.setVisibility(View.VISIBLE);
}
holder.name.setText(name);
holder.screenTV.setText("@" + screenname);
}
}
if (!settings.absoluteDate) {
holder.time.setText(Utils.getTimeAgo(longTime, context));
} else {
Date date = new Date(longTime);
holder.time.setText(timeFormatter.format(date).replace("24:", "00:") + ", " + dateFormatter.format(date));
}
holder.tweet.setText(tweetText);
boolean picture = false;
if ((settings.inlinePics || isDM) && holder.picUrl != null) {
if (holder.picUrl.equals("")) {
if (holder.image.getVisibility() != View.GONE) {
holder.image.setVisibility(View.GONE);
}
if (holder.playButton.getVisibility() == View.VISIBLE) {
holder.playButton.setVisibility(View.GONE);
}
} else {
if (holder.image.getVisibility() == View.GONE) {
holder.image.setVisibility(View.VISIBLE);
}
if (holder.picUrl.contains("youtube") || (holder.gifUrl != null && !android.text.TextUtils.isEmpty(holder.gifUrl))) {
if (holder.playButton.getVisibility() == View.GONE) {
holder.playButton.setVisibility(View.VISIBLE);
}
final String fRetweeter = retweeter;
holder.image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String link;
boolean hasGif = holder.gifUrl != null && !holder.gifUrl.isEmpty();
boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube") && !(hasGif);
if (displayPic) {
link = holder.picUrl;
} else {
link = otherUrl.split(" ")[0];
}
Intent viewTweet = new Intent(context, TweetPager.class);
viewTweet.putExtra("name", name);
viewTweet.putExtra("screenname", screenname);
viewTweet.putExtra("time", longTime);
viewTweet.putExtra("tweet", tweetText);
viewTweet.putExtra("retweeter", fRetweeter);
viewTweet.putExtra("webpage", link);
viewTweet.putExtra("other_links", otherUrl);
viewTweet.putExtra("picture", displayPic);
viewTweet.putExtra("tweetid", holder.tweetId);
viewTweet.putExtra("proPic", profilePic);
viewTweet.putExtra("users", users);
viewTweet.putExtra("hashtags", hashtags);
viewTweet.putExtra("clicked_youtube", true);
viewTweet.putExtra("animated_gif", holder.gifUrl);
if (isHomeTimeline) {
sharedPrefs.edit().putLong("current_position_" + settings.currentAccount, holder.tweetId).commit();
}
context.startActivity(viewTweet);
}
});
holder.image.setImageDrawable(null);
picture = true;
} else {
if (holder.playButton.getVisibility() == View.VISIBLE) {
holder.playButton.setVisibility(View.GONE);
}
holder.image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isHomeTimeline) {
sharedPrefs.edit().putLong("current_position_" + settings.currentAccount, holder.tweetId).commit();
}
if (holder.picUrl.contains(" ")) {
context.startActivity(new Intent(context, ViewPictures.class).putExtra("pictures", holder.picUrl));
} else {
context.startActivity(new Intent(context, PhotoViewerActivity.class).putExtra("url", holder.picUrl));
}
}
});
holder.image.setImageDrawable(null);
picture = true;
}
}
}
if (retweeter.length() > 0 && !isDM) {
String text = context.getResources().getString(R.string.retweeter);
// holder.retweeter.setText(settings.displayScreenName ? text + retweeter : text.substring(0, text.length() - 2) + " " + name);
holder.retweeter.setText(text + retweeter);
holder.retweeterName = retweeter;
holder.retweeter.setVisibility(View.VISIBLE);
} else if (holder.retweeter.getVisibility() == View.VISIBLE) {
holder.retweeter.setVisibility(View.GONE);
}
if (picture) {
CacheableBitmapDrawable wrapper = mCache.getFromMemoryCache(holder.picUrl);
if (wrapper != null) {
holder.image.setImageDrawable(wrapper);
picture = false;
}
}
CacheableBitmapDrawable wrapper2 = mCache.getFromMemoryCache(holder.proPicUrl);
final boolean gotProPic;
if (wrapper2 == null) {
gotProPic = false;
if (holder.profilePic.getDrawable() != null) {
holder.profilePic.setImageDrawable(null);
}
} else {
gotProPic = true;
holder.profilePic.setImageDrawable(wrapper2);
}
final boolean hasPicture = picture;
mHandlers[currHandler].removeCallbacksAndMessages(null);
mHandlers[currHandler].postDelayed(new Runnable() {
@Override
public void run() {
if (holder.tweetId == id) {
if (hasPicture) {
loadImage(context, holder, holder.picUrl, mCache, id);
}
if (!gotProPic) {
loadProPic(context, holder, holder.proPicUrl, mCache, id);
}
if (settings.useEmoji && (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || EmojiUtils.ios)) {
String text = holder.tweet.getText().toString();
if (EmojiUtils.emojiPattern.matcher(text).find()) {
final Spannable span = EmojiUtils.getSmiledText(context, Html.fromHtml(tweetText));
holder.tweet.setText(span);
}
}
holder.tweet.setSoundEffectsEnabled(false);
holder.tweet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!TouchableMovementMethod.touched) {
// absorbs the click on the background
if (!holder.preventNextClick) {
holder.background.getBackground().setState(new int[] { android.R.attr.state_pressed });
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
holder.background.getBackground().setState(new int[] { android.R.attr.state_empty });
}
}, 25);
}
holder.background.performClick();
}
}
});
holder.tweet.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (!TouchableMovementMethod.touched) {
holder.background.performLongClick();
holder.preventNextClick = true;
}
return false;
}
});
if (holder.retweeter.getVisibility() == View.VISIBLE) {
holder.retweeter.setSoundEffectsEnabled(false);
holder.retweeter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!TouchableMovementMethod.touched) {
if (!holder.preventNextClick) {
holder.background.getBackground().setState(new int[] { android.R.attr.state_pressed });
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
holder.background.getBackground().setState(new int[] { android.R.attr.state_empty });
}
}, 25);
}
holder.background.performClick();
}
}
});
holder.retweeter.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (!TouchableMovementMethod.touched) {
holder.background.performLongClick();
holder.preventNextClick = true;
}
return false;
}
});
}
TextUtils.linkifyText(context, holder.tweet, holder.background, true, otherUrl, false);
TextUtils.linkifyText(context, holder.retweeter, holder.background, true, "", false);
}
}
}, 400);
currHandler++;
if (currHandler == 10) {
currHandler = 0;
}
}
Aggregations