Browse Source

修改视频录制控件

gongpm 10 years ago
parent
commit
5b34cb9dda

+ 18 - 18
WeiChat/src/main/AndroidManifest.xml

@@ -2,7 +2,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.xzjmyk.pm.activity"
     android:versionCode="41"
-    android:versionName="4.1" >
+    android:versionName="4.1">
 
     <uses-sdk
         android:minSdkVersion="14"
@@ -10,9 +10,11 @@
 
     <!-- 拨打电话 -->
     <uses-permission android:name="android.permission.CALL_PHONE" />
+
     <uses-feature android:name="android.hardware.camera" />
     <uses-feature android:name="android.hardware.camera.autofocus" />
     <uses-feature android:name="android.hardware.microphone" />
+
     <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
     <uses-permission android:name="android.permission.WAKE_LOCK" />
     <uses-permission android:name="android.permission.GET_TASKS" />
@@ -67,7 +69,7 @@
         android:allowBackup="true"
         android:icon="@drawable/uuu"
         android:label="@string/app_name"
-        android:theme="@style/AppTheme" >
+        android:theme="@style/AppTheme">
         <meta-data
             android:name="UMENG_APPKEY"
             android:value="574504a167e58eec520017df" />
@@ -78,7 +80,7 @@
         <!-- 启动页面 -->
         <activity
             android:name=".ui.SplashActivity"
-            android:theme="@style/SplashTheme" >
+            android:theme="@style/SplashTheme">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
@@ -238,7 +240,7 @@
             android:exported="true"
             android:icon="@drawable/ic_chooser"
             android:label="@string/choose_file"
-            android:theme="@style/ChooserTheme" >
+            android:theme="@style/ChooserTheme">
             <intent-filter>
                 <action android:name="android.intent.action.GET_CONTENT" />
 
@@ -255,13 +257,13 @@
             android:enabled="@bool/use_provider"
             android:exported="true"
             android:grantUriPermissions="true"
-            android:permission="android.permission.MANAGE_DOCUMENTS" >
+            android:permission="android.permission.MANAGE_DOCUMENTS">
             <intent-filter>
                 <action android:name="android.content.action.DOCUMENTS_PROVIDER" />
             </intent-filter>
         </provider>
 
-        <receiver android:name=".broadcast.ScrenLockedBroadCastReceiver" >
+        <receiver android:name=".broadcast.ScrenLockedBroadCastReceiver">
             <intent-filter>
                 <action android:name="android.intent.action.SCREEN_OFF" />
                 <action android:name="android.intent.action.SCREEN_ON" />
@@ -288,7 +290,7 @@
         <!-- 用于接收系统消息以保证PushService正常运行 -->
         <receiver
             android:name="com.baidu.android.pushservice.PushServiceReceiver"
-            android:process=":bdservice_v1" >
+            android:process=":bdservice_v1">
             <intent-filter>
                 <action android:name="android.intent.action.BOOT_COMPLETED" />
                 <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
@@ -304,7 +306,7 @@
         <!-- Push服务接收客户端发送的各种请求 -->
         <receiver
             android:name="com.baidu.android.pushservice.RegistrationReceiver"
-            android:process=":bdservice_v1" >
+            android:process=":bdservice_v1">
             <intent-filter>
                 <action android:name="com.baidu.android.pushservice.action.METHOD" />
                 <action android:name="com.baidu.android.pushservice.action.BIND_SYNC" />
@@ -323,7 +325,7 @@
             android:name="com.baidu.android.pushservice.PushService"
             android:exported="true"
             android:persistent="true"
-            android:process=":bdservice_v1" >
+            android:process=":bdservice_v1">
             <intent-filter>
                 <action android:name="com.baidu.android.pushservice.action.PUSH_SERVICE" />
             </intent-filter>
@@ -337,7 +339,7 @@
 
 
         <!-- 此处Receiver名字修改为当前包名路径 -->
-        <receiver android:name=".ui.PushNetMessageReceiver" >
+        <receiver android:name=".ui.PushNetMessageReceiver">
             <intent-filter>
 
                 <!-- 接收push消息 -->
@@ -358,7 +360,7 @@
             </intent-filter>
         </activity>
         -->
-        <activity android:name=".ui.message.SelectCardActivity" >
+        <activity android:name=".ui.message.SelectCardActivity">
             <intent-filter>
                 <action android:name="com.xzjmyk.pm.activity.ui.message.SelectCardActivity" />
             </intent-filter>
@@ -382,7 +384,7 @@
 
         <receiver
             android:name="com.baidu.autoupdatesdk.receiver.BDBroadcastReceiver"
-            android:exported="false" >
+            android:exported="false">
             <intent-filter>
                 <action android:name="com.baidu.autoupdatesdk.ACTION_NEW_UPDATE" />
                 <action android:name="com.baidu.autoupdatesdk.ACTION_DOWNLOAD_COMPLETE" />
@@ -391,14 +393,12 @@
             </intent-filter>
         </receiver>
 
+        <activity android:name=".video.VideoActivity" />
         <activity android:name=".ui.erp.activity.CompanyActivity" />
         <activity android:name=".ui.erp.activity.BaseInfoActivity" />
-        <activity android:name=".ui.erp.activity.ClientActivity" >
-        </activity>
-        <activity android:name=".ui.erp.activity.SubscribeActivity" >
-        </activity>
-        <activity android:name=".ui.message.SubscriptionActivity" >
-        </activity>
+        <activity android:name=".ui.erp.activity.ClientActivity"></activity>
+        <activity android:name=".ui.erp.activity.SubscribeActivity"></activity>
+        <activity android:name=".ui.message.SubscriptionActivity"></activity>
     </application>
 
 </manifest>

+ 307 - 299
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/me/LocalVideoActivity.java

@@ -8,6 +8,7 @@ import android.os.Bundle;
 import android.os.Handler;
 import android.provider.MediaStore.Video.Thumbnails;
 import android.text.TextUtils;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuItem;
@@ -22,17 +23,17 @@ import com.nostra13.universalimageloader.core.ImageLoader;
 import com.roamer.slidelistview.SlideBaseAdapter;
 import com.roamer.slidelistview.SlideListView;
 import com.xzjmyk.pm.activity.AppConstant;
+import com.xzjmyk.pm.activity.MyApplication;
+import com.xzjmyk.pm.activity.R;
 import com.xzjmyk.pm.activity.bean.VideoFile;
 import com.xzjmyk.pm.activity.db.dao.VideoFileDao;
 import com.xzjmyk.pm.activity.ui.base.ActionBackActivity;
 import com.xzjmyk.pm.activity.ui.tool.VideoPlayActivity;
 import com.xzjmyk.pm.activity.util.TimeUtils;
-import com.xzjmyk.pm.activity.view.PullToRefreshSlideListView;
-import com.xzjmyk.pm.activity.MyApplication;
-import com.xzjmyk.pm.activity.R;
 import com.xzjmyk.pm.activity.util.ToastUtil;
 import com.xzjmyk.pm.activity.util.ViewHolder;
