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
17package com.android.music;
18
19import android.app.ListActivity;
20import android.content.ContentResolver;
21import android.content.ContentUris;
22import android.content.Intent;
23import android.database.Cursor;
24import android.media.AudioManager;
25import android.os.Bundle;
26import android.provider.MediaStore;
27import android.view.View;
28import android.widget.ListView;
29import android.widget.SimpleCursorAdapter;
30
31import java.lang.Integer;
32
33public class VideoBrowserActivity extends ListActivity implements MusicUtils.Defs
34{
35    public VideoBrowserActivity()
36    {
37    }
38
39    /** Called when the activity is first created. */
40    @Override
41    public void onCreate(Bundle icicle)
42    {
43        super.onCreate(icicle);
44        setVolumeControlStream(AudioManager.STREAM_MUSIC);
45        init();
46    }
47
48    public void init() {
49
50        // Set the layout for this activity.  You can find it
51        // in assets/res/any/layout/media_picker_activity.xml
52        setContentView(R.layout.media_picker_activity);
53
54        MakeCursor();
55
56        if (mCursor == null) {
57            MusicUtils.displayDatabaseError(this);
58            return;
59        }
60
61        if (mCursor.getCount() > 0) {
62            setTitle(R.string.videos_title);
63        } else {
64            setTitle(R.string.no_videos_title);
65        }
66
67        // Map Cursor columns to views defined in media_list_item.xml
68        SimpleCursorAdapter adapter = new SimpleCursorAdapter(
69                this,
70                android.R.layout.simple_list_item_1,
71                mCursor,
72                new String[] { MediaStore.Video.Media.TITLE},
73                new int[] { android.R.id.text1 });
74
75        setListAdapter(adapter);
76    }
77
78    @Override
79    protected void onListItemClick(ListView l, View v, int position, long id)
80    {
81        Intent intent = new Intent(Intent.ACTION_VIEW);
82        mCursor.moveToPosition(position);
83        String type = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
84        intent.setDataAndType(ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id), type);
85
86        startActivity(intent);
87    }
88
89    private void MakeCursor() {
90        String[] cols = new String[] {
91                MediaStore.Video.Media._ID,
92                MediaStore.Video.Media.TITLE,
93                MediaStore.Video.Media.DATA,
94                MediaStore.Video.Media.MIME_TYPE,
95                MediaStore.Video.Media.ARTIST
96        };
97        ContentResolver resolver = getContentResolver();
98        if (resolver == null) {
99            System.out.println("resolver = null");
100        } else {
101            mSortOrder = MediaStore.Video.Media.TITLE + " COLLATE UNICODE";
102            mWhereClause = MediaStore.Video.Media.TITLE + " != ''";
103            mCursor = resolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
104                cols, mWhereClause , null, mSortOrder);
105        }
106    }
107
108    @Override
109    public void onDestroy() {
110        if (mCursor != null) {
111            mCursor.close();
112        }
113        super.onDestroy();
114    }
115
116    private Cursor mCursor;
117    private String mWhereClause;
118    private String mSortOrder;
119}
120
121