Example usage for android.widget ImageView setTag

List of usage examples for android.widget ImageView setTag

Introduction

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

Prototype

public void setTag(final Object tag) 

Source Link

Document

Sets the tag associated with this view.

Usage

From source file:com.haomee.chat.activity.ChatActivity.java

/**
 * ?/*from  w  ww.  j ava2s  .  c o  m*/
 */

public void add_points(int total_number, View container) {
    // ?ViewGroup
    tips_anim_emoji = new ImageView[total_number];
    Map<String, ImageView[]> map = new HashMap<String, ImageView[]>();
    for (int i = 0; i < tips_anim_emoji.length; i++) {
        ImageView imageView = new ImageView(ChatActivity.this);
        LinearLayout.LayoutParams layout = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        layout.setMargins(10, 0, 10, 0);
        imageView.setTag(tab_emotions_tag);
        imageView.setLayoutParams(layout);
        tips_anim_emoji[i] = imageView;
        if (i == 0) {
            tips_anim_emoji[i].setBackgroundResource(R.drawable.dot);
        } else {
            tips_anim_emoji[i].setBackgroundResource(R.drawable.dot_normal);
        }

        ((LinearLayout) container).setGravity(Gravity.CENTER);
        ((ViewGroup) container).addView(imageView);
    }
}

From source file:com.example.android_test.loopviewpager.LoopViewPager.java

void populate(int newCurrentItem) {

    // CHANGE/*from ww w  . j  a  v  a 2 s . c o  m*/
    int oldCurrentItem = mCurItem;
    int oldItemsSize = mItems.size();

    ItemInfo oldCurInfo = null;
    if (mCurItem != newCurrentItem) {
        oldCurInfo = infoForPosition(mCurItem);
        mCurItem = newCurrentItem;
        mRequestLayoutNeed = true;
    }

    if (mAdapter == null) {
        return;
    }

    // Bail now if we are waiting to populate. This is to hold off
    // on creating views from the time the user releases their finger to
    // fling to a new position until we have finished the scroll to
    // that position, avoiding glitches from happening at that point.
    if (mPopulatePending) {
        if (DEBUG)
            Log.i(TAG, "populate is pending, skipping for now...");
        return;
    }

    // Also, don't populate until we are attached to a window. This is to
    // avoid trying to populate before we have restored our view hierarchy
    // state and conflicting with what is restored.
    if (getWindowToken() == null) {
        return;
    }

    mAdapter.startUpdate(this);

    final int N = mAdapter.getCount();

    final int pageLimit = mOffscreenPageLimit;
    // CHANGE
    final int startPos = (mCurItem + N - pageLimit) % N;
    // final int startPos = Math.max(0, mCurItem - pageLimit);
    final int endPos = (mCurItem + pageLimit) % N;
    // final int endPos = Math.min(N - 1, mCurItem + pageLimit);

    // Locate the currently focused item or add it if needed.
    int curIndex = -1;
    ItemInfo curItem = null;
    for (curIndex = 0; curIndex < mItems.size(); curIndex++) {
        final ItemInfo ii = mItems.get(curIndex);
        // CHANGE
        if (ii.position == mCurItem) {
            curItem = ii;
            break;
        }
    }

    // CHANGE
    if (curIndex >= mItems.size() && mItems.size() > 0 && oldCurInfo != null) {
        int oldPosition = oldCurInfo.position;
        int f = oldPosition < mCurItem ? oldPosition + N : oldPosition;
        int l = oldPosition > mCurItem ? oldPosition - N : oldPosition;
        int fDiff = f - mCurItem;
        int lDiff = mCurItem - l;
        if (fDiff < lDiff) {
            curIndex = 0;
        } else if (lDiff < fDiff) {
            curIndex = mItems.size();
        } else {
            curIndex = mCurItem < oldPosition ? 0 : mItems.size();
        }
    }

    if (curItem == null && N > 0) {
        curItem = addNewItem(mCurItem, curIndex);
    }

    // Fill 3x the available width or up to the number of offscreen
    // pages requested to either side, whichever is larger.
    // If we have no current item we have no work to do.
    if (curItem != null) {

        if (N > 1) {
            // ANALYZE ??
            float extraWidthLeft = 0.f;
            int itemIndex = curIndex - 1;
            ItemInfo ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
            final float leftWidthNeeded = 2.f - curItem.widthFactor;

            for (int i = 0; i < N; i++) {
                final int pos = ((mCurItem - 1 - i) + N) % N;

                // CHANGE
                ItemInfo firstInfo = mItems.get(0);
                if (pos == firstInfo.position && firstInfo.scrolling) {
                    break;
                }

                // CHANGE
                if (extraWidthLeft >= leftWidthNeeded && (pos < startPos || pos > endPos || itemIndex < 0)) {
                    if (ii == null) {
                        break;
                    }
                    // ANALYZE ???????
                    if (pos == ii.position && !ii.scrolling && N > 3) {
                        mItems.remove(itemIndex);
                        mAdapter.destroyItem(this, pos, ii.object);
                        itemIndex--;
                        curIndex--;
                        ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
                    }
                } else if (ii != null && pos == ii.position) {
                    extraWidthLeft += ii.widthFactor;
                    itemIndex--;
                    ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
                } else {
                    // CHANGE
                    ItemInfo lastInfo = mItems.get(mItems.size() - 1);
                    if (pos == lastInfo.position) {
                        ii = lastInfo;
                        mItems.remove(lastInfo);
                        mItems.add(itemIndex + 1, lastInfo);
                    } else {
                        // ??
                        ii = addNewItem(pos, itemIndex + 1);
                    }
                    curIndex++;
                    extraWidthLeft += ii.widthFactor;
                    ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
                }
            }

            // ANALYZE ???
            float extraWidthRight = curItem.widthFactor;
            itemIndex = curIndex + 1;
            if (extraWidthRight < 2.f) {
                ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                for (int i = 0; i < N; i++) {
                    final int pos = ((mCurItem + 1 + i) + N) % N;
                    // CHANGE
                    if (extraWidthRight >= 2.f
                            && (pos > endPos || pos < startPos || itemIndex >= mItems.size())) {
                        if (ii == null) {
                            break;
                        }

                        // ANALYZE ???????
                        // CHANGE
                        if (pos == ii.position) {
                            if (!ii.scrolling) {
                                mItems.remove(itemIndex);
                                mAdapter.destroyItem(this, pos, ii.object);
                                ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                            } else {
                                itemIndex++;
                                ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                            }
                        }
                    } else if (ii != null && pos == ii.position) {
                        extraWidthRight += ii.widthFactor;
                        itemIndex++;
                        ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                    } else {
                        // CHANGE
                        ItemInfo firstInfo = mItems.get(0);
                        if (firstInfo.position == -1 && mItems.size() > 1) {
                            firstInfo = mItems.get(1);
                        }
                        if (pos == firstInfo.position && N > 1) {
                            ii = firstInfo;
                            mItems.remove(firstInfo);
                            mItems.add(itemIndex - 1, firstInfo);
                            curIndex--;
                        } else {
                            // ???
                            ii = addNewItem(pos, itemIndex);
                            itemIndex++;
                        }
                        extraWidthRight += ii.widthFactor;
                        ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                    }
                }
            }
        }

        // CHANGE
        if (N == 2) {
            if (mItems.size() < 3) {
                ItemInfo lastInfo = mItems.get(mItems.size() - 1);
                // ??
                ItemInfo ii = new ItemInfo();
                ii.position = -1;
                ii.object = null;
                ii.widthFactor = lastInfo.widthFactor;
                ImageView dummyView = new ImageView(getContext());
                dummyView.setTag(-1);
                this.addView(dummyView);
                mItems.add(0, ii);
                curIndex++;
            }
        }

        calculatePageOffsets(curItem, curIndex, oldCurInfo);

        if (N > 3) {
            Log.d("??", "N = " + N + ", oldItemsSize = " + oldItemsSize + ", mItems.size = " + mItems.size()
                    + ", mRequestLayoutNeed = " + mRequestLayoutNeed);
            if (oldItemsSize > 3) {
                if (mItems.size() > 3) {
                    if (mRequestLayoutNeed) {
                        requestLayout();
                        mRequestLayoutNeed = false;
                    }
                }
            }
        }
    }

    if (DEBUG) {
        Log.i(TAG, "Current page list:");
        for (int i = 0; i < mItems.size(); i++) {
            Log.i(TAG, "#" + i + ": page " + mItems.get(i).position + "  offset " + mItems.get(i).offset);
        }
    }

    mAdapter.setPrimaryItem(this, mCurItem, curItem != null ? curItem.object : null);

    mAdapter.finishUpdate(this);

    // Check width measurement of current pages. Update LayoutParams as
    // needed.
    final int childCount = getChildCount();

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (!lp.isDecor && lp.widthFactor == 0.f) {
            // 0 means requery the adapter for this, it doesn't have a valid
            // width.
            final ItemInfo ii = infoForChild(child);
            if (ii != null) {
                lp.widthFactor = ii.widthFactor;
            }
        }
    }

    if (hasFocus()) {
        View currentFocused = findFocus();
        ItemInfo ii = currentFocused != null ? infoForAnyChild(currentFocused) : null;
        if (ii == null || ii.position != mCurItem) {
            for (int i = 0; i < getChildCount(); i++) {
                View child = getChildAt(i);
                ii = infoForChild(child);
                if (ii != null && ii.position == mCurItem) {
                    if (child.requestFocus(FOCUS_FORWARD)) {
                        break;
                    }
                }
            }
        }
    }
}

