Example usage for android.graphics.drawable LayerDrawable getDrawable

List of usage examples for android.graphics.drawable LayerDrawable getDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable LayerDrawable getDrawable.

Prototype

public Drawable getDrawable(int index) 

Source Link

Document

Returns the drawable for the layer at the specified index.

Usage

From source file:android.support.v7.widget.AppCompatProgressBarHelper.java

/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 *///  www  .j  a  v a2s . c o  m
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof DrawableWrapper) {
        Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable();
        if (inner != null) {
            inner = tileify(inner, clip);
            ((DrawableWrapper) drawable).setWrappedDrawable(inner);
        }
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];

        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i),
                    (id == android.R.id.progress || id == android.R.id.secondaryProgress));
        }
        LayerDrawable newBg = new LayerDrawable(outDrawables);

        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }

        return newBg;

    } else if (drawable instanceof BitmapDrawable) {
        final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        final Bitmap tileBitmap = bitmapDrawable.getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
        final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT,
                Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);
        shapeDrawable.getPaint().setColorFilter(bitmapDrawable.getPaint().getColorFilter());
        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}

From source file:android.support.v7.internal.widget.TintRatingBar.java

/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 *//*from ww  w . ja v  a  2  s.  c  o m*/
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof DrawableWrapper) {
        Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable();
        if (inner != null) {
            inner = tileify(inner, clip);
            ((DrawableWrapper) drawable).setWrappedDrawable(inner);
        }
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];

        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i),
                    (id == android.R.id.progress || id == android.R.id.secondaryProgress));
        }
        LayerDrawable newBg = new LayerDrawable(outDrawables);

        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }

        return newBg;

    } else if (drawable instanceof BitmapDrawable) {
        final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
        final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT,
                Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);
        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}

From source file:com.google.android.apps.iosched.ui.ScheduleFragment.java

/**
 * {@inheritDoc}/*from   www . j a va2 s .  c  o m*/
 */
public void onQueryComplete(int token, Object cookie, Cursor cursor) {
    if (getActivity() == null) {
        return;
    }

    Day day = (Day) cookie;

    // Clear out any existing sessions before inserting again
    day.blocksView.removeAllBlocks();

    try {
        while (cursor.moveToNext()) {
            final String type = cursor.getString(BlocksQuery.BLOCK_TYPE);
            final Integer column = sTypeColumnMap.get(type);
            // TODO: place random blocks at bottom of entire layout
            if (column == null) {
                continue;
            }

            final String blockId = cursor.getString(BlocksQuery.BLOCK_ID);
            final String title = cursor.getString(BlocksQuery.BLOCK_TITLE);
            final long start = cursor.getLong(BlocksQuery.BLOCK_START);
            final long end = cursor.getLong(BlocksQuery.BLOCK_END);
            final boolean containsStarred = cursor.getInt(BlocksQuery.CONTAINS_STARRED) != 0;

            final BlockView blockView = new BlockView(getActivity(), blockId, title, start, end,
                    containsStarred, column);

            final int sessionsCount = cursor.getInt(BlocksQuery.SESSIONS_COUNT);
            if (sessionsCount > 0) {
                blockView.setOnClickListener(this);
            } else {
                blockView.setFocusable(false);
                blockView.setEnabled(false);
                LayerDrawable buttonDrawable = (LayerDrawable) blockView.getBackground();
                buttonDrawable.getDrawable(0).setAlpha(DISABLED_BLOCK_ALPHA);
                buttonDrawable.getDrawable(2).setAlpha(DISABLED_BLOCK_ALPHA);
            }

            day.blocksView.addBlock(blockView);
        }
    } finally {
        cursor.close();
    }
}

From source file:org.dalmasso.ietfsched.ui.ScheduleFragment.java

/**
 * {@inheritDoc}/*from w ww . ja v  a 2s  . com*/
 */
public void onQueryComplete(int token, Object cookie, Cursor cursor) {
    //      Log.d(TAG, "onQueryComplete cursor " + cursor + "activity " + getActivity() + "count rows " + cursor.getCount());
    if (getActivity() == null) {
        return;
    }

    Day day = (Day) cookie;

    // Clear out any existing sessions before inserting again
    day.blocksView.removeAllBlocks();

    try {
        while (cursor.moveToNext()) {
            final String type = cursor.getString(BlocksQuery.BLOCK_TYPE);
            final Integer column = sTypeColumnMap.get(type);
            // TODO: place random blocks at bottom of entire layout
            if (column == null) {
                continue;
            }

            final String blockId = cursor.getString(BlocksQuery.BLOCK_ID);
            final String title = cursor.getString(BlocksQuery.BLOCK_TITLE);
            final long start = cursor.getLong(BlocksQuery.BLOCK_START);
            final long end = cursor.getLong(BlocksQuery.BLOCK_END);
            final boolean containsStarred = cursor.getInt(BlocksQuery.CONTAINS_STARRED) != 0;

            final BlockView blockView = new BlockView(getActivity(), blockId, title, start, end,
                    containsStarred, column);

            final int sessionsCount = cursor.getInt(BlocksQuery.SESSIONS_COUNT);
            if (sessionsCount > 0) {
                blockView.setOnClickListener(this);
            } else {
                blockView.setFocusable(false);
                blockView.setEnabled(false);
                LayerDrawable buttonDrawable = (LayerDrawable) blockView.getBackground();
                buttonDrawable.getDrawable(0).setAlpha(DISABLED_BLOCK_ALPHA);
                buttonDrawable.getDrawable(2).setAlpha(DISABLED_BLOCK_ALPHA);
            }

            day.blocksView.addBlock(blockView);
        }
    } finally {
        cursor.close();
    }
}

From source file:com.infine.android.devoxx.ui.ScheduleFragment.java

/**
 * {@inheritDoc}/*w  w w .  j  a v  a 2 s.  c  o m*/
 */
public void onQueryComplete(int token, Object cookie, Cursor cursor) {
    if (getActivity() == null) {
        return;
    }

    Day day = (Day) cookie;

    // Clear out any existing sessions before inserting again
    day.blocksView.removeAllBlocks();

    try {
        while (cursor.moveToNext()) {
            final String type = cursor.getString(BlocksQuery.BLOCK_CATEGORY);
            // final Integer column = sTypeColumnMap.get(type);
            BlockColumnType columnType = BlockColumnType.typeOf(type);
            if (columnType == null || columnType == BlockColumnType.UNDEFINED) {
                continue;
            }

            final String blockId = cursor.getString(BlocksQuery.BLOCK_ID);
            final String title = cursor.getString(BlocksQuery.BLOCK_TITLE);
            final long start = cursor.getLong(BlocksQuery.BLOCK_START);
            final long end = cursor.getLong(BlocksQuery.BLOCK_END);
            final int nbStar = cursor.getInt(BlocksQuery.COUNT_STARRED);
            final String titleStarred = cursor.getString(BlocksQuery.TITLE_STARRED);

            // TODO : temporary to manage code story
            columnType = patchColumnType(columnType, start, end);

            String blockTitle = title;
            if (title.contains("Code-Story")) {
                blockTitle = "Code story";
            }
            if (title.contains("Devoxx4Kids")) {
                blockTitle = "Devoxx4Kids";
            }
            if (title.contains("Devops Mercenaries")) {
                blockTitle = "Devops Mercenaries";
            }

            final BlockView blockView = new BlockView(getActivity(), blockId, blockTitle, start, end, nbStar,
                    titleStarred != null ? titleStarred : "", columnType);

            final int sessionsCount = cursor.getInt(BlocksQuery.SESSIONS_COUNT);
            if (sessionsCount > 0) {
                blockView.setOnClickListener(this);
            } else {
                blockView.setFocusable(false);
                blockView.setEnabled(false);
                LayerDrawable buttonDrawable = (LayerDrawable) blockView.getBackground();
                buttonDrawable.getDrawable(0).setAlpha(DISABLED_BLOCK_ALPHA);
                buttonDrawable.getDrawable(2).setAlpha(DISABLED_BLOCK_ALPHA);
            }

            day.blocksView.addBlock(blockView);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
}

From source file:uk.co.brightec.ratetheapp.RateTheApp.java

/**
 * Converts a drawable to a tiled version of itself. It will recursively traverse layer and state list drawables.
 * This method was copied from android.widget.ProgressBar, however it was highlighted in their code that this may be sub optimal.
 *
 * @param drawable The drawable to tileify
 * @param clip     Whether to clip drawable
 * @return The tiled drawable//from   ww  w.j a v a  2 s  .  co m
 */
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof LayerDrawable) {
        final LayerDrawable orig = (LayerDrawable) drawable;
        final int N = orig.getNumberOfLayers();
        final Drawable[] outDrawables = new Drawable[N];

        for (int i = 0; i < N; i++) {
            final int id = orig.getId(i);
            outDrawables[i] = tileify(orig.getDrawable(i),
                    (id == android.R.id.progress || id == android.R.id.secondaryProgress));
        }

        final LayerDrawable clone = new LayerDrawable(outDrawables);
        for (int i = 0; i < N; i++) {
            clone.setId(i, orig.getId(i));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                clone.setLayerGravity(i, orig.getLayerGravity(i));
                clone.setLayerWidth(i, orig.getLayerWidth(i));
                clone.setLayerHeight(i, orig.getLayerHeight(i));
                clone.setLayerInsetLeft(i, orig.getLayerInsetLeft(i));
                clone.setLayerInsetRight(i, orig.getLayerInsetRight(i));
                clone.setLayerInsetTop(i, orig.getLayerInsetTop(i));
                clone.setLayerInsetBottom(i, orig.getLayerInsetBottom(i));
                clone.setLayerInsetStart(i, orig.getLayerInsetStart(i));
                clone.setLayerInsetEnd(i, orig.getLayerInsetEnd(i));
            }
        }

        return clone;
    }

    if (drawable instanceof BitmapDrawable) {
        final BitmapDrawable bitmap = (BitmapDrawable) drawable;

        final BitmapDrawable clone = (BitmapDrawable) bitmap.getConstantState().newDrawable();
        clone.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);

        if (clip) {
            return new ClipDrawable(clone, Gravity.LEFT, ClipDrawable.HORIZONTAL);
        } else {
            return clone;
        }
    }

    return drawable;
}

