|
|
|
@ -1,53 +1,25 @@
|
|
|
|
|
package com.xypower.mpremote;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
|
|
|
|
|
|
import android.content.ContentUris;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.res.Configuration;
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.graphics.Typeface;
|
|
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
import android.net.wifi.ScanResult;
|
|
|
|
|
import android.net.wifi.WifiInfo;
|
|
|
|
|
import android.net.wifi.WifiManager;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.os.Environment;
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.os.Looper;
|
|
|
|
|
import android.provider.MediaStore;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.view.WindowInsets;
|
|
|
|
|
import android.widget.SimpleAdapter;
|
|
|
|
|
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.AppUtils;
|
|
|
|
|
import com.xypower.mpremote.utils.FileUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class ImageActivity extends AppCompatActivity implements View.OnClickListener {
|
|
|
|
|
private String mSerialNo = "";
|
|
|
|
@ -76,22 +48,25 @@ public class ImageActivity extends AppCompatActivity implements View.OnClickList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initView() {
|
|
|
|
|
// binding.imageView.setImageDrawable(null);
|
|
|
|
|
// binding.imageView.setClickable(true);
|
|
|
|
|
// binding.imageView.setOnClickListener(this);
|
|
|
|
|
// if (path != null) {
|
|
|
|
|
// loadImage(path);
|
|
|
|
|
// }
|
|
|
|
|
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() {
|
|
|
|
|
|
|
|
|
|
// 在Activity或Fragment中
|
|
|
|
|
// getPicList();
|
|
|
|
|
loadPhotos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadPhotos() {
|
|
|
|
|
List<String> imageFiles = FileUtils.getImageFiles(photodirpath);
|
|
|
|
|
mAdapter.setItemList(imageFiles);
|
|
|
|
|
}
|
|
|
|
@ -102,21 +77,12 @@ public class ImageActivity extends AppCompatActivity implements View.OnClickList
|
|
|
|
|
// String relativePath = Environment.DIRECTORY_PICTURES + "/" + Constants.PACKAGE_NAME_MPREMOTE + "/";
|
|
|
|
|
String relativePath = photodirpath;
|
|
|
|
|
|
|
|
|
|
String[] projection = {
|
|
|
|
|
MediaStore.Images.Media._ID,
|
|
|
|
|
MediaStore.Images.Media.DISPLAY_NAME
|
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
);
|
|
|
|
|
Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, null);
|
|
|
|
|
|
|
|
|
|
List<String> imageList = new ArrayList<>();
|
|
|
|
|
if (cursor != null) {
|
|
|
|
@ -126,8 +92,7 @@ public class ImageActivity extends AppCompatActivity implements View.OnClickList
|
|
|
|
|
while (cursor.moveToNext()) {
|
|
|
|
|
long id = cursor.getLong(idColumn);
|
|
|
|
|
String name = cursor.getString(nameColumn);
|
|
|
|
|
Uri contentUri = ContentUris.withAppendedId(
|
|
|
|
|
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);
|
|
|
|
|
Uri contentUri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);
|
|
|
|
|
|
|
|
|
|
imageList.add(name);
|
|
|
|
|
}
|
|
|
|
@ -137,40 +102,6 @@ public class ImageActivity extends AppCompatActivity implements View.OnClickList
|
|
|
|
|
Log.e("dfsdaf", imageList.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
|
// 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 Drawable loadDrawable(String file) {
|
|
|
|
|
if (file == null || file.isEmpty()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Drawable drawable = null;
|
|
|
|
|
try {
|
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeFile(file);
|
|
|
|
|
drawable = new BitmapDrawable(getResources(), bitmap);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return drawable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void loadAllImages() {
|
|
|
|
|
File localDevicePath = new File(getFilesDir(), "Photos" + File.separator + mSerialNo);
|
|
|
|
@ -185,6 +116,9 @@ public class ImageActivity extends AppCompatActivity implements View.OnClickList
|
|
|
|
|
case R.id.back:
|
|
|
|
|
finish();
|
|
|
|
|
break;
|
|
|
|
|
case R.id.refresh:
|
|
|
|
|
loadPhotos();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|