From source file:org.chinenv.onroad.loopview.LoopViewPager.java

void populate(int newCurrentItem) {

    // CHANGE/* ww  w.  jav  a2 s  .  c  om*/
    int oldCurrentItem = mCurItem;
    int oldItemsSize = mItems.size();

    ItemInfo oldCurInfo = null;
    if (mCurItem != newCurrentItem) {
        oldCurInfo = infoForPosition(mCurItem);
        mCurItem = newCurrentItem;
        mRequestLayoutNeed = true;
    }

    if (mAdapter == null) {
        return;
    }

    // Bail now if we are waiting to populate. This is to hold off
    // on creating views from the time the user releases their finger to
    // fling to a new position until we have finished the scroll to
    // that position, avoiding glitches from happening at that point.
    if (mPopulatePending) {
        if (DEBUG)
            Log.i(TAG, "populate is pending, skipping for now...");
        return;
    }

    // Also, don't populate until we are attached to a window. This is to
    // avoid trying to populate before we have restored our view hierarchy
    // state and conflicting with what is restored.
    if (getWindowToken() == null) {
        return;
    }

    mAdapter.startUpdate(this);

    final int N = mAdapter.getCount();

    final int pageLimit = mOffscreenPageLimit;
    // CHANGE
    final int startPos = (mCurItem + N - pageLimit) % N;
    // final int startPos = Math.max(0, mCurItem - pageLimit);
    final int endPos = (mCurItem + pageLimit) % N;
    // final int endPos = Math.min(N - 1, mCurItem + pageLimit);

    // Locate the currently focused item or add it if needed.
    int curIndex = -1;
    ItemInfo curItem = null;
    for (curIndex = 0; curIndex < mItems.size(); curIndex++) {
        final ItemInfo ii = mItems.get(curIndex);
        // CHANGE
        if (ii.position == mCurItem) {
            curItem = ii;
            break;
        }
    }

    // CHANGE
    if (curIndex >= mItems.size() && mItems.size() > 0 && oldCurInfo != null) {
        int oldPosition = oldCurInfo.position;
        int f = oldPosition < mCurItem ? oldPosition + N : oldPosition;
        int l = oldPosition > mCurItem ? oldPosition - N : oldPosition;
        int fDiff = f - mCurItem;
        int lDiff = mCurItem - l;
        if (fDiff < lDiff) {
            curIndex = 0;
        } else if (lDiff < fDiff) {
            curIndex = mItems.size();
        } else {
            curIndex = mCurItem < oldPosition ? 0 : mItems.size();
        }
    }

    if (curItem == null && N > 0) {
        curItem = addNewItem(mCurItem, curIndex);
    }

    // Fill 3x the available width or up to the number of offscreen
    // pages requested to either side, whichever is larger.
    // If we have no current item we have no work to do.
    if (curItem != null) {

        if (N > 1) {
            // ANALYZE ??
            float extraWidthLeft = 0.f;
            int itemIndex = curIndex - 1;
            ItemInfo ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
            final float leftWidthNeeded = 2.f - curItem.widthFactor;

            for (int i = 0; i < N; i++) {
                final int pos = ((mCurItem - 1 - i) + N) % N;

                // CHANGE
                ItemInfo firstInfo = mItems.get(0);
                if (pos == firstInfo.position && firstInfo.scrolling) {
                    break;
                }

                // CHANGE
                if (extraWidthLeft >= leftWidthNeeded && (pos < startPos || pos > endPos || itemIndex < 0)) {
                    if (ii == null) {
                        break;
                    }
                    // ANALYZE ????????
                    if (pos == ii.position && !ii.scrolling && N > 3) {
                        mItems.remove(itemIndex);
                        mAdapter.destroyItem(this, pos, ii.object);
                        itemIndex--;
                        curIndex--;
                        ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
                    }
                } else if (ii != null && pos == ii.position) {
                    extraWidthLeft += ii.widthFactor;
                    itemIndex--;
                    ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
                } else {
                    // CHANGE
                    ItemInfo lastInfo = mItems.get(mItems.size() - 1);
                    if (pos == lastInfo.position) {
                        ii = lastInfo;
                        mItems.remove(lastInfo);
                        mItems.add(itemIndex + 1, lastInfo);
                    } else {
                        // ???
                        ii = addNewItem(pos, itemIndex + 1);
                    }
                    curIndex++;
                    extraWidthLeft += ii.widthFactor;
                    ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
                }
            }

            // ANALYZE ???
            float extraWidthRight = curItem.widthFactor;
            itemIndex = curIndex + 1;
            if (extraWidthRight < 2.f) {
                ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                for (int i = 0; i < N; i++) {
                    final int pos = ((mCurItem + 1 + i) + N) % N;
                    // CHANGE
                    if (extraWidthRight >= 2.f
                            && (pos > endPos || pos < startPos || itemIndex >= mItems.size())) {
                        if (ii == null) {
                            break;
                        }

                        // ANALYZE ????????
                        // CHANGE
                        if (pos == ii.position) {
                            if (!ii.scrolling) {
                                mItems.remove(itemIndex);
                                mAdapter.destroyItem(this, pos, ii.object);
                                ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                            } else {
                                itemIndex++;
                                ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                            }
                        }
                    } else if (ii != null && pos == ii.position) {
                        extraWidthRight += ii.widthFactor;
                        itemIndex++;
                        ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                    } else {
                        // CHANGE
                        ItemInfo firstInfo = mItems.get(0);
                        if (firstInfo.position == -1 && mItems.size() > 1) {
                            firstInfo = mItems.get(1);
                        }
                        if (pos == firstInfo.position && N > 1) {
                            ii = firstInfo;
                            mItems.remove(firstInfo);
                            mItems.add(itemIndex - 1, firstInfo);
                            curIndex--;
                        } else {
                            // ????
                            ii = addNewItem(pos, itemIndex);
                            itemIndex++;
                        }
                        extraWidthRight += ii.widthFactor;
                        ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                    }
                }
            }
        }

        // CHANGE
        if (N == 2) {
            if (mItems.size() < 3) {
                ItemInfo lastInfo = mItems.get(mItems.size() - 1);
                // ??
                ItemInfo ii = new ItemInfo();
                ii.position = -1;
                ii.object = null;
                ii.widthFactor = lastInfo.widthFactor;
                ImageView dummyView = new ImageView(getContext());
                dummyView.setTag(-1);
                this.addView(dummyView);
                mItems.add(0, ii);
                curIndex++;
            }
        }

        calculatePageOffsets(curItem, curIndex, oldCurInfo);

        if (N > 3) {
            Log.d("??", "N = " + N + ", oldItemsSize = " + oldItemsSize + ", mItems.size = " + mItems.size()
                    + ", mRequestLayoutNeed = " + mRequestLayoutNeed);
            if (oldItemsSize > 3) {
                if (mItems.size() > 3) {
                    if (mRequestLayoutNeed) {
                        requestLayout();
                        mRequestLayoutNeed = false;
                    }
                }
            }
        }
    }

    if (DEBUG) {
        Log.i(TAG, "Current page list:");
        for (int i = 0; i < mItems.size(); i++) {
            Log.i(TAG, "#" + i + ": page " + mItems.get(i).position + "  offset " + mItems.get(i).offset);
        }
    }

    mAdapter.setPrimaryItem(this, mCurItem, curItem != null ? curItem.object : null);

    mAdapter.finishUpdate(this);

    // Check width measurement of current pages. Update LayoutParams as
    // needed.
    final int childCount = getChildCount();

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (!lp.isDecor && lp.widthFactor == 0.f) {
            // 0 means requery the adapter for this, it doesn't have a valid
            // width.
            final ItemInfo ii = infoForChild(child);
            if (ii != null) {
                lp.widthFactor = ii.widthFactor;
            }
        }
    }

    if (hasFocus()) {
        View currentFocused = findFocus();
        ItemInfo ii = currentFocused != null ? infoForAnyChild(currentFocused) : null;
        if (ii == null || ii.position != mCurItem) {
            for (int i = 0; i < getChildCount(); i++) {
                View child = getChildAt(i);
                ii = infoForChild(child);
                if (ii != null && ii.position == mCurItem) {
                    if (child.requestFocus(FOCUS_FORWARD)) {
                        break;
                    }
                }
            }
        }
    }
}

