Thinking in XiaoQiang
世人皆有悲哀,只有你不明白
posts - 56,comments - 150,trackbacks - 0
学习android的练习小软件.

 

    制作文件管理器的初衷是发现G1上并没有随系统附带文件浏览软件, 考虑到电子书,媒体播放器或其它一些软件会使用到文件浏览,选择文件或文件夹, 所以先做了这个文件管理工具并封装一些参数供第三方程序调用

    应用很简单, 只是把手机和SD卡中的文件列出来, 支持图片和mp3的简单预览. 未来会有更多的功能扩充进来. 欢迎大家试用并提出意见.

--------------------------------------------------------4月更新0.3版 --------------------------------------------------------------------

自从上次更新后工作太忙,半年没玩儿ANDROID了, 最近刚刚闲下来, 继续完善文件管理器

顺便封装了一些其它的widget, 整理后再发上来

 

看着网上铺天盖地的各种android应用, 再看看我这个小破软件, 实在有点拿不出手, 但既然做了就得不断完善下去

目标是做一个封装widget的集合, 方便开发者使用

 

1, 使用线程和handler message机制读取文件列表, 提升软件性能

2, 解决文件列表多次滚动后速度下降的问题

3, 打开文件使用手机关联的应用

4, 增加文件缩略图显示

--------------------------------------------------------10月27日更新0.2版 --------------------------------------------------------------------

1.  0.2版主要增加了一些使用者的功能, 增加了收藏夹功能, 方便用户快速的浏览到经常访问的文件或文件夹

2.  修改了一些for developer的bug

 

 

--------------------------------------------------------  0.1版 --------------------------------------------------------------------

 

   

 

 

 

 

-------------------------------------------------------------------- for developer --------------------------------------------------------------------

G1上并没有随系统附带文件浏览软件, 考虑到电子书,媒体播放器或其它一些软件会使用到文件浏览,选择文件或文件夹, 所以先做了这个文件管理工具并封装一些参数供第三方程序调用,可以做为插件形式使用
把文件管理器封装起来并使用intent机制设置浏览参数和调用
目前暂不支持多文件选择, 将在下一版中发布
调用程序示例

1           Button button2  =  (Button) findViewById(R.id.but2);
2           button2.setOnClickListener(testFileManager);

 

 1  private  OnClickListener testFileManager  =   new  OnClickListener() {
 2           public   void  onClick(View v) {
 3              Intent intent  =   new  Intent( " net.uiiang.android.alkaid.FILEMANAGER " );
 4              
 5               // 参数root_directory, 设置浏览的根目录, 例如设置 /sdcard则只允许程序浏览sd卡中的内容, 当程序回退上层文件夹到/sdcard后不再向上回退
 6               // 参数类型为字符串, 默认为"/"(根目录)
 7              intent.putExtra( " root_directory " " / " );
 8              
 9               // 参数exclude_directory, 设置不显示的目录, 例如设 置"/data", "/dev", 则"/data", "/dev"这两个目录不会显示给用户
10               // 参数类型为字符串数组, 默认不排除任何文件夹
11              intent.putExtra( " exclude_directory " ,
12                       new  String[] {  " /data " " /dev "  });
13  
14               // 参数thrid_party_call, 当第三方程序调用时, 必须设置 此参数为true, 否则下面几个参数不起作用
15               // 参数类型为boolean, 默认为false, 会显示以下参数可设置的 所有菜单(除 选择菜单)
16              intent.putExtra( " thrid_party_call " true
);
17              
18               //  参数directory_show_type, 目录浏览方式
19               //  参数类型为 int, 默认为0
20               //  0 : 显示文件和文件夹(默认)
21               //  1 : 只显示文件
22               //  3 : 只显示文件夹 
23              intent.putExtra( " directory_show_type " 0 );
24              
25               // 参数use_menu_items, 设置显示的预置菜单
26               // 参数类型为:int数组
27               // 菜单列表:
28               //  1 : 上下文菜单-打开  (文件夹)
29               //  2 : 上下文菜单-删除
30               //  3 : 上下文菜单-详细信息
31               //  4 : 上下文菜单-复制
32               //  5 : option菜单-粘贴
33               //  6 : option菜单-新建文件夹
34               //  99: 上下文菜单-选择 , 若需要文件管理器返回一个选中的文件路 径, 则必须设置此菜单
35               //  当用户点击此菜单后, 文件管理器退出并返回给调用程序一个字符串数 组, 数组中包含文件路径信息
36              intent.putExtra( " use_menu_items " new   int [] {  99  });
37              
38               //  参数show_info_in_list, 是否在浏览文件中显示简单的 信息, 如文件夹中包含多少子文件夹和文件
39               //  默认为true
40              intent.putExtra( " show_info_in_list " false );
41              
42               //  参数show_file_extension, 是否显示文件后缀名
43               //  默认为 true
44              intent.putExtra( " show_file_extension " false );
45              
46               //  参数use_simple_view, 是否使用简单文件预览
47               //  用户单击文件后可以简单的预览文件内容, 目前支持图片和音乐文件
48               //  默认为 true
49              intent.putExtra( " use_simple_view " false );
50              
51               //  参数animation_show_list, 是否使用动态效果显示文 件列表, 目前只支持向下卷帘式的效果
52               //  默认为true
53              intent.putExtra( " animation_show_list " true );
54              
55               // 参数mutiple_select, 是否支持多选, 为true可以一次 性选择多个文件或目录
56               // 默认为false
57              intent.putExtra( " mutiple_select " , false );
58  
59              startActivityForResult(intent, SELECT_FILE);
60          }
61      };



通过startActivityForResult调用文件管理器, 并使用上下文菜单选择文件或文件夹

 

 

点击"选择"后, 返回到调用程序

 1      @Override
 2       protected   void  onActivityResult( int  requestCode,  int  resultCode, Intent data) {
 3           super .onActivityResult(requestCode, resultCode, data);
 4           if  (requestCode  ==  SELECT_FILE) {
 5               if  (resultCode  ==  RESULT_OK) {
 6                   //  参数名为selected_uri, 得到字符串数组中包含文件路径
 7                  String[] selectArr  =  data.getExtras().getStringArray(
 8                           " selected_uri " );
 9                   if  (selectArr  !=   null ) {
10                      String selectFile  =   "" ;
11                       for  (String string : selectArr) {
12                          System.out.println( " you select  =  "
13                                   +  data.getExtras().getStringArray(
14                                           " selected_uri " ));
15                      }
16                  }
17  
18              }
19          }
20      }

 

posted on 2010-05-05 17:10 小强 阅读(316) 评论(0)  编辑  收藏 所属分类: google-android

只有注册用户登录后才能发表评论。


网站导航: