();
public static interface LifeCycleListener {
public void onActivityCreated(MonitoredActivity activity);
public void onActivityDestroyed(MonitoredActivity activity);
public void onActivityStarted(MonitoredActivity activity);
public void onActivityStopped(MonitoredActivity activity);
}
public static class LifeCycleAdapter implements LifeCycleListener {
public void onActivityCreated(MonitoredActivity activity) {
}
public void onActivityDestroyed(MonitoredActivity activity) {
}
public void onActivityStarted(MonitoredActivity activity) {
}
public void onActivityStopped(MonitoredActivity activity) {
}
}
public void addLifeCycleListener(LifeCycleListener listener) {
if (listeners.contains(listener)) return;
listeners.add(listener);
}
public void removeLifeCycleListener(LifeCycleListener listener) {
listeners.remove(listener);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
for (LifeCycleListener listener : listeners) {
listener.onActivityCreated(this);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
for (LifeCycleListener listener : listeners) {
listener.onActivityDestroyed(this);
}
}
@Override
protected void onStart() {
super.onStart();
for (LifeCycleListener listener : listeners) {
listener.onActivityStarted(this);
}
}
@Override
protected void onStop() {
super.onStop();
for (LifeCycleListener listener : listeners) {
listener.onActivityStopped(this);
}
}
}
================================================
FILE: library/src/main/java/com/liuguangqiang/ipicker/crop/RotateBitmap.java
================================================
/*
* Copyright 2016 Eric Liu
*
* 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
*
* 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.
*/
package com.liuguangqiang.ipicker.crop;
import android.graphics.Bitmap;
import android.graphics.Matrix;
/*
* Modified from original in AOSP.
*/
public class RotateBitmap {
private Bitmap bitmap;
private int rotation;
public RotateBitmap(Bitmap bitmap, int rotation) {
this.bitmap = bitmap;
this.rotation = rotation % 360;
}
public void setRotation(int rotation) {
this.rotation = rotation;
}
public int getRotation() {
return rotation;
}
public Bitmap getBitmap() {
return bitmap;
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
public Matrix getRotateMatrix() {
// By default this is an identity matrix
Matrix matrix = new Matrix();
if (bitmap != null && rotation != 0) {
// We want to do the rotation at origin, but since the bounding
// rectangle will be changed after rotation, so the delta values
// are based on old & new width/height respectively.
int cx = bitmap.getWidth() / 2;
int cy = bitmap.getHeight() / 2;
matrix.preTranslate(-cx, -cy);
matrix.postRotate(rotation);
matrix.postTranslate(getWidth() / 2, getHeight() / 2);
}
return matrix;
}
public boolean isOrientationChanged() {
return (rotation / 90) % 2 != 0;
}
public int getHeight() {
if (bitmap == null) return 0;
if (isOrientationChanged()) {
return bitmap.getWidth();
} else {
return bitmap.getHeight();
}
}
public int getWidth() {
if (bitmap == null) return 0;
if (isOrientationChanged()) {
return bitmap.getHeight();
} else {
return bitmap.getWidth();
}
}
public void recycle() {
if (bitmap != null) {
bitmap.recycle();
bitmap = null;
}
}
}
================================================
FILE: library/src/main/java/com/liuguangqiang/ipicker/entities/Photo.java
================================================
/*
* Copyright 2016 Eric Liu
*
* 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
*
* 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.
*/
package com.liuguangqiang.ipicker.entities;
/**
* Created by Eric on 16/9/12.
*/
public class Photo {
public String path;
public boolean showCamera = false;
public Photo(String path) {
this.path = path;
this.showCamera = false;
}
public Photo(boolean showCamera) {
this.showCamera = showCamera;
}
}
================================================
FILE: library/src/main/java/com/liuguangqiang/ipicker/internal/ImageMedia.java
================================================
/*
* Copyright 2016 Eric Liu
*
* 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
*
* 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.
*/
package com.liuguangqiang.ipicker.internal;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import com.liuguangqiang.ipicker.entities.Photo;
import java.util.ArrayList;
import java.util.List;
/**
* A helper for querying all images from sd card.
*
* Created by Eric on 16/9/12.
*/
public class ImageMedia {
/**
* Return a collection of image path.
*
* @param context
* @return
*/
public static List queryAll(Context context) {
List photos = new ArrayList<>();
// which image properties are we querying
String[] projection = new String[]{
MediaStore.Images.Media._ID,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.DATE_TAKEN,
MediaStore.Images.Media.DATA,
};
Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Cursor cur = MediaStore.Images.Media.query(
context.getContentResolver(),
images, // Uri
projection, // Which columns to return
null, // Which rows to return (all rows)
null, // Selection arguments (none)
MediaStore.Images.Media.DATE_TAKEN + " DESC" // Ordering
);
if (cur.moveToFirst()) {
int dataColumn = cur.getColumnIndex(
MediaStore.Images.Media.DATA);
do {
// Get the field values
photos.add(new Photo(cur.getString(dataColumn)));
} while (cur.moveToNext());
}
return photos;
}
/**
* Return the absolutely path of a uri.
*
* @param context
* @param uri
* @return
*/
public static String getFilePath(Context context, Uri uri) {
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = context.getContentResolver().query(uri, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
return filePath;
}
}
================================================
FILE: library/src/main/java/com/liuguangqiang/ipicker/internal/Logger.java
================================================
/*
* Copyright 2016 Eric Liu
*
* 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
*
* 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.
*/
package com.liuguangqiang.ipicker.internal;
import android.util.Log;
/**
* Created by Eric on 16/9/12.
*/
public class Logger {
private static final String TAG = "IPicker";
public static void i(String msg) {
Log.i(TAG, msg);
}
}
================================================
FILE: library/src/main/java/com/liuguangqiang/ipicker/widgets/SquareRelativeLayout.java
================================================
/*
* Copyright 2016 Eric Liu
*
* 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
*
* 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.
*/
package com.liuguangqiang.ipicker.widgets;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
/**
* Created by Eric on 16/9/12.
*/
public class SquareRelativeLayout extends RelativeLayout {
public SquareRelativeLayout(Context context) {
super(context);
}
public SquareRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
}
================================================
FILE: library/src/main/res/drawable/crop_texture.xml
================================================
================================================
FILE: library/src/main/res/drawable/round_white.xml
================================================
================================================
FILE: library/src/main/res/layout/activity_ipicker.xml
================================================
================================================
FILE: library/src/main/res/layout/activity_ipicker_crop.xml
================================================
================================================
FILE: library/src/main/res/layout/item_photo.xml
================================================
================================================
FILE: library/src/main/res/values/attrs.xml
================================================
================================================
FILE: library/src/main/res/values/colors.xml
================================================
#f45d64
#c34a51
#666666
#3d4049
#ffffff
#f3f3f3
#666666
#1a000000
#77000000
================================================
FILE: library/src/main/res/values/dimens.xml
================================================
56dp
================================================
FILE: library/src/main/res/values/strings.xml
================================================
All Pictures
DONE
Go Setting
Sorry, No permission to take pictures.
Sorry, No permission to access photos on your device.
Only %1$d photos can be selected.
Clipping Picture
Saving picture…
Please wait…
No image sources available
DONE
CANCEL
================================================
FILE: library/src/main/res/values-zh/strings.xml
================================================
选择照片
完成
设置
对不起, 没有拍照的权限。
对不起, 没有访问照片的权限。
最多只能选%1$d张图片哦。
裁剪图片
完成
取消
================================================
FILE: library/src/test/java/com/liuguangqiang/ipicker/ExampleUnitTest.java
================================================
package com.liuguangqiang.ipicker;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see Testing documentation
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
================================================
FILE: settings.gradle
================================================
include ':app', ':library'