From source file:com.andrada.sitracker.ui.fragment.PublicationInfoFragment.java

private void setOrAnimateReadPubIcon(final ImageView imageView, PublicationState currentState,
        boolean allowAnimate) {
    final int imageResId = currentState.equals(PublicationState.READY_FOR_READING)
            ? R.drawable.read_pub_button_icon_checked
            : currentState.equals(PublicationState.DOWNLOADING) ? R.drawable.download_pub_icon_fab_up
                    : R.drawable.read_pub_button_icon_unchecked;

    if (imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();// w  w w  .  j a  va 2s  . co m
            ViewHelper.setAlpha(imageView, 1f);
        }
    }
    /*
    if (imageView.getBackground() instanceof AnimationDrawable) {
    AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground();
    frameAnimation.stop();
    imageView.setBackgroundResource(0);
    }*/

    if (allowAnimate && currentState.equals(PublicationState.DOWNLOADING)) {
        int duration = getResources().getInteger(android.R.integer.config_shortAnimTime);
        Animator outAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 0f);
        outAnimator.setDuration(duration);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageDrawable(null);
                imageView.setBackgroundResource(imageResId);
                Drawable frameAnimation = imageView.getBackground();
                if (frameAnimation instanceof AnimationDrawable) {
                    ((AnimationDrawable) frameAnimation).start();
                }
            }
        });

        ObjectAnimator inAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 1f);
        inAnimator.setDuration(duration * 2);
        final AnimatorSet set = new AnimatorSet();
        set.playSequentially(outAnimator, inAnimator);
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setTag(null);
            }
        });
        imageView.setTag(set);
        set.start();

    } else if (allowAnimate && currentState.equals(PublicationState.READY_FOR_READING)) {
        int duration = getResources().getInteger(android.R.integer.config_shortAnimTime);
        Animator outAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 0f);
        outAnimator.setDuration(duration);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setBackgroundResource(0);
                imageView.setImageResource(imageResId);
            }
        });
        ObjectAnimator inAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 1f);
        inAnimator.setDuration(duration * 2);
        final AnimatorSet set = new AnimatorSet();
        set.playSequentially(outAnimator, inAnimator);
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setTag(null);
            }
        });
        imageView.setTag(set);
        set.start();
    } else if (!allowAnimate && currentState.equals(PublicationState.DOWNLOADING)) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageDrawable(null);
                imageView.setBackgroundResource(imageResId);
                AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground();
                frameAnimation.start();
            }
        });
    } else {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setBackgroundResource(0);
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:org.hpdroid.base.view.LoopViewPager.java

void populate(int newCurrentItem) {

    // CHANGE/*from   w  w  w.ja  v  a  2  s .  c o  m*/
    //        int oldCurrentItem = mCurItem;
    int oldItemsSize = mItems.size();

    ItemInfo oldCurInfo = null;
    if (mCurItem != newCurrentItem) {
        oldCurInfo = infoForPosition(mCurItem);
        mCurItem = newCurrentItem;
        mRequestLayoutNeed = true;
    }

    if (mAdapter == null) {
        return;
    }

    // Bail now if we are waiting to populate. This is to hold off
    // on creating views from the time the user releases their finger to
    // fling to a new position until we have finished the scroll to
    // that position, avoiding glitches from happening at that point.
    if (mPopulatePending || mAdapter.getCount() == 0) {
        if (DEBUG)
            Log.i(TAG, "populate is pending, skipping for now...");
        return;
    }

    // Also, don't populate until we are attached to a window. This is to
    // avoid trying to populate before we have restored our view hierarchy
    // state and conflicting with what is restored.
    if (getWindowToken() == null) {
        return;
    }

    mAdapter.startUpdate(this);

    final int N = mAdapter.getCount();

    final int pageLimit = mOffscreenPageLimit;
    // CHANGE
    final int startPos = (mCurItem + N - pageLimit) % N;
    // final int startPos = Math.max(0, mCurItem - pageLimit);
    final int endPos = (mCurItem + pageLimit) % N;
    // final int endPos = Math.min(N - 1, mCurItem + pageLimit);

    // Locate the currently focused item or add it if needed.
    int curIndex = -1;
    ItemInfo curItem = null;
    for (curIndex = 0; curIndex < mItems.size(); curIndex++) {
        final ItemInfo ii = mItems.get(curIndex);
        // CHANGE
        if (ii.position == mCurItem) {
            curItem = ii;
            break;
        }
    }

    // CHANGE
    if (curIndex >= mItems.size() && mItems.size() > 0 && oldCurInfo != null) {
        int oldPosition = oldCurInfo.position;
        int f = oldPosition < mCurItem ? oldPosition + N : oldPosition;
        int l = oldPosition > mCurItem ? oldPosition - N : oldPosition;
        int fDiff = f - mCurItem;
        int lDiff = mCurItem - l;
        if (fDiff < lDiff) {
            curIndex = 0;
        } else if (lDiff < fDiff) {
            curIndex = mItems.size();
        } else {
            curIndex = mCurItem < oldPosition ? 0 : mItems.size();
        }
    }

    if (curItem == null && N > 0) {
        curItem = addNewItem(mCurItem, curIndex);
    }

    // Fill 3x the available width or up to the number of offscreen
    // pages requested to either side, whichever is larger.
    // If we have no current item we have no work to do.
    if (curItem != null) {

        if (N > 1) {
            // ANALYZE ??
            float extraWidthLeft = 0.f;
            int itemIndex = curIndex - 1;
            ItemInfo ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
            final float leftWidthNeeded = 2.f - curItem.widthFactor;

            for (int i = 0; i < N; i++) {
                final int pos = ((mCurItem - 1 - i) + N) % N;

                // CHANGE
                ItemInfo firstInfo = mItems.get(0);
                if (pos == firstInfo.position && firstInfo.scrolling) {
                    break;
                }

                // CHANGE
                if (extraWidthLeft >= leftWidthNeeded && (pos < startPos || pos > endPos || itemIndex < 0)) {
                    if (ii == null) {
                        break;
                    }
                    // ANALYZE ????????
                    if (pos == ii.position && !ii.scrolling && N > 3) {
                        mItems.remove(itemIndex);
                        mAdapter.destroyItem(this, pos, ii.object);
                        itemIndex--;
                        curIndex--;
                        ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
                    }
                } else if (ii != null && pos == ii.position) {
                    extraWidthLeft += ii.widthFactor;
                    itemIndex--;
                    ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
                } else {
                    // CHANGE
                    ItemInfo lastInfo = mItems.get(mItems.size() - 1);
                    if (pos == lastInfo.position) {
                        ii = lastInfo;
                        mItems.remove(lastInfo);
                        mItems.add(itemIndex + 1, lastInfo);
                    } else {
                        // ???
                        ii = addNewItem(pos, itemIndex + 1);
                    }
                    curIndex++;
                    extraWidthLeft += ii.widthFactor;
                    ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
                }
            }

            // ANALYZE ???
            float extraWidthRight = curItem.widthFactor;
            itemIndex = curIndex + 1;
            if (extraWidthRight < 2.f) {
                ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                for (int i = 0; i < N; i++) {
                    final int pos = ((mCurItem + 1 + i) + N) % N;
                    // CHANGE
                    if (extraWidthRight >= 2.f
                            && (pos > endPos || pos < startPos || itemIndex >= mItems.size())) {
                        if (ii == null) {
                            break;
                        }

                        // ANALYZE ????????
                        // CHANGE
                        if (pos == ii.position) {
                            if (!ii.scrolling) {
                                mItems.remove(itemIndex);
                                mAdapter.destroyItem(this, pos, ii.object);
                                ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                            } else {
                                itemIndex++;
                                ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                            }
                        }
                    } else if (ii != null && pos == ii.position) {
                        extraWidthRight += ii.widthFactor;
                        itemIndex++;
                        ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                    } else {
                        // CHANGE
                        ItemInfo firstInfo = mItems.get(0);
                        if (firstInfo.position == -1 && mItems.size() > 1) {
                            firstInfo = mItems.get(1);
                        }
                        if (pos == firstInfo.position && N > 1) {
                            ii = firstInfo;
                            mItems.remove(firstInfo);
                            mItems.add(itemIndex - 1, firstInfo);
                            curIndex--;
                        } else {
                            // ????
                            ii = addNewItem(pos, itemIndex);
                            itemIndex++;
                        }
                        extraWidthRight += ii.widthFactor;
                        ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                    }
                }
            }
        }

        // CHANGE
        if (N == 2) {
            if (mItems.size() < 3) {
                ItemInfo lastInfo = mItems.get(mItems.size() - 1);
                // ??
                ItemInfo ii = new ItemInfo();
                ii.position = -1;
                ii.object = null;
                ii.widthFactor = lastInfo.widthFactor;
                ImageView dummyView = new ImageView(getContext());
                dummyView.setTag(-1);
                this.addView(dummyView);
                mItems.add(0, ii);
                curIndex++;
            }
        }

        calculatePageOffsets(curItem, curIndex, oldCurInfo);

        if (N > 3) {
            Log.d("??", "N = " + N + ", oldItemsSize = " + oldItemsSize + ", mItems.size = " + mItems.size()
                    + ", mRequestLayoutNeed = " + mRequestLayoutNeed);
            if (oldItemsSize > 3) {
                if (mItems.size() > 3) {
                    if (mRequestLayoutNeed) {
                        requestLayout();
                        mRequestLayoutNeed = false;
                    }
                }
            }
        }
    }

    if (DEBUG) {
        Log.i(TAG, "Current page list:");
        for (int i = 0; i < mItems.size(); i++) {
            Log.i(TAG, "#" + i + ": page " + mItems.get(i).position + "  offset " + mItems.get(i).offset);
        }
    }

    mAdapter.setPrimaryItem(this, mCurItem, curItem != null ? curItem.object : null);

    mAdapter.finishUpdate(this);

    // Check width measurement of current pages. Update LayoutParams as
    // needed.
    final int childCount = getChildCount();

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (!lp.isDecor && lp.widthFactor == 0.f) {
            // 0 means requery the adapter for this, it doesn't have a valid
            // width.
            final ItemInfo ii = infoForChild(child);
            if (ii != null) {
                lp.widthFactor = ii.widthFactor;
            }
        }
    }

    if (hasFocus()) {
        View currentFocused = findFocus();
        ItemInfo ii = currentFocused != null ? infoForAnyChild(currentFocused) : null;
        if (ii == null || ii.position != mCurItem) {
            for (int i = 0; i < getChildCount(); i++) {
                View child = getChildAt(i);
                ii = infoForChild(child);
                if (ii != null && ii.position == mCurItem) {
                    if (child.requestFocus(FOCUS_FORWARD)) {
                        break;
                    }
                }
            }
        }
    }
}

From source file:com.baiiu.autoloopviewpager.loopvp.LoopViewPager.java

void populate(int newCurrentItem) {

    // CHANGE/*  ww w  .j  av  a2  s  .c o  m*/
    int oldCurrentItem = mCurItem;
    int oldItemsSize = mItems.size();

    ItemInfo oldCurInfo = null;
    if (mCurItem != newCurrentItem) {
        oldCurInfo = infoForPosition(mCurItem);
        mCurItem = newCurrentItem;
        mRequestLayoutNeed = true;
    }

    if (mAdapter == null) {
        return;
    }

    // Bail now if we are waiting to populate. This is to hold off
    // on creating views from the time the user releases their finger to
    // fling to a new position until we have finished the scroll to
    // that position, avoiding glitches from happening at that point.
    if (mPopulatePending) {
        if (DEBUG)
            Log.i(TAG, "populate is pending, skipping for now...");
        return;
    }

    // Also, don't populate until we are attached to a window. This is to
    // avoid trying to populate before we have restored our view hierarchy
    // state and conflicting with what is restored.
    if (getWindowToken() == null) {
        return;
    }

    mAdapter.startUpdate(this);

    final int N = mAdapter.getCount();

    final int pageLimit = mOffscreenPageLimit;
    // CHANGE
    final int startPos = (mCurItem + N - pageLimit) % N;
    // final int startPos = Math.max(0, mCurItem - pageLimit);
    final int endPos = (mCurItem + pageLimit) % N;
    // final int endPos = Math.min(N - 1, mCurItem + pageLimit);

    // Locate the currently focused item or add it if needed.
    int curIndex = -1;
    ItemInfo curItem = null;
    for (curIndex = 0; curIndex < mItems.size(); curIndex++) {
        final ItemInfo ii = mItems.get(curIndex);
        // CHANGE
        if (ii.position == mCurItem) {
            curItem = ii;
            break;
        }
    }

    // CHANGE
    if (curIndex >= mItems.size() && mItems.size() > 0 && oldCurInfo != null) {
        int oldPosition = oldCurInfo.position;
        int f = oldPosition < mCurItem ? oldPosition + N : oldPosition;
        int l = oldPosition > mCurItem ? oldPosition - N : oldPosition;
        int fDiff = f - mCurItem;
        int lDiff = mCurItem - l;
        if (fDiff < lDiff) {
            curIndex = 0;
        } else if (lDiff < fDiff) {
            curIndex = mItems.size();
        } else {
            curIndex = mCurItem < oldPosition ? 0 : mItems.size();
        }
    }

    if (curItem == null && N > 0) {
        curItem = addNewItem(mCurItem, curIndex);
    }

    // Fill 3x the available width or up to the number of offscreen
    // pages requested to either side, whichever is larger.
    // If we have no current item we have no work to do.
    if (curItem != null) {

        if (N > 1) {
            // ANALYZE ??
            float extraWidthLeft = 0.f;
            int itemIndex = curIndex - 1;
            ItemInfo ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
            final float leftWidthNeeded = 2.f - curItem.widthFactor;

            for (int i = 0; i < N; i++) {
                final int pos = ((mCurItem - 1 - i) + N) % N;

                // CHANGE
                ItemInfo firstInfo = mItems.get(0);
                if (pos == firstInfo.position && firstInfo.scrolling) {
                    break;
                }

                // CHANGE
                if (extraWidthLeft >= leftWidthNeeded && (pos < startPos || pos > endPos || itemIndex < 0)) {
                    if (ii == null) {
                        break;
                    }
                    // ANALYZE ???????
                    if (pos == ii.position && !ii.scrolling && N > 3) {
                        mItems.remove(itemIndex);
                        mAdapter.destroyItem(this, pos, ii.object);
                        itemIndex--;
                        curIndex--;
                        ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
                    }
                } else if (ii != null && pos == ii.position) {
                    extraWidthLeft += ii.widthFactor;
                    itemIndex--;
                    ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
                } else {
                    // CHANGE
                    ItemInfo lastInfo = mItems.get(mItems.size() - 1);
                    if (pos == lastInfo.position) {
                        ii = lastInfo;
                        mItems.remove(lastInfo);
                        mItems.add(itemIndex + 1, lastInfo);
                    } else {
                        // ??
                        ii = addNewItem(pos, itemIndex + 1);
                    }
                    curIndex++;
                    extraWidthLeft += ii.widthFactor;
                    ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
                }
            }

            // ANALYZE ???
            float extraWidthRight = curItem.widthFactor;
            itemIndex = curIndex + 1;
            if (extraWidthRight < 2.f) {
                ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                for (int i = 0; i < N; i++) {
                    final int pos = ((mCurItem + 1 + i) + N) % N;
                    // CHANGE
                    if (extraWidthRight >= 2.f
                            && (pos > endPos || pos < startPos || itemIndex >= mItems.size())) {
                        if (ii == null) {
                            break;
                        }

                        // ANALYZE ???????
                        // CHANGE
                        if (pos == ii.position) {
                            if (!ii.scrolling) {
                                mItems.remove(itemIndex);
                                mAdapter.destroyItem(this, pos, ii.object);
                                ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                            } else {
                                itemIndex++;
                                ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                            }
                        }
                    } else if (ii != null && pos == ii.position) {
                        extraWidthRight += ii.widthFactor;
                        itemIndex++;
                        ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                    } else {
                        // CHANGE
                        ItemInfo firstInfo = mItems.get(0);
                        if (firstInfo.position == -1 && mItems.size() > 1) {
                            firstInfo = mItems.get(1);
                        }
                        if (pos == firstInfo.position && N > 1) {
                            ii = firstInfo;
                            mItems.remove(firstInfo);
                            mItems.add(itemIndex - 1, firstInfo);
                            curIndex--;
                        } else {
                            // ???
                            ii = addNewItem(pos, itemIndex);
                            itemIndex++;
                        }
                        extraWidthRight += ii.widthFactor;
                        ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
                    }
                }
            }
        }

        // CHANGE
        if (N == 2) {
            if (mItems.size() < 3) {
                ItemInfo lastInfo = mItems.get(mItems.size() - 1);
                // ??
                ItemInfo ii = new ItemInfo();
                ii.position = -1;
                ii.object = null;
                ii.widthFactor = lastInfo.widthFactor;
                ImageView dummyView = new ImageView(getContext());
                dummyView.setTag(-1);
                this.addView(dummyView);
                mItems.add(0, ii);
                curIndex++;
            }
        }

        calculatePageOffsets(curItem, curIndex, oldCurInfo);

        if (N > 3) {
            if (DEBUG) {
                Log.d("??", "N = " + N + ", oldItemsSize = " + oldItemsSize + ", mItems.size = "
                        + mItems.size() + ", mRequestLayoutNeed = " + mRequestLayoutNeed);
            }
            if (oldItemsSize > 3) {
                if (mItems.size() > 3) {
                    if (mRequestLayoutNeed) {
                        requestLayout();
                        mRequestLayoutNeed = false;
                    }
                }
            }
        }
    }

    if (DEBUG) {
        Log.i(TAG, "Current page list:");
        for (int i = 0; i < mItems.size(); i++) {
            Log.i(TAG, "#" + i + ": page " + mItems.get(i).position + "  offset " + mItems.get(i).offset);
        }
    }

    mAdapter.setPrimaryItem(this, mCurItem, curItem != null ? curItem.object : null);

    mAdapter.finishUpdate(this);

    // Check width measurement of current pages. Update LayoutParams as
    // needed.
    final int childCount = getChildCount();

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (!lp.isDecor && lp.widthFactor == 0.f) {
            // 0 means requery the adapter for this, it doesn't have a valid
            // width.
            final ItemInfo ii = infoForChild(child);
            if (ii != null) {
                lp.widthFactor = ii.widthFactor;
            }
        }
    }

    if (hasFocus()) {
        View currentFocused = findFocus();
        ItemInfo ii = currentFocused != null ? infoForAnyChild(currentFocused) : null;
        if (ii == null || ii.position != mCurItem) {
            for (int i = 0; i < getChildCount(); i++) {
                View child = getChildAt(i);
                ii = infoForChild(child);
                if (ii != null && ii.position == mCurItem) {
                    if (child.requestFocus(FOCUS_FORWARD)) {
                        break;
                    }
                }
            }
        }
    }
}

From source file:com.haomee.chat.activity.ChatActivity.java

/**
 * // w  w w .j a  v a2s  .  com
 */
private void init_new_emotions(final String path) {
    File file = new File(emotions_base_path);
    File[] files = file.listFiles();// ?
    for (File f : files) {
        if (path == null) {
            return;
        }
        if (f == null) {
            return;
        }
        if (!file.exists() || !file.isDirectory()) {
            return;
        }
        // if (f.listFiles().length == 0) {
        // return;
        // }
        if (path.equals(f.getName())) {// ??
            File[] file_image_list = f.listFiles();
            image_path = new ArrayList<String>();
            image_name = new ArrayList<String>();
            if (file_image_list == null) {
                return;
            }
            for (int j = 0; j < file_image_list.length; j++) {
                File file_image = file_image_list[j];
                try {
                    String newFileName = new String(file_image.getName().getBytes(), "UTF-8");
                    if (newFileName.contains(big_cover_name) || newFileName.contains(simall_cover_name)) {
                        // 
                        final ImageView iv_bottom_emotion = new ImageView(ChatActivity.this);
                        Bitmap decodeFile = BitmapFactory.decodeFile(file_image.getAbsolutePath());
                        iv_bottom_emotion.setImageBitmap(decodeFile);
                        int screen_width = ViewUtil.getScreenWidth(ChatActivity.this);
                        layoutParams.width = screen_width / 8;
                        layoutParams.height = screen_width / 8;
                        iv_bottom_emotion.setLayoutParams(layoutParams);
                        iv_bottom_emotion.setBackgroundResource(R.drawable.grid_line);
                        iv_bottom_emotion.setTag(path);
                        // imag_list.add(iv_bottom_emotion);
                        imag_list.add(0, iv_bottom_emotion);
                        iv_bottom_emotion.setOnClickListener(new OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                // TODO Auto-generated method stub
                                selected_pager = (String) iv_bottom_emotion.getTag();
                                iv_expression_emoji.setBackgroundResource(R.drawable.grid_line);
                                for (ImageView iv : imag_list) {
                                    if (selected_pager.equals(iv.getTag())) {
                                        iv.setBackgroundResource(R.drawable.grid_line_press);
                                    } else {
                                        iv.setBackgroundResource(R.drawable.grid_line);
                                    }
                                }
                                search_selected_emotions((String) iv_bottom_emotion.getTag());
                            }
                        });

                        ll_emotions_content.addView(iv_bottom_emotion);
                        viewpager.setTag(tab_emotions_tag);// ?
                    }
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }

        }
    }
}

From source file:cm.aptoide.pt.MainActivity.java

private void loadUIEditorsApps() {

    final int[] res_ids = { R.id.central, R.id.topleft, R.id.topright, R.id.bottomleft, R.id.bottomcenter,
            R.id.bottomright };/*www  .  j  a v a 2 s  . c  o  m*/
    final ArrayList<HashMap<String, String>> image_urls = db.getFeaturedGraphics();
    final HashMap<String, String> image_url_highlight = db.getHighLightFeature();

    //        System.out.println(image_url_highlight + "ASDASDASDASD");
    //        System.out.println(image_urls + "ASDASDASDASD");

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (image_url_highlight.size() > 0) {
                a = 1;
                ImageView v = (ImageView) featuredView.findViewById(res_ids[0]);
                // imageLoader.DisplayImage(-1, image_url_highlight.get("url"), v,
                // mContext);
                DisplayImageOptions options = new DisplayImageOptions.Builder()
                        .displayer(new FadeInBitmapDisplayer(1000)).cacheOnDisc().cacheInMemory().build();
                cm.aptoide.com.nostra13.universalimageloader.core.ImageLoader.getInstance()
                        .displayImage(image_url_highlight.get("url"), v, options);
                v.setTag(image_url_highlight.get("id"));
                v.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {

                        Intent i = new Intent(MainActivity.this, ApkInfo.class);
                        i.putExtra("_id", Long.parseLong((String) arg0.getTag()));
                        i.putExtra("top", false);
                        i.putExtra("category", Category.EDITORSCHOICE.ordinal());
                        startActivity(i);

                    }
                });
                // v.setOnClickListener(featuredListener);
            }
        }
    });

    Collections.shuffle(image_urls);
    runOnUiThread(new Runnable() {

        public void run() {

            for (int i = a; i != res_ids.length; i++) {
                try {
                    ImageView v = (ImageView) featuredView.findViewById(res_ids[i]);

                    // imageLoader.DisplayImage(-1,
                    // image_urls.get(i).get("url"), v, mContext);
                    DisplayImageOptions options = new DisplayImageOptions.Builder()
                            .displayer(new FadeInBitmapDisplayer(1000)).cacheOnDisc().cacheInMemory().build();
                    cm.aptoide.com.nostra13.universalimageloader.core.ImageLoader.getInstance()
                            .displayImage(image_urls.get(i - a).get("url"), v, options);

                    v.setTag(image_urls.get(i - a).get("id"));
                    v.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent i = new Intent(MainActivity.this, ApkInfo.class);
                            i.putExtra("_id", Long.parseLong((String) arg0.getTag()));
                            i.putExtra("top", false);
                            i.putExtra("category", Category.EDITORSCHOICE.ordinal());
                            startActivity(i);
                        }
                    });
                    // v.setOnClickListener(featuredListener);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }
    });
}

From source file:fr.shywim.antoinedaniel.ui.fragment.VideoDetailsFragment.java

private void bindMusic(View view, Cursor cursor) {
    final TextView titleView = (TextView) view.findViewById(R.id.music_title);
    final TextView artistView = (TextView) view.findViewById(R.id.music_artist);
    final TextView timeView = (TextView) view.findViewById(R.id.music_time);
    final ImageView artView = (ImageView) view.findViewById(R.id.music_art);
    final Button youtubeView = (Button) view.findViewById(R.id.music_youtube);
    final Button gplayView = (Button) view.findViewById(R.id.music_gplay);
    final Button amazonView = (Button) view.findViewById(R.id.music_amazon);

    // Title//from   w w w .j  a v a  2 s . c om
    String title = cursor.getString(cursor.getColumnIndex(ProviderContract.MusicEntry.COLUMN_TITLE));
    titleView.setText(title);
    // Artist
    String artist = cursor.getString(cursor.getColumnIndex(ProviderContract.MusicEntry.COLUMN_ARTIST));
    artistView.setText(artist);
    // Ep Link (Time, Click)
    final String epLink = cursor
            .getString(cursor.getColumnIndex(ProviderContract.MusicEntry.COLUMN_EPISODE_LINK));
    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(mContext.getString(R.string.youtube_link_prefix) + epLink));
            mContext.startActivity(intent);
        }
    });
    if (epLink.contains("?t=")) {
        timeView.setText(epLink.substring(epLink.indexOf('=') + 1));
    }
    // Store Links
    final String ytLink = cursor.getString(cursor.getColumnIndex(ProviderContract.MusicEntry.COLUMN_YOUTUBE));
    if (ytLink == null || ytLink.isEmpty()) {
        youtubeView.setEnabled(false);
    } else {
        youtubeView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(mContext.getString(R.string.youtube_link_prefix) + ytLink));
                mContext.startActivity(intent);
            }
        });
        youtubeView.setEnabled(true);
    }
    final String gpLink = cursor.getString(cursor.getColumnIndex(ProviderContract.MusicEntry.COLUMN_GPLAY));
    if (gpLink == null || gpLink.isEmpty()) {
        gplayView.setEnabled(false);
    } else {
        gplayView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(mContext.getString(R.string.play_music_prefix) + gpLink));
                mContext.startActivity(intent);
            }
        });
        gplayView.setEnabled(true);
    }
    final String amLink = cursor.getString(cursor.getColumnIndex(ProviderContract.MusicEntry.COLUMN_AMAZON));
    if (amLink == null || amLink.isEmpty()) {
        amazonView.setEnabled(false);
    } else {
        amazonView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(mContext.getString(R.string.amazon_prefix) + amLink));
                mContext.startActivity(intent);
            }
        });
        amazonView.setEnabled(true);
    }
    artView.setTag(ytLink);

    String file = mContext.getString(R.string.api_get_yt_thmb_music) + ytLink;
    Picasso.with(mContext).load(file).placeholder(R.drawable.noimg).into(artView);
}

