Android Open Source - UniversalImagePick Pick Activity






From Project

Back to project page UniversalImagePick.

License

The source code is released under:

Apache License

If you think the Android project UniversalImagePick listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.luffyjet.universalimagepick.ui;
//from w w  w .  j av  a 2s  . c  o  m
import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.luffyjet.universalimagepick.R;
import com.luffyjet.universalimagepick.adapter.BucketAdapter;
import com.luffyjet.universalimagepick.adapter.PickGridAdapter;
import com.luffyjet.universalimagepick.model.ImageBucket;
import com.luffyjet.universalimagepick.model.Image;
import com.luffyjet.universalimagepick.model.ImagesHelper;
import com.luffyjet.universalimagepick.utils.LogUtil;

public class PickActivity extends BaseActivity
{
  private TextView folderListBtn, previewBtn;
  private GridView pickGridView;
  private PopupWindow popupWindow;
  private BucketAdapter bucketAdapter;
  private PickGridAdapter gridAdapter;
  private ArrayList<ImageBucket> mBucketList = new ArrayList<ImageBucket>();
  private ArrayList<Image> mTempList = new ArrayList<Image>();
  
  private ImagesHelper helper;
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_pick_layout);
    helper = ImagesHelper.getHelper(getApplicationContext());

    mReturnBtn = (TextView) findViewById(R.id.return_btn);
    mTitleTv = (TextView) findViewById(R.id.title);
    mSubmitBtn = (TextView) findViewById(R.id.submit_btn);
    pickGridView = (GridView) findViewById(R.id.pick_gridview);
    gridAdapter = new PickGridAdapter(mTempList, this);
    pickGridView.setAdapter(gridAdapter);
    
    folderListBtn = (TextView) findViewById(R.id.folder_list_btn);
    previewBtn = (TextView) findViewById(R.id.preview_btn);

    folderListBtn.setOnClickListener(new OnClickListener()
    {

      @Override
      public void onClick(View arg0)
      {
        showBucketList();
      }
    });
    
    getData();
  }

  @SuppressLint("HandlerLeak")
  @SuppressWarnings("unchecked")
  private Handler handler = new Handler(){
    
    @Override
    public void handleMessage(Message msg)
    {
      if (null!=msg.obj)
      {
        mBucketList = (ArrayList<ImageBucket>) msg.obj;
        mTempList.addAll(mBucketList.get(0).imageList);
        gridAdapter.notifyDataSetChanged();
      }
    }
  };
  
  private void getData()
  {
    new Thread(new Runnable()
    {
      @Override
      public void run()
      {
        Message msg = handler.obtainMessage();
        ArrayList<ImageBucket> bucketList = helper.getImagesBucketList(null, null, null, null, false);
        ImageBucket bucket = new ImageBucket();
        bucket.bucketName = "????";
        bucket.imageList = helper.getAllImages();
        bucketList.add(0, bucket);
        
        msg.obj = bucketList;
        handler.sendMessage(msg);
      }
    }).start();
  }

  private void showBucketList()
  {
    if (null != popupWindow)
    {
      popupWindow.showAtLocation(folderListBtn, Gravity.BOTTOM, 0, 0);
    } else
    {
      View view = getLayoutInflater().inflate(
          R.layout.select_bucket_list, null);
      ListView listView = (ListView) view.findViewById(R.id.bucket_list);
      bucketAdapter = new BucketAdapter(mBucketList, this);
      
      listView.setOnItemClickListener(new OnItemClickListener()
      {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id)
        {
          LogUtil.showLog("**************************************8");
          mTempList.clear();
          mTempList.addAll(mBucketList.get(position).imageList);
          gridAdapter.notifyDataSetChanged();
          popupWindow.dismiss();
        }
      });
      
      listView.setAdapter(bucketAdapter);
      
      popupWindow = new PopupWindow(view, LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT, true);
      popupWindow.setBackgroundDrawable(new BitmapDrawable());
      popupWindow.update();
      popupWindow.showAtLocation(folderListBtn, Gravity.BOTTOM, 0, 0);
    }
  }

}




Java Source Code List

com.luffyjet.universalimagepick.App.java
com.luffyjet.universalimagepick.Constants.java
com.luffyjet.universalimagepick.MainActivity.java
com.luffyjet.universalimagepick.Test.java
com.luffyjet.universalimagepick.adapter.BucketAdapter.java
com.luffyjet.universalimagepick.adapter.GalleryAdapter.java
com.luffyjet.universalimagepick.adapter.PickGridAdapter.java
com.luffyjet.universalimagepick.adapter.PreviewAdapter.java
com.luffyjet.universalimagepick.adapter.ResultAdapter.java
com.luffyjet.universalimagepick.model.ImageBucket.java
com.luffyjet.universalimagepick.model.Image.java
com.luffyjet.universalimagepick.model.ImagesHelper.java
com.luffyjet.universalimagepick.model.Thumbnail.java
com.luffyjet.universalimagepick.ui.BaseActivity.java
com.luffyjet.universalimagepick.ui.GalleryActivity.java
com.luffyjet.universalimagepick.ui.PickActivity.java
com.luffyjet.universalimagepick.utils.LogUtil.java
com.luffyjet.universalimagepick.widget.CropImageView.java
com.luffyjet.universalimagepick.widget.CustomGridView.java
com.luffyjet.universalimagepick.widget.MulitPointTouchListener.java
com.luffyjet.universalimagepick.widget.ViewfinderView.java