diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png
new file mode 100644
index 0000000..4457b7e
Binary files /dev/null and b/app/src/main/ic_launcher-web.png differ
diff --git a/app/src/main/ic_launcher_round-web.png b/app/src/main/ic_launcher_round-web.png
new file mode 100644
index 0000000..74cf31a
Binary files /dev/null and b/app/src/main/ic_launcher_round-web.png differ
diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/EditFragment.java b/app/src/main/java/com/wbrawner/simplemarkdown/EditFragment.java
index b07e5d0..59e45cb 100644
--- a/app/src/main/java/com/wbrawner/simplemarkdown/EditFragment.java
+++ b/app/src/main/java/com/wbrawner/simplemarkdown/EditFragment.java
@@ -13,6 +13,7 @@ import android.support.v4.app.FragmentActivity;
import android.support.v4.content.FileProvider;
import android.support.v4.content.LocalBroadcastManager;
import android.text.Editable;
+import android.text.Layout;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
@@ -62,7 +63,8 @@ public class EditFragment extends Fragment {
filter
);
mContext = getActivity();
- mFileUtils = new FileUtils(mContext); }
+ mFileUtils = new FileUtils(mContext);
+ }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@@ -107,6 +109,16 @@ public class EditFragment extends Fragment {
public static void updatePreview(Context context) {
Intent broadcastIntent = new Intent(PreviewFragment.PREVIEW_ACTION);
broadcastIntent.putExtra("markdownData", mMarkdownEditor.getText().toString());
+ Layout layout = mMarkdownEditor.getLayout();
+ if (layout != null) {
+ int line =
+ layout.getLineForOffset(mMarkdownEditor.getSelectionStart());
+ int baseline = layout.getLineBaseline(line);
+ int ascent = layout.getLineAscent(line);
+ float yPos = (baseline + ascent) * 1.0f;
+ float yPercent = yPos / mMarkdownEditor.getMeasuredHeight();
+ broadcastIntent.putExtra("scrollY", yPercent);
+ }
LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
manager.sendBroadcast(broadcastIntent);
}
diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/MainActivity.java b/app/src/main/java/com/wbrawner/simplemarkdown/MainActivity.java
index 19ba8e3..0d9c4c0 100644
--- a/app/src/main/java/com/wbrawner/simplemarkdown/MainActivity.java
+++ b/app/src/main/java/com/wbrawner/simplemarkdown/MainActivity.java
@@ -9,6 +9,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
+import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Environment;
import android.support.annotation.Nullable;
@@ -90,10 +91,13 @@ public class MainActivity extends AppCompatActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+ getWindow().setBackgroundDrawable(new ColorDrawable(0xFFFFFFFF));
ButterKnife.bind(this);
pager.setAdapter(
new EditPagerAdapter(getSupportFragmentManager(), MainActivity.this)
);
+ pager.setPageMargin(1);
+ pager.setPageMarginDrawable(R.color.colorAccent);
mFilesDir = getFilesDir();
Intent intent = getIntent();
if (intent != null && !intent.getAction().equals(Intent.ACTION_MAIN) && intent.getData() != null) {
diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/PreviewFragment.java b/app/src/main/java/com/wbrawner/simplemarkdown/PreviewFragment.java
index e89c8d9..dd5aacd 100644
--- a/app/src/main/java/com/wbrawner/simplemarkdown/PreviewFragment.java
+++ b/app/src/main/java/com/wbrawner/simplemarkdown/PreviewFragment.java
@@ -14,6 +14,7 @@ import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -28,11 +29,11 @@ public class PreviewFragment extends Fragment {
private static final String TAG = PreviewFragment.class.getSimpleName();
private static final int INTERNET_REQUEST = 0;
private WebView mMarkdownView;
- private boolean timeoutActive = false;
@BindView(R.id.markdown_view)
WebView markdownView;
+ public static final String SCROLL_ACTION = "com.wbrawner.simplemarkdown.scroll";
public static final String PREVIEW_ACTION = "com.wbrawner.simplemarkdown.preview";
public PreviewFragment() {
@@ -77,16 +78,25 @@ public class PreviewFragment extends Fragment {
private class MarkdownBroadcastSender extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
- if (intent.hasExtra("markdownData")) {
- String data = intent.getStringExtra("markdownData");
- markdown(data);
+ Log.d(TAG, "Intent received: " + intent.getAction());
+ switch (intent.getAction()) {
+ case PREVIEW_ACTION:
+ if (intent.hasExtra("markdownData")) {
+ String data = intent.getStringExtra("markdownData");
+ int yPos = 0;
+ if (intent.hasExtra("scrollY")) {
+ float yPercent = intent.getFloatExtra("scrollY", 0);
+ Log.d(TAG, "Scrolling to: " + yPercent);
+ yPos = Math.round(mMarkdownView.getContentHeight() * yPercent);
+ }
+ markdown(data, yPos);
+ }
+ break;
}
}
}
- private void markdown(String text) {
- final String iText = text;
- final Handler handler = new Handler();
+ private void markdown(final String text, final int scrollY) {
Thread setMarkdown = new Thread() {
@Override
public void run() {
@@ -94,14 +104,11 @@ public class PreviewFragment extends Fragment {
int hoedownFlags =
AndDown.HOEDOWN_EXT_STRIKETHROUGH | AndDown.HOEDOWN_EXT_TABLES |
AndDown.HOEDOWN_EXT_UNDERLINE | AndDown.HOEDOWN_EXT_SUPERSCRIPT;
- String html = andDown.markdownToHtml(iText, hoedownFlags, 0);
+ String html = andDown.markdownToHtml(text, hoedownFlags, 0);
mMarkdownView.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
- timeoutActive = false;
+ mMarkdownView.scrollTo(0, scrollY);
}
};
- if (!timeoutActive) {
- timeoutActive = true;
- handler.postDelayed(setMarkdown, 0);
- }
+ setMarkdown.run();
}
}
diff --git a/app/src/main/res/drawable-hdpi/ic_action_save.png b/app/src/main/res/drawable-hdpi/ic_action_save.png
new file mode 100644
index 0000000..36b4360
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_save.png differ
diff --git a/app/src/main/res/drawable-hdpi/ic_action_share.png b/app/src/main/res/drawable-hdpi/ic_action_share.png
new file mode 100644
index 0000000..521874c
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_share.png differ
diff --git a/app/src/main/res/drawable-land/bg_splash.png b/app/src/main/res/drawable-land/bg_splash.png
new file mode 100644
index 0000000..a8d32db
Binary files /dev/null and b/app/src/main/res/drawable-land/bg_splash.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_action_save.png b/app/src/main/res/drawable-mdpi/ic_action_save.png
new file mode 100644
index 0000000..65e695e
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_save.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_action_share.png b/app/src/main/res/drawable-mdpi/ic_action_share.png
new file mode 100644
index 0000000..858ef60
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_share.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_action_save.png b/app/src/main/res/drawable-xhdpi/ic_action_save.png
new file mode 100644
index 0000000..d71f8d5
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_save.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_action_share.png b/app/src/main/res/drawable-xhdpi/ic_action_share.png
new file mode 100644
index 0000000..6d10b39
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_share.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_save.png b/app/src/main/res/drawable-xxhdpi/ic_action_save.png
new file mode 100644
index 0000000..eccedc3
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_save.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_share.png b/app/src/main/res/drawable-xxhdpi/ic_action_share.png
new file mode 100644
index 0000000..45a3da0
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_share.png differ
diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_save.png b/app/src/main/res/drawable-xxxhdpi/ic_action_save.png
new file mode 100644
index 0000000..f23bd7f
Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_save.png differ
diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_share.png b/app/src/main/res/drawable-xxxhdpi/ic_action_share.png
new file mode 100644
index 0000000..995514d
Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_share.png differ
diff --git a/app/src/main/res/drawable/bg_splash.png b/app/src/main/res/drawable/bg_splash.png
new file mode 100644
index 0000000..5be02bf
Binary files /dev/null and b/app/src/main/res/drawable/bg_splash.png differ
diff --git a/app/src/main/res/menu/menu_edit.xml b/app/src/main/res/menu/menu_edit.xml
index 4d99a82..0154110 100644
--- a/app/src/main/res/menu/menu_edit.xml
+++ b/app/src/main/res/menu/menu_edit.xml
@@ -4,12 +4,12 @@
-
- #3F51B5
- #303F9F
- #FF4081
+ #d32f2f
+ #b71c1c
+ #ef9a9a
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 545b9c6..cebb9aa 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -6,6 +6,7 @@
- @color/colorPrimary
- @color/colorPrimaryDark
- @color/colorAccent
+ - @drawable/bg_splash