-import com.xzjmyk.pm.activity.video.VideoRecordActivity;
+import com.xzjmyk.pm.activity.video.VideoActivity;
+import com.xzjmyk.pm.activity.view.PullToRefreshSlideListView;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -40,309 +41,316 @@ import java.util.List;
 
 /**
  * 本地视频选择界面
- * 
+ *
  * @author Dean Tao
  * @version 1.0
  */
 public class LocalVideoActivity extends ActionBackActivity {
 
-	private PullToRefreshSlideListView mPullToRefreshListView;
-	private List<VideoFile> mVideoFiles;
-	private LocalVideoAdapter mAdapter;
-
-	private int mAction = AppConstant.ACTION_NONE;
-	private Handler mHandler;
-
-	@Override
-	protected void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		if (getIntent() != null) {
-			mAction = getIntent().getIntExtra(AppConstant.EXTRA_ACTION, AppConstant.ACTION_NONE);
-		}
-		setContentView(R.layout.layout_pullrefresh_list_slide);
-		mHandler = new Handler();
-		mVideoFiles = new ArrayList<VideoFile>();
-		mAdapter = new LocalVideoAdapter(this);
-		initView();
-
-	}
-	private void initView() {
-		getSupportActionBar().setTitle(R.string.local_video);
-		mPullToRefreshListView = (PullToRefreshSlideListView) findViewById(R.id.pull_refresh_list);
-
-		View emptyView = LayoutInflater.from(mContext).inflate(R.layout.layout_list_empty_view, null);
-		mPullToRefreshListView.setEmptyView(emptyView);
-
-		mPullToRefreshListView.getRefreshableView().setAdapter(mAdapter);
-		mPullToRefreshListView.setShowIndicator(false);
-
-		mPullToRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<SlideListView>() {
-			@Override
-			public void onRefresh(PullToRefreshBase<SlideListView> refreshView) {
-				loadData();
-			}
-		});
-
-		mPullToRefreshListView.getRefreshableView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
-			@Override
-			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-				if (mAction == AppConstant.ACTION_SELECT) {
-					VideoFile videoFile = mVideoFiles.get((int) id);
-					if (TextUtils.isEmpty(videoFile.getFilePath())) {
-						ToastUtil.showToast(LocalVideoActivity.this, R.string.video_file_not_exist);
-						return;
-					}
-					File file = new File(videoFile.getFilePath());
-					if (!file.exists()) {
-						ToastUtil.showToast(LocalVideoActivity.this, R.string.video_file_not_exist);
-						return;
-					}
-
-					Intent intent = new Intent();
-					intent.putExtra(AppConstant.EXTRA_SELECT_ID, videoFile.get_id());
-					intent.putExtra(AppConstant.EXTRA_FILE_PATH, videoFile.getFilePath());
-					intent.putExtra(AppConstant.EXTRA_TIME_LEN, videoFile.getFileLength());
-					setResult(RESULT_OK, intent);
-					finish();
-				}
-			}
-		});
-
-		mPullToRefreshListView.setAdapter(mAdapter);
-
-		loadData();
-	}
-
-	private void loadData() {
-		new Thread(new Runnable() {
-			@Override
-			public void run() {
-				long startTime = System.currentTimeMillis();
-				final List<VideoFile> videos = VideoFileDao.getInstance().getVideoFiles(MyApplication.getInstance().mLoginUser.getUserId());
-				long delayTime = 200 - (startTime - System.currentTimeMillis());// 保证至少200ms的刷新过程
-				if (delayTime < 0) {
-					delayTime = 0;
-				}
-				mHandler.postDelayed(new Runnable() {
-					@Override
-					public void run() {
-						mVideoFiles.clear();
-						if (videos != null && videos.size() > 0) {
-							mVideoFiles.addAll(videos);
-						}
-						mAdapter.notifyDataSetChanged();
-						mPullToRefreshListView.onRefreshComplete();
-					}
-				}, delayTime);
-			}
-		}).start();
-	}
-
-	private boolean delete(VideoFile videoFile) {
-		boolean success = true;
-		String filePath = videoFile.getFilePath();
-		if (!TextUtils.isEmpty(filePath)) {
-			File file = new File(filePath);
-			if (file.exists()) {
-				success = file.delete();
-			}
-		}
-		if (success) {
-			mVideoFiles.remove(videoFile);
-			VideoFileDao.getInstance().deleteVideoFile(videoFile);
-			mAdapter.notifyDataSetChanged();
-		}
-		return success;
-	}
-
-	@Override
-	public boolean onCreateOptionsMenu(Menu menu) {
-		getMenuInflater().inflate(R.menu.menu_add_icon, menu);
-		return super.onCreateOptionsMenu(menu);
-	}
-
-	@Override
-	public boolean onOptionsItemSelected(MenuItem item) {
-		if (item.getItemId() == R.id.add_item) {
-			startActivityForResult(new Intent(LocalVideoActivity.this, VideoRecordActivity.class), 1);
-			return true;
-		}
-		return super.onOptionsItemSelected(item);
-	}
-
-	@Override
-	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-		if (requestCode == 1 && resultCode == RESULT_OK) {
-			if (data != null) {
-				String filePath = data.getStringExtra(VideoRecordActivity.EXTRA_RESULT_FILE_PATH);
-				long timeLen = data.getLongExtra(VideoRecordActivity.EXTRA_RESULT_TIME_LEN, 0);
-				if (timeLen <= 0) {
-					timeLen = 10 * 1000;// 数据出错,默认给个10s
-				}
-				long fizeSize = data.getLongExtra(VideoRecordActivity.EXTRA_RESULT_FILE_SIZE, 0);
-				if (fizeSize <= 0) {
-					fizeSize = 10 * 1024;// 数据出错,给个10k
-				}
-				VideoFile videoFile = new VideoFile();
-				videoFile.setCreateTime(TimeUtils.f_long_2_str(System.currentTimeMillis()));
-				videoFile.setFileLength(timeLen);
-				videoFile.setFileSize(fizeSize);
-				videoFile.setFilePath(filePath);
-				videoFile.setOwnerId(MyApplication.getInstance().mLoginUser.getUserId());
-				VideoFileDao.getInstance().addVideoFile(videoFile);
-				mVideoFiles.add(0, videoFile);
-				mAdapter.notifyDataSetChanged();
-			}
-		}
-	}
-
-	private class LocalVideoAdapter extends SlideBaseAdapter {
-
-		public LocalVideoAdapter(Context context) {
-			super(context);
-		}
-
-		@Override
-		public int getCount() {
-			return mVideoFiles.size();
-		}
-
-		@Override
-		public Object getItem(int position) {
-			return position;
-		}
-
-		@Override
-		public long getItemId(int position) {
-			return position;
-		}
-
-		@Override
-		public View getView(final int position, View convertView, ViewGroup parent) {
-			if (convertView == null) {
-				convertView = createConvertView(position);
-			}
-			ImageView thumbnail_img = ViewHolder.get(convertView, R.id.thumbnail_img);
-			TextView des_tv = ViewHolder.get(convertView, R.id.des_tv);
-			TextView create_time_tv = ViewHolder.get(convertView, R.id.create_time_tv);
-			TextView length_tv = ViewHolder.get(convertView, R.id.length_tv);
-			TextView size_tv = ViewHolder.get(convertView, R.id.size_tv);
-
-			TextView delete_tv = ViewHolder.get(convertView, R.id.delete_tv);
+    private PullToRefreshSlideListView mPullToRefreshListView;
+    private List<VideoFile> mVideoFiles;
+    private LocalVideoAdapter mAdapter;
+
+    private int mAction = AppConstant.ACTION_NONE;
+    private Handler mHandler;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        if (getIntent() != null) {
+            mAction = getIntent().getIntExtra(AppConstant.EXTRA_ACTION, AppConstant.ACTION_NONE);
+        }
+        setContentView(R.layout.layout_pullrefresh_list_slide);
+        mHandler = new Handler();
+        mVideoFiles = new ArrayList<VideoFile>();
+        mAdapter = new LocalVideoAdapter(this);
+        initView();
+
+    }
+
+    private void initView() {
+        getSupportActionBar().setTitle(R.string.local_video);
+        mPullToRefreshListView = (PullToRefreshSlideListView) findViewById(R.id.pull_refresh_list);
+
+        View emptyView = LayoutInflater.from(mContext).inflate(R.layout.layout_list_empty_view, null);
+        mPullToRefreshListView.setEmptyView(emptyView);
+
+        mPullToRefreshListView.getRefreshableView().setAdapter(mAdapter);
+        mPullToRefreshListView.setShowIndicator(false);
+
+        mPullToRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<SlideListView>() {
+            @Override
+            public void onRefresh(PullToRefreshBase<SlideListView> refreshView) {
+                loadData();
+            }
+        });
+
+        mPullToRefreshListView.getRefreshableView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+                if (mAction == AppConstant.ACTION_SELECT) {
+                    VideoFile videoFile = mVideoFiles.get((int) id);
+                    if (TextUtils.isEmpty(videoFile.getFilePath())) {
+                        ToastUtil.showToast(LocalVideoActivity.this, R.string.video_file_not_exist);
+                        return;
+                    }
+                    File file = new File(videoFile.getFilePath());
+                    if (!file.exists()) {
+                        ToastUtil.showToast(LocalVideoActivity.this, R.string.video_file_not_exist);
+                        return;
+                    }
+
+                    Intent intent = new Intent();
+                    intent.putExtra(AppConstant.EXTRA_SELECT_ID, videoFile.get_id());
+                    intent.putExtra(AppConstant.EXTRA_FILE_PATH, videoFile.getFilePath());
+                    intent.putExtra(AppConstant.EXTRA_TIME_LEN, videoFile.getFileLength());
+                    setResult(RESULT_OK, intent);
+                    finish();
+                }
+            }
+        });
+
+        mPullToRefreshListView.setAdapter(mAdapter);
+
+        loadData();
+    }
+
+    private void loadData() {
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                long startTime = System.currentTimeMillis();
+                final List<VideoFile> videos = VideoFileDao.getInstance().getVideoFiles(MyApplication.getInstance().mLoginUser.getUserId());
+                long delayTime = 200 - (startTime - System.currentTimeMillis());// 保证至少200ms的刷新过程
+                if (delayTime < 0) {
+                    delayTime = 0;
+                }
+                mHandler.postDelayed(new Runnable() {
+                    @Override
+                    public void run() {
+                        mVideoFiles.clear();
+                        if (videos != null && videos.size() > 0) {
+                            mVideoFiles.addAll(videos);
+                        }
+                        mAdapter.notifyDataSetChanged();
+                        mPullToRefreshListView.onRefreshComplete();
+                    }
+                }, delayTime);
+            }
+        }).start();
+    }
+
+    private boolean delete(VideoFile videoFile) {
+        boolean success = true;
+        String filePath = videoFile.getFilePath();
+        if (!TextUtils.isEmpty(filePath)) {
+            File file = new File(filePath);
+            if (file.exists()) {
+                success = file.delete();
+            }
+        }
+        if (success) {
+            mVideoFiles.remove(videoFile);
+            VideoFileDao.getInstance().deleteVideoFile(videoFile);
+            mAdapter.notifyDataSetChanged();
+        }
+        return success;
+    }
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        getMenuInflater().inflate(R.menu.menu_add_icon, menu);
+        return super.onCreateOptionsMenu(menu);
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        if (item.getItemId() == R.id.add_item) {
+//			startActivityForResult(new Intent(LocalVideoActivity.this, VideoRecordActivity.class), 1);
+            startActivityForResult(new Intent(LocalVideoActivity.this, VideoActivity.class), 1);
+            return true;
+        }
+        return super.onOptionsItemSelected(item);
+    }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        if (requestCode == 1 && resultCode == RESULT_OK) {
+            if (data != null) {
+                //转回来三个数据
+                String filePath = data.getStringExtra(VideoActivity.EXTRA_RESULT_FILE_PATH);
+                long timeLen = data.getLongExtra(VideoActivity.EXTRA_RESULT_TIME_LEN, 0);
+                long fizeSize = data.getLongExtra(VideoActivity.EXTRA_RESULT_FILE_SIZE, 0);
+                if (timeLen <= 0) {
+                    timeLen = 10 * 1000;// 数据出错,默认给个10s
+                }
+
+                if (fizeSize <= 0) {
+                    fizeSize = 10 * 1024;// 数据出错,给个10k
+                }
+                VideoFile videoFile = new VideoFile();
+
+                videoFile.setCreateTime(TimeUtils.f_long_2_str(System.currentTimeMillis()));
+                videoFile.setFileLength(timeLen);
+                videoFile.setFileSize(fizeSize);
+                videoFile.setFilePath(filePath);
+                videoFile.setOwnerId(MyApplication.getInstance().mLoginUser.getUserId());
+
+                Log.i("gong", filePath);
+                VideoFileDao.getInstance().addVideoFile(videoFile);
+                mVideoFiles.add(0, videoFile);
+                mAdapter.notifyDataSetChanged();
+            }
+        }
+    }
+
+    private class LocalVideoAdapter extends SlideBaseAdapter {
+
+        public LocalVideoAdapter(Context context) {
+            super(context);
+        }
+
+        @Override
+        public int getCount() {
+            return mVideoFiles.size();
+        }
+
+        @Override
+        public Object getItem(int position) {
+            return position;
+        }
+
+        @Override
+        public long getItemId(int position) {
+            return position;
+        }
+
+        @Override
+        public View getView(final int position, View convertView, ViewGroup parent) {
+            if (convertView == null) {
+                convertView = createConvertView(position);
+            }
+            ImageView thumbnail_img = ViewHolder.get(convertView, R.id.thumbnail_img);
+            TextView des_tv = ViewHolder.get(convertView, R.id.des_tv);
+            TextView create_time_tv = ViewHolder.get(convertView, R.id.create_time_tv);
+            TextView length_tv = ViewHolder.get(convertView, R.id.length_tv);
+            TextView size_tv = ViewHolder.get(convertView, R.id.size_tv);
+
+            TextView delete_tv = ViewHolder.get(convertView, R.id.delete_tv);
 
 			/* 获取缩略图显示 */
-			Bitmap bitmap = null;
-			String videoUrl = mVideoFiles.get(position).getFilePath();
-			if (!TextUtils.isEmpty(videoUrl)) {
-				bitmap = ImageLoader.getInstance().getMemoryCache().get(videoUrl);
-				if (bitmap == null || bitmap.isRecycled()) {
-					bitmap = ThumbnailUtils.createVideoThumbnail(videoUrl, Thumbnails.MINI_KIND);
-					if (bitmap != null) {
-						ImageLoader.getInstance().getMemoryCache().put(videoUrl, bitmap);
-					}
-				}
-			}
-			if (bitmap != null && !bitmap.isRecycled()) {
-				thumbnail_img.setImageBitmap(bitmap);
-			} else {
-				thumbnail_img.setImageBitmap(null);
-			}
-
-			thumbnail_img.setOnClickListener(new View.OnClickListener() {
-				@Override
-				public void onClick(View v) {
-					VideoFile videoFile = mVideoFiles.get(position);
-					if (videoFile == null) {
-						return;
-					}
-					if (TextUtils.isEmpty(videoFile.getFilePath())) {
-						ToastUtil.showToast(LocalVideoActivity.this, R.string.video_file_not_exist);
-						return;
-					}
-					File file = new File(videoFile.getFilePath());
-					if (!file.exists()) {
-						ToastUtil.showToast(LocalVideoActivity.this, R.string.video_file_not_exist);
-						delete(mVideoFiles.get(position));
-						return;
-					}
-					Intent intent = new Intent(LocalVideoActivity.this, VideoPlayActivity.class);
-					intent.putExtra(AppConstant.EXTRA_FILE_PATH, videoFile.getFilePath());
-					startActivity(intent);
-				}
-			});
+            Bitmap bitmap = null;
+            String videoUrl = mVideoFiles.get(position).getFilePath();
+            if (!TextUtils.isEmpty(videoUrl)) {
+                bitmap = ImageLoader.getInstance().getMemoryCache().get(videoUrl);
+                if (bitmap == null || bitmap.isRecycled()) {
+                    bitmap = ThumbnailUtils.createVideoThumbnail(videoUrl, Thumbnails.MINI_KIND);
+                    if (bitmap != null) {
+                        ImageLoader.getInstance().getMemoryCache().put(videoUrl, bitmap);
+                    }
+                }
+            }
+            if (bitmap != null && !bitmap.isRecycled()) {
+                thumbnail_img.setImageBitmap(bitmap);
+            } else {
+                thumbnail_img.setImageBitmap(null);
+            }
+
+            thumbnail_img.setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    VideoFile videoFile = mVideoFiles.get(position);
+                    if (videoFile == null) {
+                        return;
+                    }
+                    if (TextUtils.isEmpty(videoFile.getFilePath())) {
+                        ToastUtil.showToast(LocalVideoActivity.this, R.string.video_file_not_exist);
+                        return;
+                    }
+                    File file = new File(videoFile.getFilePath());
+                    if (!file.exists()) {
+                        ToastUtil.showToast(LocalVideoActivity.this, R.string.video_file_not_exist);
+                        delete(mVideoFiles.get(position));
+                        return;
+                    }
+                    Intent intent = new Intent(LocalVideoActivity.this, VideoPlayActivity.class);
+                    intent.putExtra(AppConstant.EXTRA_FILE_PATH, videoFile.getFilePath());
+                    startActivity(intent);
+                }
+            });
 
 			/* 其他信息 */
