mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +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"?>
|
<?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" />
|
<uses-sdk android:minSdkVersion="3" />
|
||||||
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" />
|
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" />
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<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) =====
|
===== 0.7.4 (Sep 20, 2010) =====
|
||||||
* EMPTY-LINE tag in fb2 files is now supported
|
* EMPTY-LINE tag in fb2 files is now supported
|
||||||
* better support for STANZA tag in fb2
|
* 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) {
|
void addItem(String actionId) {
|
||||||
myItems.add(new Menubar.PlainItem(myResource.getResource(actionId).getValue(), actionId));
|
myItems.add(new Menubar.PlainItem(myResource.getResource(actionId)));
|
||||||
}
|
|
||||||
|
|
||||||
void addSeparator() {
|
|
||||||
myItems.add(new Menubar.Separator());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Menubar.Submenu addSubmenu(String key) {
|
Menubar.Submenu addSubmenu(String key) {
|
||||||
|
@ -267,12 +263,18 @@ public abstract class ZLApplication {
|
||||||
//MenuBar
|
//MenuBar
|
||||||
public static final class Menubar extends Menu {
|
public static final class Menubar extends Menu {
|
||||||
public static final class PlainItem implements Item {
|
public static final class PlainItem implements Item {
|
||||||
public final String Name;
|
private final ZLResource myResource;
|
||||||
public final String ActionId;
|
|
||||||
|
|
||||||
public PlainItem(String name, String actionId) {
|
public PlainItem(ZLResource resource) {
|
||||||
Name = name;
|
myResource = resource;
|
||||||
ActionId = actionId;
|
}
|
||||||
|
|
||||||
|
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() {
|
public Menubar() {
|
||||||
super(ZLResource.resource("menu"));
|
super(ZLResource.resource("menu"));
|
||||||
}
|
}
|
||||||
|
@ -313,8 +312,6 @@ public abstract class ZLApplication {
|
||||||
processSubmenuBeforeItems(submenu);
|
processSubmenuBeforeItems(submenu);
|
||||||
processMenu(submenu);
|
processMenu(submenu);
|
||||||
processSubmenuAfterItems(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 processSubmenuBeforeItems(Menubar.Submenu submenu);
|
||||||
protected abstract void processSubmenuAfterItems(Menubar.Submenu submenu);
|
protected abstract void processSubmenuAfterItems(Menubar.Submenu submenu);
|
||||||
protected abstract void processItem(Menubar.PlainItem item);
|
protected abstract void processItem(Menubar.PlainItem item);
|
||||||
protected abstract void processSepartor(Menubar.Separator separator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MenubarCreator extends ZLXMLReaderAdapter {
|
private class MenubarCreator extends ZLXMLReaderAdapter {
|
||||||
|
|
|
@ -26,7 +26,10 @@ import org.geometerplus.zlibrary.core.xml.ZLXMLReaderAdapter;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.*;
|
import org.geometerplus.zlibrary.core.filesystem.*;
|
||||||
|
|
||||||
final class ZLTreeResource extends ZLResource {
|
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 boolean myHasValue;
|
||||||
private String myValue;
|
private String myValue;
|
||||||
|
@ -36,14 +39,29 @@ final class ZLTreeResource extends ZLResource {
|
||||||
if (ourRoot == null) {
|
if (ourRoot == null) {
|
||||||
ourRoot = new ZLTreeResource("", null);
|
ourRoot = new ZLTreeResource("", null);
|
||||||
loadData("en");
|
loadData("en");
|
||||||
Locale locale = Locale.getDefault();
|
ourLanguage = Locale.getDefault().getLanguage();
|
||||||
String language = locale.getLanguage();
|
if (!"en".equals(ourLanguage)) {
|
||||||
if (!language.equals("en")) {
|
loadData(ourLanguage);
|
||||||
loadData(language);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void loadData(String language) {
|
public static void loadData(String language) {
|
||||||
final String fileName = language + ".xml";
|
final String fileName = language + ".xml";
|
||||||
ResourceTreeReader reader = new ResourceTreeReader();
|
ResourceTreeReader reader = new ResourceTreeReader();
|
||||||
|
@ -66,6 +84,7 @@ final class ZLTreeResource extends ZLResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
|
updateLanguage();
|
||||||
return myHasValue ? myValue : ZLMissingResource.Value;
|
return myHasValue ? myValue : ZLMissingResource.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,9 +52,9 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
|
||||||
myMenuStack.pop();
|
myMenuStack.pop();
|
||||||
}
|
}
|
||||||
protected void processItem(ZLApplication.Menubar.PlainItem item) {
|
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 {
|
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));
|
menuItem.setIcon(R.drawable.class.getField(fieldName).getInt(null));
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
|
@ -62,15 +62,29 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
|
||||||
menuItem.setOnMenuItemClickListener(myMenuListener);
|
menuItem.setOnMenuItemClickListener(myMenuListener);
|
||||||
myMenuItemMap.put(menuItem, item);
|
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 =
|
private final MenuItem.OnMenuItemClickListener myMenuListener =
|
||||||
new MenuItem.OnMenuItemClickListener() {
|
new MenuItem.OnMenuItemClickListener() {
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
getApplication().doAction(myMenuItemMap.get(item).ActionId);
|
getApplication().doAction(myMenuItemMap.get(item).getActionId());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -87,7 +101,7 @@ public final class ZLAndroidApplicationWindow extends ZLApplicationWindow {
|
||||||
@Override
|
@Override
|
||||||
protected void refreshMenu() {
|
protected void refreshMenu() {
|
||||||
for (Map.Entry<MenuItem,ZLApplication.Menubar.PlainItem> entry : myMenuItemMap.entrySet()) {
|
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();
|
final ZLApplication application = getApplication();
|
||||||
entry.getKey().setVisible(application.isActionVisible(actionId) && application.isActionEnabled(actionId));
|
entry.getKey().setVisible(application.isActionVisible(actionId) && application.isActionEnabled(actionId));
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,6 +149,12 @@ public abstract class ZLAndroidActivity extends Activity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPrepareOptionsMenu(final Menu menu) {
|
||||||
|
super.onPrepareOptionsMenu(menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
View view = findViewById(R.id.main_view);
|
View view = findViewById(R.id.main_view);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue