main.xml
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/arc_hf_search_result" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/arc_hf_search_item" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > </LinearLayout> </ScrollView>
ArcHFSearchResult.java
public class ArcHFSearchResult extends Activity { protected static final String TAG = "ArcHFSearchResult"; private ScrollView svResult; private LinearLayout llItem; private String[] arrayStr; private int pageCount = 0; private int resultCount = 10000; private int eachCount = 3000; private View view; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); svResult = (ScrollView) findViewById(R.id.arc_hf_search_result); llItem = (LinearLayout) findViewById(R.id.arc_hf_search_item); svResult.setOnTouchListener(svListener); view = svResult.getChildAt(0); // 将要显示的10000条数据 arrayStr = new String[resultCount]; for (int i = 0; i < resultCount; i++) { arrayStr[i] = i + ""; } // 第一次添加数据,每次添加3000条。 AddResult(); } class svTouchListener implements OnTouchListener { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_UP: // 如果触发监听事件,并且有内容,并且ScrollView已经拉到底部,加载一次数据 if (svListener != null && view != null && view.getMeasuredHeight() - 20 <= svResult .getScrollY() + svResult.getHeight()) { AddResult(); } break; default: break; } return false; } } svTouchListener svListener = new svTouchListener(); /** * 添加结果 */ protected void AddResult() { if (eachCount * pageCount < resultCount) { for (int i = 0; i < eachCount; i++) { int k = i + eachCount * pageCount; if (k >= resultCount) break; TextView tv = new TextView(this); tv.setText("hello world" + arrayStr[k]); llItem.addView(tv); } pageCount++; } } }
posted @ 2012-06-01 13:19 oldfeel 阅读(163) 评论(0) 编辑
转自 http://blog.sina.com.cn/s/blog_63a27dc501012iyl.html
方法一:SSH+autoproxy+firefox
1.首先要安装openSSH,
Ubuntu缺省没有安装SSH Server,使用以下命令安装:
sudo apt-get install openssh-server
2.在firfox中搜索安装autoproxy这个扩展组件,安装完成之后,会自动打开一个设置页面,选择gfwlist 这个规则,然后在最下面选择默认代理,设置为ssh -D 这种方式,之后点完成,完成设置
3.本地的设置完毕之后,到http://www.cjb.net/cgi-bin/shell.cgi?action=signup 注 册一个免费的ssh的帐号,填上你的用户名, 邮箱, 设置密码就成了,邮箱最好是用gmail的邮箱,其他的邮箱我也没尝试过,然后cjb会给你发激活邮件, 收信点里边的激活链接,激活后会再发送一个邮件给你,告诉你帐号,密码,服务器之类的,有时候注册网站打不开,多尝试几次就好了
4.有了以上的准备工作后,在终端输入ssh -qTfnN -D 7070 user_name@216.194.70.6
例如我自己的就是ssh -qTfnN -D 7070 shenhao0129@216.194.70.6
其中@之前的user_name换成你刚才自己的申请的用户名就好了,本来@之后是主机名shell.cjb.net的,但是据说是DNS污染,导致指向的不是正确的IP地址,所以直接用IP地址来代替
然后第一次运行会有个小提示,你直接输入yes就好了,然后提示输入密码,输入你申请的帐号的密码就万事OK了
5. 如果认为每次输入这个东西比较麻烦的话,建议vim sshd,建立一个sshd的文本文件,然后把刚才输入的内容粘贴到sshd文件中,并chmod 755 sshd 然后拷贝到/usr/bin目录下,以后要翻墙的时候就执行sshd,输入密码就好了,系统启动后,之需要输入一次就好了。
5.剩下的就不用多说了,赶快打开www.youtube.com测试一下吧!
方法二: phzilla
1.首先搜索安装phzilla这个firefox扩展phproxy 找到Phzilla这个(对,你没有弄错,就是这个)插件安装,然后提示重启firefox的时候重新启动firefox。
2.在地址栏最后面那可以看到一个P字的小图标,右击那个小图标,选择选项,打开设置页面,单击“使用默认服务”,然后选择开始测试,看到左边有成功的字样之后,点“建议此服务器”,然后关闭设置窗口,打开www.youtube.com 是不是依然显示“连接被重置”等???别着急,再次点击那个P字的小图标,然后刷新一下,一般就能上了。
3.如果此时还不能打开的话,那么你需要回到上一步骤,然后重新选择服务器,重新测试,重新使用建议服务器等设置就好了。也可以自己添加服务器的,我就不详细说了。
Ubuntu缺省没有安装SSH Server,使用以下命令安装:
sudo apt-get install openssh-server
2.在firfox中搜索安装autoproxy这个扩展组件,安装完成之后,会自动打开一个设置页面,选择gfwlist 这个规则,然后在最下面选择默认代理,设置为ssh -D 这种方式,之后点完成,完成设置
3.本地的设置完毕之后,到http://www.cjb.net/cgi-bin/shell.cgi?action=signup 注 册一个免费的ssh的帐号,填上你的用户名, 邮箱, 设置密码就成了,邮箱最好是用gmail的邮箱,其他的邮箱我也没尝试过,然后cjb会给你发激活邮件, 收信点里边的激活链接,激活后会再发送一个邮件给你,告诉你帐号,密码,服务器之类的,有时候注册网站打不开,多尝试几次就好了
4.有了以上的准备工作后,在终端输入ssh -qTfnN -D 7070 user_name@216.194.70.6
例如我自己的就是ssh -qTfnN -D 7070 shenhao0129@216.194.70.6
其中@之前的user_name换成你刚才自己的申请的用户名就好了,本来@之后是主机名shell.cjb.net的,但是据说是DNS污染,导致指向的不是正确的IP地址,所以直接用IP地址来代替
然后第一次运行会有个小提示,你直接输入yes就好了,然后提示输入密码,输入你申请的帐号的密码就万事OK了
5. 如果认为每次输入这个东西比较麻烦的话,建议vim sshd,建立一个sshd的文本文件,然后把刚才输入的内容粘贴到sshd文件中,并chmod 755 sshd 然后拷贝到/usr/bin目录下,以后要翻墙的时候就执行sshd,输入密码就好了,系统启动后,之需要输入一次就好了。
5.剩下的就不用多说了,赶快打开www.youtube.com测试一下吧!
方法二: phzilla
1.首先搜索安装phzilla这个firefox扩展phproxy 找到Phzilla这个(对,你没有弄错,就是这个)插件安装,然后提示重启firefox的时候重新启动firefox。
2.在地址栏最后面那可以看到一个P字的小图标,右击那个小图标,选择选项,打开设置页面,单击“使用默认服务”,然后选择开始测试,看到左边有成功的字样之后,点“建议此服务器”,然后关闭设置窗口,打开www.youtube.com 是不是依然显示“连接被重置”等???别着急,再次点击那个P字的小图标,然后刷新一下,一般就能上了。
3.如果此时还不能打开的话,那么你需要回到上一步骤,然后重新选择服务器,重新测试,重新使用建议服务器等设置就好了。也可以自己添加服务器的,我就不详细说了。
方法三:wine
先装好wine
sodu apt-get install wine;
sodu apt-get install wine;
然后终端:
wget http://www.kegel.com/wine/winetricks
sudo apt-get install cabextract
chmod +x winetricks
./winetricks
在弹出的窗口选择你需要的库
想要在wine上使用Free Gate就需要添加mfc42才行
然后配合firefox+autoproxy就不再“撞墙”了!
wget http://www.kegel.com/wine/winetricks
sudo apt-get install cabextract
chmod +x winetricks
./winetricks
在弹出的窗口选择你需要的库
想要在wine上使用Free Gate就需要添加mfc42才行
然后配合firefox+autoproxy就不再“撞墙”了!
posted @ 2012-05-27 13:41 oldfeel 阅读(157) 评论(1) 编辑
建一个AsyncLoadedImage类继承AsyncTask异步加载类,调用publishProgress方法更新onProgressUpdate贮存缩略图信息到Adapter。监听Adapter Change实现异步加载缩略图。
main.xml
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <GridView android:id="@+id/sdcard" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:horizontalSpacing="10dp" android:numColumns="auto_fit" android:stretchMode="columnWidth" android:verticalSpacing="10dp" /> </FrameLayout>
MFile.java
public class MFile extends Activity { private GridView sdcardImages; private FileAdapter fileAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.main); setupViews(); setProgressBarIndeterminateVisibility(true); new AsyncLoadedImage().execute(); } /* * 释放Bitmap内存 */ protected void onDestroy() { super.onDestroy(); final GridView grid = sdcardImages; final int count = grid.getChildCount(); ImageView v = null; for (int i = 0; i < count; i++) { v = (ImageView) grid.getChildAt(i); ((BitmapDrawable) v.getDrawable()).setCallback(null); } } /* * 初始化文件浏览View */ private void setupViews() { sdcardImages = (GridView) findViewById(R.id.sdcard); sdcardImages.setOnItemClickListener(new fileListener()); fileAdapter = new FileAdapter(getApplicationContext()); sdcardImages.setAdapter(fileAdapter); } /* * 刷新Adapter */ private void addImage(LoadedImage... value) { for (LoadedImage image : value) { fileAdapter.addPhoto(image); fileAdapter.notifyDataSetChanged(); } } /* * 点击监听 */ class fileListener implements OnItemClickListener { @Override public void onItemClick(AdapterView<?> paramAdapterView, View paramView, int paramInt, long paramLong) { } } /* * 异步加载缩略图到LoadedImage然后调用addImage方法更新Adapter */ class AsyncLoadedImage extends AsyncTask<Object, LoadedImage, Object> { @Override protected Object doInBackground(Object... params) { String path = Environment.getExternalStorageDirectory() .getAbsolutePath() + "/hfdatabase/3/img"; File file = new File(path); if (!file.exists()) { file.mkdirs(); } else { File[] files = file.listFiles(); String[] paths = new String[files.length]; Bitmap bitmap; Bitmap newBitmap; for (int i = 0; i < files.length; i++) { paths[i] = files[i].getPath(); try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 10; bitmap = BitmapFactory.decodeFile(paths[i], options); newBitmap = ThumbnailUtils.extractThumbnail(bitmap, 80, 80); bitmap.recycle(); if (newBitmap != null) { publishProgress(new LoadedImage(newBitmap)); } } catch (Exception e) { e.printStackTrace(); } } } return null; } @Override public void onProgressUpdate(LoadedImage... value) { addImage(value); } @Override protected void onPostExecute(Object result) { setProgressBarIndeterminateVisibility(false); } } /* * Adapter */ class FileAdapter extends BaseAdapter { private Context mContext; private ArrayList<LoadedImage> photos = new ArrayList<LoadedImage>(); public FileAdapter(Context context) { mContext = context; } public void addPhoto(LoadedImage photo) { photos.add(photo); } public int getCount() { return photos.size(); } public Object getItem(int position) { return photos.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { final ImageView imageView; if (convertView == null) { imageView = new ImageView(mContext); } else { imageView = (ImageView) convertView; } imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); imageView.setPadding(8, 8, 8, 8); imageView.setImageBitmap(photos.get(position).getBitmap()); return imageView; } } /* * 这是个保存bitmap的类,加入Adapter的ArrayList中,随着addImage更新Adapter */ private static class LoadedImage { Bitmap mBitmap; LoadedImage(Bitmap bitmap) { mBitmap = bitmap; } public Bitmap getBitmap() { return mBitmap; } } /* * 消息提示 */ private Toast toast; public void showMsg(String arg) { if (toast == null) { toast = Toast.makeText(this, arg, Toast.LENGTH_SHORT); } else { toast.cancel(); toast.setText(arg); } toast.show(); } }
posted @ 2012-05-24 08:23 oldfeel 阅读(283) 评论(0) 编辑
先在 manifest 里添加权限
<uses-permission android:name="android.permission.CAMERA" /> <!-- 调用摄像头权限 --> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <!-- 录制视频/音频权限 --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- sd卡读写权限 --> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <!-- 挂载sd卡 -->
layout 布局预览窗口 camera.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <SurfaceView android:id="@+id/arc_hf_video_view" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <TextView android:id="@+id/arc_hf_video_timer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="40dp" android:textColor="#ffff0000" android:textSize="35dp" android:textStyle="bold" > </TextView> <LinearLayout android:id="@+id/arc_hf_video_btn" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentRight="true" android:gravity="center" android:orientation="vertical" > <Button android:id="@+id/arc_hf_video_start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/arc_hf_btn_video_start" /> <Button android:id="@+id/arc_hf_img_start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/arc_hf_btn_img" /> </LinearLayout> </RelativeLayout>
主Activity MCamera.java
public class MCamera extends Activity { private Button mVideoStartBtn; private SurfaceView mSurfaceview; private MediaRecorder mMediaRecorder; private SurfaceHolder mSurfaceHolder; private File mRecVedioPath; private File mRecAudioFile; private TextView timer; private int hour = 0; private int minute = 0; private int second = 0; private boolean bool; private int parentId; protected Camera camera; protected boolean isPreview; private Drawable iconStart; private Drawable iconStop; private boolean isRecording = true; // true表示没有录像,点击开始;false表示正在录像,点击暂停 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* * 全屏显示 */ this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setFormat(PixelFormat.TRANSLUCENT); setContentView(R.layout.map_video); iconStart = getResources().getDrawable( R.drawable.arc_hf_btn_video_start); iconStop = getResources().getDrawable(R.drawable.arc_hf_btn_video_stop); parentId = getIntent().getIntExtra("parentId", 0); timer = (TextView) findViewById(R.id.arc_hf_video_timer); mVideoStartBtn = (Button) findViewById(R.id.arc_hf_video_start); mSurfaceview = (SurfaceView) this.findViewById(R.id.arc_hf_video_view); // 设置计时器不可见 timer.setVisibility(View.GONE); // 设置缓存路径 mRecVedioPath = new File(Environment.getExternalStorageDirectory() .getAbsolutePath() + "/hfdatabase/video/temp/"); if (!mRecVedioPath.exists()) { mRecVedioPath.mkdirs(); } // 绑定预览视图 SurfaceHolder holder = mSurfaceview.getHolder(); holder.addCallback(new Callback() { @Override public void surfaceDestroyed(SurfaceHolder holder) { if (camera != null) { if (isPreview) { camera.stopPreview(); isPreview = false; } camera.release(); camera = null; // 记得释放 } mSurfaceview = null; mSurfaceHolder = null; mMediaRecorder = null; } @Override public void surfaceCreated(SurfaceHolder holder) { try { camera = Camera.open(); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewFrameRate(5); // 每秒5帧 parameters.setPictureFormat(PixelFormat.JPEG);// 设置照片的输出格式 parameters.set("jpeg-quality", 85);// 照片质量 camera.setParameters(parameters); camera.setPreviewDisplay(holder); camera.startPreview(); isPreview = true; } catch (Exception e) { e.printStackTrace(); } mSurfaceHolder = holder; } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { mSurfaceHolder = holder; } }); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); mVideoStartBtn.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { if (isRecording) { /* * 点击开始录像 */ if (isPreview) { camera.stopPreview(); camera.release(); camera = null; } second = 0; minute = 0; hour = 0; bool = true; if (mMediaRecorder == null) mMediaRecorder = new MediaRecorder(); else mMediaRecorder.reset(); mMediaRecorder.setPreviewDisplay(mSurfaceHolder .getSurface()); mMediaRecorder .setVideoSource(MediaRecorder.VideoSource.CAMERA); mMediaRecorder .setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder .setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mMediaRecorder .setVideoEncoder(MediaRecorder.VideoEncoder.H264); mMediaRecorder .setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); mMediaRecorder.setVideoSize(320, 240); mMediaRecorder.setVideoFrameRate(15); try { mRecAudioFile = File.createTempFile("Vedio", ".3gp", mRecVedioPath); } catch (IOException e) { e.printStackTrace(); } mMediaRecorder.setOutputFile(mRecAudioFile .getAbsolutePath()); try { mMediaRecorder.prepare(); timer.setVisibility(View.VISIBLE); handler.postDelayed(task, 1000); mMediaRecorder.start(); } catch (Exception e) { e.printStackTrace(); } showMsg("开始录制"); mVideoStartBtn.setBackgroundDrawable(iconStop); isRecording = !isRecording; } else { /* * 点击停止 */ try { bool = false; mMediaRecorder.stop(); timer.setText(format(hour) + ":" + format(minute) + ":" + format(second)); mMediaRecorder.release(); mMediaRecorder = null; videoRename(); } catch (Exception e) { e.printStackTrace(); } isRecording = !isRecording; mVideoStartBtn.setBackgroundDrawable(iconStart); showMsg("录制完成,已保存"); try { camera = Camera.open(); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewFrameRate(5); // 每秒5帧 parameters.setPictureFormat(PixelFormat.JPEG);// 设置照片的输出格式 parameters.set("jpeg-quality", 85);// 照片质量 camera.setParameters(parameters); camera.setPreviewDisplay(mSurfaceHolder); camera.startPreview(); isPreview = true; } catch (Exception e) { e.printStackTrace(); } } } }); Button btnImgStart = (Button) findViewById(R.id.arc_hf_img_start); btnImgStart.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mMediaRecorder != null) { try { bool = false; mMediaRecorder.stop(); timer.setText(format(hour) + ":" + format(minute) + ":" + format(second)); mMediaRecorder.release(); mMediaRecorder = null; videoRename(); } catch (Exception e) { e.printStackTrace(); } isRecording = !isRecording; mVideoStartBtn.setBackgroundDrawable(iconStart); showMsg("录制完成,已保存"); try { camera = Camera.open(); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewFrameRate(5); // 每秒5帧 parameters.setPictureFormat(PixelFormat.JPEG);// 设置照片的输出格式 parameters.set("jpeg-quality", 85);// 照片质量 camera.setParameters(parameters); camera.setPreviewDisplay(mSurfaceHolder); camera.startPreview(); isPreview = true; } catch (Exception e) { e.printStackTrace(); } } if (camera != null) { camera.autoFocus(null); camera.takePicture(null, null, new PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) { Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); Matrix matrix = new Matrix(); // 设置缩放 matrix.postScale(5f, 4f); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); String path = Environment .getExternalStorageDirectory() .getAbsolutePath() + "/hfdatabase/img/" + String.valueOf(parentId) + "/"; String fileName = new SimpleDateFormat( "yyyyMMddHHmmss").format(new Date()) + ".jpg"; File out = new File(path); if (!out.exists()) { out.mkdirs(); } out = new File(path, fileName); try { FileOutputStream outStream = new FileOutputStream( out); bitmap.compress(CompressFormat.JPEG, 100, outStream); outStream.close(); camera.startPreview(); } catch (Exception e) { e.printStackTrace(); } showMsg("拍照成功"); } }); // 拍照 } } }); } /* * 消息提示 */ private Toast toast; public void showMsg(String arg) { if (toast == null) { toast = Toast.makeText(this, arg, Toast.LENGTH_SHORT); } else { toast.cancel(); toast.setText(arg); } toast.show(); } /* * 生成video文件名字 */ protected void videoRename() { String path = Environment.getExternalStorageDirectory() .getAbsolutePath() + "/hfdatabase/video/" + String.valueOf(parentId) + "/"; String fileName = new SimpleDateFormat("yyyyMMddHHmmss") .format(new Date()) + ".3gp"; File out = new File(path); if (!out.exists()) { out.mkdirs(); } out = new File(path, fileName); if (mRecAudioFile.exists()) mRecAudioFile.renameTo(out); } /* * 定时器设置,实现计时 */ private Handler handler = new Handler(); private Runnable task = new Runnable() { public void run() { if (bool) { handler.postDelayed(this, 1000); second++; if (second >= 60) { minute++; second = second % 60; } if (minute >= 60) { hour++; minute = minute % 60; } timer.setText(format(hour) + ":" + format(minute) + ":" + format(second)); } } }; /* * 格式化时间 */ public String format(int i) { String s = i + ""; if (s.length() == 1) { s = "0" + s; } return s; } /* * 覆写返回键监听 */ @Override public void onBackPressed() { if (mMediaRecorder != null) { mMediaRecorder.stop(); mMediaRecorder.release(); mMediaRecorder = null; videoRename(); } finish(); } @Override protected void onPause() { super.onPause(); onBackPressed(); } }
浏览图片/视频 FileShow.java
public class FileShow extends Activity { private static final int MENU_DELETE = Menu.FIRST; private static final int MENU_RENAME = Menu.FIRST + 1; private File[] files; private String[] names; private String[] paths; private GridView fileGrid; private BaseAdapter adapter = null; private String path; private EditText etRename; private File file; protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.map_file_show); path = getIntent().getStringExtra("path"); File file = new File(path); files = file.listFiles(); fileGrid = (GridView) findViewById(R.id.arc_hf_file_show); adapter = new fileAdapter(this); fileGrid.setAdapter(adapter); showFileItems(); fileGrid.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { File f = new File(paths[arg2]); Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(android.content.Intent.ACTION_VIEW); String type = thisFileType(names[arg2]); intent.setDataAndType(Uri.fromFile(f), type); startActivity(intent); } }); // 注册上下文菜单 registerForContextMenu(fileGrid); } /* * 覆写上下文菜单 */ @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); AdapterView.AdapterContextMenuInfo info = null; try { info = (AdapterView.AdapterContextMenuInfo) menuInfo; } catch (ClassCastException e) { return; } menu.setHeaderTitle(names[info.position]); menu.add(0, MENU_DELETE, 1, "删除"); menu.add(0, MENU_RENAME, 2, "重命名"); } /* * 上下文菜单监听 */ @Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item .getMenuInfo(); File file = new File(paths[info.position]); switch (item.getItemId()) { case MENU_DELETE: file.delete(); showFileItems(); return true; case MENU_RENAME: fileRename(file); return true; default: return super.onContextItemSelected(item); } } /* * 获取文件 */ private void showFileItems() { File file = new File(path); files = file.listFiles(); int count = files.length; names = new String[count]; paths = new String[count]; for (int i = 0; i < count; i++) { File f = files[i]; names[i] = f.getName(); paths[i] = f.getPath(); } adapter.notifyDataSetChanged(); } /* * 获取文件类型 */ public static String thisFileType(String name) { String type = ""; String end = name.substring(name.lastIndexOf(".") + 1, name.length()) .toLowerCase(); if (end.equals("jpg")) { type = "image"; } else if (end.equals("3gp")) { type = "video"; } else { type = "*"; } type += "/*"; return type; } /** * 重命名 */ private void fileRename(File file) { this.file = file; View view = getLayoutInflater().inflate(R.layout.map_file_rename, null); etRename = (EditText) view.findViewById(R.id.arc_hf_file_rename); new AlertDialog.Builder(this).setView(view) .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String newName = etRename.getText().toString().trim(); File newFile = new File(path, newName); if (newFile.exists()) { showMsg(newName + "已经存在,请重新输入"); } else FileShow.this.file.renameTo(newFile); showFileItems(); } }).setNegativeButton("取消", null).show(); } /* * 消息提示 */ private Toast toast; public void showMsg(String arg) { if (toast == null) { toast = Toast.makeText(this, arg, Toast.LENGTH_SHORT); } else { toast.cancel(); toast.setText(arg); } toast.show(); } /* * File adapter设置 */ class fileAdapter extends BaseAdapter { Context context; public fileAdapter(Context context) { this.context = context; } @Override public int getCount() { return files.length; } @Override public Object getItem(int arg0) { // return files[arg0]; return names[arg0]; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { String type = thisFileType(names[position]); convertView = getLayoutInflater().inflate(R.layout.map_file_item, null); ImageView icon = (ImageView) convertView .findViewById(R.id.arc_hf_file_icon); TextView name = (TextView) convertView .findViewById(R.id.arc_hf_file_name); if (type.equals("video/*")) { Bitmap videoIcon = ThumbnailUtils.createVideoThumbnail( paths[position], Video.Thumbnails.MINI_KIND); icon.setImageBitmap(videoIcon); } else if (type.equals("image/*")) { Bitmap bitmap = BitmapFactory.decodeFile(paths[position]); Bitmap imgIcon = ThumbnailUtils.extractThumbnail(bitmap, 150, 120); icon.setImageBitmap(imgIcon); } name.setText(names[position]); return convertView; } } }
缩略图加载这一块速度特别慢,希望会异步加载缩略图的同学能功能交流一下
完整代码下载
posted @ 2012-05-23 08:31 oldfeel 阅读(191) 评论(0) 编辑
先建立录像窗口 map_video.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <SurfaceView android:id="@+id/arc_hf_video_view" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <TextView android:id="@+id/arc_hf_video_timer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="40dp" android:textColor="#ffff0000" android:textSize="35dp" android:textStyle="bold" > </TextView> <LinearLayout android:id="@+id/arc_hf_video_btn" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentRight="true" android:gravity="center" android:orientation="vertical" > <Button android:id="@+id/arc_hf_video_start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/arc_hf_video_start" /> <Button android:id="@+id/arc_hf_video_return" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/arc_hf_video_return" /> </LinearLayout> </RelativeLayout>
主类 ArcHFVideo.java
public class ArcHFVideo extends Activity implements SurfaceHolder.Callback { private Button mVideoStartBtn, mVideoReturnBtn; private SurfaceView mSurfaceview; private MediaRecorder mMediaRecorder; private SurfaceHolder mSurfaceHolder; // private File mRecVedioPath; private File mRecAudioFile; private TextView timer; private int hour = 0; private int minute = 0; private int second = 0; private boolean bool; private int parentId; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setFormat(PixelFormat.TRANSLUCENT); setContentView(R.layout.map_video); parentId = getIntent().getIntExtra("parentId", 0); timer = (TextView) findViewById(R.id.arc_hf_video_timer); mVideoStartBtn = (Button) findViewById(R.id.arc_hf_video_start); mVideoReturnBtn = (Button) findViewById(R.id.arc_hf_video_return); mSurfaceview = (SurfaceView) this.findViewById(R.id.arc_hf_video_view); // 设置计时器不可见 timer.setVisibility(View.GONE); // 设置缓存路径 mRecVedioPath = new File(Environment.getExternalStorageDirectory() .getAbsolutePath() + "/hfdatabase/temp/"); if (!mRecVedioPath.exists()) { mRecVedioPath.mkdirs(); } // 绑定预览视图 SurfaceHolder holder = mSurfaceview.getHolder(); holder.addCallback(ArcHFVideo.this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); mVideoStartBtn.setOnClickListener(new Button.OnClickListener() { private boolean isRecording = true; @Override public void onClick(View v) { Drawable iconStart = getResources().getDrawable( R.drawable.arc_hf_video_start); Drawable iconStop = getResources().getDrawable( R.drawable.arc_hf_video_stop); if (isRecording) { mVideoStartBtn.setBackgroundDrawable(iconStop); bool = true; if (mMediaRecorder == null) mMediaRecorder = new MediaRecorder(); else mMediaRecorder.reset(); mMediaRecorder.setPreviewDisplay(mSurfaceHolder .getSurface()); mMediaRecorder .setVideoSource(MediaRecorder.VideoSource.CAMERA); mMediaRecorder .setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder .setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mMediaRecorder .setVideoEncoder(MediaRecorder.VideoEncoder.H264); mMediaRecorder .setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); mMediaRecorder.setVideoSize(176, 144); mMediaRecorder.setVideoFrameRate(15); try { mRecAudioFile = File.createTempFile("Vedio", ".3gp", mRecVedioPath); } catch (IOException e1) { e1.printStackTrace(); } mMediaRecorder.setOutputFile(mRecAudioFile .getAbsolutePath()); try { mMediaRecorder.prepare(); timer.setVisibility(View.VISIBLE); handler.postDelayed(task, 1000); mMediaRecorder.start(); } catch (Exception e) { e.printStackTrace(); } isRecording = !isRecording; } else { mVideoStartBtn.setBackgroundDrawable(iconStart); if (mMediaRecorder != null) { mMediaRecorder.stop(); bool = false; timer.setText(format(hour) + ":" + format(minute) + ":" + format(second)); mMediaRecorder.release(); mMediaRecorder = null; audioRename(); } isRecording = !isRecording; } } }); mVideoReturnBtn.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { if (mMediaRecorder != null) { mMediaRecorder.stop(); mMediaRecorder.release(); mMediaRecorder = null; } audioRename(); finish(); } }); } @Override public void surfaceCreated(SurfaceHolder holder) { mSurfaceHolder = holder; } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { mSurfaceHolder = holder; } @Override public void surfaceDestroyed(SurfaceHolder holder) { mSurfaceview = null; mSurfaceHolder = null; mMediaRecorder = null; } /* * 生成Audio文件名字 */ protected void audioRename() { String path = Environment.getExternalStorageDirectory() .getAbsolutePath() + "/hfdatabase/video/" + String.valueOf(parentId) + "/"; String fileName = new SimpleDateFormat("yyyyMMddHHmmss") .format(new Date()) + ".3gp"; File out = new File(path); if (!out.exists()) { out.mkdirs(); } out = new File(path, fileName); mRecAudioFile.renameTo(out); } /* * 定时器设置,实现计时 */ private Handler handler = new Handler(); private Runnable task = new Runnable() { public void run() { if (bool) { handler.postDelayed(this, 1000); second++; if (second < 60) { timer.setText(format(second)); } else if (second < 3600) { minute = second / 60; second = second % 60; timer.setText(format(minute) + ":" + format(second)); } else { hour = second / 3600; minute = (second % 3600) / 60; second = (second % 3600) % 60; timer.setText(format(hour) + ":" + format(minute) + ":" + format(second)); } } } }; /* * 格式化时间 */ public String format(int i) { String s = i + ""; if (s.length() == 1) { s = "0" + s; } return s; } }
打开指定路径的video文件
File f = new File(filePath); Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(f), "video/*"); startActivity(intent);
posted @ 2012-05-15 12:01 oldfeel 阅读(106) 评论(0) 编辑
摘要: 打开终端,输入:killall ibus-daemon(结束进程)ibus-daemon -d(重启ibus)阅读全文
posted @ 2012-05-14 22:48 oldfeel 阅读(7) 评论(0) 编辑
摘要: public class Test extends Activity implements OnClickListener { private EditText etName; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); etName = (EditText) findViewById(R.id.etName); ...阅读全文
posted @ 2012-05-11 12:44 oldfeel 阅读(130) 评论(0) 编辑
摘要: public class CreateFile extends Activity { private BufferedReader reader; private TextView tvFileReader; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.lay...阅读全文
posted @ 2012-05-10 08:10 oldfeel 阅读(183) 评论(0) 编辑
摘要: 如果是Activity的话在 Manifest.xml 相应的 Activity 里添加android:windowSoftInputMode="adjustPan|stateHidden"如果是其他View的话添加以下代码InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); // view是需要控制的view对象阅读全文
posted @ 2012-05-08 17:18 oldfeel 阅读(179) 评论(0) 编辑
