Merge branch 'simple_cleanup' of https://github.com/tonymanou/Shelter

This commit is contained in:
Peter Cai 2019-04-03 17:42:34 +08:00
commit bb2e425f06
No known key found for this signature in database
GPG key ID: 71F5FB4E4F3FD54F
6 changed files with 25 additions and 25 deletions

View file

@ -26,6 +26,7 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -46,9 +47,9 @@ public class FileShuttleService extends Service {
} }
@Override @Override
public List<Map> loadFiles(String path) { public List<Map<String, Serializable>> loadFiles(String path) {
resetSuicideTask(); resetSuicideTask();
ArrayList<Map> ret = new ArrayList<>(); ArrayList<Map<String, Serializable>> ret = new ArrayList<>();
File f = new File(resolvePath(path)); File f = new File(resolvePath(path));
if (f.listFiles() != null) { if (f.listFiles() != null) {
for (File child : f.listFiles()) { for (File child : f.listFiles()) {
@ -59,10 +60,10 @@ public class FileShuttleService extends Service {
} }
@Override @Override
public Map loadFileMeta(String path) { public Map<String, Serializable> loadFileMeta(String path) {
resetSuicideTask(); resetSuicideTask();
File f = new File(resolvePath(path)); File f = new File(resolvePath(path));
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Serializable> map = new HashMap<>();
map.put(DocumentsContract.Document.COLUMN_DOCUMENT_ID, f.getAbsolutePath()); map.put(DocumentsContract.Document.COLUMN_DOCUMENT_ID, f.getAbsolutePath());
map.put(DocumentsContract.Document.COLUMN_DISPLAY_NAME, f.getName()); map.put(DocumentsContract.Document.COLUMN_DISPLAY_NAME, f.getName());
map.put(DocumentsContract.Document.COLUMN_SIZE, f.length()); map.put(DocumentsContract.Document.COLUMN_SIZE, f.length());

View file

@ -50,10 +50,10 @@ public class FreezeService extends Service {
} }
// An app being inactive for this amount of time will be frozen // An app being inactive for this amount of time will be frozen
private static long APP_INACTIVE_TIMEOUT = 1000; private static final long APP_INACTIVE_TIMEOUT = 1000;
// Notification ID // Notification ID
private static int NOTIFICATION_ID = 0xe49c0; private static final int NOTIFICATION_ID = 0xe49c0;
// The actual receiver of the screen-off event // The actual receiver of the screen-off event
private BroadcastReceiver mLockReceiver = new BroadcastReceiver() { private BroadcastReceiver mLockReceiver = new BroadcastReceiver() {

View file

@ -29,16 +29,14 @@ import java.util.stream.Collectors;
public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHolder> { public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHolder> {
class ViewHolder extends RecyclerView.ViewHolder { class ViewHolder extends RecyclerView.ViewHolder {
private ViewGroup mView;
private ImageView mIcon; private ImageView mIcon;
private TextView mTitle; private TextView mTitle;
private TextView mPackage; private TextView mPackage;
// This text view shows the order of all selected items // This text view shows the order of all selected items
private TextView mSelectOrder; private TextView mSelectOrder;
int mIndex = -1; int mIndex = -1;
ViewHolder(ViewGroup view) { ViewHolder(View view) {
super(view); super(view);
mView = view;
mIcon = view.findViewById(R.id.list_app_icon); mIcon = view.findViewById(R.id.list_app_icon);
mTitle = view.findViewById(R.id.list_app_title); mTitle = view.findViewById(R.id.list_app_title);
mPackage = view.findViewById(R.id.list_app_package); mPackage = view.findViewById(R.id.list_app_package);
@ -57,7 +55,7 @@ public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHold
// pass the full info to it, since we can't be sure // pass the full info to it, since we can't be sure
// the index won't change // the index won't change
if (mContextMenuHandler != null) { if (mContextMenuHandler != null) {
mContextMenuHandler.showContextMenu(mList.get(mIndex), mView); mContextMenuHandler.showContextMenu(mList.get(mIndex), itemView);
} }
} else { } else {
// In multi-select mode, single clicks just adds to the selection // In multi-select mode, single clicks just adds to the selection
@ -91,7 +89,7 @@ public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHold
void select() { void select() {
mSelectedIndices.add(mIndex); mSelectedIndices.add(mIndex);
mSelectOrder.clearAnimation(); mSelectOrder.clearAnimation();
mSelectOrder.startAnimation(AnimationUtils.loadAnimation(mView.getContext(), R.anim.scale_appear)); mSelectOrder.startAnimation(AnimationUtils.loadAnimation(itemView.getContext(), R.anim.scale_appear));
showSelectOrder(); showSelectOrder();
} }
@ -100,7 +98,7 @@ public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHold
mSelectedIndices.remove((Integer) mIndex); mSelectedIndices.remove((Integer) mIndex);
mSelectOrder.clearAnimation(); mSelectOrder.clearAnimation();
setUnselectedBackground(); setUnselectedBackground();
Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.scale_hide); Animation anim = AnimationUtils.loadAnimation(itemView.getContext(), R.anim.scale_hide);
anim.setAnimationListener(new Animation.AnimationListener() { anim.setAnimationListener(new Animation.AnimationListener() {
@Override @Override
public void onAnimationStart(Animation animation) { public void onAnimationStart(Animation animation) {
@ -132,11 +130,11 @@ public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHold
// (not necessarily when the user clicked on it; the view might have been recycled) // (not necessarily when the user clicked on it; the view might have been recycled)
void showSelectOrder() { void showSelectOrder() {
if (!mList.get(mIndex).isHidden()) { if (!mList.get(mIndex).isHidden()) {
mView.setBackgroundResource(R.color.selectedAppBackground); itemView.setBackgroundResource(R.color.selectedAppBackground);
} else { } else {
// The app is both frozen and selected // The app is both frozen and selected
// we use a blended color of the two for its background // we use a blended color of the two for its background
mView.setBackgroundResource(R.color.selectedAndDisabledAppBackground); itemView.setBackgroundResource(R.color.selectedAndDisabledAppBackground);
} }
mSelectOrder.setVisibility(View.VISIBLE); mSelectOrder.setVisibility(View.VISIBLE);
mSelectOrder.setText(String.valueOf(mSelectedIndices.indexOf(mIndex) + 1)); mSelectOrder.setText(String.valueOf(mSelectedIndices.indexOf(mIndex) + 1));
@ -151,9 +149,9 @@ public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHold
// Set the background when not in the selected state // Set the background when not in the selected state
void setUnselectedBackground() { void setUnselectedBackground() {
if (!mList.get(mIndex).isHidden()) { if (!mList.get(mIndex).isHidden()) {
mView.setBackground(null); itemView.setBackground(null);
} else { } else {
mView.setBackgroundResource(R.color.disabledAppBackground); itemView.setBackgroundResource(R.color.disabledAppBackground);
} }
} }
@ -327,8 +325,8 @@ public class AppListAdapter extends RecyclerView.Adapter<AppListAdapter.ViewHold
if (mLabelDisabled == null) { if (mLabelDisabled == null) {
mLabelDisabled = viewGroup.getContext().getString(R.string.list_item_disabled); mLabelDisabled = viewGroup.getContext().getString(R.string.list_item_disabled);
} }
LayoutInflater inflater = viewGroup.getContext().getSystemService(LayoutInflater.class); LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
ViewGroup view = (ViewGroup) inflater.inflate(R.layout.app_list_item, viewGroup, false); View view = inflater.inflate(R.layout.app_list_item, viewGroup, false);
ViewHolder vh = new ViewHolder(view); ViewHolder vh = new ViewHolder(view);
vh.setIndex(i); vh.setIndex(i);
return vh; return vh;

View file

@ -98,7 +98,7 @@ public class AppListFragment extends BaseFragment {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String query = intent.getStringExtra("text"); String query = intent.getStringExtra("text");
if (query == "") { if ("".equals(query)) {
// Consider empty query as null // Consider empty query as null
query = null; query = null;
} }

View file

@ -22,6 +22,7 @@ import net.typeblog.shelter.services.IFileShuttleService;
import net.typeblog.shelter.services.IFileShuttleServiceCallback; import net.typeblog.shelter.services.IFileShuttleServiceCallback;
import net.typeblog.shelter.ui.DummyActivity; import net.typeblog.shelter.ui.DummyActivity;
import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -50,7 +51,7 @@ public class CrossProfileDocumentsProvider extends DocumentsProvider {
// We just release the service when idle, thus enabling the // We just release the service when idle, thus enabling the
// system to release memory // system to release memory
private Runnable mReleaseServiceTask = this::releaseService; private Runnable mReleaseServiceTask = this::releaseService;
private Object mLock = new Object(); private final Object mLock = new Object();
private void doBindService() { private void doBindService() {
// Call DummyActivity on the other side to bind the service for us // Call DummyActivity on the other side to bind the service for us
@ -137,7 +138,7 @@ public class CrossProfileDocumentsProvider extends DocumentsProvider {
public Cursor queryDocument(String documentId, String[] projection) { public Cursor queryDocument(String documentId, String[] projection) {
ensureServiceBound(); ensureServiceBound();
final MatrixCursor result = new MatrixCursor(projection == null ? DEFAULT_DOCUMENT_PROJECTION : projection); final MatrixCursor result = new MatrixCursor(projection == null ? DEFAULT_DOCUMENT_PROJECTION : projection);
Map<String, Object> fileInfo = null; Map<String, Serializable> fileInfo;
try { try {
fileInfo = mService.loadFileMeta(documentId); fileInfo = mService.loadFileMeta(documentId);
} catch (RemoteException e) { } catch (RemoteException e) {
@ -150,7 +151,7 @@ public class CrossProfileDocumentsProvider extends DocumentsProvider {
@Override @Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) { public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) {
ensureServiceBound(); ensureServiceBound();
List<Map<String, Object>> files = null; List<Map<String, Serializable>> files;
try { try {
files = mService.loadFiles(parentDocumentId); files = mService.loadFiles(parentDocumentId);
} catch (RemoteException e) { } catch (RemoteException e) {
@ -161,7 +162,7 @@ public class CrossProfileDocumentsProvider extends DocumentsProvider {
result.setNotificationUri(getContext().getContentResolver(), result.setNotificationUri(getContext().getContentResolver(),
DocumentsContract.buildDocumentUri(AUTHORITY, parentDocumentId)); DocumentsContract.buildDocumentUri(AUTHORITY, parentDocumentId));
for (Map<String, Object> file : files) { for (Map<String, Serializable> file : files) {
includeFile(result, file); includeFile(result, file);
} }
return result; return result;
@ -223,7 +224,7 @@ public class CrossProfileDocumentsProvider extends DocumentsProvider {
} }
} }
private void includeFile(MatrixCursor cursor, Map<String, Object> fileInfo) { private void includeFile(MatrixCursor cursor, Map<String, Serializable> fileInfo) {
final MatrixCursor.RowBuilder row = cursor.newRow(); final MatrixCursor.RowBuilder row = cursor.newRow();
for (String col : DEFAULT_DOCUMENT_PROJECTION) { for (String col : DEFAULT_DOCUMENT_PROJECTION) {
row.add(col, fileInfo.get(col)); row.add(col, fileInfo.get(col));

View file

@ -353,7 +353,7 @@ public class Utility {
public static String getFileExtension(String filePath) { public static String getFileExtension(String filePath) {
int index = filePath.lastIndexOf("."); int index = filePath.lastIndexOf(".");
if (index > 0) { if (index > 0) {
return filePath.substring(index + 1, filePath.length()); return filePath.substring(index + 1);
} else { } else {
return null; return null;
} }