ZNDS智能电视网 推荐当贝市场

TV应用下载 / 资源分享区

软件下载 | 游戏 | 讨论 | 电视计算器

综合交流 / 评测 / 活动区

交流区 | 测硬件 | 网站活动 | Z币中心

新手入门 / 进阶 / 社区互助

新手 | 你问我答 | 免费刷机救砖 | ROM固件

查看: 16098|回复: 0
上一主题 下一主题
[案例]

遍历3gp视频文件

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-28 16:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
0 本帖最后由 q421338868 于 2013-2-15 09:18 编辑       public class UpImages extends Activity{   
//适配器   
TextView tView ;     
ListView i ;     
Button qs;   
Button qx;   
CheckboxAdapter listItemAdapter;   
private ArrayList<File> list ;   
String  name;   
String[] a;   
private EditText describeText;   
private TextView resulView;     
private ProgressBar uploadbar;     
private UploadLogService Service;   
String username;   
String path;   
static String myJpgPath;   
List<String> list2;   
private Handler handler = new Handler(){     
  public void handleMessage(Message msg) {     
   int length = msg.getData().getInt("size");     
         uploadbar.setProgress(length);   
   float num = (float)uploadbar.getProgress()/(float)uploadbar.getMax();     
   int result = (int)(num * 100);     
   resulView.setText(result+ "%");     
   if(uploadbar.getProgress()==uploadbar.getMax()){     
    Toast.makeText(UpImages.this, R.string.success, 1).show();   
    Intent intent = new Intent();   
    intent.seTCLass(UpImages.this, Button1Activity.class);   
    startActivity(intent);   
    UpImages.this.finish();   
   }     
  }     
};     
public void onCreate(Bundle savedInstanceState) {   
  super.onCreate(savedInstanceState);   
  setContentView(R.layout.upimages);   
  Service = new UploadLogService(this);     
  describeText = (EditText)this.findViewById(R.id.describe);   
  uploadbar = (ProgressBar) this.findViewById(R.id.uploadbar);     
  resulView = (TextView)this.findViewById(R.id.result);   
  //按钮及事件响应   
  Button getValue=(Button)findViewById(R.id.get_value);   
  getValue.setOnClickListener(listener);   
  qs = (Button)findViewById(R.id.qs);   
  qx = (Button)findViewById(R.id.qx);   
  qs.setOnClickListener(new OnClickListener() {   
      
   @Override   
   public void onClick(View v) {   
    Intent intent = new Intent();   
    intent.setClass(UpImages.this, Button1Activity.class);   
    startActivity(intent);   
    UpImages.this.finish();   
   }   
  });   
  qx.setOnClickListener(new OnClickListener() {   
      
   @Override   
   public void onClick(View v) {   
       HashMap<Integer, Boolean> state = listItemAdapter.state;   
                      for (int j = 0; j < listItemAdapter.getCount(); j++) {   
                              state.put(j, true);   
                      }   
                      listItemAdapter.notifyDataSetChanged();   
   }   
  });   
  tView = (TextView)findViewById(R.id.textview1);      
  //btn = (Button) findViewById(R.id.go);      
  tView = new TextView(this);     
  tView.setText("get all files in your sd card");     
  //init data      
  i = (ListView) findViewById(R.id.list);     
  list = new ArrayList<File>();      
  getAllFiles(new File("/sdcard/myImage"));     
  SimpleAdapter ladapter = new SimpleAdapter(this,getMapData(list),R.layout.itemss, new String[]{"ItemText","ItemTitle"},new int[]{R.id.friend_username});     
  i.setAdapter(ladapter);     
  TextView empty = new TextView(this);     
  empty.setText("empty!");     
  i.setEmptyView(empty);     
  ListView list = (ListView) findViewById(R.id.list);   
  //存储数据的数组列表   
  ArrayList<HashMap<String, Object>> listData=new ArrayList<HashMap<String,Object>>();   
  for(int i=0;i<a.length;i++){   
   HashMap<String, Object> map=new HashMap<String, Object>();   
   map.put("friend_image", R.drawable.s18_tp);   
   map.put("friend_username", a);   
   //Log.d("gxb", ""+"55555555555555555" + a);   
   map.put("selected", false);   
   //添加数据   
   listData.add(map);   
  }   
  //适配器   
  listItemAdapter = new CheckboxAdapter(this, listData);   
  list.setAdapter(listItemAdapter);   
  i.setOnItemClickListener(new OnItemClickListener() {   
   @Override   
   public void onItemClick(AdapterView<?> arg0, View arg1, int position,   
     long arg3) {   
    System.out.println(arg1+"--------------");   
    //这里怎么获得Item的值啊  就是名称   
    myJpgPath = "/sdcard/myImage/"+list2.get(position);   
    Intent intent = new Intent();   
    intent.setClass(UpImages.this, JPG1Activity.class);   
    startActivity(intent);   
    //UpImages.this.finish();   
   }   
  });   
}   
//事件响应   
OnClickListener listener=new OnClickListener() {   
  @Override   
  public void onClick(View v) {   
   HashMap<Integer, Boolean> state =listItemAdapter.state;   
   String options="选择的项是:";   
   for(int j=0;j<listItemAdapter.getCount();j++){   
    //System.out.println("state.get("+j+")=="+state.get(j));   
    if(state.get(j)!=null){   
     @SuppressWarnings("unchecked")   
     HashMap<String, Object> map=(HashMap<String, Object>) listItemAdapter.getItem(j);   
     username=map.get("friend_username").toString();   
     options+="
"+username;   
     //显示选择内容   
     //Toast.makeText(getApplicationContext(), options, Toast.LENGTH_LONG).show();   
     //Log.d("gxb", ""+"111111111111111filename"+username);   
    //Log.d("gxb", ""+describe);   
    //System.out.print(describe);   
    if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){     
     File file = new File("/sdcard/myImage/"+username);   
     //File file = new File(Environment.getExternalStorageDirectory(),username);   
     if(file.exists()){     
      uploadbar.setMax((int)file.length());   
      uploadFile(file);   
      //Toast.makeText(UpImages.this, R.string.success, 1).show();   
     }else{     
      Toast.makeText(UpImages.this, R.string.filenotexsit, 1).show();     
     }     
    }else{     
     Toast.makeText(UpImages.this, R.string.sdcarderror, 1).show();     
    }   
   }   
   }   
   }   
  };   
  private ArrayList<Map<String, Object>> getMapData(ArrayList<File> list){     
   ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>();     
   int i = 0 ;     
      
   list2 = new ArrayList<String>();   
   for(i=0;i<list.size();i++){     
    path  = list.get(i).toString();     
    String name = path.substring(path.lastIndexOf("/")+1,path.length());   
    if (name.endsWith(".3gp")) {   
          list2.add(name);   
    }     
   }   
   //System.out.println(list2.size()+"=============================");   
   a = new String[list2.size()];   
   for (int j = 0; j < list2.size(); j++) {   
    a[j]=list2.get(j);   
   }   
   return data;     
  }   
  private void getAllFiles(File root){     
   File files[] = root.listFiles();     
   if(files != null)     
    for(File f:files){     
     if(f.isDirectory()){     
      getAllFiles(f);     
     }     
     else{     
      this.list.add(f);     
     }     
    }     
  }   
}   
   
   
   
