java GalleryViewAdapter_WITH_BUG.java

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java GalleryViewAdapter_WITH_BUG.java相关的知识,希望对你有一定的参考价值。

package com.slingmedia.adolslinguilib;

import java.lang.ref.WeakReference;
import java.util.concurrent.TimeUnit;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.text.Html;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

import com.slingmedia.MyTransfers.DeviceManagementController;
import com.slingmedia.OnDemandCommonData.MediaCardContent;
import com.slingmedia.ParentalControls.PCController;
import com.slingmedia.adolslinglib.constants.DBCommon;
import com.slingmedia.adolslinglib.constants.Networks;
import com.slingmedia.adolslinglib.provider.DOLContentProvider;
import com.slingmedia.api.DOLCoreAPI;
import com.slingmedia.profiles.SGProfileManagerData;
import com.slingmedia.utils.LibUtils;
import com.slingmedia.utils.Utils;
import com.slingmedia.webmc.SGOnDemandMediacardData;
import com.sm.SlingGuide.SlingGuideApp;
import com.sm.SlingGuide.Data.DetailedProgramInfo;
import com.sm.SlingGuide.Engine.ImageCache.SGImageLoader;
import com.sm.SlingGuide.Interfaces.ISGBottombarInterface;
import com.sm.SlingGuide.SGConstants.TabConstants;
import com.sm.SlingGuide.Utils.FlurryLogger;
import com.sm.SlingGuide.Utils.RubenAnalyticsInfo;
import com.sm.SlingGuide.Utils.SGProgramsUtils;
import com.sm.SlingGuide.Utils.SGUIUtils;
import com.sm.SlingGuide.Utils.SGUserActionHandler;
import com.sm.SlingGuide.Utils.SGUtil;
import com.sm.dra2.Data.WatchListData;
import com.sm.dra2.interfaces.ISGHomeActivityInterface;
import com.sm.homescreen.interfaces.ISGHomeScreenActivityInterface;

public class GalleryViewAdapter extends MyCursorAdapter
        implements
        MediaCardPeviewFragment.IClosePreviewListener,
        OnScrollListener {
    private static final String _TAG = "GalleryViewAdapter";
    private Context context;
    private int contentType;
    private int itemsPerPage;
    private int _pageCount = 1;
    private SGImageLoader _imageloader = null;
    private PCController _pcController = null;
    private LayoutInflater _layoutInflater = null;
    private RelativeLayout _mcpreviewLayout = null;
    private MediaCardPeviewFragment _mcpreviewFragment = null;
    private int _programIconWidth;
    private int _programIconHeight;
    private final static int image_id = R.id.gallery_program_icon;
    private WatchListData _watchListData = WatchListData.getInstance(null);
    private boolean _isWatchList = SGUtil.isWatchListEnableMDConfig();
    private Bitmap _defaultBitmap = null;
    private PreviewLauncher _previewLauncher = null;
    private boolean _bIsInHomescreen = false;
    private int _marginTop = 0;
    // HOM MANY PAGES LOAD PER REQUEST
    public static final int NUM_PAGES_PER_LOAD = 3;

    // //////////////
    private int TEXT_COLOR_BLUE;
    private String TEXT_MINS;
    private String TEXT_HD;
    private String TEXT_LIVE;
    private String TEXT_OD;
    private String TEXT_GUIDE;

    private WeakReference<OnItemClickListener> _clickListener;
    private WeakReference<OnKeyListener> _onKeyListener;

    /*
     * Caching content only while in homescreen.
     */
    private SparseArray<MediaCardContent> _mediaContentMap = new SparseArray<MediaCardContent>();

    public GalleryViewAdapter(Context context, int layout, Cursor c, String[] from, int[] to, final int contentType,
                              final int itemsPerPage, final PCController pcController, final DeviceManagementController dmController,
                              final RelativeLayout mcpreviewLayout, final MediaCardPeviewFragment mcpreviewFragment,
                              final int programIconWidth, final int programIconHeight, boolean bIsInHomescreen, OnItemClickListener listener) {
        this(context, layout, c, from, to, contentType, itemsPerPage, pcController, dmController,
                mcpreviewLayout, mcpreviewFragment,
                programIconWidth, programIconHeight, bIsInHomescreen, listener, null);
    }

    public GalleryViewAdapter(Context context, int layout, Cursor c, String[] from, int[] to, final int contentType,
                              final int itemsPerPage, final PCController pcController, final DeviceManagementController dmController,
                              final RelativeLayout mcpreviewLayout, final MediaCardPeviewFragment mcpreviewFragment,
                              final int programIconWidth, final int programIconHeight, boolean bIsInHomescreen, OnItemClickListener listener, OnKeyListener onKey) {
        super(context, layout, c, from, to);

        this.context = context;
        this.contentType = contentType;
        this.itemsPerPage = itemsPerPage;
        _pcController = pcController;
        _programIconWidth = programIconWidth;
        _programIconHeight = programIconHeight;
        _layoutInflater = LayoutInflater.from(context);
        _imageloader = SGImageLoader.getInstance();
        if (!_imageloader.initImageLoader(context,
                BitmapFactory.decodeResource(context.getResources(), R.drawable.default_icon_small_dish))) {
            Log.e(GalleryViewAdapter.class.getName(), "Cannot Initialize ImageLoader");
            _imageloader = null;
        }
        _mcpreviewLayout = mcpreviewLayout;
        _mcpreviewFragment = mcpreviewFragment;
        _bIsInHomescreen = bIsInHomescreen;
        _marginTop = _bIsInHomescreen ? 0 : (int) context.getResources().getDimension(R.dimen.gallery_margin__top);

        // ///////////////
        TEXT_COLOR_BLUE = context.getResources().getColor(R.color.dra_blue);
        TEXT_MINS = context.getResources().getString(R.string.mins_label);
        TEXT_HD = context.getResources().getString(R.string.hd_label);

        TEXT_LIVE = context.getResources().getString(R.string.live_label);
        TEXT_OD = context.getResources().getString(R.string.od_label);
        TEXT_GUIDE = context.getResources().getString(R.string.guide_label);

        // intit mcpreview
        _mcpreviewFragment.initMediaCard(this);
        _defaultBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.default_channel_logo);
        _previewLauncher = new PreviewLauncher(context, mcpreviewFragment, mcpreviewLayout, pcController);
        if (null != listener) {
            _clickListener = new WeakReference<OnItemClickListener>(listener);
        }
        _onKeyListener = new WeakReference<OnKeyListener>(onKey);
    }

    @Override
    public int getCount() {
        return super.getCount();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        final int count = super.getCount();

        if (convertView == null) {
            convertView = _layoutInflater.inflate(R.layout.content_gallery_item, null);
            holder = new ViewHolder();
            holder.textView = (TextView) convertView.findViewById(R.id.gallery_prog_name);
            holder.imageView = (ImageView) convertView.findViewById(image_id);
            holder.loadingView = (View) convertView.findViewById(R.id.prog_loading);
            holder.countView = (TextView) convertView.findViewById(R.id.program_count);
            holder.programStatusIcon = (ImageView) convertView.findViewById(R.id.program_status_icon);
            holder.imagewNetworkIcon = (ImageView) convertView.findViewById(R.id.gallery_channel_icon);
            holder.miscDetailsView = (TextView) convertView.findViewById(R.id.misc_prog_info);
            holder.overlayTextView = (TextView) convertView.findViewById(R.id.program_overlay_text);
            holder.watchListIcon = (ImageView) convertView.findViewById(R.id.watch_list_program_icon);
            holder.programDeleteIcon = (ImageButton) convertView.findViewById(R.id.program_delete_icon);
            holder.programStarredIcon = (ImageButton) convertView.findViewById(R.id.program_starred_icon);
            holder.programDurationBar = (ProgressBar) convertView.findViewById(R.id.live_prog_duration_bar);
            updateViewDimensions(convertView, holder);
            convertView.setTag(holder); // non-null tag means that view needs
            if (null != _clickListener) {
                convertView.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Log.d(_TAG, "on click listener pos=" + position);
                        if (_clickListener != null) {
                            OnItemClickListener listener = _clickListener.get();
                            if (listener != null)
                                listener.onItemClick(null, v, position, 0);
                        }
                    }
                });
            }

            if (_onKeyListener != null) {
                OnKeyListener onKey = _onKeyListener.get();
                if (onKey != null)
                    convertView.setOnKeyListener(onKey);
            }
            // update at the position
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (position >= count) {
            if (count != 0) {
                convertView.setVisibility(View.GONE);
            }
        } else {
            try {
                final Cursor cursor = getCursor();
                if (cursor != null && cursor.moveToPosition(position)) {
                    final String mediaId = cursor.getString(DBCommon.DbColumnsIds.MEDIA_ID_COLUMN);
                    if (mediaId != null && !mediaId.isEmpty()) {
                        // program image
                        setThumbResource(holder.imageView, cursor, contentType);
                        holder.loadingView.setVisibility(View.GONE);
                        holder.imageView.setVisibility(View.VISIBLE);

                        ISGBottombarInterface bottombarFragment = null;
                        if (SlingGuideApp.getInstance().isPhoneApp()) {
                            bottombarFragment = (ISGBottombarInterface) ((Activity) context).getFragmentManager()
                                    .findFragmentById(R.id.bottombarfragment);
                        } else {
                            bottombarFragment = (ISGBottombarInterface) SlingGuideApp.getInstance().getBottomBar();
                        }

                        if (contentType == DOLContentProvider.NETWORKS_ALL) {
                            try {
                                // check not required
                                if (true) {// bottombarFragment != null && bottombarFragment.getLastUsedNavigationTabConstant()
                                    // !=
                                    // TabConstants.TAB_SHOWCASE) {
                                    holder.textView.setText(cursor.getString(Networks.DbColumnsIds.NAME_COLUMN));
                                }
                                // setLockNetwork(holder.imagewLockView, cursor);
                            } catch (Exception ex) {
                                // no lock
                            }
                        } else {
                            try {
                                final MediaCardContent mcContent = getMediaCardContent(position, cursor);
                                boolean showTitleUI = true; // logic changed to show title and avoid count
                                if (showTitleUI) {
                                    holder.textView.setText(cursor.getString(DBCommon.DbColumnsIds.FRANCHISE_NAME_COLUMN));
                                    showTitleUI = ((bottombarFragment != null) && (bottombarFragment
                                            .getLastUsedNavigationTabConstant() != TabConstants.TAB_SHOWCASE));
                                    if (showTitleUI) {
                                        setEpisodeNum(holder.countView, mcContent);
                                    }
                                }
                                updateItemDetails(holder.miscDetailsView, holder.programDurationBar, mcContent);
                                setNetworkLogo(mcContent, holder.imagewNetworkIcon);
                                boolean isLockPermanent = setLock(holder.overlayTextView, mcContent);
                                if (_isWatchList && !isLockPermanent) {
                                    handleWatchListIcon(holder.watchListIcon, mcContent);
                                }
                            } catch (Exception ex) {
                                // no lock
                            }
                        }
                    } else {
                        showEmptyItem(holder);
                    }
                }
            } catch (Exception ex) {
                // something is wrong
                Log.e(GalleryViewAdapter.class.getName(), ex.getMessage());
                showEmptyItem(holder);
                holder.overlayTextView.setText(R.string.tile_not_available);
                holder.overlayTextView.setVisibility(View.VISIBLE);
            }
        }
        return convertView;
    }

    /**
     * If we are in homescreen and if mediacard content has been parsed already, fetch cached content.
     *
     * @param position
     * @param cursor
     * @return
     */
    private MediaCardContent getMediaCardContent(int position, Cursor cursor) {
        MediaCardContent mContent = null;
        try {
            mContent = _mediaContentMap.get(position);
            if (null == mContent) {
                mContent = Utils.getContentFromCursor(context, cursor, false);
                _mediaContentMap.put(position, mContent);
            }

        } catch (Exception e) {

        }
        return mContent;
    }

    private void showEmptyItem(final ViewHolder holder) {
        holder.textView.setText("");
        holder.loadingView.setVisibility(View.VISIBLE);
        holder.imageView.setVisibility(View.INVISIBLE);
        holder.imageView.setImageDrawable(null);
        holder.countView.setText("");
        holder.programStatusIcon.setImageDrawable(null);
        holder.imagewNetworkIcon.setVisibility(View.GONE);
        holder.imagewNetworkIcon.setImageDrawable(null);
        holder.watchListIcon.setVisibility(View.GONE);
        holder.miscDetailsView.setText("");
        holder.overlayTextView.setText("");
        holder.programDurationBar.setVisibility(View.GONE);
    }

    /**
     * Sets the network logo
     *
     * @param cursor - Cursor with program info
     */
    private void setNetworkLogo(final MediaCardContent mcContent, final ImageView imageView) {
        if (contentType == DOLContentProvider.LIVE_CHANNEL) {
            // live channels
            imageView.setTag(SGImageLoader.SCALE_VIEW_CENTER);
            _imageloader.loadImage(mcContent.networkImageUrl, imageView, false, null);
        } else {
            if (null != mcContent.contentPlayerType
                    && true == mcContent.contentPlayerType.equalsIgnoreCase(MediaCardContent.slingType)) {
                // live linear
                _imageloader.loadImage(mcContent.networkImageUrl, imageView, _defaultBitmap, null);
            } else {
                setThumbResource(imageView, mcContent.networkImageUrl, R.dimen.gallery_channel_logo_size,
                        R.dimen.gallery_channel_logo_size);
            }
        }
        imageView.setVisibility(View.VISIBLE);
    }

    /**
     * Handle watch list icon.
     *
     * @param itemHolder the item holder
     * @param pgmInfo    the pgm info
     */
    private void handleWatchListIcon(final ImageView imgView, final MediaCardContent mcContent) {
        if (contentType == DOLContentProvider.LIVE_CHANNEL || true == SGProfileManagerData.getInstance().isKidProfile()) {
            // live channels & kids profiles will not have watch list for now
            return;
        }

        imgView.setVisibility(View.VISIBLE);

        try {
            boolean bIsProgramPresentInWatchList = _watchListData.isTmsIDPresent(mcContent.tms_id);
            imgView.setSelected(bIsProgramPresentInWatchList);

            imgView.setTag(mcContent);

            imgView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    try {
                        final DetailedProgramInfo programInfo = LibUtils.getProgramInfoFromMediaContent((MediaCardContent) v
                                .getTag());
                        if (programInfo.getContentSource().isEmpty()) {
                            MediaCardContent content = (MediaCardContent) v.getTag();
                            if ((null == content.contentPlayerType)
                                    || !(content.contentPlayerType.equalsIgnoreCase(MediaCardContent.slingType))) {
                                programInfo.setContentSource("ott");
                            }
                        }

                        if (true == LibUtils.isValidTMSID(programInfo)) {
                            boolean isChecked = v.isSelected();
                            v.setSelected(!isChecked);

                            if (true == isChecked) {
                                _watchListData.deleteProgramFromWatchList(programInfo);
                                if (context != null) {
                                    _watchListData.userActionForWatchList((Activity) context,
                                            SGUserActionHandler.USER_ACTION_REMOVE_WATCHLIST, null);
                                }
                            } else {
                                _watchListData.addProgramToWatchList(programInfo);
                                if (context != null) {
                                    _watchListData.userActionForWatchList((Activity) context,
                                            SGUserActionHandler.USER_ACTION_ADD_TO_WATCHLIST, null);
                                }
                            }
                        } else {
                            SGUIUtils.showMessageWithOK(context, null, R.string.watch_list_not_eligible, R.string.app_name,
                                    false);
                        }
                    } catch (Exception ex) {
                        Log.e(GalleryViewAdapter.class.getName(), "Cannot move item to /from watch list " + ex.getMessage());
                    }
                }
            });
        } catch (Exception ex) {

        }

    }

    /**
     * Sets the height and width of the gallery item based on device size
     *
     * @param holder
     */
    private void updateViewDimensions(View view, final ViewHolder holder) {
        android.view.ViewGroup.LayoutParams params = holder.imageView.getLayoutParams();
        params.height = _programIconHeight;
        params.width = _programIconWidth;
        ((LayoutParams) params).topMargin = _marginTop;
        holder.imageView.setLayoutParams(params);

        View galleryTileDetailsView = view.findViewById(R.id.gallery_tile_details);
        params = galleryTileDetailsView.getLayoutParams();
        // Change only the width to match the program icon
        params.width = _programIconWidth;
        galleryTileDetailsView.setLayoutParams(params);

        View programOverlayView = holder.overlayTextView;
        params = programOverlayView.getLayoutParams();
        params.height = _programIconHeight;
        params.width = _programIconWidth;
        ((LayoutParams) params).topMargin = _marginTop;
        programOverlayView.setLayoutParams(params);

        View loadingIcon = holder.loadingView;
        params = loadingIcon.getLayoutParams();
        params.height = _programIconHeight;
        params.width = _programIconWidth;
        loadingIcon.setLayoutParams(params);

    }

    public MediaCardContent clickItem(final int position, final String flurryTab, final String flurryFilter) {
        MediaCardContent content = null;
        if (position < super.getCount()) {
            RubenAnalyticsInfo.getInstance().handleProgramChoosenPosition(position);
            RubenAnalyticsInfo.getInstance().handleChosenProgramControl(RubenAnalyticsInfo.CONTROL_TILE);

            try {
                // get info from cursor
                final Cursor cursor = getCursor();
                cursor.moveToPosition(position);
                // check if that is LL
                if (Boolean.parseBoolean(cursor.getString(DBCommon.DbColumnsIds.IS_LIVE_COLUMN))
                        && !Boolean.parseBoolean(cursor.getString(DBCommon.DbColumnsIds.QUERY_PARAMS_COLUMN))) {
                    // program is not updated yet no allow to select
                    Toast.makeText(context, context.getResources().getString(R.string.no_program_retrived),
                            Toast.LENGTH_LONG).show();
                } else {
                    content = getMediaCardContent(position, cursor);
                    FlurryLogger.logTileTapped(flurryTab, flurryFilter, content.tms_id, content.itemTitle, position);
                    _previewLauncher.setIsInHomescreen(_bIsInHomescreen);
                    if (!SlingGuideApp.getInstance().isPhoneApp()) {
                        ((ISGHomeScreenActivityInterface) context).returnMediacardViewBackToActivityLayout();
                    }
                    _previewLauncher.launchPreview(content,
                            flurryTab.equalsIgnoreCase(context.getString(R.string.navigation_showcase)));
                }
            } catch (Exception ex) {
                Log.e(GalleryViewAdapter.class.getName(), "Item:" + ex.getMessage());
            }

        }
        return content;
    }

    public void clickNetworkItem(final int position, final String flurryTab, final String flurryFilter) {
        if (position < super.getCount()) {
            try {
                // get info from cursor
                final Cursor cursor = getCursor();
                cursor.moveToPosition(position);
                final MediaCardContent content = LibUtils.getNetworkItemFromCursor(cursor);
                FlurryLogger.logTileTapped(flurryTab, flurryFilter, content.tms_id, content.itemTitle, position);

                ((ISGHomeActivityInterface) context).onOdNetwork(DOLContentProvider.NETWORKS_SINGLE,
                        new SGOnDemandMediacardData(content));
            } catch (Exception ex) {
                Log.e(GalleryViewAdapter.class.getName(), "clickNetworkItem:" + ex.getMessage());
            }
        }
    }

    private void setEpisodeNum(final TextView numOfEpisodesView, final MediaCardContent mcContent) {
        // set num of episodes
        if (mcContent.episodeCount > 1) {
            numOfEpisodesView.setText(String.format(context.getResources().getString(R.string.episodecount),
                    mcContent.episodeCount));
        } else {
            numOfEpisodesView.setText("");
        }
    }

    private void updateItemDetails(TextView miscDetailsView, ProgressBar programDurationBar,
                                   final MediaCardContent mcContent) {
        if (true == mcContent.contentPlayerType.equalsIgnoreCase(MediaCardContent.slingType)) {
            updateDetailsForLinearContent(miscDetailsView, programDurationBar, mcContent);
        } else {
            updateDetailsForODContent(miscDetailsView, programDurationBar, mcContent);
        }
    }

    /**
     * Updates program details for linear content
     *
     * @param miscDetailsView
     * @param statusProgressBar
     * @param cursor
     */
    private void updateDetailsForLinearContent(final TextView miscDetailsView, ProgressBar statusProgressBar,
                                               final MediaCardContent mcContent) {
        // statusProgressBar.getProgressDrawable().setColorFilter(Color.CYAN, android.graphics.PorterDuff.Mode.SRC_ATOP);

        statusProgressBar.setVisibility(View.VISIBLE);

        DetailedProgramInfo program = DetailedProgramInfo.parseOdFeaturedLiveContent(mcContent);
        int progress = SGProgramsUtils.getInstance().getWatchedProgress(program, true);
        statusProgressBar.setProgress(progress);

        boolean bIsLive = isLive(program);
        String miscDetailsText = "<font color=";

        if (true == bIsLive) {
            miscDetailsText += Color.YELLOW + "><b>" + TEXT_LIVE + "</b>";
        } else {
            miscDetailsText += Color.YELLOW + "><b>" + TEXT_GUIDE + "</b>";
        }
        miscDetailsText += "</font>";
        miscDetailsView.setText(Html.fromHtml(miscDetailsText));

        LayoutParams params = (LayoutParams) miscDetailsView.getLayoutParams();
        // params.addRule(RelativeLayout.BELOW, 0); //commented as logic changed to show title
        // params.addRule(RelativeLayout.CENTER_VERTICAL);
        miscDetailsView.setLayoutParams(params);
    }

    /**
     * Checks if is program is live.
     *
     * @param pgmInfo the pgm info
     * @return true, if live
     */
    private boolean isLive(DetailedProgramInfo pgmInfo) {
        boolean bNeeded = false;

        String startTime = pgmInfo.getStartTime();
        String endTime = pgmInfo.getEndTime();

        bNeeded = SGUtil.showWatchButton(null, SGUtil.getTimeObject(startTime), SGUtil.getTimeObject(endTime));

        return bNeeded;
    }

    /**
     * Updates program details for OD content Details will show duration and recording quality like this: "125 min | HD"
     *
     * @param miscDetailsView
     * @param programDurationBar
     * @param cursor
     */
    private void updateDetailsForODContent(TextView miscDetailsView, ProgressBar programDurationBar,
                                           final MediaCardContent mcContent) {
        programDurationBar.setVisibility(View.INVISIBLE);

        String miscDetailsText = "<font color=";

        ISGBottombarInterface bottombarFragment = null;
        if (SlingGuideApp.getInstance().isPhoneApp()) {
            bottombarFragment = (ISGBottombarInterface) ((Activity) context).getFragmentManager().findFragmentById(
                    R.id.bottombarfragment);
        } else {
            bottombarFragment = (ISGBottombarInterface) SlingGuideApp.getInstance().getBottomBar();
        }
        if (bottombarFragment != null) {
            if (bottombarFragment.getLastUsedNavigationTabConstant() == TabConstants.TAB_SHOWCASE) {
                miscDetailsText += Color.YELLOW + "><b>" + TEXT_OD + "</b>";

                LayoutParams params = (LayoutParams) miscDetailsView.getLayoutParams();
                // params.addRule(RelativeLayout.BELOW, 0); //commented as logic changed to show title
                // params.addRule(RelativeLayout.CENTER_VERTICAL);
                miscDetailsView.setLayoutParams(params);
            } else {
                miscDetailsText += TEXT_COLOR_BLUE + ">";
                long duration = TimeUnit.SECONDS.toMinutes(Long.parseLong(mcContent.duration));

                if (duration > 0) {
                    miscDetailsText += "<b> " + duration + " " + TEXT_MINS + " </b>";
                }

                if (mcContent.is_hd) {
                    if (duration > 0) {
                        miscDetailsText += "| " + "<b>" + TEXT_HD + "</b>";
                    } else {
                        miscDetailsText += "<b>" + TEXT_HD + "</b>";
                    }
                }
            }
        }

        miscDetailsText += "</font>";
        miscDetailsView.setText(Html.fromHtml(miscDetailsText));
    }

    /***
     * @param overlayTextView
     * @param cursor
     * @return true if lock is permanent
     */
    private boolean setLock(final TextView overlayTextView, final MediaCardContent mcContent) {
        boolean isLockPermanent = false;

        if (LibUtils.getPermanentLockContainer(mcContent)) {
            // if no network id should be permanent lock
            overlayTextView.setText(R.string.premium_title);
            overlayTextView.setVisibility(View.VISIBLE);

            isLockPermanent = true;
        } else {
            if (false == SGProfileManagerData.getInstance().isKidProfile()
                    && LibUtils.getParentalLockContainer(mcContent, _pcController)) {
                // if parental lock field should be parental lock
                overlayTextView.setText(R.string.parental_title);
                overlayTextView.setVisibility(View.VISIBLE);
            } else {
                overlayTextView.setVisibility(View.GONE);
            }
        }
        return isLockPermanent;
    }

    public void clearCache() {
        _mediaContentMap.clear();
    }

    static class ViewHolder {
        TextView textView;
        ImageView imageView;
        View loadingView;
        TextView countView;
        ImageView programStatusIcon;
        ImageView imagewNetworkIcon;
        TextView miscDetailsView;
        TextView overlayTextView;
        ImageView watchListIcon;
        ImageButton programDeleteIcon;
        ImageButton programStarredIcon;
        ProgressBar programDurationBar;
    }

    private void setThumbResource(final ImageView imageView, final Cursor cursor, int contentType) {
        if (_imageloader != null) {
            // To indicate the image loader that appropriate scale type has to be
            imageView.setTag(SGImageLoader.SCALE_VIEW);

            String strThumbUriHTTP = "";
            try {
                strThumbUriHTTP = LibUtils.getThumbUriFromCursor(DOLCoreAPI.getProvider().getThumbId(contentType), cursor);
                if (contentType == DOLContentProvider.LIVE_CHANNEL) {
                    // strThumbUriHTTP =
                    // getOneOfTheLiveChannelUrls(strThumbUriHTTP);
                    imageView.setTag(SGImageLoader.SCALE_VIEW_CENTER);
                    _imageloader.loadImage(strThumbUriHTTP, imageView, true, null);
                } else {
                    if (contentType == DOLContentProvider.NETWORKS_ALL) {
                        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    }
                    _imageloader.loadImage(String.format(Utils.setProgramDishImage(strThumbUriHTTP), _programIconWidth,
                            _programIconHeight), imageView, true, null);
                }
            } catch (Exception ex) {
                Log.e(GalleryViewAdapter.class.getName(), "Cannot load image " + strThumbUriHTTP);
            }
        }
    }

    public int convertToPx(int dp) {
        // Get the screen's density scale
        final float scale = context.getResources().getDisplayMetrics().density;
        // Convert the dps to pixels, based on density scale
        return (int) (dp * scale + 0.5f);
    }

    private void setThumbResource(final ImageView imageView, final String strThumbUriHTTP, final int resWidth, final int resHeight) {
        if (_imageloader != null) {
            int width = (int) context.getResources().getDimension(resWidth);
            int height = (int) context.getResources().getDimension(resHeight);
            imageView.setTag(SGImageLoader.SCALE_VIEW);
            _imageloader.loadChannelImage(String.format(Utils.setProgramDishImageResizedConstrainProportions(strThumbUriHTTP), width, height),
                    imageView, _defaultBitmap, null);
        }
    }

    public int getPageCount(final int totalItems) {
        if (itemsPerPage == 0 || totalItems == 0) {
            return 0;
        }

        _pageCount = totalItems / itemsPerPage;
        if (totalItems % itemsPerPage != 0) {
            _pageCount++;
        }
        return _pageCount;
    }

    public int getPageNumber(final int firstVisibleItemPosition) {
        if (itemsPerPage == 0) {
            return 0;
        }
        return (firstVisibleItemPosition / itemsPerPage) + 1;
    }

    @Override
    public void OnClose() {
        // TODO Auto-generated method stub
        Utils.hidePreviewFragment((Activity) context, _mcpreviewLayout, _mcpreviewFragment);
    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        if (_imageloader == null)
            return;

        if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
            _imageloader.resumeLoading();
        } else {
            _imageloader.pauseLoading();
        }

    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        // TODO Auto-generated method stub

    }
}

以上是关于java GalleryViewAdapter_WITH_BUG.java的主要内容,如果未能解决你的问题,请参考以下文章

Java 布尔运算

java [Java] Java常用代码#java

Java - 35 Java 实例

Java While 循环

Java 字符串

Java If ... Else