You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
4.0 KiB
Java
127 lines
4.0 KiB
Java
package com.xypower.mpremote;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import android.content.ContentUris;
|
|
import android.content.Intent;
|
|
import android.database.Cursor;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.provider.MediaStore;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
|
|
import com.xypower.mpremote.adapter.ImageItemAdapter;
|
|
import com.xypower.mpremote.databinding.ActivityImageBinding;
|
|
import com.xypower.mpremote.utils.AppUtils;
|
|
import com.xypower.mpremote.utils.FileUtils;
|
|
|
|
import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class ImageActivity extends AppCompatActivity implements View.OnClickListener {
|
|
private String mSerialNo = "";
|
|
private ImageItemAdapter mAdapter;
|
|
private ActivityImageBinding binding;
|
|
private String path;//图片地址
|
|
private String cmdid;
|
|
private String photodirpath;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
binding = ActivityImageBinding.inflate(getLayoutInflater());
|
|
setContentView(binding.getRoot());
|
|
initIntent();
|
|
initView();
|
|
initData();
|
|
}
|
|
|
|
|
|
private void initIntent() {
|
|
Intent intent = getIntent();
|
|
path = intent.getStringExtra("path");
|
|
photodirpath = intent.getStringExtra("photodirpath");
|
|
cmdid = intent.getStringExtra("cmdid");
|
|
}
|
|
|
|
private void initView() {
|
|
String versionName = AppUtils.getAppNameWithVersion(this);
|
|
binding.toolbar.title.setText(versionName);
|
|
binding.toolbar.refresh.setVisibility(View.VISIBLE);
|
|
binding.toolbar.back.setOnClickListener(this);
|
|
binding.toolbar.refresh.setOnClickListener(this);
|
|
mAdapter = new ImageItemAdapter();
|
|
// mAdapter.setOnClickListener(this);
|
|
binding.recyclerView.setAdapter(mAdapter);
|
|
binding.recyclerView.setHasFixedSize(true);
|
|
binding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
|
|
|
}
|
|
|
|
private void initData() {
|
|
// getPicList();
|
|
loadPhotos();
|
|
}
|
|
|
|
private void loadPhotos() {
|
|
List<String> imageFiles = FileUtils.getImageFiles(photodirpath);
|
|
mAdapter.setItemList(imageFiles);
|
|
}
|
|
|
|
//获取文件夹下所有的照片
|
|
private void getPicList() {
|
|
// 获取应用专属目录的相对路径
|
|
// String relativePath = Environment.DIRECTORY_PICTURES + "/" + Constants.PACKAGE_NAME_MPREMOTE + "/";
|
|
String relativePath = photodirpath;
|
|
|
|
String[] projection = {MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME};
|
|
|
|
String selection = MediaStore.Images.Media.RELATIVE_PATH + " = ?";
|
|
String[] selectionArgs = new String[]{relativePath};
|
|
|
|
Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, null);
|
|
|
|
List<String> imageList = new ArrayList<>();
|
|
if (cursor != null) {
|
|
int idColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
|
|
int nameColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME);
|
|
|
|
while (cursor.moveToNext()) {
|
|
long id = cursor.getLong(idColumn);
|
|
String name = cursor.getString(nameColumn);
|
|
Uri contentUri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);
|
|
|
|
imageList.add(name);
|
|
}
|
|
cursor.close();
|
|
}
|
|
|
|
Log.e("dfsdaf", imageList.toString());
|
|
}
|
|
|
|
|
|
protected void loadAllImages() {
|
|
File localDevicePath = new File(getFilesDir(), "Photos" + File.separator + mSerialNo);
|
|
if (!localDevicePath.exists()) {
|
|
localDevicePath.mkdirs();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
switch (v.getId()) {
|
|
case R.id.back:
|
|
finish();
|
|
break;
|
|
case R.id.refresh:
|
|
loadPhotos();
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
} |