android="
android:
layout_width="fill_parent"
android:
layout_height="fill_parent"
android:
background="@drawable/welcome"
android:
orientation="vertical">
三秒后进行跳转,进入界面,利用TabHost,VideoPlayerActivity代码如下
package.iotek;
import.adapter.OverwriteSimpleCursorAdapter;
import.adapter.OverwriterSimAdapter;
importandroid.app.TabActivity;
importandroid.content.Context;
importandroid.content.Intent;
importandroid.content.pm.PackageManager.NameNotFoundException;
importandroid.os.Bundle;
importandroid.view.Window;
importandroid.view.WindowManager;
importandroid.widget.SimpleAdapter;
importandroid.widget.SimpleCursorAdapter;
importandroid.widget.TabHost;
importandroid.widget.TabHost.OnTabChangeListener;
importandroid.widget.TabHost.TabSpec;
publicclassVideoPlayerActivityextendsTabActivity{
/**Calledwhentheactivityisfirstcreated.*/
staticbooleanflag;
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
try{
//获取ShareActivity上下文
VideoList.context=createPackageContext(".iotek",Context.CONTEXT_IGNORE_SECURITY);
VideoList.share=VideoList.context.getSharedPreferences("setupadapter",VideoList.context.MODE_WORLD_READABLE);
VideoList.editor=VideoList.share.edit();
}catch(NameNotFoundExceptione){
e.printStackTrace();
}
if(VideoList.share.getString("setupadapter","off").equals("on")){
flag=true;
}
if(VideoList.share.getString("setupadapter","off").equals("off")){
flag=false;
}
VideoList.helper=newDbhelper(this,"/mnt/sdcard/videoinfo.db",null,1);
//设置为可读
//VideoList.db=VideoList.helper.getReadableDatabase();
TabHosttabHost=getTabHost();
//创建选项卡
TabSpeclocalVideo=tabHost.newTabSpec("localvideo");
TabSpecvideoList=tabHost.newTabSpec("videoList");
//设置选项卡名称
localVideo.setIndicator("加载本地文件");
videoList.setIndicator("播放列表");
tabHost.setOnTabChangedListener(newOnTabChangeListener(){
@Override
publicvoidonTabChanged(StringtabId){
//TODOAuto-generatedmethodstub
}
});
IntentintentLocal=newIntent(getApplicationContext(),ShowList.class);
IntentintentList=newIntent(getApplicationContext(),VideoList.class);
localVideo.setContent(intentLocal);
videoList.setContent(intentList);
//添加选项卡
tabHost.addTab(localVideo);
tabHost.addTab(videoList);
//设置监听
tabHost.setOnTabChangedListener(newOnTabChangeListener(){
@Override
publicvoidonTabChanged(StringtabId){
//TODOAuto-generatedmethodstub
booleanf=tabId.equals("videoList");
booleanb=tabId.equals("localvideo");
if(f){
if(flag){
VideoList.db=VideoList.helper.getReadableDatabase();
Stringsql="select*fromvideoinfo";
VideoList.cursor=VideoList.db.rawQuery(sql,null);
VideoList.adapter=newOverwriteSimpleCursorAdapter(getApplicationContext(),R.layout.show,VideoList.cursor,
newString[]{"path","videoname"},
newint[]{R.id.picture,R.id.videoname});
VideoList.videoList.setAdapter(VideoList.adapter);
}if(!
flag){
VideoList.db=VideoList.helper.getReadableDatabase();
Stringsql="select*fromvideoinfo";
VideoList.cursor=VideoList.db.rawQuery(sql,null);
VideoList.adapter=newSimpleCursorAdapter(getApplicationContext(),R.layout.show,VideoList.cursor,
newString[]{"path","videoname"},
newint[]{R.id.picture,R.id.videoname});
VideoList.videoList.setAdapter(VideoList.adapter);
}
}
if(b){
if(flag){
OverwriterSimAdapteradapter=newOverwriterSimAdapter(
getApplicationContext(),ShowList.listItems,R.layout.filelist,
newString[]{"filename","icon","modify"},newint[]{
R.id.file_name,R.id.icon,R.id.file_modify});
ShowList.filesList.setAdapter(adapter);
}if(!
flag){
SimpleAdapteradapter=newSimpleAdapter(
getApplicationContext(),ShowList.listItems,R.layout.filelist,
newString[]{"filename","icon","modify"},newint[]{
R.id.file_name,R.id.icon,R.id.file_modify});
ShowList.filesList.setAdapter(adapter);
}
}
}
});
}
@Override
protectedvoidonDestroy(){
//VideoList.db.close();
//VideoList.cursor.close();
super.onDestroy();
}
}
配置文件main.xml
xmlversion="1.0"encoding="utf-8"?
>
android="
android:
id="@android:
id/tabhost"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent">
android:
orientation="vertical"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent"
android:
padding="5dp">
android:
id="@android:
id/tabs"
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
android:
background="#00000000"
/>
android:
id="@android:
id/tabcontent"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent"
android:
padding="5dp"/>
遍历内存卡ShowList代码
package.iotek;
importjava.io.File;
importjava.util.ArrayList;
importjava.util.HashMap;
importjava.util.List;
importjava.util.Map;
import.adapter.OverwriterSimAdapter;
importandroid.app.Activity;
importandroid.content.Context;
importandroid.content.pm.PackageManager.NameNotFoundException;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.AdapterView;
importandroid.widget.AdapterView.OnItemClickListener;
importandroid.widget.Button;
importandroid.widget.LinearLayout;
importandroid.widget.ListView;
importandroid.widget.SimpleAdapter;
importandroid.widget.TextView;
importandroid.widget.Toast;
publicclassShowListextendsActivity{
privateTextViewfilepath;
staticListViewfilesList;
privateButtonbackButton;
LinearLayoutlocalBack;
//记录当前的父文件夹
FilefloderParent;
inti;
//记录当前路径下的所有文件夹的文件数组
File[]dirFiles;
staticList
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.showlist);
localBack=(LinearLayout)findViewById(R.id.localback);
localBack.setBackgroundResource(R.drawable.bleach3);
VideoList.helper=newDbhelper(this,"/mnt/sdcard/videoinfo.db",null,1);
//设置为可读
//VideoList.db=VideoList.helper.getReadableDatabase();
filesList=(ListView)this.findViewById(R.id.filesList);
filepath=(TextView)this.findViewById(R.id.filepath);
backButton=(Button)this.findViewById(R.id.backButton);
VideoList.helper=newDbhelper(this,"/mnt/sdcard/videoinfo.db",null,1);
//VideoList.db=VideoList.helper.getReadableDatabase();
try{
//获取ShareActivity上下文
VideoList.context=createPackageContext(".iotek",Context.CONTEXT_IGNORE_SECURITY);
VideoList.share=VideoList.context.getSharedPreferences("setupadapter",VideoList.context.MODE_WORLD_READABLE);
VideoList.editor=VideoList.share.edit();
}catch(NameNotFoundExceptione){
e.printStackTrace();
}
//对背景进行判断
if(VideoList.share.getString("picture","卡通").equals("卡通")){
localBack.setBackgroundResource(R.drawable.haizei);
}
if(VideoList.share.getString("picture","卡通").equals("风景")){
localBack.setBackgroundResource(R.drawable.suround2);
}
if(VideoList.share.getString("picture","卡通").equals("明星")){
localBack.setBackgroundResource(R.drawable.xuanya);
}
//获取系统的SDCard的目录
Fileroot=newFile("/mnt/sdcard/");
//如果SD卡存在的话
if(root.exists()){
floderParent=root;
dirFiles=root.listFiles();
//使用当前目录下的全部文件、文件夹来填充ListView
inflateListView(dirFiles);
}
filesList.setOnItemClickListener(newOnItemClickListener(){
@Override
publicvoidonItemClick(AdapterView
>adapterView,Viewview,
intposition,longid){
//如果用户单击了文件,直接返回,不做任何处理
if(dirFiles[position].isFile()){
i=position;
if(dirFiles[position].getPath().endsWith(".3gp")||dirFiles[position].getPath().endsWith(".mp4")
||dirFiles[position].getPath().endsWith(".mp3")||dirFiles[position].getPath().endsWith(".rmvb")){
/*if(currentFiles[position].getPath().equals(VideoList.cursor.getString
(1))){
Toast.makeText(getApplicationContext(),"你妹啊,路径名相同了",1000).show();