@Override protected void onDestroy() { super.onDestroy(); articleFeed.stopLoad(); ThumbnailCache.getInstance().stopLoad(); }
private void refreshImages() { Bitmap thumbnailBitmap; RssArticle article; for (View articleView : listArticlesViews) { ImageView thumbnailImageView = (ImageView) articleView.findViewById(R.id.article_image); article = (RssArticle) articleView.getTag(); Boolean tag = (Boolean) thumbnailImageView.getTag(R.bool.image_empty); if (tag != null && tag == true) { thumbnailBitmap = ThumbnailCache.getInstance().getBitmap(article.getEnclosure()); if (thumbnailBitmap != null) { thumbnailImageView.setImageBitmap(thumbnailBitmap); } else { ThumbnailCache.getInstance().load(thumbnailImageView, article.getEnclosure()); } } } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); articleFeed = new ArticleFeed(this.getBaseContext()); setFeed(articleFeed); articleFeed.loadCache(); ThumbnailCache.getInstance().setContext(getBaseContext()); setContentView(R.layout.articles_list); rubricsList = (LinearLayout) findViewById(R.id.articles_list); emptyMessage = (TextView) findViewById(R.id.empty); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); String fontSize = preferences.getString("font_list_size", "medium"); float imageSize = 12; if (fontSize.equalsIgnoreCase("small")) { imageSize = getResources().getDimension(R.dimen.image_size_small); } else if (fontSize.equalsIgnoreCase("medium")) { imageSize = getResources().getDimension(R.dimen.image_size_medium); } else if (fontSize.equalsIgnoreCase("large")) { imageSize = getResources().getDimension(R.dimen.image_size_large); } Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int width = display.getWidth(); int maxImageCount = (int) (width / imageSize + 1); Rubric.setDefaultViewCount(maxImageCount); System.gc(); listArticlesViews = new LinkedList<View>(); generateRubricsList(); }
/** * Add article thumbnail to the appropriate rubric * * @param article */ private void insertArticleView(RssArticle article) { LayoutInflater layoutInflater; View articleView; SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); LinearLayout rubricLayout; Bitmap thumbnailBitmap; TextView articleTitle; ImageView thumbnailImageView; int rubricId = article.getRubricId(); Rubric rubric = articleFeed.getRubric(rubricId); int articlePosition = rubric.getPosition(article); updateRubricTitle(rubric); if (articlePosition >= rubric.getViewCount() && articlePosition > rubric.getMaximumViewCount()) { return; } rubric.increaseViewCount(1); layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); articleView = layoutInflater.inflate(R.layout.article_thumbnail, null); thumbnailImageView = (ImageView) articleView.findViewById(R.id.article_image); articleTitle = (TextView) articleView.findViewById(R.id.article_title); articleTitle.setText(article.getTitle()); thumbnailBitmap = ThumbnailCache.getInstance().getBitmap(article.getEnclosure()); if (thumbnailBitmap != null) { thumbnailImageView.setImageBitmap(thumbnailBitmap); } else { ThumbnailCache.getInstance().load(thumbnailImageView, article.getEnclosure()); } listArticlesViews.add(articleView); if (article.isRead()) { thumbnailImageView.setColorFilter(0x99ffffff, PorterDuff.Mode.MULTIPLY); articleTitle.setTextColor(0xffb7b7b7); } String fontSize = preferences.getString("font_list_size", "medium"); float imageSize = 12; float density = getResources().getDisplayMetrics().density; if (fontSize.equalsIgnoreCase("small")) { articleTitle.setTextSize(getResources().getDimension(R.dimen.tile_text_small) / density); imageSize = getResources().getDimension(R.dimen.image_size_small); } else if (fontSize.equalsIgnoreCase("medium")) { articleTitle.setTextSize(getResources().getDimension(R.dimen.tile_text_medium) / density); imageSize = getResources().getDimension(R.dimen.image_size_medium); } else if (fontSize.equalsIgnoreCase("large")) { articleTitle.setTextSize(getResources().getDimension(R.dimen.tile_text_large) / density); imageSize = getResources().getDimension(R.dimen.image_size_large); } thumbnailImageView.setLayoutParams( new RelativeLayout.LayoutParams((int) imageSize, (int) imageSize)); articleView.setOnClickListener(this); articleView.setTag(article); rubricLayout = (LinearLayout) rubricsViews.get(rubricId).findViewById(R.id.rubric_layout); rubricLayout.addView(articleView, articlePosition); }