Skip to content

Commit fc65662

Browse files
committed
first commit
0 parents  commit fc65662

File tree

27 files changed

+626
-0
lines changed

27 files changed

+626
-0
lines changed

.gitignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# OS X generated file
2+
.DS_Store
3+
4+
# built application files
5+
*.apk
6+
*.ap_
7+
8+
# files for the dex VM
9+
*.dex
10+
11+
# Java class files
12+
*.class
13+
14+
# generated files
15+
bin/
16+
gen/
17+
build/
18+
*/build/
19+
20+
# Local configuration file (sdk path, etc)
21+
local.properties
22+
23+
# Eclipse project files
24+
.settings/
25+
.classpath
26+
.project
27+
28+
# Intellij project files
29+
*.iml
30+
*.ipr
31+
*.iws
32+
.idea/
33+
34+
# Gradle
35+
.gradle/
36+
gradle.properties
37+
38+
# Generated by gradle
39+
crashlytics.properties
40+
41+
# Generated by Crashlytics
42+
WordPress/src/main/res/values/com_crashlytics_export_strings.xml
43+
44+
# Silver Searcher ignore file
45+
.agignore
46+
47+
# Monkey runner settings
48+
*.pyc

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# WordPress-Android-Editor
2+
3+
## Introduction
4+
5+
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.

build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.0.0-rc4'
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+
}

editor/build.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 21
5+
buildToolsVersion "21.1.2"
6+
7+
defaultConfig {
8+
minSdkVersion 15
9+
targetSdkVersion 21
10+
versionCode 1
11+
versionName "1.0"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
compile 'com.android.support:appcompat-v7:21.0.3'
23+
}

editor/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/max/work/android-sdk-mac/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+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.wordpress.editor;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="org.wordpress.editor" >
4+
5+
<application
6+
android:allowBackup="true"
7+
android:label="@string/app_name" >
8+
<activity
9+
android:name=".EditorActivity"
10+
android:label="@string/app_name" >
11+
<intent-filter>
12+
<action android:name="android.intent.action.MAIN" />
13+
14+
<category android:name="android.intent.category.LAUNCHER" />
15+
</intent-filter>
16+
</activity>
17+
</application>
18+
19+
</manifest>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package org.wordpress.editor;
2+
3+
import android.annotation.SuppressLint;
4+
import android.content.res.AssetManager;
5+
import android.os.Bundle;
6+
import android.support.v7.app.ActionBarActivity;
7+
import android.util.Log;
8+
import android.webkit.ConsoleMessage;
9+
import android.webkit.JsResult;
10+
import android.webkit.WebChromeClient;
11+
import android.webkit.WebSettings;
12+
import android.webkit.WebView;
13+
import android.webkit.WebViewClient;
14+
15+
import java.io.BufferedReader;
16+
import java.io.IOException;
17+
import java.io.InputStream;
18+
import java.io.InputStreamReader;
19+
20+
public class EditorActivity extends ActionBarActivity {
21+
WebView mWebView;
22+
23+
@SuppressLint("SetJavaScriptEnabled")
24+
@Override
25+
protected void onCreate(Bundle savedInstanceState) {
26+
super.onCreate(savedInstanceState);
27+
setContentView(R.layout.activity_editor);
28+
mWebView = (WebView) findViewById(R.id.webview);
29+
WebSettings webSettings = mWebView.getSettings();
30+
webSettings.setJavaScriptEnabled(true);
31+
webSettings.setDefaultTextEncodingName("utf-8");
32+
mWebView.getSettings().setJavaScriptEnabled(true);
33+
mWebView.setWebViewClient(new WebViewClient() {
34+
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
35+
Log.e("WordPress-Editor", description);
36+
}
37+
});
38+
mWebView.setWebChromeClient(new WebChromeClient() {
39+
public boolean onConsoleMessage(ConsoleMessage cm) {
40+
Log.e("WordPress-Editor", cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
41+
return true;
42+
}
43+
44+
@Override
45+
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
46+
Log.e("WordPress-Editor", message);
47+
return true;
48+
}
49+
50+
@Override
51+
public void onConsoleMessage(String message, int lineNumber, String sourceId) {
52+
Log.e("WordPress-Editor", message + " -- from line " + lineNumber + " of " + sourceId);
53+
}
54+
});
55+
String htmlEditor = getHtmlEditor();
56+
mWebView.loadDataWithBaseURL("file:///android_asset/", htmlEditor, "text/html", "utf-8", "");
57+
}
58+
59+
private String getStringFromAsset(String filename) throws IOException {
60+
AssetManager assetManager = getAssets();
61+
InputStream in = assetManager.open(filename);
62+
InputStreamReader is = new InputStreamReader(in);
63+
StringBuilder sb = new StringBuilder();
64+
BufferedReader br = new BufferedReader(is);
65+
String read = br.readLine();
66+
while (read != null) {
67+
sb.append(read);
68+
sb.append('\n');
69+
read = br.readLine();
70+
}
71+
return sb.toString();
72+
}
73+
74+
private String getHtmlEditor() {
75+
try {
76+
return getStringFromAsset("android-editor.html");
77+
} catch (IOException e) {
78+
Log.e("WordPress-Editor", e.getMessage());
79+
return null;
80+
}
81+
}
82+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
tools:context=".EditorActivity">
6+
7+
<WebView
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"
10+
android:id="@+id/webview"/>
11+
12+
</RelativeLayout>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">Editor</string>
3+
</resources>

0 commit comments

Comments
 (0)