1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 09:49:19 +02:00

new background preference (in progress) + tips are back

This commit is contained in:
Nikolay Pultsin 2014-08-25 17:30:26 +04:00
parent 8d1d11aef3
commit 31e75b7b2d
14 changed files with 271 additions and 13 deletions

View file

@ -327,6 +327,7 @@
<service android:name="org.geometerplus.android.fbreader.httpd.DataService" android:launchMode="singleTask" android:process=":dataService" android:exported="false"/> <service android:name="org.geometerplus.android.fbreader.httpd.DataService" android:launchMode="singleTask" android:process=":dataService" android:exported="false"/>
<service android:name="group.pals.android.lib.ui.filechooser.services.LocalFileProvider" android:exported="false"/> <service android:name="group.pals.android.lib.ui.filechooser.services.LocalFileProvider" android:exported="false"/>
<activity android:name="group.pals.android.lib.ui.filechooser.FileChooserActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/> <activity android:name="group.pals.android.lib.ui.filechooser.FileChooserActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
<activity android:name="org.geometerplus.android.fbreader.preferences.background.Chooser" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
<activity android:name="org.geometerplus.android.util.FolderListDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/> <activity android:name="org.geometerplus.android.util.FolderListDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
<activity android:name="org.geometerplus.android.util.EditTagsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/> <activity android:name="org.geometerplus.android.util.EditTagsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
<activity android:name="org.geometerplus.android.util.EditAuthorsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/> <activity android:name="org.geometerplus.android.util.EditAuthorsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>

View file

@ -327,6 +327,7 @@
<service android:name="org.geometerplus.android.fbreader.httpd.DataService" android:launchMode="singleTask" android:process=":dataService" android:exported="false"/> <service android:name="org.geometerplus.android.fbreader.httpd.DataService" android:launchMode="singleTask" android:process=":dataService" android:exported="false"/>
<service android:name="group.pals.android.lib.ui.filechooser.services.LocalFileProvider" android:exported="false"/> <service android:name="group.pals.android.lib.ui.filechooser.services.LocalFileProvider" android:exported="false"/>
<activity android:name="group.pals.android.lib.ui.filechooser.FileChooserActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/> <activity android:name="group.pals.android.lib.ui.filechooser.FileChooserActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
<activity android:name="org.geometerplus.android.fbreader.preferences.background.Chooser" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
<activity android:name="org.geometerplus.android.util.FolderListDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/> <activity android:name="org.geometerplus.android.util.FolderListDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
<activity android:name="org.geometerplus.android.util.EditTagsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/> <activity android:name="org.geometerplus.android.util.EditTagsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
<activity android:name="org.geometerplus.android.util.EditAuthorsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/> <activity android:name="org.geometerplus.android.util.EditAuthorsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>

View file

@ -616,6 +616,11 @@
<node name="colors" value="Colors &amp; wallpapers"> <node name="colors" value="Colors &amp; wallpapers">
<node name="summary" value="Color settings"/> <node name="summary" value="Color settings"/>
<node name="background" value="Background"> <node name="background" value="Background">
<node name="chooser">
<node name="solidColor" value="Solid color…"/>
<node name="predefined" value="Predefined image…"/>
<node name="selectFile" value="Select file…"/>
</node>
<node name="solidColor" value="Solid color"/> <node name="solidColor" value="Solid color"/>
<node name="leather" value="Leather"/> <node name="leather" value="Leather"/>
<node name="sepia" value="Sepia"/> <node name="sepia" value="Sepia"/>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
>
<TextView
android:id="@+id/background_chooser_item_title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
/>
<View
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>

View file

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:orientation="horizontal"
>
<yuku.ambilwarna.widget.AmbilWarnaPrefWidgetView
android:id="@+id/background_preference_widget"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical|left"
android:focusable="false"
android:clickable="false"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="13dip"
android:gravity="center_vertical|left"
android:orientation="vertical"
>
<TextView
android:id="@+id/background_preference_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/background_preference_summary"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3"
/>
</LinearLayout>

View file

