mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
new options: show new folder button & filename regexp
This commit is contained in:
parent
7a18393e5a
commit
5328375941
6 changed files with 42 additions and 25 deletions
|
@ -80,7 +80,9 @@ public class Chooser extends ListActivity implements AdapterView.OnItemClickList
|
|||
startActivityForResult(new Intent(this, PredefinedImages.class), 1);
|
||||
break;
|
||||
case 2:
|
||||
FileChooserUtil.runFileChooser(this, 2, myResource.getValue(), "");
|
||||
FileChooserUtil.runFileChooser(
|
||||
this, 2, myResource.getValue(), "", ".+\\.(jpe?g|png)"
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -88,8 +90,15 @@ public class Chooser extends ListActivity implements AdapterView.OnItemClickList
|
|||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
switch (requestCode) {
|
||||
case 1:
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
break;
|
||||
case 2:
|
||||
System.err.println("FILE DATA: " + data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,14 +55,17 @@ public abstract class FileChooserUtil {
|
|||
Activity activity,
|
||||
int requestCode,
|
||||
String title,
|
||||
String initialValue
|
||||
String initialDir,
|
||||
String regexp
|
||||
) {
|
||||
final Intent intent = new Intent(activity, FileChooserActivity.class);
|
||||
intent.putExtra(FileChooserActivity._TextResources, textResources(title));
|
||||
intent.putExtra(FileChooserActivity._Rootpath, (Parcelable)new LocalFile(initialValue));
|
||||
intent.putExtra(FileChooserActivity._Rootpath, (Parcelable)new LocalFile(initialDir));
|
||||
intent.putExtra(FileChooserActivity._ActionBar, true);
|
||||
intent.putExtra(FileChooserActivity._SaveLastLocation, false);
|
||||
intent.putExtra(FileChooserActivity._DisplayHiddenFiles, false);
|
||||
intent.putExtra(FileChooserActivity._ShowNewFolderButton, false);
|
||||
intent.putExtra(FileChooserActivity._FilenameRegExp, regexp);
|
||||
intent.putExtra(
|
||||
FileChooserActivity._FilterMode,
|
||||
IFileProvider.FilterMode.FilesOnly
|
||||
|
|
|
@ -205,6 +205,8 @@ public class FileChooserActivity extends Activity {
|
|||
public static final String _SelectFile = _ClassName + ".select_file";
|
||||
|
||||
public static final String _TextResources = _ClassName + ".text_resources";
|
||||
public static final String _ShowNewFolderButton = _ClassName + ".show_new_folder_button";
|
||||
public static final String _FilenameRegExp = _ClassName + ".file_regexp";
|
||||
// ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
@ -298,6 +300,7 @@ public class FileChooserActivity extends Activity {
|
|||
private ImageView mViewSort;
|
||||
|
||||
private HashMap<String, String> mTextResources;
|
||||
private String mFilenameRegexp;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
|
@ -346,6 +349,10 @@ public class FileChooserActivity extends Activity {
|
|||
mViewSort = (ImageView) findViewById(R.id.afc_filechooser_activity_button_sort);
|
||||
mViewFoldersView = (ImageView) findViewById(R.id.afc_filechooser_activity_button_folders_view);
|
||||
mViewCreateFolder = (ImageView) findViewById(R.id.afc_filechooser_activity_button_create_folder);
|
||||
if (!getIntent().getBooleanExtra(_ShowNewFolderButton, true)) {
|
||||
mViewCreateFolder.setVisibility(View.GONE);
|
||||
}
|
||||
mFilenameRegexp = getIntent().getStringExtra(_FilenameRegExp);
|
||||
mViewGoBack = (ImageView) findViewById(R.id.afc_filechooser_activity_button_go_back);
|
||||
mViewGoForward = (ImageView) findViewById(R.id.afc_filechooser_activity_button_go_forward);
|
||||
mViewLocations = (ViewGroup) findViewById(R.id.afc_filechooser_activity_view_locations);
|
||||
|
@ -744,7 +751,7 @@ public class FileChooserActivity extends Activity {
|
|||
mFileAdapter.clear();
|
||||
|
||||
mFileAdapter = new IFileAdapter(FileChooserActivity.this, new ArrayList<IFileDataModel>(),
|
||||
mFileProvider.getFilterMode(), mIsMultiSelection);
|
||||
mFileProvider.getFilterMode(), mFilenameRegexp, mIsMultiSelection);
|
||||
/*
|
||||
* API 13+ does not recognize AbsListView.setAdapter(), so we cast it to
|
||||
* explicit class
|
||||
|
|
|
@ -52,6 +52,7 @@ public class IFileAdapter extends BaseAdapter {
|
|||
|
||||
private final Integer[] mAdvancedSelectionOptions;
|
||||
private final IFileProvider.FilterMode mFilterMode;
|
||||
private final String mFilenameRegexp;
|
||||
private final Context mContext;
|
||||
private final FileTimeDisplay mFileTimeDisplay;
|
||||
|
||||
|
@ -71,8 +72,7 @@ public class IFileAdapter extends BaseAdapter {
|
|||
* @param multiSelection
|
||||
* see {@link FileChooserActivity#_MultiSelection}
|
||||
*/
|
||||
public IFileAdapter(Context context, List<IFileDataModel> objects, IFileProvider.FilterMode filterMode,
|
||||
boolean multiSelection) {
|
||||
public IFileAdapter(Context context, List<IFileDataModel> objects, IFileProvider.FilterMode filterMode, String filenameRegexp, boolean multiSelection) {
|
||||
// DO NOT use getApplicationContext(), due to this bug:
|
||||
// http://stackoverflow.com/questions/2634991/android-1-6-android-view-windowmanagerbadtokenexception-unable-to-add-window
|
||||
// http://code.google.com/p/android/issues/detail?id=11199
|
||||
|
@ -80,6 +80,7 @@ public class IFileAdapter extends BaseAdapter {
|
|||
mData = objects;
|
||||
mInflater = LayoutInflater.from(mContext);
|
||||
mFilterMode = filterMode;
|
||||
mFilenameRegexp = filenameRegexp;
|
||||
mMultiSelection = multiSelection;
|
||||
|
||||
switch (mFilterMode) {
|
||||
|
@ -287,17 +288,16 @@ public class IFileAdapter extends BaseAdapter {
|
|||
*/
|
||||
bag.mTxtFileName.setSingleLine(parent instanceof GridView);
|
||||
|
||||
final boolean isAccessible = FileUtils.isAccessible(file, mFilenameRegexp);
|
||||
// file icon
|
||||
bag.mImageIcon.setImageResource(FileUtils.getResIcon(file, mFilterMode));
|
||||
final ColorMatrix matrix = new ColorMatrix();
|
||||
if (!FileUtils.isAccessible(file, mFilterMode)) {
|
||||
if (!isAccessible) {
|
||||
final ColorMatrix scaleMatrix = new ColorMatrix();
|
||||
scaleMatrix.setScale(.7f, .7f, .7f, 1f);
|
||||
final ColorMatrix saturationMatrix = new ColorMatrix();
|
||||
saturationMatrix.setSaturation(0f);
|
||||
matrix.setConcat(saturationMatrix, scaleMatrix);
|
||||
bag.mTxtFileName.setEnabled(false);
|
||||
bag.mTxtFileInfo.setEnabled(false);
|
||||
}
|
||||
bag.mImageIcon.setColorFilter(new ColorMatrixColorFilter(matrix));
|
||||
|
||||
|
@ -316,6 +316,9 @@ public class IFileAdapter extends BaseAdapter {
|
|||
else
|
||||
bag.mTxtFileInfo.setText(String.format("%s, %s", Converter.sizeToStr(file.length()), time));
|
||||
|
||||
bag.mTxtFileName.setEnabled(isAccessible);
|
||||
bag.mTxtFileInfo.setEnabled(isAccessible);
|
||||
|
||||
// checkbox
|
||||
if (mMultiSelection) {
|
||||
if (FilterMode.FilesOnly.equals(mFilterMode) && file.isDirectory()) {
|
||||
|
|
|
@ -71,7 +71,7 @@ public class FileUtils {
|
|||
|
||||
return R.drawable.afc_file;
|
||||
} else if (file.isDirectory()) {
|
||||
if (filterMode != IFileProvider.FilterMode.AnyDirectories) {
|
||||
if (filterMode == IFileProvider.FilterMode.DirectoriesOnly) {
|
||||
if (file instanceof File && !((File)file).canWrite()) {
|
||||
if (file instanceof ParentFile) {
|
||||
return R.drawable.afc_folder;
|
||||
|
@ -91,24 +91,19 @@ public class FileUtils {
|
|||
return R.drawable.afc_file;
|
||||
}// getResIcon()
|
||||
|
||||
public static boolean isAccessible(IFile file, final IFileProvider.FilterMode filterMode) {
|
||||
public static boolean isAccessible(IFile file, final String regexp) {
|
||||
if (file == null || !file.exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (accessDenied(file)) {
|
||||
return false;
|
||||
}
|
||||
if (file.isFile()) {
|
||||
return true;
|
||||
return regexp == null || file.getName().matches(regexp);
|
||||
} else if (file.isDirectory()) {
|
||||
if (filterMode != IFileProvider.FilterMode.AnyDirectories) {
|
||||
if (file instanceof File && !((File)file).canWrite()) {
|
||||
return (file instanceof ParentFile || !accessDenied(file));
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return !accessDenied(file);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}// isAccessible()
|
||||
|
|
|
@ -80,7 +80,7 @@ public class ViewFilesContextMenuUtils {
|
|||
data.add(new IFileDataModel(f));
|
||||
}
|
||||
|
||||
final IFileAdapter _adapter = new IFileAdapter(context, data, FilterMode.DirectoriesOnly, false);
|
||||
final IFileAdapter _adapter = new IFileAdapter(context, data, FilterMode.DirectoriesOnly, null, false);
|
||||
|
||||
ListView listView = (ListView) LayoutInflater.from(context).inflate(R.layout.afc_listview_files, null);
|
||||
listView.setBackgroundResource(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue