Skip to content

Commit

Permalink
add new version v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wangqiong committed Apr 1, 2015
1 parent a33f076 commit 7fb85a0
Show file tree
Hide file tree
Showing 23 changed files with 958 additions and 113 deletions.
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@



![Image text](https://github.com/wqandroid/wqgallery/blob/master/app/screenshort/wqgallert.gif)
![Image text](https://github.com/wqandroid/wqgallery/blob/master/app/screenshort/wqgallert1.gif)

![Image text](https://github.com/wqandroid/wqgallery/blob/master/app/screenshort/Screenshot_2015-03-31-18-35-29.png)

Expand All @@ -14,12 +14,19 @@
#####2.支持多选模式
####下面是调用选择器

Intent intent=new Intent(MainActivity.this, MediaChoseActivity.class);
Intent intent=new Intent(MainActivity.this, MediaChoseActivity.class);
//chose_mode选择模式 0单选 1多选
intent.putExtra("chose_mode",0);
//chose_mode选择模式 0单选 1多选
intent.putExtra("max_chose_count",6);
//最多支持选择多少张
startActivityForResult(intent, REQUEST_IMAGE);
intent.putExtra("max_chose_count",6);
//是否剪裁图片(只有单选模式才有剪裁)
intent.putExtra("crop",true);
//输出剪裁图片的宽度
intent.putExtra("crop_image_w",720);
//输出剪裁图片的高度
intent.putExtra("crop_image_h",720);
startActivityForResult(intent, REQUEST_IMAGE);

####在onActivityResult中获取选择的图片路径列表

ArrayList<String>paths=data.getStringArrayListExtra("data");
Expand All @@ -29,24 +36,24 @@



###当前版本1.0.0
###当前版本1.0.1
下个版本能够在gradle引入photogallery库

1.0.1 新增单选截图模式

##Developed By
#####[email protected]
##License

Copyright 2013 Andreas Stuetz
Copyright 2013 Andreas Stuetz

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Binary file removed app/screenshort/wqgallert.gif
Binary file not shown.
Binary file added app/screenshort/wqgallert1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package="com.eq.gallery" >

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<application
android:allowBackup="true"
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/eq/gallery/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ public void onClick(View v) {
startActivityForResult(intent, REQUEST_IMAGE);
}
});

findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this, MediaChoseActivity.class);
intent.putExtra("crop",true);
intent.putExtra("crop_image_w",720);
intent.putExtra("crop_image_h",720);
startActivityForResult(intent, REQUEST_IMAGE);
}
});
}
public void onclick(){
Intent intent=new Intent(this, MediaChoseActivity.class);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="多选模式" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="单选剪裁" />
</LinearLayout>


Expand Down
1 change: 0 additions & 1 deletion photogallery/photogallery.iml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="universal-image-loader-1.9.3" level="project" />
</component>
</module>

9 changes: 8 additions & 1 deletion photogallery/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wq.photo" >
package="com.wq.photo"
android:versionCode="2"
android:versionName="1.0.1"
>

<application
android:allowBackup="true"
Expand All @@ -9,6 +12,10 @@
android:name=".MediaChoseActivity"
android:label="@string/title_activity_media_chose" >
</activity>
<activity
android:name=".CropImageActivity"
android:label="@string/title_activity_crop_image" >
</activity>
</application>

</manifest>
99 changes: 99 additions & 0 deletions photogallery/src/main/java/com/wq/photo/CropImageActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.wq.photo;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.wq.photo.widget.CropImageView;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;


public class CropImageActivity extends ActionBarActivity {
private String filePath;
private String outFilePath;

/**上传图片大小*/
public int crop_image_w=0;
public int crop_image_h=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crop_image);
getSupportActionBar().setTitle("裁剪图片");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
try {
crop_image_w=getIntent().getIntExtra("crop_image_w",720);
crop_image_h=getIntent().getIntExtra("crop_image_h",720);
Uri uri = getIntent().getData();
if("file".equals(uri.getScheme())) {
filePath = uri.getPath();
outFilePath = getIntent().getStringExtra(MediaStore.EXTRA_OUTPUT);
cropImage();
}
} catch (Exception e) {
finish();
}
}

private void cropImage()
{
final CropImageView mCropImage=(CropImageView)findViewById(R.id.cropImg);
mCropImage.setDrawable(Drawable.createFromPath(filePath), crop_image_w, crop_image_h);
findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable(){
@Override
public void run() {
File f= save2Storage(mCropImage.getCropImage(),getCropFile().getAbsolutePath());
Intent intent=new Intent();
intent.putExtra("crop_path",f.getAbsolutePath());
setResult(RESULT_OK, intent);
finish();
}
}).start();
}
});
}

public static File save2Storage(Bitmap bitmap, String path) {
try {
File filename = new File(path);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
try {
FileOutputStream fos = new FileOutputStream(path);
fos.write(baos.toByteArray());
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
return filename;
} catch (Exception e) {}
return null;
}
public File getCropFile() {
File f= new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "crop.jpg");
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
return f;
}

}
14 changes: 12 additions & 2 deletions photogallery/src/main/java/com/wq/photo/FloderAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public FloderAdapter(List<ImageFloder>floders,Context context){
this.floders=floders;
inflater=LayoutInflater.from(context);
}

int ckpos=0;
public void setCheck(int pos){
ckpos=pos;
notifyDataSetChanged();
}

@Override
public int getCount() {
Expand Down Expand Up @@ -60,14 +64,20 @@ public View getView(int position, View convertView, ViewGroup parent) {
displayImage(floder.getFirstImagePath(),holderFoler.iv_floderimage);
holderFoler.tv_flodername.setText(floder.getName());
holderFoler.tv_flodercount.setText(floder.getCount()+"");
if(position==ckpos){
holderFoler.is_checked.setVisibility(View.VISIBLE);
}else {
holderFoler.is_checked.setVisibility(View.INVISIBLE);
}
return convertView;
}

public static class ViewHolderFoler {

ImageView iv_floderimage;
ImageView iv_floderimage,is_checked;
TextView tv_flodername,tv_flodercount;
public ViewHolderFoler(View convertView){
is_checked= (ImageView) convertView.findViewById(R.id.is_checked);
iv_floderimage= (ImageView) convertView.findViewById(R.id.id_dir_item_image);
tv_flodercount= (TextView) convertView.findViewById(R.id.id_dir_item_count);
tv_flodername= (TextView) convertView.findViewById(R.id.id_dir_item_name);
Expand Down
71 changes: 61 additions & 10 deletions photogallery/src/main/java/com/wq/photo/ImageLoader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wq.photo;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
Expand Down Expand Up @@ -88,7 +89,7 @@ public static ImageLoader getInstance()
{
if (mInstance == null)
{
mInstance = new ImageLoader(1, Type.LIFO);
mInstance = new ImageLoader(3, Type.LIFO);
}
}
}
Expand Down Expand Up @@ -150,6 +151,63 @@ protected int sizeOf(String key, Bitmap value)

}

public void loadImage(final String path,final ImageView imageView,final int w,final int h){

// set tag
imageView.setTag(path);
// UI线程
if (mHandler == null)
{
mHandler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
ImgBeanHolder holder = (ImgBeanHolder) msg.obj;
ImageView imageView = holder.imageView;
Bitmap bm = holder.bitmap;
String path = holder.path;
if (imageView.getTag().toString().equals(path))
{
imageView.setImageBitmap(bm);
}
}
};
}

Bitmap bm = getBitmapFromLruCache(path);
if (bm != null)
{

imageView.setImageBitmap(bm);

} else
{
addTask(new Runnable()
{
@Override
public void run()
{
int reqWidth = w;
int reqHeight = h;
Bitmap bm = decodeSampledBitmapFromResource(path, reqWidth,
reqHeight);
addBitmapToLruCache(path, bm);
ImgBeanHolder holder = new ImgBeanHolder();
holder.imageView = imageView;
holder.bitmap=bm;
holder.path = path;
Message message = Message.obtain();
message.obj = holder;
// Log.e("TAG", "mHandler.sendMessage(message);");
mHandler.sendMessage(message);
mPoolSemaphore.release();
}
});
}

}

/**
* 加载图片
*
Expand Down Expand Up @@ -183,13 +241,6 @@ public void handleMessage(Message msg)
Bitmap bm = getBitmapFromLruCache(path);
if (bm != null)
{
// ImgBeanHolder holder = new ImgBeanHolder();
// holder.bitmap = bm;
// holder.imageView = imageView;
// holder.path = path;
// Message message = Message.obtain();
// message.obj = holder;
// mHandler.sendMessage(message);
imageView.setImageBitmap(bm);
} else
{
Expand Down Expand Up @@ -265,7 +316,7 @@ private synchronized Runnable getTask()
*
* @return
*/
public static ImageLoader getInstance(int threadCount, Type type)
public static ImageLoader getInstance(int threadCount,Type type)
{

if (mInstance == null)
Expand Down Expand Up @@ -402,7 +453,7 @@ private class ImgBeanHolder
String path;
}

private class ImageSize
public class ImageSize
{
int width;
int height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.widget.ImageView;
import android.widget.ListView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.wq.photo.mode.Images;

import java.lang.reflect.Array;
Expand Down
Loading

0 comments on commit 7fb85a0

Please sign in to comment.