• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.music;
18 
19 import android.app.ListActivity;
20 import android.content.ContentResolver;
21 import android.content.ContentUris;
22 import android.content.Intent;
23 import android.database.Cursor;
24 import android.media.AudioManager;
25 import android.os.Bundle;
26 import android.provider.MediaStore;
27 import android.view.View;
28 import android.widget.ListView;
29 import android.widget.SimpleCursorAdapter;
30 
31 import java.lang.Integer;
32 
33 public class VideoBrowserActivity extends ListActivity implements MusicUtils.Defs {
VideoBrowserActivity()34     public VideoBrowserActivity() {}
35 
36     /** Called when the activity is first created. */
37     @Override
onCreate(Bundle icicle)38     public void onCreate(Bundle icicle) {
39         super.onCreate(icicle);
40         setVolumeControlStream(AudioManager.STREAM_MUSIC);
41         init();
42     }
43 
init()44     public void init() {
45         // Set the layout for this activity.  You can find it
46         // in assets/res/any/layout/media_picker_activity.xml
47         setContentView(R.layout.media_picker_activity);
48 
49         MakeCursor();
50 
51         if (mCursor == null) {
52             MusicUtils.displayDatabaseError(this);
53             return;
54         }
55 
56         if (mCursor.getCount() > 0) {
57             setTitle(R.string.videos_title);
58         } else {
59             setTitle(R.string.no_videos_title);
60         }
61 
62         // Map Cursor columns to views defined in media_list_item.xml
63         SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
64                 android.R.layout.simple_list_item_1, mCursor,
65                 new String[] {MediaStore.Video.Media.TITLE}, new int[] {android.R.id.text1});
66 
67         setListAdapter(adapter);
68     }
69 
70     @Override
onListItemClick(ListView l, View v, int position, long id)71     protected void onListItemClick(ListView l, View v, int position, long id) {
72         Intent intent = new Intent(Intent.ACTION_VIEW);
73         mCursor.moveToPosition(position);
74         String type =
75                 mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
76         intent.setDataAndType(
77                 ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id), type);
78 
79         startActivity(intent);
80     }
81 
MakeCursor()82     private void MakeCursor() {
83         String[] cols = new String[] {MediaStore.Video.Media._ID, MediaStore.Video.Media.TITLE,
84                 MediaStore.Video.Media.DATA, MediaStore.Video.Media.MIME_TYPE,
85                 MediaStore.Video.Media.ARTIST};
86         ContentResolver resolver = getContentResolver();
87         if (resolver == null) {
88             System.out.println("resolver = null");
89         } else {
90             mSortOrder = MediaStore.Video.Media.TITLE + " COLLATE UNICODE";
91             mWhereClause = MediaStore.Video.Media.TITLE + " != ''";
92             mCursor = resolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, cols,
93                     mWhereClause, null, mSortOrder);
94         }
95     }
96 
97     @Override
onDestroy()98     public void onDestroy() {
99         if (mCursor != null) {
100             mCursor.close();
101         }
102         super.onDestroy();
103     }
104 
105     private Cursor mCursor;
106     private String mWhereClause;
107     private String mSortOrder;
108 }
109