Thinking in XiaoQiang
世人皆有悲哀,只有你不明白
posts - 56,comments - 150,trackbacks - 0
android SDK中提供了TabHost使用起来很方便, 但是当tab比较多的时候,就会挤在一起,而不能横向的滚动比较麻烦.

      于是我尝试的制作了一个简单的使用Gallery来代替TabHost的例子, 确实够简单的,自娱自乐.....仅供参考

 

     

 

      使用BroadcastReceiver来切换不同的Tab

 

    public class ChangeTabBroadcastReceiver extends BroadcastReceiver {
        @Override
        
public void onReceive(Context context, Intent intent) {
            
int index = intent.getExtras().getInt(CURRENT_TAB_INDEX);
            Log.i(TAG, 
"onReceive index = " + index);
            
// setCurrentTab(index);
            topBar.setSelection(index);
            startGroupActivity(titleList.get(index).toString(),
                    (Intent) intentList.get(index));
        }
    }

 

     没有详细研究SDK中的TabHost实现机制, 使用起来还是有些不方便的地方


public class GalleryTabActivityDemo extends GalleryTabactivity {
    @Override
    
public void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        setDelegate(
new SliderBarActivityDelegateImpl());
        
for (int i = 0; i < 14; i++) {
            Intent intent;
            
if (i % 2 == 0)
                intent 
= new Intent(this, DemoActivity1.class);
            
else
                intent 
= new Intent(this, DemoActivity2.class);

            
this.addTab("title" + i, android.R.drawable.star_on, intent);

        }
//必须在addTab后调用commit, 有点麻烦, 将来会找更好的办法
        super.setup();
    }

//可自定义切换tab时触发的操作
    private class SliderBarActivityDelegateImpl extends
            SliderBarActivityDelegate {
        
protected void onTabChanged(int tabIndex) {
            Log.d(
"onTabChanged""" + tabIndex);
        }
    }
}

最近工作比较忙,没太多时间学习android,将来会慢慢改善, 先凑合用, 抛块砖先, 各位有玉的使劲砸, 金条也行

 下载

posted @ 2010-05-13 15:46 小强 阅读(2124) | 评论 (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 @ 2010-05-05 17:10 小强 阅读(316) | 评论 (0)编辑 收藏
     摘要: 1. 0.2版主要增加了一些使用者的功能, 增加了收藏夹功能, 方便用户快速的浏览到经常访问的文件或文件夹

2. 修改了一些for developer的bug  阅读全文
posted @ 2009-10-27 16:05 小强 阅读(1618) | 评论 (2)编辑 收藏
     摘要: 为文件将来做电子书或媒体播放器等程序时浏览文件
把文件管理器封装起来并使用intent机制设置浏览参数和调用  阅读全文
posted @ 2009-10-17 20:21 小强 阅读(2644) | 评论 (2)编辑 收藏
     摘要: 练习作品 一个简单的 android 文件管理器, 支持第三方程序调用  阅读全文
posted @ 2009-10-17 19:50 小强 阅读(1912) | 评论 (1)编辑 收藏
     摘要: 为了体现出android强大的网络功能 写了一个小爬虫程序, 通过网络直接从网站上下载电子书  阅读全文
posted @ 2008-06-30 12:00 小强 阅读(1360) | 评论 (0)编辑 收藏
     摘要: 晚上等着看欧洲杯,闲来无赖接着研究android , 更新了一下uReader  阅读全文
posted @ 2008-06-18 12:46 小强 阅读(1470) | 评论 (4)编辑 收藏