Comments (6)
This is what i did exactly:
- First of all, in LoadBitmapTask class i changed the
getBitmap()
method to look as follows:
public Bitmap getBitmap(int number) {
return getNextBitmap(number);
}
Note that i removed all the code that is supposed to run in another thread as it is not really needed.
- In that same class, change the
getRandomBitmap()
method to what i wrote in my last comment but leaving the array bidimensional as you mentioned. That should work.
private Bitmap getNextBitmap(int number) {
int resId = mPortraitBGs[mBGSizeIndex][number - 1];
Bitmap b = BitmapFactory.decodeResource(mResources, resId);
if (mIsLandscape) {
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap lb = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(),
matrix, true);
b.recycle();
return lb;
}
return b;
}
- In SinglePageRender as well as in DoublePagesRender classes, in the
drawPage(int number)
method change the lineBitmap background = LoadBitmapTask.get(mContext).getBitmap();
toBitmap background = LoadBitmapTask.get(mContext).getBitmap(number);
and you should be good to go.
Note that at this point the IDE will complain at compile time because there is another call to getBitmap()
method that actually needs an argument. But, as i said before, i deleted all the code that runs in another thread so this call got deleted as well.
I leave here my LoadBitmapTask class so you can take a look in case something is not clear at all:
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
public final class LoadBitmapTask {
private final static String TAG = "LoadBitmapTask";
private static LoadBitmapTask __object;
private int mQueueMaxSize;
private Resources mResources;
private int[] mPortraitBGs;
private boolean mIsLandscape;
public static LoadBitmapTask get(Context context) {
if (__object == null) {
__object = new LoadBitmapTask(context);
}
return __object;
}
public static void destroyInstance(){
if (__object != null)
__object = null;
}
private LoadBitmapTask(Context context) {
mResources = context.getResources();
mIsLandscape = false;
mQueueMaxSize = 1;
// init all available bitmaps
mPortraitBGs = new int[] {R.drawable.pag01, R.drawable.pag02, R.drawable.pag03,
R.drawable.pag04, R.drawable.pag05, R.drawable.pag06,
R.drawable.pag07, R.drawable.pag08, R.drawable.pag09,
R.drawable.pag10, R.drawable.pag11, R.drawable.pag12,
R.drawable.pag13, R.drawable.pag14, R.drawable.pag15,
R.drawable.pag16, R.drawable.pag17, R.drawable.pag18,
R.drawable.pag19, R.drawable.pag20, R.drawable.pag21,
R.drawable.pag22, R.drawable.pag23, R.drawable.pag24,
R.drawable.pag25, R.drawable.pag26, R.drawable.pag27,
R.drawable.pag28, R.drawable.pag29, R.drawable.pag30,
R.drawable.pag31, R.drawable.pag32, R.drawable.pag33,
R.drawable.pag34};
}
/**
* Acquire a bitmap to show
* <p>If there is no cached bitmap, it will load one immediately</p>
*
* @return
*/
public Bitmap getBitmap(int number) {
return getNextBitmap(number);
}
/**
* Set bitmap width , height and maximum size of cache queue
*
* @param w width of bitmap
* @param h height of bitmap
* @param maxCached maximum size of cache queue
*/
public void set(int w, int h, int maxCached) {
mIsLandscape = w > h;
if (maxCached != mQueueMaxSize) {
mQueueMaxSize = maxCached;
}
}
/**
* Load next image
*
* @param number
* @return
*/
private Bitmap getNextBitmap(int number) {
int resId = mPortraitBGs[number - 1];
Bitmap b = BitmapFactory.decodeResource(mResources, resId);
if (mIsLandscape) {
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap lb = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(),
matrix, true);
b.recycle();
return lb;
}
return b;
}
}
Another thing to point out is that i made the mPortraitBGs
array 1D and i changed images to drawable-nodpi folder so Android itself rescales the images according to device density which i believe by doing that images won't take a lot of space on memory when the app is running.
from android-pageflip.
That's an amazing answer!
I have understood the code snippet pretty well.
Along with these modifications I have disabled the following two lines from SampleActivity as well :
LoadBitmapTask.get(this).start(); //disabled this from onResume()
LoadBitmapTask.get(this).stop(); //disabled this from onPause()
I haven't modified anything else. And the code is working like a charm!!
Let me get back to you again if I come across any other issues on this.
Do you have any blogs ? I believe I can learn from that if you have any blogs / YouTube videos / or anything else.
from android-pageflip.
It took some time for me as well to figure that out.
In the PageRender class, the drawPage
method takes an argument which represents the number of the page to draw. I achieved the order of the pages by passing that argument all the way to the getRandomBitmap
method of the class LoadBitmapTask which i renamed and changed it a bit. Now it looks as follows:
/**
* Load next image
*
* @param number of page to load
* @return correctly ordered bitmap
*/
private Bitmap getNextBitmap(int number) {
int resId = mPortraitBGs[number - 1];
Bitmap b = BitmapFactory.decodeResource(mResources, resId);
if (mIsLandscape) {
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap lb = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(),
matrix, true);
b.recycle();
return lb;
}
return b;
}
This way the bitmap order should be the same as you have it in you initialization array.
Hope that helps :)
from android-pageflip.
Thanks for your input!
Based on your answer I need a few clarification:
-
How are you passing this "number" argument of drawPage(int number) from Single/DoublePageRender to LoadBitmapTask ?
-
From where should I call this new method getNextBitmap(int number) and what should be the argument value while calling this method ?
-
As you have mentioned in this new method:
int resId = mPortraitBGs[number - 1];
But mPortraitBGs[][] is basically a 2D array.
So if I want to maintain 2D array like following:
int resId = mPortraitBGs[mBGSizeIndex][number - 1];
Will this work ?
It'd also be great if you could provide those modified class files. I could integrate them in my project and try understanding the code.
from android-pageflip.
Hey, sorry for late reply, I was really busy with work untill now. I'm glad the answer helped you :)
I do have a blog but it's in Spanish and i'm not posting too frequently nor it's about coding xD
No Youtube channels nor any social network. I don't really like them, sorry.
But if you run into any issues just let me know via email if you want and i will be happy to help. My email address is on my profile here.
Good luck!
from android-pageflip.
That's fine.
I'll mail you if I come across any issues. Thanks again. :)
from android-pageflip.
Related Issues (20)
- specific position
- How to add SupportMapFragment to Canvas HOT 1
- Modify current page./redraw current page. HOT 1
- How to maintain the sequence of the page flip. HOT 1
- Landscape View in Flip Page not working HOT 3
- 如何跳转到指定页 HOT 2
- Black screen in landscape view. Realme 5 phone android 9 HOT 3
- Any suggestions on how to handle front and back pages in doublePagesRender? HOT 3
- Dynamic bitmaps HOT 5
- Navigating to a specific page HOT 1
- Incorrect Page Number. HOT 2
- Landscape Mode Issue HOT 3
- There is a problem with page ranking HOT 2
- Help
- I
- Instead of Bitmaps, does it support custom layout or webview even? HOT 1
- Can we use it on PDF? HOT 8
- Could not find com.github.eschao:android-PageFlip:1.0.2. HOT 3
- 有双页翻页效果的电子书的例子吗
- 从第二页左下角翻回第一页没有效果
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-pageflip.