summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorIain Billett <iainbillett@gmail.com>2012-06-29 12:08:27 +0100
committerIain Billett <iainbillett@gmail.com>2012-07-04 18:38:23 +0100
commit75e43a66dcda016128b1dea241d630167d17c689 (patch)
treed8fad9cf313de377169a9294a41c975c574dcb1b /android
parentc42a8d41afbd8c49b68046eeb8480e04d4f072c4 (diff)
Some optimisations of the open method to re use page views where possible. work in progress
Diffstat (limited to 'android')
-rw-r--r--android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java58
1 files changed, 42 insertions, 16 deletions
diff --git a/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java b/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
index bd40040da1d4..8bacc6c07f7b 100644
--- a/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
+++ b/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
@@ -114,6 +114,7 @@ public class DocumentLoader
XDevice dummySmallDevice;
Object doc;
int pageCount;
+ int currentPage;
XRenderable renderable;
GestureDetector gestureDetector;
@@ -440,7 +441,7 @@ public class DocumentLoader
class PageViewer
extends ViewSwitcher
{
- int currentPageNumber = -1;
+ public final int currentPageNumber = -1;
TextView waitView;
PageState state = PageState.NONEXISTENT;
Bitmap bm;
@@ -488,6 +489,7 @@ public class DocumentLoader
Log.i(TAG, "PageViewer display(" + number + ")");
if (number >= 0)
waitView.setText("Page " + (number+1) + ", wait...");
+ currentPageNumber = number;
state = PageState.NONEXISTENT;
if (getDisplayedChild() == 1) {
@@ -503,7 +505,8 @@ public class DocumentLoader
PageViewer(int number)
{
super(DocumentLoader.this);
-
+ if( number < 0)
+ return
waitView = new TextView(DocumentLoader.this);
waitView.setTextSize(24);
waitView.setGravity(Gravity.CENTER);
@@ -625,6 +628,7 @@ public class DocumentLoader
flipper = (ViewFlipper)findViewById( R.id.page_flipper );
matchParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
flipper.addView( waitView , 0 , matchParent);
+ currentPage = 0;
}
protected Integer doInBackground(String... params)
{
@@ -692,14 +696,16 @@ public class DocumentLoader
matchParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
flipper.removeViewAt( 0 );
-
- //Should check that pages exist ie >=0 && < pageCount
+ currentPage = 0;
+ openPageWithPrefetching( currentPage );
+ /*
+ //open method? set current page = 0?
flipper.addView(new PageViewer(0), 0, matchParent);
for (int i = 0; i < PAGECACHE_PLUSMINUS; i++)
flipper.addView(new PageViewer(i+1), i+1, matchParent);
for (int i = 0; i < PAGECACHE_PLUSMINUS; i++)
flipper.addView(new PageViewer(-1), PAGECACHE_PLUSMINUS + i+1, matchParent);
-
+ */
ll = (LinearLayout)findViewById( R.id.navigator);
inflater = (LayoutInflater) getApplicationContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
@@ -919,18 +925,38 @@ public class DocumentLoader
public void openPageWithPrefetching( int number ){
//as a first draft clear an refill "cache" on load.
//should move views where "cache window" overlaps
- flipper.removeAllViews();
+ if(currentPage == number || number < 0 || number >= pageCount)
+ return;
+ boolean[] hits = new boolean[PAGECACHE_SIZE];
+ //flipper.removeAllViews();
flipper.addView(new PageViewer(number), 0, matchParent);
- for (int i = 0; i < PAGECACHE_PLUSMINUS; i++){
- if( number + i+1 >= 0 && number + i+1 < pageCount){//pageCount will always be correctly defined when this is called (famous last words)
- flipper.addView(new PageViewer( number + i+1), i+1, matchParent);
- }
- }
- for (int i = 0; i < PAGECACHE_PLUSMINUS; i++){
- if( number + i+1 >= 0 && number + i+1 < pageCount){
- flipper.addView(new PageViewer( number - (i+1)), PAGECACHE_PLUSMINUS + i+1, matchParent);
- }
- }
+ //If diff is > 2*+- do this
+ if( number - currentPage >= PAGECACHE_SIZE ){
+ for (int i = 0; i < PAGECACHE_PLUSMINUS; i++){
+ if( number + i+1 >= 0 && number + i+1 < pageCount){//pageCount will always be correctly defined when this is called (famous last words)
+ flipper.addView(new PageViewer( number + i+1), i+1, matchParent);
+ }
+ }
+ for (int i = 0; i < PAGECACHE_PLUSMINUS; i++){
+ if( number - i+1 >= 0 && number - i+1 < pageCount){
+ flipper.addView(new PageViewer( number - (i+1)), PAGECACHE_PLUSMINUS + i+1, matchParent);
+ }
+ }
+ }else{
+ for( int i = 0 ; i < flipper.getViewCount() ; i++){
+ if( flipper.getViewAt( i ).currentPageNumber < number - PAGECACHE_PLUSMINUS &&
+ flipper.getViewAt( i ).currentPageNumber > number + PAGECACHE_PLUSMINUS ){
+ continue;
+ }else{
+ flipper.removeViewAt( i );
+ }
+ }
+ /*have the reuseable views. Make a mapping array [differnce wrt number ] [ index ] ; */
+ }
+ currentPage = number;
+ return;
+ //else
+ //for each page if in new range => spare it
}
}