Commit 512fdfe6 authored by 赵鹏翔's avatar 赵鹏翔

查看本地日志功能添加,日志浏览配置完成

parent e0f31f6f
......@@ -60,9 +60,9 @@
<activity
android:name=".log.FunctionCenterActivity"
android:exported="true" />
<!-- <activity-->
<!-- android:name=".log.LFilePickerActivity"-->
<!-- android:exported="true" />-->
<activity
android:name=".log.LFilePickerActivity"
android:exported="true" />
</application>
......
package com.miya.fastcashier.log;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import com.blankj.utilcode.util.SizeUtils;
import com.miya.fastcashier.R;
import com.miya.print.utils.QRCodeUtil;
import androidx.annotation.NonNull;
public class CustomImageCenterDialog extends Dialog{
private TextView tvOk;
private TextView tvHint;
private ImageView ivContent;
boolean isFullScreen;
private String mImageContent;
private String mHintContentText;
private String mConfirmContent;
private Bitmap mQrCodeBitmap;
/**
* 设置是否全屏显示
*
* @param isFullScreen
* @return
*/
public CustomImageCenterDialog setFullScreen(boolean isFullScreen) {
this.isFullScreen = isFullScreen;
return this;
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (isFullScreen) {
setFullScreen();
}
}
/**
* 隐藏虚拟按键,并且全屏
*/
protected void setFullScreen() {
//隐藏虚拟按键,并且全屏
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if (Build.VERSION.SDK_INT >= 19) {
//for new api versions.
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION//暂时不需要hideNavigation
// | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
}
public CustomImageCenterDialog(@NonNull Context context) {
super(context, R.style.CommonDialog);
initWindows();
setCanceledOnTouchOutside(false);
// setContentView(R.layout.dialog_center_image);
setCancelable(true);
initView();
}
private void initView() {
// tvOk = findViewById(R.id.tvOk);
// tvHint = findViewById(R.id.tvSubContent);
// ivContent = findViewById(R.id.ivContent);
}
public CustomImageCenterDialog setQrContent(String msg) {
mImageContent = msg;
return this;
}
public CustomImageCenterDialog setConfirmContent(String msg) {
mConfirmContent = msg;
return this;
}
public CustomImageCenterDialog setHintContent(String msg) {
mHintContentText = msg;
return this;
}
/**
* 创建dialog
*
* @return
*/
public CustomImageCenterDialog build() {
if (!TextUtils.isEmpty(mConfirmContent)){
tvOk.setText(mConfirmContent);
}
if (!TextUtils.isEmpty(mHintContentText)){
tvHint.setText(mHintContentText);
}
if (!TextUtils.isEmpty(mImageContent)){
mQrCodeBitmap = QRCodeUtil.createQRCodeBitmap(mImageContent, SizeUtils.dp2px(300));
ivContent.setImageBitmap(mQrCodeBitmap);
}
tvOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mQrCodeBitmap != null) {
mQrCodeBitmap.recycle();
}
dismiss();
}
});
if (isFullScreen) {
setFullScreen();
}
return this;
}
/**
* 初始化对话框(供子类选择调用)
*/
protected void initWindows() {
Window win = this.getWindow();
win.requestFeature(Window.FEATURE_NO_TITLE);
win.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams lp = win.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
// lp.windowAnimations = R.style.LightInAndOutStyle;
lp.gravity = Gravity.CENTER;
win.setAttributes(lp);
win.setBackgroundDrawableResource(android.R.color.transparent);
}
}
package com.miya.fastcashier.log;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
/**
* 作者:Leon
* 时间:2017/3/17 13:44
*/
public class EmptyRecyclerView extends RecyclerView {
private View mEmptyView;
public EmptyRecyclerView(Context context) {
super(context);
}
public EmptyRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public EmptyRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
/**
* 根据数据源判断是否显示空白view
*/
private void checkIfEmpty() {
if (mEmptyView != null || getAdapter() != null) {
mEmptyView.setVisibility(getAdapter().getItemCount() > 0 ? GONE : VISIBLE);
}
}
public void setmEmptyView(View mEmptyView) {
this.mEmptyView = mEmptyView;
checkIfEmpty();
}
@Override
public void setAdapter(Adapter adapter) {
Adapter adapterOld = getAdapter();
if (adapterOld != null) {
adapterOld.unregisterAdapterDataObserver(observer);
}
super.setAdapter(adapter);
if (adapter != null) {
adapter.registerAdapterDataObserver(observer);
}
}
AdapterDataObserver observer = new AdapterDataObserver() {
@Override
public void onChanged() {
super.onChanged();
checkIfEmpty();
}
};
}
package com.miya.fastcashier.log;
import java.io.File;
import java.util.Comparator;
/**
* Created by Dimorinny on 24.10.15.
*/
public class FileComparator implements Comparator<File> {
@Override
public int compare(File f1, File f2) {
if(f1 == f2) {
return 0;
}
if(f1.isDirectory() && f2.isFile()) {
// Show directories above files
return -1;
}
if(f1.isFile() && f2.isDirectory()) {
// Show files below directories
return 1;
}
// Sort the directories alphabetically
return f1.getName().compareToIgnoreCase(f2.getName());
}
}
package com.miya.fastcashier.log;
import java.io.File;
import java.io.FileFilter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Created by Dimorinny on 24.10.15.
*/
public class FileUtils {
public static List<File> getFileListByDirPath(String path, FileFilter filter) {
File directory = new File(path);
File[] files = directory.listFiles(filter);
List<File> result = new ArrayList<>();
if (files == null) {
return new ArrayList<>();
}
for (int i = 0; i < files.length; i++) {
result.add(files[i]);
}
Collections.sort(result, new FileComparator());
return result;
}
public static String cutLastSegmentOfPath(String path) {
return path.substring(0, path.lastIndexOf("/"));
}
public static String getReadableFileSize(long size) {
if (size <= 0) return "0";
final String[] units = new String[]{"B", "KB", "MB", "GB", "TB"};
int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
return new DecimalFormat("#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
/**
* 获取文件长度
*
* @param file 文件
* @return 文件长度
*/
public static long getFileLength(final File file) {
if (!isFile(file)) return -1;
return file.length();
}
/**
* 判断是否是文件
*
* @param file 文件
* @return {@code true}: 是<br>{@code false}: 否
*/
public static boolean isFile(final File file) {
return file != null && file.exists() && file.isFile();
}
/**
* 根据地址获取当前地址下的所有目录和文件,并且排序,同时过滤掉不符合大小要求的文件
*
* @param path
* @return List<File>
*/
public static List<File> getFileList(String path, FileFilter filter, boolean isGreater, long targetSize) {
List<File> list = FileUtils.getFileListByDirPath(path, filter);
//进行过滤文件大小
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
File f = (File) iterator.next();
if (f.isFile()) {
//获取当前文件大小
long size = FileUtils.getFileLength(f);
if (isGreater) {
//当前想要留下大于指定大小的文件,所以过滤掉小于指定大小的文件
if (size < targetSize) {
iterator.remove();
}
} else {
//当前想要留下小于指定大小的文件,所以过滤掉大于指定大小的文件
if (size > targetSize) {
iterator.remove();
}
}
}
}
return list;
}
}
package com.miya.fastcashier.log;
import java.io.File;
import java.io.FileFilter;
/**
* 作者:Leon
* 时间:2017/3/24 13:43
*/
public class LFileFilter implements FileFilter {
private String[] mTypes;
public LFileFilter(String[] types) {
this.mTypes = types;
}
@Override
public boolean accept(File file) {
if (file.isDirectory()) {
return true;
}
if (mTypes != null && mTypes.length > 0) {
for (int i = 0; i < mTypes.length; i++) {
if (file.getName().endsWith(mTypes[i].toLowerCase()) || file.getName().endsWith(mTypes[i].toUpperCase())) {
return true;
}
}
}else {
return true;
}
return false;
}
}
......@@ -270,14 +270,13 @@ public class LFilePicker {
private Intent initIntent() {
// Intent intent;
// if (mActivity != null) {
// intent = new Intent(mActivity, LFilePickerActivity.class);
// } else {
// intent = new Intent(mFragment.getActivity(), LFilePickerActivity.class);
// }
// return intent;
return null;
Intent intent;
if (mActivity != null) {
intent = new Intent(mActivity, LFilePickerActivity.class);
} else {
intent = new Intent(mFragment.getActivity(), LFilePickerActivity.class);
}
return intent;
}
@NonNull
......
package com.miya.fastcashier.log;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.miya.fastcashier.R;
import java.io.File;
import java.io.FileFilter;
import java.util.List;
import androidx.recyclerview.widget.RecyclerView;
/**
* 作者:Leon
* 时间:2017/3/15 15:47
*/
public class PathAdapter extends RecyclerView.Adapter<PathAdapter.PathViewHolder> {
public interface OnItemClickListener {
void click(int position);
}
public interface OnCancelChoosedListener {
void cancelChoosed(CheckBox checkBox);
}
private final String TAG = "FilePickerLeon";
private List<File> mListData;
private Context mContext;
public OnItemClickListener onItemClickListener;
private FileFilter mFileFilter;
private boolean[] mCheckedFlags;
private boolean mMutilyMode;
private int mIconStyle;
private boolean mIsGreater;
private long mFileSize;
public PathAdapter(List<File> mListData, Context mContext, FileFilter mFileFilter, boolean mMutilyMode, boolean mIsGreater, long mFileSize) {
this.mListData = mListData;
this.mContext = mContext;
this.mFileFilter = mFileFilter;
this.mMutilyMode = mMutilyMode;
this.mIsGreater = mIsGreater;
this.mFileSize = mFileSize;
mCheckedFlags = new boolean[mListData.size()];
}
@Override
public PathViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = View.inflate(mContext, R.layout.layout_lfile_list_item, null);
PathViewHolder pathViewHolder = new PathViewHolder(view);
return pathViewHolder;
}
@Override
public int getItemCount() {
return mListData.size();
}
@Override
public void onBindViewHolder(final PathViewHolder holder, @SuppressLint("RecyclerView") int position) {
final File file = mListData.get(position);
if (file.isFile()) {
updateFileIconStyle(holder.ivType);
holder.tvName.setText(file.getName());
holder.tvDetail.setText(mContext.getString(R.string.lfile_FileSize) + " " + FileUtils.getReadableFileSize(file.length()));
holder.cbChoose.setVisibility(View.VISIBLE);
} else {
updateFloaderIconStyle(holder.ivType);
holder.tvName.setText(file.getName());
//文件大小过滤
List files = FileUtils.getFileList(file.getAbsolutePath(), mFileFilter, mIsGreater, mFileSize);
if (files == null) {
holder.tvDetail.setText("0 " + mContext.getString(R.string.lfile_LItem));
} else {
holder.tvDetail.setText(files.size() + " " + mContext.getString(R.string.lfile_LItem));
}
holder.cbChoose.setVisibility(View.GONE);
}
if (!mMutilyMode) {
holder.cbChoose.setVisibility(View.GONE);
}
holder.layoutRoot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (file.isFile()) {
holder.cbChoose.setChecked(!holder.cbChoose.isChecked());
}
onItemClickListener.click(position);
}
});
holder.cbChoose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//同步复选框和外部布局点击的处理
onItemClickListener.click(position);
}
});
holder.cbChoose.setOnCheckedChangeListener(null);//先设置一次CheckBox的选中监听器,传入参数null
holder.cbChoose.setChecked(mCheckedFlags[position]);//用数组中的值设置CheckBox的选中状态
//再设置一次CheckBox的选中监听器,当CheckBox的选中状态发生改变时,把改变后的状态储存在数组中
holder.cbChoose.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
mCheckedFlags[position] = b;
}
});
}
private void updateFloaderIconStyle(ImageView imageView) {
// switch (mIconStyle) {
// case Constant.ICON_STYLE_BLUE:
// imageView.setBackgroundResource(R.mipmap.lfile_folder_style_blue);
// break;
// case Constant.ICON_STYLE_GREEN:
// imageView.setBackgroundResource(R.mipmap.lfile_folder_style_green);
// break;
// case Constant.ICON_STYLE_YELLOW:
// imageView.setBackgroundResource(R.mipmap.lfile_folder_style_yellow);
// break;
// }
}
private void updateFileIconStyle(ImageView imageView) {
// switch (mIconStyle) {
// case Constant.ICON_STYLE_BLUE:
// imageView.setBackgroundResource(R.mipmap.lfile_file_style_blue);
// break;
// case Constant.ICON_STYLE_GREEN:
// imageView.setBackgroundResource(R.mipmap.lfile_file_style_green);
// break;
// case Constant.ICON_STYLE_YELLOW:
// imageView.setBackgroundResource(R.mipmap.lfile_file_style_yellow);
// break;
// }
}
/**
* 设置监听器
*
* @param onItemClickListener
*/
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}
/**
* 设置数据源
*
* @param mListData
*/
public void setmListData(List<File> mListData) {
this.mListData = mListData;
mCheckedFlags = new boolean[mListData.size()];
}
public void setmIconStyle(int mIconStyle) {
this.mIconStyle = mIconStyle;
}
/**
* 设置是否全选
*
* @param isAllSelected
*/
public void updateAllSelelcted(boolean isAllSelected) {
for (int i = 0; i < mCheckedFlags.length; i++) {
mCheckedFlags[i] = isAllSelected;
}
notifyDataSetChanged();
}
class PathViewHolder extends RecyclerView.ViewHolder {
private RelativeLayout layoutRoot;
private ImageView ivType;
private TextView tvName;
private TextView tvDetail;
private CheckBox cbChoose;
public PathViewHolder(View itemView) {
super(itemView);
ivType = (ImageView) itemView.findViewById(R.id.iv_type);
layoutRoot = (RelativeLayout) itemView.findViewById(R.id.layout_item_root);
tvName = (TextView) itemView.findViewById(R.id.tv_name);
tvDetail = (TextView) itemView.findViewById(R.id.tv_detail);
cbChoose = (CheckBox) itemView.findViewById(R.id.cb_choose);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/lfile_lightgray" android:state_pressed="true" />
<item android:drawable="@color/lfile_lightgray" android:state_selected="true" />
<item android:drawable="@color/lfile_white" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="12dp" />
<solid android:color="#ffe5e5e5"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/lfile_gray" android:state_pressed="true"/>
<item android:drawable="@color/lfile_gray" android:state_selected="true"/>
<item android:drawable="@color/lfile_lightgray"/>
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/lfile_defaultColor" android:state_pressed="true"/>
<item android:drawable="@color/lfile_defaultColor" android:state_selected="true"/>
<item android:drawable="@color/lfile_defaultColor"/>
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/lfile_white">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="?attr/colorPrimary"
android:minHeight="?android:attr/actionBarSize"
app:navigationIcon="?attr/navigationIcon" />
<LinearLayout
android:id="@+id/layout_path"
android:layout_width="match_parent"
android:layout_height="44dp"
android:layout_below="@id/toolbar"
android:background="#dddddd"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_path"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:ellipsize="middle"
android:gravity="left|center"
android:singleLine="true"
android:textSize="14sp" />
<TextView
android:visibility="gone"
android:id="@+id/tv_back"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="@drawable/shape_lfile_back_bg"
android:clickable="true"
android:drawableLeft="@mipmap/app_icon_lfile_up"
android:drawablePadding="4dp"
android:gravity="center"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="@string/lfile_UpOneLevel" />
</LinearLayout>
<Button
android:id="@+id/btn_addbook"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/shape_lfile_btn_bg"
android:text="@string/lfile_Selected"
android:textColor="@color/lfile_white"
android:textSize="18sp" />
<com.miya.fastcashier.log.EmptyRecyclerView
android:id="@+id/recylerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/btn_addbook"
android:layout_below="@id/layout_path" />
<include
android:id="@+id/empty_view"
layout="@layout/layout_lfile_emptyview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/layout_path" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/lfile_white">
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_above="@id/tv_empty"
android:layout_centerHorizontal="true"
android:background="@mipmap/lfile_emptyimg" />
<TextView
android:id="@+id/tv_empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:padding="12dp"
android:text="暂无数据"
android:textColor="@color/lfile_gray"
android:textSize="18sp" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_item_root"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="10dp"
android:background="@drawable/selector_file_item_bg"
android:clickable="true"
android:paddingLeft="12dp"
android:paddingRight="12dp">
<CheckBox
android:id="@+id/cb_choose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:theme="@style/LFileCheckBoxTheme" />
<ImageView
android:id="@+id/iv_type"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_centerVertical="true"
android:background="@mipmap/app_icon_lfile_file_style_green" />
<LinearLayout
android:id="@+id/layout_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_toLeftOf="@id/cb_choose"
android:layout_toRightOf="@id/iv_type"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/tv_name"
style="@style/LFile_item_text_name"
android:text="鬼吹灯" />
<TextView
android:id="@+id/tv_detail"
style="@style/LFile_item_text_detail"
android:text="类型:txt 大小:1024KB" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_below="@id/layout_info"
android:layout_marginTop="6dp"
android:background="@color/lfile_lightgray" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_selecteall_cancel"
android:title="全选"
app:showAsAction="always"/>
</menu>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment