Skip to content

Commit

Permalink
Merge branch 'master' into pocketbook-port
Browse files Browse the repository at this point in the history
  • Loading branch information
pkb committed Jun 6, 2011
2 parents 2b1bcc1 + a1c5eb3 commit efae3bf
Show file tree
Hide file tree
Showing 11 changed files with 392 additions and 170 deletions.
2 changes: 1 addition & 1 deletion android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.coolreader"
android:installLocation="auto"
android:versionName="3.0.46-5" android:versionCode="135">
android:versionName="3.0.46-7" android:versionCode="137">
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
Expand Down
30 changes: 14 additions & 16 deletions android/jni/battery_icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,18 @@
" .........................",
};

LVRefVec<LVImageSource> icons;

icons.add( LVCreateXPMImageSource( battery_charge ) );

icons.add( LVCreateXPMImageSource( battery0 ) );
icons.add( LVCreateXPMImageSource( battery1 ) );
icons.add( LVCreateXPMImageSource( battery2 ) );
icons.add( LVCreateXPMImageSource( battery3 ) );
icons.add( LVCreateXPMImageSource( battery4 ) );
icons.add( LVCreateXPMImageSource( battery5 ) );
icons.add( LVCreateXPMImageSource( battery6 ) );
icons.add( LVCreateXPMImageSource( battery7 ) );
icons.add( LVCreateXPMImageSource( battery8 ) );

icons.add( LVCreateXPMImageSource( battery_frame ) );
const char * * icon_bpm[] = {
battery_charge,
battery0,
battery1,
battery2,
battery3,
battery4,
battery5,
battery6,
battery7,
battery8,
battery_frame,
NULL
};

return icons;
89 changes: 59 additions & 30 deletions android/jni/readerview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,35 +138,55 @@ DECL_DEF_CR_FONT_SIZES;

#define NO_BATTERY_GAUGE 1

static LVRefVec<LVImageSource> getBatteryIcons( bool nightMode )
{
if ( !nightMode ) {
#define BATTERY_HEADER \
"28 15 5 1", \
"0 c #80000000", \
"X c #80000000", \
"o c #80AAAAAA", \
". c #80FFFFFF", \
" c None",
#include "battery_icons.h"
} else {
#undef BATTERY_HEADER
#define BATTERY_HEADER \
"28 15 5 1", \
"0 c #80000000", \
"X c #80000000", \
"o c #80888888", \
". c #80AAAAAA", \
" c None",
#include "battery_icons.h"
static void replaceColor( char * str, lUInt32 color )
{
// in line like "0 c #80000000",
// replace value of color
for ( int i=0; i<8; i++ ) {
str[i+5] = toHexDigit((color>>28) & 0xF);
color <<= 4;
}
}

static LVRefVec<LVImageSource> getBatteryIcons( lUInt32 color )
{
CRLog::debug("Making list of Battery icon bitmats");
lUInt32 cl1 = 0x00000000|(color&0xFFFFFF);
lUInt32 cl2 = 0x40000000|(color&0xFFFFFF);
lUInt32 cl3 = 0x80000000|(color&0xFFFFFF);
lUInt32 cl4 = 0xF0000000|(color&0xFFFFFF);

static char color1[] = "0 c #80000000";
static char color2[] = "X c #80000000";
static char color3[] = "o c #80AAAAAA";
static char color4[] = ". c #80FFFFFF";
#define BATTERY_HEADER \
"28 15 5 1", \
color1, \
color2, \
color3, \
color4, \
" c None",

#include "battery_icons.h"

replaceColor( color1, cl1 );
replaceColor( color2, cl2 );
replaceColor( color3, cl3 );
replaceColor( color4, cl4 );

LVRefVec<LVImageSource> icons;
for ( int i=0; icon_bpm[i]; i++ )
icons.add( LVCreateXPMImageSource( icon_bpm[i] ) );

return icons;
}

ReaderViewNative::ReaderViewNative()
{
_docview = new LVDocView(16); //16bpp

LVRefVec<LVImageSource> icons = getBatteryIcons( false );
LVRefVec<LVImageSource> icons = getBatteryIcons( 0x000000 );
_docview->setBatteryIcons( icons );

LVArray<int> sizes( cr_font_sizes, sizeof(cr_font_sizes)/sizeof(int) );
Expand Down Expand Up @@ -424,9 +444,7 @@ JNIEXPORT void JNICALL Java_org_coolreader_crengine_ReaderView_getPageImageInter
//CRLog::trace("getPageImageInternal calling bitmap->lock");
LVDrawBuf * drawbuf = BitmapAccessorInterface::getInstance()->lock(env, bitmap);
if ( drawbuf!=NULL ) {

//CRLog::trace("getPageImageInternal calling Draw drawbuf width=%d height=%d", drawbuf->GetWidth(), drawbuf->GetHeight());
p->_docview->Draw( *drawbuf );
p->_docview->Draw( *drawbuf );
//CRLog::trace("getPageImageInternal calling bitmap->unlock");
BitmapAccessorInterface::getInstance()->unlock(env, bitmap, drawbuf);
} else {
Expand Down Expand Up @@ -483,13 +501,24 @@ JNIEXPORT jboolean JNICALL Java_org_coolreader_crengine_ReaderView_applySettings
CRPropRef props = env.fromJavaProperties(_props);
CRPropRef oldProps = p->_docview->propsGetCurrent();
p->_docview->propsUpdateDefaults( props );
bool oldNightMode = oldProps->getBoolDef(PROP_NIGHT_MODE, false);
bool newNightMode = props->getBoolDef(PROP_NIGHT_MODE, false);
if ( oldNightMode!=newNightMode ) {
LVRefVec<LVImageSource> icons = getBatteryIcons( newNightMode );
//bool oldNightMode = oldProps->getBoolDef(PROP_NIGHT_MODE, false);
//bool newNightMode = props->getBoolDef(PROP_NIGHT_MODE, false);
lUInt32 oldTextColor = oldProps->getColorDef(PROP_FONT_COLOR, 0x000000);
lUInt32 newTextColor = props->getColorDef(PROP_FONT_COLOR, 0x000000);
lUInt32 oldStatusColor = oldProps->getColorDef(PROP_STATUS_FONT_COLOR, 0xFF000000);
lUInt32 newStatusColor = props->getColorDef(PROP_STATUS_FONT_COLOR, 0xFF000000);
//CRLog::debug("Text colors: %x->%x, %x->%x", oldTextColor, newTextColor, oldStatusColor, newStatusColor);
p->_docview->propsApply( props );
lUInt32 batteryColor = newStatusColor;
if ( batteryColor==0xFF000000 )
batteryColor = newTextColor;
if ( 1 || oldTextColor!=newTextColor || oldStatusColor!=newStatusColor ) { //oldNightMode!=newNightMode
//CRLog::debug("%x->%x, %x->%x: Setting Battery icon color = #%06x", oldTextColor, newTextColor, oldStatusColor, newStatusColor, batteryColor);
LVRefVec<LVImageSource> icons = getBatteryIcons( batteryColor );
//CRLog::debug("Setting list of Battery icon bitmats");
p->_docview->setBatteryIcons( icons );
//CRLog::debug("Setting list of Battery icon bitmats - done");
}
p->_docview->propsApply( props );
return JNI_TRUE;
}
#if 0
Expand Down
23 changes: 21 additions & 2 deletions android/src/org/coolreader/crengine/History.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.coolreader.crengine;

import java.io.ByteArrayInputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;

import org.coolreader.CoolReader;
Expand Down Expand Up @@ -200,17 +201,35 @@ synchronized void invalidateImages()
}
}

private static Method bitmapSetDensityMethod;
private static Method canvasSetDensityMethod;
private static boolean isNewApiChecked;
public BitmapDrawable decodeCoverPage( byte[] data )
{
try {
ByteArrayInputStream is = new ByteArrayInputStream(data);
Bitmap srcbmp = BitmapFactory.decodeStream(is);
//BitmapDrawable drawable = new BitmapDrawable(mCoolReader.getResources(), is);
//BitmapDrawable drawable = new BitmapDrawable(null, is);

if ( !isNewApiChecked ) {
isNewApiChecked = true;
try {
bitmapSetDensityMethod = Bitmap.class.getMethod("setDensity", new Class[] {int.class});
canvasSetDensityMethod = Canvas.class.getMethod("setDensity", new Class[] {int.class});
} catch ( Exception e ) {
L.w("No Bitmap.setDensity() method found");
}
}

Bitmap bmp = Bitmap.createBitmap(coverPageWidth, coverPageHeight, Bitmap.Config.ARGB_8888);
bmp.setDensity(Bitmap.DENSITY_NONE); // mCoolReader.getResources().getDisplayMetrics().densityDpi
if ( bitmapSetDensityMethod!=null )
bitmapSetDensityMethod.invoke(bmp, Bitmap.DENSITY_NONE);
//bmp.setDensity(Bitmap.DENSITY_NONE); // mCoolReader.getResources().getDisplayMetrics().densityDpi
Canvas canvas = new Canvas(bmp);
canvas.setDensity(Bitmap.DENSITY_NONE); // mCoolReader.getResources().getDisplayMetrics().densityDpi
if ( canvasSetDensityMethod!=null )
canvasSetDensityMethod.invoke(canvas, Bitmap.DENSITY_NONE);
//canvas.setDensity(Bitmap.DENSITY_NONE); // mCoolReader.getResources().getDisplayMetrics().densityDpi
canvas.drawBitmap(srcbmp, new Rect(0, 0, srcbmp.getWidth(), srcbmp.getHeight()),
new Rect(0, 0, coverPageWidth, coverPageHeight), null);
Log.d("cr3", "cover page format: " + srcbmp.getWidth() + "x" + srcbmp.getHeight());
Expand Down
2 changes: 1 addition & 1 deletion android/src/org/coolreader/crengine/OptionsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static int findBacklightSettingIndex( int value ) {
"10%", "12%", "15%", "20%", "25%", "30%", "35%", "40%", "45%", "50%", "55%", "60%", "65%", "70%", "75%", "80%", "85%", "90%", "95%", "100%",
};
int[] mInterlineSpaces = new int[] {
80, 90, 100, 110, 120, 130, 140, 150
80, 90, 100, 105, 110, 115, 120, 130, 140, 150, 160, 180, 200
};
int[] mMargins = new int[] {
0, 1, 2, 3, 4, 5, 8, 10, 12, 15, 20, 25, 30
Expand Down
Loading

0 comments on commit efae3bf

Please sign in to comment.