Remove codes for pre-21

This commit is contained in:
NekoInverter committed 2020-03-23 22:58:37 +08:00
1 parent 910c05b5a6
commit d75e2e78bf
30 files changed
+84 -805

No files matched your search

@@ -82,9 +82,6 @@ public class CheckTextView extends AppCompatTextView implements OnClickListener,
mPaint.setColor(mMaskColor);
setOnClickListener(this);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Hotspot.addHotspotable(this, this);
}
}
@Override
@@ -1,190 +0,0 @@
/*
* Copyright 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.widget;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Environment;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.hippo.android.resource.AttrResources;
import com.hippo.easyrecyclerview.EasyRecyclerView;
import com.hippo.easyrecyclerview.LinearDividerItemDecoration;
import com.hippo.ehviewer.R;
import com.hippo.ripple.Ripple;
import com.hippo.yorozuya.LayoutUtils;
import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class DirExplorer extends EasyRecyclerView implements EasyRecyclerView.OnItemClickListener {
private static final DirFilter DIR_FILTER = new DirFilter();
private static final FileSort FILE_SORT = new FileSort();
private static final File PARENT_DIR = null;
private static final String PARENT_DIR_NAME = "..";
private final List<File> mFiles = new ArrayList<>();
private File mCurrentFile;
private DirAdapter mAdapter;
private OnChangeDirListener mOnChangeDirListener;
public DirExplorer(Context context) {
super(context);
init(context);
}
public DirExplorer(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public DirExplorer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
private void init(Context context) {
mAdapter = new DirAdapter();
setAdapter(mAdapter);
setLayoutManager(new LinearLayoutManager(context));
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
LinearDividerItemDecoration.VERTICAL, AttrResources.getAttrColor(context, R.attr.dividerColor),
LayoutUtils.dp2pix(context, 1));
decoration.setShowLastDivider(true);
addItemDecoration(decoration);
setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
setOnItemClickListener(this);
mCurrentFile = Environment.getExternalStorageDirectory();
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|| mCurrentFile == null) {
mCurrentFile = new File("/");
}
updateFileList();
}
public void setOnChangeDirListener(OnChangeDirListener listener) {
mOnChangeDirListener = listener;
}
public void updateFileList() {
File[] files = mCurrentFile.listFiles(DIR_FILTER);
mFiles.clear();
if (mCurrentFile.getParent() != null) {
mFiles.add(PARENT_DIR);
}
if (files != null) {
Collections.addAll(mFiles, files);
}
// sort
Collections.sort(mFiles, FILE_SORT);
}
public File getCurrentFile() {
return mCurrentFile;
}
public void setCurrentFile(File file) {
if (file != null && file.isDirectory()) {
mCurrentFile = file;
updateFileList();
mAdapter.notifyDataSetChanged();
if (mOnChangeDirListener != null) {
mOnChangeDirListener.onChangeDir(mCurrentFile);
}
}
}
@Override
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
File file = mFiles.get(position);
if (file == PARENT_DIR) {
file = mCurrentFile.getParentFile();
}
setCurrentFile(file);
return true;
}
public interface OnChangeDirListener {
void onChangeDir(File dir);
}
static class DirFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory();
}
}
static class FileSort implements Comparator<File> {
@Override
public int compare(File lhs, File rhs) {
if (lhs == null) {
return Integer.MIN_VALUE;
} else if (rhs == null) {
return Integer.MAX_VALUE;
} else {
return lhs.getName().compareToIgnoreCase(rhs.getName());
}
}
}
private class DirHolder extends ViewHolder {
public TextView textView;
public DirHolder(View itemView) {
super(itemView);
textView = (TextView) itemView;
}
}
private class DirAdapter extends Adapter<DirHolder> {
@Override
public DirHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new DirHolder(LayoutInflater.from(getContext()).inflate(R.layout.item_dir_explorer, parent, false));
}
@Override
public void onBindViewHolder(DirHolder holder, int position) {
File file = mFiles.get(position);
holder.textView.setText(file == PARENT_DIR ? PARENT_DIR_NAME : file.getName());
}
@Override
public int getItemCount() {
return mFiles.size();
}
}
}
@@ -32,9 +32,6 @@ import com.hippo.yorozuya.LayoutUtils;
public class ShadowLinearLayout extends LinearLayout {
private final Rect mShadowPaddings = new Rect();
private NinePatchDrawable mShadow;
public ShadowLinearLayout(Context context) {
super(context);
init(context);
@@ -51,47 +48,8 @@ public class ShadowLinearLayout extends LinearLayout {
}
private void init(Context context) {
// TODO not only 2dp
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setOutlineProvider(ViewOutlineProvider.BOUNDS);
setElevation(LayoutUtils.dp2pix(context, 2));
} else {
setShadow((NinePatchDrawable) context.getResources().getDrawable(R.drawable.shadow_2dp)); // TODO draktheme
}
setOutlineProvider(ViewOutlineProvider.BOUNDS);
setElevation(LayoutUtils.dp2pix(context, 2));
}
private void setShadow(NinePatchDrawable shadow) {
mShadow = shadow;
mShadow.getPadding(mShadowPaddings);
updateShadowBounds();
setWillNotDraw(false);
}
private void updateShadowBounds() {
NinePatchDrawable shadow = mShadow;
if (shadow == null) {
return;
}
int width = getWidth();
int height = getHeight();
Rect paddings = mShadowPaddings;
if (width != 0 && height != 0) {
shadow.setBounds(-paddings.left, -paddings.top, width + paddings.right, height + paddings.bottom);
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
updateShadowBounds();
}
@Override
public void draw(@NonNull Canvas canvas) {
if (mShadow != null) {
mShadow.draw(canvas);
}
super.draw(canvas);
}
}