From fc65662914ec4e1c4a64b865c5cdf80c3787fb8e Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Wed, 4 Feb 2015 11:34:48 +0100 Subject: [PATCH] first commit --- .gitignore | 48 +++++ README.md | 5 + build.gradle | 19 ++ editor/build.gradle | 23 +++ editor/proguard-rules.pro | 17 ++ .../org/wordpress/editor/ApplicationTest.java | 13 ++ editor/src/main/AndroidManifest.xml | 19 ++ .../org/wordpress/editor/EditorActivity.java | 82 +++++++++ .../src/main/res/layout/activity_editor.xml | 12 ++ editor/src/main/res/values/strings.xml | 3 + example/build.gradle | 25 +++ example/proguard-rules.pro | 17 ++ .../editorexample/ApplicationTest.java | 13 ++ example/src/main/AndroidManifest.xml | 16 ++ .../editorexample/ExampleActivity.java | 24 +++ .../src/main/res/layout/activity_example.xml | 16 ++ .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes example/src/main/res/values/strings.xml | 4 + example/src/main/res/values/styles.xml | 8 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 49896 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 164 ++++++++++++++++++ gradlew.bat | 90 ++++++++++ settings.gradle | 2 + 27 files changed, 626 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 build.gradle create mode 100644 editor/build.gradle create mode 100644 editor/proguard-rules.pro create mode 100644 editor/src/androidTest/java/org/wordpress/editor/ApplicationTest.java create mode 100644 editor/src/main/AndroidManifest.xml create mode 100644 editor/src/main/java/org/wordpress/editor/EditorActivity.java create mode 100644 editor/src/main/res/layout/activity_editor.xml create mode 100644 editor/src/main/res/values/strings.xml create mode 100644 example/build.gradle create mode 100644 example/proguard-rules.pro create mode 100644 example/src/androidTest/java/org/wordpress/editorexample/ApplicationTest.java create mode 100644 example/src/main/AndroidManifest.xml create mode 100644 example/src/main/java/org/wordpress/editorexample/ExampleActivity.java create mode 100644 example/src/main/res/layout/activity_example.xml create mode 100644 example/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 example/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 example/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 example/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 example/src/main/res/values/strings.xml create mode 100644 example/src/main/res/values/styles.xml create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000000..cd6a3d9b15d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,48 @@ +# OS X generated file +.DS_Store + +# built application files +*.apk +*.ap_ + +# files for the dex VM +*.dex + +# Java class files +*.class + +# generated files +bin/ +gen/ +build/ +*/build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Eclipse project files +.settings/ +.classpath +.project + +# Intellij project files +*.iml +*.ipr +*.iws +.idea/ + +# Gradle +.gradle/ +gradle.properties + +# Generated by gradle +crashlytics.properties + +# Generated by Crashlytics +WordPress/src/main/res/values/com_crashlytics_export_strings.xml + +# Silver Searcher ignore file +.agignore + +# Monkey runner settings +*.pyc diff --git a/README.md b/README.md new file mode 100644 index 000000000000..e8cd5438ed16 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# WordPress-Android-Editor + +## Introduction + +The WordPress-Android-Editor is the text editor used in the [WordPress Android app](https://github.com/wordpress-mobile/WordPress-Android) to create and edit pages & posts. In short it's a simple, straightforward way to visually edit HTML. diff --git a/build.gradle b/build.gradle new file mode 100644 index 000000000000..234dff0a6edf --- /dev/null +++ b/build.gradle @@ -0,0 +1,19 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.0.0-rc4' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + jcenter() + } +} diff --git a/editor/build.gradle b/editor/build.gradle new file mode 100644 index 000000000000..c714bf3469f7 --- /dev/null +++ b/editor/build.gradle @@ -0,0 +1,23 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 21 + buildToolsVersion "21.1.2" + + defaultConfig { + minSdkVersion 15 + targetSdkVersion 21 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile 'com.android.support:appcompat-v7:21.0.3' +} diff --git a/editor/proguard-rules.pro b/editor/proguard-rules.pro new file mode 100644 index 000000000000..d8d549daaadc --- /dev/null +++ b/editor/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/max/work/android-sdk-mac/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/editor/src/androidTest/java/org/wordpress/editor/ApplicationTest.java b/editor/src/androidTest/java/org/wordpress/editor/ApplicationTest.java new file mode 100644 index 000000000000..dfc7e0def17e --- /dev/null +++ b/editor/src/androidTest/java/org/wordpress/editor/ApplicationTest.java @@ -0,0 +1,13 @@ +package org.wordpress.editor; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} diff --git a/editor/src/main/AndroidManifest.xml b/editor/src/main/AndroidManifest.xml new file mode 100644 index 000000000000..a5080b935f74 --- /dev/null +++ b/editor/src/main/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + diff --git a/editor/src/main/java/org/wordpress/editor/EditorActivity.java b/editor/src/main/java/org/wordpress/editor/EditorActivity.java new file mode 100644 index 000000000000..34e44c3c6141 --- /dev/null +++ b/editor/src/main/java/org/wordpress/editor/EditorActivity.java @@ -0,0 +1,82 @@ +package org.wordpress.editor; + +import android.annotation.SuppressLint; +import android.content.res.AssetManager; +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; +import android.util.Log; +import android.webkit.ConsoleMessage; +import android.webkit.JsResult; +import android.webkit.WebChromeClient; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class EditorActivity extends ActionBarActivity { + WebView mWebView; + + @SuppressLint("SetJavaScriptEnabled") + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_editor); + mWebView = (WebView) findViewById(R.id.webview); + WebSettings webSettings = mWebView.getSettings(); + webSettings.setJavaScriptEnabled(true); + webSettings.setDefaultTextEncodingName("utf-8"); + mWebView.getSettings().setJavaScriptEnabled(true); + mWebView.setWebViewClient(new WebViewClient() { + public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { + Log.e("WordPress-Editor", description); + } + }); + mWebView.setWebChromeClient(new WebChromeClient() { + public boolean onConsoleMessage(ConsoleMessage cm) { + Log.e("WordPress-Editor", cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId()); + return true; + } + + @Override + public boolean onJsAlert(WebView view, String url, String message, JsResult result) { + Log.e("WordPress-Editor", message); + return true; + } + + @Override + public void onConsoleMessage(String message, int lineNumber, String sourceId) { + Log.e("WordPress-Editor", message + " -- from line " + lineNumber + " of " + sourceId); + } + }); + String htmlEditor = getHtmlEditor(); + mWebView.loadDataWithBaseURL("file:///android_asset/", htmlEditor, "text/html", "utf-8", ""); + } + + private String getStringFromAsset(String filename) throws IOException { + AssetManager assetManager = getAssets(); + InputStream in = assetManager.open(filename); + InputStreamReader is = new InputStreamReader(in); + StringBuilder sb = new StringBuilder(); + BufferedReader br = new BufferedReader(is); + String read = br.readLine(); + while (read != null) { + sb.append(read); + sb.append('\n'); + read = br.readLine(); + } + return sb.toString(); + } + + private String getHtmlEditor() { + try { + return getStringFromAsset("android-editor.html"); + } catch (IOException e) { + Log.e("WordPress-Editor", e.getMessage()); + return null; + } + } +} diff --git a/editor/src/main/res/layout/activity_editor.xml b/editor/src/main/res/layout/activity_editor.xml new file mode 100644 index 000000000000..8b5955aabc43 --- /dev/null +++ b/editor/src/main/res/layout/activity_editor.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/editor/src/main/res/values/strings.xml b/editor/src/main/res/values/strings.xml new file mode 100644 index 000000000000..a38313aa7a79 --- /dev/null +++ b/editor/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Editor + diff --git a/example/build.gradle b/example/build.gradle new file mode 100644 index 000000000000..70cc518aad80 --- /dev/null +++ b/example/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 21 + buildToolsVersion "21.1.2" + + defaultConfig { + applicationId "org.wordpress.editorexample" + minSdkVersion 15 + targetSdkVersion 21 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile 'com.android.support:appcompat-v7:21.0.3' + compile project(":editor"); +} diff --git a/example/proguard-rules.pro b/example/proguard-rules.pro new file mode 100644 index 000000000000..d8d549daaadc --- /dev/null +++ b/example/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/max/work/android-sdk-mac/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/example/src/androidTest/java/org/wordpress/editorexample/ApplicationTest.java b/example/src/androidTest/java/org/wordpress/editorexample/ApplicationTest.java new file mode 100644 index 000000000000..87b7b7cb929f --- /dev/null +++ b/example/src/androidTest/java/org/wordpress/editorexample/ApplicationTest.java @@ -0,0 +1,13 @@ +package org.wordpress.editorexample; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} diff --git a/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml new file mode 100644 index 000000000000..654e894a6c34 --- /dev/null +++ b/example/src/main/AndroidManifest.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/example/src/main/java/org/wordpress/editorexample/ExampleActivity.java b/example/src/main/java/org/wordpress/editorexample/ExampleActivity.java new file mode 100644 index 000000000000..398bdcc04a04 --- /dev/null +++ b/example/src/main/java/org/wordpress/editorexample/ExampleActivity.java @@ -0,0 +1,24 @@ +package org.wordpress.editorexample; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; + +import org.wordpress.editor.EditorActivity; + +public class ExampleActivity extends ActionBarActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_example); + Button button1 = (Button) findViewById(R.id.button1); + button1.setOnClickListener(new OnClickListener() { + @Override public void onClick(View v) { + startActivity(new Intent(ExampleActivity.this, EditorActivity.class)); + } + }); + } +} diff --git a/example/src/main/res/layout/activity_example.xml b/example/src/main/res/layout/activity_example.xml new file mode 100644 index 000000000000..b9ddcd5e9b42 --- /dev/null +++ b/example/src/main/res/layout/activity_example.xml @@ -0,0 +1,16 @@ + + +