Skip to content

Commit

Permalink
improve editing-experience
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTasche committed Oct 5, 2013
1 parent 117b8c2 commit 6d94f79
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 52 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="at.tomtasche.reader"
android:installLocation="auto"
android:versionCode="51"
android:versionName="2.11.5" >
android:versionCode="52"
android:versionName="2.12.0" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
Binary file removed OpenDocument.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion odf2html
Submodule odf2html updated from 51bd69 to 5671ad
10 changes: 5 additions & 5 deletions res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
android:title="@string/media_route_menu_title"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
app:showAsAction="always"/>
<!-- <item -->
<!-- android:id="@+id/menu_edit" -->
<!-- android:icon="@drawable/ic_action_edit" -->
<!-- android:title="@string/menu_edit" -->
<!-- app:showAsAction="ifRoom"/> -->
<item
android:id="@+id/menu_edit"
android:icon="@drawable/ic_action_edit"
android:title="@string/menu_edit"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_recent"
android:icon="@drawable/ic_action_heart"
Expand Down
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<string name="menu_edit">Edit</string>
<string name="edit_save">Save</string>
<string name="edit_help">Help!?</string>
<string name="edit_banner">Edit your document below and press Save</string>
<string name="menu_feedback">Feedback</string>
<string name="menu_about">About</string>
<string name="menu_remove_ads">Remove ads</string>
Expand Down
41 changes: 27 additions & 14 deletions src/at/tomtasche/reader/background/DocumentLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class DocumentLoader extends AsyncTaskLoader<Document> implements
private Throwable lastError;
private Uri uri;
private boolean limit;
private boolean translatable;
private String password;
private Document document;
private GenericDocumentTranslator<?, ?, ?> translator;
Expand All @@ -62,6 +63,10 @@ public void setLimit(boolean limit) {
this.limit = limit;
}

public void setTranslatable(boolean translatable) {
this.translatable = translatable;
}

@Override
public Throwable getLastError() {
return lastError;
Expand Down Expand Up @@ -103,6 +108,7 @@ protected void onReset() {
translator = null;
password = null;
limit = true;
translatable = false;
}

@Override
Expand All @@ -124,16 +130,28 @@ public Document loadInBackground() {
uri.toString().length()));
}

// TODO: don't delete file being displayed at the moment, but keep
// it until the new document has finished loading
AndroidFileCache.cleanup(getContext());
AndroidFileCache cache = new AndroidFileCache(getContext());

