mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
file chooser options
This commit is contained in:
parent
94d21365d3
commit
41c8aac22e
4 changed files with 247 additions and 0 deletions
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010-2014 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.preferences.fileChooser;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
||||||
|
import org.geometerplus.zlibrary.core.options.ZLStringListOption;
|
||||||
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
|
public class FileChooserCollection {
|
||||||
|
private final Context myContext;
|
||||||
|
private final List<FileChooserPreference> myPreferences = new ArrayList<FileChooserPreference>();
|
||||||
|
|
||||||
|
public FileChooserCollection(Context context) {
|
||||||
|
myContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileChooserPreference createPreference(ZLResource rootResource, String resourceKey, ZLStringListOption option) {
|
||||||
|
return createPreference(rootResource, resourceKey, option, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileChooserPreference createPreference(ZLResource rootResource, String resourceKey, ZLStringListOption option, Runnable onValueSetAction) {
|
||||||
|
final FileChooserPreference preference = new FileChooserStringListPreference(
|
||||||
|
myContext, rootResource, resourceKey, option, myPreferences.size(), onValueSetAction
|
||||||
|
);
|
||||||
|
myPreferences.add(preference);
|
||||||
|
return preference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileChooserPreference createPreference(ZLResource rootResource, String resourceKey, ZLStringOption option) {
|
||||||
|
final FileChooserPreference preference = new FileChooserStringPreference(
|
||||||
|
myContext, rootResource, resourceKey, option, myPreferences.size()
|
||||||
|
);
|
||||||
|
myPreferences.add(preference);
|
||||||
|
return preference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(int index, String value) {
|
||||||
|
try {
|
||||||
|
myPreferences.get(index).setValue(value);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010-2014 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.preferences.fileChooser;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
import android.preference.Preference;
|
||||||
|
|
||||||
|
import group.pals.android.lib.ui.filechooser.FileChooserActivity;
|
||||||
|
import group.pals.android.lib.ui.filechooser.services.IFileProvider;
|
||||||
|
import group.pals.android.lib.ui.filechooser.io.localfile.LocalFile;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
|
abstract class FileChooserPreference extends Preference {
|
||||||
|
private final int myRegCode;
|
||||||
|
|
||||||
|
FileChooserPreference(Context context, ZLResource rootResource, String resourceKey, int regCode) {
|
||||||
|
super(context);
|
||||||
|
|
||||||
|
myRegCode = regCode;
|
||||||
|
|
||||||
|
setTitle(rootResource.getResource(resourceKey).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onClick() {
|
||||||
|
final Intent intent = new Intent(getContext(), FileChooserActivity.class);
|
||||||
|
intent.putExtra(FileChooserActivity._Rootpath, (Parcelable)new LocalFile(getStringValue()));
|
||||||
|
intent.putExtra(FileChooserActivity._ActionBar, true);
|
||||||
|
intent.putExtra(FileChooserActivity._SaveLastLocation, false);
|
||||||
|
//intent.putExtra(FileChooserActivity._FilterMode, IFileProvider.FilterMode.AnyDirectories);
|
||||||
|
//intent.putExtra(FileChooserActivity._FilterMode, IFileProvider.FilterMode.FilesOnly);
|
||||||
|
//intent.putExtra(FileChooserActivity._FilterMode, IFileProvider.FilterMode.FilesAndDirectories);
|
||||||
|
intent.putExtra(FileChooserActivity._FilterMode, IFileProvider.FilterMode.DirectoriesOnly);
|
||||||
|
((Activity)getContext()).startActivityForResult(intent, myRegCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract String getStringValue();
|
||||||
|
protected abstract void setValue(String value);
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010-2014 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.preferences.fileChooser;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.options.ZLStringListOption;
|
||||||
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
||||||
|
|
||||||
|
class FileChooserStringListPreference extends FileChooserPreference {
|
||||||
|
private final ZLStringListOption myOption;
|
||||||
|
private final Runnable myOnValueSetAction;
|
||||||
|
|
||||||
|
FileChooserStringListPreference(Context context, ZLResource rootResource, String resourceKey, ZLStringListOption option, int regCode, Runnable onValueSetAction) {
|
||||||
|
super(context, rootResource, resourceKey, regCode);
|
||||||
|
|
||||||
|
myOption = option;
|
||||||
|
myOnValueSetAction = onValueSetAction;
|
||||||
|
|
||||||
|
setSummary(getStringValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getStringValue() {
|
||||||
|
final List<String> values = myOption.getValue();
|
||||||
|
return values.isEmpty() ? "" : values.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setValue(String value) {
|
||||||
|
if (MiscUtil.isEmptyString(value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> currentValues = myOption.getValue();
|
||||||
|
if (currentValues.size() != 1 || !currentValues.get(0).equals(value)) {
|
||||||
|
myOption.setValue(Collections.singletonList(value));
|
||||||
|
setSummary(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (myOnValueSetAction != null) {
|
||||||
|
myOnValueSetAction.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010-2014 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.preferences.fileChooser;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
||||||
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
||||||
|
|
||||||
|
class FileChooserStringPreference extends FileChooserPreference {
|
||||||
|
private final ZLStringOption myOption;
|
||||||
|
|
||||||
|
FileChooserStringPreference(Context context, ZLResource rootResource, String resourceKey, ZLStringOption option, int regCode) {
|
||||||
|
super(context, rootResource, resourceKey, regCode);
|
||||||
|
myOption = option;
|
||||||
|
|
||||||
|
setSummary(getStringValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getStringValue() {
|
||||||
|
return myOption.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setValue(String value) {
|
||||||
|
if (MiscUtil.isEmptyString(value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String currentValue = myOption.getValue();
|
||||||
|
if (!currentValue.equals(value)) {
|
||||||
|
myOption.setValue(value);
|
||||||
|
setSummary(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue