Example usage for android.widget ImageView getDrawable

List of usage examples for android.widget ImageView getDrawable

Introduction

In this page you can find the example usage for android.widget ImageView getDrawable.

Prototype

public Drawable getDrawable() 

Source Link

Document

Gets the current Drawable, or null if no Drawable has been assigned.

Usage

From source file:com.htc.dotdesign.ToolBoxService.java

private void updateBrushColor() {
    Resources resources = getResources();
    ImageView button = null;
    GradientDrawable drawable = null;/* w ww  . java2 s. com*/

    View extendView = null;
    if (mCurrFun == FunType.Fun_Palette) {
        extendView = mPalette;
    } else {
        extendView = mEraser;
    }
    if (extendView != null) {
        button = (ImageView) extendView.findViewById(R.id.btn_1x1);
        if (button != null) {
            //drawable = (GradientDrawable) button.getBackground();
            drawable = (GradientDrawable) button.getDrawable();
            if (mCurrBrushSize == BrushSize.Size_1x1) {
                drawable.setColor(resources.getColor(R.color.brush_size_enable_color));
            } else if (mCurrBrushSize == BrushSize.Size_2x2) {
                drawable.setColor(resources.getColor(R.color.brush_size_disable_color));
            }
        }

        button = (ImageView) extendView.findViewById(R.id.btn_2x2);
        if (button != null) {
            //drawable = (GradientDrawable) button.getBackground();
            drawable = (GradientDrawable) button.getDrawable();
            if (mCurrBrushSize == BrushSize.Size_1x1) {
                drawable.setColor(resources.getColor(R.color.brush_size_disable_color));
            } else if (mCurrBrushSize == BrushSize.Size_2x2) {
                drawable.setColor(resources.getColor(R.color.brush_size_enable_color));
            }
        }
    }
}

From source file:com.github.colorchief.colorchief.MainActivity.java

private boolean clickInImage(int x, int y, ImageView imageView) {

    //ImageView imageViewer = (ImageView) findViewById(R.id.imageView);

    if (imageView.getVisibility() != View.VISIBLE) {
        return false;
    }// w w  w.  j  a v  a  2s. c  o  m

    int[] imageViewCoords = new int[2];
    imageView.getLocationOnScreen(imageViewCoords);

    float[] imageViewMatrix = new float[9];
    imageView.getImageMatrix().getValues(imageViewMatrix);
    float scaleX = imageViewMatrix[Matrix.MSCALE_X];
    float scaleY = imageViewMatrix[Matrix.MSCALE_Y];

    Bitmap bitmap = null;
    int bitmapWidth = 0;
    int bitmapHeight = 0;

    try {
        bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        bitmapWidth = bitmap.getWidth();
        bitmapHeight = bitmap.getHeight();
    } catch (NullPointerException npe) {
        Log.e(TAG, "Failed to extract Bitmap from ImageView: " + npe);
    }

    //assuming Bitmap is centred in imageViewer
    int scaledBitmapWidth = Math.round(bitmapWidth * scaleX);
    int scaledBitmapHeight = Math.round(bitmapHeight * scaleY);

    int xOffsetBitmap2imageViewer = (imageView.getWidth() - scaledBitmapWidth) / 2;
    int yOffsetBitmap2imageViewer = (imageView.getHeight() - scaledBitmapHeight) / 2;

    // get total bitmap offset vs. screen origin
    int xTotalOffset = imageViewCoords[0] + xOffsetBitmap2imageViewer;
    int yTotalOffset = imageViewCoords[1] + yOffsetBitmap2imageViewer;

    if ((x >= xTotalOffset) && (x <= xTotalOffset + scaledBitmapWidth) && (y >= yTotalOffset)
            && (y <= yTotalOffset + scaledBitmapHeight)) {
        return true;
    } else {
        return false;
    }
}

From source file:com.master.metehan.filtereagle.ActivityMain.java

private void menu_legend() {
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    int colorOn = tv.data;
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    int colorOff = tv.data;

    // Create view
    LayoutInflater inflater = LayoutInflater.from(this);
    View view = inflater.inflate(R.layout.legend, null, false);
    ImageView ivWifiOn = (ImageView) view.findViewById(R.id.ivWifiOn);
    ImageView ivWifiOff = (ImageView) view.findViewById(R.id.ivWifiOff);
    ImageView ivOtherOn = (ImageView) view.findViewById(R.id.ivOtherOn);
    ImageView ivOtherOff = (ImageView) view.findViewById(R.id.ivOtherOff);
    ImageView ivScreenOn = (ImageView) view.findViewById(R.id.ivScreenOn);
    ImageView ivHostAllowed = (ImageView) view.findViewById(R.id.ivHostAllowed);
    ImageView ivHostBlocked = (ImageView) view.findViewById(R.id.ivHostBlocked);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrapWifiOn = DrawableCompat.wrap(ivWifiOn.getDrawable());
        Drawable wrapWifiOff = DrawableCompat.wrap(ivWifiOff.getDrawable());
        Drawable wrapOtherOn = DrawableCompat.wrap(ivOtherOn.getDrawable());
        Drawable wrapOtherOff = DrawableCompat.wrap(ivOtherOff.getDrawable());
        Drawable wrapScreenOn = DrawableCompat.wrap(ivScreenOn.getDrawable());
        Drawable wrapHostAllowed = DrawableCompat.wrap(ivHostAllowed.getDrawable());
        Drawable wrapHostBlocked = DrawableCompat.wrap(ivHostBlocked.getDrawable());

        DrawableCompat.setTint(wrapWifiOn, colorOn);
        DrawableCompat.setTint(wrapWifiOff, colorOff);
        DrawableCompat.setTint(wrapOtherOn, colorOn);
        DrawableCompat.setTint(wrapOtherOff, colorOff);
        DrawableCompat.setTint(wrapScreenOn, colorOn);
        DrawableCompat.setTint(wrapHostAllowed, colorOn);
        DrawableCompat.setTint(wrapHostBlocked, colorOff);
    }/*from www  . j a  va2s .c  o m*/

    // Show dialog
    dialogLegend = new AlertDialog.Builder(this).setView(view).setCancelable(true)
            .setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    dialogLegend = null;
                }
            }).create();
    dialogLegend.show();
}

From source file:it.configure.imageloader.zoom.PhotoViewAttacher.java

@Override
public final void onGlobalLayout() {
    ImageView imageView = getImageView();

    if (null != imageView && mZoomEnabled) {
        final int top = imageView.getTop();
        final int right = imageView.getRight();
        final int bottom = imageView.getBottom();
        final int left = imageView.getLeft();

        /**//from  ww w .j  a va 2  s. c om
         * We need to check whether the ImageView's bounds have changed.
         * This would be easier if we targeted API 11+ as we could just use
         * View.OnLayoutChangeListener. Instead we have to replicate the
         * work, keeping track of the ImageView's bounds and then checking
         * if the values change.
         */
        if (top != mIvTop || bottom != mIvBottom || left != mIvLeft || right != mIvRight) {
            // Update our base matrix, as the bounds have changed
            updateBaseMatrix(imageView.getDrawable());

            // Update values as something has changed
            mIvTop = top;
            mIvRight = right;
            mIvBottom = bottom;
            mIvLeft = left;
        }
    }
}

From source file:org.kiwix.kiwixmobile.KiwixMobileActivity.java

public void toggleImageViewGrayFilter(ImageView image, boolean state) {
    Drawable originalIcon = image.getDrawable();
    Drawable res = originalIcon.mutate();
    if (state) {//from www. j  a v  a  2  s .  c  o  m
        res.clearColorFilter();
    } else {
        res.setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN);
    }
    image.setImageDrawable(res);
}

From source file:org.catnut.fragment.TweetFragment.java

/**
 * ??/*  w w  w  . jav a  2s.c  om*/
 *
 * @param thumb url
 * @param originalUrl url
 */
private void loadThumbs(String thumb, final String originalUrl, final ImageView thumbs,
        final JSONArray jsonArray, View overflow) {
    if (!TextUtils.isEmpty(thumb)) {
        if (mStayInLatest) {
            int screenWidth = CatnutUtils.getScreenWidth(getActivity());
            Picasso.with(getActivity()).load(thumb).into(thumbs);
            thumbs.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return CatnutUtils.imageOverlay(v, event);
                }
            });
            thumbs.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    thumbs.getDrawable().clearColorFilter();
                    mText.invalidate();
                    Intent intent = SingleFragmentActivity.getIntent(getActivity(),
                            SingleFragmentActivity.PHOTO_VIEWER);
                    intent.putExtra(Constants.PIC, originalUrl);
                    startActivity(intent);
                }
            });
        } else {
            thumbs.setImageResource(R.drawable.error);
        }
        thumbs.setVisibility(View.VISIBLE);
    } else {
        thumbs.setVisibility(View.GONE);
        overflow.setVisibility(View.GONE);
    }
    if (jsonArray != null && jsonArray.length() > 1) {
        overflow.setVisibility(View.VISIBLE);
        overflow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                View view = LayoutInflater.from(getActivity()).inflate(R.layout.tweet_pics, null);
                LinePageIndicator indicator = (LinePageIndicator) view.findViewById(R.id.indicator);
                final ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
                pager.setPageTransformer(true, new PageTransformer.DepthPageTransformer());
                pager.setAdapter(new PagerAdapter() {
                    @Override
                    public int getCount() {
                        return jsonArray.length();
                    }

                    @Override
                    public boolean isViewFromObject(View view, Object object) {
                        return view == object;
                    }

                    @Override
                    public void destroyItem(ViewGroup container, int position, Object object) {
                        container.removeView((View) object);
                    }

                    @Override
                    public Object instantiateItem(ViewGroup container, int position) {
                        View v = LayoutInflater.from(getActivity()).inflate(R.layout.photo, null);
                        TouchImageView iv = (TouchImageView) v.findViewById(R.id.image);
                        String url = jsonArray.optJSONObject(position).optString(Status.thumbnail_pic);
                        String replace = url.replace(Constants.THUMBNAIL, Status.MEDIUM_THUMBNAIL);
                        Picasso.with(getActivity()).load(replace).into(iv);
                        container.addView(v);
                        return v;
                    }
                });
                indicator.setViewPager(pager);
                new AlertDialog.Builder(
                        new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Dialog)).setView(view)
                                .setPositiveButton(getString(R.string.original_pics),
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                ArrayList<Uri> urls = new ArrayList<Uri>(jsonArray.length());
                                                for (int i = 0; i < jsonArray.length(); i++) {
                                                    String s = jsonArray.optJSONObject(i)
                                                            .optString(Status.thumbnail_pic)
                                                            .replace(Constants.THUMBNAIL,
                                                                    Status.LARGE_THUMBNAIL);
                                                    urls.add(Uri.parse(s));
                                                }
                                                Intent intent = SingleFragmentActivity.getIntent(getActivity(),
                                                        SingleFragmentActivity.GALLERY);
                                                intent.putExtra(GalleryPagerFragment.CUR_INDEX,
                                                        pager.getCurrentItem());
                                                intent.putExtra(GalleryPagerFragment.URLS, urls);
                                                intent.putExtra(GalleryPagerFragment.TITLE,
                                                        getString(R.string.tweet_pics));
                                                startActivity(intent);
                                            }
                                        })
                                .setNegativeButton(getString(R.string.close), null).show();
            }
        });
    } else {
        overflow.setVisibility(View.GONE);
    }
}

From source file:org.catnut.adapter.TweetAdapter.java

private void injectThumbs(final Context context, final String originUri, String mediumThumbUrl,
        String smallThumbUrl, final ImageView thumbs) {
    switch (mThumbsOption) {
    case SMALL:/*from  w  w  w .ja  v a 2s .c  o m*/
    case MEDIUM:
        if (!TextUtils.isEmpty(originUri)) {
            if (mStayInLatest) { // not in offline mode
                RequestCreator creator;
                if (mThumbsOption == ThumbsOption.MEDIUM) {
                    creator = Picasso.with(context).load(mediumThumbUrl).centerCrop().resize(mScreenWidth,
                            (int) (mScreenWidth * Constants.GOLDEN_RATIO));
                } else {
                    creator = Picasso.with(context).load(smallThumbUrl);
                }
                creator.placeholder(android.R.drawable.ic_menu_report_image).error(R.drawable.error)
                        .into(thumbs);
                thumbs.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        return CatnutUtils.imageOverlay(v, event);
                    }
                });
                thumbs.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        thumbs.getDrawable().clearColorFilter();
                        thumbs.invalidate();
                        Intent intent = SingleFragmentActivity.getIntent(context,
                                SingleFragmentActivity.PHOTO_VIEWER);
                        intent.putExtra(Constants.PIC, originUri);
                        mContext.startActivity(intent);
                    }
                });
            } else {
                // sometimes, the user may read timeline in offline mode(may opening the 2/3g),
                // so, don' t load the image
                // todo, may be we need to check it in cache or place the network unavailable image?
                thumbs.setImageResource(android.R.drawable.ic_menu_report_image);
            }
            thumbs.setVisibility(View.VISIBLE);
            break;
        }
        // otherwise, fall through...
    case NONE:
    case ORIGINAL:
    default:
        thumbs.setVisibility(View.GONE);
        break;
    }
}

From source file:github.daneren2005.dsub.fragments.SelectDirectoryFragment.java

private void setupTextDisplay(final View header) {
    final TextView titleView = (TextView) header.findViewById(R.id.select_album_title);
    if (playlistName != null) {
        titleView.setText(playlistName);
    } else if (podcastName != null) {
        titleView.setText(podcastName);//from w  w  w.  j a va  2  s.c  om
        titleView.setPadding(0, 6, 4, 8);
    } else if (name != null) {
        titleView.setText(name);

        if (artistInfo != null) {
            titleView.setPadding(0, 6, 4, 8);
        }
    } else if (share != null) {
        titleView.setVisibility(View.GONE);
    }

    int songCount = 0;

    Set<String> artists = new HashSet<String>();
    Set<Integer> years = new HashSet<Integer>();
    Integer totalDuration = 0;
    for (Entry entry : entries) {
        if (!entry.isDirectory()) {
            songCount++;
            if (entry.getArtist() != null) {
                artists.add(entry.getArtist());
            }
            if (entry.getYear() != null) {
                years.add(entry.getYear());
            }
            Integer duration = entry.getDuration();
            if (duration != null) {
                totalDuration += duration;
            }
        }
    }

    final TextView artistView = (TextView) header.findViewById(R.id.select_album_artist);
    if (podcastDescription != null || artistInfo != null) {
        artistView.setVisibility(View.VISIBLE);
        String text = podcastDescription != null ? podcastDescription : artistInfo.getBiography();
        Spanned spanned = null;
        if (text != null) {
            spanned = Html.fromHtml(text);
        }
        artistView.setText(spanned);
        artistView.setSingleLine(false);
        final int minLines = context.getResources().getInteger(R.integer.TextDescriptionLength);
        artistView.setLines(minLines);
        artistView.setTextAppearance(context, android.R.style.TextAppearance_Small);

        final Spanned spannedText = spanned;
        artistView.setOnClickListener(new View.OnClickListener() {
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            @Override
            public void onClick(View v) {
                if (artistView.getMaxLines() == minLines) {
                    // Use LeadingMarginSpan2 to try to make text flow around image
                    Display display = context.getWindowManager().getDefaultDisplay();
                    ImageView coverArtView = (ImageView) header.findViewById(R.id.select_album_art);
                    coverArtView.measure(display.getWidth(), display.getHeight());

                    int height, width;
                    ViewGroup.MarginLayoutParams vlp = (ViewGroup.MarginLayoutParams) coverArtView
                            .getLayoutParams();
                    if (coverArtView.getDrawable() != null) {
                        height = coverArtView.getMeasuredHeight() + coverArtView.getPaddingBottom();
                        width = coverArtView.getWidth() + coverArtView.getPaddingRight();
                    } else {
                        height = coverArtView.getHeight();
                        width = coverArtView.getWidth() + coverArtView.getPaddingRight();
                    }
                    float textLineHeight = artistView.getPaint().getTextSize();
                    int lines = (int) Math.ceil(height / textLineHeight);

                    SpannableString ss = new SpannableString(spannedText);
                    ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(),
                            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

                    View linearLayout = header.findViewById(R.id.select_album_text_layout);
                    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) linearLayout
                            .getLayoutParams();
                    int[] rules = params.getRules();
                    rules[RelativeLayout.RIGHT_OF] = 0;
                    params.leftMargin = vlp.rightMargin;

                    artistView.setText(ss);
                    artistView.setMaxLines(100);

                    vlp = (ViewGroup.MarginLayoutParams) titleView.getLayoutParams();
                    vlp.leftMargin = width;
                } else {
                    artistView.setMaxLines(minLines);
                }
            }
        });
        artistView.setMovementMethod(LinkMovementMethod.getInstance());
    } else if (topTracks) {
        artistView.setText(R.string.menu_top_tracks);
        artistView.setVisibility(View.VISIBLE);
    } else if (showAll) {
        artistView.setText(R.string.menu_show_all);
        artistView.setVisibility(View.VISIBLE);
    } else if (artists.size() == 1) {
        String artistText = artists.iterator().next();
        if (years.size() == 1) {
            artistText += " - " + years.iterator().next();
        }
        artistView.setText(artistText);
        artistView.setVisibility(View.VISIBLE);
    } else {
        artistView.setVisibility(View.GONE);
    }

    TextView songCountView = (TextView) header.findViewById(R.id.select_album_song_count);
    TextView songLengthView = (TextView) header.findViewById(R.id.select_album_song_length);
    if (podcastDescription != null || artistInfo != null) {
        songCountView.setVisibility(View.GONE);
        songLengthView.setVisibility(View.GONE);
    } else {
        String s = context.getResources().getQuantityString(R.plurals.select_album_n_songs, songCount,
                songCount);
        songCountView.setText(s.toUpperCase());
        songLengthView.setText(Util.formatDuration(totalDuration));
    }
}

