Android Open Source - MediaCodecVideoPlayer Menu Adapter






From Project

Back to project page MediaCodecVideoPlayer.

License

The source code is released under:

Apache License

If you think the Android project MediaCodecVideoPlayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.jasonsoft.mediacodecvideoplayer.adapter;
/*from  www.j a  va2  s  .  co  m*/
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.provider.MediaStore.Video.VideoColumns;
import android.util.LruCache;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jasonsoft.mediacodecvideoplayer.LoadThumbnailTask;
import com.jasonsoft.mediacodecvideoplayer.R;
import com.jasonsoft.mediacodecvideoplayer.RoundedCornerImageView;
import com.jasonsoft.mediacodecvideoplayer.Utils;
import com.jasonsoft.mediacodecvideoplayer.data.MenuDrawerItem;
import com.jasonsoft.mediacodecvideoplayer.data.MenuDrawerCategory;

import java.util.List;

public class MenuAdapter extends CursorAdapter {

    public interface MenuListener {

        void onActiveViewChanged(View v);
    }

    class ViewHolder {
        RoundedCornerImageView thumbnailView;
        TextView title;
        TextView details;
    }

    private Context mContext;
    private final LayoutInflater mInflater;
    private Bitmap mDefaultPhotoBitmap;
    private LruCache<String, Bitmap> mMemoryCache;

    private List<Object> mItems;

    private MenuListener mListener;

    private int mActivePosition = -1;

    public MenuAdapter(Context context, Cursor c) {
        super(context, c);
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mDefaultPhotoBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.placeholder_empty);
    }

    public void setListener(MenuListener listener) {
        mListener = listener;
    }

    public void setActivePosition(int activePosition) {
        mActivePosition = activePosition;
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        final View view = mInflater.inflate(R.layout.video_list_item, null);
        return view;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        ViewHolder holder = (ViewHolder)view.getTag();
        if (null == holder) {
            holder =  populateViewHolder(view);
        }

        long duration = cursor.getLong(cursor.getColumnIndex(VideoColumns.DURATION));
        String details = Utils.msToDisplayDuration(duration) + " - "
                + cursor.getString(cursor.getColumnIndex(VideoColumns.RESOLUTION));
        holder.title.setText(cursor.getString(cursor.getColumnIndex(VideoColumns.TITLE)));
        holder.details.setText(details);

        long origId = cursor.getInt(cursor.getColumnIndex(VideoColumns._ID));
        Utils.loadThumbnail(mContext, origId, holder.thumbnailView, mDefaultPhotoBitmap);
    }

    ViewHolder populateViewHolder(View view) {
        ViewHolder holder = new ViewHolder();
        holder.thumbnailView = (RoundedCornerImageView) view.findViewById(R.id.video_thumbnail);
        holder.title = (TextView) view.findViewById(R.id.video_title);
        holder.details = (TextView) view.findViewById(R.id.video_details);
        view.setTag(holder);
        return holder;
    }
}




Java Source Code List

com.example.hellojni.HelloJni.java
com.jasonsoft.mediacodecvideoplayer.LoadThumbnailTask.java
com.jasonsoft.mediacodecvideoplayer.MediaCodecVideoPlayerActivity.java
com.jasonsoft.mediacodecvideoplayer.MenuDrawerBaseActivity.java
com.jasonsoft.mediacodecvideoplayer.RoundedCornerImageView.java
com.jasonsoft.mediacodecvideoplayer.Utils.java
com.jasonsoft.mediacodecvideoplayer.VideoSurfaceView.java
com.jasonsoft.mediacodecvideoplayer.adapter.MenuAdapter.java
com.jasonsoft.mediacodecvideoplayer.cache.CacheManager.java
com.jasonsoft.mediacodecvideoplayer.data.AsyncDrawable.java
com.jasonsoft.mediacodecvideoplayer.data.LoadThumbnailParams.java
com.jasonsoft.mediacodecvideoplayer.data.LoadThumbnailResult.java
com.jasonsoft.mediacodecvideoplayer.data.MenuDrawerCategory.java
com.jasonsoft.mediacodecvideoplayer.data.MenuDrawerItem.java
net.simonvt.menudrawer.BuildLayerFrameLayout.java
net.simonvt.menudrawer.ColorDrawable.java
net.simonvt.menudrawer.DraggableDrawer.java
net.simonvt.menudrawer.FloatScroller.java
net.simonvt.menudrawer.MenuDrawer.java
net.simonvt.menudrawer.NoClickThroughFrameLayout.java
net.simonvt.menudrawer.OverlayDrawer.java
net.simonvt.menudrawer.PeekInterpolator.java
net.simonvt.menudrawer.Position.java
net.simonvt.menudrawer.Scroller.java
net.simonvt.menudrawer.SinusoidalInterpolator.java
net.simonvt.menudrawer.SlideDrawable.java
net.simonvt.menudrawer.SlidingDrawer.java
net.simonvt.menudrawer.SmoothInterpolator.java
net.simonvt.menudrawer.StaticDrawer.java
net.simonvt.menudrawer.ViewHelper.java
net.simonvt.menudrawer.compat.ActionBarHelperCompat.java
net.simonvt.menudrawer.compat.ActionBarHelperNative.java
net.simonvt.menudrawer.compat.ActionBarHelper.java