-			String des = mVideoFiles.get(position).getDesc();
-			if (TextUtils.isEmpty(des)) {
-				des_tv.setVisibility(View.GONE);
-			} else {
-				des_tv.setVisibility(View.VISIBLE);
-				des_tv.setText(des);
-			}
-			create_time_tv.setText(mVideoFiles.get(position).getCreateTime());
-			length_tv.setText(parserTimeLength(mVideoFiles.get(position).getFileLength()));
-			size_tv.setText(parserFileSize(mVideoFiles.get(position).getFileSize()));
-
-			delete_tv.setOnClickListener(new View.OnClickListener() {
-				@Override
-				public void onClick(View v) {
-					if (!delete(mVideoFiles.get(position))) {
-						ToastUtil.showToast(LocalVideoActivity.this, R.string.delete_failed);
-					}
-				}
-			});
-			return convertView;
-		}
-
-		@Override
-		public int getFrontViewId(int position) {
-			return R.layout.row_local_video;
-		}
-
-		@Override
-		public int getLeftBackViewId(int position) {
-			return 0;
-		}
-
-		@Override
-		public int getRightBackViewId(int position) {
-			return R.layout.row_item_delete;
-		}
-
-	}
-
-	private static String parserFileSize(long size) {
-		float temp = size / (float) 1024;
-		if (temp < 1024) {
-			return (int) temp + "KB";
-		}
-		temp = temp / 1024;
-		if (temp < 1024) {
-			return ((int) (temp * 100)) / (float) 100 + "M";
-		}
-		temp = temp / 1024;
-		return ((int) (temp * 100)) / (float) 100 + "G";
-	}
-
-	private String parserTimeLength(long length) {
-		int intLength = (int) (length / 1000);// 毫秒级转换为秒
-		int hour = intLength / 3600;
-		int temp = intLength - (hour * 3600);
-		int minute = temp / 60;
-		temp = temp - (minute * 60);
-		int second = temp;
-
-		StringBuilder sb = new StringBuilder();
-		if (hour != 0) {
-			sb.append(hour < 10 ? ("0" + hour) : hour).append(getString(R.string.hour));
-		}
-		if (minute != 0) {
-			sb.append(minute < 10 ? ("0" + minute) : minute).append(getString(R.string.minute));
-		}
-		if (second != 0) {
-			sb.append(second < 10 ? ("0" + second) : second).append(getString(R.string.second));
-		}
-		return sb.toString();
-	}
+            String des = mVideoFiles.get(position).getDesc();
+            if (TextUtils.isEmpty(des)) {
+                des_tv.setVisibility(View.GONE);
+            } else {
+                des_tv.setVisibility(View.VISIBLE);
+                des_tv.setText(des);
+            }
+            create_time_tv.setText(mVideoFiles.get(position).getCreateTime());
+            length_tv.setText(parserTimeLength(mVideoFiles.get(position).getFileLength()));
+            size_tv.setText(parserFileSize(mVideoFiles.get(position).getFileSize()));
+
+            delete_tv.setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    if (!delete(mVideoFiles.get(position))) {
+                        ToastUtil.showToast(LocalVideoActivity.this, R.string.delete_failed);
+                    }
+                }
+            });
+            return convertView;
+        }
+
+        @Override
+        public int getFrontViewId(int position) {
+            return R.layout.row_local_video;
+        }
+
+        @Override
+        public int getLeftBackViewId(int position) {
+            return 0;
+        }
+
+        @Override
+        public int getRightBackViewId(int position) {
+            return R.layout.row_item_delete;
+        }
+
+    }
+
+    private static String parserFileSize(long size) {
+        float temp = size / (float) 1024;
+        if (temp < 1024) {
+            return (int) temp + "KB";
+        }
+        temp = temp / 1024;
+        if (temp < 1024) {
+            return ((int) (temp * 100)) / (float) 100 + "M";
+        }
+        temp = temp / 1024;
+        return ((int) (temp * 100)) / (float) 100 + "G";
+    }
+
+    private String parserTimeLength(long length) {
+        int intLength = (int) (length / 1000);// 毫秒级转换为秒
+        int hour = intLength / 3600;
+        int temp = intLength - (hour * 3600);
+        int minute = temp / 60;
+        temp = temp - (minute * 60);
+        int second = temp;
+
+        StringBuilder sb = new StringBuilder();
+        if (hour != 0) {
+            sb.append(hour < 10 ? ("0" + hour) : hour).append(getString(R.string.hour));
+        }
+        if (minute != 0) {
+            sb.append(minute < 10 ? ("0" + minute) : minute).append(getString(R.string.minute));
+        }
+        if (second != 0) {
+            sb.append(second < 10 ? ("0" + second) : second).append(getString(R.string.second));
+        }
+        return sb.toString();
+    }
 
 }

