fix #20, add viewer for big picture

This commit is contained in:
houxg
2017-02-14 13:46:17 +08:00
parent 5c164e99cd
commit b1d60c906f
12 changed files with 119 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ repositories {
mavenCentral()
jcenter()
maven { url "https://www.jitpack.io" }
maven { url "http://dl.bintray.com/piasy/maven" }
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
@@ -109,5 +110,6 @@ dependencies {
compile 'net.danlew:android.joda:2.9.5'
compile group: 'com.tencent.bugly', name: 'crashreport_upgrade', version: '1.2.1'
compile 'com.elvishew:xlog:1.3.0'
compile 'com.github.piasy:BigImageViewer:1.2.5'
compile 'com.github.piasy:GlideImageLoader:1.2.5'
}

View File

@@ -45,6 +45,8 @@
<activity
android:name=".ui.AboutActivity"
android:label="@string/about" />
<activity
android:name=".ui.PictureViewerActivity" />
<service
android:name=".background.NoteSyncService"

View File

@@ -188,6 +188,10 @@
var title = target.innerHTML;
e.preventDefault();
nativeCallbackHandler.linkTo(link);
} else if (target.tagName === 'IMG') {
var src = target.getAttribute('src');
e.preventDefault();
nativeCallbackHandler.onClickedImage(src);
}
}

View File

@@ -9,6 +9,8 @@ import android.text.TextUtils;
import com.elvishew.xlog.LogLevel;
import com.elvishew.xlog.XLog;
import com.facebook.stetho.Stetho;
import com.github.piasy.biv.BigImageViewer;
import com.github.piasy.biv.loader.glide.GlideImageLoader;
import com.raizlabs.android.dbflow.config.FlowConfig;
import com.raizlabs.android.dbflow.config.FlowManager;
import com.tencent.bugly.Bugly;
@@ -35,7 +37,7 @@ public class Leamonax extends Application {
if (!TextUtils.isEmpty(BuildConfig.BUGLY_KEY)) {
initBugly();
}
BigImageViewer.initialize(GlideImageLoader.with(this));
EventBus.builder()
.logNoSubscriberMessages(false)
.sendNoSubscriberEvent(false)

View File

@@ -80,6 +80,7 @@ public abstract class Editor {
void onFormatChanged(Map<Format, Object> enabledFormats);
void onCursorChanged(Map<Format, Object> enabledFormats);
void linkTo(String url);
void onClickedImage(String url);
}
protected class EditorClient extends WebViewClient {

View File

@@ -156,6 +156,11 @@ public class RichTextEditor extends Editor implements TinnyMceCallback.TinnyMceL
mListener.linkTo(url);
}
@Override
public void onClickedImage(String url) {
mListener.onClickedImage(url);
}
@Override
public void onCursorChanged(Map<Format, Object> enabledFormats) {
mListener.onCursorChanged(enabledFormats);

View File

@@ -25,6 +25,8 @@ public class TinnyMceCallback {
void linkTo(String url);
void onClickedImage(String url);
void onCursorChanged(Map<Editor.Format, Object> enabledFormats);
}
@@ -43,6 +45,13 @@ public class TinnyMceCallback {
}
}
@JavascriptInterface
public void onClickedImage(String url) {
if (mListener != null) {
mListener.onClickedImage(url);
}
}
@JavascriptInterface
public void onCursorChanged(String data) {
XLog.i(TAG + data);

View File

@@ -58,6 +58,20 @@ public class NoteFileService {
return SCHEME.equals(uri.getScheme()) && IMAGE_PATH_WITH_SLASH.equals(uri.getPath());
}
public static String getImagePath(Uri uri) {
String localId = uri.getQueryParameter("id");
NoteFile noteFile = AppDataBase.getNoteFileByLocalId(localId);
if (noteFile == null) {
return null;
}
if (!TextUtils.isEmpty(noteFile.getLocalPath())) {
File file = new File(noteFile.getLocalPath());
return file.isFile() ? noteFile.getLocalPath() : null;
} else {
return null;
}
}
public static InputStream getImage(String localId) {
NoteFile noteFile = AppDataBase.getNoteFileByLocalId(localId);
if (noteFile == null) {

View File

@@ -0,0 +1,52 @@
package org.houxg.leamonax.ui;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import com.github.piasy.biv.view.BigImageView;
import org.houxg.leamonax.R;
import java.io.File;
import butterknife.BindView;
import butterknife.ButterKnife;
public class PictureViewerActivity extends BaseActivity {
private static final String EXTRA_FILE_PATH = "extra.filePath";
@BindView(R.id.big_image)
BigImageView mBigImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_picture_viewer);
ButterKnife.bind(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(getResources().getColor(R.color.black));
}
String path = getIntent().getStringExtra(EXTRA_FILE_PATH);
if (TextUtils.isEmpty(path)) {
finish();
return;
}
Uri uri = Uri.fromFile(new File(path));
mBigImageView.showImage(uri);
}
public static Intent getOpenIntent(Context context, String path) {
Intent intent = new Intent(context, PictureViewerActivity.class);
intent.putExtra(EXTRA_FILE_PATH, path);
return intent;
}
}

View File

@@ -34,11 +34,14 @@ import org.houxg.leamonax.R;
import org.houxg.leamonax.editor.Editor;
import org.houxg.leamonax.editor.MarkdownEditor;
import org.houxg.leamonax.editor.RichTextEditor;
import org.houxg.leamonax.service.NoteFileService;
import org.houxg.leamonax.ui.PictureViewerActivity;
import org.houxg.leamonax.utils.CollectionUtils;
import org.houxg.leamonax.utils.DialogUtils;
import org.houxg.leamonax.utils.OpenUtils;
import org.houxg.leamonax.widget.ToggleImageButton;
import java.io.File;
import java.util.List;
import java.util.Map;
@@ -459,6 +462,14 @@ public class EditorFragment extends Fragment implements Editor.EditorListener {
OpenUtils.openUrl(getActivity(), url);
}
@Override
public void onClickedImage(String url) {
String path = NoteFileService.getImagePath(Uri.parse(url));
if (!TextUtils.isEmpty(path)) {
startActivity(PictureViewerActivity.getOpenIntent(getActivity(), path));
}
}
private void refreshFormatStatus(Map<Editor.Format, Object> formatStatus) {
for (Map.Entry<Editor.Format, Object> entry : formatStatus.entrySet()) {
switch (entry.getKey()) {

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_about"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context="org.houxg.leamonax.ui.AboutActivity">
<com.github.piasy.biv.view.BigImageView
android:id="@+id/big_image"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>

View File

@@ -16,4 +16,5 @@
<color name="navigation">#F5F5F5</color>
<color name="transparent">#00000000</color>
<color name="white">#FFFFFF</color>
<color name="black">#000</color>
</resources>