Back to project page ImageScanner.
The source code is released under:
Apache License
If you think the Android project ImageScanner 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.example.imagescanner; /*w w w .java 2s. com*/ import java.util.ArrayList; import android.app.Activity; import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.GridView; import android.widget.ImageView; import com.atermenji.android.iconicdroid.icon.EntypoIcon; import com.scanner.adapter.GalleryGridAdapter; import com.scanner.beans.GridImageBean; import com.scanner.utils.BitmapUtils; import com.scanner.utils.ConstantsUtils; import com.scanner.utils.ScannerUtils; import com.scanner.utils.UIHelper; public class GalleryGridActivity extends Activity implements OnClickListener { // PRIKDK private final static int REDIRECT_2_POST = 0; private final static int REDIREC_2_BACK = 1; private final static String TAG = "GalleryGridActivity"; private GridView gridview; private ArrayList<GridImageBean> gdData; private GalleryGridAdapter adapter; private String chosenPath; private View backArea; private ImageView backIcon; private View postArea; private ImageView postIcon; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setContentView(R.layout.activity_gallery_grid); initValue(); initUI(); } public void initUI() { // TODO Auto-generated method stub backArea = findViewById(R.id.galleryGridBack); backIcon = (ImageView) findViewById(R.id.galleryGridBack_icon); postArea = findViewById(R.id.galleryGridOK); postIcon = (ImageView) findViewById(R.id.galleryGridOK_icon); BitmapUtils.setIconFont(this, backIcon, EntypoIcon.CHEVRON_THIN_LEFT, R.color.theme_color); BitmapUtils.setIconFont(this, postIcon, EntypoIcon.PLAY, R.color.theme_color); postArea.setVisibility(View.GONE); gridview = (GridView) findViewById(R.id.gallery_photo_gridview); adapter = new GalleryGridAdapter(this, gridview, gdData, R.layout.item_gd__gallery_photo); gridview.setAdapter(adapter); postArea.setOnClickListener(this); backArea.setOnClickListener(this); if (gdData.isEmpty()) loadGdData(); } public void initValue() { // TODO Auto-generated method stub gdData = new ArrayList<GridImageBean>(); chosenPath = getIntent().getExtras().getString( ConstantsUtils.BUNDLE_FOLDER_PATH); } /** * load data of gridview * * @param folderPath */ public void loadGdData() { final Handler handler = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub if (msg.what == 1) { adapter.notifyDataSetChanged(); } } }; new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub ArrayList<String> tempList = ScannerUtils .getGalleryBitmapsIn_A_Folder(chosenPath); for (String bean : tempList) { gdData.add(new GridImageBean(bean, false)); } Message msg = new Message(); msg.what = 1; handler.sendMessage(msg); } }).start(); } public void redirectTo(int dest) { // TODO Auto-generated method stub switch (dest) { case REDIREC_2_BACK: setResult(RESULT_CANCELED); finish(); break; case REDIRECT_2_POST: String imgUrl = gdData.get(adapter.getChosenPosition()).getPath(); Intent intent = new Intent(); intent.putExtra(ConstantsUtils.BUNDLE_IMAGE_PATH_FROM_GRIDVIEW, imgUrl); setResult(RESULT_OK, intent); finish(); break; default: break; } } @Override public void onClick(View v) { // TODO Auto-generated method stub if (v.getId() == R.id.galleryGridBack) redirectTo(REDIREC_2_BACK); if (v.getId() == R.id.galleryGridOK) redirectTo(REDIRECT_2_POST); } public void showOk() { UIHelper.crossfade(null, postArea); } }