mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 12:00:17 +02:00
fix some remarks
This commit is contained in:
parent
74169aa9c3
commit
7fcdfb01f4
8 changed files with 678 additions and 4 deletions
160
src/org/geometerplus/android/fbreader/library/FileListView.java
Normal file
160
src/org/geometerplus/android/fbreader/library/FileListView.java
Normal file
|
@ -0,0 +1,160 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.android.fbreader.library;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.ui.android.R;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
|
|
||||||
|
public class FileListView {
|
||||||
|
private static final String START_DIR = "sdcard/Books";
|
||||||
|
|
||||||
|
private Activity myParent;
|
||||||
|
private ListView myListView;
|
||||||
|
private String myCurDir = ".";
|
||||||
|
private String myCurFile = ".";
|
||||||
|
private List<String> myHistory = new ArrayList<String>();
|
||||||
|
private String myFilterTypes = "";
|
||||||
|
|
||||||
|
// Members for dynamic loading //
|
||||||
|
private ArrayAdapter<String> myAdapter;
|
||||||
|
private List<String> myOrders = Collections.synchronizedList(new ArrayList<String>());
|
||||||
|
private SmartFilter myFilter;
|
||||||
|
private ReturnRes myReturnRes;
|
||||||
|
private Thread myCurFilterThread;
|
||||||
|
private ProgressDialog myProgressDialog;
|
||||||
|
|
||||||
|
|
||||||
|
public FileListView(Activity parent, ListView listView) {
|
||||||
|
myParent = parent;
|
||||||
|
myListView = listView;
|
||||||
|
|
||||||
|
// set parameters ProgressDialog
|
||||||
|
myProgressDialog = new ProgressDialog(myParent);
|
||||||
|
myProgressDialog.setTitle("Please wait...");
|
||||||
|
myProgressDialog.setMessage("Retrieving data ...");
|
||||||
|
|
||||||
|
myAdapter = new ArrayAdapter<String>(myParent, R.layout.list_item);
|
||||||
|
myListView.setAdapter(myAdapter);
|
||||||
|
myReturnRes = new ReturnRes(myOrders, myAdapter, myProgressDialog);
|
||||||
|
myFilter = new SmartFilter(myParent, myOrders, myReturnRes);
|
||||||
|
|
||||||
|
init(myCurDir);
|
||||||
|
|
||||||
|
myListView.setTextFilterEnabled(true);
|
||||||
|
myListView.setOnItemClickListener(new OnItemClickListener() {
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view,
|
||||||
|
int position, long id) {
|
||||||
|
view.setSelected(true);
|
||||||
|
|
||||||
|
myCurFile = ((TextView) view).getText().toString();
|
||||||
|
if (new File(myCurDir + "/" + myCurFile).isDirectory())
|
||||||
|
myHistory.add(myCurFile);
|
||||||
|
goAtDir(myCurDir + "/" + myCurFile);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListView getListView() {
|
||||||
|
return myListView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFilterTypes(){
|
||||||
|
return myFilterTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPathToFile(){
|
||||||
|
if (myCurDir.equals(myCurFile))
|
||||||
|
return null;
|
||||||
|
return myCurDir + "/" + myCurFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void goAtBack(){
|
||||||
|
back();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFilter(String filterTypes){
|
||||||
|
if (!myFilterTypes.equals(filterTypes)){
|
||||||
|
myFilterTypes = filterTypes;
|
||||||
|
goAtDir(myCurDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void back(){
|
||||||
|
if (myHistory.size() > 0){
|
||||||
|
|
||||||
|
// TODO delete later
|
||||||
|
for (String s : myHistory){
|
||||||
|
Log.v(FileManager.FILE_MANAGER_LOG_TAG, "histiry : " + s);
|
||||||
|
}
|
||||||
|
|
||||||
|
String dir = myHistory.remove(myHistory.size() - 1);
|
||||||
|
myCurDir = myCurDir.substring(0, myCurDir.length() - dir.length() - 1);
|
||||||
|
goAtDir(myCurDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(String path){
|
||||||
|
myProgressDialog.show();
|
||||||
|
File file = new File(path);
|
||||||
|
myCurDir = path;
|
||||||
|
myFilter.setPreferences(file, myFilterTypes);
|
||||||
|
myCurFilterThread = new Thread(null, myFilter, "MagentoBackground");
|
||||||
|
myCurFilterThread.start();
|
||||||
|
|
||||||
|
for(String dir : START_DIR.split("[\\/]+")){
|
||||||
|
myCurFile = dir;
|
||||||
|
myCurDir += "/" + dir;
|
||||||
|
|
||||||
|
Log.v(FileManager.FILE_MANAGER_LOG_TAG, "file: " + myCurFile + "\t dir: " + myCurDir);
|
||||||
|
|
||||||
|
myHistory.add(myCurFile);
|
||||||
|
goAtDir(myCurDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void goAtDir(String path) {
|
||||||
|
if (new File(path).isDirectory()){
|
||||||
|
|
||||||
|
myProgressDialog.show();
|
||||||
|
File file = new File(path);
|
||||||
|
myCurDir = path;
|
||||||
|
myCurFilterThread.interrupt();
|
||||||
|
myFilter.setPreferences(file, myFilterTypes);
|
||||||
|
myCurFilterThread = new Thread(null, myFilter, "MagentoBackground");
|
||||||
|
myCurFilterThread.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
125
src/org/geometerplus/android/fbreader/library/FileManager.java
Normal file
125
src/org/geometerplus/android/fbreader/library/FileManager.java
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.android.fbreader.library;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.ui.android.R;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
public final class FileManager extends Activity {
|
||||||
|
private static String FB_HOME_DIR = "./sdcard/Books";
|
||||||
|
private static String ROOT_DIR = ".";
|
||||||
|
private static String SDCARD_DIR = "./sdcard";
|
||||||
|
|
||||||
|
private FileListView myFileListView;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
Log.v(FILE_MANAGER_LOG_TAG, "onCreate()");
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.file_manager);
|
||||||
|
|
||||||
|
// Obtain handles to UI objects
|
||||||
|
ImageButton fbhomeButton = (ImageButton) findViewById(R.id.fmanagerFBHomeButton);
|
||||||
|
ImageButton cardButton = (ImageButton) findViewById(R.id.fmanagerCardButton);
|
||||||
|
ImageButton rootButton = (ImageButton) findViewById(R.id.fmanagerRootButton);
|
||||||
|
ImageButton filterButton = (ImageButton) findViewById(R.id.fmanagerFilterButton);
|
||||||
|
ImageButton backButton = (ImageButton) findViewById(R.id.fmanagerBackButton);
|
||||||
|
|
||||||
|
Button okButton = (Button) findViewById(R.id.fmanagerOkButton);
|
||||||
|
Button cancelButton = (Button) findViewById(R.id.fmanagerCancelButton);
|
||||||
|
|
||||||
|
ListView fileList = (ListView) findViewById(R.id.fileList1);
|
||||||
|
myFileListView = new FileListView(this, fileList);
|
||||||
|
|
||||||
|
|
||||||
|
fbhomeButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
// TODO
|
||||||
|
myFileListView.goAtDir(FB_HOME_DIR);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cardButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
// TODO
|
||||||
|
myFileListView.goAtDir(SDCARD_DIR);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
rootButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
// TODO
|
||||||
|
myFileListView.goAtDir(ROOT_DIR);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
filterButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
launchFilterView();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
backButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
myFileListView.goAtBack();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
okButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
// TODO
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
// TODO
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void launchFilterView() {
|
||||||
|
Intent i = new Intent(this, FilterView.class);
|
||||||
|
i.setAction(myFileListView.getFilterTypes());
|
||||||
|
startActivityForResult(i, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
if (data != null)
|
||||||
|
myFileListView.setFilter(data.getAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String FILE_MANAGER_LOG_TAG = "FileManager";
|
||||||
|
}
|
77
src/org/geometerplus/android/fbreader/library/FileUtils.java
Normal file
77
src/org/geometerplus/android/fbreader/library/FileUtils.java
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.android.fbreader.library;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class FileUtils {
|
||||||
|
|
||||||
|
// unstable - not testing
|
||||||
|
public static void copyRecursive(String src, String path)
|
||||||
|
throws IOException {
|
||||||
|
// TODO
|
||||||
|
File file = new File(src);
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
path += src;
|
||||||
|
for (String f : file.list()) {
|
||||||
|
copyRecursive(f, path);
|
||||||
|
copyFile(f, path + f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// stable
|
||||||
|
public static void copyFile(String src, String target) throws IOException {
|
||||||
|
FileChannel ic = new FileInputStream(src).getChannel();
|
||||||
|
FileChannel oc = new FileOutputStream(target).getChannel();
|
||||||
|
ic.transferTo(0, ic.size(), oc);
|
||||||
|
ic.close();
|
||||||
|
oc.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getFiltredList(File[] files, String types){
|
||||||
|
List<String> resultList = new ArrayList<String>();
|
||||||
|
for(File file : files){
|
||||||
|
if (file.isDirectory())
|
||||||
|
resultList.add(file.getName());
|
||||||
|
else if (condition(file, types))
|
||||||
|
resultList.add(file.getName());
|
||||||
|
}
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean condition(File file, String types) {
|
||||||
|
return condition(file.getName(), types);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean condition(String val, String types) {
|
||||||
|
for (String type : types.split("[\\s]+")) {
|
||||||
|
if (val.endsWith(type))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,99 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.android.fbreader.library;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.ui.android.R;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
|
|
||||||
|
public class FilterView extends Activity{
|
||||||
|
|
||||||
|
List<CheckBox> myListChBox = new ArrayList<CheckBox>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.filter);
|
||||||
|
|
||||||
|
myListChBox.add((CheckBox) findViewById(R.id.checkboxTypeTXT));
|
||||||
|
myListChBox.add((CheckBox) findViewById(R.id.checkboxTypeFB2));
|
||||||
|
myListChBox.add((CheckBox) findViewById(R.id.checkboxTypePDF));
|
||||||
|
myListChBox.add((CheckBox) findViewById(R.id.checkboxTypeDOC));
|
||||||
|
myListChBox.add((CheckBox) findViewById(R.id.checkboxTypeDOCX));
|
||||||
|
myListChBox.add((CheckBox) findViewById(R.id.checkboxTypeODT));
|
||||||
|
|
||||||
|
setCurrentTypes();
|
||||||
|
|
||||||
|
CheckBox checkBoxAll = (CheckBox)findViewById(R.id.checkboxAll);
|
||||||
|
checkBoxAll.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
for (CheckBox ch : myListChBox){
|
||||||
|
ch.setChecked(isChecked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Button cancelButton = (Button) findViewById(R.id.cancelButton);
|
||||||
|
Button okButton = (Button) findViewById(R.id.okButton);
|
||||||
|
|
||||||
|
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
okButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
String filterStr = "";
|
||||||
|
for (CheckBox ch : myListChBox){
|
||||||
|
if (ch.isChecked())
|
||||||
|
filterStr += ch.getText().toString() + " ";
|
||||||
|
}
|
||||||
|
setResult(1, new Intent(filterStr));
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCurrentTypes(){
|
||||||
|
String types = getIntent().getAction();
|
||||||
|
if (types.equals(""))
|
||||||
|
return;
|
||||||
|
for (String type : types.split("[\\s]+")) {
|
||||||
|
for(CheckBox chBox : myListChBox){
|
||||||
|
if (type.equals(chBox.getText().toString())){
|
||||||
|
chBox.setChecked(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,6 +25,7 @@ import android.app.ListActivity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
||||||
|
@ -133,7 +134,7 @@ abstract class LibraryBaseActivity extends ListActivity {
|
||||||
mySelectedBookPath = selectedBookPath;
|
mySelectedBookPath = selectedBookPath;
|
||||||
|
|
||||||
// TODO delete later
|
// TODO delete later
|
||||||
// Log.v();
|
Log.v(FileManager.FILE_MANAGER_LOG_TAG, "===" + myTreePath + mySelectedBookPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -37,8 +37,6 @@ import org.geometerplus.fbreader.library.Library;
|
||||||
import org.geometerplus.zlibrary.ui.android.R;
|
import org.geometerplus.zlibrary.ui.android.R;
|
||||||
|
|
||||||
import org.geometerplus.android.fbreader.SQLiteBooksDatabase;
|
import org.geometerplus.android.fbreader.SQLiteBooksDatabase;
|
||||||
import org.geometerplus.android.fbreader.fmanager.FileManager;
|
|
||||||
import org.geometerplus.android.fbreader.fmanager.FilterView;
|
|
||||||
import org.geometerplus.android.fbreader.tree.ZLAndroidTree;
|
import org.geometerplus.android.fbreader.tree.ZLAndroidTree;
|
||||||
|
|
||||||
public class LibraryTopLevelActivity extends LibraryBaseActivity {
|
public class LibraryTopLevelActivity extends LibraryBaseActivity {
|
||||||
|
@ -112,7 +110,7 @@ public class LibraryTopLevelActivity extends LibraryBaseActivity {
|
||||||
private void runFileManager(){
|
private void runFileManager(){
|
||||||
Log.v(FileManager.FILE_MANAGER_LOG_TAG, "runFileManager()");
|
Log.v(FileManager.FILE_MANAGER_LOG_TAG, "runFileManager()");
|
||||||
Intent i = new Intent(this, FileManager.class);
|
Intent i = new Intent(this, FileManager.class);
|
||||||
startActivityForResult(i, 1);
|
startActivity(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
60
src/org/geometerplus/android/fbreader/library/ReturnRes.java
Normal file
60
src/org/geometerplus/android/fbreader/library/ReturnRes.java
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.android.fbreader.library;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import android.app.ProgressDialog;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
|
public class ReturnRes implements Runnable {
|
||||||
|
|
||||||
|
private int myCurIdx = 0;
|
||||||
|
private List<String> myOrders;
|
||||||
|
private ArrayAdapter<String> myAdapter;
|
||||||
|
private ProgressDialog myProgressDialog;
|
||||||
|
|
||||||
|
public ReturnRes(List<String> orders, ArrayAdapter<String> adapter,
|
||||||
|
ProgressDialog pd) {
|
||||||
|
myOrders = orders;
|
||||||
|
myAdapter = adapter;
|
||||||
|
myProgressDialog = pd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
myCurIdx = 0;
|
||||||
|
myOrders.clear();
|
||||||
|
myAdapter.clear();
|
||||||
|
myAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
if (myOrders != null && myOrders.size() > 0) {
|
||||||
|
myAdapter.notifyDataSetChanged();
|
||||||
|
int i = myCurIdx;
|
||||||
|
for (i = myCurIdx; i < myOrders.size(); i++) {
|
||||||
|
myAdapter.add(myOrders.get(i));
|
||||||
|
}
|
||||||
|
myCurIdx = i;
|
||||||
|
}
|
||||||
|
myAdapter.notifyDataSetChanged();
|
||||||
|
myProgressDialog.dismiss();
|
||||||
|
}
|
||||||
|
};
|
154
src/org/geometerplus/android/fbreader/library/SmartFilter.java
Normal file
154
src/org/geometerplus/android/fbreader/library/SmartFilter.java
Normal file
|
@ -0,0 +1,154 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geometerplus.android.fbreader.library;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class SmartFilter implements Runnable {
|
||||||
|
|
||||||
|
private Activity myParent;
|
||||||
|
private Runnable myAction;
|
||||||
|
private List<String> myOrders;
|
||||||
|
|
||||||
|
private File myFile;
|
||||||
|
private String myNewTypes;
|
||||||
|
|
||||||
|
private String myCurPath = "";
|
||||||
|
private List<String> myCurFiles = new ArrayList<String>();
|
||||||
|
private String myCurTypes = "";
|
||||||
|
|
||||||
|
|
||||||
|
public SmartFilter(Activity parent, List<String> orders, Runnable action) {
|
||||||
|
myParent = parent;
|
||||||
|
myOrders = orders;
|
||||||
|
myAction = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreferences(File file, String types) {
|
||||||
|
myFile = file;
|
||||||
|
myNewTypes = types;
|
||||||
|
((ReturnRes) myAction).refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
getOrders();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getOrders() {
|
||||||
|
try {
|
||||||
|
if (myCurPath.equals(myFile.getPath())
|
||||||
|
&& compareTypes(myCurTypes, myNewTypes))
|
||||||
|
getOrderInCurrentDir();
|
||||||
|
else
|
||||||
|
getOrderInNewDir();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("BACKGROUND_PROC", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getOrderInCurrentDir() {
|
||||||
|
String delTypes = "";
|
||||||
|
for (String curType : myCurTypes.split("[\\s]+")) {
|
||||||
|
if (myNewTypes.indexOf(curType.trim()) < 0)
|
||||||
|
delTypes += curType + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> newListFiles = new ArrayList<String>();
|
||||||
|
for (String file : myCurFiles) {
|
||||||
|
if (!Thread.currentThread().isInterrupted()) {
|
||||||
|
|
||||||
|
// В реальных условиях здесь
|
||||||
|
// код будет красивее
|
||||||
|
// timeKiller() - работаем c файлом
|
||||||
|
// FIXME delete later!!!
|
||||||
|
// timeKiller(); // TODO DELETE LATER
|
||||||
|
|
||||||
|
String fileName = null;
|
||||||
|
if (!condition(file, delTypes))
|
||||||
|
fileName = file;
|
||||||
|
if (!Thread.currentThread().isInterrupted() && fileName != null) {
|
||||||
|
myOrders.add(fileName);
|
||||||
|
newListFiles.add(fileName);
|
||||||
|
}
|
||||||
|
myParent.runOnUiThread(myAction);
|
||||||
|
}
|
||||||
|
myCurFiles = newListFiles;
|
||||||
|
myParent.runOnUiThread(myAction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getOrderInNewDir() {
|
||||||
|
myCurPath = myFile.getPath();
|
||||||
|
for (File file : myFile.listFiles()) {
|
||||||
|
if (!Thread.currentThread().isInterrupted()) {
|
||||||
|
|
||||||
|
// В реальных условиях здесь
|
||||||
|
// код будет красивее
|
||||||
|
// timeKiller() - работаем c файлом
|
||||||
|
// FIXME delete later!!!
|
||||||
|
// timeKiller(); // TODO DELETE LATER
|
||||||
|
|
||||||
|
String fileName = null;
|
||||||
|
if (file.isDirectory())
|
||||||
|
fileName = file.getName();
|
||||||
|
else if (condition(file, myNewTypes))
|
||||||
|
fileName = file.getName();
|
||||||
|
if (!Thread.currentThread().isInterrupted() && fileName != null) {
|
||||||
|
myOrders.add(fileName);
|
||||||
|
myCurFiles.add(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
myParent.runOnUiThread(myAction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
myParent.runOnUiThread(myAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean condition(File file, String types) {
|
||||||
|
return condition(file.getName(), types);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean condition(String val, String types) {
|
||||||
|
if (types.equals(""))
|
||||||
|
return true;
|
||||||
|
for (String type : types.split("[\\s]+")) {
|
||||||
|
if (val.endsWith(type))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean compareTypes(String curTypes, String newTypes) {
|
||||||
|
if (newTypes.equals(""))
|
||||||
|
return false;
|
||||||
|
if (newTypes.length() > curTypes.length())
|
||||||
|
return false;
|
||||||
|
for (String newType : newTypes.split("[\\s]+")) {
|
||||||
|
if (curTypes.indexOf(newType.trim()) < 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue