public static void setTheme(Activity activity) { activity.setTheme(ThemeHelper.getInstance().getTheme().resValue); }
private void buildView(final Context context, TypedArray ta) { int thumbnailBackground = ta.getColor(R.styleable.PostView_thumbnail_background, 0); int replyCountColor = ta.getColor(R.styleable.PostView_reply_count_color, 0); int iconPadding = ta.getDimensionPixelSize(R.styleable.PostView_icon_padding, 0); int iconWidth = ta.getDimensionPixelSize(R.styleable.PostView_icon_width, 0); int iconHeight = ta.getDimensionPixelSize(R.styleable.PostView_icon_height, 0); int gridHeight = ta.getDimensionPixelSize(R.styleable.PostView_grid_height, 0); int optionsSpacing = ta.getDimensionPixelSize(R.styleable.PostView_options_spacing, 0); int titleSize = ta.getDimensionPixelSize(R.styleable.PostView_title_size, 0); int optionsLeftPadding = ta.getDimensionPixelSize(R.styleable.PostView_options_left_padding, 0); int optionsTopPadding = ta.getDimensionPixelSize(R.styleable.PostView_options_top_padding, 0); int optionsRightPadding = ta.getDimensionPixelSize(R.styleable.PostView_options_right_padding, 0); int optionsBottomPadding = ta.getDimensionPixelSize(R.styleable.PostView_options_bottom_padding, 0); int lastSeenHeight = ta.getDimensionPixelSize(R.styleable.PostView_last_seen_height, 0); int postListMaxHeight = ta.getDimensionPixelSize(R.styleable.PostView_list_comment_max_height, 0); int postCommentSize = 0; int commentPadding = 0; int postPadding = 0; int imageSize = 0; int repliesCountSize = 0; if (isList()) { postCommentSize = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_SP, ThemeHelper.getInstance().getFontSize(), getResources().getDisplayMetrics()); commentPadding = ta.getDimensionPixelSize(R.styleable.PostView_list_comment_padding, 0); postPadding = ta.getDimensionPixelSize(R.styleable.PostView_list_padding, 0); imageSize = ta.getDimensionPixelSize(R.styleable.PostView_list_image_size, 0); repliesCountSize = ta.getDimensionPixelSize(R.styleable.PostView_list_replies_count_size, 0); } else if (isGrid()) { postCommentSize = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_SP, ThemeHelper.getInstance().getFontSize() - 1, getResources().getDisplayMetrics()); commentPadding = ta.getDimensionPixelSize(R.styleable.PostView_grid_comment_padding, 0); postPadding = ta.getDimensionPixelSize(R.styleable.PostView_grid_padding, 0); imageSize = ta.getDimensionPixelSize(R.styleable.PostView_grid_image_size, 0); repliesCountSize = ta.getDimensionPixelSize(R.styleable.PostView_grid_replies_count_size, 0); } RelativeLayout wrapper = new RelativeLayout(context); wrapper.setLayoutParams(matchParams); full = new LinearLayout(context); if (isList()) { full.setOrientation(HORIZONTAL); wrapper.addView(full, matchParams); } else if (isGrid()) { full.setOrientation(VERTICAL); wrapper.addView(full, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, gridHeight)); } LinearLayout imageContainer = new LinearLayout(context); imageContainer.setOrientation(VERTICAL); imageContainer.setBackgroundColor(thumbnailBackground); // Create thumbnail imageView = new CustomNetworkImageView(context); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setFadeIn(100); imageView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { manager.onThumbnailClicked(post); } }); if (isList()) { imageContainer.addView(imageView, new LinearLayout.LayoutParams(imageSize, imageSize)); full.addView(imageContainer, wrapMatchParams); full.setMinimumHeight(imageSize); } else if (isGrid()) { imageContainer.addView( imageView, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, imageSize)); full.addView(imageContainer, matchWrapParams); } contentContainer = new LinearLayout(context); contentContainer.setOrientation(VERTICAL); LinearLayout titleContainer = new LinearLayout(context); titleContainer.setOrientation(HORIZONTAL); if (isList()) { // 25 padding to give optionsView some space titleContainer.setPadding(0, 0, optionsSpacing, 0); } titleView = new TextView(context); titleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); titleView.setPadding(postPadding, postPadding, postPadding, 0); titleContainer.addView(titleView, wrapParams); contentContainer.addView(titleContainer, matchWrapParams); iconsView = new LinearLayout(context); iconsView.setOrientation(HORIZONTAL); iconsView.setPadding(postPadding, iconPadding, postPadding, 0); stickyView = new ImageView(context); stickyView.setImageDrawable(IconCache.stickyIcon); iconsView.addView(stickyView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); closedView = new ImageView(context); closedView.setImageDrawable(IconCache.closedIcon); iconsView.addView(closedView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); deletedView = new ImageView(context); deletedView.setImageDrawable(IconCache.trashIcon); iconsView.addView(deletedView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); archivedView = new ImageView(context); archivedView.setImageDrawable(IconCache.archivedIcon); iconsView.addView(archivedView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); countryView = new NetworkImageView(context); countryView.setScaleType(ImageView.ScaleType.FIT_CENTER); iconsView.addView(countryView, new LinearLayout.LayoutParams(iconWidth, iconHeight)); contentContainer.addView(iconsView, matchWrapParams); commentView = new TextView(context); commentView.setTextSize(TypedValue.COMPLEX_UNIT_PX, postCommentSize); if (isList()) { commentView.setPadding(postPadding, commentPadding, postPadding, commentPadding); if (manager.getLoadable().isBoardMode() || manager.getLoadable().isCatalogMode()) { commentView.setMaxHeight(postListMaxHeight); } } else if (isGrid()) { commentView.setPadding(postPadding, commentPadding, postPadding, 0); // So that is fills up all the height using weight later on commentView.setMinHeight(10000); } if (isList()) { contentContainer.addView(commentView, matchWrapParams); } else if (isGrid()) { contentContainer.addView( commentView, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1f)); } repliesCountView = new TextView(context); Utils.setPressedDrawable(repliesCountView); repliesCountView.setTextColor(replyCountColor); repliesCountView.setPadding(postPadding, postPadding, postPadding, postPadding); repliesCountView.setTextSize(TypedValue.COMPLEX_UNIT_PX, repliesCountSize); repliesCountView.setSingleLine(); contentContainer.addView(repliesCountView, wrapParams); lastSeen = new View(context); lastSeen.setBackgroundColor(0xffff0000); contentContainer.addView(lastSeen, new LayoutParams(LayoutParams.MATCH_PARENT, lastSeenHeight)); if (!manager.getLoadable().isThreadMode()) { Utils.setPressedDrawable(contentContainer); } full.addView(contentContainer, matchWrapParams); optionsView = new ImageView(context); optionsView.setImageResource(R.drawable.ic_overflow); Utils.setPressedDrawable(optionsView); optionsView.setPadding( optionsLeftPadding, optionsTopPadding, optionsRightPadding, optionsBottomPadding); optionsView.setOnClickListener( new OnClickListener() { @Override public void onClick(final View v) { PopupMenu popupMenu = new PopupMenu(context, v); manager.showPostOptions(post, popupMenu); popupMenu.show(); if (ThemeHelper.getInstance().getTheme().isLightTheme) { optionsView.setImageResource(R.drawable.ic_overflow_black); popupMenu.setOnDismissListener( new PopupMenu.OnDismissListener() { @Override public void onDismiss(final PopupMenu menu) { optionsView.setImageResource(R.drawable.ic_overflow); } }); } } }); wrapper.addView(optionsView, wrapParams); RelativeLayout.LayoutParams optionsParams = (RelativeLayout.LayoutParams) optionsView.getLayoutParams(); optionsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); optionsParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); optionsView.setLayoutParams(optionsParams); addView(wrapper, matchParams); wrapper.setOnClickListener(this); }