From source file:github.popeen.dsub.fragments.SelectDirectoryFragment.java

private void setupTextDisplay(final View header) {

    final TextView titleView = (TextView) header.findViewById(R.id.select_album_title);
    if (playlistName != null) {
        titleView.setText(playlistName);
    } else if (podcastName != null) {
        Collections.reverse(entries);
        titleView.setText(podcastName);/*from   ww  w  . j a va 2 s  .  c  o m*/
        titleView.setPadding(0, 6, 4, 8);
    } else if (name != null) {
        titleView.setText(name);
        if (artistInfo != null) {
            titleView.setPadding(0, 6, 4, 8);
        }
    } else if (share != null) {
        titleView.setVisibility(View.GONE);
    }

    int songCount = 0;

    Set<String> artists = new HashSet<String>();
    Set<Integer> years = new HashSet<Integer>();
    totalDuration = 0;
    for (Entry entry : entries) {
        if (!entry.isDirectory()) {
            songCount++;
            if (entry.getArtist() != null) {
                artists.add(entry.getArtist());
            }
            if (entry.getYear() != null) {
                years.add(entry.getYear());
            }
            Integer duration = entry.getDuration();
            if (duration != null) {
                totalDuration += duration;
            }
        }
    }
    String artistName = "";
    bookDescription = "Could not collect any info about the book at this time";
    try {

        artistName = artists.iterator().next();
        String endpoint = "getBookDirectory";
        if (Util.isTagBrowsing(context)) {
            endpoint = "getBook";
        }
        SharedPreferences prefs = Util.getPreferences(context);
        String url = Util.getRestUrl(context, endpoint) + "&id=" + directory.getId() + "&f=json";

        Log.w("GetInfo", url);
        String artist, title;
        int year = 0;
        artist = title = "";

        try {
            artist = artists.iterator().next();
        } catch (Exception e) {
            Log.w("GetInfoArtist", e.toString());
        }
        try {
            title = titleView.getText().toString();
        } catch (Exception e) {
            Log.w("GetInfoTitle", e.toString());
        }
        try {
            year = years.iterator().next();
        } catch (Exception e) {
            Log.w("GetInfoYear", e.toString());
        }

        BookInfoAPIParams params = new BookInfoAPIParams(url, artist, title, year);
        bookInfo = new BookInfoAPI(context).execute(params).get();
        bookDescription = bookInfo[0];
        bookReader = bookInfo[1];

    } catch (Exception e) {
        Log.w("GetInfoError", e.toString());
    }
    if (bookDescription.equals("noInfo")) {
        bookDescription = "The server has no description for this book";
    }

    final TextView artistView = (TextView) header.findViewById(R.id.select_album_artist);
    if (podcastDescription != null || artistInfo != null || bookDescription != null) {
        artistView.setVisibility(View.VISIBLE);

        String text = "";
        if (bookDescription != null) {
            text = bookDescription;
        }
        if (podcastDescription != null) {
            text = podcastDescription;
        }
        if (artistInfo != null) {
            text = artistInfo.getBiography();
        }
        Spanned spanned = null;
        if (text != null) {
            String newText = "";
            try {
                if (!artistName.equals("")) {
                    newText += "<b>" + context.getResources().getString(R.string.main_artist) + "</b>: "
                            + artistName + "<br/>";
                }
            } catch (Exception e) {
            }
            try {
                if (totalDuration > 0) {
                    newText += "<b>" + context.getResources().getString(R.string.album_book_reader) + "</b>: "
                            + bookReader + "<br/>";
                }
            } catch (Exception e) {
            }
            try {
                if (totalDuration > 0) {
                    newText += "<b>" + context.getResources().getString(R.string.album_book_length) + "</b>: "
                            + Util.formatDuration(totalDuration) + "<br/>";
                }
            } catch (Exception e) {
            }
            try {
                newText += text + "<br/>";
            } catch (Exception e) {
            }
            spanned = Html.fromHtml(newText);
        }

        artistView.setText(spanned);
        artistView.setSingleLine(false);
        final int minLines = context.getResources().getInteger(R.integer.TextDescriptionLength);
        artistView.setLines(minLines);
        artistView.setTextAppearance(context, android.R.style.TextAppearance_Small);

        final Spanned spannedText = spanned;
        artistView.setOnClickListener(new View.OnClickListener() {
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            @Override
            public void onClick(View v) {
                if (artistView.getMaxLines() == minLines) {
                    // Use LeadingMarginSpan2 to try to make text flow around image
                    Display display = context.getWindowManager().getDefaultDisplay();
                    ImageView coverArtView = (ImageView) header.findViewById(R.id.select_album_art);
                    coverArtView.measure(display.getWidth(), display.getHeight());

                    int height, width;
                    ViewGroup.MarginLayoutParams vlp = (ViewGroup.MarginLayoutParams) coverArtView
                            .getLayoutParams();
                    if (coverArtView.getDrawable() != null) {
                        height = coverArtView.getMeasuredHeight() + coverArtView.getPaddingBottom();
                        width = coverArtView.getWidth() + coverArtView.getPaddingRight();
                    } else {
                        height = coverArtView.getHeight();
                        width = coverArtView.getWidth() + coverArtView.getPaddingRight();
                    }
                    float textLineHeight = artistView.getPaint().getTextSize();

                    int lines = (int) Math.ceil(height / textLineHeight) + 1;

                    SpannableString ss = new SpannableString(spannedText);
                    ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(),
                            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

                    View linearLayout = header.findViewById(R.id.select_album_text_layout);
                    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) linearLayout
                            .getLayoutParams();
                    int[] rules = params.getRules();
                    rules[RelativeLayout.RIGHT_OF] = 0;
                    params.leftMargin = vlp.rightMargin;

                    artistView.setText(ss);
                    artistView.setMaxLines(100);

                    vlp = (ViewGroup.MarginLayoutParams) titleView.getLayoutParams();
                    vlp.leftMargin = width;
                } else {
                    artistView.setMaxLines(minLines);
                }
            }
        });
        artistView.setMovementMethod(LinkMovementMethod.getInstance());
    } else if (topTracks) {
        artistView.setText(R.string.menu_top_tracks);
        artistView.setVisibility(View.VISIBLE);
    } else if (showAll) {
        artistView.setText(R.string.menu_show_all);
        artistView.setVisibility(View.VISIBLE);
    } else if (artists.size() == 1) {
        String artistText = artists.iterator().next();
        if (years.size() == 1) {
            artistText += " - " + years.iterator().next();
        }
        artistView.setText(artistText);
        artistView.setVisibility(View.VISIBLE);
    } else {
        artistView.setVisibility(View.GONE);
    }

    TextView songCountView = (TextView) header.findViewById(R.id.select_album_song_count);
    TextView songLengthView = (TextView) header.findViewById(R.id.select_album_song_length);
    if (podcastDescription != null || artistInfo != null) {
        songCountView.setVisibility(View.GONE);
        songLengthView.setVisibility(View.GONE);
    } else {
        String s = context.getResources().getQuantityString(R.plurals.select_album_n_songs, songCount,
                songCount);

        songCountView.setVisibility(View.GONE);
        songLengthView.setVisibility(View.GONE);
    }
}

From source file:com.zhengde163.netguard.ActivityMain.java

private void menu_legend() {
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    int colorOn = tv.data;
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    int colorOff = tv.data;

    // Create view
    LayoutInflater inflater = LayoutInflater.from(this);
    View view = inflater.inflate(R.layout.legend, null, false);
    ImageView ivWifiOn = (ImageView) view.findViewById(R.id.ivWifiOn);
    ImageView ivWifiOff = (ImageView) view.findViewById(R.id.ivWifiOff);
    ImageView ivOtherOn = (ImageView) view.findViewById(R.id.ivOtherOn);
    ImageView ivOtherOff = (ImageView) view.findViewById(R.id.ivOtherOff);
    ImageView ivScreenOn = (ImageView) view.findViewById(R.id.ivScreenOn);
    ImageView ivHostAllowed = (ImageView) view.findViewById(R.id.ivHostAllowed);
    ImageView ivHostBlocked = (ImageView) view.findViewById(R.id.ivHostBlocked);
    ImageView ivClose = (ImageView) view.findViewById(R.id.ivClose);
    ivClose.setOnClickListener(new View.OnClickListener() {
        @Override/*from   ww w  . j av a  2 s . c om*/
        public void onClick(View v) {
            dialogLegend.dismiss();
        }
    });
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrapWifiOn = DrawableCompat.wrap(ivWifiOn.getDrawable());
        Drawable wrapWifiOff = DrawableCompat.wrap(ivWifiOff.getDrawable());
        Drawable wrapOtherOn = DrawableCompat.wrap(ivOtherOn.getDrawable());
        Drawable wrapOtherOff = DrawableCompat.wrap(ivOtherOff.getDrawable());
        Drawable wrapScreenOn = DrawableCompat.wrap(ivScreenOn.getDrawable());
        Drawable wrapHostAllowed = DrawableCompat.wrap(ivHostAllowed.getDrawable());
        Drawable wrapHostBlocked = DrawableCompat.wrap(ivHostBlocked.getDrawable());

        DrawableCompat.setTint(wrapWifiOn, colorOn);
        DrawableCompat.setTint(wrapWifiOff, colorOff);
        DrawableCompat.setTint(wrapOtherOn, colorOn);
        DrawableCompat.setTint(wrapOtherOff, colorOff);
        DrawableCompat.setTint(wrapScreenOn, colorOn);
        DrawableCompat.setTint(wrapHostAllowed, colorOn);
        DrawableCompat.setTint(wrapHostBlocked, colorOff);
    }

    // Show dialog
    dialogLegend = new AlertDialog.Builder(this).setView(view).setCancelable(true)
            .setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    dialogLegend = null;
                }
            }).create();
    dialogLegend.show();
}