[Libreoffice-commits] core.git: 4 commits - android/experimental
Jacobo Aragunde Pérez
jaragunde at igalia.com
Tue Feb 10 01:41:35 PST 2015
android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java | 150 ++++++----
1 file changed, 103 insertions(+), 47 deletions(-)
New commits:
commit cc9d29ff7b781b5f1392e13bb9a21bc05229da8a
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date: Tue Jan 27 11:55:02 2015 +0000
Android: run open(IFile) in a different thread.
Change-Id: I3a7023dba7621f9bd066edb9c0894df48313b117
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 8c93b41..25870c0 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -272,12 +272,24 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
}
public void open(IFile document) {
- File file = document.getDocument();
- Intent i = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
- String packageName = getApplicationContext().getPackageName();
- ComponentName componentName = new ComponentName(packageName, LibreOfficeMainActivity.class.getName());
- i.setComponent(componentName);
- startActivity(i);
+ new AsyncTask<IFile, Void, File>() {
+ @Override
+ protected File doInBackground(IFile... document) {
+ // this operation may imply network access and must be run in
+ // a different thread
+ return document[0].getDocument();
+ }
+
+ @Override
+ protected void onPostExecute(File file) {
+ Intent i = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
+ String packageName = getApplicationContext().getPackageName();
+ ComponentName componentName = new ComponentName(packageName,
+ LibreOfficeMainActivity.class.getName());
+ i.setComponent(componentName);
+ startActivity(i);
+ }
+ }.execute(document);
}
private void open(int position) {
commit 4810f108c4d7c2e4ff79fd5cecbe60900f68068c
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date: Wed Jan 21 10:59:40 2015 +0000
Android: run openParentDirectory() in a different thread.
The Document Provider framework will implement access to network
services in the future, and network operations must be run in separate
threads.
Change-Id: Ifcba8f28cc4dbffaf2946c12749aa38d0eb11923
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 5606b1c..8c93b41 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -289,6 +289,22 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
}
}
+ private void openParentDirectory() {
+ new AsyncTask<Void, Void, IFile>() {
+ @Override
+ protected IFile doInBackground(Void... dir) {
+ // this operation may imply network access and must be run in
+ // a different thread
+ return currentDirectory.getParent();
+ }
+
+ @Override
+ protected void onPostExecute(IFile result) {
+ openDirectory(result);
+ }
+ }.execute();
+ }
+
private void share(int position) {
File file = filePaths.get(position).getDocument();
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
@@ -323,7 +339,7 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
switch (item.getItemId()) {
case android.R.id.home:
if( !currentDirectory.equals( homeDirectory ) ){
- openDirectory(currentDirectory.getParent());
+ openParentDirectory();
}
break;
case R.id.menu_view_toggle:
commit bc8cb4e3b2a1fc4b84bf366945dd72e9ebeb00ce
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date: Tue Jan 20 19:01:28 2015 +0100
Android: run openDirectory() in a different thread.
The Document Provider framework will implement access to network
services in the future, and network operations must be run in separate
threads.
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index efd4105..5606b1c 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -182,6 +182,25 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
}
+ private void refreshView() {
+ // enable home icon as "up" if required
+ if (!currentDirectory.equals(homeDirectory)) {
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ } else {
+ getActionBar().setDisplayHomeAsUpEnabled(false);
+ }
+ // refresh view
+ if (viewMode == GRID_VIEW) {
+ gv.setAdapter(new GridItemAdapter(getApplicationContext(),
+ currentDirectory, filePaths));
+ } else {
+ lv.setAdapter(new ListItemAdapter(getApplicationContext(),
+ filePaths));
+ }
+ // close drawer if it was open
+ drawerLayout.closeDrawer(drawerList);
+ }
+
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
@@ -224,49 +243,32 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
@Override
protected void onPostExecute(Void result) {
- // enable home icon as "up" if required
- if (!currentDirectory.equals(homeDirectory)) {
- getActionBar().setDisplayHomeAsUpEnabled(true);
- }
- // refresh view
- if (viewMode == GRID_VIEW) {
- gv.setAdapter(new GridItemAdapter(getApplicationContext(),
- currentDirectory, filePaths));
- } else {
- lv.setAdapter(new ListItemAdapter(getApplicationContext(),
- filePaths));
- }
- // close drawer
- drawerLayout.closeDrawer(drawerList);
+ refreshView();
}
}.execute(provider);
}
public void openDirectory(IFile dir) {
- currentDirectory = dir;
- if( !currentDirectory.equals( homeDirectory )){
- ActionBar actionBar = getActionBar();
- actionBar.setDisplayHomeAsUpEnabled(true);
- }else{
- ActionBar actionBar = getActionBar();
- actionBar.setDisplayHomeAsUpEnabled( false );
- }
- filePaths = currentDirectory.listFiles(FileUtilities.getFileFilter(filterMode));
- // FileUtilities.sortFiles( filePaths, sortMode );
- /*
- for( int i = 0; i < fileNames.length; i++){
- fileNames[ i ] = filePaths[ i ].getName();
- if( !FileUtilities.hasThumbnail( filePaths[ i ] ) )
- {
- new ThumbnailGenerator( filePaths[ i ] );
- }
- }
- */
- if( viewMode == GRID_VIEW){
- gv.setAdapter( new GridItemAdapter(getApplicationContext(), currentDirectory, filePaths ) );
- }else{
- lv.setAdapter( new ListItemAdapter(getApplicationContext(), filePaths) );
- }
+ if (dir == null)
+ return;
+
+ new AsyncTask<IFile, Void, Void>() {
+ @Override
+ protected Void doInBackground(IFile... dir) {
+ // get list of files:
+ // this operation may imply network access and must be run in
+ // a different thread
+ currentDirectory = dir[0];
+ filePaths = currentDirectory.listFiles(FileUtilities
+ .getFileFilter(filterMode));
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void result) {
+ refreshView();
+ }
+ }.execute(dir);
}
public void open(IFile document) {
commit ca022d5047fe252e4164008535cdc2ff156dbe7e
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date: Fri Jan 16 12:32:15 2015 +0100
Android: run IDocumentProvider setup in a different thread.
The Document Provider framework will implement access to network
services in the future, and network operations must be run in separate
threads.
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 6fcd5aa..efd4105 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -38,6 +38,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.DataSetObserver;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
@@ -111,10 +112,9 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
DocumentProviderFactory.initialize(this);
documentProviderFactory = DocumentProviderFactory.getInstance();
- //Set the "home" - top level - directory.
- documentProvider = documentProviderFactory.getDefaultProvider();
- homeDirectory = documentProvider.getRootDirectory();
- currentDirectory = homeDirectory;
+ // init UI and populate with contents from the provider
+ createUI();
+ switchToDocumentProvider(documentProviderFactory.getDefaultProvider());
}
public void createUI(){
@@ -142,30 +142,22 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
bgSplit.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
actionBar.setSplitBackgroundDrawable(bgSplit);
- if( !currentDirectory.equals( homeDirectory )){
- actionBar.setDisplayHomeAsUpEnabled(true);
- }
-
if( viewMode == GRID_VIEW){
// code to make a grid view
setContentView(R.layout.file_grid);
gv = (GridView)findViewById(R.id.file_explorer_grid_view);
- filePaths = currentDirectory.listFiles(FileUtilities.getFileFilter(filterMode));
gv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
open(position);
}
});
- gv.setAdapter( new GridItemAdapter(getApplicationContext(), currentDirectory, filePaths ) );
actionBar.setSelectedNavigationItem( filterMode + 1 );//This triggers the listener which modifies the view.
registerForContextMenu(gv);
}else{
setContentView(R.layout.file_list);
lv = (ListView)findViewById( R.id.file_explorer_list_view);
lv.setClickable(true);
- filePaths = currentDirectory.listFiles(FileUtilities.getFileFilter(filterMode));
- lv.setAdapter( new ListItemAdapter(getApplicationContext(), filePaths) );
actionBar.setSelectedNavigationItem( filterMode + 1 );
registerForContextMenu(lv);
}
@@ -183,10 +175,8 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
@Override
public void onItemClick(AdapterView parent, View view,
int position, long id) {
- documentProvider = documentProviderFactory.getProvider(position);
- homeDirectory = documentProvider.getRootDirectory();
- currentDirectory = homeDirectory;
- createUI();
+ switchToDocumentProvider(documentProviderFactory
+ .getProvider(position));
}
});
@@ -216,6 +206,42 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga
}
}
+ private void switchToDocumentProvider(IDocumentProvider provider) {
+
+ new AsyncTask<IDocumentProvider, Void, Void>() {
+ @Override
+ protected Void doInBackground(IDocumentProvider... provider) {
+ // switch document provider:
+ // these operations may imply network access and must be run in
+ // a different thread
+ documentProvider = provider[0];
+ homeDirectory = documentProvider.getRootDirectory();
+ currentDirectory = homeDirectory;
+ filePaths = currentDirectory.listFiles(FileUtilities
+ .getFileFilter(filterMode));
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void result) {
+ // enable home icon as "up" if required
+ if (!currentDirectory.equals(homeDirectory)) {
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+ // refresh view
+ if (viewMode == GRID_VIEW) {
+ gv.setAdapter(new GridItemAdapter(getApplicationContext(),
+ currentDirectory, filePaths));
+ } else {
+ lv.setAdapter(new ListItemAdapter(getApplicationContext(),
+ filePaths));
+ }
+ // close drawer
+ drawerLayout.closeDrawer(drawerList);
+ }
+ }.execute(provider);
+ }
+
public void openDirectory(IFile dir) {
currentDirectory = dir;
if( !currentDirectory.equals( homeDirectory )){
More information about the Libreoffice-commits
mailing list