@ -186,7 +186,7 @@ public final class FBReader extends Activity implements ZLApplicationWindow {
public void run() { public void run() {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
//new TipRunner().start(); new TipRunner().start();
DictionaryUtil.init(FBReader.this, null); DictionaryUtil.init(FBReader.this, null);
final Intent intent = getIntent(); final Intent intent = getIntent();
if (intent != null && FBReaderIntents.Action.PLUGIN.equals(intent.getAction())) { if (intent != null && FBReaderIntents.Action.PLUGIN.equals(intent.getAction())) {

View file

@ -44,13 +44,14 @@ import org.geometerplus.fbreader.fbreader.*;
import org.geometerplus.fbreader.fbreader.options.*; import org.geometerplus.fbreader.fbreader.options.*;
import org.geometerplus.fbreader.network.sync.SyncData; import org.geometerplus.fbreader.network.sync.SyncData;
import org.geometerplus.fbreader.network.sync.SyncUtil; import org.geometerplus.fbreader.network.sync.SyncUtil;
//import org.geometerplus.fbreader.tips.TipsManager; import org.geometerplus.fbreader.tips.TipsManager;
import org.geometerplus.android.fbreader.DictionaryUtil; import org.geometerplus.android.fbreader.DictionaryUtil;
import org.geometerplus.android.fbreader.FBReader; import org.geometerplus.android.fbreader.FBReader;
import org.geometerplus.android.fbreader.libraryService.BookCollectionShadow; import org.geometerplus.android.fbreader.libraryService.BookCollectionShadow;
import org.geometerplus.android.fbreader.network.auth.ActivityNetworkContext; import org.geometerplus.android.fbreader.network.auth.ActivityNetworkContext;
import org.geometerplus.android.fbreader.preferences.fileChooser.FileChooserCollection; import org.geometerplus.android.fbreader.preferences.fileChooser.FileChooserCollection;
import org.geometerplus.android.fbreader.preferences.background.BackgroundPreference;
import org.geometerplus.android.fbreader.sync.SyncOperations; import org.geometerplus.android.fbreader.sync.SyncOperations;
import org.geometerplus.android.util.UIUtil; import org.geometerplus.android.util.UIUtil;
@ -447,6 +448,9 @@ public class PreferenceActivity extends ZLPreferenceActivity {
final Screen colorsScreen = createPreferenceScreen("colors"); final Screen colorsScreen = createPreferenceScreen("colors");
colorsScreen.addPreference(new BackgroundPreference(
this, profile, colorsScreen.Resource.getResource("background")
));
final WallpaperPreference wallpaperPreference = new WallpaperPreference( final WallpaperPreference wallpaperPreference = new WallpaperPreference(
this, profile, colorsScreen.Resource.getResource("background") this, profile, colorsScreen.Resource.getResource("background")
) { ) {
@ -681,8 +685,8 @@ public class PreferenceActivity extends ZLPreferenceActivity {
keyBindings.getOption(KeyEvent.KEYCODE_BACK, true), backKeyLongPressActions keyBindings.getOption(KeyEvent.KEYCODE_BACK, true), backKeyLongPressActions
)); ));
//final Screen tipsScreen = createPreferenceScreen("tips"); final Screen tipsScreen = createPreferenceScreen("tips");
//tipsScreen.addOption(TipsManager.Instance().ShowTipsOption, "showTips"); tipsScreen.addOption(TipsManager.Instance().ShowTipsOption, "showTips");
final Screen aboutScreen = createPreferenceScreen("about"); final Screen aboutScreen = createPreferenceScreen("about");
aboutScreen.addPreference(new InfoPreference( aboutScreen.addPreference(new InfoPreference(

View file

@ -40,14 +40,17 @@ class ZLColorPreference extends ColorPreference {
myTitle = resource.getResource(resourceKey).getValue(); myTitle = resource.getResource(resourceKey).getValue();
} }
@Override
public String getTitle() { public String getTitle() {
return myTitle; return myTitle;
} }
@Override
protected ZLColor getSavedColor() { protected ZLColor getSavedColor() {
return myOption.getValue(); return myOption.getValue();
} }
@Override
protected void saveColor(ZLColor color) { protected void saveColor(ZLColor color) {
myOption.setValue(color); myOption.setValue(color);
} }

View file

@ -0,0 +1,92 @@
/*
* Copyright (C) 2009-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.background;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.preference.Preference;
import android.view.View;
import android.widget.TextView;
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.options.ZLStringOption;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.zlibrary.ui.android.util.ZLAndroidColorUtil;
import org.geometerplus.fbreader.fbreader.options.ColorProfile;
public class BackgroundPreference extends Preference {
private final ZLResource myResource;
private final ColorProfile myProfile;
public BackgroundPreference(Context context, ColorProfile profile, ZLResource resource) {
super(context);
setWidgetLayoutResource(R.layout.background_preference);
myResource = resource;
myProfile = profile;
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
final TextView titleView =
(TextView)view.findViewById(R.id.background_preference_title);
titleView.setText(myResource.getValue());
final TextView summaryView =
(TextView)view.findViewById(R.id.background_preference_summary);
final View previewWidget = view.findViewById(R.id.background_preference_widget);
final String value = myProfile.WallpaperOption.getValue();
if (value.length() == 0) {
summaryView.setText(myResource.getResource("solidColor").getValue());
previewWidget.setBackgroundColor(
ZLAndroidColorUtil.rgb(myProfile.BackgroundOption.getValue())
);
} else {
if (value.startsWith("/")) {
summaryView.setText(value.substring(value.lastIndexOf("/") + 1));
} else {
final String key =
value.substring(value.lastIndexOf("/") + 1, value.lastIndexOf("."));
summaryView.setText(myResource.getResource(key).getValue());
}
try {
previewWidget.setBackgroundDrawable(
new BitmapDrawable(
getContext().getResources(),
ZLFile.createFileByPath(value).getInputStream()
)
);
} catch (Throwable t) {
// ignore
}
}
}
@Override
protected void onClick() {
((Activity)getContext()).startActivity(new Intent(getContext(), Chooser.class));
}
}

View file

@ -0,0 +1,62 @@
/*
* Copyright (C) 2009-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.background;
import android.app.ListActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.android.util.FileChooserUtil;
public class Chooser extends ListActivity implements AdapterView.OnItemClickListener {
private final ZLResource myResource = ZLResource.resource("Preferences").getResource("colors").getResource("background");
@Override
protected void onStart() {
super.onStart();
setTitle(myResource.getValue());
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, R.layout.background_chooser_item, R.id.background_chooser_item_title
);
final ZLResource chooserResource = myResource.getResource("chooser");
adapter.add(chooserResource.getResource("solidColor").getValue());
adapter.add(chooserResource.getResource("predefined").getValue());
adapter.add(chooserResource.getResource("selectFile").getValue());
setListAdapter(adapter);
getListView().setOnItemClickListener(this);
}
public final void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.err.println("CLICKED:" + position);
switch (position) {
case 0:
break;
case 1:
break;
case 2:
FileChooserUtil.runFileChooser(this, 2, myResource.getValue(), "");
break;
}
}
}

View file

@ -51,6 +51,25 @@ public abstract class FileChooserUtil {
activity.startActivityForResult(intent, requestCode); activity.startActivityForResult(intent, requestCode);
} }
public static void runFileChooser(
Activity activity,
int requestCode,
String title,
String initialValue
) {
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._ActionBar, true);
intent.putExtra(FileChooserActivity._SaveLastLocation, false);
intent.putExtra(FileChooserActivity._DisplayHiddenFiles, false);
intent.putExtra(
FileChooserActivity._FilterMode,
IFileProvider.FilterMode.FilesOnly
);
activity.startActivityForResult(intent, requestCode);
}
public static void runDirectoryChooser( public static void runDirectoryChooser(
Activity activity, Activity activity,
int requestCode, int requestCode,

View file

@ -139,7 +139,8 @@ public class TipsManager {
? Action.None : Action.Download; ? Action.None : Action.Download;
} }
} else if (!TipsAreInitializedOption.getValue()) { } else if (!TipsAreInitializedOption.getValue()) {
return Action.Initialize; //return Action.Initialize;
return Action.None;
} }
return Action.None; return Action.None;
} }

View file

@ -789,10 +789,10 @@ public class FileChooserActivity extends Activity {
if(mIsActionBar){ if(mIsActionBar){
viewGroupFooterContainer.setVisibility(View.VISIBLE); viewGroupFooterContainer.setVisibility(View.VISIBLE);
viewGroupFooterBottom.setVisibility(View.VISIBLE); viewGroupFooterBottom.setVisibility(View.VISIBLE);
if(mFileProvider.getFilterMode() != IFileProvider.FilterMode.FilesOnly){ if (mFileProvider.getFilterMode() != IFileProvider.FilterMode.FilesOnly) {
mBtnOk.setVisibility(View.VISIBLE); mBtnOk.setVisibility(View.VISIBLE);
mBtnOk.setOnClickListener(mBtnOk_ActionBar_OnClickListener); mBtnOk.setOnClickListener(mBtnOk_ActionBar_OnClickListener);
}else{ } else {
mBtnOk.setVisibility(View.GONE); mBtnOk.setVisibility(View.GONE);
} }
mBtnCancel.setVisibility(View.VISIBLE); mBtnCancel.setVisibility(View.VISIBLE);
@ -1465,8 +1465,8 @@ public class FileChooserActivity extends Activity {
* @param files * @param files
* list of {@link IFile} * list of {@link IFile}
*/ */
private void doFinish(IFile... files) { private void doFinish(IFile ... files) {
List<IFile> list = new ArrayList<IFile>(); final List<IFile> list = new ArrayList<IFile>();
for (IFile f : files) for (IFile f : files)
list.add(f); list.add(f);
doFinish((ArrayList<IFile>) list); doFinish((ArrayList<IFile>) list);
@ -1483,7 +1483,7 @@ public class FileChooserActivity extends Activity {
// set results // set results
switch(mFileProvider.getFilterMode()){ switch(mFileProvider.getFilterMode()){
case FilesOnly: case FilesOnly:
if(files == null || files.isEmpty()){ if (files == null || files.isEmpty()) {
setResult(RESULT_CANCELED); setResult(RESULT_CANCELED);
finish(); finish();
return; return;