summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorIain Billett <iainbillett@gmail.com>2012-07-31 18:01:47 +0100
committerMichael Meeks <michael.meeks@suse.com>2012-08-07 15:23:54 +0100
commit12fff840aba5e6d93d9becf9efcf94b4849c36e0 (patch)
tree47548aa76d6aaebb24fe998fb6975c534d8132bd /android
parent779baa0572f5d2593e2347600b95a6db5f693bc5 (diff)
Async loading of thumbnails.
Change-Id: I385f5fce8b332b2b9eaa5e6c4dc58516f4cfa9b8
Diffstat (limited to 'android')
-rw-r--r--android/experimental/LibreOffice4Android/res/layout/file_explorer_grid_item.xml1
-rw-r--r--android/experimental/LibreOffice4Android/src/org/libreoffice/ui/GridItemAdapter.java7
-rw-r--r--android/experimental/LibreOffice4Android/src/org/libreoffice/ui/LibreOfficeUIActivity.java127
3 files changed, 73 insertions, 62 deletions
diff --git a/android/experimental/LibreOffice4Android/res/layout/file_explorer_grid_item.xml b/android/experimental/LibreOffice4Android/res/layout/file_explorer_grid_item.xml
index ae5bb022eb5c..62609be5600b 100644
--- a/android/experimental/LibreOffice4Android/res/layout/file_explorer_grid_item.xml
+++ b/android/experimental/LibreOffice4Android/res/layout/file_explorer_grid_item.xml
@@ -16,6 +16,7 @@
android:layout_height="142dp"
android:paddingTop="15dp"
android:paddingBottom="10dp"
+ android:scaleType="fitStart"
android:layout_gravity="center" >
</ImageView>
diff --git a/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/GridItemAdapter.java b/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/GridItemAdapter.java
index 983aba914783..664a04e10c92 100644
--- a/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/GridItemAdapter.java
+++ b/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/GridItemAdapter.java
@@ -59,7 +59,7 @@ public class GridItemAdapter extends BaseAdapter{
return null;//filePaths[ position ];
}
- public long getItemId(int arg0) {
+ public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@@ -72,10 +72,10 @@ public class GridItemAdapter extends BaseAdapter{
View gridView;
if (convertView == null) {
+ gridView = new View(mContext);
} else {
gridView = (View) convertView;
}
- gridView = new View(mContext);
// get layout from mobile.xml
gridView = inflater.inflate(R.layout.file_explorer_grid_item, null);
@@ -135,4 +135,7 @@ public class GridItemAdapter extends BaseAdapter{
return gridView;
}
+ public void update(){
+ this.notifyDataSetChanged();
+ }
}
diff --git a/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/LibreOfficeUIActivity.java
index 8a9b1cbd340e..c5cfc531e14c 100644
--- a/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -215,7 +215,7 @@ public class LibreOfficeUIActivity extends SherlockActivity implements ActionBar
fileNames[ i ] = filePaths[ i ].getName();
if( !FileUtilities.hasThumbnail( filePaths[ i ] ) )
{
- //new ThumbnailGenerator( filePaths[ i ] );
+ new ThumbnailGenerator( filePaths[ i ] );
}
}
if( viewMode == GRID_VIEW){
@@ -485,6 +485,11 @@ public class LibreOfficeUIActivity extends SherlockActivity implements ActionBar
return true;
}
+ private int dpToPx( int dp ){
+ final float scale = getApplicationContext().getResources().getDisplayMetrics().density;
+ return (int) (dp * scale + 0.5f);
+ }
+
class ListItemAdapter implements ListAdapter{
private Context mContext;
private File[] filePaths;
@@ -633,64 +638,11 @@ class ListItemAdapter implements ListAdapter{
ThumbnailGenerator( File file ){
this.file = file;
- try {
- long t0 = System.currentTimeMillis();
- long t1 = System.currentTimeMillis();
- timingOverhead = t1 - t0;
-
- Bootstrap.setup(LibreOfficeUIActivity.this);
-
- Bootstrap.putenv("SAL_LOG=yes");
-
- // Load a lot of shlibs here explicitly in advance because that
- // makes debugging work better, sigh
- Bootstrap.dlopen("libvcllo.so");
- Bootstrap.dlopen("libmergedlo.so");
- Bootstrap.dlopen("libswdlo.so");
- Bootstrap.dlopen("libswlo.so");
-
- // Log.i(TAG, "Sleeping NOW");
- // Thread.sleep(20000);
-
- context = com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext();
-
- Log.i(TAG, "context is" + (context!=null ? " not" : "") + " null");
-
- mcf = context.getServiceManager();
-
- Log.i(TAG, "mcf is" + (mcf!=null ? " not" : "") + " null");
-
String input = file.getAbsolutePath();
if (input == null)
input = "/assets/test1.odt";
-
- // We need to fake up an argv, and the argv[0] even needs to
- // point to some file name that we can pretend is the "program".
- // setCommandArgs() will prefix argv[0] with the app's data
- // directory.
-
- String[] argv = { "lo-document-loader", input };
-
- Bootstrap.setCommandArgs(argv);
-
- Bootstrap.initVCL();
-
- Object desktop = mcf.createInstanceWithContext
- ("com.sun.star.frame.Desktop", context);
-
- Log.i(TAG, "desktop is" + (desktop!=null ? " not" : "") + " null");
-
- Bootstrap.initUCBHelper();
-
- componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop);
-
- Log.i(TAG, "componentLoader is" + (componentLoader!=null ? " not" : "") + " null");
// Load the wanted document
new DocumentLoadTask().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, "file://" + input);
- }
- catch (Exception e) {
- e.printStackTrace(System.err);
- }
}
class DocumentLoadTask
@@ -781,13 +733,67 @@ class ListItemAdapter implements ListAdapter{
return null;
}
- protected void onPreExecute (){
- //TODO put doc loading & set-up here?
+ protected void onPreExecute ()
+ {
+ try{
+
+ }
+ catch (Exception e) {
+ e.printStackTrace(System.err);
+ }
}
protected Integer doInBackground(String... params)
{
try {
+ long t0 = System.currentTimeMillis();
+ long t1 = System.currentTimeMillis();
+ timingOverhead = t1 - t0;
+
+ Bootstrap.setup(LibreOfficeUIActivity.this);
+
+ Bootstrap.putenv("SAL_LOG=yes");
+
+ // Load a lot of shlibs here explicitly in advance because that
+ // makes debugging work better, sigh
+ Bootstrap.dlopen("libvcllo.so");
+ Bootstrap.dlopen("libmergedlo.so");
+ Bootstrap.dlopen("libswdlo.so");
+ Bootstrap.dlopen("libswlo.so");
+
+ // Log.i(TAG, "Sleeping NOW");
+ // Thread.sleep(20000);
+
+ context = com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext();
+
+ Log.i(TAG, "context is" + (context!=null ? " not" : "") + " null");
+
+ mcf = context.getServiceManager();
+
+ Log.i(TAG, "mcf is" + (mcf!=null ? " not" : "") + " null");
+
+ // We need to fake up an argv, and the argv[0] even needs to
+ // point to some file name that we can pretend is the "program".
+ // setCommandArgs() will prefix argv[0] with the app's data
+ // directory.
+
+ String[] argv = { "lo-document-loader", file.getAbsolutePath() };
+
+ Bootstrap.setCommandArgs(argv);
+
+ Bootstrap.initVCL();
+
+ Object desktop = mcf.createInstanceWithContext
+ ("com.sun.star.frame.Desktop", context);
+
+ Log.i(TAG, "desktop is" + (desktop!=null ? " not" : "") + " null");
+
+ Bootstrap.initUCBHelper();
+
+ componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop);
+
+ Log.i(TAG, "componentLoader is" + (componentLoader!=null ? " not" : "") + " null");
+
String url = params[0];
Log.i(TAG, "Attempting to load " + url);
@@ -802,9 +808,9 @@ class ListItemAdapter implements ListAdapter{
loadProps[2].Name = "Preview";
loadProps[2].Value = new Boolean(true);
- long t0 = System.currentTimeMillis();
+ t0 = System.currentTimeMillis();
doc = componentLoader.loadComponentFromURL(url, "_blank", 0, loadProps);
- long t1 = System.currentTimeMillis();
+ t1 = System.currentTimeMillis();
Log.i(TAG, "Loading took " + ((t1-t0)-timingOverhead) + " ms");
Object toolkitService = mcf.createInstanceWithContext
@@ -844,8 +850,8 @@ class ListItemAdapter implements ListAdapter{
}
protected void onPostExecute(Integer result){
- int widthInPx = 120;
- int heightInPx = 120;
+ int widthInPx = dpToPx( 100 );
+ int heightInPx = dpToPx( (int)( 100*Math.sqrt(2) ) );
ByteBuffer bb = renderPage( 0 , widthInPx , heightInPx);
Bitmap bm = Bitmap.createBitmap( widthInPx , heightInPx , Bitmap.Config.ARGB_8888);
bm.copyPixelsFromBuffer(bb);
@@ -860,6 +866,7 @@ class ListItemAdapter implements ListAdapter{
} catch (IOException e) {
// TODO: handle exception
}
+ ( (GridItemAdapter)gv.getAdapter() ).update();
}
}