Commit 6d225728 by zhengnw@sobot.com

album 1.0.0

parent 0ad71fca
......@@ -32,9 +32,10 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.google.android.material:material:1.4.+'
implementation project(':sobot_common')
implementation project(':sobot_widget')
implementation project(':sobot_album')
// implementation 'com.sobot.library:widget:0.3'
// api 'com.sobot.library:sobotcommon:1.0'
// api 'com.sobot.library:sobotcommon_x:1.0'
......
......@@ -9,10 +9,14 @@ import android.net.Uri;
import android.widget.ImageView;
import android.widget.TextView;
import com.sobot.common.login.SobotLoginTools;
import com.sobot.common.login.callback.SobotResultBlock;
import com.sobot.common.login.callback.SobotResultCode;
import com.sobot.common.login.model.HostModel;
import androidx.annotation.NonNull;
import com.sobot.album.Action;
import com.sobot.album.AlbumConfig;
import com.sobot.album.AlbumFile;
import com.sobot.album.SobotAlbum;
import com.sobot.album.SobotMediaLoader;
import com.sobot.album.api.widget.Widget;
import com.sobot.common.utils.SobotImageUtils;
import com.sobot.pictureframe.SobotBitmapUtil;
import com.sobot.utils.SobotLogUtils;
......@@ -25,12 +29,14 @@ import com.sobot.widget.refresh.layout.footer.ClassicsFooter;
import com.sobot.widget.refresh.layout.header.ClassicsHeader;
import com.sobot.widget.ui.SobotMarkConfig;
import com.sobot.widget.ui.base.SobotBaseActivity;
import com.sobot.widget.ui.permission.SobotPermissionListenerImpl;
import com.sobot.widget.ui.rich.HtmlToolUtils;
import com.sobot.widget.ui.toast.SobotToastUtil;
import com.sobot.widget.ui.webview.SobotWebViewActivity;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class MainActivity extends SobotBaseActivity {
......@@ -255,8 +261,61 @@ public class MainActivity extends SobotBaseActivity {
//// 是否隐藏底部工具栏 默认false显示, true 隐藏
// intent.putExtra("isHideToolBar", true);
// startActivity(intent);
permissionListener = new SobotPermissionListenerImpl() {
@Override
public void onPermissionSuccessListener() {
openAlbum();
}
};
if (checkIsShowPermissionPop(getString(R.string.sobot_memory_card), getString(R.string.sobot_memory_card_yongtu), 1, 4)) {
return;
}
if (!checkStoragePermission(4)) {
return;
}
openAlbum();
}
private void openAlbum() {
SobotAlbum.initialize(AlbumConfig.newBuilder(this)
.setAlbumLoader(new SobotMediaLoader())
.setLocale(Locale.getDefault())
.build());
SobotAlbum.album(MainActivity.this)
.multipleChoice()
.columnCount(4)
.selectCount(4)
.camera(false)
.cameraVideoQuality(1)
.cameraVideoLimitDuration(Integer.MAX_VALUE)
.cameraVideoLimitBytes(Integer.MAX_VALUE)
.checkedList(mAlbumFiles)
.widget(
Widget.newDarkBuilder(MainActivity.this)
.title("")
.build()
)
.onResult(new Action<ArrayList<AlbumFile>>() {
@Override
public void onAction(@NonNull ArrayList<AlbumFile> result) {
if (result.size() > 0) {
}
}
})
.onCancel(new Action<String>() {
@Override
public void onAction(@NonNull String result) {
//取消选择
}
})
.start();
}
private ArrayList<AlbumFile> mAlbumFiles = new ArrayList<>();//编辑的图片地址
@Override
protected void initData() {
}
......
......@@ -4,6 +4,7 @@ include ':sobot_utils'
include ':sobot_gson'
include ':sobot_common'
include ':sobot_widget'
include ':sobot_album'
include ':app'
rootProject.name = "Sobot_module_Dev"
/build
\ No newline at end of file
apply plugin: 'com.android.library'
android {
compileSdkVersion 34
defaultConfig {
minSdkVersion 17
targetSdkVersion 34
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles 'proguard-rules.pro'
}
qa_test {
}
qa_api {
}
}
}
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
compileOnly 'com.google.android.material:material:1.4.+'
compileOnly 'androidx.appcompat:appcompat:1.0.0'
compileOnly 'androidx.recyclerview:recyclerview:1.0.0'
api 'com.sobot.library:widget_x:1.2.1'
api 'com.sobot.library:picture_x:1.1.8'
}
//添加发布到mavenCentral脚本
apply from: './sobot-album_publish-mavencentral.gradle'
\ No newline at end of file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
\ No newline at end of file
apply plugin: 'maven-publish'
apply plugin: 'signing'
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.source
exclude "**/R.class"
exclude "**/BuildConfig.class"
}
ext {
PUBLISH_GROUP_ID = "com.sobot.library" //项目包名
PUBLISH_ARTIFACT_ID = 'album' //项目名
PUBLISH_VERSION = '1.0.0' //版本号
}
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.secretKeyRingFile"] = ''
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
println "Found secret props file, loading props"
Properties p = new Properties()
p.load(new FileInputStream(secretPropsFile))
p.each { name, value ->
ext[name] = value
}
} else {
println "No props file, loading env vars"
}
publishing {
publications {
release(MavenPublication) {
// The coordinates of the library, being set from variables that
// we'll set up in a moment
groupId PUBLISH_GROUP_ID
artifactId PUBLISH_ARTIFACT_ID
version PUBLISH_VERSION
// Two artifacts, the `aar` and the sources
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
artifact androidSourcesJar
// Self-explanatory metadata for the most part
pom {
name = PUBLISH_ARTIFACT_ID
description = 'sobotcommon'
// If your project has a dedicated site, use its URL here
url = 'http://code.zhichidata.com/sobot_android/Sobot_module_Dev'
licenses {
license {
//协议类型,一般默认Apache License2.0的话不用改:
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'app_dev@sobot.com'
name = 'zhichi'
email = 'app_dev@sobot.com'
}
}
// Version control info, if you're using GitHub, follow the format as seen here
scm {
//修改成你的Git地址:
connection = 'git@code.zhichidata.com:sobot_android/Sobot_module_Dev.git'
developerConnection = 'git@code.zhichidata.com:sobot_android/Sobot_module_Dev.git'
//分支地址:
url = 'http://code.zhichidata.com/sobot_android/Sobot_module_Dev/master'
}
// A slightly hacky fix so that your POM will include any transitive dependencies
// that your library builds upon
// withXml {
// def dependenciesNode = asNode().appendNode('dependencies')
//
// project.configurations.implementation.allDependencies.each {
// def dependencyNode = dependenciesNode.appendNode('dependency')
// dependencyNode.appendNode('groupId', it.group)
// dependencyNode.appendNode('artifactId', it.name)
// dependencyNode.appendNode('version', it.version)
// }
// }
withXml {
def dependenciesNode = asNode().appendNode('dependencies')
//跳过“unspecified”的依赖项
//避免出现问题:
//Execution failed for task ':sample:checkDebugAarMetadata'.
//> Could not resolve all files for configuration ':sample:debugRuntimeClasspath'.
// > Could not find :unspecified:.
// Required by:
project.configurations.implementation.allDependencies.each {
if (it.name != 'unspecified') {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}
repositories {
// The repository to publish to, Sonatype/MavenCentral
maven {
// This is an arbitrary name, you may also use "mavencentral" or
// any other name that's descriptive for you
//项目名称
name = "sobotwidget"
def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
// You only need this if you want to publish snapshots, otherwise just set the URL
// to the release repo directly
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
// The username and password we've fetched earlier
credentials {
username ossrhUsername
password ossrhPassword
}
}
}
}
signing {
sign publishing.publications
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sobot.album">
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!-- To handle the reselection within the app on Android 14 (API level 34) -->
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
<application>
<provider
android:name=".provider.CameraFileProvider"
android:authorities="${applicationId}.app.file.provider"
android:exported="false"
android:grantUriPermissions="true"
android:multiprocess="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/album_camera_provider" />
</provider>
<activity
android:name="com.sobot.album.activity.CameraActivity"
android:configChanges="orientation|keyboardHidden|screenSize|touchscreen|navigation|locale|fontScale|uiMode|screenLayout|smallestScreenSize"
android:screenOrientation="portrait"
android:theme="@style/sobot_activity_def_theme" />
<activity
android:name="com.sobot.album.activity.SobotAlbumActivity"
android:configChanges="orientation|keyboardHidden|screenSize|touchscreen|navigation|locale|fontScale|uiMode|screenLayout|smallestScreenSize"
android:screenOrientation="portrait"
android:theme="@style/sobot_activity_def_theme" />
<activity
android:name="com.sobot.album.activity.DefineStyleActivity"
android:configChanges="orientation|keyboardHidden|screenSize|touchscreen|navigation|locale|fontScale|uiMode|screenLayout|smallestScreenSize"
android:screenOrientation="portrait"
android:theme="@style/sobot_activity_def_theme" />
<activity
android:name="com.sobot.album.activity.GalleryActivity"
android:configChanges="orientation|keyboardHidden|screenSize|touchscreen|navigation|locale|fontScale|uiMode|screenLayout|smallestScreenSize"
android:screenOrientation="portrait" />
<activity
android:name="com.sobot.album.activity.AlbumFilterActivity"
android:configChanges="orientation|keyboardHidden|screenSize|touchscreen|navigation|locale|fontScale|uiMode|screenLayout|smallestScreenSize"
android:screenOrientation="portrait"
android:theme="@style/sobot_activity_def_theme" />
<activity
android:name="com.sobot.album.app.album.AlbumActivity"
android:configChanges="orientation|keyboardHidden|screenSize|touchscreen|navigation|locale|fontScale|uiMode|screenLayout|smallestScreenSize"
android:screenOrientation="portrait"
android:theme="@style/sobot_activity_def_theme" />
<activity
android:name="com.sobot.album.app.album.GalleryActivity"
android:configChanges="orientation|keyboardHidden|screenSize|touchscreen|navigation|locale|fontScale|uiMode|screenLayout|smallestScreenSize"
android:screenOrientation="portrait"
android:theme="@style/sobot_activity_def_theme" />
<activity
android:name="com.sobot.album.app.album.NullActivity"
android:configChanges="orientation|keyboardHidden|screenSize|touchscreen|navigation|locale|fontScale|uiMode|screenLayout|smallestScreenSize"
android:screenOrientation="portrait"
android:theme="@style/sobot_activity_def_theme" />
<activity
android:name="com.sobot.album.app.gallery.GalleryAlbumActivity"
android:configChanges="orientation|keyboardHidden|screenSize|touchscreen|navigation|locale|fontScale|uiMode|screenLayout|smallestScreenSize"
android:screenOrientation="portrait"
android:theme="@style/sobot_activity_def_theme" />
</application>
</manifest>
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album;
import androidx.annotation.NonNull;
public interface Action<T> {
/**
* When the action responds.
*
* @param result the result of the action.
*/
void onAction(@NonNull T result);
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album;
import android.content.Context;
import java.util.Locale;
/**
* <p>Album config.</p>
* Created by Yan Zhenjie on 2017/3/31.
*/
public class AlbumConfig {
/**
* Create a new builder.
*/
public static Builder newBuilder(Context context) {
return new Builder(context);
}
private AlbumLoader mLoader;
private Locale mLocale;
private AlbumConfig(Builder builder) {
this.mLoader = builder.mLoader == null ? AlbumLoader.DEFAULT : builder.mLoader;
this.mLocale = builder.mLocale == null ? Locale.getDefault() : builder.mLocale;
}
/**
* Get {@link AlbumLoader}.
*
* @return {@link AlbumLoader}.
*/
public AlbumLoader getAlbumLoader() {
return mLoader;
}
/**
* Get {@link Locale}.
*
* @return {@link Locale}.
*/
public Locale getLocale() {
return mLocale;
}
public static final class Builder {
private AlbumLoader mLoader;
private Locale mLocale;
private Builder(Context context) {
}
/**
* Set album loader.
*
* @param loader {@link AlbumLoader}.
* @return {@link Builder}.
*/
public Builder setAlbumLoader(AlbumLoader loader) {
this.mLoader = loader;
return this;
}
/**
* Set locale for language.
*
* @param locale {@link Locale}.
* @return {@link Builder}.
*/
public Builder setLocale(Locale locale) {
this.mLocale = locale;
return this;
}
/**
* Create AlbumConfig.
*
* @return {@link AlbumConfig}.
*/
public AlbumConfig build() {
return new AlbumConfig(this);
}
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
public class AlbumFile implements Parcelable, Comparable<AlbumFile> {
public static final int TYPE_IMAGE = 1;
public static final int TYPE_VIDEO = 2;
public static final int TYPE_ADD = 3;
@Retention(RetentionPolicy.SOURCE)
@IntDef({TYPE_IMAGE, TYPE_VIDEO,TYPE_ADD})
public @interface MediaType {
}
/**
* 本地文件路径.
*/
private String mPath;
/**
* 本地的uri
*/
private Uri uri;
private String fileNumKey;
/**
* 远程的地址
*/
private String fileUrl;
/**
* 文件名字.
*/
private String fileName;
/**
* 文件夹名字.
*/
private String mBucketName;
/**
* 文件扩展类型.
*/
private String mMimeType;
/**
* 添加日期.
*/
private long mAddDate;
/**
* Latitude
*/
private float mLatitude;
/**
* Longitude.
*/
private float mLongitude;
/**
* 大小.
*/
private long mSize;
/**
* Duration.
*/
private long mDuration;
/**
* Thumb path.
*/
private String mThumbPath;
/**
* MediaType.
*/
private int mMediaType;
/**
* Checked.
*/
private boolean isChecked;
/**
* Enabled.
*/
private boolean isDisable;
public AlbumFile() {
}
public Uri getUri() {
return uri;
}
public void setUri(Uri uri) {
this.uri = uri;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
@Override
public int compareTo(AlbumFile o) {
long time = o.getAddDate() - getAddDate();
if (time > Integer.MAX_VALUE)
return Integer.MAX_VALUE;
else if (time < -Integer.MAX_VALUE)
return -Integer.MAX_VALUE;
return (int) time;
}
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof AlbumFile) {
AlbumFile o = (AlbumFile) obj;
String inPath = o.getPath();
if (mPath != null && inPath != null) {
return mPath.equals(inPath);
}
}
return super.equals(obj);
}
@Override
public int hashCode() {
return mPath != null ? mPath.hashCode() : super.hashCode();
}
public String getPath() {
return mPath;
}
public void setPath(String path) {
mPath = path;
}
public String getBucketName() {
return mBucketName;
}
public void setBucketName(String bucketName) {
mBucketName = bucketName;
}
public String getMimeType() {
return mMimeType;
}
public void setMimeType(String mimeType) {
mMimeType = mimeType;
}
public long getAddDate() {
return mAddDate;
}
public void setAddDate(long addDate) {
mAddDate = addDate;
}
public float getLatitude() {
return mLatitude;
}
public void setLatitude(float latitude) {
mLatitude = latitude;
}
public float getLongitude() {
return mLongitude;
}
public void setLongitude(float longitude) {
mLongitude = longitude;
}
public long getSize() {
return mSize;
}
public void setSize(long size) {
mSize = size;
}
public long getDuration() {
return mDuration;
}
public void setDuration(long duration) {
mDuration = duration;
}
public String getThumbPath() {
return mThumbPath;
}
public void setThumbPath(String thumbPath) {
mThumbPath = thumbPath;
}
@MediaType
public int getMediaType() {
return mMediaType;
}
public void setMediaType(@MediaType int mediaType) {
mMediaType = mediaType;
}
public boolean isChecked() {
return isChecked;
}
public void setChecked(boolean checked) {
isChecked = checked;
}
public boolean isDisable() {
return isDisable;
}
public void setDisable(boolean disable) {
this.isDisable = disable;
}
public String getFileNumKey() {
return fileNumKey;
}
public void setFileNumKey(String fileNumKey) {
this.fileNumKey = fileNumKey;
}
public String getFileUrl() {
return fileUrl;
}
public void setFileUrl(String fileUrl) {
this.fileUrl = fileUrl;
}
protected AlbumFile(Parcel in) {
mPath = in.readString();
mBucketName = in.readString();
mMimeType = in.readString();
mAddDate = in.readLong();
mLatitude = in.readFloat();
mLongitude = in.readFloat();
mSize = in.readLong();
mDuration = in.readLong();
mThumbPath = in.readString();
mMediaType = in.readInt();
isChecked = in.readByte() != 0;
isDisable = in.readByte() != 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mPath);
dest.writeString(mBucketName);
dest.writeString(mMimeType);
dest.writeLong(mAddDate);
dest.writeFloat(mLatitude);
dest.writeFloat(mLongitude);
dest.writeLong(mSize);
dest.writeLong(mDuration);
dest.writeString(mThumbPath);
dest.writeInt(mMediaType);
dest.writeByte((byte) (isChecked ? 1 : 0));
dest.writeByte((byte) (isDisable ? 1 : 0));
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<AlbumFile> CREATOR = new Creator<AlbumFile>() {
@Override
public AlbumFile createFromParcel(Parcel in) {
return new AlbumFile(in);
}
@Override
public AlbumFile[] newArray(int size) {
return new AlbumFile[size];
}
};
}
\ No newline at end of file
/*
* Copyright 2016 Yan Zhenjie.
*
* 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.sobot.album;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
/**
* <p>Album folder, contains selected status and pictures.</p>
* Created by Yan Zhenjie on 2016/10/14.
*/
public class AlbumFolder implements Parcelable {
/**
* Folder name.
*/
private String name;
/**
* Image list in folder.
*/
private ArrayList<AlbumFile> mAlbumFiles = new ArrayList<>();
/**
* checked.
*/
private boolean isChecked;
public AlbumFolder() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<AlbumFile> getAlbumFiles() {
return mAlbumFiles;
}
public void addAlbumFile(AlbumFile albumFile) {
mAlbumFiles.add(albumFile);
}
public boolean isChecked() {
return isChecked;
}
public void setChecked(boolean checked) {
isChecked = checked;
}
protected AlbumFolder(Parcel in) {
name = in.readString();
mAlbumFiles = in.createTypedArrayList(AlbumFile.CREATOR);
isChecked = in.readByte() != 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeTypedList(mAlbumFiles);
dest.writeByte((byte) (isChecked ? 1 : 0));
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<AlbumFolder> CREATOR = new Creator<AlbumFolder>() {
@Override
public AlbumFolder createFromParcel(Parcel in) {
return new AlbumFolder(in);
}
@Override
public AlbumFolder[] newArray(int size) {
return new AlbumFolder[size];
}
};
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album;
import android.widget.ImageView;
public interface AlbumLoader {
AlbumLoader DEFAULT = new AlbumLoader() {
@Override
public void load(ImageView imageView, AlbumFile albumFile) {
}
@Override
public void load(ImageView imageView, String url) {
}
};
/**
* Load a preview of the album file.
*
* @param imageView {@link ImageView}.
* @param albumFile the media object may be a picture or video.
*/
void load(ImageView imageView, AlbumFile albumFile);
/**
* Load thumbnails of pictures or videos, either local file or remote file.
*
* @param imageView {@link ImageView}.
* @param url The url of the file, local path or remote path.
*/
void load(ImageView imageView, String url);
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album;
public interface Filter<T> {
/**
* Filter the file.
*
* @param attributes attributes of file.
* @return filter returns true, otherwise false.
*/
boolean filter(T attributes);
}
\ No newline at end of file
/*
* Copyright 2018 Yan Zhenjie.
*
* 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.sobot.album;
import android.content.Context;
public interface ItemAction<T> {
/**
* When the action responds.
*
* @param context context.
* @param item item.
*/
void onAction(Context context, T item);
}
/*
* Copyright 2016 Yan Zhenjie.
*
* 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.sobot.album;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.util.Log;
import androidx.annotation.IntDef;
import com.sobot.album.api.AlbumMultipleWrapper;
import com.sobot.album.api.AlbumSingleWrapper;
import com.sobot.album.api.BasicGalleryWrapper;
import com.sobot.album.api.GalleryAlbumWrapper;
import com.sobot.album.api.GalleryWrapper;
import com.sobot.album.api.ImageCameraWrapper;
import com.sobot.album.api.ImageMultipleWrapper;
import com.sobot.album.api.ImageSingleWrapper;
import com.sobot.album.api.VideoCameraWrapper;
import com.sobot.album.api.VideoMultipleWrapper;
import com.sobot.album.api.VideoSingleWrapper;
import com.sobot.album.api.camera.AlbumCamera;
import com.sobot.album.api.camera.Camera;
import com.sobot.album.api.choice.AlbumChoice;
import com.sobot.album.api.choice.Choice;
import com.sobot.album.api.choice.ImageChoice;
import com.sobot.album.api.choice.VideoChoice;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* 图片选择器
*/
public final class SobotAlbum {
// All.
public static final String KEY_INPUT_WIDGET = "KEY_INPUT_WIDGET";
public static final String KEY_INPUT_CHECKED_LIST = "KEY_INPUT_CHECKED_LIST";
// Album.
public static final String KEY_INPUT_FUNCTION = "KEY_INPUT_FUNCTION";
public static final int FUNCTION_CHOICE_IMAGE = 0;
public static final int FUNCTION_CHOICE_VIDEO = 1;
public static final int FUNCTION_CHOICE_ALBUM = 2;
public static final int FUNCTION_CAMERA_IMAGE = 0;
public static final int FUNCTION_CAMERA_VIDEO = 1;
public static final String KEY_INPUT_CHOICE_MODE = "KEY_INPUT_CHOICE_MODE";
public static final int MODE_MULTIPLE = 1;
public static final int MODE_SINGLE = 2;
public static final String KEY_INPUT_COLUMN_COUNT = "KEY_INPUT_COLUMN_COUNT";
public static final String KEY_INPUT_ALLOW_CAMERA = "KEY_INPUT_ALLOW_CAMERA";
public static final String KEY_INPUT_LIMIT_COUNT = "KEY_INPUT_LIMIT_COUNT";
// Gallery.
public static final String KEY_INPUT_CURRENT_POSITION = "KEY_INPUT_CURRENT_POSITION";
public static final String KEY_INPUT_GALLERY_CHECKABLE = "KEY_INPUT_GALLERY_CHECKABLE";
// Camera.
public static final String KEY_INPUT_FILE_PATH = "KEY_INPUT_FILE_PATH";
public static final String KEY_INPUT_CAMERA_QUALITY = "KEY_INPUT_CAMERA_QUALITY";
public static final String KEY_INPUT_CAMERA_DURATION = "KEY_INPUT_CAMERA_DURATION";
public static final String KEY_INPUT_CAMERA_BYTES = "KEY_INPUT_CAMERA_BYTES";
// Filter.
public static final String KEY_INPUT_FILTER_VISIBILITY = "KEY_INPUT_FILTER_VISIBILITY";
@IntDef({FUNCTION_CHOICE_IMAGE, FUNCTION_CHOICE_VIDEO, FUNCTION_CHOICE_ALBUM})
@Retention(RetentionPolicy.SOURCE)
public @interface ChoiceFunction {
}
@IntDef({FUNCTION_CAMERA_IMAGE, FUNCTION_CAMERA_VIDEO})
@Retention(RetentionPolicy.SOURCE)
public @interface CameraFunction {
}
@IntDef({MODE_MULTIPLE, MODE_SINGLE})
@Retention(RetentionPolicy.SOURCE)
public @interface ChoiceMode {
}
private static AlbumConfig sAlbumConfig;
/**
* Initialize Album.
*
* @param albumConfig {@link AlbumConfig}.
*/
public static void initialize(AlbumConfig albumConfig) {
if (sAlbumConfig == null) sAlbumConfig = albumConfig;
else
Log.w("Album", new IllegalStateException("Illegal operation, only allowed to configure once."));
}
/**
* Get the album configuration.
*/
public static AlbumConfig getAlbumConfig() {
if (sAlbumConfig == null) {
sAlbumConfig = AlbumConfig.newBuilder(null).build();
}
return sAlbumConfig;
}
/**
* Open the camera from the activity.
*/
public static Camera<ImageCameraWrapper, VideoCameraWrapper> camera(Context context) {
return new AlbumCamera(context);
}
/**
* Select images.
*/
public static Choice<ImageMultipleWrapper, ImageSingleWrapper> image(Context context) {
return new ImageChoice(context);
}
/**
* Select videos.
*/
public static Choice<VideoMultipleWrapper, VideoSingleWrapper> video(Context context) {
return new VideoChoice(context);
}
/**
* Select images and videos.
*/
public static Choice<AlbumMultipleWrapper, AlbumSingleWrapper> album(Context context) {
return new AlbumChoice(context);
}
/**
* Preview picture.
*/
public static GalleryWrapper gallery(Context context) {
return new GalleryWrapper(context);
}
/**
* Preview Album.
*/
public static GalleryAlbumWrapper galleryAlbum(Context context) {
return new GalleryAlbumWrapper(context);
}
/**
* Open the camera from the activity.
*/
public static Camera<ImageCameraWrapper, VideoCameraWrapper> camera(Activity activity) {
return new AlbumCamera(activity);
}
/**
* Select images.
*/
public static Choice<ImageMultipleWrapper, ImageSingleWrapper> image(Activity activity) {
return new ImageChoice(activity);
}
/**
* Select videos.
*/
public static Choice<VideoMultipleWrapper, VideoSingleWrapper> video(Activity activity) {
return new VideoChoice(activity);
}
/**
* Select images and videos.
*/
public static Choice<AlbumMultipleWrapper, AlbumSingleWrapper> album(Activity activity) {
return new AlbumChoice(activity);
}
/**
* Preview picture.
*/
public static BasicGalleryWrapper<GalleryWrapper, String, String, String> gallery(Activity activity) {
return new GalleryWrapper(activity);
}
/**
* Preview Album.
*/
public static BasicGalleryWrapper<GalleryAlbumWrapper, AlbumFile, String, AlbumFile> galleryAlbum(Activity activity) {
return new GalleryAlbumWrapper(activity);
}
/**
* Open the camera from the activity.
*/
public static Camera<ImageCameraWrapper, VideoCameraWrapper> camera(Fragment fragment) {
return new AlbumCamera(fragment.getActivity());
}
/**
* Select images.
*/
public static Choice<ImageMultipleWrapper, ImageSingleWrapper> image(Fragment fragment) {
return new ImageChoice(fragment.getActivity());
}
/**
* Select videos.
*/
public static Choice<VideoMultipleWrapper, VideoSingleWrapper> video(Fragment fragment) {
return new VideoChoice(fragment.getActivity());
}
/**
* Select images and videos.
*/
public static Choice<AlbumMultipleWrapper, AlbumSingleWrapper> album(Fragment fragment) {
return new AlbumChoice(fragment.getActivity());
}
/**
* Preview picture.
*/
public static BasicGalleryWrapper<GalleryWrapper, String, String, String> gallery(Fragment fragment) {
return new GalleryWrapper(fragment.getActivity());
}
/**
* Preview Album.
*/
public static BasicGalleryWrapper<GalleryAlbumWrapper, AlbumFile, String, AlbumFile> galleryAlbum(Fragment fragment) {
return new GalleryAlbumWrapper(fragment.getActivity());
}
}
\ No newline at end of file
package com.sobot.album;
import android.net.Uri;
import android.widget.ImageView;
import com.sobot.pictureframe.SobotBitmapUtil;
import com.sobot.utils.SobotStringUtils;
public class SobotMediaLoader implements AlbumLoader {
@Override
public void load(ImageView imageView, AlbumFile albumFile) {
if (albumFile != null && SobotStringUtils.isNoEmpty(albumFile.getPath())) {
load(imageView, albumFile.getPath());
}
}
@Override
public void load(ImageView imageView, String url) {
if (SobotStringUtils.isNoEmpty(url) && imageView != null) {
SobotBitmapUtil.display(imageView.getContext(), url, imageView);
}
}
public void load(ImageView imageView, Uri uri) {
// if (uri != null && imageView != null) {
// imageView.setImageURI(uri);
// }
}
}
\ No newline at end of file
package com.sobot.album.activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.sobot.album.AlbumFile;
import com.sobot.album.R;
import com.sobot.album.SobotAlbum;
import com.sobot.album.impl.OnItemClickListener;
import com.sobot.album.util.AlbumUtils;
import java.util.List;
public class Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private LayoutInflater mInflater;
private OnItemClickListener mItemClickListener;
private List<AlbumFile> mAlbumFiles;
private Context mContext;
public Adapter(Context context, OnItemClickListener itemClickListener) {
this.mInflater = LayoutInflater.from(context);
this.mItemClickListener = itemClickListener;
this.mContext = context;
}
public void notifyDataSetChanged(List<AlbumFile> imagePathList) {
this.mAlbumFiles = imagePathList;
super.notifyDataSetChanged();
}
@Override
public int getItemViewType(int position) {
AlbumFile albumFile = mAlbumFiles.get(position);
if (albumFile.getMediaType() == AlbumFile.TYPE_IMAGE) {
return AlbumFile.TYPE_IMAGE;
} else {
return AlbumFile.TYPE_VIDEO;
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
switch (viewType) {
case AlbumFile.TYPE_IMAGE: {
return new ImageViewHolder(mContext, mInflater.inflate(R.layout.item_content_image, parent, false), mItemClickListener);
}
case AlbumFile.TYPE_VIDEO: {
return new VideoViewHolder(mContext, mInflater.inflate(R.layout.item_content_video, parent, false), mItemClickListener);
}
default: {
throw new AssertionError("This should not be the case.");
}
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
int viewType = getItemViewType(position);
switch (viewType) {
case AlbumFile.TYPE_IMAGE: {
((ImageViewHolder) holder).setData(mAlbumFiles.get(position));
break;
}
case AlbumFile.TYPE_VIDEO: {
((VideoViewHolder) holder).setData(mAlbumFiles.get(position));
break;
}
}
}
@Override
public int getItemCount() {
return mAlbumFiles == null ? 0 : mAlbumFiles.size();
}
private static class ImageViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private final OnItemClickListener mItemClickListener;
private ImageView mIvImage;
private Context mContext;
ImageViewHolder(Context context, View itemView, OnItemClickListener itemClickListener) {
super(itemView);
this.mContext = context;
this.mItemClickListener = itemClickListener;
this.mIvImage = itemView.findViewById(R.id.iv_album_content_image);
itemView.setOnClickListener(this);
}
public void setData(AlbumFile albumFile) {
SobotAlbum.getAlbumConfig().
getAlbumLoader().
load(mIvImage, albumFile);
}
@Override
public void onClick(View v) {
if (mItemClickListener != null) {
mItemClickListener.onItemClick(v, getAdapterPosition());
}
}
}
private static class VideoViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private final OnItemClickListener mItemClickListener;
private ImageView mIvImage;
private TextView mTvDuration;
private Context mContext;
VideoViewHolder(Context context, View itemView, OnItemClickListener itemClickListener) {
super(itemView);
this.mContext = context;
this.mItemClickListener = itemClickListener;
this.mIvImage = itemView.findViewById(R.id.iv_album_content_image);
this.mTvDuration = itemView.findViewById(R.id.tv_duration);
itemView.setOnClickListener(this);
}
void setData(AlbumFile albumFile) {
SobotAlbum.getAlbumConfig().
getAlbumLoader().
load(mIvImage, albumFile);
mTvDuration.setText(AlbumUtils.convertDuration(albumFile.getDuration()));
}
@Override
public void onClick(View v) {
if (mItemClickListener != null) {
mItemClickListener.onItemClick(v, getAdapterPosition());
}
}
}
}
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.sobot.album.Action;
import com.sobot.album.AlbumFile;
import com.sobot.album.Filter;
import com.sobot.album.R;
import com.sobot.album.SobotAlbum;
import com.sobot.album.api.widget.Widget;
import com.sobot.album.impl.OnItemClickListener;
import com.sobot.album.widget.divider.Api21ItemDivider;
import com.sobot.album.widget.divider.Divider;
import java.util.ArrayList;
public class AlbumFilterActivity extends AppCompatActivity {
// private Toolbar mToolbar;
private TextView mTvMessage;
private Adapter mAdapter;
private ArrayList<AlbumFile> mAlbumFiles;
private boolean mAfterFilterVisibility;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_album_filter);
// mToolbar = findViewById(R.id.toolbar);
// setSupportActionBar(mToolbar);
mTvMessage = findViewById(R.id.tv_message);
RecyclerView recyclerView = findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
Divider divider = new Api21ItemDivider(Color.TRANSPARENT, 10, 10);
recyclerView.addItemDecoration(divider);
mAdapter = new Adapter(this, new OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
previewAlbum(position);
}
});
recyclerView.setAdapter(mAdapter);
}
/**
* Select picture, from album.
*/
private void selectAlbum() {
SobotAlbum.album(this)
.multipleChoice()
.filterMimeType(new Filter<String>() { // MimeType of File.
@Override
public boolean filter(String attributes) {
// MimeType: image/jpeg, image/png, video/mp4, video/3gp...
return attributes.contains("jpeg");
}
})
// .filterSize() // File size.
// .filterDuration() // Video duration.
.afterFilterVisibility(mAfterFilterVisibility)
.columnCount(2)
.selectCount(6)
.camera(true)
.checkedList(mAlbumFiles)
.widget(
Widget.newDarkBuilder(this)
.title("albun filter")
.build()
)
.onResult(new Action<ArrayList<AlbumFile>>() {
@Override
public void onAction(@NonNull ArrayList<AlbumFile> result) {
mAlbumFiles = result;
mAdapter.notifyDataSetChanged(mAlbumFiles);
mTvMessage.setVisibility(result.size() > 0 ? View.VISIBLE : View.GONE);
}
})
.onCancel(new Action<String>() {
@Override
public void onAction(@NonNull String result) {
Toast.makeText(AlbumFilterActivity.this, R.string.canceled, Toast.LENGTH_LONG).show();
}
})
.start();
}
/**
* Preview image, to album.
*/
private void previewAlbum(int position) {
if (mAlbumFiles == null || mAlbumFiles.size() == 0) {
Toast.makeText(this, R.string.no_selected, Toast.LENGTH_LONG).show();
} else {
SobotAlbum.galleryAlbum(this)
.checkable(true)
.checkedList(mAlbumFiles)
.currentPosition(position)
.widget(
Widget.newDarkBuilder(this)
.title("Album filter")
.build()
)
.onResult(new Action<ArrayList<AlbumFile>>() {
@Override
public void onAction(@NonNull ArrayList<AlbumFile> result) {
mAlbumFiles = result;
mAdapter.notifyDataSetChanged(mAlbumFiles);
mTvMessage.setVisibility(result.size() > 0 ? View.VISIBLE : View.GONE);
}
})
.start();
}
}
/* @Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_album, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
finish();
} else if (id == R.id.menu_eye) {
previewAlbum(0);
} else if (id == R.id.menu_album) {
new AlertDialog.Builder(this)
.setCancelable(false)
.setTitle(R.string.app_name)
.setMessage(R.string.hint_filter_after_visibility)
.setNeutralButton(R.string.filter_after_visibility_gone, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mAfterFilterVisibility = false;
selectAlbum();
}
})
.setPositiveButton(R.string.filter_after_visibility_visible, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mAfterFilterVisibility = true;
selectAlbum();
}
})
.show();
}
return true;
}*/
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import com.sobot.album.Action;
import com.sobot.album.R;
import com.sobot.album.SobotAlbum;
public class CameraActivity extends AppCompatActivity {
TextView mTextView;
private ImageView mImageView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
// Toolbar toolbar = findViewById(R.id.toolbar);
// setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
mTextView = findViewById(R.id.tv_message);
mImageView = findViewById(R.id.image_view);
}
private void takePicture() {
SobotAlbum.camera(this)
.image()
// .filePath()
.onResult(new Action<String>() {
@Override
public void onAction(@NonNull String result) {
mTextView.setText(result);
SobotAlbum.getAlbumConfig()
.getAlbumLoader()
.load(mImageView, result);
}
})
.onCancel(new Action<String>() {
@Override
public void onAction(@NonNull String result) {
Toast.makeText(CameraActivity.this, R.string.canceled, Toast.LENGTH_LONG).show();
}
})
.start();
}
private void recordVideo() {
SobotAlbum.camera(this)
.video()
// .filePath()
.quality(1)
.limitDuration(Integer.MAX_VALUE)
.limitBytes(Integer.MAX_VALUE)
.onResult(new Action<String>() {
@Override
public void onAction(@NonNull String result) {
mTextView.setText(result);
SobotAlbum.getAlbumConfig()
.getAlbumLoader()
.load(mImageView, result);
}
})
.onCancel(new Action<String>() {
@Override
public void onAction(@NonNull String result) {
Toast.makeText(CameraActivity.this, R.string.canceled, Toast.LENGTH_LONG).show();
}
})
.start();
}
/* @Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_album_camera, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
finish();
} else if (id == R.id.menu_image_capture) {
takePicture();
} else if (id == R.id.menu_video_capture) {
recordVideo();
}
return true;
}*/
}
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.sobot.album.Action;
import com.sobot.album.AlbumFile;
import com.sobot.album.R;
import com.sobot.album.SobotAlbum;
import com.sobot.album.api.widget.Widget;
import com.sobot.album.impl.OnItemClickListener;
import com.sobot.album.widget.divider.Api21ItemDivider;
import com.sobot.album.widget.divider.Divider;
import java.util.ArrayList;
public class DefineStyleActivity extends AppCompatActivity {
// private Toolbar mToolbar;
private TextView mTvMessage;
private Adapter mAdapter;
private ArrayList<AlbumFile> mAlbumFiles;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_album_ui);
// mToolbar = findViewById(R.id.toolbar);
// setSupportActionBar(mToolbar);
mTvMessage = findViewById(R.id.tv_message);
RecyclerView recyclerView = findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
Divider divider = new Api21ItemDivider(Color.TRANSPARENT, 10, 10);
recyclerView.addItemDecoration(divider);
mAdapter = new Adapter(this, new OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
previewAlbum(position);
}
});
recyclerView.setAdapter(mAdapter);
}
/**
* Select picture, from album.
*/
private void selectAlbum() {
SobotAlbum.album(this)
.multipleChoice()
.selectCount(6)
.camera(true)
.checkedList(mAlbumFiles)
.widget(
Widget.newLightBuilder(this)
.title("define style")
.statusBarColor(Color.WHITE)
.toolBarColor(Color.WHITE)
.mediaItemCheckSelector(Color.BLUE, Color.GREEN)
.bucketItemCheckSelector(Color.RED, Color.YELLOW)
.buttonStyle(
Widget.ButtonStyle.newLightBuilder(this)
.setButtonSelector(Color.WHITE, Color.WHITE)
.build()
)
.build()
)
.onResult(new Action<ArrayList<AlbumFile>>() {
@Override
public void onAction(@NonNull ArrayList<AlbumFile> result) {
mAlbumFiles = result;
mAdapter.notifyDataSetChanged(mAlbumFiles);
mTvMessage.setVisibility(result.size() > 0 ? View.VISIBLE : View.GONE);
}
})
.onCancel(new Action<String>() {
@Override
public void onAction(@NonNull String result) {
Toast.makeText(DefineStyleActivity.this, R.string.canceled, Toast.LENGTH_LONG).show();
}
})
.start();
}
/**
* Preview image, to album.
*/
private void previewAlbum(int position) {
if (mAlbumFiles == null || mAlbumFiles.size() == 0) {
Toast.makeText(this, R.string.no_selected, Toast.LENGTH_LONG).show();
} else {
SobotAlbum.galleryAlbum(this)
.checkable(true)
.checkedList(mAlbumFiles)
.currentPosition(position)
.widget(
Widget.newLightBuilder(this)
.toolBarColor(Color.WHITE)
.statusBarColor(Color.WHITE)
.mediaItemCheckSelector(Color.GREEN, Color.RED)
.bucketItemCheckSelector(Color.GREEN, Color.RED)
.buttonStyle(
Widget.ButtonStyle.newLightBuilder(this)
.setButtonSelector(Color.WHITE, Color.GRAY)
.build()
)
.build()
)
.onResult(new Action<ArrayList<AlbumFile>>() {
@Override
public void onAction(@NonNull ArrayList<AlbumFile> result) {
mAlbumFiles = result;
mAdapter.notifyDataSetChanged(mAlbumFiles);
mTvMessage.setVisibility(result.size() > 0 ? View.VISIBLE : View.GONE);
}
})
.start();
}
}
/*@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_album, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
finish();
} else if (id == R.id.menu_eye) {
previewAlbum(0);
} else if (id == R.id.menu_album) {
selectAlbum();
}
return true;
}*/
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.sobot.album.Action;
import com.sobot.album.R;
import com.sobot.album.SobotAlbum;
import com.sobot.album.api.widget.Widget;
import java.util.ArrayList;
import java.util.Collections;
public class GalleryActivity extends AppCompatActivity {
private static final String[] IMAGE_PATH_LIST = {
"http://pic1.win4000.com/mobile/1/520d9410ebc79.jpg", "http://pic1.win4000.com/mobile/1/520d941218b04.jpg",
"http://wapfile.desktx.com/7681280/0925/160925tn4a5sz3at2.jpg", "http://wapfile.desktx.com/7681280/0925/160925ruuqfaqwuvx.jpg",
"http://wapfile.desktx.com/7681280/0925/160925a0x5knyt3ue.jpg", "http://wapfile.desktx.com/7681280/0925/160925jrfl5dnvln1.jpg",
"http://wapfile.desktx.com/7681280/0925/160925csx5pu2ysam.jpg", "http://wapfile.desktx.com/7681280/0925/160925m4lgeuakuc5.jpg",
"http://wapfile.desktx.com/7681280/0925/160925gcmbg5gycqw.jpg", "http://wapfile.desktx.com/7681280/0925/160925o0zf2pbozw1.jpg",
"http://wapfile.desktx.com/7681280/0925/160925danhsef1uzu.jpg", "http://wapfile.desktx.com/7681280/0925/160925y5lmcrqslm4.jpg",
"http://wapfile.desktx.com/7681280/0925/160925njt3dm2hlw0.jpg", "http://wapfile.desktx.com/7681280/0925/160925xgesspjxztt.jpg",
"http://wapfile.desktx.com/7681280/0925/160925a5dg2zsddtx.jpg", "http://wapfile.desktx.com/7681280/0925/1609252fupmrdasrp.jpg",
"http://wapfile.desktx.com/7681280/0925/160925lasaphesxkd.jpg", "http://wapfile.desktx.com/7681280/0925/160925ti2kged45bp.jpg",
"http://wapfile.desktx.com/7681280/0925/160925dsx3uyapoen.jpg", "http://wapfile.desktx.com/7681280/0925/160925largrb3p2l4.jpg",
"http://wapfile.desktx.com/7681280/0925/160925l0vaht45uy1.jpg", "http://wapfile.desktx.com/7681280/0925/160925054jrhaerro.jpg",
"http://wapfile.desktx.com/7681280/0925/1609255mlt2so5yp2.jpg", "http://wapfile.desktx.com/7681280/0925/160925bm3jmwdptie.jpg",
"http://wapfile.desktx.com/7681280/0925/1609251brfaryoizu.jpg", "http://wapfile.desktx.com/7681280/0925/1609254qfjkbwjlox.jpg",
"http://wapfile.desktx.com/7681280/0925/160925memb5c4pcnt.jpg", "http://wapfile.desktx.com/7681280/0925/160925c5i4dbhh2rh.jpg",
"http://wapfile.desktx.com/7681280/0925/1609254pmjqhppmah.jpg", "http://wapfile.desktx.com/7681280/0925/16092505gvkuoampz.jpg",
"http://wapfile.desktx.com/7681280/0925/1609254dxk3vpsrvj.jpg", "http://wapfile.desktx.com/7681280/0925/160925bgyxuik3j4y.jpg",
"http://wapfile.desktx.com/7681280/0925/160925jbhhtendosg.jpg", "http://wapfile.desktx.com/7681280/0925/160925knnv51uglia.jpg",
"http://wapfile.desktx.com/7681280/0925/160925vajxn2aqfkc.jpg", "http://wapfile.desktx.com/7681280/0925/160925xehnehy5frf.jpg",
"http://wapfile.desktx.com/7681280/0925/160925e2rajc4zi4k.jpg", "http://wapfile.desktx.com/7681280/0925/160925dfxg2wlarga.jpg",
"http://wapfile.desktx.com/7681280/0925/160925vuifhcqactt.jpg", "http://wapfile.desktx.com/7681280/0925/160925rcxiez3ikcg.jpg"
};
// private Toolbar mToolbar;
private CheckBox mCheckBox;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gallery);
// mToolbar = findViewById(R.id.toolbar);
// setSupportActionBar(mToolbar);
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mCheckBox = findViewById(R.id.checkbox);
findViewById(R.id.btn_gallery).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
previewImages();
}
});
}
private void previewImages() {
ArrayList<String> imageList = new ArrayList<>();
Collections.addAll(imageList, IMAGE_PATH_LIST);
SobotAlbum.gallery(this)
.checkedList(imageList)
.checkable(mCheckBox.isChecked())
.widget(
Widget.newDarkBuilder(this)
.title("gallery ")
.build()
)
.onResult(new Action<ArrayList<String>>() {
@Override
public void onAction(@NonNull ArrayList<String> result) {
// TODO If it is optional, here you can accept the results of user selection.
}
})
.start();
}
/* @Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
finish();
}
return true;
}*/
@Override
protected void onDestroy() {
super.onDestroy();
}
}
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import android.content.Intent;
import androidx.annotation.IntRange;
import com.sobot.album.AlbumFile;
import com.sobot.album.Filter;
import com.sobot.album.SobotAlbum;
import com.sobot.album.app.album.AlbumActivity;
import java.util.ArrayList;
public class AlbumMultipleWrapper extends BasicChoiceAlbumWrapper<AlbumMultipleWrapper, ArrayList<AlbumFile>, String, ArrayList<AlbumFile>> {
private int mLimitCount = Integer.MAX_VALUE;
private Filter<Long> mDurationFilter;
public AlbumMultipleWrapper(Context context) {
super(context);
}
/**
* Set the list has been selected.
*
* @param checked the data list.
*/
public final AlbumMultipleWrapper checkedList(ArrayList<AlbumFile> checked) {
this.mChecked = checked;
return this;
}
/**
* Set the maximum number to be selected.
*
* @param count the maximum number.
*/
public AlbumMultipleWrapper selectCount(@IntRange(from = 1, to = Integer.MAX_VALUE) int count) {
this.mLimitCount = count;
return this;
}
/**
* Filter video duration.
*
* @param filter filter.
*/
public AlbumMultipleWrapper filterDuration(Filter<Long> filter) {
this.mDurationFilter = filter;
return this;
}
@Override
public void start() {
AlbumActivity.sSizeFilter = mSizeFilter;
AlbumActivity.sMimeFilter = mMimeTypeFilter;
AlbumActivity.sDurationFilter = mDurationFilter;
AlbumActivity.sResult = mResult;
AlbumActivity.sCancel = mCancel;
Intent intent = new Intent(mContext, AlbumActivity.class);
intent.putExtra(SobotAlbum.KEY_INPUT_WIDGET, mWidget);
intent.putParcelableArrayListExtra(SobotAlbum.KEY_INPUT_CHECKED_LIST, mChecked);
intent.putExtra(SobotAlbum.KEY_INPUT_FUNCTION, SobotAlbum.FUNCTION_CHOICE_ALBUM);
intent.putExtra(SobotAlbum.KEY_INPUT_CHOICE_MODE, SobotAlbum.MODE_MULTIPLE);
intent.putExtra(SobotAlbum.KEY_INPUT_COLUMN_COUNT, mColumnCount);
intent.putExtra(SobotAlbum.KEY_INPUT_ALLOW_CAMERA, mHasCamera);
intent.putExtra(SobotAlbum.KEY_INPUT_LIMIT_COUNT, mLimitCount);
intent.putExtra(SobotAlbum.KEY_INPUT_FILTER_VISIBILITY, mFilterVisibility);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_QUALITY, mQuality);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_DURATION, mLimitDuration);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_BYTES, mLimitBytes);
mContext.startActivity(intent);
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import android.content.Intent;
import com.sobot.album.AlbumFile;
import com.sobot.album.Filter;
import com.sobot.album.SobotAlbum;
import com.sobot.album.app.album.AlbumActivity;
import java.util.ArrayList;
public class AlbumSingleWrapper extends BasicChoiceAlbumWrapper<AlbumSingleWrapper, ArrayList<AlbumFile>, String, AlbumFile> {
private Filter<Long> mDurationFilter;
public AlbumSingleWrapper(Context context) {
super(context);
}
/**
* Filter video duration.
*
* @param filter filter.
*/
public AlbumSingleWrapper filterDuration(Filter<Long> filter) {
this.mDurationFilter = filter;
return this;
}
@Override
public void start() {
AlbumActivity.sSizeFilter = mSizeFilter;
AlbumActivity.sMimeFilter = mMimeTypeFilter;
AlbumActivity.sDurationFilter = mDurationFilter;
AlbumActivity.sResult = mResult;
AlbumActivity.sCancel = mCancel;
Intent intent = new Intent(mContext, AlbumActivity.class);
intent.putExtra(SobotAlbum.KEY_INPUT_WIDGET, mWidget);
intent.putExtra(SobotAlbum.KEY_INPUT_FUNCTION, SobotAlbum.FUNCTION_CHOICE_ALBUM);
intent.putExtra(SobotAlbum.KEY_INPUT_CHOICE_MODE, SobotAlbum.MODE_SINGLE);
intent.putExtra(SobotAlbum.KEY_INPUT_COLUMN_COUNT, mColumnCount);
intent.putExtra(SobotAlbum.KEY_INPUT_ALLOW_CAMERA, mHasCamera);
intent.putExtra(SobotAlbum.KEY_INPUT_LIMIT_COUNT, 1);
intent.putExtra(SobotAlbum.KEY_INPUT_FILTER_VISIBILITY, mFilterVisibility);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_QUALITY, mQuality);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_DURATION, mLimitDuration);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_BYTES, mLimitBytes);
mContext.startActivity(intent);
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import androidx.annotation.Nullable;
import com.sobot.album.Action;
import com.sobot.album.api.widget.Widget;
public abstract class BasicAlbumWrapper<Returner extends BasicAlbumWrapper, Result, Cancel, Checked> {
final Context mContext;
Action<Result> mResult;
Action<Cancel> mCancel;
Widget mWidget;
Checked mChecked;
BasicAlbumWrapper(Context context) {
this.mContext = context;
mWidget = Widget.getDefaultWidget(context);
}
/**
* Set the action when result.
*
* @param result action when producing result.
*/
public final Returner onResult(Action<Result> result) {
this.mResult = result;
return (Returner) this;
}
/**
* Set the action when canceling.
*
* @param cancel action when canceled.
*/
public final Returner onCancel(Action<Cancel> cancel) {
this.mCancel = cancel;
return (Returner) this;
}
/**
* Set the widget property.
*
* @param widget the widget.
*/
public final Returner widget(@Nullable Widget widget) {
this.mWidget = widget;
return (Returner) this;
}
/**
* Start up.
*/
public abstract void start();
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import androidx.annotation.Nullable;
import com.sobot.album.Action;
public abstract class BasicCameraWrapper<Returner extends BasicCameraWrapper> {
Context mContext;
Action<String> mResult;
Action<String> mCancel;
String mFilePath;
public BasicCameraWrapper(Context context) {
this.mContext = context;
}
/**
* Set the action when result.
*
* @param result action when producing result.
*/
public final Returner onResult(Action<String> result) {
this.mResult = result;
return (Returner) this;
}
/**
* Set the action when canceling.
*
* @param cancel action when canceled.
*/
public final Returner onCancel(Action<String> cancel) {
this.mCancel = cancel;
return (Returner) this;
}
/**
* Set the image storage path.
*
* @param filePath storage path.
*/
public Returner filePath(@Nullable String filePath) {
this.mFilePath = filePath;
return (Returner) this;
}
/**
* Start up.
*/
public abstract void start();
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import androidx.annotation.IntRange;
public abstract class BasicChoiceAlbumWrapper<Returner extends BasicChoiceAlbumWrapper, Result, Cancel, Checked> extends BasicChoiceWrapper<Returner, Result, Cancel, Checked> {
BasicChoiceAlbumWrapper(Context context) {
super(context);
}
int mQuality = 1;
long mLimitDuration = Integer.MAX_VALUE;
long mLimitBytes = Integer.MAX_VALUE;
/**
* Set the quality when taking video, should be 0 or 1. Currently value 0 means low quality, and value 1 means high quality.
*
* @param quality should be 0 or 1.
*/
public Returner cameraVideoQuality(@IntRange(from = 0, to = 1) int quality) {
this.mQuality = quality;
return (Returner) this;
}
/**
* Set the maximum number of seconds to take video.
*
* @param duration seconds.
*/
public Returner cameraVideoLimitDuration(@IntRange(from = 1) long duration) {
this.mLimitDuration = duration;
return (Returner) this;
}
/**
* Set the maximum file size when taking video.
*
* @param bytes the size of the byte.
*/
public Returner cameraVideoLimitBytes(@IntRange(from = 1) long bytes) {
this.mLimitBytes = bytes;
return (Returner) this;
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import androidx.annotation.IntRange;
public abstract class BasicChoiceVideoWrapper<Returner extends BasicChoiceVideoWrapper, Result, Cancel, Checked> extends BasicChoiceWrapper<Returner, Result, Cancel, Checked> {
BasicChoiceVideoWrapper(Context context) {
super(context);
}
int mQuality = 1;
long mLimitDuration = Integer.MAX_VALUE;
long mLimitBytes = Integer.MAX_VALUE;
/**
* Set the quality when taking video, should be 0 or 1. Currently value 0 means low quality, and value 1 means high quality.
*
* @param quality should be 0 or 1.
*/
public Returner quality(@IntRange(from = 0, to = 1) int quality) {
this.mQuality = quality;
return (Returner) this;
}
/**
* Specify the maximum allowed recording duration in seconds.
*
* @param duration the maximum number of seconds.
*/
public Returner limitDuration(@IntRange(from = 1) long duration) {
this.mLimitDuration = duration;
return (Returner) this;
}
/**
* Specify the maximum allowed size.
*
* @param bytes the size of the byte.
*/
public Returner limitBytes(@IntRange(from = 1) long bytes) {
this.mLimitBytes = bytes;
return (Returner) this;
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import androidx.annotation.IntRange;
import com.sobot.album.Filter;
public abstract class BasicChoiceWrapper<Returner extends BasicChoiceWrapper, Result, Cancel, Checked> extends BasicAlbumWrapper<Returner, Result, Cancel, Checked> {
boolean mHasCamera = true;
int mColumnCount = 2;
Filter<Long> mSizeFilter;
Filter<String> mMimeTypeFilter;
boolean mFilterVisibility = true;
BasicChoiceWrapper(Context context) {
super(context);
}
/**
* Turn on the camera function.
*/
public Returner camera(boolean hasCamera) {
this.mHasCamera = hasCamera;
return (Returner) this;
}
/**
* Sets the number of columns for the page.
*
* @param count the number of columns.
*/
public Returner columnCount(@IntRange(from = 2, to = 4) int count) {
this.mColumnCount = count;
return (Returner) this;
}
/**
* Filter the file size.
*
* @param filter filter.
*/
public Returner filterSize(Filter<Long> filter) {
this.mSizeFilter = filter;
return (Returner) this;
}
/**
* Filter the file extension.
*
* @param filter filter.
*/
public Returner filterMimeType(Filter<String> filter) {
this.mMimeTypeFilter = filter;
return (Returner) this;
}
/**
* The visibility of the filtered file.
*
* @param visibility true is displayed, false is not displayed.
*/
public Returner afterFilterVisibility(boolean visibility) {
this.mFilterVisibility = visibility;
return (Returner) this;
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import androidx.annotation.IntRange;
import com.sobot.album.ItemAction;
import java.util.ArrayList;
public abstract class BasicGalleryWrapper<Returner extends BasicGalleryWrapper, Result, Cancel, Checked> extends BasicAlbumWrapper<Returner, ArrayList<Result>, Cancel, ArrayList<Checked>> {
ItemAction<Checked> mItemClick;
ItemAction<Checked> mItemLongClick;
int mCurrentPosition;
boolean mCheckable;
public BasicGalleryWrapper(Context context) {
super(context);
}
/**
* Set the list has been selected.
*
* @param checked the data list.
*/
public final Returner checkedList(ArrayList<Checked> checked) {
this.mChecked = checked;
return (Returner) this;
}
/**
* When the preview item is clicked.
*
* @param click action.
*/
public Returner itemClick(ItemAction<Checked> click) {
this.mItemClick = click;
return (Returner) this;
}
/**
* When the preview item is clicked long.
*
* @param longClick action.
*/
public Returner itemLongClick(ItemAction<Checked> longClick) {
this.mItemLongClick = longClick;
return (Returner) this;
}
/**
* Set the show position of List.
*
* @param currentPosition the current position.
*/
public Returner currentPosition(@IntRange(from = 0, to = Integer.MAX_VALUE) int currentPosition) {
this.mCurrentPosition = currentPosition;
return (Returner) this;
}
/**
* The ability to select pictures.
*
* @param checkable checkBox is provided.
*/
public Returner checkable(boolean checkable) {
this.mCheckable = checkable;
return (Returner) this;
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import android.content.Intent;
import com.sobot.album.AlbumFile;
import com.sobot.album.SobotAlbum;
import com.sobot.album.app.gallery.GalleryAlbumActivity;
public class GalleryAlbumWrapper extends BasicGalleryWrapper<GalleryAlbumWrapper, AlbumFile, String, AlbumFile> {
public GalleryAlbumWrapper(Context context) {
super(context);
}
@Override
public void start() {
GalleryAlbumActivity.sResult = mResult;
GalleryAlbumActivity.sCancel = mCancel;
GalleryAlbumActivity.sClick = mItemClick;
GalleryAlbumActivity.sLongClick = mItemLongClick;
Intent intent = new Intent(mContext, GalleryAlbumActivity.class);
intent.putExtra(SobotAlbum.KEY_INPUT_WIDGET, mWidget);
intent.putParcelableArrayListExtra(SobotAlbum.KEY_INPUT_CHECKED_LIST, mChecked);
intent.putExtra(SobotAlbum.KEY_INPUT_CURRENT_POSITION, mCurrentPosition);
intent.putExtra(SobotAlbum.KEY_INPUT_GALLERY_CHECKABLE, mCheckable);
mContext.startActivity(intent);
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import android.content.Intent;
import com.sobot.album.SobotAlbum;
import com.sobot.album.app.gallery.GalleryActivity;
public class GalleryWrapper extends BasicGalleryWrapper<GalleryWrapper, String, String, String> {
public GalleryWrapper(Context context) {
super(context);
}
@Override
public void start() {
GalleryActivity.sResult = mResult;
GalleryActivity.sCancel = mCancel;
GalleryActivity.sClick = mItemClick;
GalleryActivity.sLongClick = mItemLongClick;
Intent intent = new Intent(mContext, GalleryActivity.class);
intent.putExtra(SobotAlbum.KEY_INPUT_WIDGET, mWidget);
intent.putStringArrayListExtra(SobotAlbum.KEY_INPUT_CHECKED_LIST, mChecked);
intent.putExtra(SobotAlbum.KEY_INPUT_CURRENT_POSITION, mCurrentPosition);
intent.putExtra(SobotAlbum.KEY_INPUT_GALLERY_CHECKABLE, mCheckable);
mContext.startActivity(intent);
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import android.content.Intent;
import com.sobot.album.SobotAlbum;
import com.sobot.album.app.camera.CameraActivity;
/**
* <p>Camera wrapper.</p>
* Created by Yan Zhenjie on 2017/4/18.
*/
public class ImageCameraWrapper extends BasicCameraWrapper<ImageCameraWrapper> {
public ImageCameraWrapper(Context context) {
super(context);
}
public void start() {
CameraActivity.sResult = mResult;
CameraActivity.sCancel = mCancel;
Intent intent = new Intent(mContext, CameraActivity.class);
intent.putExtra(SobotAlbum.KEY_INPUT_FUNCTION, SobotAlbum.FUNCTION_CAMERA_IMAGE);
intent.putExtra(SobotAlbum.KEY_INPUT_FILE_PATH, mFilePath);
mContext.startActivity(intent);
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import android.content.Intent;
import androidx.annotation.IntRange;
import com.sobot.album.AlbumFile;
import com.sobot.album.SobotAlbum;
import com.sobot.album.app.album.AlbumActivity;
import java.util.ArrayList;
public final class ImageMultipleWrapper extends BasicChoiceWrapper<ImageMultipleWrapper, ArrayList<AlbumFile>, String, ArrayList<AlbumFile>> {
@IntRange(from = 1, to = Integer.MAX_VALUE)
private int mLimitCount = Integer.MAX_VALUE;
public ImageMultipleWrapper(Context context) {
super(context);
}
/**
* Set the list has been selected.
*
* @param checked the data list.
*/
public final ImageMultipleWrapper checkedList(ArrayList<AlbumFile> checked) {
this.mChecked = checked;
return this;
}
/**
* Set the maximum number to be selected.
*
* @param count the maximum number.
*/
public ImageMultipleWrapper selectCount(@IntRange(from = 1, to = Integer.MAX_VALUE) int count) {
this.mLimitCount = count;
return this;
}
@Override
public void start() {
AlbumActivity.sSizeFilter = mSizeFilter;
AlbumActivity.sMimeFilter = mMimeTypeFilter;
AlbumActivity.sResult = mResult;
AlbumActivity.sCancel = mCancel;
Intent intent = new Intent(mContext, AlbumActivity.class);
intent.putExtra(SobotAlbum.KEY_INPUT_WIDGET, mWidget);
intent.putParcelableArrayListExtra(SobotAlbum.KEY_INPUT_CHECKED_LIST, mChecked);
intent.putExtra(SobotAlbum.KEY_INPUT_FUNCTION, SobotAlbum.FUNCTION_CHOICE_IMAGE);
intent.putExtra(SobotAlbum.KEY_INPUT_CHOICE_MODE, SobotAlbum.MODE_MULTIPLE);
intent.putExtra(SobotAlbum.KEY_INPUT_COLUMN_COUNT, mColumnCount);
intent.putExtra(SobotAlbum.KEY_INPUT_ALLOW_CAMERA, mHasCamera);
intent.putExtra(SobotAlbum.KEY_INPUT_LIMIT_COUNT, mLimitCount);
intent.putExtra(SobotAlbum.KEY_INPUT_FILTER_VISIBILITY, mFilterVisibility);
mContext.startActivity(intent);
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import android.content.Intent;
import com.sobot.album.AlbumFile;
import com.sobot.album.SobotAlbum;
import com.sobot.album.app.album.AlbumActivity;
import java.util.ArrayList;
public final class ImageSingleWrapper extends BasicChoiceWrapper<ImageSingleWrapper, ArrayList<AlbumFile>, String, AlbumFile> {
public ImageSingleWrapper(Context context) {
super(context);
}
@Override
public void start() {
AlbumActivity.sSizeFilter = mSizeFilter;
AlbumActivity.sMimeFilter = mMimeTypeFilter;
AlbumActivity.sResult = mResult;
AlbumActivity.sCancel = mCancel;
Intent intent = new Intent(mContext, AlbumActivity.class);
intent.putExtra(SobotAlbum.KEY_INPUT_WIDGET, mWidget);
intent.putExtra(SobotAlbum.KEY_INPUT_FUNCTION, SobotAlbum.FUNCTION_CHOICE_IMAGE);
intent.putExtra(SobotAlbum.KEY_INPUT_CHOICE_MODE, SobotAlbum.MODE_SINGLE);
intent.putExtra(SobotAlbum.KEY_INPUT_COLUMN_COUNT, mColumnCount);
intent.putExtra(SobotAlbum.KEY_INPUT_ALLOW_CAMERA, mHasCamera);
intent.putExtra(SobotAlbum.KEY_INPUT_LIMIT_COUNT, 1);
intent.putExtra(SobotAlbum.KEY_INPUT_FILTER_VISIBILITY, mFilterVisibility);
mContext.startActivity(intent);
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import android.content.Intent;
import androidx.annotation.IntRange;
import com.sobot.album.SobotAlbum;
import com.sobot.album.app.camera.CameraActivity;
/**
* <p>Camera wrapper.</p>
* Created by Yan Zhenjie on 2017/4/18.
*/
public class VideoCameraWrapper extends BasicCameraWrapper<VideoCameraWrapper> {
private int mQuality = 1;
private long mLimitDuration = Integer.MAX_VALUE;
private long mLimitBytes = Integer.MAX_VALUE;
public VideoCameraWrapper(Context context) {
super(context);
}
/**
* Currently value 0 means low quality, suitable for MMS messages, and value 1 means high quality.
*
* @param quality should be 0 or 1.
*/
public VideoCameraWrapper quality(@IntRange(from = 0, to = 1) int quality) {
this.mQuality = quality;
return this;
}
/**
* Specify the maximum allowed recording duration in seconds.
*
* @param duration the maximum number of seconds.
*/
public VideoCameraWrapper limitDuration(@IntRange(from = 1) long duration) {
this.mLimitDuration = duration;
return this;
}
/**
* Specify the maximum allowed size.
*
* @param bytes the size of the byte.
*/
public VideoCameraWrapper limitBytes(@IntRange(from = 1) long bytes) {
this.mLimitBytes = bytes;
return this;
}
public void start() {
CameraActivity.sResult = mResult;
CameraActivity.sCancel = mCancel;
Intent intent = new Intent(mContext, CameraActivity.class);
intent.putExtra(SobotAlbum.KEY_INPUT_FUNCTION, SobotAlbum.FUNCTION_CAMERA_VIDEO);
intent.putExtra(SobotAlbum.KEY_INPUT_FILE_PATH, mFilePath);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_QUALITY, mQuality);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_DURATION, mLimitDuration);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_BYTES, mLimitBytes);
mContext.startActivity(intent);
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import android.content.Intent;
import androidx.annotation.IntRange;
import com.sobot.album.AlbumFile;
import com.sobot.album.Filter;
import com.sobot.album.SobotAlbum;
import com.sobot.album.app.album.AlbumActivity;
import java.util.ArrayList;
public final class VideoMultipleWrapper extends BasicChoiceVideoWrapper<VideoMultipleWrapper, ArrayList<AlbumFile>, String, ArrayList<AlbumFile>> {
private int mLimitCount = Integer.MAX_VALUE;
private Filter<Long> mDurationFilter;
public VideoMultipleWrapper(Context context) {
super(context);
}
/**
* Set the list has been selected.
*
* @param checked the data list.
*/
public final VideoMultipleWrapper checkedList(ArrayList<AlbumFile> checked) {
this.mChecked = checked;
return this;
}
/**
* Set the maximum number to be selected.
*
* @param count the maximum number.
*/
public VideoMultipleWrapper selectCount(@IntRange(from = 1, to = Integer.MAX_VALUE) int count) {
this.mLimitCount = count;
return this;
}
/**
* Filter video duration.
*
* @param filter filter.
*/
public VideoMultipleWrapper filterDuration(Filter<Long> filter) {
this.mDurationFilter = filter;
return this;
}
@Override
public void start() {
AlbumActivity.sSizeFilter = mSizeFilter;
AlbumActivity.sMimeFilter = mMimeTypeFilter;
AlbumActivity.sDurationFilter = mDurationFilter;
AlbumActivity.sResult = mResult;
AlbumActivity.sCancel = mCancel;
Intent intent = new Intent(mContext, AlbumActivity.class);
intent.putExtra(SobotAlbum.KEY_INPUT_WIDGET, mWidget);
intent.putParcelableArrayListExtra(SobotAlbum.KEY_INPUT_CHECKED_LIST, mChecked);
intent.putExtra(SobotAlbum.KEY_INPUT_FUNCTION, SobotAlbum.FUNCTION_CHOICE_VIDEO);
intent.putExtra(SobotAlbum.KEY_INPUT_CHOICE_MODE, SobotAlbum.MODE_MULTIPLE);
intent.putExtra(SobotAlbum.KEY_INPUT_COLUMN_COUNT, mColumnCount);
intent.putExtra(SobotAlbum.KEY_INPUT_ALLOW_CAMERA, mHasCamera);
intent.putExtra(SobotAlbum.KEY_INPUT_LIMIT_COUNT, mLimitCount);
intent.putExtra(SobotAlbum.KEY_INPUT_FILTER_VISIBILITY, mFilterVisibility);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_QUALITY, mQuality);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_DURATION, mLimitDuration);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_BYTES, mLimitBytes);
mContext.startActivity(intent);
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api;
import android.content.Context;
import android.content.Intent;
import com.sobot.album.AlbumFile;
import com.sobot.album.Filter;
import com.sobot.album.SobotAlbum;
import com.sobot.album.app.album.AlbumActivity;
import java.util.ArrayList;
public final class VideoSingleWrapper extends BasicChoiceVideoWrapper<VideoSingleWrapper, ArrayList<AlbumFile>, String, AlbumFile> {
private Filter<Long> mDurationFilter;
public VideoSingleWrapper(Context context) {
super(context);
}
/**
* Filter video duration.
*
* @param filter filter.
*/
public VideoSingleWrapper filterDuration(Filter<Long> filter) {
this.mDurationFilter = filter;
return this;
}
@Override
public void start() {
AlbumActivity.sSizeFilter = mSizeFilter;
AlbumActivity.sMimeFilter = mMimeTypeFilter;
AlbumActivity.sDurationFilter = mDurationFilter;
AlbumActivity.sResult = mResult;
AlbumActivity.sCancel = mCancel;
Intent intent = new Intent(mContext, AlbumActivity.class);
intent.putExtra(SobotAlbum.KEY_INPUT_WIDGET, mWidget);
intent.putExtra(SobotAlbum.KEY_INPUT_FUNCTION, SobotAlbum.FUNCTION_CHOICE_VIDEO);
intent.putExtra(SobotAlbum.KEY_INPUT_CHOICE_MODE, SobotAlbum.MODE_SINGLE);
intent.putExtra(SobotAlbum.KEY_INPUT_COLUMN_COUNT, mColumnCount);
intent.putExtra(SobotAlbum.KEY_INPUT_ALLOW_CAMERA, mHasCamera);
intent.putExtra(SobotAlbum.KEY_INPUT_LIMIT_COUNT, 1);
intent.putExtra(SobotAlbum.KEY_INPUT_FILTER_VISIBILITY, mFilterVisibility);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_QUALITY, mQuality);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_DURATION, mLimitDuration);
intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_BYTES, mLimitBytes);
mContext.startActivity(intent);
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api.camera;
import android.content.Context;
import com.sobot.album.api.ImageCameraWrapper;
import com.sobot.album.api.VideoCameraWrapper;
public class AlbumCamera implements Camera<ImageCameraWrapper, VideoCameraWrapper> {
private Context mContext;
public AlbumCamera(Context context) {
mContext = context;
}
@Override
public ImageCameraWrapper image() {
return new ImageCameraWrapper(mContext);
}
@Override
public VideoCameraWrapper video() {
return new VideoCameraWrapper(mContext);
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api.camera;
public interface Camera<Image, Video> {
/**
* Take picture.
*/
Image image();
/**
* Take video.
*/
Video video();
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api.choice;
import android.content.Context;
import com.sobot.album.api.AlbumMultipleWrapper;
import com.sobot.album.api.AlbumSingleWrapper;
public final class AlbumChoice implements Choice<AlbumMultipleWrapper, AlbumSingleWrapper> {
private Context mContext;
public AlbumChoice(Context context) {
mContext = context;
}
@Override
public AlbumMultipleWrapper multipleChoice() {
return new AlbumMultipleWrapper(mContext);
}
@Override
public AlbumSingleWrapper singleChoice() {
return new AlbumSingleWrapper(mContext);
}
}
\ No newline at end of file
package com.sobot.album.api.choice;
public interface Choice<Multiple, Single> {
/**
* Multiple choice.
*/
Multiple multipleChoice();
/**
* Single choice.
*/
Single singleChoice();
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api.choice;
import android.content.Context;
import com.sobot.album.api.ImageMultipleWrapper;
import com.sobot.album.api.ImageSingleWrapper;
public final class ImageChoice implements Choice<ImageMultipleWrapper, ImageSingleWrapper> {
private Context mContext;
public ImageChoice(Context context) {
mContext = context;
}
@Override
public ImageMultipleWrapper multipleChoice() {
return new ImageMultipleWrapper(mContext);
}
@Override
public ImageSingleWrapper singleChoice() {
return new ImageSingleWrapper(mContext);
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.api.choice;
import android.content.Context;
import com.sobot.album.api.VideoMultipleWrapper;
import com.sobot.album.api.VideoSingleWrapper;
public final class VideoChoice implements Choice<VideoMultipleWrapper, VideoSingleWrapper> {
private Context mContext;
public VideoChoice(Context context) {
mContext = context;
}
@Override
public VideoMultipleWrapper multipleChoice() {
return new VideoMultipleWrapper(mContext);
}
@Override
public VideoSingleWrapper singleChoice() {
return new VideoSingleWrapper(mContext);
}
}
\ No newline at end of file
/*
* Copyright 2018 Yan Zhenjie
*
* 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.sobot.album.app;
import android.app.Activity;
import android.content.res.Configuration;
import android.view.View;
import android.widget.CompoundButton;
import com.sobot.album.AlbumFolder;
import com.sobot.album.SobotAlbum;
import com.sobot.album.api.widget.Widget;
import com.sobot.album.mvp.BasePresenter;
import com.sobot.album.mvp.BaseView;
import java.util.List;
public final class Contract {
public interface AlbumPresenter extends BasePresenter {
/**
* Click the folder switch.
*/
void clickFolderSwitch();
/**
* Click camera.
*/
void clickCamera(View v);
/**
* Try to check item.
*
* @param button view.
* @param position position of item.
*/
void tryCheckItem(CompoundButton button, int position);
/**
* Try to preview item.
*
* @param position position of item.
*/
void tryPreviewItem(int position);
/**
* Preview the checked items.
*/
void tryPreviewChecked();
/**
* Complete.
*/
void complete();
}
public static abstract class AlbumView extends BaseView<AlbumPresenter> {
public AlbumView(Activity activity, AlbumPresenter presenter) {
super(activity, presenter);
}
/**
* Set some properties of the view.
*
* @param widget {@link Widget}.
* @param column the count of columns.
* @param hasCamera the camera is enabled.
* @param choiceMode choice mode, one of {@link SobotAlbum#FUNCTION_CHOICE_ALBUM}, {@link
* SobotAlbum#FUNCTION_CHOICE_IMAGE} or {@link SobotAlbum#FUNCTION_CHOICE_VIDEO}.
*/
public abstract void setupViews(Widget widget, int column, boolean hasCamera, int choiceMode);
/**
* Set the loading visibility.
*
* @param display true is displayed, otherwise it is not displayed.
*/
public abstract void setLoadingDisplay(boolean display);
/**
* Should be re-layout.
*
* @param newConfig config.
*/
public abstract void onConfigurationChanged(Configuration newConfig);
/**
* Set the complete menu visibility.
*
* @param display true is displayed, otherwise it is not displayed.
*/
public abstract void setCompleteDisplay(boolean display);
/**
* Bind folder.
*
* @param albumFolder {@link AlbumFolder}.
*/
public abstract void bindAlbumFolder(AlbumFolder albumFolder);
/**
* Notify item was inserted.
*
* @param position position of item.
*/
public abstract void notifyInsertItem(int position);
/**
* Notify item was changed.
*
* @param position position of item.
*/
public abstract void notifyItem(int position);
/**
* Set checked count.
*
* @param count the number of items checked.
*/
public abstract void setCheckedCount(int count);
}
public interface NullPresenter extends BasePresenter {
/**
* Take a picture.
*/
void takePicture();
/**
* Take a video.
*/
void takeVideo();
}
public static abstract class NullView extends BaseView<NullPresenter> {
public NullView(Activity activity, NullPresenter presenter) {
super(activity, presenter);
}
/**
* Set some properties of the view.
*
* @param widget {@link Widget}.
*/
public abstract void setupViews(Widget widget);
/**
* Set the message of page.
*
* @param message message.
*/
public abstract void setMessage(int message);
/**
* Set the button visibility.
*
* @param display true is displayed, otherwise it is not displayed.
*/
public abstract void setMakeImageDisplay(boolean display);
/**
* Set the button visibility.
*
* @param display true is displayed, otherwise it is not displayed.
*/
public abstract void setMakeVideoDisplay(boolean display);
}
public interface GalleryPresenter extends BasePresenter {
void clickItem(int position);
void longClickItem(int position);
/**
* Set the current position of item .
*/
void onCurrentChanged(int position);
/**
* Try to check the current item.
*/
void onCheckedChanged();
/**
* Complete.
*/
void complete();
}
public static abstract class GalleryView<Data> extends BaseView<GalleryPresenter> {
public GalleryView(Activity activity, GalleryPresenter presenter) {
super(activity, presenter);
}
/**
* Set some properties of the view.
*
* @param widget {@link Widget}.
* @param checkable show the checkbox.
*/
public abstract void setupViews(Widget widget, boolean checkable);
/**
* Bind data.
*
* @param dataList data.
*/
public abstract void bindData(List<Data> dataList);
/**
* Set the position of the item to be displayed.
*
* @param position position.
*/
public abstract void setCurrentItem(int position);
/**
* Set duration visibility.
*
* @param display true is displayed, otherwise it is not displayed.
*/
public abstract void setDurationDisplay(boolean display);
/**
* Set duration.
*
* @param duration duration.
*/
public abstract void setDuration(String duration);
/**
* Changes the checked state of this button.
*
* @param checked true to check the button, false to uncheck it.
*/
public abstract void setChecked(boolean checked);
/**
* Set bottom visibility.
*
* @param display true is displayed, otherwise it is not displayed.
*/
public abstract void setBottomDisplay(boolean display);
/**
* Set layer visibility.
*
* @param display true is displayed, otherwise it is not displayed.
*/
public abstract void setLayerDisplay(boolean display);
/**
* Set the complete button text.
*
* @param text text.
*/
public abstract void setCompleteText(String text);
public void setShowTitle(boolean previewMySelect) {
}
}
}
\ No newline at end of file
/*
* Copyright 2018 Yan Zhenjie
*
* 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.sobot.album.app.album;
import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.Color;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.sobot.album.AlbumFolder;
import com.sobot.album.R;
import com.sobot.album.api.widget.Widget;
import com.sobot.album.app.Contract;
import com.sobot.album.impl.OnCheckedClickListener;
import com.sobot.album.impl.OnItemClickListener;
import com.sobot.album.widget.divider.Api21ItemDivider;
class AlbumView extends Contract.AlbumView implements View.OnClickListener {
private Activity mActivity;
private RecyclerView mRecyclerView;
private GridLayoutManager mLayoutManager;
private AlbumAdapter mAdapter;
private TextView mBtnPreview;//预览
// 不能更改
// private TextView mBtnSwitchFolder;//更改路径
private TextView mTvOK;//确定
private TextView mTVSelect;//已选中
private LinearLayout mLayoutLoading;
private int selectCount;
private String selectText,sizeText;
public AlbumView(Activity activity, Contract.AlbumPresenter presenter) {
super(activity, presenter);
this.mActivity = activity;
selectText = mActivity.getResources().getString(R.string.sobot_select_photo_num);
sizeText = mActivity.getResources().getString(R.string.sobot_pic_siza_xiaoyu);
this.mRecyclerView = activity.findViewById(R.id.recycler_view);
// this.mBtnSwitchFolder = activity.findViewById(R.id.sobot_text_title);
this.mBtnPreview = activity.findViewById(R.id.sobot_tv_preview);
this.mTvOK = activity.findViewById(R.id.sobot_tv_add);
this.mTVSelect = activity.findViewById(R.id.sobot_tv_select);
this.mLayoutLoading = activity.findViewById(R.id.layout_loading);
// this.mBtnSwitchFolder.setOnClickListener(this);
this.mBtnPreview.setOnClickListener(this);
this.mTvOK.setOnClickListener(this);
this.mTVSelect.setOnClickListener(this);
}
@Override
protected void onCreateOptionsMenu(Menu menu) {
// getMenuInflater().inflate(R.menu.album_menu_album, menu);
// mCompleteMenu = menu.findItem(R.id.album_menu_finish);
}
@Override
protected void onOptionsItemSelected(MenuItem item) {
// int itemId = item.getItemId();
// if (itemId == R.id.album_menu_finish) {
// getPresenter().complete();
// }
}
@Override
public void setupViews(Widget widget, int column, boolean hasCamera, int choiceMode) {
/* SystemBar.setNavigationBarColor(mActivity, widget.getNavigationBarColor());
int statusBarColor = widget.getStatusBarColor();
if (widget.getUiStyle() == Widget.STYLE_LIGHT) {
if (SystemBar.setStatusBarDarkFont(mActivity, true)) {
SystemBar.setStatusBarColor(mActivity, statusBarColor);
} else {
SystemBar.setStatusBarColor(mActivity, getColor(R.color.albumColorPrimaryBlack));
}
mProgressBar.setColorFilter(getColor(R.color.albumLoadingDark));
Drawable navigationIcon = getDrawable(R.drawable.album_ic_back_white);
AlbumUtils.setDrawableTint(navigationIcon, getColor(R.color.albumIconDark));
setHomeAsUpIndicator(navigationIcon);
Drawable completeIcon = mCompleteMenu.getIcon();
AlbumUtils.setDrawableTint(completeIcon, getColor(R.color.albumIconDark));
mCompleteMenu.setIcon(completeIcon);
} else {
mProgressBar.setColorFilter(widget.getToolBarColor());
SystemBar.setStatusBarColor(mActivity, statusBarColor);
setHomeAsUpIndicator(R.drawable.album_ic_back_white);
}
mToolbar.setBackgroundColor(widget.getToolBarColor());
*/
Configuration config = mActivity.getResources().getConfiguration();
mLayoutManager = new GridLayoutManager(getContext(), column, getOrientation(config), false);
mRecyclerView.setLayoutManager(mLayoutManager);
int dividerSize = getResources().getDimensionPixelSize(R.dimen.album_dp_4);
mRecyclerView.addItemDecoration(new Api21ItemDivider(Color.TRANSPARENT, dividerSize, dividerSize));
mAdapter = new AlbumAdapter(getContext(), hasCamera, choiceMode, widget.getMediaItemCheckSelector());
mAdapter.setAddClickListener(new OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
getPresenter().clickCamera(view);
}
});
mAdapter.setCheckedClickListener(new OnCheckedClickListener() {
@Override
public void onCheckedClick(CompoundButton button, int position) {
getPresenter().tryCheckItem(button, position);
}
@Override
public void onCheckedFail() {
Toast toast = Toast.makeText(mActivity, sizeText, Toast.LENGTH_LONG);
// 可以控制toast显示的位置
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 10);
toast.show();
}
});
mAdapter.setItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
getPresenter().tryPreviewItem(position);
}
});
mRecyclerView.setAdapter(mAdapter);
}
@Override
public void setLoadingDisplay(boolean display) {
mLayoutLoading.setVisibility(display ? View.VISIBLE : View.GONE);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
int position = mLayoutManager.findFirstVisibleItemPosition();
mLayoutManager.setOrientation(getOrientation(newConfig));
mRecyclerView.setAdapter(mAdapter);
mLayoutManager.scrollToPosition(position);
}
@RecyclerView.Orientation
private int getOrientation(Configuration config) {
switch (config.orientation) {
case Configuration.ORIENTATION_PORTRAIT: {
return LinearLayoutManager.VERTICAL;
}
case Configuration.ORIENTATION_LANDSCAPE: {
return LinearLayoutManager.HORIZONTAL;
}
default: {
throw new AssertionError("This should not be the case.");
}
}
}
@Override
public void setCompleteDisplay(boolean display) {
// mCompleteMenu.setVisible(display);
}
@Override
public void bindAlbumFolder(AlbumFolder albumFolder) {
// mBtnSwitchFolder.setText(albumFolder.getName());
mAdapter.setAlbumFiles(albumFolder.getAlbumFiles());
mAdapter.notifyDataSetChanged();
mRecyclerView.scrollToPosition(0);
}
@Override
public void notifyInsertItem(int position) {
mAdapter.notifyItemInserted(position);
}
@Override
public void notifyItem(int position) {
mAdapter.notifyItemChanged(position);
}
@Override
public void setCheckedCount(int count) {
selectCount = count;
String sCount = String.valueOf(count);
String text = String.format(selectText,sCount);
SpannableStringBuilder ssp = new SpannableStringBuilder(text);
ssp.setSpan(new ForegroundColorSpan(mActivity.getResources().getColor(R.color.sobot_color)),text.indexOf(sCount),text.indexOf(sCount)+sCount.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mTVSelect.setText(ssp);
if(count == 0){
mTvOK.setBackgroundResource(R.drawable.sobot_bg_theme_unable_4dp);
}else {
mTvOK.setBackgroundResource(R.drawable.sobot_bg_theme_color_4dp);
}
}
@Override
public void onClick(View v) {
if (v == mTvOK) {
if(selectCount>0) {
getPresenter().complete();
}
// } else if (v == mBtnSwitchFolder) {
// getPresenter().clickFolderSwitch();
} else if (v == mBtnPreview) {
getPresenter().tryPreviewChecked();
}
}
}
\ No newline at end of file
/*
* Copyright 2016 Yan Zhenjie.
*
* 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.sobot.album.app.album;
import android.content.Context;
import android.content.res.ColorStateList;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.widget.AppCompatRadioButton;
import androidx.recyclerview.widget.RecyclerView;
import com.sobot.album.AlbumFile;
import com.sobot.album.AlbumFolder;
import com.sobot.album.R;
import com.sobot.album.SobotAlbum;
import com.sobot.album.impl.OnItemClickListener;
import java.util.List;
class FolderAdapter extends RecyclerView.Adapter<FolderAdapter.FolderViewHolder> {
private LayoutInflater mInflater;
private List<AlbumFolder> mAlbumFolders;
private ColorStateList mSelector;
private Context mContext;
private OnItemClickListener mItemClickListener;
public FolderAdapter(Context context, List<AlbumFolder> mAlbumFolders, ColorStateList buttonTint) {
this.mContext = context;
this.mInflater = LayoutInflater.from(context);
this.mSelector = buttonTint;
this.mAlbumFolders = mAlbumFolders;
}
public void setItemClickListener(OnItemClickListener itemClickListener) {
this.mItemClickListener = itemClickListener;
}
@Override
public FolderViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new FolderViewHolder(mContext, mInflater.inflate(R.layout.album_item_dialog_folder, parent, false),
mSelector,
new OnItemClickListener() {
private int oldPosition = 0;
@Override
public void onItemClick(View view, int position) {
if (mItemClickListener != null)
mItemClickListener.onItemClick(view, position);
AlbumFolder albumFolder = mAlbumFolders.get(position);
if (!albumFolder.isChecked()) {
albumFolder.setChecked(true);
mAlbumFolders.get(oldPosition).setChecked(false);
notifyItemChanged(oldPosition);
notifyItemChanged(position);
oldPosition = position;
}
}
});
}
@Override
public void onBindViewHolder(FolderViewHolder holder, int position) {
final int newPosition = holder.getAdapterPosition();
holder.setData(mAlbumFolders.get(newPosition));
}
@Override
public int getItemCount() {
return mAlbumFolders == null ? 0 : mAlbumFolders.size();
}
static class FolderViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private OnItemClickListener mItemClickListener;
private ImageView mIvImage;
private TextView mTvTitle;
private AppCompatRadioButton mCheckBox;
private Context mContext;
private FolderViewHolder(Context context, View itemView, ColorStateList selector, OnItemClickListener itemClickListener) {
super(itemView);
this.mContext = context;
this.mItemClickListener = itemClickListener;
mIvImage = itemView.findViewById(R.id.iv_gallery_preview_image);
mTvTitle = itemView.findViewById(R.id.tv_gallery_preview_title);
mCheckBox = itemView.findViewById(R.id.rb_gallery_preview_check);
itemView.setOnClickListener(this);
}
public void setData(AlbumFolder albumFolder) {
List<AlbumFile> albumFiles = albumFolder.getAlbumFiles();
mTvTitle.setText("(" + albumFiles.size() + ") " + albumFolder.getName());
mCheckBox.setChecked(albumFolder.isChecked());
SobotAlbum.getAlbumConfig().getAlbumLoader().load(mIvImage, albumFiles.get(0));
}
@Override
public void onClick(View v) {
if (mItemClickListener != null)
mItemClickListener.onItemClick(v, getAdapterPosition());
}
}
}
\ No newline at end of file
/*
* Copyright 2016 Yan Zhenjie.
*
* 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.sobot.album.app.album;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.Window;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.sobot.album.AlbumFolder;
import com.sobot.album.R;
import com.sobot.album.api.widget.Widget;
import com.sobot.album.impl.OnItemClickListener;
import java.util.List;
/**
* <p>Folder preview.</p>
* Created by Yan Zhenjie on 2016/10/18.
*/
public class FolderDialog extends BottomSheetDialog {
private Widget mWidget;
private FolderAdapter mFolderAdapter;
private List<AlbumFolder> mAlbumFolders;
private int mCurrentPosition = 0;
private OnItemClickListener mItemClickListener;
public FolderDialog(Context context, Widget widget, List<AlbumFolder> albumFolders, OnItemClickListener itemClickListener) {
super(context, R.style.Album_Dialog_Folder);
setContentView(R.layout.album_dialog_floder);
this.mWidget = widget;
this.mAlbumFolders = albumFolders;
this.mItemClickListener = itemClickListener;
RecyclerView recyclerView = getDelegate().findViewById(R.id.rv_content_list);
assert recyclerView != null;
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mFolderAdapter = new FolderAdapter(context, mAlbumFolders, widget.getBucketItemCheckSelector());
mFolderAdapter.setItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(final View view, final int position) {
if (mCurrentPosition != position) {
mAlbumFolders.get(mCurrentPosition).setChecked(false);
mFolderAdapter.notifyItemChanged(mCurrentPosition);
mCurrentPosition = position;
mAlbumFolders.get(mCurrentPosition).setChecked(true);
mFolderAdapter.notifyItemChanged(mCurrentPosition);
if (mItemClickListener != null) {
mItemClickListener.onItemClick(view, position);
}
}
dismiss();
}
});
recyclerView.setAdapter(mFolderAdapter);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window window = getWindow();
if (window != null) {
Display display = window.getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
if (Build.VERSION.SDK_INT >= 17) display.getRealMetrics(metrics);
else display.getMetrics(metrics);
int minSize = Math.min(metrics.widthPixels, metrics.heightPixels);
window.setLayout(minSize, -1);
if (Build.VERSION.SDK_INT >= 21) {
window.setStatusBarColor(Color.TRANSPARENT);
window.setNavigationBarColor(mWidget.getNavigationBarColor());
}
}
}
}
\ No newline at end of file
/*
* Copyright 2017 Yan Zhenjie.
*
* 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.sobot.album.app.album;
import android.os.Bundle;
import androidx.annotation.Nullable;
import com.sobot.album.AlbumFile;
import com.sobot.album.R;
import com.sobot.album.SobotAlbum;
import com.sobot.album.api.widget.Widget;
import com.sobot.album.app.Contract;
import com.sobot.album.app.gallery.GalleryView;
import com.sobot.album.util.AlbumUtils;
import com.sobot.widget.ui.base.SobotBaseActivity;
import java.util.ArrayList;
/**
* <p>Preview the pictures in the folder in enlarged form.</p>
* Created by Yan Zhenjie on 2017/3/25.
* 预览
*/
public class GalleryActivity extends SobotBaseActivity implements Contract.GalleryPresenter {
public static ArrayList<AlbumFile> sAlbumFiles;
public static int sCheckedCount;
public static int sCurrentPosition;
public static Callback sCallback;
public static boolean previewMySelect;
private Widget mWidget;
private int mFunction;
private int mAllowSelectCount;
private Contract.GalleryView<AlbumFile> mView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
changeAppLanguage();
super.onCreate(savedInstanceState);
}
@Override
protected int getContentViewResId() {
return R.layout.sobot_activity_album_gallery;
}
@Override
protected void initView() throws InterruptedException {
mView = new GalleryView<>(this, getSupportFragmentManager(),this);
Bundle argument = getIntent().getExtras();
assert argument != null;
mWidget = argument.getParcelable(SobotAlbum.KEY_INPUT_WIDGET);
mFunction = argument.getInt(SobotAlbum.KEY_INPUT_FUNCTION);
mAllowSelectCount = argument.getInt(SobotAlbum.KEY_INPUT_LIMIT_COUNT);
mView.setShowTitle(previewMySelect);
mView.setupViews(mWidget, true);
mView.bindData(sAlbumFiles);
if (sCurrentPosition == 0) {
onCurrentChanged(sCurrentPosition);
} else {
mView.setCurrentItem(sCurrentPosition);
}
setCheckedCount();
}
@Override
protected void initData() {
}
private void setCheckedCount() {
//显示已选
mView.setCompleteText(String.valueOf(sCheckedCount));
}
@Override
public void clickItem(int position) {
}
@Override
public void longClickItem(int position) {
}
@Override
public void onCurrentChanged(int position) {
sCurrentPosition = position;
mView.setTitle(sCurrentPosition + 1 + " / " + sAlbumFiles.size());
AlbumFile albumFile = sAlbumFiles.get(position);
mView.setChecked(albumFile.isChecked());
mView.setLayerDisplay(albumFile.isDisable());
if (albumFile.getMediaType() == AlbumFile.TYPE_VIDEO) {
mView.setDuration(AlbumUtils.convertDuration(albumFile.getDuration()));
mView.setDurationDisplay(true);
} else {
mView.setDurationDisplay(false);
}
}
@Override
public void onCheckedChanged() {
AlbumFile albumFile = sAlbumFiles.get(sCurrentPosition);
if (albumFile.isChecked()) {
albumFile.setChecked(false);
sCallback.onPreviewChanged(albumFile);
sCheckedCount--;
} else {
if (sCheckedCount >= mAllowSelectCount) {
int messageRes;
switch (mFunction) {
case SobotAlbum.FUNCTION_CHOICE_IMAGE: {
messageRes = R.plurals.album_check_image_limit;
break;
}
case SobotAlbum.FUNCTION_CHOICE_VIDEO: {
messageRes = R.plurals.album_check_video_limit;
break;
}
case SobotAlbum.FUNCTION_CHOICE_ALBUM: {
messageRes = R.plurals.album_check_album_limit;
break;
}
default: {
throw new AssertionError("This should not be the case.");
}
}
mView.toast(getResources().getQuantityString(messageRes, mAllowSelectCount, mAllowSelectCount));
mView.setChecked(false);
} else if(albumFile.getSize()>= 50 * 1024 * 1024){
mView.toast(getResources().getString(R.string.sobot_pic_siza_xiaoyu) );
mView.setChecked(false);
} else {
albumFile.setChecked(true);
sCallback.onPreviewChanged(albumFile);
sCheckedCount++;
}
}
setCheckedCount();
}
@Override
public void complete() {
if (sCheckedCount == 0) {
int messageRes;
switch (mFunction) {
case SobotAlbum.FUNCTION_CHOICE_IMAGE: {
messageRes = R.string.sobot_album_check_image_little;
break;
}
case SobotAlbum.FUNCTION_CHOICE_VIDEO: {
messageRes = R.string.sobot_album_check_video_little;
break;
}
case SobotAlbum.FUNCTION_CHOICE_ALBUM: {
messageRes = R.string.sobot_album_check_album_little;
break;
}
default: {
throw new AssertionError("This should not be the case.");
}
}
mView.toast(messageRes);
} else {
sCallback.onPreviewComplete();
finish();
}
}
@Override
public void onBackPressed() {
finish();
}
@Override
public void finish() {
sAlbumFiles = null;
sCheckedCount = 0;
sCurrentPosition = 0;
sCallback = null;
super.finish();
}
@Override
public void bye() {
}
public interface Callback {
/**
* Complete the preview.
*/
void onPreviewComplete();
/**
* Check or uncheck a item.
*
* @param albumFile target item.
*/
void onPreviewChanged(AlbumFile albumFile);
}
}
\ No newline at end of file
package com.sobot.album.app.album;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import com.sobot.album.Action;
import com.sobot.album.R;
import com.sobot.album.SobotAlbum;
import com.sobot.album.api.widget.Widget;
import com.sobot.album.app.Contract;
import com.sobot.album.mvp.SobotAlbumBaseActivity;
public class NullActivity extends SobotAlbumBaseActivity implements Contract.NullPresenter {
private static final String KEY_OUTPUT_IMAGE_PATH = "KEY_OUTPUT_IMAGE_PATH";
public static String parsePath(Intent intent) {
return intent.getStringExtra(KEY_OUTPUT_IMAGE_PATH);
}
private Widget mWidget;
private int mQuality = 1;
private long mLimitDuration;
private long mLimitBytes;
private Contract.NullView mView;
@Override
protected int getContentViewResId() {
return R.layout.album_activity_null;
}
@Override
protected void initView() throws InterruptedException {
mView = new NullView(this, this);
Bundle argument = getIntent().getExtras();
assert argument != null;
int function = argument.getInt(SobotAlbum.KEY_INPUT_FUNCTION);
boolean hasCamera = argument.getBoolean(SobotAlbum.KEY_INPUT_ALLOW_CAMERA);
mQuality = argument.getInt(SobotAlbum.KEY_INPUT_CAMERA_QUALITY);
mLimitDuration = argument.getLong(SobotAlbum.KEY_INPUT_CAMERA_DURATION);
mLimitBytes = argument.getLong(SobotAlbum.KEY_INPUT_CAMERA_BYTES);
mWidget = argument.getParcelable(SobotAlbum.KEY_INPUT_WIDGET);
mView.setupViews(mWidget);
mView.setTitle(mWidget.getTitle());
switch (function) {
case SobotAlbum.FUNCTION_CHOICE_IMAGE: {
mView.setMessage(R.string.album_not_found_image);
mView.setMakeVideoDisplay(false);
break;
}
case SobotAlbum.FUNCTION_CHOICE_VIDEO: {
mView.setMessage(R.string.album_not_found_video);
mView.setMakeImageDisplay(false);
break;
}
case SobotAlbum.FUNCTION_CHOICE_ALBUM: {
mView.setMessage(R.string.album_not_found_album);
break;
}
default: {
throw new AssertionError("This should not be the case.");
}
}
if (!hasCamera) {
mView.setMakeImageDisplay(false);
mView.setMakeVideoDisplay(false);
}
}
@Override
protected void initData() {
}
@Override
public void takePicture() {
SobotAlbum.camera(this)
.image()
.onResult(mCameraAction)
.start();
}
@Override
public void takeVideo() {
SobotAlbum.camera(this)
.video()
.quality(mQuality)
.limitDuration(mLimitDuration)
.limitBytes(mLimitBytes)
.onResult(mCameraAction)
.start();
}
private Action<String> mCameraAction = new Action<String>() {
@Override
public void onAction(@NonNull String result) {
Intent intent = new Intent();
intent.putExtra(KEY_OUTPUT_IMAGE_PATH, result);
setResult(RESULT_OK, intent);
finish();
}
};
}
\ No newline at end of file
/*
* Copyright 2018 Yan Zhenjie
*
* 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.sobot.album.app.album;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.sobot.album.R;
import com.sobot.album.api.widget.Widget;
import com.sobot.album.app.Contract;
import com.sobot.album.util.AlbumUtils;
class NullView extends Contract.NullView implements View.OnClickListener {
private Activity mActivity;
// private Toolbar mToolbar;
private TextView mTvMessage;
private Button mBtnTakeImage;
private Button mBtnTakeVideo;
public NullView(Activity activity, Contract.NullPresenter presenter) {
super(activity, presenter);
this.mActivity = activity;
// this.mToolbar = activity.findViewById(R.id.toolbar);
this.mTvMessage = activity.findViewById(R.id.tv_message);
this.mBtnTakeImage = activity.findViewById(R.id.btn_camera_image);
this.mBtnTakeVideo = activity.findViewById(R.id.btn_camera_video);
this.mBtnTakeImage.setOnClickListener(this);
this.mBtnTakeVideo.setOnClickListener(this);
}
@Override
public void setupViews(Widget widget) {
// mToolbar.setBackgroundColor(widget.getToolBarColor());
// int statusBarColor = widget.getStatusBarColor();
// Drawable navigationIcon = getDrawable(R.drawable.album_ic_back_white);
// if (widget.getUiStyle() == Widget.STYLE_LIGHT) {
// if (SystemBar.setStatusBarDarkFont(mActivity, true)) {
// SystemBar.setStatusBarColor(mActivity, statusBarColor);
// } else {
// SystemBar.setStatusBarColor(mActivity, getColor(R.color.albumColorPrimaryBlack));
// }
//
// AlbumUtils.setDrawableTint(navigationIcon, getColor(R.color.albumIconDark));
// setHomeAsUpIndicator(navigationIcon);
// } else {
// SystemBar.setStatusBarColor(mActivity, statusBarColor);
// setHomeAsUpIndicator(navigationIcon);
// }
// SystemBar.setNavigationBarColor(mActivity, widget.getNavigationBarColor());
Widget.ButtonStyle buttonStyle = widget.getButtonStyle();
// ColorStateList buttonSelector = buttonStyle.getButtonSelector();
// mBtnTakeImage.setSupportBackgroundTintList(buttonSelector);
// mBtnTakeVideo.setSupportBackgroundTintList(buttonSelector);
if (buttonStyle.getUiStyle() == Widget.STYLE_LIGHT) {
Drawable drawable = mBtnTakeImage.getCompoundDrawables()[0];
AlbumUtils.setDrawableTint(drawable, getColor(R.color.albumIconDark));
mBtnTakeImage.setCompoundDrawables(drawable, null, null, null);
drawable = mBtnTakeVideo.getCompoundDrawables()[0];
AlbumUtils.setDrawableTint(drawable, getColor(R.color.albumIconDark));
mBtnTakeVideo.setCompoundDrawables(drawable, null, null, null);
mBtnTakeImage.setTextColor(getColor(R.color.albumFontDark));
mBtnTakeVideo.setTextColor(getColor(R.color.albumFontDark));
}
}
@Override
public void setMessage(int message) {
mTvMessage.setText(message);
}
@Override
public void setMakeImageDisplay(boolean display) {
mBtnTakeImage.setVisibility(display ? View.VISIBLE : View.GONE);
}
@Override
public void setMakeVideoDisplay(boolean display) {
mBtnTakeVideo.setVisibility(display ? View.VISIBLE : View.GONE);
}
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.btn_camera_image) {
getPresenter().takePicture();
} else if (id == R.id.btn_camera_video) {
getPresenter().takeVideo();
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment