爱上soso 发表于 2013-8-28 16:29

遍历3gp视频文件

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 ;   
Stringname;   
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;   
   for (int j = 0; j < list2.size(); j++) {   
    a=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
页: [1]
查看完整版本: 遍历3gp视频文件