mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
0.7.5: language on-the-fly change has been implemented
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1754 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
39b8f74dad
commit
4f47544ff5
7 changed files with 68 additions and 29 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.geometerplus.zlibrary.ui.android" android:versionCode="704" android:versionName="0.7.4" android:installLocation="auto">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.geometerplus.zlibrary.ui.android" android:versionCode="705" android:versionName="0.7.5" android:installLocation="auto">
|
||||
<uses-sdk android:minSdkVersion="3" />
|
||||
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
===== 0.7.5 (Sep 22, 2010) =====
|
||||
* Mistyping in Russian help has been fixed
|
||||
* On-fly language change has been implemented
|
||||
|
||||
===== 0.7.4 (Sep 20, 2010) =====
|
||||
* EMPTY-LINE tag in fb2 files is now supported
|
||||
* better support for STANZA tag in fb2
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
0.7.4
|
||||
0.7.5
|
||||
|
|
|
@ -242,11 +242,7 @@ public abstract class ZLApplication {
|
|||
}
|
||||
|
||||
void addItem(String actionId) {
|
||||
myItems.add(new Menubar.PlainItem(myResource.getResource(actionId).getValue(), actionId));
|
||||
}
|
||||
|
||||
void addSeparator() {
|
||||
myItems.add(new Menubar.Separator());
|
||||
myItems.add(new Menubar.PlainItem(myResource.getResource(actionId)));
|
||||
}
|
||||
|
||||
Menubar.Submenu addSubmenu(String key) {
|
||||
|
@ -267,12 +263,18 @@ public abstract class ZLApplication {
|
|||
//MenuBar
|
||||
public static final class Menubar extends Menu {
|
||||
public static final class PlainItem implements Item {
|
||||
public final String Name;
|
||||
public final String ActionId;
|
||||
private final ZLResource myResource;
|
||||
|
||||
public PlainItem(String name, String actionId) {
|
||||
Name = name;
|
||||
ActionId = actionId;
|
||||
public PlainItem(ZLResource resource) {
|
||||
myResource = resource;
|
||||
}
|
||||
|
||||
public String getActionId() {
|
||||
return myResource.Name;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return myResource.getValue();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -286,9 +288,6 @@ public abstract class ZLApplication {
|
|||
}
|
||||
};
|
||||
|
||||
public static final class Separator implements Item {
|
||||
};
|
||||
|
||||
public Menubar() {
|
||||
super(ZLResource.resource("menu"));
|
||||
}
|
||||
|
@ -313,8 +312,6 @@ public abstract class ZLApplication {
|
|||
processSubmenuBeforeItems(submenu);
|
||||
processMenu(submenu);
|
||||
processSubmenuAfterItems(submenu);
|
||||
} else if (item instanceof Menubar.Separator) {
|
||||
processSepartor((Menubar.Separator)item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -322,7 +319,6 @@ public abstract class ZLApplication {
|
|||
protected abstract void processSubmenuBeforeItems(Menubar.Submenu submenu);
|
||||
protected abstract void processSubmenuAfterItems(Menubar.Submenu submenu);
|
||||
protected abstract void processItem(Menubar.PlainItem item);
|
||||
protected abstract void processSepartor(Menubar.Separator separator);
|
||||
}
|
||||
|
||||
private class MenubarCreator extends ZLXMLReaderAdapter {
|
||||
|
|
|
@ -26,7 +26,10 @@ import org.geometerplus.zlibrary.core.xml.ZLXMLReaderAdapter;
|
|||
import org.geometerplus.zlibrary.core.filesystem.*;
|
||||
|
||||
final class ZLTreeResource extends ZLResource {
|
||||
public static ZLTreeResource ourRoot;
|
||||
static ZLTreeResource ourRoot;
|
||||
|
||||
private static long ourTimeStamp = 0;
|
||||
private static String ourLanguage = null;
|
||||
|
||||
private boolean myHasValue;
|
||||
private String myValue;
|
||||
|
@ -36,10 +39,25 @@ final class ZLTreeResource extends ZLResource {
|
|||
if (ourRoot == null) {
|
||||
ourRoot = new ZLTreeResource("", null);
|
||||
loadData("en");
|
||||
Locale locale = Locale.getDefault();
|
||||
String language = locale.getLanguage();
|
||||
if (!language.equals("en")) {
|
||||
loadData(language);
|
||||
ourLanguage = Locale.getDefault().getLanguage();
|
||||
if (!"en".equals(ourLanguage)) {
|
||||
loadData(ourLanguage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateLanguage() {
|
||||
final long timeStamp = System.currentTimeMillis();
|
||||
if (timeStamp > ourTimeStamp + 1000) {
|
||||
synchronized (ourRoot) {
|
||||
if (timeStamp > ourTimeStamp + 1000) {
|
||||
ourTimeStamp = timeStamp;
|
||||
final String language = Locale.getDefault().getLanguage();
|
||||
if (language != null && !language.equals(ourLanguage)) {
|
||||
ourLanguage = language;
|
||||
loadData(ourLanguage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +84,7 @@ final class ZLTreeResource extends ZLResource {
|
|||
}
|
||||
|
||||
public String getValue() {
|
||||
updateLanguage();
|
||||
return myHasValue ? myValue : ZLMissingResource.Value;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,9 +52,9 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
|
|||
myMenuStack.pop();
|
||||
}
|
||||
protected void processItem(ZLApplication.Menubar.PlainItem item) {
|
||||
MenuItem menuItem = myMenuStack.peek().add(0, myItemCount++, Menu.NONE, item.Name);
|
||||
MenuItem menuItem = myMenuStack.peek().add(0, myItemCount++, Menu.NONE, item.getTitle());
|
||||
try {
|
||||
final String fieldName = "ic_menu_" + item.ActionId.toLowerCase();
|
||||
final String fieldName = "ic_menu_" + item.getActionId().toLowerCase();
|
||||
menuItem.setIcon(R.drawable.class.getField(fieldName).getInt(null));
|
||||
} catch (NoSuchFieldException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
|
@ -62,15 +62,29 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
|
|||
menuItem.setOnMenuItemClickListener(myMenuListener);
|
||||
myMenuItemMap.put(menuItem, item);
|
||||
}
|
||||
protected void processSepartor(ZLApplication.Menubar.Separator separator) {
|
||||
//myMenuStack.peek().addSeparator(0, myItemCount++);
|
||||
}
|
||||
|
||||
private class MenuUpdater extends ZLApplication.MenuVisitor {
|
||||
private int myItemCount = Menu.FIRST;
|
||||
private Menu myRoot;
|
||||
|
||||
private MenuUpdater(Menu menu) {
|
||||
myRoot = menu;
|
||||
}
|
||||
protected void processSubmenuBeforeItems(ZLApplication.Menubar.Submenu submenu) {
|
||||
}
|
||||
protected void processSubmenuAfterItems(ZLApplication.Menubar.Submenu submenu) {
|
||||
}
|
||||
protected void processItem(ZLApplication.Menubar.PlainItem item) {
|
||||
MenuItem menuItem = myRoot.findItem(myItemCount++);
|
||||
menuItem.setTitle(item.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
private final MenuItem.OnMenuItemClickListener myMenuListener =
|
||||
new MenuItem.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
getApplication().doAction(myMenuItemMap.get(item).ActionId);
|
||||
getApplication().doAction(myMenuItemMap.get(item).getActionId());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -87,7 +101,7 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
|
|||
@Override
|
||||
protected void refreshMenu() {
|
||||
for (Map.Entry<MenuItem,ZLApplication.Menubar.PlainItem> entry : myMenuItemMap.entrySet()) {
|
||||
final String actionId = entry.getValue().ActionId;
|
||||
final String actionId = entry.getValue().getActionId();
|
||||
final ZLApplication application = getApplication();
|
||||
entry.getKey().setVisible(application.isActionVisible(actionId) && application.isActionEnabled(actionId));
|
||||
}
|
||||
|
|
|
@ -149,6 +149,12 @@ public abstract class ZLAndroidActivity extends Activity {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(final Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
View view = findViewById(R.id.main_view);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue