|
|
|
@ -41,6 +41,7 @@ import android.widget.TextView;
|
|
|
|
|
import com.xypower.mpremote.adapter.ImageItemAdapter;
|
|
|
|
|
import com.xypower.mpremote.adapter.ItemAdapter;
|
|
|
|
|
import com.xypower.mpremote.databinding.ActivityImageBinding;
|
|
|
|
|
import com.xypower.mpremote.utils.FileUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
@ -49,22 +50,12 @@ import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class ImageActivity extends AppCompatActivity implements View.OnClickListener {
|
|
|
|
|
private static final boolean AUTO_HIDE = true;
|
|
|
|
|
|
|
|
|
|
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
|
|
|
|
|
|
|
|
|
|
private static final int UI_ANIMATION_DELAY = 300;
|
|
|
|
|
private final Handler mHideHandler = new Handler(Looper.myLooper());
|
|
|
|
|
|
|
|
|
|
private String mSerialNo = "";
|
|
|
|
|
|
|
|
|
|
private List<File> mImageFiles = new ArrayList<>();
|
|
|
|
|
private ImageItemAdapter mAdapter;
|
|
|
|
|
private List<Map<String, Object>> mItems = new ArrayList<Map<String, Object>>();
|
|
|
|
|
|
|
|
|
|
private ActivityImageBinding binding;
|
|
|
|
|
private String path;//图片地址
|
|
|
|
|
private String cmdid;
|
|
|
|
|
private String photodirpath;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
@ -80,16 +71,17 @@ public class ImageActivity extends AppCompatActivity implements View.OnClickList
|
|
|
|
|
private void initIntent() {
|
|
|
|
|
Intent intent = getIntent();
|
|
|
|
|
path = intent.getStringExtra("path");
|
|
|
|
|
photodirpath = intent.getStringExtra("photodirpath");
|
|
|
|
|
cmdid = intent.getStringExtra("cmdid");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initView() {
|
|
|
|
|
binding.imageView.setImageDrawable(null);
|
|
|
|
|
binding.imageView.setClickable(true);
|
|
|
|
|
binding.imageView.setOnClickListener(this);
|
|
|
|
|
if (path != null) {
|
|
|
|
|
loadImage(path);
|
|
|
|
|
}
|
|
|
|
|
// binding.imageView.setImageDrawable(null);
|
|
|
|
|
// binding.imageView.setClickable(true);
|
|
|
|
|
// binding.imageView.setOnClickListener(this);
|
|
|
|
|
// if (path != null) {
|
|
|
|
|
// loadImage(path);
|
|
|
|
|
// }
|
|
|
|
|
mAdapter = new ImageItemAdapter();
|
|
|
|
|
// mAdapter.setOnClickListener(this);
|
|
|
|
|
binding.recyclerView.setAdapter(mAdapter);
|
|
|
|
@ -99,13 +91,16 @@ public class ImageActivity extends AppCompatActivity implements View.OnClickList
|
|
|
|
|
private void initData() {
|
|
|
|
|
|
|
|
|
|
// 在Activity或Fragment中
|
|
|
|
|
getPicList();
|
|
|
|
|
// getPicList();
|
|
|
|
|
List<String> imageFiles = FileUtils.getImageFiles(photodirpath);
|
|
|
|
|
mAdapter.setItemList(imageFiles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取文件夹下所有的照片
|
|
|
|
|
private void getPicList() {
|
|
|
|
|
// 获取应用专属目录的相对路径
|
|
|
|
|
String relativePath = Environment.DIRECTORY_PICTURES + "/" + Constants.PACKAGE_NAME_MPREMOTE + "/";
|
|
|
|
|
// String relativePath = Environment.DIRECTORY_PICTURES + "/" + Constants.PACKAGE_NAME_MPREMOTE + "/";
|
|
|
|
|
String relativePath = photodirpath;
|
|
|
|
|
|
|
|
|
|
String[] projection = {
|
|
|
|
|
MediaStore.Images.Media._ID,
|
|
|
|
@ -145,21 +140,21 @@ public class ImageActivity extends AppCompatActivity implements View.OnClickList
|
|
|
|
|
@Override
|
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
|
binding.imageView.requestLayout();
|
|
|
|
|
// binding.imageView.requestLayout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean loadImage(String path) {
|
|
|
|
|
binding.imageView.setImageDrawable(null);
|
|
|
|
|
File file = new File(path);
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
Drawable drawable = loadDrawable(path);
|
|
|
|
|
if (drawable != null) {
|
|
|
|
|
binding.imageView.setImageDrawable(drawable);
|
|
|
|
|
}
|
|
|
|
|
return drawable != null;
|
|
|
|
|
}
|
|
|
|
|
// private boolean loadImage(String path) {
|
|
|
|
|
// binding.imageView.setImageDrawable(null);
|
|
|
|
|
// File file = new File(path);
|
|
|
|
|
// if (!file.exists()) {
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// Drawable drawable = loadDrawable(path);
|
|
|
|
|
// if (drawable != null) {
|
|
|
|
|
// binding.imageView.setImageDrawable(drawable);
|
|
|
|
|
// }
|
|
|
|
|
// return drawable != null;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
private Drawable loadDrawable(String file) {
|
|
|
|
|
if (file == null || file.isEmpty()) {
|
|
|
|
@ -187,7 +182,7 @@ public class ImageActivity extends AppCompatActivity implements View.OnClickList
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
switch (v.getId()) {
|
|
|
|
|
case R.id.imageView:
|
|
|
|
|
case R.id.back:
|
|
|
|
|
finish();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|