├── MarkdownView
├── .idea
│ ├── .name
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── vcs.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ ├── gradle.xml
│ ├── compiler.xml
│ └── misc.xml
├── app
│ ├── .gitignore
│ ├── src
│ │ └── main
│ │ │ ├── res
│ │ │ ├── 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
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── markdown_themes.xml
│ │ │ │ ├── markdown_view.xml
│ │ │ │ └── activity_main.xml
│ │ │ ├── assets
│ │ │ ├── hello.md
│ │ │ └── markdown_css_themes
│ │ │ │ ├── alt.css
│ │ │ │ ├── foghorn.css
│ │ │ │ ├── classic.css
│ │ │ │ └── paperwhite.css
│ │ │ ├── java
│ │ │ └── us
│ │ │ │ └── feras
│ │ │ │ └── mdv
│ │ │ │ └── demo
│ │ │ │ ├── LocalMarkdownActivity.java
│ │ │ │ ├── RemoteMarkdownActivity.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── MarkdownDataActivity.java
│ │ │ │ └── MarkdownThemesActivity.java
│ │ │ └── AndroidManifest.xml
│ ├── proguard-rules.pro
│ └── build.gradle
├── markdownview
│ ├── .gitignore
│ ├── src
│ │ └── main
│ │ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ │ ├── AndroidManifest.xml
│ │ │ └── java
│ │ │ └── us
│ │ │ └── feras
│ │ │ └── mdv
│ │ │ ├── MarkdownView.java
│ │ │ └── util
│ │ │ └── HttpHelper.java
│ ├── proguard-rules.pro
│ └── build.gradle
├── settings.gradle
├── .gitignore
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── build.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
├── markdown-example.md
├── license.txt
├── .gitignore
├── css-themes
├── alt.css
├── foghorn.css
├── classic.css
└── paperwhite.css
└── README.md
/MarkdownView/.idea/.name:
--------------------------------------------------------------------------------
1 | MarkdownView
--------------------------------------------------------------------------------
/MarkdownView/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/MarkdownView/markdownview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/MarkdownView/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':markdownview'
2 |
--------------------------------------------------------------------------------
/MarkdownView/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/MarkdownView/markdownview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MarkdownView
3 |
4 |
--------------------------------------------------------------------------------
/MarkdownView/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/MarkdownView/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/falnatsheh/MarkdownView/HEAD/MarkdownView/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/falnatsheh/MarkdownView/HEAD/MarkdownView/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/falnatsheh/MarkdownView/HEAD/MarkdownView/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/falnatsheh/MarkdownView/HEAD/MarkdownView/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/falnatsheh/MarkdownView/HEAD/MarkdownView/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/falnatsheh/MarkdownView/HEAD/MarkdownView/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MarkdownView/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/MarkdownView/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Nov 10 11:53:01 EST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
7 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/assets/hello.md:
--------------------------------------------------------------------------------
1 | ## What is MarkdownView?
2 | It's an Android WebView that is capable of loading Markdown file or text and display it as HTML. The library uses MarkdownJ and extends Android WebView.
3 | ***
4 | For more information, please visit the project page on [Github](https://github.com/falnatsheh/MarkdownView)
--------------------------------------------------------------------------------
/MarkdownView/markdownview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MarkdownView Demo
3 | ### MarkdownView Live Preview \n * * * \n Edit the text to see it updated instantly.
4 |
5 |
6 | - foghorn
7 | - alt
8 | - classic
9 | - paperwhite
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/MarkdownView/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/markdown-example.md:
--------------------------------------------------------------------------------
1 | # Markdown
2 |
3 | ## Basic formatting
4 |
5 | Paragraphs can be written like so. A paragraph is the basic block of Markdown. A paragraph is what text will turn into when there is no reason it should become anything else.
6 |
7 | Paragraphs must be separated by a blank line. Basic formatting of *italics* and **bold** is supported.
8 |
9 | ## Lists
10 |
11 | ### Ordered list
12 |
13 | 1. Item 1
14 | 2. A second item
15 | 3. Number 3
16 |
17 | ### Unordered list
18 |
19 | * An item
20 | * Another item
21 | * And there's more...
22 |
--------------------------------------------------------------------------------
/MarkdownView/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.3.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/MarkdownView/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/java/us/feras/mdv/demo/LocalMarkdownActivity.java:
--------------------------------------------------------------------------------
1 | package us.feras.mdv.demo;
2 |
3 | import us.feras.mdv.MarkdownView;
4 | import android.app.Activity;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.Window;
8 |
9 | public class LocalMarkdownActivity extends AppCompatActivity {
10 | @Override
11 | public void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | MarkdownView webView = new MarkdownView(this);
14 | setContentView(webView);
15 | webView.loadMarkdownFile("file:///android_asset/hello.md");
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | Copyright 2011 Feras Alnatsheh
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | 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
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/res/layout/markdown_themes.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
11 |
12 |
17 |
18 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/java/us/feras/mdv/demo/RemoteMarkdownActivity.java:
--------------------------------------------------------------------------------
1 | package us.feras.mdv.demo;
2 |
3 | import us.feras.mdv.MarkdownView;
4 | import android.app.Activity;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.Window;
8 |
9 | public class RemoteMarkdownActivity extends AppCompatActivity {
10 | @Override
11 | public void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | MarkdownView markdownView = new MarkdownView(this);
14 | setContentView(markdownView);
15 | markdownView.loadMarkdownFile("https://raw.github.com/falnatsheh/MarkdownView/master/README.md");
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/.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 | # Mac OS X clutter
35 | *.DS_Store
36 |
37 | # Intellij IDEA
38 | .idea/workspace.xml
39 | .idea/tasks.xml
40 | .idea/datasources.xml
41 | .idea/dataSources.ids
--------------------------------------------------------------------------------
/MarkdownView/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/MarkdownView/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/feras/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/MarkdownView/markdownview/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/feras/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/MarkdownView/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/MarkdownView/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "us.feras.mdv.demo"
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 2
12 | versionName "1.1"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.1.0'
26 | compile project(':markdownview')
27 | }
28 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/res/layout/markdown_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
23 |
24 |
--------------------------------------------------------------------------------
/MarkdownView/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/MarkdownView/markdownview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | ext {
4 | PUBLISH_GROUP_ID = 'us.feras.mdv'
5 | PUBLISH_ARTIFACT_ID = 'markdownview'
6 | PUBLISH_VERSION = '1.1.0'
7 | }
8 |
9 | android {
10 | compileSdkVersion 23
11 | buildToolsVersion "23.0.1"
12 |
13 | defaultConfig {
14 | minSdkVersion 14
15 | targetSdkVersion 23
16 | versionCode 2
17 | versionName "1.1"
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | compile fileTree(dir: 'libs', include: ['*.jar'])
29 | testCompile 'junit:junit:4.12'
30 | compile 'com.android.support:appcompat-v7:23.1.0'
31 | compile 'org.markdownj:markdownj-core:0.4'
32 | }
33 |
34 | apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle'
35 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/java/us/feras/mdv/demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package us.feras.mdv.demo;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 | }
15 |
16 | public void displayDataActivity(View view) {
17 | this.startActivity(new Intent(this, MarkdownDataActivity.class));
18 | }
19 |
20 | public void displayThemesActivity(View view) {
21 | this.startActivity(new Intent(this, MarkdownThemesActivity.class));
22 | }
23 |
24 | public void displayOnlineMdActivity(View view) {
25 | this.startActivity(new Intent(this, RemoteMarkdownActivity.class));
26 | }
27 |
28 | public void displayLocalMdFileActivity(View view) {
29 | this.startActivity(new Intent(this, LocalMarkdownActivity.class));
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/css-themes/alt.css:
--------------------------------------------------------------------------------
1 | body {
2 | line-height: 1.4em;
3 | color: black;
4 | padding: 1em;
5 | margin: auto;
6 | max-width: 42em;
7 | }
8 |
9 | li {
10 | color: black;
11 | }
12 |
13 | h1,h2,h3,h4,h5,h6 {
14 | border: 0 none !important;
15 | }
16 |
17 | h1 {
18 | margin-top: 0.5em;
19 | margin-bottom: 0.5em;
20 | border-bottom: 2px solid #000080 !important;
21 | }
22 |
23 | h2 {
24 | margin-top: 1em;
25 | margin-bottom: 0.5em;
26 | border-bottom: 2px solid #000080 !important;
27 | }
28 |
29 | pre {
30 | background-color: #f8f8f8;
31 | border: 1px solid #2f6fab;
32 | border-radius: 3px;
33 | overflow: auto;
34 | padding: 5px;
35 | }
36 |
37 | pre code {
38 | background-color: inherit;
39 | border: none;
40 | padding: 0;
41 | }
42 |
43 | code {
44 | background-color: #ffffe0;
45 | border: 1px solid orange;
46 | border-radius: 3px;
47 | padding: 0 0.2em;
48 | }
49 |
50 | a {
51 | text-decoration: underline;
52 | }
53 |
54 | ul,ol {
55 | padding-left: 30px;
56 | }
57 |
58 | li {
59 | margin: 0.2em 0 0 0em;
60 | padding: 0px;
61 | }
62 |
63 | em {
64 | color: #b05000;
65 | }
66 |
67 | table.text th,table.text td {
68 | vertical-align: top;
69 | border-top: 1px solid #ccc;
70 | padding: 5px;
71 | }
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/assets/markdown_css_themes/alt.css:
--------------------------------------------------------------------------------
1 | body {
2 | line-height: 1.4em;
3 | color: black;
4 | padding: 1em;
5 | margin: auto;
6 | max-width: 42em;
7 | }
8 |
9 | li {
10 | color: black;
11 | }
12 |
13 | h1,h2,h3,h4,h5,h6 {
14 | border: 0 none !important;
15 | }
16 |
17 | h1 {
18 | margin-top: 0.5em;
19 | margin-bottom: 0.5em;
20 | border-bottom: 2px solid #000080 !important;
21 | }
22 |
23 | h2 {
24 | margin-top: 1em;
25 | margin-bottom: 0.5em;
26 | border-bottom: 2px solid #000080 !important;
27 | }
28 |
29 | pre {
30 | background-color: #f8f8f8;
31 | border: 1px solid #2f6fab;
32 | border-radius: 3px;
33 | overflow: auto;
34 | padding: 5px;
35 | }
36 |
37 | pre code {
38 | background-color: inherit;
39 | border: none;
40 | padding: 0;
41 | }
42 |
43 | code {
44 | background-color: #ffffe0;
45 | border: 1px solid orange;
46 | border-radius: 3px;
47 | padding: 0 0.2em;
48 | }
49 |
50 | a {
51 | text-decoration: underline;
52 | }
53 |
54 | ul,ol {
55 | padding-left: 30px;
56 | }
57 |
58 | li {
59 | margin: 0.2em 0 0 0em;
60 | padding: 0px;
61 | }
62 |
63 | em {
64 | color: #b05000;
65 | }
66 |
67 | table.text th,table.text td {
68 | vertical-align: top;
69 | border-top: 1px solid #ccc;
70 | padding: 5px;
71 | }
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/java/us/feras/mdv/demo/MarkdownDataActivity.java:
--------------------------------------------------------------------------------
1 | package us.feras.mdv.demo;
2 |
3 | import us.feras.mdv.MarkdownView;
4 | import android.app.Activity;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.text.Editable;
8 | import android.text.TextWatcher;
9 | import android.view.View;
10 | import android.view.View.OnClickListener;
11 | import android.widget.Button;
12 | import android.widget.EditText;
13 |
14 | public class MarkdownDataActivity extends AppCompatActivity {
15 |
16 | private EditText markdownEditText;
17 | private MarkdownView markdownView;
18 |
19 | @Override
20 | public void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.markdown_view);
23 | markdownEditText = (EditText) findViewById(R.id.markdownText);
24 | markdownView = (MarkdownView) findViewById(R.id.markdownView);
25 | String text = getResources().getString(R.string.md_sample_data);
26 | markdownEditText.setText(text);
27 | updateMarkdownView();
28 |
29 | markdownEditText.addTextChangedListener(new TextWatcher() {
30 |
31 | @Override
32 | public void afterTextChanged(Editable s) {}
33 |
34 | @Override
35 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
36 |
37 | @Override
38 | public void onTextChanged(CharSequence s, int start, int before, int count) {
39 | updateMarkdownView();
40 | }
41 | });
42 |
43 |
44 | }
45 |
46 | private void updateMarkdownView() {
47 | markdownView.loadMarkdown(markdownEditText.getText().toString());
48 | }
49 | }
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/java/us/feras/mdv/demo/MarkdownThemesActivity.java:
--------------------------------------------------------------------------------
1 | package us.feras.mdv.demo;
2 |
3 | import us.feras.mdv.MarkdownView;
4 | import android.app.Activity;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.AdapterView;
9 | import android.widget.AdapterView.OnItemSelectedListener;
10 | import android.widget.ArrayAdapter;
11 | import android.widget.Spinner;
12 |
13 | public class MarkdownThemesActivity extends AppCompatActivity implements
14 | OnItemSelectedListener {
15 | @Override
16 | public void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.markdown_themes);
19 | Spinner themesSpinner = (Spinner) findViewById(R.id.themes_spinner);
20 | ArrayAdapter adapter = ArrayAdapter.createFromResource(
21 | this, R.array.md_themes, android.R.layout.simple_spinner_item);
22 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
23 | themesSpinner.setAdapter(adapter);
24 | themesSpinner.setSelection(0);
25 | themesSpinner.setOnItemSelectedListener(this);
26 | }
27 |
28 | @Override
29 | public void onItemSelected(AdapterView> parent, View view, int pos,
30 | long id) {
31 | MarkdownView mdv = (MarkdownView) findViewById(R.id.markdownView);
32 | mdv.loadMarkdownFile("file:///android_asset/hello.md",
33 | "file:///android_asset/markdown_css_themes/"
34 | + parent.getItemAtPosition(pos).toString() + ".css");
35 | }
36 |
37 | @Override
38 | public void onNothingSelected(AdapterView> parent) {
39 | // no-op
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
21 |
22 |
30 |
31 |
41 |
42 |
52 |
53 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/MarkdownView/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/css-themes/foghorn.css:
--------------------------------------------------------------------------------
1 | html, body {
2 | padding:1em;
3 | margin:auto;
4 | max-width:42em;
5 | background:#fefefe;
6 | }
7 | body {
8 | font: 1.3em "Vollkorn", Palatino, Times;
9 | color: #333;
10 | line-height: 1.4;
11 | text-align: justify;
12 | }
13 | header, nav, article, footer {
14 | width: 700px;
15 | margin:0 auto;
16 | }
17 | article {
18 | margin-top: 4em;
19 | margin-bottom: 4em;
20 | min-height: 400px;
21 | }
22 | footer {
23 | margin-bottom:50px;
24 | }
25 | video {
26 | margin: 2em 0;
27 | border:1px solid #ddd;
28 | }
29 |
30 | nav {
31 | font-size: .9em;
32 | font-style: italic;
33 | border-bottom: 1px solid #ddd;
34 | padding: 1em 0;
35 | }
36 | nav p {
37 | margin: 0;
38 | }
39 |
40 | /* Typography
41 | -------------------------------------------------------- */
42 |
43 | h1 {
44 | margin-top: 0;
45 | font-weight: normal;
46 | }
47 | h2 {
48 | font-weight: normal;
49 | }
50 | h3 {
51 | font-weight: normal;
52 | font-style: italic;
53 | margin-top:3em;
54 | }
55 | p {
56 | margin-top:0;
57 | -webkit-hypens:auto;
58 | -moz-hypens:auto;
59 | hyphens:auto;
60 | }
61 | ul {
62 | list-style: square;
63 | padding-left:1.2em;
64 | }
65 | ol {
66 | padding-left:1.2em;
67 | }
68 | blockquote {
69 | margin-left: 1em;
70 | padding-left: 1em;
71 | border-left: 1px solid #ddd;
72 | }
73 | code {
74 | font-family: "Consolas", "Menlo", "Monaco", monospace, serif;
75 | font-size: .9em;
76 | background: white;
77 | }
78 | a {
79 | color: #2484c1;
80 | text-decoration: none;
81 | }
82 | a:hover {
83 | text-decoration: underline;
84 | }
85 | a img {
86 | border:none;
87 | }
88 | h1 a, h1 a:hover {
89 | color: #333;
90 | text-decoration: none;
91 | }
92 | hr {
93 | color : #ddd;
94 | height : 1px;
95 | margin: 2em 0;
96 | border-top : solid 1px #ddd;
97 | border-bottom : none;
98 | border-left: 0;
99 | border-right: 0;
100 | }
101 | p#heart{
102 | font-size: 2em;
103 | line-height: 1;
104 | text-align: center;
105 | color: #ccc;
106 | }
107 | .red {
108 | color:#B50000;
109 | }
110 |
111 | /* Home Page
112 | --------------------------- */
113 |
114 | body#index li {
115 | margin-bottom: 1em;
116 | }
117 |
118 |
119 | /* iPad
120 | -------------------------------------------------------- */
121 | @media only screen and (max-device-width: 1024px) {
122 | body {
123 | font-size: 120%;
124 | line-height: 1.4;
125 | }
126 | } /* @iPad */
127 |
128 | /* iPhone
129 | -------------------------------------------------------- */
130 | @media only screen and (max-device-width: 480px) {
131 | body {
132 | text-align: left;
133 | }
134 | article, footer {
135 | width: auto;
136 | }
137 | article {
138 | padding: 0 10px;
139 | }
140 | } /* @iPhone */
141 |
142 |
--------------------------------------------------------------------------------
/css-themes/classic.css:
--------------------------------------------------------------------------------
1 | @charset "utf-8";
2 |
3 | /**
4 | * markdown.css
5 | *
6 | * This program is free software: you can redistribute it and/or modify it under
7 | * the terms of the GNU Lesser General Public License as published by the Free
8 | * Software Foundation, either version 3 of the License, or (at your option) any
9 | * later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 | * details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see http://gnu.org/licenses/lgpl.txt.
18 | *
19 | * @project Weblog and Open Source Projects of Florian Wolters
20 | * @version GIT: $Id$
21 | * @package xhtml-css
22 | * @author Florian Wolters
23 | * @copyright 2012 Florian Wolters
24 | * @cssdoc version 1.0-pre
25 | * @license http://gnu.org/licenses/lgpl.txt GNU Lesser General Public License
26 | * @link http://github.com/FlorianWolters/jekyll-bootstrap-theme
27 | * @media all
28 | * @valid true
29 | */
30 |
31 | body {
32 | font-family: Helvetica, Arial, Freesans, clean, sans-serif;
33 | padding:1em;
34 | margin:auto;
35 | max-width:42em;
36 | background:#fefefe;
37 | }
38 |
39 | h1, h2, h3, h4, h5, h6 {
40 | font-weight: bold;
41 | }
42 |
43 | h1 {
44 | color: #000000;
45 | font-size: 28px;
46 | }
47 |
48 | h2 {
49 | border-bottom: 1px solid #CCCCCC;
50 | color: #000000;
51 | font-size: 24px;
52 | }
53 |
54 | h3 {
55 | font-size: 18px;
56 | }
57 |
58 | h4 {
59 | font-size: 16px;
60 | }
61 |
62 | h5 {
63 | font-size: 14px;
64 | }
65 |
66 | h6 {
67 | color: #777777;
68 | background-color: inherit;
69 | font-size: 14px;
70 | }
71 |
72 | hr {
73 | height: 0.2em;
74 | border: 0;
75 | color: #CCCCCC;
76 | background-color: #CCCCCC;
77 | }
78 |
79 | p, blockquote, ul, ol, dl, li, table, pre {
80 | margin: 15px 0;
81 | }
82 |
83 | code, pre {
84 | border-radius: 3px;
85 | background-color: #F8F8F8;
86 | color: inherit;
87 | }
88 |
89 | code {
90 | border: 1px solid #EAEAEA;
91 | margin: 0 2px;
92 | padding: 0 5px;
93 | }
94 |
95 | pre {
96 | border: 1px solid #CCCCCC;
97 | line-height: 1.25em;
98 | overflow: auto;
99 | padding: 6px 10px;
100 | }
101 |
102 | pre > code {
103 | border: 0;
104 | margin: 0;
105 | padding: 0;
106 | }
107 |
108 | a, a:visited {
109 | color: #4183C4;
110 | background-color: inherit;
111 | text-decoration: none;
112 | }
113 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/assets/markdown_css_themes/foghorn.css:
--------------------------------------------------------------------------------
1 | html, body {
2 | padding:1em;
3 | margin:auto;
4 | max-width:42em;
5 | background:#fefefe;
6 | }
7 | body {
8 | font: 1.3em "Vollkorn", Palatino, Times;
9 | color: #333;
10 | line-height: 1.4;
11 | text-align: justify;
12 | }
13 | header, nav, article, footer {
14 | width: 700px;
15 | margin:0 auto;
16 | }
17 | article {
18 | margin-top: 4em;
19 | margin-bottom: 4em;
20 | min-height: 400px;
21 | }
22 | footer {
23 | margin-bottom:50px;
24 | }
25 | video {
26 | margin: 2em 0;
27 | border:1px solid #ddd;
28 | }
29 |
30 | nav {
31 | font-size: .9em;
32 | font-style: italic;
33 | border-bottom: 1px solid #ddd;
34 | padding: 1em 0;
35 | }
36 | nav p {
37 | margin: 0;
38 | }
39 |
40 | /* Typography
41 | -------------------------------------------------------- */
42 |
43 | h1 {
44 | margin-top: 0;
45 | font-weight: normal;
46 | }
47 | h2 {
48 | font-weight: normal;
49 | }
50 | h3 {
51 | font-weight: normal;
52 | font-style: italic;
53 | margin-top:3em;
54 | }
55 | p {
56 | margin-top:0;
57 | -webkit-hypens:auto;
58 | -moz-hypens:auto;
59 | hyphens:auto;
60 | }
61 | ul {
62 | list-style: square;
63 | padding-left:1.2em;
64 | }
65 | ol {
66 | padding-left:1.2em;
67 | }
68 | blockquote {
69 | margin-left: 1em;
70 | padding-left: 1em;
71 | border-left: 1px solid #ddd;
72 | }
73 | code {
74 | font-family: "Consolas", "Menlo", "Monaco", monospace, serif;
75 | font-size: .9em;
76 | background: white;
77 | }
78 | a {
79 | color: #2484c1;
80 | text-decoration: none;
81 | }
82 | a:hover {
83 | text-decoration: underline;
84 | }
85 | a img {
86 | border:none;
87 | }
88 | h1 a, h1 a:hover {
89 | color: #333;
90 | text-decoration: none;
91 | }
92 | hr {
93 | color : #ddd;
94 | height : 1px;
95 | margin: 2em 0;
96 | border-top : solid 1px #ddd;
97 | border-bottom : none;
98 | border-left: 0;
99 | border-right: 0;
100 | }
101 | p#heart{
102 | font-size: 2em;
103 | line-height: 1;
104 | text-align: center;
105 | color: #ccc;
106 | }
107 | .red {
108 | color:#B50000;
109 | }
110 |
111 | /* Home Page
112 | --------------------------- */
113 |
114 | body#index li {
115 | margin-bottom: 1em;
116 | }
117 |
118 |
119 | /* iPad
120 | -------------------------------------------------------- */
121 | @media only screen and (max-device-width: 1024px) {
122 | body {
123 | font-size: 120%;
124 | line-height: 1.4;
125 | }
126 | } /* @iPad */
127 |
128 | /* iPhone
129 | -------------------------------------------------------- */
130 | @media only screen and (max-device-width: 480px) {
131 | body {
132 | text-align: left;
133 | }
134 | article, footer {
135 | width: auto;
136 | }
137 | article {
138 | padding: 0 10px;
139 | }
140 | } /* @iPhone */
141 |
142 |
--------------------------------------------------------------------------------
/MarkdownView/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Android API 19 Platform
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/assets/markdown_css_themes/classic.css:
--------------------------------------------------------------------------------
1 | @charset "utf-8";
2 |
3 | /**
4 | * markdown.css
5 | *
6 | * This program is free software: you can redistribute it and/or modify it under
7 | * the terms of the GNU Lesser General Public License as published by the Free
8 | * Software Foundation, either version 3 of the License, or (at your option) any
9 | * later version.
10 | *
11 | * This program is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 | * details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with this program. If not, see http://gnu.org/licenses/lgpl.txt.
18 | *
19 | * @project Weblog and Open Source Projects of Florian Wolters
20 | * @version GIT: $Id$
21 | * @package xhtml-css
22 | * @author Florian Wolters
23 | * @copyright 2012 Florian Wolters
24 | * @cssdoc version 1.0-pre
25 | * @license http://gnu.org/licenses/lgpl.txt GNU Lesser General Public License
26 | * @link http://github.com/FlorianWolters/jekyll-bootstrap-theme
27 | * @media all
28 | * @valid true
29 | */
30 |
31 | body {
32 | font-family: Helvetica, Arial, Freesans, clean, sans-serif;
33 | padding:1em;
34 | margin:auto;
35 | max-width:42em;
36 | background:#fefefe;
37 | }
38 |
39 | h1, h2, h3, h4, h5, h6 {
40 | font-weight: bold;
41 | }
42 |
43 | h1 {
44 | color: #000000;
45 | font-size: 28px;
46 | }
47 |
48 | h2 {
49 | border-bottom: 1px solid #CCCCCC;
50 | color: #000000;
51 | font-size: 24px;
52 | }
53 |
54 | h3 {
55 | font-size: 18px;
56 | }
57 |
58 | h4 {
59 | font-size: 16px;
60 | }
61 |
62 | h5 {
63 | font-size: 14px;
64 | }
65 |
66 | h6 {
67 | color: #777777;
68 | background-color: inherit;
69 | font-size: 14px;
70 | }
71 |
72 | hr {
73 | height: 0.2em;
74 | border: 0;
75 | color: #CCCCCC;
76 | background-color: #CCCCCC;
77 | }
78 |
79 | p, blockquote, ul, ol, dl, li, table, pre {
80 | margin: 15px 0;
81 | }
82 |
83 | code, pre {
84 | border-radius: 3px;
85 | background-color: #F8F8F8;
86 | color: inherit;
87 | }
88 |
89 | code {
90 | border: 1px solid #EAEAEA;
91 | margin: 0 2px;
92 | padding: 0 5px;
93 | }
94 |
95 | pre {
96 | border: 1px solid #CCCCCC;
97 | line-height: 1.25em;
98 | overflow: auto;
99 | padding: 6px 10px;
100 | }
101 |
102 | pre > code {
103 | border: 0;
104 | margin: 0;
105 | padding: 0;
106 | }
107 |
108 | a, a:visited {
109 | color: #4183C4;
110 | background-color: inherit;
111 | text-decoration: none;
112 | }
113 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | 
3 | [](https://bintray.com/falnatsheh/maven/MarkdownView/_latestVersion)
4 |
5 | ## About
6 |
7 | MarkdownView (Markdown For Android) is an Android library that helps you display Markdown text or files (local/remote) as formatted HTML, and style the output using CSS.
8 |
9 | The MarkdownView itself extends Android Webview and adds the necessary logic to parse Markdown (using MarkdownJ) and display the output HTML on the view.
10 |
11 | ## Getting started
12 |
13 | - To add MarkdownView to your project, add the following to `build.gradle` file:
14 | ```javascript
15 | dependencies {
16 | compile 'us.feras.mdv:markdownview:1.1.0'
17 | }
18 | ```
19 |
20 | ## Usage
21 |
22 | Add MarkdownView to your layout:
23 |
24 | ```xml
25 |
29 | ```
30 |
31 | and reference it in your Activity/Fragment:
32 |
33 | ```java
34 | MarkdownView markdownView = (MarkdownView) findViewById(R.id.markdownView);
35 | markdownView.loadMarkdown("## Hello Markdown");
36 | ```
37 | **Note**:
38 | You could also create the view by code. Below an example of how to set the whole activity to be a MarkdownView by Adding the following to your onCreate method:
39 |
40 | ```java
41 | MarkdownView markdownView = new MarkdownView(this);
42 | setContentView(markdownView);
43 | markdownView.loadMarkdown("## Hello Markdown");
44 | ```
45 |
46 | ## Screenshots
47 |
48 |
49 |
50 |
51 | ## Demo App and Code Sample
52 |
53 | The above screenshots taking from the demo app which could be found here. The demo app include code to demonstrate:
54 |
55 | - Loading Local Markdown File.
56 | - Loading Remote Markdown File.
57 | - Loading Markdown text.
58 | - Live Preview sample code (similar to [Marked Mac app](http://marked2app.com/))
59 | - Themes
60 |
61 | ## Loading Markdown text or file:
62 |
63 | - `loadMarkdown(String text)`:
64 | Using this method will result in loading md string to the MarkdownView and displaying it as HTML.
65 |
66 |
67 | - `loadMarkdownFile(String url)`:
68 | You can use this method to load local or online files.
69 |
70 | To load a local file, you have to add it to your assets folder and pass a url that start with "file:///android_asset/" :
71 |
72 | ```java
73 | markdownView.loadMarkdownFile("file:///android_asset/myFile.md");
74 | ```
75 |
76 | To load a remote file you need to pass the full url :
77 |
78 | ```java
79 | markdownView.loadMarkdownFile("http://www.my-site.com/myFile.md");
80 | ```
81 |
82 | ## Theming
83 |
84 | You could apply custom CSS to the MarkdownView. Example:
85 |
86 | ```java
87 | markdownView.loadMarkdownFile("file:///android_asset/hello.md","file:///android_asset/MyCustomTheme.css");
88 | ```
89 | You could take a look at CSS example [here](https://github.com/falnatsheh/MarkdownView/tree/master/css-themes), you could also view them in the sample app.
90 |
91 | ## ChangeLog:
92 |
93 | - **MarkdownView 1.1.0**:
94 | - Support Loading Markdown file from assets subfolders (Thanks [@echodjb](https://github.com/DiegoRosado)).
95 | - **MarkdownView 1.0.0**:
96 | - Convert to Gradle Project (Avillable now on [jCenter](https://bintray.com/falnatsheh/maven/MarkdownView/view)).
97 | - Fix CSS Issue (Thanks [@swanson](https://github.com/swanson) & [@echodjb](https://github.com/echodjb)).
98 | - Update demo app.
99 |
100 |
101 | ## License
102 | Apache 2.0
103 |
--------------------------------------------------------------------------------
/css-themes/paperwhite.css:
--------------------------------------------------------------------------------
1 | html {
2 | font-size: 100%;
3 | overflow-y: scroll;
4 | -webkit-text-size-adjust: 100%;
5 | -ms-text-size-adjust: 100%;
6 | }
7 |
8 | body {
9 | color: #444;
10 | font-family: Georgia, Palatino, 'Palatino Linotype', Times,
11 | 'Times New Roman', serif;
12 | font-size: 12px;
13 | line-height: 1.5em;
14 | padding: 1em;
15 | margin: auto;
16 | max-width: 42em;
17 | background: #fefefe;
18 | }
19 |
20 | a {
21 | color: #0645ad;
22 | text-decoration: none;
23 | }
24 |
25 | a:visited {
26 | color: #0b0080;
27 | }
28 |
29 | a:hover {
30 | color: #06e;
31 | }
32 |
33 | a:active {
34 | color: #faa700;
35 | }
36 |
37 | a:focus {
38 | outline: thin dotted;
39 | }
40 |
41 | a:hover,a:active {
42 | outline: 0;
43 | }
44 |
45 | ::-moz-selection {
46 | background: rgba(255, 255, 0, 0.3);
47 | color: #000
48 | }
49 |
50 | ::selection {
51 | background: rgba(255, 255, 0, 0.3);
52 | color: #000
53 | }
54 |
55 | a::-moz-selection {
56 | background: rgba(255, 255, 0, 0.3);
57 | color: #0645ad
58 | }
59 |
60 | a::selection {
61 | background: rgba(255, 255, 0, 0.3);
62 | color: #0645ad
63 | }
64 |
65 | p {
66 | margin: 1em 0;
67 | }
68 |
69 | img {
70 | max-width: 100%;
71 | }
72 |
73 | h1,h2,h3,h4,h5,h6 {
74 | font-weight: normal;
75 | color: #111;
76 | line-height: 1em;
77 | }
78 |
79 | h4,h5,h6 {
80 | font-weight: bold;
81 | }
82 |
83 | h1 {
84 | font-size: 2.5em;
85 | }
86 |
87 | h2 {
88 | font-size: 2em;
89 | }
90 |
91 | h3 {
92 | font-size: 1.5em;
93 | }
94 |
95 | h4 {
96 | font-size: 1.2em;
97 | }
98 |
99 | h5 {
100 | font-size: 1em;
101 | }
102 |
103 | h6 {
104 | font-size: 0.9em;
105 | }
106 |
107 | blockquote {
108 | color: #666666;
109 | margin: 0;
110 | padding-left: 3em;
111 | border-left: 0.5em #EEE solid;
112 | }
113 |
114 | hr {
115 | display: block;
116 | height: 2px;
117 | border: 0;
118 | border-top: 1px solid #aaa;
119 | border-bottom: 1px solid #eee;
120 | margin: 1em 0;
121 | padding: 0;
122 | }
123 |
124 | pre,code,kbd,samp {
125 | color: #000;
126 | font-family: monospace, monospace;
127 | _font-family: 'courier new', monospace;
128 | font-size: 0.98em;
129 | }
130 |
131 | pre {
132 | white-space: pre;
133 | white-space: pre-wrap;
134 | word-wrap: break-word;
135 | }
136 |
137 | b,strong {
138 | font-weight: bold;
139 | }
140 |
141 | dfn {
142 | font-style: italic;
143 | }
144 |
145 | ins {
146 | background: #ff9;
147 | color: #000;
148 | text-decoration: none;
149 | }
150 |
151 | mark {
152 | background: #ff0;
153 | color: #000;
154 | font-style: italic;
155 | font-weight: bold;
156 | }
157 |
158 | sub,sup {
159 | font-size: 75%;
160 | line-height: 0;
161 | position: relative;
162 | vertical-align: baseline;
163 | }
164 |
165 | sup {
166 | top: -0.5em;
167 | }
168 |
169 | sub {
170 | bottom: -0.25em;
171 | }
172 |
173 | ul,ol {
174 | margin: 1em 0;
175 | padding: 0 0 0 2em;
176 | }
177 |
178 | li p:last-child {
179 | margin: 0
180 | }
181 |
182 | dd {
183 | margin: 0 0 0 2em;
184 | }
185 |
186 | img {
187 | border: 0;
188 | -ms-interpolation-mode: bicubic;
189 | vertical-align: middle;
190 | }
191 |
192 | table {
193 | border-collapse: collapse;
194 | border-spacing: 0;
195 | }
196 |
197 | td {
198 | vertical-align: top;
199 | }
200 |
201 | @media only screen and (min-width: 480px) {
202 | body {
203 | font-size: 14px;
204 | }
205 | }
206 |
207 | @media only screen and (min-width: 768px) {
208 | body {
209 | font-size: 16px;
210 | }
211 | }
212 |
213 | @media print {
214 | * {
215 | background: transparent !important;
216 | color: black !important;
217 | filter: none !important;
218 | -ms-filter: none !important;
219 | }
220 | body {
221 | font-size: 12pt;
222 | max-width: 100%;
223 | }
224 | a,a:visited {
225 | text-decoration: underline;
226 | }
227 | hr {
228 | height: 1px;
229 | border: 0;
230 | border-bottom: 1px solid black;
231 | }
232 | a[href]:after {
233 | content: " (" attr(href) ")";
234 | }
235 | abbr[title]:after {
236 | content: " (" attr(title) ")";
237 | }
238 | .ir a:after,a[href ^="javascript:"]:after,a[href ^="#"]:after {
239 | content: "";
240 | }
241 | pre,blockquote {
242 | border: 1px solid #999;
243 | padding-right: 1em;
244 | page-break-inside: avoid;
245 | }
246 | tr,img {
247 | page-break-inside: avoid;
248 | }
249 | img {
250 | max-width: 100% !important;
251 | }
252 | @page :left {
253 | margin: 15mm 20mm 15mm 10mm;
254 | }
255 | @page :right {
256 | margin: 15mm 10mm 15mm 20mm;
257 | }
258 | p,h2,h3 {
259 | orphans: 3;
260 | widows: 3;
261 | }
262 | h2,h3 {
263 | page-break-after: avoid;
264 | }
265 | }
--------------------------------------------------------------------------------
/MarkdownView/app/src/main/assets/markdown_css_themes/paperwhite.css:
--------------------------------------------------------------------------------
1 | html {
2 | font-size: 100%;
3 | overflow-y: scroll;
4 | -webkit-text-size-adjust: 100%;
5 | -ms-text-size-adjust: 100%;
6 | }
7 |
8 | body {
9 | color: #444;
10 | font-family: Georgia, Palatino, 'Palatino Linotype', Times,
11 | 'Times New Roman', serif;
12 | font-size: 12px;
13 | line-height: 1.5em;
14 | padding: 1em;
15 | margin: auto;
16 | max-width: 42em;
17 | background: #fefefe;
18 | }
19 |
20 | a {
21 | color: #0645ad;
22 | text-decoration: none;
23 | }
24 |
25 | a:visited {
26 | color: #0b0080;
27 | }
28 |
29 | a:hover {
30 | color: #06e;
31 | }
32 |
33 | a:active {
34 | color: #faa700;
35 | }
36 |
37 | a:focus {
38 | outline: thin dotted;
39 | }
40 |
41 | a:hover,a:active {
42 | outline: 0;
43 | }
44 |
45 | ::-moz-selection {
46 | background: rgba(255, 255, 0, 0.3);
47 | color: #000
48 | }
49 |
50 | ::selection {
51 | background: rgba(255, 255, 0, 0.3);
52 | color: #000
53 | }
54 |
55 | a::-moz-selection {
56 | background: rgba(255, 255, 0, 0.3);
57 | color: #0645ad
58 | }
59 |
60 | a::selection {
61 | background: rgba(255, 255, 0, 0.3);
62 | color: #0645ad
63 | }
64 |
65 | p {
66 | margin: 1em 0;
67 | }
68 |
69 | img {
70 | max-width: 100%;
71 | }
72 |
73 | h1,h2,h3,h4,h5,h6 {
74 | font-weight: normal;
75 | color: #111;
76 | line-height: 1em;
77 | }
78 |
79 | h4,h5,h6 {
80 | font-weight: bold;
81 | }
82 |
83 | h1 {
84 | font-size: 2.5em;
85 | }
86 |
87 | h2 {
88 | font-size: 2em;
89 | }
90 |
91 | h3 {
92 | font-size: 1.5em;
93 | }
94 |
95 | h4 {
96 | font-size: 1.2em;
97 | }
98 |
99 | h5 {
100 | font-size: 1em;
101 | }
102 |
103 | h6 {
104 | font-size: 0.9em;
105 | }
106 |
107 | blockquote {
108 | color: #666666;
109 | margin: 0;
110 | padding-left: 3em;
111 | border-left: 0.5em #EEE solid;
112 | }
113 |
114 | hr {
115 | display: block;
116 | height: 2px;
117 | border: 0;
118 | border-top: 1px solid #aaa;
119 | border-bottom: 1px solid #eee;
120 | margin: 1em 0;
121 | padding: 0;
122 | }
123 |
124 | pre,code,kbd,samp {
125 | color: #000;
126 | font-family: monospace, monospace;
127 | _font-family: 'courier new', monospace;
128 | font-size: 0.98em;
129 | }
130 |
131 | pre {
132 | white-space: pre;
133 | white-space: pre-wrap;
134 | word-wrap: break-word;
135 | }
136 |
137 | b,strong {
138 | font-weight: bold;
139 | }
140 |
141 | dfn {
142 | font-style: italic;
143 | }
144 |
145 | ins {
146 | background: #ff9;
147 | color: #000;
148 | text-decoration: none;
149 | }
150 |
151 | mark {
152 | background: #ff0;
153 | color: #000;
154 | font-style: italic;
155 | font-weight: bold;
156 | }
157 |
158 | sub,sup {
159 | font-size: 75%;
160 | line-height: 0;
161 | position: relative;
162 | vertical-align: baseline;
163 | }
164 |
165 | sup {
166 | top: -0.5em;
167 | }
168 |
169 | sub {
170 | bottom: -0.25em;
171 | }
172 |
173 | ul,ol {
174 | margin: 1em 0;
175 | padding: 0 0 0 2em;
176 | }
177 |
178 | li p:last-child {
179 | margin: 0
180 | }
181 |
182 | dd {
183 | margin: 0 0 0 2em;
184 | }
185 |
186 | img {
187 | border: 0;
188 | -ms-interpolation-mode: bicubic;
189 | vertical-align: middle;
190 | }
191 |
192 | table {
193 | border-collapse: collapse;
194 | border-spacing: 0;
195 | }
196 |
197 | td {
198 | vertical-align: top;
199 | }
200 |
201 | @media only screen and (min-width: 480px) {
202 | body {
203 | font-size: 14px;
204 | }
205 | }
206 |
207 | @media only screen and (min-width: 768px) {
208 | body {
209 | font-size: 16px;
210 | }
211 | }
212 |
213 | @media print {
214 | * {
215 | background: transparent !important;
216 | color: black !important;
217 | filter: none !important;
218 | -ms-filter: none !important;
219 | }
220 | body {
221 | font-size: 12pt;
222 | max-width: 100%;
223 | }
224 | a,a:visited {
225 | text-decoration: underline;
226 | }
227 | hr {
228 | height: 1px;
229 | border: 0;
230 | border-bottom: 1px solid black;
231 | }
232 | a[href]:after {
233 | content: " (" attr(href) ")";
234 | }
235 | abbr[title]:after {
236 | content: " (" attr(title) ")";
237 | }
238 | .ir a:after,a[href ^="javascript:"]:after,a[href ^="#"]:after {
239 | content: "";
240 | }
241 | pre,blockquote {
242 | border: 1px solid #999;
243 | padding-right: 1em;
244 | page-break-inside: avoid;
245 | }
246 | tr,img {
247 | page-break-inside: avoid;
248 | }
249 | img {
250 | max-width: 100% !important;
251 | }
252 | @page :left {
253 | margin: 15mm 20mm 15mm 10mm;
254 | }
255 | @page :right {
256 | margin: 15mm 10mm 15mm 20mm;
257 | }
258 | p,h2,h3 {
259 | orphans: 3;
260 | widows: 3;
261 | }
262 | h2,h3 {
263 | page-break-after: avoid;
264 | }
265 | }
--------------------------------------------------------------------------------
/MarkdownView/markdownview/src/main/java/us/feras/mdv/MarkdownView.java:
--------------------------------------------------------------------------------
1 | package us.feras.mdv;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.InputStreamReader;
7 | import java.io.Reader;
8 |
9 | import us.feras.mdv.util.HttpHelper;
10 |
11 | import android.content.Context;
12 | import android.os.AsyncTask;
13 | import android.util.AttributeSet;
14 | import android.util.Log;
15 | import android.webkit.URLUtil;
16 | import android.webkit.WebView;
17 |
18 | import org.markdownj.MarkdownProcessor;
19 |
20 | /**
21 | * @author Feras Alnatsheh
22 | */
23 | public class MarkdownView extends WebView {
24 |
25 | private static final String TAG = "MarkdownView";
26 |
27 | public MarkdownView(Context context, AttributeSet attrs) {
28 | super(context, attrs);
29 | }
30 |
31 | public MarkdownView(Context context) {
32 | super(context);
33 | }
34 |
35 | /**
36 | * Loads the given Markdown text to the view as rich formatted HTML. The
37 | * HTML output will be styled based on the given CSS file.
38 | *
39 | * @param txt
40 | * - input in markdown format
41 | * @param cssFileUrl
42 | * - a URL to css File. If the file located in the project assets
43 | * folder then the URL should start with "file:///android_asset/"
44 | */
45 | public void loadMarkdown(String txt, String cssFileUrl) {
46 | loadMarkdownToView(txt, cssFileUrl);
47 | }
48 |
49 | /**
50 | * Loads the given Markdown text to the view as rich formatted HTML.
51 | *
52 | * @param txt
53 | * - input in Markdown format
54 | */
55 | public void loadMarkdown(String txt) {
56 | loadMarkdown(txt, null);
57 | }
58 |
59 | /**
60 | * Loads the given Markdown file to the view as rich formatted HTML. The HTML
61 | * output will be styled based on the given CSS file.
62 | *
63 | * @param url
64 | * - a URL to the Markdown file. If the file located in the
65 | * project assets folder then the URL should start with
66 | * "file:///android_asset/"
67 | * @param cssFileUrl
68 | * - a URL to css File. If the file located in the project assets
69 | * folder then the URL should start with "file:///android_asset/"
70 | */
71 | public void loadMarkdownFile(String url, String cssFileUrl) {
72 | new LoadMarkdownUrlTask().execute(url, cssFileUrl);
73 | }
74 |
75 | public void loadMarkdownFile(String url) {
76 | loadMarkdownFile(url, null);
77 | }
78 |
79 | private String readFileFromAsset(String fileName){
80 | try {
81 | InputStream input = getContext().getAssets().open(fileName);
82 | try {
83 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(input));
84 | StringBuilder content = new StringBuilder(input.available());
85 | String line;
86 | while ((line = bufferedReader.readLine()) != null) {
87 | content.append(line);
88 | content.append(System.getProperty("line.separator"));
89 | }
90 | return content.toString();
91 | } finally { input.close(); }
92 | } catch (Exception ex){
93 | Log.d(TAG, "Error while reading file from assets", ex);
94 | return null;
95 | }
96 | }
97 |
98 | private class LoadMarkdownUrlTask extends
99 | AsyncTask {
100 | private String cssFileUrl;
101 |
102 | protected String doInBackground(String... params) {
103 | try {
104 | String markdown = "";
105 | String url = params[0];
106 | this.cssFileUrl = params[1];
107 | if(URLUtil.isNetworkUrl(url)){
108 | markdown = HttpHelper.get(url).getResponseMessage();
109 | } else if (URLUtil.isAssetUrl(url)) {
110 | markdown = readFileFromAsset(url.substring("file:///android_asset/".length() , url.length()));
111 | } else{
112 | throw new IllegalArgumentException("The URL string provided is not a network URL or Asset URL.");
113 | }
114 |
115 | return markdown;
116 | } catch (Exception ex) {
117 | Log.d(TAG, "Error Loading Markdown File.", ex);
118 | return null;
119 | }
120 | }
121 |
122 | protected void onProgressUpdate(Integer... progress) {
123 | // no-op
124 | }
125 |
126 | protected void onPostExecute(String result) {
127 | if (result != null) {
128 | loadMarkdownToView(result, cssFileUrl);
129 | } else {
130 | loadUrl("about:blank");
131 | }
132 | }
133 | }
134 |
135 | private void loadMarkdownToView(String txt, String cssFileUrl) {
136 | MarkdownProcessor m = new MarkdownProcessor();
137 | String html = m.markdown(txt);
138 | if (cssFileUrl != null) {
139 | html = "" + html;
140 | }
141 | loadDataWithBaseURL("fake://", html, "text/html", "UTF-8", null);
142 | }
143 |
144 | }
--------------------------------------------------------------------------------
/MarkdownView/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/MarkdownView/markdownview/src/main/java/us/feras/mdv/util/HttpHelper.java:
--------------------------------------------------------------------------------
1 | package us.feras.mdv.util;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 | import java.io.UnsupportedEncodingException;
7 | import java.net.HttpURLConnection;
8 | import java.net.MalformedURLException;
9 | import java.net.URL;
10 | import java.net.URLConnection;
11 | import java.util.List;
12 | import java.util.Set;
13 | import java.util.Map.Entry;
14 |
15 | /**
16 | * @author Feras Alnatsheh
17 | */
18 |
19 | public class HttpHelper {
20 |
21 | private static final String CHARSET_UTF8 = "UTF-8";
22 | public static final String CONTENT_TYPE_JSON = "json";
23 | public static final String CONTENT_TYPE_XML = "xml";
24 |
25 | // Timeout when reading from Input stream when a connection is established
26 | // to a resource
27 | private static final int DEFULT_READ_TIMEOUT = 5000;
28 | // Timeout for establishing a connection.
29 | private static final int DEFULT_CONNECT_TIMEOUT = 5000;
30 |
31 | static public Response get(String url, String query)
32 | throws MalformedURLException, IOException {
33 | return get(url, query, DEFULT_CONNECT_TIMEOUT, DEFULT_READ_TIMEOUT);
34 | }
35 |
36 | static public Response get(String url) throws MalformedURLException,
37 | IOException {
38 | return get(url, null, DEFULT_CONNECT_TIMEOUT, DEFULT_READ_TIMEOUT);
39 | }
40 |
41 | static public Response get(String url, String query, int connectTimeout,
42 | int readTimeout) throws MalformedURLException, IOException {
43 | String fullUrl = url;
44 | if (query != null && !query.equals("")) {
45 | fullUrl += "?" + query;
46 | }
47 | URLConnection connection = new URL(fullUrl).openConnection();
48 | connection.setReadTimeout(readTimeout);
49 | connection.setConnectTimeout(connectTimeout);
50 | connection.setRequestProperty("Accept-Charset", CHARSET_UTF8);
51 | return getResponse((HttpURLConnection) connection);
52 | }
53 |
54 | static public Response post(String url, String query, String contentType)
55 | throws MalformedURLException, IOException {
56 | return post(url, query, contentType, DEFULT_CONNECT_TIMEOUT,
57 | DEFULT_READ_TIMEOUT);
58 | }
59 |
60 | static public Response post(String url, String query, String contentType,
61 | int connectTimeout, int readTimeout) throws MalformedURLException,
62 | IOException {
63 | URLConnection connection = new URL(url).openConnection();
64 | connection.setReadTimeout(readTimeout);
65 | connection.setConnectTimeout(connectTimeout);
66 | connection.setDoOutput(true); // Triggers POST.
67 | connection.setRequestProperty("Accept-Charset", CHARSET_UTF8);
68 | connection.setRequestProperty("Content-Type", "application/"
69 | + contentType);
70 | OutputStream output = null;
71 | try {
72 | output = connection.getOutputStream();
73 | output.write(query.getBytes(CHARSET_UTF8));
74 | } finally {
75 | closeSilently(output);
76 | }
77 | return getResponse((HttpURLConnection) connection);
78 | }
79 |
80 | /*
81 | * Open the input stream to get responses from the server.
82 | */
83 | private static Response getResponse(HttpURLConnection connection)
84 | throws IOException {
85 | InputStream inputStream = connection.getInputStream();
86 | Response response = new Response();
87 | response.setHttpResponseCode(connection.getResponseCode());
88 | response.setHttpResponseHeader(connection.getHeaderFields().entrySet());
89 | response.setResponseMessage(getResponseMessage(inputStream, connection));
90 | response.setHttpResponseMessage(connection.getResponseMessage());
91 | return response;
92 | }
93 |
94 | /*
95 | * Get the HTTP response message from the server.
96 | */
97 | private static String getResponseMessage(InputStream inputStream,
98 | HttpURLConnection connection) throws UnsupportedEncodingException,
99 | IOException {
100 | String responseMessage = null;
101 | StringBuffer sb = new StringBuffer();
102 | InputStream dis = connection.getInputStream();
103 | int chr;
104 | while ((chr = dis.read()) != -1) {
105 | sb.append((char) chr);
106 | }
107 | if (sb != null) {
108 | responseMessage = sb.toString();
109 | }
110 | return responseMessage;
111 | }
112 |
113 | /*
114 | * Close the connection, if the connection could not be closed (probably
115 | * because its already closed) ignore the error.
116 | */
117 | private static void closeSilently(OutputStream output) {
118 | if (output != null) {
119 | try {
120 | output.close();
121 | } catch (IOException e) {
122 | }
123 | }
124 | }
125 |
126 | public static class Response {
127 |
128 | private Set>> httpResponseHeader;
129 | private int httpResponseCode;
130 | private String httpResponseMessage;
131 | private String serverResponseMessage;
132 |
133 | Response() {
134 | }
135 |
136 | Response(Set>> httpResponseHeader,
137 | int httpResponseCode, String httpResponseMessage,
138 | String responseMessage) {
139 | setHttpResponseHeader(httpResponseHeader);
140 | setHttpResponseCode(httpResponseCode);
141 | setHttpResponseMessage(httpResponseMessage);
142 | setResponseMessage(responseMessage);
143 | }
144 |
145 | public String getHttpResponseMessage() {
146 | return httpResponseMessage;
147 | }
148 |
149 | public void setHttpResponseMessage(String httpResponseMessage) {
150 | this.httpResponseMessage = httpResponseMessage;
151 | }
152 |
153 | public Set>> getHttpResponseHeader() {
154 | return httpResponseHeader;
155 | }
156 |
157 | public void setHttpResponseHeader(
158 | Set>> httpResponseHeader) {
159 | this.httpResponseHeader = httpResponseHeader;
160 | }
161 |
162 | public int getHttpResponseCode() {
163 | return httpResponseCode;
164 | }
165 |
166 | public void setHttpResponseCode(int httpResponseCode) {
167 | this.httpResponseCode = httpResponseCode;
168 | }
169 |
170 | public String getResponseMessage() {
171 | return serverResponseMessage;
172 | }
173 |
174 | public void setResponseMessage(String responseMessage) {
175 | this.serverResponseMessage = responseMessage;
176 | }
177 |
178 | public String toString() {
179 | return "httpResponseCode = " + httpResponseCode + " , "
180 | + "httpResponseMessage = " + httpResponseMessage + " , "
181 | + "serverResponseMessage = " + serverResponseMessage;
182 | }
183 |
184 | }
185 |
186 | }
--------------------------------------------------------------------------------