if (URI_INTRO.equals(uri)) {
stream = getContext().getAssets().open("intro.odt");
} else if (URI_ABOUT.equals(uri)) {
stream = getContext().getAssets().open("about.odt");
if (uri.getScheme() == null) {
documentFile = new LocatedOpenDocumentFile(new File(
uri.getPath()));
} else {
stream = getContext().getContentResolver().openInputStream(uri);
// TODO: don't delete file being displayed at the moment, but
// keep it until the new document has finished loading
AndroidFileCache.cleanup(getContext());

if (URI_INTRO.equals(uri)) {
stream = getContext().getAssets().open("intro.odt");
} else if (URI_ABOUT.equals(uri)) {
stream = getContext().getAssets().open("about.odt");
} else {
stream = getContext().getContentResolver().openInputStream(
uri);
}

String cachedFileName = cache.create(stream);
documentFile = new LocatedOpenDocumentFile(
cache.getFile(cachedFileName));
}

try {
Expand All @@ -144,12 +162,6 @@ public Document loadInBackground() {
e.printStackTrace();
}

AndroidFileCache cache = new AndroidFileCache(getContext());

String cachedFileName = cache.create(stream);
documentFile = new LocatedOpenDocumentFile(
cache.getFile(cachedFileName));

if (documentFile.isEncrypted()) {
if (password == null)
throw new EncryptedDocumentException();
Expand All @@ -164,6 +176,7 @@ public Document loadInBackground() {

TranslationSettings settings = new TranslationSettings();
settings.setCache(cache);
settings.setBackTranslateable(translatable);
settings.setImageStoreMode(ImageStoreMode.CACHE);

if (openDocument instanceof OpenDocumentText) {
Expand Down
16 changes: 10 additions & 6 deletions src/at/tomtasche/reader/ui/EditActionModeCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.widget.TextView;
import at.stefl.opendocument.java.odf.LocatedOpenDocumentFile;
import at.stefl.opendocument.java.odf.OpenDocument;
import at.stefl.opendocument.java.translator.Retranslator;
import at.tomtasche.reader.R;
import at.tomtasche.reader.ui.activity.MainActivity;
import at.tomtasche.reader.ui.widget.PageView;
Expand All @@ -34,7 +35,7 @@ public EditActionModeCallback(MainActivity activity, PageView pageView,
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
statusView = new TextView(activity);
statusView.setText("Getting your document ready for some changes...");
statusView.setText(R.string.edit_banner);
mode.setCustomView(statusView);

mode.getMenuInflater().inflate(R.menu.edit, menu);
Expand All @@ -44,7 +45,10 @@ public boolean onCreateActionMode(ActionMode mode, Menu menu) {

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
// reload document with translation enabled
activity.loadUri(activity.getCacheFileUri(), null, true, true);

return true;
}

@Override
Expand All @@ -59,7 +63,8 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
}

case R.id.edit_save: {
final File htmlFile = new File(activity.getCacheDir(),
// TODO: use getCacheDir() in release-build
final File htmlFile = new File(activity.getExternalCacheDir(),
"content.html");
pageView.requestHtml(htmlFile, new Runnable() {

Expand All @@ -80,9 +85,8 @@ public void run() {
((LocatedOpenDocumentFile) document
.getDocumentFile()).getFile());

// TODO: disabled for hotifx-release
// Retranslator.retranslate(documentFile.getAsDocument(),
// htmlStream, modifiedStream);
Retranslator.retranslate(documentFile.getAsDocument(),
htmlStream, modifiedStream);

modifiedStream.close();

Expand Down
16 changes: 11 additions & 5 deletions src/at/tomtasche/reader/ui/activity/DocumentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public abstract class DocumentActivity extends ActionBarActivity implements
private static final String EXTRA_URI = "uri";
private static final String EXTRA_LIMIT = "limit";
private static final String EXTRA_PASSWORD = "password";
private static final String EXTRA_TRANSLATABLE = "translatable";

private ProgressDialogFragment progressDialog;
private PageFragment pageFragment;
Expand Down Expand Up @@ -85,22 +86,24 @@ public void onCreate(Bundle savedInstanceState) {

@Override
public DocumentLoader loadUri(Uri uri) {
return loadUri(uri, null, true);
return loadUri(uri, null, true, false);
}

public DocumentLoader loadUri(Uri uri, String password) {
return loadUri(uri, password, true);
return loadUri(uri, password, true, false);
}

public DocumentLoader loadUri(Uri uri, boolean limit) {
return loadUri(uri, null, limit);
return loadUri(uri, null, limit, false);
}

public DocumentLoader loadUri(Uri uri, String password, boolean limit) {
public DocumentLoader loadUri(Uri uri, String password, boolean limit,
boolean translatable) {
Bundle bundle = new Bundle();
bundle.putString(EXTRA_PASSWORD, password);
bundle.putParcelable(EXTRA_URI, uri);
bundle.putBoolean(EXTRA_LIMIT, limit);
bundle.putBoolean(EXTRA_TRANSLATABLE, translatable);

return (DocumentLoader) getSupportLoaderManager().restartLoader(0,
bundle, this);
Expand All @@ -117,11 +120,13 @@ public UpLoader uploadUri(Uri uri) {
@Override
public Loader<Document> onCreateLoader(int id, Bundle bundle) {
boolean limit = true;
boolean translatable = false;
String password = null;
Uri uri = DocumentLoader.URI_INTRO;
if (bundle != null) {
uri = bundle.getParcelable(EXTRA_URI);
limit = bundle.getBoolean(EXTRA_LIMIT);
translatable = bundle.getBoolean(EXTRA_TRANSLATABLE);
password = bundle.getString(EXTRA_PASSWORD);
}

Expand All @@ -130,6 +135,7 @@ public Loader<Document> onCreateLoader(int id, Bundle bundle) {
DocumentLoader documentLoader = new DocumentLoader(this, uri);
documentLoader.setPassword(password);
documentLoader.setLimit(limit);
documentLoader.setTranslatable(translatable);

showProgress(documentLoader, false);

Expand Down Expand Up @@ -167,7 +173,7 @@ public void onLoadFinished(final Loader<Document> loader, Document document) {
@Override
public void run() {
loadUri(uri, ((DocumentLoader) loader).getPassword(),
false);
false, false);
}
}, AppMsg.STYLE_INFO);
}
Expand Down
71 changes: 53 additions & 18 deletions src/at/tomtasche/reader/ui/activity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.tomtasche.reader.ui.activity;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -35,6 +36,7 @@
import at.tomtasche.reader.background.DocumentLoader;
import at.tomtasche.reader.background.LoadingListener;
import at.tomtasche.reader.ui.ChromecastManager;
import at.tomtasche.reader.ui.EditActionModeCallback;
import at.tomtasche.reader.ui.FindActionModeCallback;
import at.tomtasche.reader.ui.TtsActionModeCallback;
import at.tomtasche.reader.ui.widget.DocumentChooserDialogFragment;
Expand Down Expand Up @@ -217,7 +219,39 @@ private void showAmazonAds() {

showAds(adView);

adView.loadAd(new AdTargetingOptions());
try {
adView.loadAd(new AdTargetingOptions());
} catch (Exception e) {
// (1802) os_unix.c:30011: (2)
// stat(/data/data/at.tomtasche.reader/databases/webviewCache.db) -
// (1802) statement aborts at 38: [CREATE TABLE IF NOT EXISTS
// android_metadata (locale TEXT)] disk I/O error
// Failed to open database
// '/data/data/at.tomtasche.reader/databases/webviewCache.db'.
// android.database.sqlite.SQLiteException: Failed to change locale
// for db '/data/data/at.tomtasche.reader/databases/webviewCache.db'
// to 'en_US'.
// android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:386)
// android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:218)
// android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
// android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
// android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
// android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
// android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
// android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
// android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
// android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:854)
// android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:843)
// android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:223)
// com.amazon.device.ads.Utils.isWebViewOk(Utils.java:99)
// com.amazon.device.ads.AdLayout.isWebViewOk(AdLayout.java:703)
// com.amazon.device.ads.AdLayout.loadAd(AdLayout.java:490)
// at.tomtasche.reader.ui.activity.MainActivity.showAmazonAds(MainActivity.java:222)

e.printStackTrace();

onAdFailedToLoad(null, null);
}
}

private void showGoogleAds() {
Expand Down Expand Up @@ -312,10 +346,11 @@ protected void onNewIntent(Intent intent) {
}

@Override
public DocumentLoader loadUri(Uri uri, String password, boolean limit) {
public DocumentLoader loadUri(Uri uri, String password, boolean limit,
boolean translatable) {
loadingStartTime = System.currentTimeMillis();

return super.loadUri(uri, password, limit);
return super.loadUri(uri, password, limit, translatable);
}

@Override
Expand Down Expand Up @@ -534,7 +569,7 @@ public void onClick(DialogInterface dialog, int which) {
Loader<Document> loader = getSupportLoaderManager().getLoader(0);
DocumentLoader documentLoader = (DocumentLoader) loader;

loadUri(documentLoader.getLastUri(), documentLoader.getPassword(),
loadUri(getCacheFileUri(), documentLoader.getPassword(), false,
false);

analytics.sendEvent("ui", "reload", "no-limit", null);
Expand Down Expand Up @@ -633,16 +668,16 @@ public void run() {

analytics.sendEvent("ui", "google+", null, null);
}
// case R.id.menu_edit: {
// EditActionModeCallback editActionMode = new
// EditActionModeCallback(this, getPageFragment()
// .getPageView(), getDocument().getOrigin());
// startSupportActionMode(editActionMode);
//
// analytics.sendEvent("ui", "edit", null, null);
//
// break;
// }
case R.id.menu_edit: {
EditActionModeCallback editActionMode = new EditActionModeCallback(
this, getPageFragment().getPageView(), getDocument()
.getOrigin());
startSupportActionMode(editActionMode);

analytics.sendEvent("ui", "edit", null, null);

break;
}
default: {
return super.onOptionsItemSelected(item);
}
Expand All @@ -651,6 +686,10 @@ public void run() {
return true;
}

public Uri getCacheFileUri() {
return Uri.parse(new File(getCacheDir(), "0").getAbsolutePath());
}

private void removeAds() {
if (madView != null)
madView.setVisibility(View.GONE);
Expand Down Expand Up @@ -860,8 +899,4 @@ public void onError(Throwable error, Uri uri) {
public Page getCurrentPage() {
return currentPage;
}

private void editDocument() {

}
}
3 changes: 2 additions & 1 deletion test/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<classpathentry kind="src" path="gen"/>
<classpathentry combineaccessrules="false" kind="src" path="/OpenDocument.droid"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

0 comments on commit 6d94f79

Please sign in to comment.