<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:gravity="center_horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <RadioGroup android:gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:id="@+id/radio_file" android:checked="true" style="@style/main_tab_bottom" android:drawableTop="@drawable/video_file" android:text="@string/title_file" /> <RadioButton android:id="@+id/radio_online" android:drawableTop="@drawable/video_online" style="@style/main_tab_bottom" android:text="@string/title_online" /> </RadioGroup> <android.support.v4.view.ViewPager android:background="@color/background" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v4.view.ViewPager> </LinearLayout>
public class MainFragmentActivity extends FragmentActivity {
private ViewPager mPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_pager);
mPager = (ViewPager) findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
}
private FragmentPagerAdapter mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
/** 仅执行一次 */
@Override
public Fragment getItem(int position) {
Fragment result = null;
switch (position) {
case 1:
result = new FragmentOnline();//在线视频
break;
case 0:
default:
result = new FragmentFile();//本地视频
break;
}
return result;
}
@Override
public int getCount() {
return 2;
}
};
}
public class FragmentFile extends FragmentBase implements OnItemClickListener {
private FileAdapter mAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = super.onCreateView(inflater, container, savedInstanceState);
mAdapter = new FileAdapter(getActivity(), null);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(this);
new ScanVideoTask().execute();
return v;
}
/** 单击启动播放 */
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final File f = mAdapter.getItem(position);
Intent intent = new Intent(getActivity(), VideoViewDemo.class);
intent.putExtra("path", f.getPath());
startActivity(intent);
}
/** 扫描SD卡 */
private class ScanVideoTask extends AsyncTask<Void, File, Void> {
@Override
protected Void doInBackground(Void... params) {
eachAllMedias(Environment.getExternalStorageDirectory());
return null;
}
@Override
protected void onProgressUpdate(File... values) {
mAdapter.add(values[0]);
mAdapter.notifyDataSetChanged();
}
/** 遍历所有文件夹,查找出视频文件 */
public void eachAllMedias(File f) {
if (f != null && f.exists() && f.isDirectory()) {
File[] files = f.listFiles();
if (files != null) {
for (File file : f.listFiles()) {
if (file.isDirectory()) {
eachAllMedias(file);
} else if (file.exists() && file.canRead() && FileUtils.isVideoOrAudio(file)) {
publishProgress(file);
}
}
}
}
}
}
private class FileAdapter extends ArrayAdapter<File> {
public FileAdapter(Context ctx, ArrayList<File> l) {
super(ctx, l);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final File f = getItem(position);
if (convertView == null) {
final LayoutInflater mInflater = getActivity().getLayoutInflater();
convertView = mInflater.inflate(R.layout.fragment_file_item, null);
}
((TextView) convertView.findViewById(R.id.title)).setText(f.getName());
return convertView;
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有