android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 30
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'me.luzhuo.java.android:lib_image_select:1.0.6-SNAPSHOT'
implementation this.rootProject.depsLibs.glide
implementation this.rootProject.depsLibs.constraintlayout
implementation this.rootProject.depsLibs.cardview
implementation this.rootProject.depsLibs.recyclerview
}
1. 图片选择
public class MainActivity extends AppCompatActivity {
ImageSelectManager manager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
manager = new ImageSelectManager(this)
.original(true)
.onSetCallbackListener(new SelectCallBack() {
@Override
public void onSelect(List<FileBean> datas) {
for (FileBean data : datas) {
Log.e("TAG", "" + data.getPath());
Log.e("TAG", "" + data.duration);
}
}
@Override
public void onCancel() {
System.out.println();
}
});
}
public void onClick(View view) {
// manager.openImage(3);
// manager.openVideo(3);
manager.openAll(3);
// manager.openHeaderImage();
}
}
2. 图片列表选择
public class GridActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ui_activity_recyclerview);
RecyclerView rev = findViewById(R.id.rev);
rev.setLayoutManager(new GridLayoutManager(this, 3));
ImageSelectAdapter adapter = new ImageSelectAdapter(this, Type.ALL, 9);
rev.setAdapter(adapter);
adapter.setOnSelectListener(new AdapterSelectListener() {
@Override
public void onSelect() {
Log.e("GridActivity", "选择了图片");
}
});
}
}