增加展示本地视频文件demo
This commit is contained in:
parent
e58fd829a6
commit
5fb5643a21
|
@ -948,6 +948,18 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- 相册+视频选择器样例代码 -->
|
||||
<activity
|
||||
android:name=".sample.imagepicker.ImagePickerActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/ImagePickerActivity"
|
||||
android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="com.zftlive.android.SAMPLE_CODE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- 静态注册短信广播接收器 -->
|
||||
<receiver android:name=".sample.sms.SMSBroadcastReceiver">
|
||||
<intent-filter android:priority="2147483647">
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Android基础开发个人积累、沉淀、封装、整理共通
|
||||
* Copyright (c) 2016. 曾繁添 <zftlive@163.com>
|
||||
* Github:https://github.com/zengfantian || http://git.oschina.net/zftlive
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zftlive.android.sample.imagepicker;
|
||||
|
||||
import com.zftlive.android.library.base.bean.AdapterModelBean;
|
||||
|
||||
/**
|
||||
* Created by AJava on 2016/8/31.
|
||||
*/
|
||||
public class ImageFileBean extends AdapterModelBean {
|
||||
|
||||
public String title = "";
|
||||
|
||||
public String imageURL = "";
|
||||
|
||||
public int id = 0;
|
||||
|
||||
public String displayName = "";
|
||||
|
||||
public String album = "";
|
||||
|
||||
public String artist = "";
|
||||
|
||||
public String mimeType = "";
|
||||
|
||||
public String path = "";
|
||||
|
||||
public long duration = 0;
|
||||
|
||||
public long size = 0;
|
||||
|
||||
public String resolution = "";
|
||||
|
||||
public ImageFileBean() {
|
||||
|
||||
}
|
||||
|
||||
public ImageFileBean(String title, String imageURL) {
|
||||
this.title = title;
|
||||
this.imageURL = imageURL;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Android基础开发个人积累、沉淀、封装、整理共通
|
||||
* Copyright (c) 2016. 曾繁添 <zftlive@163.com>
|
||||
* Github:https://github.com/zengfantian || http://git.oschina.net/zftlive
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zftlive.android.sample.imagepicker;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.View;
|
||||
import android.widget.GridView;
|
||||
|
||||
import com.zftlive.android.R;
|
||||
import com.zftlive.android.library.base.ui.CommonActivity;
|
||||
import com.zftlive.android.library.common.adapter.SingleTypeAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* 异步加载图片示例DEMO,防止图片错位
|
||||
* @author 曾繁添
|
||||
* @version 1.0
|
||||
*
|
||||
*/
|
||||
public class ImagePickerActivity extends CommonActivity {
|
||||
|
||||
private GridView mListView;
|
||||
private SingleTypeAdapter mMyListViewAdapter;
|
||||
|
||||
@Override
|
||||
public int bindLayout() {
|
||||
return R.layout.activity_image_grid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initParams(Bundle parms) {
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public void initView(View view) {
|
||||
mListView = (GridView)findViewById(R.id.gv_square);
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.ImagePickerActivity);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
mWindowTitle.initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doBusiness(Context mContext) {
|
||||
mMyListViewAdapter = new SingleTypeAdapter(this);
|
||||
mMyListViewAdapter.registeViewTemplet(MyGridViewTemplet.class);
|
||||
initData();
|
||||
mListView.setAdapter(mMyListViewAdapter);
|
||||
}
|
||||
|
||||
private void initData(){
|
||||
mMyListViewAdapter.clear();
|
||||
mMyListViewAdapter.addItem(getLoadMedia());
|
||||
|
||||
// //构造数据
|
||||
// for (int i = 0; i < 20; i++) {
|
||||
// mMyListViewAdapter.addItem(new ImageRowBean(i+1+"-"+titles[i],imageURLs[i]));
|
||||
// }
|
||||
// mListView.postDelayed(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if(mListView.isRefreshing()){
|
||||
// mListView.setRefreshing(false);
|
||||
// }
|
||||
// }
|
||||
// },200);
|
||||
|
||||
}
|
||||
|
||||
public ArrayList getLoadMedia() {
|
||||
|
||||
ArrayList<ImageFileBean> result = new ArrayList<>();
|
||||
|
||||
Cursor cursor = this.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Video.Media.DEFAULT_SORT_ORDER);
|
||||
try {
|
||||
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
|
||||
int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID)); // id
|
||||
String displayName =cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
|
||||
String album = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.ALBUM)); // 专辑
|
||||
String artist = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.ARTIST)); // 艺术家
|
||||
String title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME)); // 显示名称
|
||||
String mimeType =cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
|
||||
String path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); // 路径
|
||||
long duration = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)); // 时长
|
||||
long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE)); // 大小
|
||||
String resolution =cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.RESOLUTION));
|
||||
|
||||
ImageFileBean item = new ImageFileBean();
|
||||
item.id = id;
|
||||
item.displayName = displayName;
|
||||
item.album = album;
|
||||
item.artist = artist;
|
||||
item.title = title;
|
||||
item.mimeType = mimeType;
|
||||
item.path = path;
|
||||
item.imageURL = path;
|
||||
item.duration = duration;
|
||||
item.size = size;
|
||||
item.resolution = resolution;
|
||||
|
||||
result.add(item);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Android基础开发个人积累、沉淀、封装、整理共通
|
||||
* Copyright (c) 2016. 曾繁添 <zftlive@163.com>
|
||||
* Github:https://github.com/zengfantian || http://git.oschina.net/zftlive
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zftlive.android.sample.imagepicker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.zftlive.android.R;
|
||||
import com.zftlive.android.library.base.adapter.IAdapterModel;
|
||||
import com.zftlive.android.library.base.templet.AbsViewTemplet;
|
||||
import com.zftlive.android.library.imageloader.ToolImage;
|
||||
|
||||
/**
|
||||
* 视图模板
|
||||
*/
|
||||
public class MyGridViewTemplet extends AbsViewTemplet {
|
||||
|
||||
DisplayImageOptions option;
|
||||
ImageView iv_icon;
|
||||
TextView tv_title;
|
||||
|
||||
public MyGridViewTemplet(Context mContext) {
|
||||
super(mContext);
|
||||
option = ToolImage.getFadeOptions(R.drawable.anl_common_default_picture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bindLayout() {
|
||||
return R.layout.activity_image_grid_item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
iv_icon = (ImageView) findViewById(R.id.iv_icon);
|
||||
tv_title = (TextView) findViewById(R.id.tv_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillData(IAdapterModel model, int postion) {
|
||||
|
||||
ImageFileBean rowBean = (ImageFileBean) model;
|
||||
//ImageLoader.getInstance().displayImage((String) rowBean.imageURL, iv_icon,option);
|
||||
ToolImage.getInstance().displayFile(rowBean.imageURL, iv_icon);
|
||||
tv_title.setText(rowBean.title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void itemClick(View view, int postion, IAdapterModel rowData) {
|
||||
try{
|
||||
ImageFileBean rowBean = (ImageFileBean) rowData;
|
||||
//ToolToast.showShort(mContext,"点击了"+ rowBean.title);
|
||||
|
||||
//打开系统的播放器 ACTION_VIEW
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
//得到视频
|
||||
//Environment.getExternalStorageDirectory() 得到Sdcard的根目录、
|
||||
Uri uri = Uri.parse(rowBean.path);
|
||||
//加载视频 和 类型
|
||||
intent.setDataAndType(uri, "video/*");
|
||||
mContext.startActivity(intent);
|
||||
}catch (Throwable e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<GridView
|
||||
android:id="@+id/gv_square"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#cccccc"
|
||||
android:columnWidth="@dimen/itemSize"
|
||||
android:gravity="center"
|
||||
android:horizontalSpacing="10dp"
|
||||
android:numColumns="3"
|
||||
android:scrollbars="none"
|
||||
android:stretchMode="columnWidth"
|
||||
android:verticalSpacing="10dp" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -0,0 +1,31 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dp"
|
||||
android:background="@color/anl_white"
|
||||
tools:context=".Launcher">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_icon"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_margin="5dp"
|
||||
android:contentDescription="@string/app_name"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/anl_common_default_picture" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:ellipsize="end"
|
||||
android:gravity="left|center_vertical"
|
||||
android:padding="10dp"
|
||||
android:singleLine="false"
|
||||
android:text="1:00"
|
||||
android:textColor="@color/anl_white"
|
||||
android:textSize="14sp" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -46,6 +46,7 @@
|
|||
<string name="MPChartActivity">MPChart图表样例</string>
|
||||
<string name="RecyclerViewActivity">RecyclerView样例一</string>
|
||||
<string name="MainTabActivity">CoordinatorTabLayout样例</string>
|
||||
<string name="ImagePickerActivity">相册+视频选择器</string>
|
||||
<!-- Android样例锦集label(结束) -->
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue