android: Add open document functionality to the document browser
To investigate: sometimes the MainActivity that displays the document crashes. Change-Id: I0f49e4449bfd8d5123153f04c4316d20d6e7ef22
This commit is contained in:
parent
150ae4e8db
commit
a21808f407
3 changed files with 96 additions and 106 deletions
|
@ -31,80 +31,73 @@
|
|||
<action android:name="android.intent.action.VIEW" />
|
||||
<action android:name="android.intent.action.EDIT" />
|
||||
<action android:name="android.intent.action.PICK" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
|
||||
<!--<activity android:name=".MainActivity">-->
|
||||
<!--<intent-filter>-->
|
||||
<!--<action android:name="android.intent.action.MAIN" />-->
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<action android:name="android.intent.action.EDIT" />
|
||||
<action android:name="android.intent.action.PICK" />
|
||||
|
||||
<!--<category android:name="android.intent.category.LAUNCHER" />-->
|
||||
<!--</intent-filter>-->
|
||||
<!--<intent-filter>-->
|
||||
<!--<action android:name="android.intent.action.VIEW" />-->
|
||||
<!--<action android:name="android.intent.action.EDIT" />-->
|
||||
<!--<action android:name="android.intent.action.PICK" />-->
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<!--<category android:name="android.intent.category.DEFAULT" />-->
|
||||
<data android:scheme="file" />
|
||||
<data android:scheme="content" />
|
||||
|
||||
<!--<data android:scheme="file" />-->
|
||||
<!--<data android:scheme="content" />-->
|
||||
<!-- ODF -->
|
||||
<data android:mimeType="application/vnd.oasis.opendocument.text" />
|
||||
<data android:mimeType="application/vnd.oasis.opendocument.graphics" />
|
||||
<data android:mimeType="application/vnd.oasis.opendocument.presentation" />
|
||||
<data android:mimeType="application/vnd.oasis.opendocument.spreadsheet" />
|
||||
<data android:mimeType="application/vnd.oasis.opendocument.text-flat-xml" />
|
||||
<data android:mimeType="application/vnd.oasis.opendocument.graphics-flat-xml" />
|
||||
<data android:mimeType="application/vnd.oasis.opendocument.presentation-flat-xml" />
|
||||
<data android:mimeType="application/vnd.oasis.opendocument.spreadsheet-flat-xml" />
|
||||
|
||||
<!--<!– ODF –>-->
|
||||
<!--<data android:mimeType="application/vnd.oasis.opendocument.text" />-->
|
||||
<!--<data android:mimeType="application/vnd.oasis.opendocument.graphics" />-->
|
||||
<!--<data android:mimeType="application/vnd.oasis.opendocument.presentation" />-->
|
||||
<!--<data android:mimeType="application/vnd.oasis.opendocument.spreadsheet" />-->
|
||||
<!--<data android:mimeType="application/vnd.oasis.opendocument.text-flat-xml" />-->
|
||||
<!--<data android:mimeType="application/vnd.oasis.opendocument.graphics-flat-xml" />-->
|
||||
<!--<data android:mimeType="application/vnd.oasis.opendocument.presentation-flat-xml" />-->
|
||||
<!--<data android:mimeType="application/vnd.oasis.opendocument.spreadsheet-flat-xml" />-->
|
||||
<!-- ODF templates -->
|
||||
<data android:mimeType="application/vnd.oasis.opendocument.text-template" />
|
||||
<data android:mimeType="application/vnd.oasis.opendocument.spreadsheet-template" />
|
||||
<data android:mimeType="application/vnd.oasis.opendocument.graphics-template" />
|
||||
<!-- Seems at least Android 5.0 does not recognize this as the mime type of .otp files. -->
|
||||
<data android:mimeType="application/vnd.oasis.opendocument.presentation-template" />
|
||||
|
||||
<!--<!– ODF templates –>-->
|
||||
<!--<data android:mimeType="application/vnd.oasis.opendocument.text-template" />-->
|
||||
<!--<data android:mimeType="application/vnd.oasis.opendocument.spreadsheet-template" />-->
|
||||
<!--<data android:mimeType="application/vnd.oasis.opendocument.graphics-template" />-->
|
||||
<!--<!– Seems at least Android 5.0 does not recognize this as the mime type of .otp files. –>-->
|
||||
<!--<data android:mimeType="application/vnd.oasis.opendocument.presentation-template" />-->
|
||||
<!-- MS -->
|
||||
<data android:mimeType="application/rtf" />
|
||||
<data android:mimeType="text/rtf" />
|
||||
<data android:mimeType="application/msword" />
|
||||
<data android:mimeType="application/vnd.ms-powerpoint" />
|
||||
<data android:mimeType="application/vnd.ms-excel" />
|
||||
<data android:mimeType="application/vnd.visio" />
|
||||
<data android:mimeType="application/vnd.visio.xml" />
|
||||
<data android:mimeType="application/x-mspublisher" />
|
||||
|
||||
<!--<!– MS –>-->
|
||||
<!--<data android:mimeType="application/rtf" />-->
|
||||
<!--<data android:mimeType="text/rtf" />-->
|
||||
<!--<data android:mimeType="application/msword" />-->
|
||||
<!--<data android:mimeType="application/vnd.ms-powerpoint" />-->
|
||||
<!--<data android:mimeType="application/vnd.ms-excel" />-->
|
||||
<!--<data android:mimeType="application/vnd.visio" />-->
|
||||
<!--<data android:mimeType="application/vnd.visio.xml" />-->
|
||||
<!--<data android:mimeType="application/x-mspublisher" />-->
|
||||
<!-- OOXML -->
|
||||
<data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
|
||||
<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.presentation" />
|
||||
<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.slideshow" />
|
||||
<data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document" />
|
||||
|
||||
<!--<!– OOXML –>-->
|
||||
<!--<data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />-->
|
||||
<!--<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.presentation" />-->
|
||||
<!--<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.slideshow" />-->
|
||||
<!--<data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document" />-->
|
||||
<!-- OOXML templates -->
|
||||
<data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.template" />
|
||||
<data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.template" />
|
||||
<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.template" />
|
||||
|
||||
<!--<!– OOXML templates –>-->
|
||||
<!--<data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.template" />-->
|
||||
<!--<data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.template" />-->
|
||||
<!--<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.template" />-->
|
||||
|
||||
<!--<!– OTHER –>-->
|
||||
<!--<data android:mimeType="text/csv" />-->
|
||||
<!--<data android:mimeType="text/comma-separated-values" />-->
|
||||
<!--<data android:mimeType="application/vnd.ms-works" />-->
|
||||
<!--<data android:mimeType="application/vnd.apple.keynote" />-->
|
||||
<!--<data android:mimeType="application/x-abiword" />-->
|
||||
<!--<data android:mimeType="application/x-pagemaker" />-->
|
||||
<!--<data android:mimeType="image/x-emf" />-->
|
||||
<!--<data android:mimeType="image/x-svm" />-->
|
||||
<!--<data android:mimeType="image/x-wmf" />-->
|
||||
<!--<data android:mimeType="image/svg+xml" />-->
|
||||
<!--</intent-filter>-->
|
||||
<!--</activity>-->
|
||||
<!-- OTHER -->
|
||||
<data android:mimeType="text/csv" />
|
||||
<data android:mimeType="text/comma-separated-values" />
|
||||
<data android:mimeType="application/vnd.ms-works" />
|
||||
<data android:mimeType="application/vnd.apple.keynote" />
|
||||
<data android:mimeType="application/x-abiword" />
|
||||
<data android:mimeType="application/x-pagemaker" />
|
||||
<data android:mimeType="image/x-emf" />
|
||||
<data android:mimeType="image/x-svm" />
|
||||
<data android:mimeType="image/x-wmf" />
|
||||
<data android:mimeType="image/svg+xml" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Document Provider Settings Activity -->
|
||||
<activity android:name=".storage.DocumentProviderSettingsActivity"
|
||||
|
|
|
@ -114,6 +114,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
|
||||
|
||||
AssetManager assetManager = getResources().getAssets();
|
||||
|
||||
ApplicationInfo applicationInfo = getApplicationInfo();
|
||||
|
@ -125,7 +127,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
String cacheDir = getApplication().getCacheDir().getAbsolutePath();
|
||||
String apkFile = getApplication().getPackageResourcePath();
|
||||
|
||||
String urlToLoad = "file://" + dataDir + "/hello-world.odt";
|
||||
// String urlToLoad = "file://" + dataDir + "/hello-world.odt";
|
||||
String urlToLoad=getIntent().getStringExtra("URI");
|
||||
|
||||
createLOOLWSD(dataDir, cacheDir, apkFile, assetManager, urlToLoad);
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.Manifest;
|
|||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
|
@ -56,6 +57,7 @@ import com.google.android.material.navigation.NavigationView;
|
|||
import org.libreoffice.androidapp.AboutDialogFragment;
|
||||
import org.libreoffice.androidapp.LOKitShell;
|
||||
import org.libreoffice.androidapp.LocaleHelper;
|
||||
import org.libreoffice.androidapp.MainActivity;
|
||||
import org.libreoffice.androidapp.R;
|
||||
import org.libreoffice.androidapp.storage.DocumentProviderFactory;
|
||||
import org.libreoffice.androidapp.storage.DocumentProviderSettingsActivity;
|
||||
|
@ -553,48 +555,37 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
|
|||
|
||||
public void open(final IFile document) {
|
||||
addDocumentToRecents(document);
|
||||
//TODO finish document opening
|
||||
// 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
|
||||
// try {
|
||||
// return document[0].getDocument();
|
||||
// }
|
||||
// catch (final RuntimeException e) {
|
||||
// final Activity activity = LibreOfficeUIActivity.this;
|
||||
// activity.runOnUiThread(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// Toast.makeText(activity, e.getMessage(),
|
||||
// Toast.LENGTH_SHORT).show();
|
||||
// }
|
||||
// });
|
||||
// Log.e(LOGTAG, e.getMessage(), e.getCause());
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onPostExecute(File file) {
|
||||
// if (file != null) {
|
||||
// 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);
|
||||
//
|
||||
// // these extras allow to rebuild the IFile object in LOMainActivity
|
||||
// i.putExtra("org.libreoffice.document_provider_id",
|
||||
// documentProvider.getId());
|
||||
// i.putExtra("org.libreoffice.document_uri",
|
||||
// document.getUri());
|
||||
//
|
||||
// startActivity(i);
|
||||
// }
|
||||
// }
|
||||
// }.execute(document);
|
||||
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
|
||||
try {
|
||||
return document[0].getDocument();
|
||||
}
|
||||
catch (final RuntimeException e) {
|
||||
final Activity activity = LibreOfficeUIActivity.this;
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(activity, e.getMessage(),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
Log.e(LOGTAG, e.getMessage(), e.getCause());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(File file) {
|
||||
if (file != null) {
|
||||
Intent intent = new Intent(getBaseContext(), MainActivity.class);
|
||||
intent.putExtra("URI", document.getUri().toString());
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
}.execute(document);
|
||||
}
|
||||
|
||||
// Opens an Input dialog to get the name of new file
|
||||
|
@ -611,7 +602,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
|
|||
input.setText(defaultFileName);
|
||||
layout.addView(input);
|
||||
|
||||
|
||||
//warning text to notify the user that such a file already exists
|
||||
final TextView warningText = new TextView(this);
|
||||
warningText.setText("A file with this name already exits, and it will be overwritten.");
|
||||
|
@ -625,7 +615,11 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
|
|||
builder.setPositiveButton(R.string.action_create, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
createNewFile(currentDirectory.getUri().getPath() + input.getText().toString(),extension);
|
||||
final String path = currentDirectory.getUri().getPath() + input.getText().toString();
|
||||
createNewFile(path, extension);
|
||||
Intent intent = new Intent(getBaseContext(), MainActivity.class);
|
||||
intent.putExtra("URI", path);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue