Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:2.2.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Fri Aug 18 14:52:46 KRAT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
12 changes: 4 additions & 8 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 25
buildToolsVersion "25.0.3"

defaultConfig {
minSdkVersion 15
targetSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
Expand All @@ -21,8 +21,4 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.6.2'
}



apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
}
2 changes: 1 addition & 1 deletion library/src/main/assets/icarus-editor/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<script>
var editor;
var toolbar = ['title', 'bold', 'italic', 'underline', 'strikethrough', 'fontScale', 'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link', 'image', 'hr', '|', 'indent', 'outdent', 'alignment', 'alignLeft', 'alignCenter', 'alignRight', 'html'];
var toolbar = ['h1_button', 'h2_button', 'h3_button', 'title', 'bold', 'italic', 'underline', 'strikethrough', 'fontScale', 'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link', 'image', 'hr', '|', 'indent', 'outdent', 'alignment', 'alignLeft', 'alignCenter', 'alignRight', 'html'];
var defaultOptions = {
textarea: $('#txt-content'),
placeholder: '',
Expand Down
207 changes: 206 additions & 1 deletion library/src/main/assets/icarus-editor/scripts/simditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
}(this, function ($, SimpleModule, simpleHotkeys, simpleUploader) {

var AlignCenterButton, AlignLeftButton, AlignRightButton, AlignmentButton, BlockquoteButton, BoldButton, Button, Clipboard, CodeButton, CodePopover, ColorButton, FontScaleButton, Formatter, HrButton, HtmlButton, ImageButton, ImagePopover, IndentButton, Indentation, InputManager, ItalicButton, Keystroke, LinkButton, ListButton, OrderListButton, OutdentButton, Popover, Selection, Simditor, SimditorMention, StrikethroughButton, TableButton, TitleButton, Toolbar, UnderlineButton, UndoManager, UnorderListButton, Util,
var H1Button, H2Button, H3Button, AlignCenterButton, AlignLeftButton, AlignRightButton, AlignmentButton, BlockquoteButton, BoldButton, Button, Clipboard, CodeButton, CodePopover, ColorButton, FontScaleButton, Formatter, HrButton, HtmlButton, ImageButton, ImagePopover, IndentButton, Indentation, InputManager, ItalicButton, Keystroke, LinkButton, ListButton, OrderListButton, OutdentButton, Popover, Selection, Simditor, SimditorMention, StrikethroughButton, TableButton, TitleButton, Toolbar, UnderlineButton, UndoManager, UnorderListButton, Util,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
Expand Down Expand Up @@ -2999,6 +2999,7 @@ Button = (function(superClass) {
}
console.log("active", active);
console.log(this);
console.log(new Error('1'));
IcarusBridge.setButtonActivated(this.name, active);
this.active = active;
return this.el.toggleClass('active', this.active);
Expand Down Expand Up @@ -3511,6 +3512,7 @@ TitleButton = (function(superClass) {
};

TitleButton.prototype.command = function(param) {
document.execCommand('bold');
var $rootNodes;
$rootNodes = this.editor.selection.rootNodes();
this.editor.selection.save();
Expand All @@ -3534,6 +3536,209 @@ TitleButton = (function(superClass) {

Simditor.Toolbar.addButton(TitleButton);

//added new type button H1Button, H2Button, H3Button
H1Button = (function(superClass) {
extend(H1Button, superClass);

function H1Button() {
return H1Button.__super__.constructor.apply(this, arguments);
}

H1Button.prototype.name = 'h1_button';

H1Button.prototype.htmlTag = 'h1';

H1Button.prototype.disableTag = 'pre, table';

H1Button.prototype._init = function() {
this.menu = [
{
name: 'h1',
text: this._t('h1_button') + ' 1',
param: 'h1'
}
];
return H1Button.__super__._init.call(this);
};

H1Button.prototype.setActive = function(active, param) {
H1Button.__super__.setActive.call(this, active);
if (active) {
param || (param = this.node[0].tagName.toLowerCase());
}
this.el.removeClass('active-p active-h1 active-h2 active-h3 active-h4 active-h5');
if (active) {
return this.el.addClass('active active-' + param);
}
};

H1Button.prototype.command = function(param) {
var $rootNodes;
$rootNodes = this.editor.selection.rootNodes();
var selectedNode = editor.selection.nodes()[0];
this.editor.selection.save();

console.log(selectedNode);
console.log($rootNodes);

$rootNodes.each((function(_this) {
return function(i, node) {
var $node;
$node = $(node);
if ($node.is('blockquote') || $node.is(_this.disableTag) || _this.editor.util.isDecoratedNode($node)) {
return;
}
if (node === selectedNode && $node.is(param)) {
$('<p/>').append($node.contents()).replaceAll($node);
return;
}
return $('<' + param + '/>').append($node.contents()).replaceAll($node);
};
})(this));
this.editor.selection.restore();
return this.editor.trigger('valuechanged');
};

return H1Button;

})(Button);
Simditor.Toolbar.addButton(H1Button);

H2Button = (function(superClass) {
extend(H2Button, superClass);

function H2Button() {
return H2Button.__super__.constructor.apply(this, arguments);
}

H2Button.prototype.name = 'h2_button';

H2Button.prototype.htmlTag = 'h2';

H2Button.prototype.disableTag = 'pre, table';

H2Button.prototype._init = function() {
this.menu = [
{
name: 'h2',
text: this._t('h2_button') + ' 1',
param: 'h2'
}
];
return H2Button.__super__._init.call(this);
};

H2Button.prototype.setActive = function(active, param) {
H2Button.__super__.setActive.call(this, active);
if (active) {
param || (param = this.node[0].tagName.toLowerCase());
}
this.el.removeClass('active-p active-h1 active-h2 active-h3 active-h4 active-h5');
if (active) {
return this.el.addClass('active active-' + param);
}
};

H2Button.prototype.command = function(param) {
var $rootNodes;
$rootNodes = this.editor.selection.rootNodes();
var selectedNode = editor.selection.nodes()[0];
this.editor.selection.save();

console.log(selectedNode);
console.log($rootNodes);

$rootNodes.each((function(_this) {
return function(i, node) {
var $node;
$node = $(node);
if ($node.is('blockquote') || $node.is(_this.disableTag) || _this.editor.util.isDecoratedNode($node)) {
return;
}
if (node === selectedNode && $node.is(param)) {
$('<p/>').append($node.contents()).replaceAll($node);
return;
}
return $('<' + param + '/>').append($node.contents()).replaceAll($node);
};
})(this));
this.editor.selection.restore();
return this.editor.trigger('valuechanged');
};

return H2Button;

})(Button);
Simditor.Toolbar.addButton(H2Button);


H3Button = (function(superClass) {
extend(H3Button, superClass);

function H3Button() {
return H3Button.__super__.constructor.apply(this, arguments);
}

H3Button.prototype.name = 'h3_button';

H3Button.prototype.htmlTag = 'h3';

H3Button.prototype.disableTag = 'pre, table';

H3Button.prototype._init = function() {
this.menu = [
{
name: 'h3',
text: this._t('h3_button') + ' 1',
param: 'h3'
}
];
return H3Button.__super__._init.call(this);
};

H3Button.prototype.setActive = function(active, param) {
H3Button.__super__.setActive.call(this, active);
if (active) {
param || (param = this.node[0].tagName.toLowerCase());
}
this.el.removeClass('active-p active-h1 active-h2 active-h3 active-h4 active-h5');
if (active) {
return this.el.addClass('active active-' + param);
}
};

H3Button.prototype.command = function(param) {
var $rootNodes;
$rootNodes = this.editor.selection.rootNodes();
var selectedNode = editor.selection.nodes()[0];
this.editor.selection.save();

console.log(selectedNode);
console.log($rootNodes);

$rootNodes.each((function(_this) {
return function(i, node) {
var $node;
$node = $(node);
if ($node.is('blockquote') || $node.is(_this.disableTag) || _this.editor.util.isDecoratedNode($node)) {
return;
}
if (node === selectedNode && $node.is(param)) {
$('<p/>').append($node.contents()).replaceAll($node);
return;
}
return $('<' + param + '/>').append($node.contents()).replaceAll($node);
};
})(this));
this.editor.selection.restore();
return this.editor.trigger('valuechanged');
};

return H3Button;

})(Button);
Simditor.Toolbar.addButton(H3Button);

HtmlButton = (function(superClass) {
extend(HtmlButton, superClass);

Expand Down
108 changes: 108 additions & 0 deletions library/src/main/java/com/github/mr5/icarus/button/HeadingButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.github.mr5.icarus.button;

import android.os.Build;
import android.text.Html;
import android.text.Spanned;
import android.widget.TextView;

import com.github.mr5.icarus.Icarus;

/**
* Button use in RichEditor for tags H1, H2, H3
*/

public class HeadingButton extends TextViewButton{

public static final String NAME_HEADER_H1 = "h1_button";
public static final String NAME_HEADER_H2 = "h2_button";
public static final String NAME_HEADER_H3 = "h3_button";
public static final String NAME_HEADER_H4 = "h4_button";
public static final String NAME_HEADER_H5 = "h5_button";
public static final String NAME_HEADER_H6 = "h6_button";

/**
* Constructor for initialization basic constructor
*
* @param aTextView view that was clicked
* @param aIcarus object, which manages content in webview
*/
public HeadingButton(TextView aTextView, Icarus aIcarus){
super(aTextView, aIcarus);
}

/**
* set label for a button
*
* @param aName name button
*/
public void setName(String aName) {
this.name = aName; //for internal use of the base class
setLabel(aName);
}

/**
* sending a command to js to process the selected tag
*/
public void command() {
icarus.jsExec("editor.toolbar.buttons['" + name + "'].command('" + getTag(name) + "')");
}

/**
* setting a label for a button
*
* @param aName name button
*/
private void setLabel(String aName) {
String htmlName = null;
switch (aName) {
case NAME_HEADER_H1:
htmlName = "<b>H1</b>";
break;
case NAME_HEADER_H2:
htmlName = "<b>H2</b>";
break;
case NAME_HEADER_H3:
htmlName = "<b>H3</b>";
break;
case NAME_HEADER_H4:
htmlName = "<b>H4</b>";
break;
case NAME_HEADER_H5:
htmlName = "<b>H5</b>";
break;
case NAME_HEADER_H6:
htmlName = "<b>H6</b>";
break;
default:
htmlName = "<b>H</b>";
break;
}
this.textView.setText(getStringFromHtml(htmlName));
}

/**
* convert html to spanned
*
* @param aHtml html code to display a button label
* @return spanned object
*/
private Spanned getStringFromHtml(String aHtml) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
return Html.fromHtml(aHtml, 0);
} else {
return Html.fromHtml(aHtml);
}
}

/**
* get tag from name button
*
* @param aName name button
* @return name tag (example: h1)
*/
private String getTag(String aName) {
return aName.split("_button")[0];
}


}
Loading