Back to project page SimpleReader.
The source code is released under:
Apache License
If you think the Android project SimpleReader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.dreamteam.app.ui; //from w ww .j a v a 2 s.c o m import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.ContentResolver; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.provider.MediaStore; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.GridView; import android.widget.Toast; import com.dreamteam.app.utils.FileUtils; import com.dreamteam.app.wallpaper.GroupGridAdapter; import com.dreamteam.app.wallpaper.ImageBean; import com.dreateam.app.ui.R; @SuppressLint("HandlerLeak") public class LocalImageBrowseActivity extends BaseTitledActivity { private static final int SUCCESS = 0; private HashMap<String, List<String>> groups; private List<ImageBean> groupImageList; private GridView gridView; private ProgressDialog pd; private Handler handler = new Handler() { public void handleMessage(android.os.Message msg) { switch(msg.what) { case SUCCESS: pd.dismiss(); gridView.setAdapter(new GroupGridAdapter(LocalImageBrowseActivity.this, groupImageList, gridView)); break; } }; }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initParam(); initView(); initData(); } private void initParam() { groups = new HashMap<String, List<String>>(); groupImageList = new ArrayList<ImageBean>(); } private void initView() { setView(R.layout.activity_local_image_browse); gridView = (GridView) findViewById(R.id.local_image_browse_grid); setTitleText(R.string.wallpaper_local_img_browse); setLeftButtonListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); hideRightButton(); gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { List<String> childList = groups.get(groupImageList.get(position).getFolderName()); Intent mIntent = new Intent(LocalImageBrowseActivity.this, ImagesBrowseActivity.class); mIntent.putStringArrayListExtra("data", (ArrayList<String>)childList); startActivity(mIntent); } }); } private void initData() { if (!FileUtils.hasSDCard()) { Toast.makeText(this, "cannot found sd card", Toast.LENGTH_SHORT) .show(); return; } pd = ProgressDialog.show(this, "info", "loing local images, please wait..."); new Thread(new Runnable() { @Override public void run() { Uri imageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; ContentResolver resolver = getContentResolver(); Cursor cursor = resolver.query(imageUri, null, MediaStore.Images.Media.MIME_TYPE + "=? or " + MediaStore.Images.Media.MIME_TYPE + "=?", new String[] { "image/jpeg", "image/png" }, MediaStore.Images.Media.DATE_MODIFIED); while(cursor.moveToNext()) { String path = cursor.getString(cursor .getColumnIndex(MediaStore.Images.Media.DATA)); String parentName = new File(path).getParentFile().getName(); if (!groups.containsKey(parentName)) { List<String> chileList = new ArrayList<String>(); chileList.add(path); groups.put(parentName, chileList); } else { groups.get(parentName).add(path); } } cursor.close(); groupImageList = subGroupOfImage(groups); handler.sendEmptyMessage(SUCCESS); } }).start(); } /** * ????????GridView??????????????????????????????HashMap? * ?????????HashMap?????????List * * @param mGruopMap * @return */ private List<ImageBean> subGroupOfImage(HashMap<String, List<String>> mGruopMap){ if(mGruopMap.size() == 0){ return null; } List<ImageBean> list = new ArrayList<ImageBean>(); Iterator<Map.Entry<String, List<String>>> it = mGruopMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, List<String>> entry = it.next(); ImageBean mImageBean = new ImageBean(); String key = entry.getKey(); List<String> value = entry.getValue(); mImageBean.setFolderName(key); mImageBean.setImageCounts(value.size()); mImageBean.setTopImagePath(value.get(0));//???????????? list.add(mImageBean); } return list; } }