Skip to content

Commit

Permalink
11/15, new version
Browse files Browse the repository at this point in the history
  • Loading branch information
YuanWenHai committed Nov 15, 2016
1 parent 30cd546 commit c451be8
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 80 deletions.
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.will.example.MainActivity">
android:supportsRtl="true">
<activity android:name="com.will.example.MainActivity"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/will/example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void onClick(View v) {
}else{
Intent intent = new Intent(MainActivity.this, FileSearcherActivity.class);
intent.putExtra("keyword",content);
intent.putExtra("theme",R.style.MTheme);
intent.putExtra("theme",R.style.SearchTheme);
intent.putExtra("min",(long)50*1024);
startActivityForResult(intent,REQUEST_CODE);
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorAccent">#c5cae9</color>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="MTheme" parent="FileSearcherActivityTheme">
<style name="SearchTheme" parent="FileSearcherActivityTheme">
<item name="colorPrimaryDark">#212121</item>
<item name="colorPrimary">#424242</item>
<item name="colorAccent">@color/colorPrimary</item>
<item name="colorAccent">#e0e0e0</item>
</style>
</resources>
9 changes: 5 additions & 4 deletions filesearcher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.YuanWenHai'
android {
compileSdkVersion 23
compileSdkVersion 24
buildToolsVersion "24.0.3"

defaultConfig {
Expand All @@ -27,8 +27,9 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:appcompat-v7:24.2.0'
testCompile 'junit:junit:4.12'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.0.0'
compile 'com.simplecityapps:recyclerview-fastscroll:1.0.11'
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.will.filesearcher.file_searcher;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.will.filesearcher.R;
Expand All @@ -21,7 +22,7 @@

public class FSAdapter extends RecyclerView.Adapter<FSAdapter.FSViewHolder> {
private Context context;
private List<File> resultList = new ArrayList<>();
private List<FileDetail> resultList = new ArrayList<>();
private List<Boolean> checkStatusMap = new ArrayList<>();
private FileSearcher fileSearcher;
private RecyclerView mRecyclerView;
Expand All @@ -35,7 +36,7 @@ public void onSearch(String pathName) {
}

@Override
public void onFind(File file) {
public void onFind(FileDetail file) {
resultList.add(file);
checkStatusMap.add(false);
mRecyclerView.smoothScrollToPosition(resultList.size());
Expand Down Expand Up @@ -77,15 +78,16 @@ public FSViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

@Override
public void onBindViewHolder(FSViewHolder holder, int position) {
File file = resultList.get(position);
holder.title.setText(file.getName());
holder.location.setText(file.getPath());
holder.size.setText(file.);
if(isFinished){
holder.checkBox.setVisibility(View.VISIBLE);
holder.checkBox.setChecked(checkStatusMap.get(position));
FileDetail file = resultList.get(position);
holder.title.setText(context.getString(R.string.file_name)+file.getName());
holder.location.setText(context.getString(R.string.file_path)+file.getPath());
holder.size.setText(context.getString(R.string.file_size)+file.getSize());
holder.time.setText(context.getString(R.string.file_last_modified_time)+file.getLastModifiedTime());
CardView cardView = (CardView) holder.itemView;
if(checkStatusMap.get(position)){
cardView.setCardBackgroundColor(fetchAccentColor());
}else{
holder.checkBox.setVisibility(View.INVISIBLE);
cardView.setCardBackgroundColor(context.getResources().getColor(R.color.cardview_light_background));
}
}

Expand All @@ -101,6 +103,7 @@ class FSViewHolder extends RecyclerView.ViewHolder{
@Override
public void onClick(View view) {
checkStatusMap.set(getAdapterPosition(),!checkStatusMap.get(getAdapterPosition()));
notifyDataSetChanged();
}
});
}
Expand Down Expand Up @@ -138,23 +141,19 @@ public List<File> getSelectedItems(){
List<File> list = new ArrayList<>();
for(int i=0;i<checkStatusMap.size();i++){
if(checkStatusMap.get(i)){
list.add(resultList.get(i));
list.add(resultList.get(i).getFile());
}
}
return list;
}
private String getSizeWithSuitableUnit(File file){
float fileSize = file.length();
int kb = 1;
int mb = 2;
int gb = 3;
int i = 0;
while (fileSize > 1){
fileSize = fileSize / 1024;
i++;
}
StringBuilder builder = new StringBuilder();
builder.append(fileSize);
if(i<)
private int fetchAccentColor() {
TypedValue typedValue = new TypedValue();

TypedArray a = context.obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent });
int color = a.getColor(0, 0);

a.recycle();

return color;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.will.filesearcher.file_searcher;

import java.io.File;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
* Created by will on 2016/11/15.
*/

public class FileDetail {
private String name,path,size,lastModifiedTime;

private File file;

public FileDetail(File file){
this.file = file;
name = file.getName();
path = file.getPath();
size = getSizeWithSuitableUnit();
lastModifiedTime = getLastModifiedTimeString();
}


public File getFile() {
return file;
}

public void setFile(File file) {
this.file = file;
}

public String getName() {
return name;
}

public String getPath() {
return path;
}

public String getSize() {
return size;
}

public String getLastModifiedTime() {
return lastModifiedTime;
}

public void setName(String name) {
this.name = name;
}

public void setLastModifiedTime(String lastModifiedTime) {
this.lastModifiedTime = lastModifiedTime;
}

public void setSize(String size) {
this.size = size;
}

public void setPath(String path) {
this.path = path;
}

private String getSizeWithSuitableUnit(){
float fileSize = file.length();
int kb = 1;
int mb = 2;
int gb = 3;
int i = 0;
String unit = "";
while(fileSize >= 1024){
fileSize = fileSize / 1024;
i++;
}
DecimalFormat format = new DecimalFormat("#.##");
StringBuilder builder = new StringBuilder();
builder.append(format.format(fileSize));
if(i == 0){
unit = "byte";
}else if(i == kb){
unit = "kb";
}else if(i == mb){
unit = "mb";
}else if(i == gb){
unit = "gb";
}
builder.append(unit);
return builder.toString();
}
private String getLastModifiedTimeString(){
Date date = new Date(file.lastModified());
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd,HH:mm:ss");
return format.format(date);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,20 @@ public void run() {
if(file.getName().toUpperCase().contains(keyword.toUpperCase())){
if(maxSize > 0){
if(file.length() <= maxSize && file.length() >= minSize ){
final FileDetail detail = new FileDetail(file);
handler.post(new Runnable() {
@Override
public void run() {
mCallback.onFind(file);
mCallback.onFind(detail);
}
});
}
}else if(file.length() >= minSize){
final FileDetail detail = new FileDetail(file);
handler.post(new Runnable() {
@Override
public void run() {
mCallback.onFind(file);
mCallback.onFind(detail);
}
});
}
Expand All @@ -84,9 +86,10 @@ public void run() {
}
}
}

public interface Callback {
void onSearch(String pathName);
void onFind(File file);
void onFind(FileDetail fileDetail);
void onFinish();
}
public void setMaxSize(long max){
Expand Down
Binary file added filesearcher/src/main/res/drawable-xhdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 42 additions & 30 deletions filesearcher/src/main/res/layout/file_searcher_item.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:cardUseCompatPadding="true">
app:cardUseCompatPadding="true"
app:cardCornerRadius="5dp"
app:contentPadding="5dp"
app:cardElevation="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/file_searcher_item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="marquee"
style="@style/FileSearcherItemTextAppearance"
tools:text="Name: abcde.txt"/>
<TextView
android:id="@+id/file_searcher_item_location"
android:layout_width="match_parent"
android:src="@drawable/icon"
android:visibility="gone"/>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
style="@style/FileSearcherItemTextAppearance"
tools:text="Location: C:\Users\will\Desktop"/>
<TextView
android:id="@+id/file_searcher_item_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/FileSearcherItemTextAppearance"
tools:text="Size: 14.1 MB (14,887,654 字节)"
/>
<TextView
android:id="@+id/file_searcher_item_create_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/FileSearcherItemTextAppearance"
tools:text="Create Time: 2016‎年‎11‎月‎10‎日,‏‎15:34:47"
/>
android:orientation="vertical">
<TextView
android:id="@+id/file_searcher_item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
style="@style/FileSearcherItemTextAppearance"
tools:text="Name: abcde.txt"/>
<TextView
android:id="@+id/file_searcher_item_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/FileSearcherItemTextAppearance"
tools:text="Location: C:\Users\will\Desktop"/>
<TextView
android:id="@+id/file_searcher_item_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/FileSearcherItemTextAppearance"
tools:text="Size: 14.1 MB (14,887,654 字节)"
/>
<TextView
android:id="@+id/file_searcher_item_create_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/FileSearcherItemTextAppearance"
tools:text="Create Time: 2016‎年‎11‎月‎10‎日,‏‎15:34:47"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
5 changes: 3 additions & 2 deletions filesearcher/src/main/res/layout/file_searcher_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
tools:text="正在搜索目录: abcde"/>
</android.support.v7.widget.Toolbar>

<android.support.v7.widget.RecyclerView
<com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
android:id="@+id/file_searcher_main_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"/>
app:fastScrollThumbColor="?attr/colorPrimary"
app:fastScrollPopupBackgroundSize="10dp"/>
</LinearLayout>
Loading

0 comments on commit c451be8

Please sign in to comment.