+ 0 - 17
WeiChat/src/main/java/com/xzjmyk/pm/activity/util/ViewAlphaUtil.java

@@ -1,17 +0,0 @@
-package com.xzjmyk.pm.activity.util;
-
-/**
- * Created by gongpengming on 2016/4/8.
- */
-public class ViewAlphaUtil {
-
-//    public static void setViewAlpha(View view) {
-//        view.getBackground().setAlpha(30);
-//    }
-
-//    public static void setViewAlpha(View view, int alpha) {
-//        view.getBackground().setAlpha(alpha);
-//    }
-
-
-}

+ 300 - 0
WeiChat/src/main/java/com/xzjmyk/pm/activity/video/VideoActivity.java

@@ -0,0 +1,300 @@
+package com.xzjmyk.pm.activity.video;
+
+
+import android.annotation.SuppressLint;
+import android.content.Intent;
+import android.hardware.Camera;
+import android.media.CamcorderProfile;
+import android.media.MediaRecorder;
+import android.os.Bundle;
+import android.os.CountDownTimer;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+
+import com.xzjmyk.pm.activity.R;
+import com.xzjmyk.pm.activity.ui.base.BaseActivity;
+import com.xzjmyk.pm.activity.util.FileUtil;
+
+import java.io.File;
+import java.io.IOException;
+
+
+/**
+ * Created by gongpm on 2016/6/8.
+ */
+public class VideoActivity extends BaseActivity implements MediaRecorder.OnErrorListener {
+    private Camera mCamera;
+    private TextView tvTime;
+    private Button btn;
+    private CountDownTimer countDownTimer;
+    private SurfaceView surfaceView;
+    private SurfaceHolder mSurfaceHolder;
+    private MediaRecorder mMediaRecorder;
+    private File mVecordFile;
+    private int timeLen = 0;  //时间长度
+    public static final String EXTRA_RESULT_FILE_PATH = "result_file_path";
+    public static final String EXTRA_RESULT_TIME_LEN = "result_time_len";
+    public static final String EXTRA_RESULT_FILE_SIZE = "result_file_size";
+    private int MAX_NUM = 30;
+    private int SPEED = 1;
+    private String filePath;
+
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_video);
+        Log.i("gong", " FileUtil.getRandomVideoFilePath();=" + FileUtil.getRandomVideoFilePath());
+        surfaceView = (SurfaceView) findViewById(R.id.lib_surface_view);
+        tvTime = (TextView) findViewById(R.id.lib_video_tv_time);
+        btn = (Button) findViewById(R.id.btn);
+        btn.setOnTouchListener(new View.OnTouchListener() {
+            @Override
+            public boolean onTouch(View v, MotionEvent event) {
+                if (event.getAction() == MotionEvent.ACTION_DOWN) {
+                    beginHandler(MAX_NUM, SPEED);
+                    record();
+                } else if (event.getAction() == MotionEvent.ACTION_UP) {
+                    countDownTimer.cancel();
+                    tvTime.setText("录制完成");
+                    stop();
+                }
+                return false;
+            }
+        });
+        mSurfaceHolder = surfaceView.getHolder();
+        mSurfaceHolder.addCallback(new CustomCallBack());
+
+    }
+
+
+    private void doTheEnd() {
+        //TODO 拍摄成功后最后操作
+        Intent intent = new Intent();
+        intent.putExtra(EXTRA_RESULT_FILE_PATH, filePath);
+        intent.putExtra(EXTRA_RESULT_TIME_LEN, MAX_NUM - timeLen);
+        intent.putExtra(EXTRA_RESULT_FILE_SIZE, mVecordFile.length());
+        setResult(RESULT_OK, intent);
+        finish();
+    }
+
+
+    public void beginHandler(final int max_num, int speed) {
+        countDownTimer = new CountDownTimer(max_num * 1000, speed * 1000) {
+            @Override
+            public void onTick(long millisUntilFinished) {
+                timeLen = (int) (millisUntilFinished / 1000);
+                tvTime.setText("倒计时:" + timeLen);
+            }
+
+            @Override
+            public void onFinish() {
+                tvTime.setText("录制完成");
+                stop();
+            }
+        };
+        countDownTimer.start();
+    }
+
+    /**
+     * 初始化摄像头
+     */
+    private void initCamera() throws IOException {
+        if (mCamera != null) {
+            freeCameraResource();
+        }
+        try {
+            mCamera = Camera.open();
+        } catch (Exception e) {
+            freeCameraResource();
+        }
+        if (mCamera == null)
+            return;
+        setCameraParams();
+        mCamera.setDisplayOrientation(90);
+        mCamera.setPreviewDisplay(mSurfaceHolder);
+        mCamera.startPreview();
+    }
+
+    /**
+     * 设置摄像头为竖屏
+     */
+    private void setCameraParams() {
+        if (mCamera != null) {
+            Camera.Parameters params = mCamera.getParameters();
+            params.set("orientation", "portrait");
+            mCamera.setParameters(params);
+        }
+    }
+
+    /**
+     * 保存的位置处理
+     */
+    private void createRecordDir() {
+        //录制的视频保存文件夹
+//        File sampleDir = new File(Environment.getExternalStorageDirectory()
+//                + File.separator + "ysb/video/");//录制视频的保存地址
+//        if (!sampleDir.exists()) {
+//            sampleDir.mkdirs();
+//        }
+//        File vecordDir = sampleDir;
+        filePath = FileUtil.getRandomVideoFilePath();
+        // 创建文件
+        // mp4格式的录制的视频文件
+//            mVecordFile = File.createTempFile("recording", ".mp4", vecordDir);
+        mVecordFile = new File(filePath);
+    }
+
+    /**
+     * 开始录制视频
+     * 视频储存位置
+     */
+    public void record() {
+        createRecordDir();
+        try {
+            initCamera();
+            if (initRecord() == true) {
+                mMediaRecorder.start();
+            } else {
+                releaseRecord();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 停止拍摄
+     */
+    public void stop() {
+        stopRecord();
+        releaseRecord();
+        freeCameraResource();
+        doTheEnd();
+
+    }
+
+
+    /**
+     * 停止录制
+     */
+    public void stopRecord() {
+        if (mMediaRecorder != null) {
+            try {
+                mMediaRecorder.stop();
+                mMediaRecorder.reset();
+            } catch (IllegalStateException e) {
+                e.printStackTrace();
+            } catch (RuntimeException e) {
+                e.printStackTrace();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    /**
+     * 释放资源
+     */
+    private void releaseRecord() {
+        if (mMediaRecorder != null) {
+            mMediaRecorder.reset();
+            mMediaRecorder = null;
+            if (mCamera != null)
+                mCamera.lock();
+        }
+    }
+
+    /**
+     * 释放摄像头资源
+     */
+    private void freeCameraResource() {
+        if (mCamera != null) {
+            mCamera.setPreviewCallback(null);
+            mCamera.stopPreview();
+            mCamera.release();
+            mCamera = null;
+        }
+    }
+
+    /**
+     * 初始化
+     *
+     * @throws IOException
+     */
+    @SuppressLint("NewApi")
+    private boolean initRecord() throws IOException {
+        mMediaRecorder = new MediaRecorder();
+        if (mCamera == null) {
+            return false;
+        }
+        mCamera.unlock();
+        mMediaRecorder.setCamera(mCamera);
+        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
+        mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
+        CamcorderProfile highCameraProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
+        mMediaRecorder.setProfile(highCameraProfile);
+        mMediaRecorder.setMaxDuration(100000); // MAXDuration 10 seconds
+        mMediaRecorder.setMaxFileSize(20000000); // MAXSIZE 20 megabytes
+        mMediaRecorder.setOrientationHint(90);// 输出旋转90度,保持竖屏录制
+        if (mVecordFile == null) {
+            createRecordDir();
+        }
+        mMediaRecorder.setOutputFile(mVecordFile.getAbsolutePath());
+        mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
+        try {
+            mMediaRecorder.prepare();
+        } catch (IllegalStateException e) {
+            releaseRecord();
+            return false;
+        } catch (IOException e) {
+            releaseRecord();
+            return false;
+        }
+        return true;
+    }
+
+
+    @Override
+    public void onError(MediaRecorder mr, int what, int extra) {
+        try {
+            if (mr != null)
+                mr.reset();
+        } catch (IllegalStateException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
+    /**
+     * 视频拍摄回调
+     */
+    class CustomCallBack implements SurfaceHolder.Callback {
+
+        @Override
+        public void surfaceCreated(SurfaceHolder holder) {
+            try {
+                initCamera();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        @Override
+        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+
+        }
+
+        @Override
+        public void surfaceDestroyed(SurfaceHolder holder) {
+            freeCameraResource();
+        }
+    }
+}

+ 2 - 0
WeiChat/src/main/java/com/xzjmyk/pm/activity/video/VideoRecordActivity.java

@@ -175,9 +175,11 @@ public class VideoRecordActivity extends Activity {
 			ToastUtil.showToast(this, R.string.record_succ);
 			// 录制成功,返回数据
 			Intent intent = new Intent();
+
 			intent.putExtra(EXTRA_RESULT_FILE_PATH, file.getAbsolutePath());
 			intent.putExtra(EXTRA_RESULT_TIME_LEN, timeLen);
 			intent.putExtra(EXTRA_RESULT_FILE_SIZE, file.length());
+
 			setResult(RESULT_OK, intent);
 			finish();
 		}

+ 38 - 0
WeiChat/src/main/res/layout/activity_video.xml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <SurfaceView
+        android:id="@+id/lib_surface_view"
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:layout_weight="5" />
+
+    <RelativeLayout
+        android:id="@+id/lib_video_rl"
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:layout_weight="2">
+
+        <TextView
+            android:id="@+id/lib_video_tv_time"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_above="@+id/btn"
+            android:layout_marginBottom="2dp"
+            android:gravity="center"
+            android:textColor="@color/red" />
+
+        <Button
+            android:id="@+id/btn"
+            android:layout_width="100dp"
+            android:layout_height="100dp"
+            android:layout_centerInParent="true"
+            android:background="@drawable/button_round_shape"
+            android:text="按下拍"
+            android:textColor="@color/white" />
+    </RelativeLayout>
+</LinearLayout>