From source file:tw.idv.gasolin.pycontw2012.ui.ScheduleFragment.java

/**
 * {@inheritDoc}//from  w w  w .j av  a 2  s . c  om
 */
public void onQueryComplete(int token, Object cookie, Cursor cursor) {
    if (getActivity() == null) {
        return;
    }

    Day day = (Day) cookie;

    // Clear out any existing sessions before inserting again
    day.blocksView.removeAllBlocks();

    ArrayList<BlockView> bvs = new ArrayList<BlockView>();

    try {
        while (cursor.moveToNext()) {
            final String type = cursor.getString(BlocksQuery.BLOCK_TYPE);
            final Integer column = sTypeColumnMap.get(type);
            // TODO: place random blocks at bottom of entire layout
            if (column == null) {
                continue;
            }

            final String blockId = cursor.getString(BlocksQuery.BLOCK_ID);
            String title = cursor.getString(BlocksQuery.BLOCK_TITLE);
            final long start = cursor.getLong(BlocksQuery.BLOCK_START);
            final long end = cursor.getLong(BlocksQuery.BLOCK_END);
            final boolean containsStarred = cursor.getInt(BlocksQuery.CONTAINS_STARRED) != 0;

            if (TextUtils.equals(title, ParserUtils.BLOCK_TITLE_BREAKOUT_SESSIONS)) {
                title = getString(R.string.block_title_breakout_sessions);
            }

            final BlockView blockView = new BlockView(getActivity(), blockId, title, start, end,
                    containsStarred, column);

            final int sessionsCount = cursor.getInt(BlocksQuery.SESSIONS_COUNT);
            if (sessionsCount > 0) {
                blockView.setOnClickListener(this);
            } else {
                blockView.setFocusable(false);
                blockView.setEnabled(false);
                LayerDrawable buttonDrawable = (LayerDrawable) blockView.getBackground();
                buttonDrawable.getDrawable(0).setAlpha(DISABLED_BLOCK_ALPHA);
                buttonDrawable.getDrawable(2).setAlpha(DISABLED_BLOCK_ALPHA);
            }

            bvs.add(blockView);
        }
    } finally {
        cursor.close();
    }

    ArrayList<BlockView> groupList = new ArrayList<BlockView>();
    for (BlockView curr : bvs) {
        int groupSize = groupList.size();
        BlockView prev = null;
        if (groupSize > 0) {
            for (int i = groupSize - 1; i >= 0; i--) {
                BlockView bv = groupList.get(i);
                if (prev == null) {
                    prev = bv;
                } else {
                    if (bv.getEndTime() > prev.getEndTime() || (bv.getEndTime() == prev.getEndTime()
                            && bv.getStartTime() < prev.getStartTime())) {
                        prev = bv;
                    }
                }
            }
        }

        if (BlockView.areOverlapping(prev, curr)) {
            // there is an overlap

            final int prevMaxSubCols = prev.getMaxSubColumns();
            int subcol = prevMaxSubCols;

            for (int i = 0; i < groupSize; i++) {
                BlockView thisBv = groupList.get(i);
                BlockView nextBv = (i + 1 == groupSize) ? null : groupList.get(i + 1);
                if (nextBv == null || thisBv.getSubColumn() != nextBv.getSubColumn()) {
                    if (!BlockView.areOverlapping(curr, thisBv)) {
                        subcol = thisBv.getSubColumn();
                        break;
                    }
                }
            }

            curr.setSubColumn(subcol);
            if (subcol < prevMaxSubCols) {
                curr.setMaxSubColumns(prevMaxSubCols);
            } else {
                curr.setMaxSubColumns(prevMaxSubCols + 1);
                for (BlockView bv : groupList) {
                    bv.setMaxSubColumns(prevMaxSubCols + 1);
                }
            }

        } else {
            // no overlap
            curr.setSubColumn(0);
            curr.setMaxSubColumns(1);
            groupList.clear();
            groupSize = 0;
        }

        int insertAt = 0;
        for (int i = 0; i < groupSize; i++) {
            BlockView bv = groupList.get(i);
            if (bv.getSubColumn() > curr.getSubColumn()) {
                insertAt = i;
                break;
            }
        }
        groupList.add(insertAt, curr);
    }

    for (BlockView blockView : bvs) {
        day.blocksView.addBlock(blockView);
    }
}

From source file:com.z299studio.pb.MainListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (Application.getInstance() == null || Application.getInstance().getAccountManager() == null) {
        return null;
    }//  ww  w.j  a v a2  s . c om
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);
    mListView = (ListView) rootView.findViewById(android.R.id.list);
    if ((mAdapter = getAdapter(mCategoryId)) == null) {
        mAdapter = new MainListAdapter(getActivity(),
                Application.getInstance().getAccountManager().getAccountsByCategory(mCategoryId),
                Application.getThemedIcons(), R.drawable.pb_unknown);
        mListView.postDelayed(new Runnable() {
            @Override
            public void run() {
                mAdapter.enableAnimation(false);
            }
        }, 100);
        cacheAdapter(mCategoryId, mAdapter);
    }
    mAdapter.setListener(this);
    mListView.setAdapter(mAdapter);
    mListView.setEmptyView(rootView.findViewById(android.R.id.empty));
    mListView.setOnItemClickListener(this);
    mListView.setOnItemLongClickListener(this);
    mToBeRemoved = new int[mAdapter.getCount()];
    mFab = (ImageButton) rootView.findViewById(R.id.fab);
    mFab.setOnClickListener(this);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
        LayerDrawable background = (LayerDrawable) mFab.getBackground();
        background.getDrawable(1).setColorFilter(C.ThemedColors[C.colorAccent], PorterDuff.Mode.SRC_ATOP);
    }
    if (!getResources().getBoolean(R.bool.snackbar_left_align)) {
        mFabToPush = (int) (getResources().getDimension(R.dimen.snackbar_height_single) + 0.5f);
    } else {
        mFabToPush = 0;
    }
    mCategoryEditView = rootView.findViewById(R.id.category_editor);
    EditText editCategoryName = (EditText) rootView.findViewById(R.id.category_name);
    editCategoryName.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (mActionMode != null) {
                mCategoryName = s.toString();
                mCategorySavable = mCategoryName.length() > 0;
                mActionMode.invalidate();
            }
        }
    });
    if (mIsEditing) {
        mIsEditing = false;
        editCategory();
    } else if (mSelectionMode) {
        mActionMode = ((MainActivity) getActivity()).startSupportActionMode(mActionModeCallback);
    }
    return rootView;
}

