|
|
|
@ -4,24 +4,32 @@ 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;
|
|
|
|
@ -30,6 +38,8 @@ 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 java.io.File;
|
|
|
|
@ -38,86 +48,98 @@ import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An example full-screen activity that shows and hides the system UI (i.e.
|
|
|
|
|
* status bar and navigation/system bar) with user interaction.
|
|
|
|
|
*/
|
|
|
|
|
public class ImageActivity extends AppCompatActivity {
|
|
|
|
|
/**
|
|
|
|
|
* Whether or not the system UI should be auto-hidden after
|
|
|
|
|
* {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
|
|
|
|
|
*/
|
|
|
|
|
public class ImageActivity extends AppCompatActivity implements View.OnClickListener {
|
|
|
|
|
private static final boolean AUTO_HIDE = true;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
|
|
|
|
|
* user interaction before hiding the system UI.
|
|
|
|
|
*/
|
|
|
|
|
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Some older devices needs a small delay between UI widget updates
|
|
|
|
|
* and a change of the status and navigation bar.
|
|
|
|
|
*/
|
|
|
|
|
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 ImagesAdaper mAdapter;
|
|
|
|
|
private ImageItemAdapter mAdapter;
|
|
|
|
|
private List<Map<String, Object>> mItems = new ArrayList<Map<String, Object>>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Touch listener to use for in-layout UI controls to delay hiding the
|
|
|
|
|
* system UI. This is to prevent the jarring behavior of controls going away
|
|
|
|
|
* while interacting with activity UI.
|
|
|
|
|
*/
|
|
|
|
|
private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
|
|
|
switch (motionEvent.getAction()) {
|
|
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
|
|
ImageActivity.this.finish();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
private ActivityImageBinding binding;
|
|
|
|
|
private String path;//图片地址
|
|
|
|
|
private String cmdid;
|
|
|
|
|
|
|
|
|
|
@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");
|
|
|
|
|
cmdid = intent.getStringExtra("cmdid");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initView() {
|
|
|
|
|
binding.imageView.setImageDrawable(null);
|
|
|
|
|
binding.imageView.setClickable(true);
|
|
|
|
|
binding.imageView.setOnTouchListener(mDelayHideTouchListener);
|
|
|
|
|
binding.imageView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
ImageActivity.this.finish();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
binding.imageView.setOnClickListener(this);
|
|
|
|
|
if (path != null) {
|
|
|
|
|
loadImage(path);
|
|
|
|
|
}
|
|
|
|
|
mAdapter = new ImageItemAdapter();
|
|
|
|
|
// mAdapter.setOnClickListener(this);
|
|
|
|
|
binding.recyclerView.setAdapter(mAdapter);
|
|
|
|
|
binding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initData() {
|
|
|
|
|
|
|
|
|
|
// 在Activity或Fragment中
|
|
|
|
|
getPicList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initIntent() {
|
|
|
|
|
Intent intent = getIntent();
|
|
|
|
|
path = intent.getStringExtra("path");
|
|
|
|
|
//获取文件夹下所有的照片
|
|
|
|
|
private void getPicList() {
|
|
|
|
|
// 获取应用专属目录的相对路径
|
|
|
|
|
String relativePath = Environment.DIRECTORY_PICTURES + "/" + Constants.PACKAGE_NAME_MPREMOTE + "/";
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -126,11 +148,8 @@ public class ImageActivity extends AppCompatActivity {
|
|
|
|
|
binding.imageView.requestLayout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean loadImage(String path) {
|
|
|
|
|
|
|
|
|
|
binding.imageView.setImageDrawable(null);
|
|
|
|
|
|
|
|
|
|
File file = new File(path);
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
return false;
|
|
|
|
@ -139,7 +158,6 @@ public class ImageActivity extends AppCompatActivity {
|
|
|
|
|
if (drawable != null) {
|
|
|
|
|
binding.imageView.setImageDrawable(drawable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return drawable != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -166,65 +184,15 @@ public class ImageActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Map<String, Object>> getData() {
|
|
|
|
|
mItems.clear();
|
|
|
|
|
|
|
|
|
|
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
|
|
|
|
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
|
|
|
|
|
|
|
|
|
String ssid = "";
|
|
|
|
|
if (wifiInfo != null) {
|
|
|
|
|
ssid = wifiInfo.getSSID();
|
|
|
|
|
if (!TextUtils.isEmpty(ssid)) {
|
|
|
|
|
if (ssid.startsWith("\"") && ssid.endsWith("\"")) {
|
|
|
|
|
ssid = ssid.substring(1, ssid.length() - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
switch (v.getId()) {
|
|
|
|
|
case R.id.imageView:
|
|
|
|
|
finish();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (File file : mImageFiles) {
|
|
|
|
|
Map map = new HashMap<String, Object>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Bitmap bm =
|
|
|
|
|
map.put("img", null);
|
|
|
|
|
// if (scanR)
|
|
|
|
|
map.put("text", file.getName());
|
|
|
|
|
mItems.add(map);
|
|
|
|
|
}
|
|
|
|
|
return mItems;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// private void refreshListView() {
|
|
|
|
|
// mAdapter = new ImagesAdaper(this, getData(), R.layout.list_item, new String[] { "img", "text" },
|
|
|
|
|
// new int[] { R.id.id_img, R.id.id_text });
|
|
|
|
|
//
|
|
|
|
|
// binding.imagesView.setAdapter(mAdapter);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public class ImagesAdaper extends SimpleAdapter {
|
|
|
|
|
public ImagesAdaper(Context context, List<Map<String, Object>> items, int resource, String[] from, int[] to) {
|
|
|
|
|
super(context, items, resource, from, to);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent){
|
|
|
|
|
convertView = super.getView(position, convertView, parent);
|
|
|
|
|
|
|
|
|
|
TextView textView = (TextView)convertView.findViewById(R.id.id_channel);
|
|
|
|
|
|
|
|
|
|
File file = mImageFiles.get(position);
|
|
|
|
|
// if (scanResult.)
|
|
|
|
|
String text = (String)mItems.get(position).get("text");
|
|
|
|
|
if (text.startsWith("XY") || text.startsWith("xy")) {
|
|
|
|
|
textView.setTextColor(Color.RED);
|
|
|
|
|
textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
|
|
|
|
|
} else {
|
|
|
|
|
textView.setTextColor(Color.BLACK);
|
|
|
|
|
textView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return convertView;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|