├── .gitignore
├── LICENSE
├── README.md
├── app
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── io
│ │ └── github
│ │ └── mthli
│ │ └── type
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── io
│ │ └── github
│ │ └── mthli
│ │ └── type
│ │ ├── app
│ │ ├── LinkActivity.java
│ │ ├── MainActivity.java
│ │ └── SettingsActivity.java
│ │ ├── event
│ │ ├── BlockEvent.java
│ │ ├── BoldEvent.java
│ │ ├── BulletEvent.java
│ │ ├── DeleteEvent.java
│ │ ├── DotsEvent.java
│ │ ├── FormatEvent.java
│ │ ├── ImageEvent.java
│ │ ├── InsertEvent.java
│ │ ├── ItalicEvent.java
│ │ ├── LinkEvent.java
│ │ ├── QuoteEvent.java
│ │ ├── StrikethroughEvent.java
│ │ └── UnderlineEvent.java
│ │ ├── util
│ │ ├── DisplayUtils.java
│ │ ├── ImageUtils.java
│ │ ├── RxBus.java
│ │ └── SharedPreferenceUtils.java
│ │ └── widget
│ │ ├── DotsView.java
│ │ ├── StatusImageButton.java
│ │ ├── adapter
│ │ └── TypeAdapter.java
│ │ ├── holder
│ │ ├── TypeBlockHolder.java
│ │ ├── TypeDotsHolder.java
│ │ ├── TypeImageHolder.java
│ │ └── TypeTitleHolder.java
│ │ ├── model
│ │ ├── Type.java
│ │ ├── TypeBlock.java
│ │ ├── TypeDots.java
│ │ ├── TypeImage.java
│ │ └── TypeTitle.java
│ │ └── text
│ │ ├── KnifePart.java
│ │ └── KnifeText.java
│ └── res
│ ├── drawable-hdpi
│ ├── ic_attachment.png
│ ├── ic_bold_activated.png
│ ├── ic_bold_default.png
│ ├── ic_bullet_activated.png
│ ├── ic_bullet_default.png
│ ├── ic_dots.png
│ ├── ic_italic_activated.png
│ ├── ic_italic_default.png
│ ├── ic_link_activated.png
│ ├── ic_link_default.png
│ ├── ic_play.png
│ ├── ic_quote_activated.png
│ ├── ic_quote_default.png
│ ├── ic_strikethrough_activated.png
│ ├── ic_strikethrough_default.png
│ ├── ic_underline_activated.png
│ └── ic_underline_default.png
│ ├── drawable-mdpi
│ ├── ic_attachment.png
│ ├── ic_bold_activated.png
│ ├── ic_bold_default.png
│ ├── ic_bullet_activated.png
│ ├── ic_bullet_default.png
│ ├── ic_dots.png
│ ├── ic_italic_activated.png
│ ├── ic_italic_default.png
│ ├── ic_link_activated.png
│ ├── ic_link_default.png
│ ├── ic_play.png
│ ├── ic_quote_activated.png
│ ├── ic_quote_default.png
│ ├── ic_strikethrough_activated.png
│ ├── ic_strikethrough_default.png
│ ├── ic_underline_activated.png
│ └── ic_underline_default.png
│ ├── drawable-xhdpi
│ ├── ic_attachment.png
│ ├── ic_bold_activated.png
│ ├── ic_bold_default.png
│ ├── ic_bullet_activated.png
│ ├── ic_bullet_default.png
│ ├── ic_dots.png
│ ├── ic_italic_activated.png
│ ├── ic_italic_default.png
│ ├── ic_link_activated.png
│ ├── ic_link_default.png
│ ├── ic_play.png
│ ├── ic_quote_activated.png
│ ├── ic_quote_default.png
│ ├── ic_strikethrough_activated.png
│ ├── ic_strikethrough_default.png
│ ├── ic_underline_activated.png
│ └── ic_underline_default.png
│ ├── drawable-xxhdpi
│ ├── ic_attachment.png
│ ├── ic_bold_activated.png
│ ├── ic_bold_default.png
│ ├── ic_bullet_activated.png
│ ├── ic_bullet_default.png
│ ├── ic_dots.png
│ ├── ic_italic_activated.png
│ ├── ic_italic_default.png
│ ├── ic_link_activated.png
│ ├── ic_link_default.png
│ ├── ic_play.png
│ ├── ic_quote_activated.png
│ ├── ic_quote_default.png
│ ├── ic_strikethrough_activated.png
│ ├── ic_strikethrough_default.png
│ ├── ic_underline_activated.png
│ └── ic_underline_default.png
│ ├── drawable-xxxhdpi
│ ├── ic_attachment.png
│ ├── ic_bold_activated.png
│ ├── ic_bold_default.png
│ ├── ic_bullet_activated.png
│ ├── ic_bullet_default.png
│ ├── ic_dots.png
│ ├── ic_italic_activated.png
│ ├── ic_italic_default.png
│ ├── ic_link_activated.png
│ ├── ic_link_default.png
│ ├── ic_play.png
│ ├── ic_quote_activated.png
│ ├── ic_quote_default.png
│ ├── ic_strikethrough_activated.png
│ ├── ic_strikethrough_default.png
│ ├── ic_underline_activated.png
│ └── ic_underline_default.png
│ ├── drawable
│ └── shape_bullet.xml
│ ├── layout
│ ├── activity_main.xml
│ ├── recycler_item_block.xml
│ ├── recycler_item_dots.xml
│ ├── recycler_item_image.xml
│ └── recycler_item_title.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ └── values
│ ├── attrs.xml
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 | # Android Studio Navigation editor temp files
29 | .navigation/
30 |
31 | # Android Studio captures folder
32 | captures/
33 |
34 | # Others
35 | .idea/
36 | *.directory
37 | *.iml
38 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2016 Matthew Lee
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Type
2 | ====
3 |
4 | Typing experiment on Android.
5 |
6 | Support Android 5.0+.
7 |
8 | **UNDER DEVELOPMENT**.
9 |
10 | ## License
11 |
12 | Copyright (C) 2016 Matthew Lee
13 |
14 | Licensed under the Apache License, Version 2.0 (the "License");
15 | you may not use this file except in compliance with the License.
16 | You may obtain a copy of the License at
17 |
18 | http://www.apache.org/licenses/LICENSE-2.0
19 |
20 | Unless required by applicable law or agreed to in writing, software
21 | distributed under the License is distributed on an "AS IS" BASIS,
22 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 | See the License for the specific language governing permissions and
24 | limitations under the License.
25 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | apply plugin: 'com.android.application'
16 |
17 | android {
18 | compileSdkVersion 23
19 | buildToolsVersion "23.0.2"
20 |
21 | defaultConfig {
22 | applicationId "io.github.mthli.type"
23 | minSdkVersion 21
24 | targetSdkVersion 23
25 | versionCode 1
26 | versionName "0.1"
27 | }
28 |
29 | buildTypes {
30 | release {
31 | minifyEnabled false
32 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33 | }
34 | }
35 | }
36 |
37 | dependencies {
38 | compile fileTree(include: ['*.jar'], dir: 'libs')
39 | compile 'com.android.support:appcompat-v7:23.3.0'
40 | compile 'com.android.support:recyclerview-v7:23.3.0'
41 | compile 'com.tbruyelle.rxpermissions:rxpermissions:0.7.0@aar'
42 | compile 'com.trello:rxlifecycle-components:0.5.0'
43 | compile 'io.reactivex:rxandroid:1.1.0'
44 | }
45 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Copyright 2016 Matthew Lee
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4 | # in compliance with the License. You may obtain a copy of the License at
5 | #
6 | # http://www.apache.org/licenses/LICENSE-2.0
7 | #
8 | # Unless required by applicable law or agreed to in writing, software distributed under the License
9 | # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10 | # or implied. See the License for the specific language governing permissions and limitations under
11 | # the License.
12 |
13 | # Add project specific ProGuard rules here.
14 | # By default, the flags in this file are appended to flags specified
15 | # in /home/matthew/Android/Sdk/tools/proguard/proguard-android.txt
16 | # You can edit the include path and order by changing the proguardFiles
17 | # directive in build.gradle.
18 | #
19 | # For more details, see
20 | # http://developer.android.com/guide/developing/tools/proguard.html
21 |
22 | # Add any project specific keep options here:
23 |
24 | # If your project uses WebView with JS, uncomment the following
25 | # and specify the fully qualified class name to the JavaScript interface
26 | # class:
27 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
28 | # public *;
29 | #}
30 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/io/github/mthli/type/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type;
16 |
17 | import android.app.Application;
18 | import android.test.ApplicationTestCase;
19 |
20 | /**
21 | * Testing Fundamentals
22 | */
23 | public class ApplicationTest extends ApplicationTestCase {
24 | public ApplicationTest() {
25 | super(Application.class);
26 | }
27 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
19 |
20 |
21 |
22 |
23 |
28 |
29 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/app/LinkActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.app;
16 |
17 | public class LinkActivity {
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/app/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.app;
16 |
17 | import android.animation.Animator;
18 | import android.animation.AnimatorListenerAdapter;
19 | import android.content.Intent;
20 | import android.graphics.Bitmap;
21 | import android.graphics.drawable.Drawable;
22 | import android.os.Bundle;
23 | import android.provider.MediaStore;
24 | import android.support.v7.widget.AppCompatImageButton;
25 | import android.support.v7.widget.DefaultItemAnimator;
26 | import android.support.v7.widget.LinearLayoutCompat;
27 | import android.support.v7.widget.LinearLayoutManager;
28 | import android.support.v7.widget.RecyclerView;
29 | import android.support.v7.widget.helper.ItemTouchHelper;
30 | import android.view.ActionMode;
31 | import android.view.View;
32 | import android.view.animation.LinearInterpolator;
33 | import android.widget.Toast;
34 |
35 | import com.jakewharton.rxbinding.view.RxView;
36 | import com.jakewharton.rxbinding.view.ViewLayoutChangeEvent;
37 | import com.trello.rxlifecycle.ActivityEvent;
38 | import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
39 |
40 | import java.io.IOException;
41 | import java.util.Collections;
42 | import java.util.LinkedList;
43 | import java.util.List;
44 | import java.util.concurrent.TimeUnit;
45 |
46 | import io.github.mthli.type.R;
47 | import io.github.mthli.type.event.BlockEvent;
48 | import io.github.mthli.type.event.BoldEvent;
49 | import io.github.mthli.type.event.BulletEvent;
50 | import io.github.mthli.type.event.DeleteEvent;
51 | import io.github.mthli.type.event.DotsEvent;
52 | import io.github.mthli.type.event.ImageEvent;
53 | import io.github.mthli.type.event.InsertEvent;
54 | import io.github.mthli.type.event.FormatEvent;
55 | import io.github.mthli.type.event.ItalicEvent;
56 | import io.github.mthli.type.event.QuoteEvent;
57 | import io.github.mthli.type.event.StrikethroughEvent;
58 | import io.github.mthli.type.event.UnderlineEvent;
59 | import io.github.mthli.type.util.ImageUtils;
60 | import io.github.mthli.type.util.RxBus;
61 | import io.github.mthli.type.widget.StatusImageButton;
62 | import io.github.mthli.type.widget.adapter.TypeAdapter;
63 | import io.github.mthli.type.widget.holder.TypeDotsHolder;
64 | import io.github.mthli.type.widget.holder.TypeImageHolder;
65 | import io.github.mthli.type.widget.holder.TypeTitleHolder;
66 | import io.github.mthli.type.widget.model.Type;
67 | import io.github.mthli.type.widget.model.TypeBlock;
68 | import io.github.mthli.type.widget.model.TypeDots;
69 | import io.github.mthli.type.widget.model.TypeImage;
70 | import io.github.mthli.type.widget.model.TypeTitle;
71 | import io.github.mthli.type.widget.text.KnifeText;
72 | import rx.Observable;
73 | import rx.Subscriber;
74 | import rx.android.schedulers.AndroidSchedulers;
75 | import rx.functions.Action1;
76 | import rx.schedulers.Schedulers;
77 |
78 | public class MainActivity extends RxAppCompatActivity implements View.OnClickListener, View.OnLongClickListener,
79 | RecyclerView.OnChildAttachStateChangeListener {
80 |
81 | private static final long SYSTEM_UI_DELAY = 1000l; // ms
82 | private static final int REQUEST_IMAGE = 0x01;
83 |
84 | private RecyclerView recyclerView;
85 | private LinearLayoutManager layoutManager;
86 | private TypeAdapter typeAdapter;
87 | private List typeList;
88 | private int targetPosition = -1;
89 |
90 | private LinearLayoutCompat controlPanel;
91 | private StatusImageButton bulletButton;
92 | private StatusImageButton quoteButton;
93 | private AppCompatImageButton attachmentButton;
94 | private AppCompatImageButton dotsButton;
95 | private AppCompatImageButton playButton;
96 |
97 | private LinearLayoutCompat stylePanel;
98 | private StatusImageButton boldButton;
99 | private StatusImageButton italicButton;
100 | private StatusImageButton underlineButton;
101 | private StatusImageButton strikethroughButton;
102 | private StatusImageButton linkButton;
103 |
104 | @Override
105 | protected void onCreate(Bundle savedInstanceState) {
106 | super.onCreate(savedInstanceState);
107 | setContentView(R.layout.activity_main);
108 |
109 | setupRootLayout();
110 | setupRecyclerView();
111 | setupItemTouchHelper();
112 | setupControlPanel();
113 | setupStylePanel();
114 | setupReactiveX();
115 | }
116 |
117 | private void setupRootLayout() {
118 | RxView.layoutChangeEvents(findViewById(R.id.root))
119 | .delay(SYSTEM_UI_DELAY, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
120 | .compose(this.bindUntilEvent(ActivityEvent.DESTROY))
121 | .subscribe(new Action1() {
122 | @Override
123 | public void call(ViewLayoutChangeEvent viewLayoutChangeEvent) {
124 | int oldHeight = viewLayoutChangeEvent.oldBottom() - viewLayoutChangeEvent.oldTop();
125 | int newHeight = viewLayoutChangeEvent.bottom() - viewLayoutChangeEvent.top();
126 | if (newHeight > oldHeight) {
127 | getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
128 | }
129 | }
130 | });
131 | }
132 |
133 | private void setupRecyclerView() {
134 | recyclerView = (RecyclerView) findViewById(R.id.recycler);
135 | layoutManager = new LinearLayoutManager(this);
136 | recyclerView.setLayoutManager(layoutManager);
137 |
138 | // TODO
139 | typeList = new LinkedList<>();
140 | typeList.add(new TypeTitle(null));
141 | typeList.add(new TypeBlock(null));
142 |
143 | typeAdapter = new TypeAdapter(this, typeList);
144 | recyclerView.setAdapter(typeAdapter);
145 | recyclerView.setItemAnimator(new DefaultItemAnimator());
146 | recyclerView.addOnChildAttachStateChangeListener(this);
147 | }
148 |
149 | private void setupItemTouchHelper() {
150 | ItemTouchHelper.SimpleCallback callback = new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.START | ItemTouchHelper.END) {
151 | @Override
152 | public int getDragDirs(RecyclerView recyclerView, RecyclerView.ViewHolder holder) {
153 | if (holder instanceof TypeDotsHolder || holder instanceof TypeImageHolder) {
154 | return ItemTouchHelper.UP | ItemTouchHelper.DOWN;
155 | } else {
156 | return 0;
157 | }
158 | }
159 |
160 | @Override
161 | public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder holder) {
162 | if (holder instanceof TypeDotsHolder || holder instanceof TypeImageHolder) {
163 | return ItemTouchHelper.START | ItemTouchHelper.END;
164 | } else {
165 | return 0;
166 | }
167 | }
168 |
169 | @Override
170 | public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) {
171 | if (target instanceof TypeTitleHolder) {
172 | return false;
173 | }
174 |
175 | int from = source.getAdapterPosition();
176 | int to = target.getAdapterPosition();
177 | Collections.swap(typeList, from, to);
178 | typeAdapter.notifyItemMoved(from, to);
179 | return true;
180 | }
181 |
182 | @Override
183 | public void onSwiped(RecyclerView.ViewHolder holder, int direction) {
184 | int position = holder.getAdapterPosition();
185 | typeList.remove(position);
186 | typeAdapter.notifyItemRemoved(position);
187 | }
188 | };
189 |
190 | ItemTouchHelper helper = new ItemTouchHelper(callback);
191 | helper.attachToRecyclerView(recyclerView);
192 | }
193 |
194 | private void setupControlPanel() {
195 | controlPanel = (LinearLayoutCompat) findViewById(R.id.control);
196 | bulletButton = (StatusImageButton) findViewById(R.id.bullet);
197 | quoteButton = (StatusImageButton) findViewById(R.id.quote);
198 | attachmentButton = (AppCompatImageButton) findViewById(R.id.attachment);
199 | dotsButton = (AppCompatImageButton) findViewById(R.id.dots);
200 | playButton = (AppCompatImageButton) findViewById(R.id.play);
201 |
202 | bulletButton.setOnClickListener(this);
203 | quoteButton.setOnClickListener(this);
204 | attachmentButton.setOnClickListener(this);
205 | dotsButton.setOnClickListener(this);
206 | playButton.setOnClickListener(this);
207 |
208 | bulletButton.setOnLongClickListener(this);
209 | quoteButton.setOnLongClickListener(this);
210 | attachmentButton.setOnLongClickListener(this);
211 | dotsButton.setOnLongClickListener(this);
212 | playButton.setOnLongClickListener(this);
213 |
214 | RxBus.getInstance().toObservable(BlockEvent.class)
215 | .subscribe(new Action1() {
216 | @Override
217 | public void call(BlockEvent event) {
218 | bulletButton.setActivated(event.isBullet());
219 | quoteButton.setActivated(event.isQuote());
220 | }
221 | });
222 | }
223 |
224 | private void setupStylePanel() {
225 | stylePanel = (LinearLayoutCompat) findViewById(R.id.style);
226 | boldButton = (StatusImageButton) findViewById(R.id.bold);
227 | italicButton = (StatusImageButton) findViewById(R.id.italic);
228 | underlineButton = (StatusImageButton) findViewById(R.id.underline);
229 | strikethroughButton = (StatusImageButton) findViewById(R.id.strikethrough);
230 | linkButton = (StatusImageButton) findViewById(R.id.link);
231 |
232 | boldButton.setOnClickListener(this);
233 | italicButton.setOnClickListener(this);
234 | underlineButton.setOnClickListener(this);
235 | strikethroughButton.setOnClickListener(this);
236 | linkButton.setOnClickListener(this);
237 |
238 | boldButton.setOnLongClickListener(this);
239 | italicButton.setOnLongClickListener(this);
240 | underlineButton.setOnLongClickListener(this);
241 | strikethroughButton.setOnLongClickListener(this);
242 | linkButton.setOnLongClickListener(this);
243 |
244 | RxBus.getInstance().toObservable(FormatEvent.class)
245 | .subscribe(new Action1() {
246 | @Override
247 | public void call(FormatEvent event) {
248 | boldButton.setActivated(event.isBold());
249 | italicButton.setActivated(event.isItalic());
250 | underlineButton.setActivated(event.isUnderline());
251 | strikethroughButton.setActivated(event.isStrikethrough());
252 | linkButton.setActivated(event.isLink());
253 | }
254 | });
255 | }
256 |
257 | private void setupReactiveX() {
258 | RxBus.getInstance().toObservable(DeleteEvent.class)
259 | .compose(this.bindUntilEvent(ActivityEvent.DESTROY))
260 | .subscribe(new Action1() {
261 | @Override
262 | public void call(DeleteEvent event) {
263 | onDeleteEvent(event);
264 | }
265 | });
266 |
267 | RxBus.getInstance().toObservable(InsertEvent.class)
268 | .compose(this.bindUntilEvent(ActivityEvent.DESTROY))
269 | .subscribe(new Action1() {
270 | @Override
271 | public void call(InsertEvent event) {
272 | onInsertEvent(event);
273 | }
274 | });
275 | }
276 |
277 | private void onInsertEvent(InsertEvent event) {
278 | int position = event.getPosition();
279 | if (position < 1 || position >= typeList.size()) {
280 | return;
281 | }
282 |
283 | switch (event.getType()) {
284 | case Type.TYPE_BLOCK:
285 | onInsertBlock(event);
286 | break;
287 | case Type.TYPE_DOTS:
288 | onInsertDots(event);
289 | break;
290 | case Type.TYPE_IMAGE:
291 | onInsertImage(event);
292 | break;
293 | default:
294 | return;
295 | }
296 |
297 | int first = layoutManager.findFirstCompletelyVisibleItemPosition();
298 | int last = layoutManager.findLastCompletelyVisibleItemPosition();
299 | if (targetPosition > last) {
300 | recyclerView.scrollToPosition(targetPosition);
301 | } else if (first <= targetPosition && targetPosition <= last) {
302 | recyclerView.scrollToPosition(first);
303 | }
304 | }
305 |
306 | private void onInsertBlock(InsertEvent event) {
307 | targetPosition = event.getPosition() + 1;
308 | typeList.add(targetPosition, new TypeBlock(event.getSuffix()));
309 | typeAdapter.notifyItemInserted(targetPosition);
310 | }
311 |
312 | private void onInsertDots(InsertEvent event) {
313 | if (event.getPrefix().length() <= 0) {
314 | targetPosition = event.getPosition();
315 | typeList.set(targetPosition, new TypeDots());
316 | typeList.add(++targetPosition, new TypeBlock(event.getSuffix()));
317 | typeAdapter.notifyDataSetChanged();
318 | } else {
319 | targetPosition = event.getPosition() + 1;
320 | typeList.add(targetPosition, new TypeDots());
321 | typeList.add(++targetPosition, new TypeBlock(event.getSuffix()));
322 | typeAdapter.notifyItemRangeInserted(event.getPosition() + 1, 2);
323 | }
324 | }
325 |
326 | private void onInsertImage(InsertEvent event) {
327 | if (event.getPrefix().length() <= 0) {
328 | targetPosition = event.getPosition();
329 | typeList.set(targetPosition, new TypeImage(event.getBitmap()));
330 | typeList.add(++targetPosition, new TypeBlock(event.getSuffix()));
331 | typeAdapter.notifyDataSetChanged();
332 | } else {
333 | targetPosition = event.getPosition() + 1;
334 | typeList.add(targetPosition, new TypeImage(event.getBitmap()));
335 | typeList.add(++targetPosition, new TypeBlock(event.getSuffix()));
336 | typeAdapter.notifyItemRangeInserted(event.getPosition() + 1, 2);
337 | }
338 | }
339 |
340 | @Override
341 | public void onChildViewAttachedToWindow(View view) {
342 | if (layoutManager.getPosition(view) == targetPosition) {
343 | targetPosition = -1;
344 |
345 | KnifeText knifeText = (KnifeText) view.findViewById(R.id.content);
346 | if (knifeText != null) {
347 | knifeText.requestFocus();
348 | knifeText.setSelection(0);
349 | } else {
350 | view.requestFocus();
351 | }
352 | }
353 | }
354 |
355 | @Override
356 | public void onChildViewDetachedFromWindow(View view) {
357 | // DO NOTHING HERE
358 | }
359 |
360 | @Override
361 | public void onPause() {
362 | super.onPause();
363 | // TODO
364 | }
365 |
366 | @Override
367 | public void onDestroy() {
368 | super.onDestroy();
369 | recyclerView.clearOnChildAttachStateChangeListeners();
370 | }
371 |
372 | @Override
373 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
374 | super.onActivityResult(requestCode, resultCode, data);
375 |
376 | if (requestCode != REQUEST_IMAGE) {
377 | return;
378 | }
379 |
380 | if (resultCode != RESULT_OK || data == null || data.getData() == null) {
381 | Toast.makeText(this, R.string.toast_attachment_failed, Toast.LENGTH_SHORT).show();
382 | return;
383 | }
384 |
385 | try {
386 | Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), data.getData());
387 | insertImageAsync(bitmap);
388 | } catch (IOException i) {
389 | Toast.makeText(this, R.string.toast_attachment_failed, Toast.LENGTH_SHORT).show();
390 | }
391 | }
392 |
393 | private void insertImageAsync(final Bitmap bitmap) {
394 | Observable.create(new Observable.OnSubscribe() {
395 | @Override
396 | public void call(Subscriber super Bitmap> subscriber) {
397 | Bitmap fix = ImageUtils.fixBitmap(MainActivity.this, bitmap);
398 | Drawable inset = ImageUtils.insetBitmap(MainActivity.this, fix);
399 | Bitmap result = ImageUtils.drawable2Bitmap(inset);
400 | subscriber.onNext(result);
401 | }
402 | }).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1() {
403 | @Override
404 | public void call(Bitmap result) {
405 | RxBus.getInstance().post(new ImageEvent(result));
406 | }
407 | });
408 | }
409 |
410 | @Override
411 | public void onActionModeStarted(ActionMode actionMode) {
412 | super.onActionModeStarted(actionMode);
413 | switchToStylePanel();
414 | }
415 |
416 | @Override
417 | public void onActionModeFinished(ActionMode actionMode) {
418 | super.onActionModeFinished(actionMode);
419 | switchToControlPanel();
420 | }
421 |
422 | private void switchToControlPanel() {
423 | stylePanel.animate().alpha(0.0f)
424 | .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime))
425 | .setInterpolator(new LinearInterpolator())
426 | .setListener(new AnimatorListenerAdapter() {
427 | @Override
428 | public void onAnimationStart(Animator animator) {
429 | stylePanel.setAlpha(1.0f);
430 | stylePanel.setVisibility(View.VISIBLE);
431 | }
432 |
433 | @Override
434 | public void onAnimationEnd(Animator animator) {
435 | stylePanel.setAlpha(0.0f);
436 | stylePanel.setVisibility(View.GONE);
437 | }
438 | }).start();
439 |
440 | controlPanel.animate().alpha(1.0f)
441 | .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime))
442 | .setInterpolator(new LinearInterpolator())
443 | .setListener(new AnimatorListenerAdapter() {
444 | @Override
445 | public void onAnimationStart(Animator animator) {
446 | controlPanel.setAlpha(0.0f);
447 | controlPanel.setVisibility(View.VISIBLE);
448 | }
449 |
450 | @Override
451 | public void onAnimationEnd (Animator animator){
452 | controlPanel.setAlpha(1.0f);
453 | controlPanel.setVisibility(View.VISIBLE);
454 | }
455 | }).start();
456 | }
457 |
458 | private void switchToStylePanel() {
459 | controlPanel.animate().alpha(0.0f)
460 | .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime))
461 | .setInterpolator(new LinearInterpolator())
462 | .setListener(new AnimatorListenerAdapter() {
463 | @Override
464 | public void onAnimationStart(Animator animator) {
465 | controlPanel.setAlpha(1.0f);
466 | controlPanel.setVisibility(View.VISIBLE);
467 | }
468 |
469 | @Override
470 | public void onAnimationEnd(Animator animator) {
471 | controlPanel.setAlpha(0.0f);
472 | controlPanel.setVisibility(View.GONE);
473 | }
474 | }).start();
475 |
476 | stylePanel.animate().alpha(1.0f)
477 | .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime))
478 | .setInterpolator(new LinearInterpolator())
479 | .setListener(new AnimatorListenerAdapter() {
480 | @Override
481 | public void onAnimationStart(Animator animator) {
482 | stylePanel.setAlpha(0.0f);
483 | stylePanel.setVisibility(View.VISIBLE);
484 | }
485 |
486 | @Override
487 | public void onAnimationEnd(Animator animator) {
488 | stylePanel.setAlpha(1.0f);
489 | stylePanel.setVisibility(View.VISIBLE);
490 | }
491 | }).start();
492 | }
493 |
494 | @Override
495 | public void onClick(View view) {
496 | if (view == bulletButton) {
497 | RxBus.getInstance().post(new BulletEvent());
498 | } else if (view == quoteButton) {
499 | RxBus.getInstance().post(new QuoteEvent());
500 | } else if (view == attachmentButton) {
501 | onClickAttachment();
502 | } else if (view == dotsButton) {
503 | RxBus.getInstance().post(new DotsEvent());
504 | } else if (view == playButton) {
505 | // TODO
506 | } else if (view == boldButton) {
507 | RxBus.getInstance().post(new BoldEvent());
508 | } else if (view == italicButton) {
509 | RxBus.getInstance().post(new ItalicEvent());
510 | } else if (view == underlineButton) {
511 | RxBus.getInstance().post(new UnderlineEvent());
512 | } else if (view == strikethroughButton) {
513 | RxBus.getInstance().post(new StrikethroughEvent());
514 | } else if (view == linkButton) {
515 | // TODO
516 | }
517 | }
518 |
519 | private void onClickAttachment() {
520 | Intent intent = new Intent();
521 | intent.setType("image/*");
522 | intent.setAction(Intent.ACTION_GET_CONTENT);
523 | startActivityForResult(intent, REQUEST_IMAGE);
524 | }
525 |
526 | @Override
527 | public boolean onLongClick(View view) {
528 | int stringResId = 0;
529 |
530 | if (view == bulletButton) {
531 | stringResId = R.string.toast_bullet;
532 | } else if (view == quoteButton) {
533 | stringResId = R.string.toast_quote;
534 | } else if (view == attachmentButton) {
535 | stringResId = R.string.toast_attachment;
536 | } else if (view == dotsButton) {
537 | stringResId = R.string.toast_dots;
538 | } else if (view == playButton) {
539 | stringResId = R.string.toast_play;
540 | } else if (view == boldButton) {
541 | stringResId = R.string.toast_bold;
542 | } else if (view == italicButton) {
543 | stringResId = R.string.toast_italic;
544 | } else if (view == underlineButton) {
545 | stringResId = R.string.toast_underline;
546 | } else if (view == strikethroughButton) {
547 | stringResId = R.string.toast_strikethrough;
548 | } else if (view == linkButton) {
549 | stringResId = R.string.toast_link;
550 | }
551 |
552 | if (stringResId != 0) {
553 | Toast.makeText(this, stringResId, Toast.LENGTH_SHORT).show();
554 | }
555 |
556 | return true;
557 | }
558 |
559 | private void onDeleteEvent(DeleteEvent event) {
560 | int position = event.getPosition();
561 | int type = event.getType();
562 | if (position <= 1 || position >= typeList.size() || type != Type.TYPE_BLOCK) {
563 | return;
564 | }
565 |
566 | // TODO
567 | }
568 | }
569 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/app/SettingsActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.app;
16 |
17 | public class SettingsActivity {
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/event/BlockEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.event;
16 |
17 | public class BlockEvent {
18 | private boolean isBullet;
19 | private boolean isQuote;
20 |
21 | public BlockEvent() {}
22 |
23 | public BlockEvent(boolean isBullet, boolean isQuote) {
24 | this.isBullet = isBullet;
25 | this.isQuote = isQuote;
26 | }
27 |
28 | public boolean isBullet() {
29 | return isBullet;
30 | }
31 |
32 | public void setBullet(boolean isBullet) {
33 | this.isBullet = isBullet;
34 | }
35 |
36 | public boolean isQuote() {
37 | return isQuote;
38 | }
39 |
40 | public void setQuote(boolean isQuote) {
41 | this.isQuote = isQuote;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/event/BoldEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.event;
16 |
17 | public class BoldEvent {}
18 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/event/BulletEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.event;
16 |
17 | public class BulletEvent {}
18 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/event/DeleteEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.event;
16 |
17 | import io.github.mthli.type.widget.model.Type;
18 |
19 | public class DeleteEvent {
20 | private int type;
21 | private int position;
22 |
23 | public DeleteEvent(@Type.TypeValue int type, int position) {
24 | this.type = type;
25 | this.position = position;
26 | }
27 |
28 | @Type.TypeValue
29 | public int getType() {
30 | return type;
31 | }
32 |
33 | public int getPosition() {
34 | return position;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/event/DotsEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.event;
16 |
17 | public class DotsEvent {}
18 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/event/FormatEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.event;
16 |
17 | public class FormatEvent {
18 | private boolean isBold;
19 | private boolean isItalic;
20 | private boolean isUnderline;
21 | private boolean isStrikethrough;
22 | private boolean isLink;
23 |
24 | public FormatEvent() {}
25 |
26 | public FormatEvent(boolean isBold, boolean isItalic, boolean isUnderline, boolean isStrikethrough, boolean isLink) {
27 | this.isBold = isBold;
28 | this.isItalic = isItalic;
29 | this.isUnderline = isUnderline;
30 | this.isStrikethrough = isStrikethrough;
31 | this.isLink = isLink;
32 | }
33 |
34 | public boolean isBold() {
35 | return isBold;
36 | }
37 |
38 | public void setBold(boolean isBold) {
39 | this.isBold = isBold;
40 | }
41 |
42 | public boolean isItalic() {
43 | return isItalic;
44 | }
45 |
46 | public void setItalic(boolean isItalic) {
47 | this.isItalic = isItalic;
48 | }
49 |
50 | public boolean isUnderline() {
51 | return isUnderline;
52 | }
53 |
54 | public void setUnderline(boolean isUnderline) {
55 | this.isUnderline = isUnderline;
56 | }
57 |
58 | public boolean isStrikethrough() {
59 | return isStrikethrough;
60 | }
61 |
62 | public void setStrikethrough(boolean isStrikethrough) {
63 | this.isStrikethrough = isStrikethrough;
64 | }
65 |
66 | public boolean isLink() {
67 | return isLink;
68 | }
69 |
70 | public void setLink(boolean isLink) {
71 | this.isLink = isLink;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/event/ImageEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.event;
16 |
17 | import android.graphics.Bitmap;
18 | import android.support.annotation.NonNull;
19 |
20 | public class ImageEvent {
21 | private Bitmap bitmap;
22 |
23 | public ImageEvent(@NonNull Bitmap bitmap) {
24 | this.bitmap = bitmap;
25 | }
26 |
27 | public Bitmap getBitmap() {
28 | return bitmap;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/event/InsertEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.event;
16 |
17 | import android.graphics.Bitmap;
18 | import android.support.annotation.NonNull;
19 | import android.support.annotation.Nullable;
20 | import android.text.SpannableString;
21 | import android.text.Spanned;
22 |
23 | import io.github.mthli.type.widget.model.Type;
24 |
25 | public class InsertEvent {
26 | private int type;
27 | private int position;
28 | private Spanned prefix;
29 | private Spanned suffix;
30 | private Bitmap bitmap;
31 |
32 | public InsertEvent(@Type.TypeValue int type, int position, @Nullable Spanned prefix, @Nullable Spanned suffix, @Nullable Bitmap bitmap) {
33 | this.type = type;
34 | this.position = position;
35 | this.prefix = prefix != null ? prefix : new SpannableString("");
36 | this.suffix = suffix != null ? suffix : new SpannableString("");
37 | this.bitmap = bitmap;
38 | }
39 |
40 | @Type.TypeValue
41 | public int getType() {
42 | return type;
43 | }
44 |
45 | public int getPosition() {
46 | return position;
47 | }
48 |
49 | @NonNull
50 | public Spanned getPrefix() {
51 | return prefix;
52 | }
53 |
54 | @NonNull
55 | public Spanned getSuffix() {
56 | return suffix;
57 | }
58 |
59 | @Nullable
60 | public Bitmap getBitmap() {
61 | return bitmap;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/event/ItalicEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.event;
16 |
17 | public class ItalicEvent {}
18 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/event/LinkEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.event;
16 |
17 | public class LinkEvent {}
18 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/event/QuoteEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.event;
16 |
17 | public class QuoteEvent {}
18 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/event/StrikethroughEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.event;
16 |
17 | public class StrikethroughEvent {}
18 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/event/UnderlineEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.event;
16 |
17 | public class UnderlineEvent {}
18 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/util/DisplayUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.util;
16 |
17 | import android.content.Context;
18 | import android.content.res.Resources;
19 | import android.support.annotation.FloatRange;
20 | import android.support.annotation.NonNull;
21 | import android.util.DisplayMetrics;
22 | import android.util.TypedValue;
23 |
24 | public class DisplayUtils {
25 | public static float dp2px(@NonNull Context context, @FloatRange(from = 0.0f, to = Float.MAX_VALUE) float dp) {
26 | DisplayMetrics metrics = context.getResources().getDisplayMetrics();
27 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);
28 | }
29 |
30 | public static float getDensity(@NonNull Context context) {
31 | return context.getResources().getDisplayMetrics().density;
32 | }
33 |
34 | public static int getScreenHeight(@NonNull Context context) {
35 | return context.getResources().getDisplayMetrics().heightPixels;
36 | }
37 |
38 | public static int getScreenWidth(@NonNull Context context) {
39 | return context.getResources().getDisplayMetrics().widthPixels;
40 | }
41 |
42 | public static int getStatusBarHeight(@NonNull Context context) {
43 | Resources resources = context.getResources();
44 | int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
45 | if (resourceId > 0) {
46 | return resources.getDimensionPixelSize(resourceId);
47 | }
48 |
49 | return 0;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/util/ImageUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.util;
16 |
17 | import android.content.Context;
18 | import android.graphics.Bitmap;
19 | import android.graphics.Canvas;
20 | import android.graphics.Matrix;
21 | import android.graphics.drawable.BitmapDrawable;
22 | import android.graphics.drawable.Drawable;
23 | import android.graphics.drawable.InsetDrawable;
24 | import android.support.annotation.NonNull;
25 | import android.util.DisplayMetrics;
26 | import android.view.WindowManager;
27 |
28 | public class ImageUtils {
29 | // http://stackoverflow.com/questions/3035692/how-to-convert-a-drawable-to-a-bitmap
30 | public static Bitmap drawable2Bitmap(@NonNull Drawable drawable) {
31 | Bitmap bitmap;
32 |
33 | if (drawable instanceof BitmapDrawable) {
34 | BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
35 | if (bitmapDrawable.getBitmap() != null) {
36 | return bitmapDrawable.getBitmap();
37 | }
38 | }
39 |
40 | if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
41 | // Single color bitmap will be created of 1x1 pixel
42 | bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
43 | } else {
44 | bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
45 | }
46 |
47 | Canvas canvas = new Canvas(bitmap);
48 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
49 | drawable.draw(canvas);
50 | return bitmap;
51 | }
52 |
53 | // https://github.com/mthli/Tweetin/blob/master/Tweetin/src/io/github/mthli/Tweetin/Picture/PictureUnit.java
54 | public static Bitmap fixBitmap(@NonNull Context context, @NonNull Bitmap bitmap) {
55 | WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
56 | DisplayMetrics metrics = new DisplayMetrics();
57 | manager.getDefaultDisplay().getMetrics(metrics);
58 |
59 | int screenWidth = metrics.widthPixels;
60 | int screenHeight = metrics.heightPixels;
61 | int bitmapWidth = bitmap.getWidth();
62 | int bitmapHeight = bitmap.getHeight();
63 |
64 | if (bitmapWidth > screenWidth || bitmapHeight > screenHeight) {
65 | float percentW = ((float) screenWidth) / ((float) bitmapWidth);
66 | float percentH = ((float) screenHeight) / ((float) bitmapHeight);
67 | float percent = percentW < percentH ? percentW : percentH;
68 | Matrix matrix = new Matrix();
69 | matrix.postScale(percent, percent);
70 | bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmapWidth, bitmapHeight, matrix, true);
71 | }
72 |
73 | return bitmap;
74 | }
75 |
76 | public static Drawable insetBitmap(@NonNull Context context, @NonNull Bitmap bitmap) {
77 | BitmapDrawable bitmapDrawable = new BitmapDrawable(context.getResources(), bitmap);
78 | bitmapDrawable.setBounds(0, 0, bitmapDrawable.getIntrinsicWidth(), bitmapDrawable.getIntrinsicHeight());
79 |
80 | int inset = (DisplayUtils.getScreenWidth(context) - bitmapDrawable.getBounds().right) / 2;
81 | if (inset <= 0) {
82 | return bitmapDrawable;
83 | }
84 |
85 | InsetDrawable insetDrawable = new InsetDrawable(bitmapDrawable, inset, 0, inset, 0);
86 | insetDrawable.setBounds(0, 0, DisplayUtils.getScreenWidth(context), bitmapDrawable.getIntrinsicHeight());
87 | return insetDrawable;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/mthli/type/util/RxBus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Matthew Lee
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package io.github.mthli.type.util;
16 |
17 | import rx.Observable;
18 | import rx.subjects.PublishSubject;
19 | import rx.subjects.SerializedSubject;
20 | import rx.subjects.Subject;
21 |
22 | public class RxBus {
23 | private static final RxBus sRxBus = new RxBus();
24 |
25 | public static RxBus getInstance() {
26 | return sRxBus;
27 | }
28 |
29 | private Subject