From source file:com.lamcreations.scaffold.common.views.RoundedImageView.java

private void updateAttrs(Drawable drawable) {
    if (drawable == null) {
        return;// ww  w  .j a va 2  s  .c  om
    }

    if (drawable instanceof RoundedDrawable) {
        ((RoundedDrawable) drawable).setScaleType(mScaleType).setBorderWidth(mBorderWidth)
                .setBorderColor(mBorderColor).setOval(mIsOval).setTileModeX(mTileModeX)
                .setTileModeY(mTileModeY);

        if (mCornerRadii != null) {
            ((RoundedDrawable) drawable).setCornerRadius(mCornerRadii[Corner.TOP_LEFT],
                    mCornerRadii[Corner.TOP_RIGHT], mCornerRadii[Corner.BOTTOM_RIGHT],
                    mCornerRadii[Corner.BOTTOM_LEFT]);
        }

        applyColorMod();
    } else if (drawable instanceof LayerDrawable) {
        // loop through layers to and set drawable attrs
        LayerDrawable ld = ((LayerDrawable) drawable);
        for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++) {
            updateAttrs(ld.getDrawable(i));
        }
    }
}

From source file:audio.lisn.adapter.StoreBookViewAdapter.java

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    final AudioBook book = items.get(position);
    selectedBookIndex = position;//from  w w w  .j  av a2 s  . c om

    if ((isLoadingPreview || isPlayingPreview) && selectedAudioBook != null
            && selectedAudioBook.getBook_id().equalsIgnoreCase(book.getBook_id())) {
        holder.previewLayout.setVisibility(View.VISIBLE);
        holder.playButton.setImageResource(R.drawable.btn_play_preview_pause);

        if (isPlayingPreview) {
            holder.spinner.setVisibility(View.INVISIBLE);
            holder.previewLabel.setText("Preview");
            holder.timeLabel.setText(leftTime);

        } else {
            holder.spinner.setVisibility(View.VISIBLE);
            holder.previewLabel.setText("Loading...");
            holder.timeLabel.setText("");
        }
    } else {
        holder.previewLayout.setVisibility(View.GONE);
        holder.playButton.setImageResource(R.drawable.btn_play_preview_start);
    }
    if (book.getLanguageCode() == AudioBook.LanguageCode.LAN_SI) {
        holder.title.setTypeface(CustomTypeFace.getSinhalaTypeFace(holder.title.getContext()));
        holder.author.setTypeface(CustomTypeFace.getSinhalaTypeFace(holder.author.getContext()));
        holder.title.setEllipsized("'''");
        holder.author.setEllipsized("'''");
    } else {
        holder.title.setTypeface(CustomTypeFace.getEnglishTypeFace(holder.title.getContext()));
        holder.author.setTypeface(CustomTypeFace.getEnglishTypeFace(holder.author.getContext()));
        holder.title.setEllipsized("...");
        holder.author.setEllipsized("...");

    }
    if (book.isAwarded()) {
        holder.awardIcon.setVisibility(View.VISIBLE);

    } else {
        holder.awardIcon.setVisibility(View.GONE);
    }
    holder.title.setText(book.getTitle());
    holder.author.setText(book.getAuthor());
    String priceText = "Free";
    if (Float.parseFloat(book.getPrice()) > 0) {
        priceText = "Rs. " + book.getPrice();
    }
    if (AppController.getInstance().isUserLogin() && book.isPurchase()) {
        holder.downloadedIcon.setVisibility(View.VISIBLE);
        holder.price.setVisibility(View.GONE);

    } else {
        holder.downloadedIcon.setVisibility(View.GONE);
        holder.price.setVisibility(View.VISIBLE);

    }
    holder.price.setText(priceText);
    LayerDrawable stars = (LayerDrawable) holder.ratingBar.getProgressDrawable();
    stars.getDrawable(2).setColorFilter(
            ContextCompat.getColor(holder.ratingBar.getContext(), R.color.colorPrimary),
            PorterDuff.Mode.SRC_ATOP);

    if (Float.parseFloat(book.getRate()) > -1) {
        holder.ratingBar.setRating(Float.parseFloat(book.getRate()));
    }

    holder.ratingBar.setIsIndicator(true);
    holder.thumbNail.setImageBitmap(null);
    //        if(position==1){
    //            Picasso.with(holder.thumbNail.getContext())
    //                    .load("http://images.veerle.duoh.com/uploads/design-article-images/adaptive-web-bookcover-final-design.jpg")
    //                    .placeholder(R.drawable.audiobook_placeholder)
    //                    .into(holder.thumbNail);
    //
    //        }else {
    Picasso.with(holder.thumbNail.getContext()).load(book.getCover_image()).placeholder(R.drawable.ic_launcher)
            .into(holder.thumbNail);

    holder.optionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
            if (AppController.getInstance().isUserLogin() && book.isPurchase()) {
                if (book.getAudioFileCount() == book.getDownloadedChapter().size()) {
                    popupMenu.inflate(R.menu.store_book_menu_downloaded);

                } else {
                    popupMenu.inflate(R.menu.store_book_menu_free);

                }

            } else {
                if (Float.parseFloat(book.getPrice()) < 1) {
                    popupMenu.inflate(R.menu.store_book_menu_free);

                } else {
                    popupMenu.inflate(R.menu.store_book_menu);

                }
            }
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    AudioBook audioBook = items.get(selectedBookIndex);

                    switch (item.getItemId()) {
                    case R.id.action_preview:
                        releaseMediaPlayer();
                        selectedView = holder.itemView;
                        playButtonPressed((AudioBook) holder.itemView.getTag());
                        break;
                    case R.id.action_purchase:
                        selectedAction = AudioBook.SelectedAction.ACTION_PURCHASE;

                        //                                releaseMediaPlayer();
                        //                                if (listener != null) {
                        //                                    new Handler().postDelayed(new Runnable() {
                        //                                        @Override public void run() {
                        //                                            listener.onStoreBookSelect(holder.itemView,(AudioBook) holder.itemView.getTag(),AudioBook.SelectedAction.ACTION_PURCHASE);
                        //                                        }
                        //                                    }, 200);
                        //                                }
                        break;
                    case R.id.action_detail:
                        selectedAction = AudioBook.SelectedAction.ACTION_DETAIL;

                        //                                releaseMediaPlayer();
                        //                                if (listener != null) {
                        //                                    new Handler().postDelayed(new Runnable() {
                        //                                        @Override public void run() {
                        //                                            listener.onStoreBookSelect(holder.itemView,(AudioBook) holder.itemView.getTag(),AudioBook.SelectedAction.ACTION_DETAIL);
                        //                                        }
                        //                                    }, 200);
                        //                                }
                        break;
                    case R.id.action_play:
                        selectedAction = AudioBook.SelectedAction.ACTION_PLAY;

                        //                                releaseMediaPlayer();
                        //                                if (listener != null) {
                        //                                    new Handler().postDelayed(new Runnable() {
                        //                                        @Override public void run() {
                        //                                            listener.onStoreBookSelect(holder.itemView,(AudioBook) holder.itemView.getTag(),AudioBook.SelectedAction.ACTION_PLAY);
                        //                                        }
                        //                                    }, 200);
                        //                                }
                        break;
                    case R.id.action_download:
                        selectedAction = AudioBook.SelectedAction.ACTION_DOWNLOAD;

                        break;
                    default:
                        break;

                    }
                    if (selectedAction != AudioBook.SelectedAction.ACTION_MORE) {
                        releaseMediaPlayer();
                        if (listener != null) {
                            new Handler().postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    listener.onStoreBookSelect(holder.itemView,
                                            (AudioBook) holder.itemView.getTag(), selectedAction);
                                }
                            }, 200);
                        }
                    }

                    return true;
                }
            });
            popupMenu.show();

        }
    });

    holder.playButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            selectedView = holder.itemView;
            playButtonPressed((AudioBook) holder.itemView.getTag());

        }
    });
    holder.itemView.setTag(book);
}