Android Open Source - dttv-android Video U I Fragment






From Project

Back to project page dttv-android.

License

The source code is released under:

GNU General Public License

If you think the Android project dttv-android 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 dttv.app.widget;
//w w w .j a v  a 2  s. co  m

import java.util.ArrayList;
import java.util.List;

import dttv.app.R;
import dttv.app.VideoPlayerActivity;
import dttv.app.impl.I_OnMyKey;
import dttv.app.utils.Constant;
import dttv.app.utils.PlayerUtil;
import dttv.app.utils.SettingUtil;
import android.annotation.SuppressLint;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.MediaStore.Audio.Media;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;


@SuppressLint("NewApi")
public class VideoUIFragment extends Fragment implements I_OnMyKey{
  final static String TAG = "VideoUIFragment";
  View rootView;
  ListView video_listview;
  SettingUtil settingUtil;
  
  private List<String> playList;
  //private AsyncQueryHandler mQueryHandler;
  
  public VideoUIFragment() {
    // TODO Auto-generated constructor stub
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    settingUtil = new SettingUtil(getActivity());
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    
    rootView = inflater.inflate(R.layout.dt_video_ui_fragment, container, false);
    /*TextView tv_tabName = (TextView) rootView.findViewById(R.id.tv_tabName);
    Bundle bundle = getArguments();
    tv_tabName.setText(bundle.getString(Constant.ARGUMENTS_NAME, ""));*/
    
    return rootView;
  }
  
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);
    initViews();
  }
  
  
  private void initViews(){
    video_listview = (ListView)rootView.findViewById(R.id.video_listview);
    /*mQueryHandler = new QueryHandler(getActivity().getContentResolver());
    getQueryCursor(mQueryHandler, null);*/
    MakeCursor();
    fillDataToListView();
    video_listview.setOnItemClickListener(new ListOnItemClickListener());
  }
  
  private class ListOnItemClickListener implements OnItemClickListener{
    @Override
    public void onItemClick(AdapterView<?> adapter, View v, int position,
        long arg3) {
      // TODO Auto-generated method stub
      String uri = playList.get(position);
      String name = ((TextView)v.findViewById(R.id.media_row_name)).getText().toString();
      PlayerUtil.getInstance().beginToPlayer(getActivity(), uri, name,Constant.LOCAL_VIDEO);
    }
  }
  
  
  class QueryHandler extends AsyncQueryHandler {
        QueryHandler(ContentResolver res) {
            super(res);
        }
        
        @Override
        protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
            //mActivity.init(cursor);
          //Log.i(TAG, "cursor.getCount() is:"+cursor.getCount());
          //fillDataToListView(cursor);
        }
    }
  
  private void fillDataToListView(){
    playList = new ArrayList<String>();
    String[] fromColumns = new String[] {MediaStore.Video.Media.TITLE};
    int[] toLayoutIDs = new int[]{R.id.media_row_name};
    //Cursor cursor = readDataFromSD(getActivity());
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), R.layout.dt_video_item, mCursor, fromColumns, toLayoutIDs, 0);
    
    video_listview.setAdapter(adapter);
    while(mCursor.moveToNext()){
      //Log.i(TAG, "mine-type is:"+mCursor.getString(mCursor.getColumnIndex(MediaStore.Video.Media.MIME_TYPE)));
      playList.add(mCursor.getString(mCursor.getColumnIndex(MediaStore.Video.Media.DATA)));
    }
  }
  
  
  private void MakeCursor() {
        String[] cols = new String[] {
                MediaStore.Video.Media._ID,
                MediaStore.Video.Media.TITLE,
                MediaStore.Video.Media.DATA,
                MediaStore.Video.Media.MIME_TYPE,
                MediaStore.Video.Media.ARTIST
        };
        ContentResolver resolver = getActivity().getContentResolver();
        if (resolver == null) {
            System.out.println("resolver = null");
        } else {
          StringBuffer select = new StringBuffer("");
        // ??????????.mp3?????????????1??????????1MB?????
        /*if(sp.getFilterSize()) {
          select.append(" and " + Media.SIZE + " > " + FILTER_SIZE);
        }*/
        if(settingUtil.isFilterVideo()) {
          select.append(" and " + Media.DURATION + " > " + Constant.FILTER_DURATION);
        }
            mSortOrder = MediaStore.Video.Media.TITLE + " COLLATE UNICODE";
            mWhereClause = MediaStore.Video.Media.TITLE + " != ''";
            mCursor = resolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                cols, mWhereClause + select, null, mSortOrder);
        }
    }
  
  @Override
  public void onDestroyView() {
    // TODO Auto-generated method stub
    super.onDestroyView();
  }
  
  @Override
  public void onDestroy() {
    // TODO Auto-generated method stub
    if(mCursor!=null)
      mCursor.close();
    super.onDestroy();
  }
  
  private Cursor mCursor;
  private String mWhereClause;
    private String mSortOrder;
  @Override
  public void myOnKeyDown(int keyCode) {
    // TODO Auto-generated method stub
    
  }
}




Java Source Code List

dttv.app.DtPlayer.java
dttv.app.FileBrowserActivity.java
dttv.app.FileShowActivity.java
dttv.app.IndexActivity.java
dttv.app.MainActivity.java
dttv.app.SettingActivity.java
dttv.app.VideoPlayerActivity.java
dttv.app.adapter.FileAdapter.java
dttv.app.compnent.Compnent.java
dttv.app.compnent.MethodPlayerCompnent.java
dttv.app.compnent.PopWindowCompnent.java
dttv.app.impl.ICallBack.java
dttv.app.impl.I_Async.java
dttv.app.impl.I_KeyIntercept.java
dttv.app.impl.I_OnMyKey.java
dttv.app.impl.I_PopWindow.java
dttv.app.model.Item.java
dttv.app.multithread.DataAsyncTask.java
dttv.app.utils.Constant.java
dttv.app.utils.ControlLightness.java
dttv.app.utils.FileUtil.java
dttv.app.utils.Log.java
dttv.app.utils.MultiMediaTypeUtil.java
dttv.app.utils.MusicUtils.java
dttv.app.utils.PlayerUtil.java
dttv.app.utils.SettingUtil.java
dttv.app.utils.TimesUtil.java
dttv.app.utils.VolumeUtil.java
dttv.app.view.SimpleDialog.java
dttv.app.widget.AudioUIFragment.java
dttv.app.widget.EffectWindow.java
dttv.app.widget.FilesUIFragment.java
dttv.app.widget.GlVideoView.java
dttv.app.widget.OnTouchMoveListener.java
dttv.app.widget.SlideTabsFragment.java
dttv.app.widget.VideoUIFragment.java