<?xml version="1.0" encoding="utf-8"?>   
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   
    android:orientation="vertical"   
    android:layout_width="fill_parent"   
    android:layout_height="fill_parent"   
    android:background="@drawable/bg"   
    >   
    <LinearLayout   
    android:layout_width="fill_parent"   
android:orientation="horizontal"   
android:layout_height="0dp"   
>   
    <TextView   
android:id="@+id/textview1"      
    android:layout_width="fill_parent"   
    android:layout_height="wrap_content"   
    android:text="@string/hello"></TextView>   
  <TextView        
     android:layout_width="fill_parent"      
     android:layout_height="wrap_content"      
     android:text=""     
     android:id="@string/describe"     
    />      
<TextView      
      android:layout_width="fill_parent"      
      android:layout_height="wrap_content"      
      android:gravity="center"     
      android:id="@+id/result"     
      />   
      </LinearLayout>   
<LinearLayout   
    android:layout_width="fill_parent"   
android:orientation="horizontal"   
android:layout_height="fill_parent"   
android:layout_weight="0.3"   
>   
<ListView   
android:id="@+id/list"   
android:layout_width="fill_parent"   
android:background="@drawable/bg"   
android:layout_height="fill_parent"/>   
    </LinearLayout>   
      
<LinearLayout   
    android:layout_width="fill_parent"   
android:orientation="vertical"   
android:layout_height="fill_parent"   
android:layout_weight="0.9"   
    >   
<EditText   
android:id="@+id/describe"   
android:hint="请在这里填写文件描述"   
android:background="@drawable/shape1"   
android:layout_width="fill_parent"   
android:layout_height="wrap_content"   
android:layout_margin="5dp"></EditText>   
<ProgressBar   
android:layout_height="20px"   
android:id="@+id/uploadbar"   
style="?android:attr/progressBarStyleHorizontal"   
android:layout_width="fill_parent"   
></ProgressBar>   
</LinearLayout>   
   
<LinearLayout   
    android:layout_width="fill_parent"   
android:orientation="horizontal"   
android:layout_height="wrap_content"   
>   
<Button   
android:layout_width="fill_parent"   
android:layout_height="45dp"   
android:id="@+id/get_value"   
android:background="@drawable/s18_sc"   
android:layout_weight="0.5"   
android:layout_margin="20dp"   
></Button>   
<Button   
android:id="@+id/qx"   
android:background="@drawable/s_qx"   
android:layout_height="45dp"   
android:layout_width="fill_parent"   
android:layout_weight="0.5"   
android:layout_margin="20dp"></Button>   
<Button   
android:id="@+id/qs"   
android:background="@drawable/s2_fh"   
android:layout_height="45dp"   
android:layout_width="fill_parent"   
android:layout_weight="0.5"   
android:layout_margin="20dp"   
></Button>   
</LinearLayout>
   
</LinearLayout>   
   
   
</i

上一篇:如何利用AlarmManager机制在一定时间后启动某Activity
下一篇:第05讲:用户界面 View(一).docx
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

Archiver|新帖|标签|软件|Sitemap|ZNDS智能电视网 ( 苏ICP备2023012627号 )

网络信息服务信用承诺书 | 增值电信业务经营许可证:苏B2-20221768 丨 苏公网安备 32011402011373号

GMT+8, 2025-7-29 13:05 , Processed in 0.064920 second(s), 17 queries , Redis On.

Powered by Discuz!

监督举报:report#znds.com (请将#替换为@)

© 2007-2025 ZNDS.Com

快速回复 返回顶部 返回列表