From 3f85cbe759d664c92d1e5cbe3367a65cd4746db2 Mon Sep 17 00:00:00 2001 From: houxg Date: Thu, 24 Nov 2016 15:47:18 +0800 Subject: [PATCH] apply different format bar for RichText/Markdown --- .../org/houxg/leamonax/editor/Editor.java | 4 ++ .../houxg/leamonax/editor/MarkdownEditor.java | 10 ++++ .../houxg/leamonax/editor/RichTextEditor.java | 10 ++++ .../leamonax/ui/edit/EditorFragment.java | 38 ++++++++++-- ...isable.png => ic_format_quote_disable.png} | Bin ..._enable.png => ic_format_quote_enable.png} | Bin .../drawable-xxhdpi/ic_heading_disable.png | Bin 0 -> 1108 bytes .../res/drawable-xxhdpi/ic_heading_enable.png | Bin 0 -> 1166 bytes .../main/res/layout/format_bar_markdown.xml | 55 +++++++++++++++++ .../main/res/layout/format_bar_richtext.xml | 55 +++++++++++++++++ app/src/main/res/layout/fragment_editor.xml | 56 ++---------------- 11 files changed, 172 insertions(+), 56 deletions(-) rename app/src/main/res/drawable-xxhdpi/{ic_format_quote_black_disable.png => ic_format_quote_disable.png} (100%) rename app/src/main/res/drawable-xxhdpi/{ic_format_quote_black_enable.png => ic_format_quote_enable.png} (100%) create mode 100644 app/src/main/res/drawable-xxhdpi/ic_heading_disable.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_heading_enable.png create mode 100755 app/src/main/res/layout/format_bar_markdown.xml create mode 100755 app/src/main/res/layout/format_bar_richtext.xml diff --git a/app/src/main/java/org/houxg/leamonax/editor/Editor.java b/app/src/main/java/org/houxg/leamonax/editor/Editor.java index 007729a..d0ee342 100644 --- a/app/src/main/java/org/houxg/leamonax/editor/Editor.java +++ b/app/src/main/java/org/houxg/leamonax/editor/Editor.java @@ -57,6 +57,10 @@ public Editor(EditorListener listener) { public abstract void toggleItalic(); + public abstract void toggleQuote(); + + public abstract void toggleHeading(); + public interface EditorListener { void onPageLoaded(); void onClickedLink(String title, String url); diff --git a/app/src/main/java/org/houxg/leamonax/editor/MarkdownEditor.java b/app/src/main/java/org/houxg/leamonax/editor/MarkdownEditor.java index 566fa16..516d500 100644 --- a/app/src/main/java/org/houxg/leamonax/editor/MarkdownEditor.java +++ b/app/src/main/java/org/houxg/leamonax/editor/MarkdownEditor.java @@ -115,4 +115,14 @@ public void toggleBold() { public void toggleItalic() { execJs("ZSSEditor.setItalic();"); } + + @Override + public void toggleQuote() { + execJs("ZSSEditor.setBlockquote();"); + } + + @Override + public void toggleHeading() { + execJs("ZSSEditor.setHeading();"); + } } diff --git a/app/src/main/java/org/houxg/leamonax/editor/RichTextEditor.java b/app/src/main/java/org/houxg/leamonax/editor/RichTextEditor.java index 1f438b4..3877f36 100644 --- a/app/src/main/java/org/houxg/leamonax/editor/RichTextEditor.java +++ b/app/src/main/java/org/houxg/leamonax/editor/RichTextEditor.java @@ -128,6 +128,16 @@ public void toggleItalic() { execJs("ZSSEditor.setItalic();"); } + @Override + public void toggleQuote() { + execJs("ZSSEditor.setBlockquote();"); + } + + @Override + public void toggleHeading() { + execJs("ZSSEditor.setHeading();"); + } + private String appendPTag(String source) { String[] segments = source.split("\n\n"); StringBuilder contentBuilder = new StringBuilder(); diff --git a/app/src/main/java/org/houxg/leamonax/ui/edit/EditorFragment.java b/app/src/main/java/org/houxg/leamonax/ui/edit/EditorFragment.java index fd6dcdc..5c693f6 100644 --- a/app/src/main/java/org/houxg/leamonax/ui/edit/EditorFragment.java +++ b/app/src/main/java/org/houxg/leamonax/ui/edit/EditorFragment.java @@ -32,6 +32,7 @@ import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; +import butterknife.Optional; public class EditorFragment extends Fragment implements Editor.EditorListener { @@ -44,13 +45,22 @@ public class EditorFragment extends Fragment implements Editor.EditorListener { private EditorFragmentListener mListener; private Editor mEditor; - @BindView(R.id.fl_tools) + @BindView(R.id.fl_container) View mToolContainer; + @Nullable @BindView(R.id.btn_bold) ToggleImageButton mBoldBtn; + @Nullable @BindView(R.id.btn_italic) ToggleImageButton mItalicBtn; + @Nullable + @BindView(R.id.btn_heading) + ToggleImageButton mHeadingBtn; + @Nullable + @BindView(R.id.btn_quote) + ToggleImageButton mQuoteBtn; + @BindView(R.id.btn_order_list) ToggleImageButton mOrderListBtn; @BindView(R.id.btn_unorder_list) @@ -92,19 +102,25 @@ public void onDetach() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_editor, container, false); - ButterKnife.bind(this, view); + Bundle arguments = savedInstanceState == null ? getArguments() : savedInstanceState; mIsEditingEnabled = arguments.getBoolean(ARG_ENABLE_EDIT, false); boolean isMarkdown = arguments.getBoolean(ARG_IS_MARKDOWN, true); - mToolContainer.setVisibility(mIsEditingEnabled ? View.VISIBLE : View.GONE); - + int formatRestId; if (isMarkdown) { mEditor = new MarkdownEditor(this); + formatRestId = R.layout.format_bar_markdown; } else { mEditor = new RichTextEditor(this); + formatRestId = R.layout.format_bar_richtext; } + ViewGroup formatBarContainer = (ViewGroup) view.findViewById(R.id.fl_container); + View formatBar = inflater.inflate(formatRestId, formatBarContainer, false); + formatBarContainer.addView(formatBar, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + ButterKnife.bind(this, view); + mToolContainer.setVisibility(mIsEditingEnabled ? View.VISIBLE : View.GONE); mEditor.init(mWebView); return view; } @@ -191,16 +207,30 @@ void toggleUnorderList() { mEditor.toggleUnorderList(); } + @Optional @OnClick(R.id.btn_bold) void toggleBold() { mEditor.toggleBold(); } + @Optional @OnClick(R.id.btn_italic) void toggleItalic() { mEditor.toggleItalic(); } + @Optional + @OnClick(R.id.btn_heading) + void toggleHeading() { + mEditor.toggleHeading(); + } + + @Optional + @OnClick(R.id.btn_quote) + void toggleQuote() { + mEditor.toggleQuote(); + } + @OnClick(R.id.btn_undo) void undo() { mEditor.undo(); diff --git a/app/src/main/res/drawable-xxhdpi/ic_format_quote_black_disable.png b/app/src/main/res/drawable-xxhdpi/ic_format_quote_disable.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/ic_format_quote_black_disable.png rename to app/src/main/res/drawable-xxhdpi/ic_format_quote_disable.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_format_quote_black_enable.png b/app/src/main/res/drawable-xxhdpi/ic_format_quote_enable.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/ic_format_quote_black_enable.png rename to app/src/main/res/drawable-xxhdpi/ic_format_quote_enable.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_heading_disable.png b/app/src/main/res/drawable-xxhdpi/ic_heading_disable.png new file mode 100644 index 0000000000000000000000000000000000000000..587127ee14016ed9d6ea2a1b0b85a83279a3230c GIT binary patch literal 1108 zcmV-a1grarP)Px(4oO5oR9FeMmrF>LQ546WhcZLyG=+wdTM=5=!$QKxjH3lXfxAFj8bq{d(V|6* zwk?8oE!sru2p2^@#&JZYbdeGgLJ=fbkyQ3TM`xzrjk$8}z2Eqlse$pH^Z)+m{O>v6 zy?3s@id}w^$>aq>uF0@`KL0+ENc2k#-b4I)iNU)AZ%|=D`Cy0kMG|yNuFvPYFa2~n zUBAA*eo11=uBxiKsxiMdb}}O9gJ*~q;)Y~=Hk(aIU)fCVLwkGsg2s0xOeIGVuhqeY zFFXQV*E9&2f7S=TrmKi|0a#aNc`w(oazbo3Zv`-Pw~vo$p}DGRGm`_lN#%*;e+ z>s|@2t*u3=WR9=Fr-j|2Q0R^3uCA_LhI32%g>fz%4xf`4>%vT=9&*$T5$ttH$k=l2 zIpZDEDz$i=m0PZgNBoc>tVF5SSh*fSWkVb$!-g=T&H^f1#Z8c@uC7kozfJ=zn3oo} zmkIS**aEzp5`%LO|B%Gss9!DPfT7wIw%~7LmC7J(kBp2AV4v5%8cBG!tE=m}#wI2v z>R9<75jXPj<8g!&YhLr@XtY{BP&SJ#h)B%FnYB>`+potKC2p~psLHpcFwa{_SZxVs zqS0ttVsOq%zhFQ2z&4>Rg-PfflT<|Zb1*qTV5u9PM`J3G6FWT$09Wg|Q&F|RGiL|)UCPm;HlZM@^<<>eR& zi~|DEZ=Ic;#;wGw&30F|5>?L(VSJ~}U`di@6{yO5%Zr-m7+g8}Fgf^cd zu107o)43d2&mDJDm@~V9N}6m&Fc>u6Z;>_|mjgS8m%k}oSfWI2`q0000Px(NJ&INR9FeEmrrQaR}jaun{Bd9TXj>kSQK&+L8$+*l+r^?HVG7zcnAnm$VEY< z7Y`mhNbu@G@Mge^^p;XeLmINXS*-aZtsW$Z6rm!xU|UMm_0J*M&Gs{4-!k*wZ`V!S zAN+VT-#0Vg_vX!;{cWsmgU`Ug!11-UweLN*C$qD&r#05s*LO1(i|y1{JRZN2&1N%# zCGHHI7zgUxE24H2{B0qra@*uAN#splTvT4I6+ z#9$`P{r&xWSj=v3A#I67Vskql85#MIfZs#}G{l^Duv@T)Gcz;Kv~Sa?US3`n(xi4q ze%;g4b4Oz=E+7UoyA}JUiE$p(1R}GO-^RzsR~TS(48e97rDf-Ql4 zt1a{WJq&01p!~JuFGIwAQbcj8(T7GJUTj>#4xB_?bISUYlsVl zLR96ph|7e@8De%DRY1n$eHG4prK_v!wmD>SJDE)8jSGSfM=Z*&A#uYU6FjJL3eYqS&UZiLpSgv|$U@4=WYXB_d6Dbx zczAet8}mne2XqsV^9|CB&E1HP0~4w)aj{rD%1+v~H9L8kN~P|4SU`+j!!(P3On%Dd z=H{M3lJWw^ePZUN8JDyj@&}&2o@#v8G|my-$mMcp9hQLfFh)BZ;6^Yf>QSytK%@;s zt}fVQ3+$G*lT-%28GNGVd#=%ZM%?5$5sRoU}zs(U7@FSeR_5wv9O(Hdxwd1@SMHw_jd^Gq=6v}X4ARU(%*TNVP)Df|M->b{fANd**z*kv gi+Ph3&puN9A2YbIXkBjm+5i9m07*qoM6N<$f@fJV#{d8T literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/format_bar_markdown.xml b/app/src/main/res/layout/format_bar_markdown.xml new file mode 100755 index 0000000..c05b027 --- /dev/null +++ b/app/src/main/res/layout/format_bar_markdown.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/format_bar_richtext.xml b/app/src/main/res/layout/format_bar_richtext.xml new file mode 100755 index 0000000..c3109ab --- /dev/null +++ b/app/src/main/res/layout/format_bar_richtext.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_editor.xml b/app/src/main/res/layout/fragment_editor.xml index ccee21c..ebd3a60 100755 --- a/app/src/main/res/layout/fragment_editor.xml +++ b/app/src/main/res/layout/fragment_editor.xml @@ -1,65 +1,17 @@ - - - - - - - - - - - - - - - - - - + android:layout_alignParentBottom="true" /> + android:layout_above="@id/fl_container" />