From source file:com.nttec.everychan.ui.tabs.TabsAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView == null ? inflater.inflate(R.layout.sidebar_tabitem, parent, false) : convertView;
    View dragHandler = view.findViewById(R.id.tab_drag_handle);
    ImageView favIcon = (ImageView) view.findViewById(R.id.tab_favicon);
    TextView title = (TextView) view.findViewById(R.id.tab_text_view);
    ImageView closeBtn = (ImageView) view.findViewById(R.id.tab_close_button);

    dragHandler.getLayoutParams().width = position == draggingItem ? ViewGroup.LayoutParams.WRAP_CONTENT : 0;
    dragHandler.setLayoutParams(dragHandler.getLayoutParams());

    if (position == selectedItem) {
        TypedValue typedValue = ThemeUtils.resolveAttribute(context.getTheme(), R.attr.sidebarSelectedItem,
                true);/*from  w  w w  . jav a2 s . c  om*/
        if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT
                && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
            view.setBackgroundColor(typedValue.data);
        } else {
            view.setBackgroundResource(typedValue.resourceId);
        }
    } else {
        view.setBackgroundColor(Color.TRANSPARENT);
    }

    TabModel model = this.getItem(position);

    switch (model.type) {
    case TabModel.TYPE_NORMAL:
    case TabModel.TYPE_LOCAL:
        closeBtn.setVisibility(View.VISIBLE);
        String titleText = model.title;
        if (model.unreadPostsCount > 0 || model.autoupdateError) {
            StringBuilder titleStringBuilder = new StringBuilder();
            if (model.unreadSubscriptions)
                titleStringBuilder.append("[*] ");
            if (model.autoupdateError)
                titleStringBuilder.append("[X] ");
            if (model.unreadPostsCount > 0)
                titleStringBuilder.append('[').append(model.unreadPostsCount).append("] ");
            titleText = titleStringBuilder.append(titleText).toString();
        }
        title.setText(titleText);
        ChanModule chan = MainApplication.getInstance().getChanModule(model.pageModel.chanName);
        Drawable icon = chan != null ? chan.getChanFavicon()
                : ResourcesCompat.getDrawable(context.getResources(), android.R.drawable.ic_delete, null);
        if (icon != null) {
            if (model.type == TabModel.TYPE_LOCAL) {
                Drawable[] layers = new Drawable[] { icon, ResourcesCompat.getDrawable(context.getResources(),
                        R.drawable.favicon_overlay_local, null) };
                icon = new LayerDrawable(layers);
            }
            /* XXX
             ?       ( overlay  favicon    ),
             ?   ?? ,   ,     (   ).
            ?    ? ? , , ? -? -  ,    ?.
               ??  ?,   ? ?  .
                    
            else if (model.type == TabModel.TYPE_NORMAL && model.pageModel != null &&
                    model.pageModel.type == UrlPageModel.TYPE_THREADPAGE && model.autoupdateBackground &&
                    MainApplication.getInstance().settings.isAutoupdateEnabled() &&
                    MainApplication.getInstance().settings.isAutoupdateBackground()) {
                Drawable[] layers = new Drawable[] {
                        icon, ResourcesCompat.getDrawable(context.getResources(), R.drawable.favicon_overlay_autoupdate, null) };
                icon = new LayerDrawable(layers);
            }
            */
            favIcon.setImageDrawable(icon);
            favIcon.setVisibility(View.VISIBLE);
        } else {
            favIcon.setVisibility(View.GONE);
        }
        break;
    default:
        closeBtn.setVisibility(View.GONE);
        title.setText(R.string.error_deserialization);
        favIcon.setVisibility(View.GONE);
    }

    closeBtn.setTag(position);
    closeBtn.setOnClickListener(onCloseClick);
    return view;
}