-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 30e335a
Showing
90 changed files
with
2,587 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.3" | ||
|
||
defaultConfig { | ||
applicationId "com.scrat.app.mackdowneditor" | ||
minSdkVersion 14 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:23.4.0' | ||
compile project(':richtext') | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/androidTest/java/com/scrat/app/richtexteditor/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.scrat.app.richtexteditor; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.scrat.app.richtexteditor"> | ||
|
||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/ic_format_bold" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name="com.scrat.app.richtexteditor.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
126 changes: 126 additions & 0 deletions
126
app/src/main/java/com/scrat/app/richtexteditor/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package com.scrat.app.richtexteditor; | ||
|
||
import android.Manifest; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
|
||
import com.scrat.app.richtext.RichEditText; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private static final int REQUEST_CODE_GET_CONTENT = 666; | ||
private static final int WRITE_EXTERNAL_STORAGE_REQUEST_CODE = 444; | ||
private RichEditText richEditText; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
richEditText = (RichEditText) findViewById(R.id.rich_text); | ||
richEditText.fromHtml("<blockquote>第五期<u>JJ</u> Bob</blockquote>" + | ||
"<blockquote>你<i><b>那</b></i><i>里</i></blockquote><ul><li>好久</li></ul>\n" + | ||
"<img src=\"http://img5.duitang.com/uploads/item/201409/07/20140907195835_GUXNn.thumb.700_0.jpeg\">" + | ||
"<img src=\"http://www.bz55.com/uploads/allimg/150707/139-150FG61K2.jpg\">"); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
getMenuInflater().inflate(R.menu.menu_main, menu); | ||
return super.onCreateOptionsMenu(menu); | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
switch (item.getItemId()) { | ||
case R.id.undo: | ||
richEditText.undo(); | ||
break; | ||
case R.id.redo: | ||
richEditText.redo(); | ||
break; | ||
case R.id.github: | ||
Log.e("xxx", richEditText.toHtml()); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, final Intent data) { | ||
if (data == null || data.getData() == null || requestCode == WRITE_EXTERNAL_STORAGE_REQUEST_CODE) | ||
return; | ||
|
||
final Uri uri = data.getData(); | ||
final int width = richEditText.getMeasuredWidth() - richEditText.getPaddingLeft() - richEditText.getPaddingRight(); | ||
richEditText.image(uri, width); | ||
} | ||
|
||
/** | ||
* 加粗 | ||
*/ | ||
public void setBold(View v) { | ||
richEditText.bold(!richEditText.contains(RichEditText.FORMAT_BOLD)); | ||
} | ||
|
||
/** | ||
* 斜体 | ||
*/ | ||
public void setItalic(View v) { | ||
richEditText.italic(!richEditText.contains(RichEditText.FORMAT_ITALIC)); | ||
} | ||
|
||
/** | ||
* 下划线 | ||
*/ | ||
public void setUnderline(View v) { | ||
richEditText.underline(!richEditText.contains(RichEditText.FORMAT_UNDERLINED)); | ||
} | ||
|
||
/** | ||
* 删除线 | ||
*/ | ||
public void setStrikethrough(View v) { | ||
richEditText.strikethrough(!richEditText.contains(RichEditText.FORMAT_STRIKETHROUGH)); | ||
} | ||
|
||
/** | ||
* 序号 | ||
*/ | ||
public void setBullet(View v) { | ||
richEditText.bullet(!richEditText.contains(RichEditText.FORMAT_BULLET)); | ||
} | ||
|
||
/** | ||
* 引用块 | ||
*/ | ||
public void setQuote(View v) { | ||
richEditText.quote(!richEditText.contains(RichEditText.FORMAT_QUOTE)); | ||
} | ||
|
||
public void insertImg(View v) { | ||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) | ||
!= PackageManager.PERMISSION_GRANTED) { | ||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, | ||
WRITE_EXTERNAL_STORAGE_REQUEST_CODE); | ||
} | ||
|
||
Intent getImage = new Intent(Intent.ACTION_GET_CONTENT); | ||
getImage.addCategory(Intent.CATEGORY_OPENABLE); | ||
getImage.setType("image/*"); | ||
startActivityForResult(getImage, REQUEST_CODE_GET_CONTENT); | ||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="com.scrat.app.richtexteditor.MainActivity"> | ||
|
||
<HorizontalScrollView | ||
android:id="@+id/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentBottom="true" | ||
android:background="@android:color/darker_gray" | ||
android:scrollbars="none"> | ||
|
||
<LinearLayout | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal"> | ||
|
||
<ImageButton | ||
android:layout_width="48dp" | ||
android:layout_height="48dp" | ||
android:background="?android:selectableItemBackground" | ||
android:contentDescription="@null" | ||
android:onClick="setBold" | ||
android:scaleType="center" | ||
android:src="@drawable/ic_format_bold" /> | ||
|
||
<ImageButton | ||
android:layout_width="48dp" | ||
android:layout_height="48dp" | ||
android:background="?android:selectableItemBackground" | ||
android:contentDescription="@null" | ||
android:onClick="setItalic" | ||
android:scaleType="center" | ||
android:src="@drawable/ic_format_italic" /> | ||
|
||
<ImageButton | ||
android:layout_width="48dp" | ||
android:layout_height="48dp" | ||
android:background="?android:selectableItemBackground" | ||
android:contentDescription="@null" | ||
android:onClick="setUnderline" | ||
android:scaleType="center" | ||
android:src="@drawable/ic_format_underline" /> | ||
|
||
<ImageButton | ||
android:layout_width="48dp" | ||
android:layout_height="48dp" | ||
android:background="?android:selectableItemBackground" | ||
android:contentDescription="@null" | ||
android:onClick="setStrikethrough" | ||
android:scaleType="center" | ||
android:src="@drawable/ic_format_strikethrough" /> | ||
|
||
<ImageButton | ||
android:layout_width="48dp" | ||
android:layout_height="48dp" | ||
android:background="?android:selectableItemBackground" | ||
android:contentDescription="@null" | ||
android:onClick="setBullet" | ||
android:scaleType="center" | ||
android:src="@drawable/ic_format_bullet" /> | ||
|
||
<ImageButton | ||
android:layout_width="48dp" | ||
android:layout_height="48dp" | ||
android:background="?android:selectableItemBackground" | ||
android:contentDescription="@null" | ||
android:onClick="setQuote" | ||
android:scaleType="center" | ||
android:src="@drawable/ic_format_quote" /> | ||
|
||
<ImageButton | ||
android:layout_width="48dp" | ||
android:layout_height="48dp" | ||
android:background="?android:selectableItemBackground" | ||
android:contentDescription="@null" | ||
android:onClick="insertImg" | ||
android:scaleType="center" | ||
android:src="@drawable/ic_insert_link" /> | ||
|
||
<!--<ImageButton android:id="@+id/clear"--> | ||
<!--android:contentDescription="@null"--> | ||
<!--android:layout_width="48dp"--> | ||
<!--android:layout_height="48dp"--> | ||
<!--android:src="@drawable/ic_format_clear"--> | ||
<!--android:scaleType="center"--> | ||
<!--android:background="?android:selectableItemBackground">--> | ||
<!--</ImageButton>--> | ||
|
||
</LinearLayout> | ||
|
||
</HorizontalScrollView> | ||
|
||
<ScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_above="@id/tools" | ||
android:layout_alignParentTop="true" | ||
android:fillViewport="true"> | ||
|
||
<com.scrat.app.richtext.RichEditText | ||
android:id="@+id/rich_text" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@android:color/transparent" | ||
android:gravity="top|start" | ||
android:paddingEnd="16dp" | ||
android:paddingLeft="16dp" | ||
android:paddingRight="16dp" | ||
android:paddingStart="16dp" | ||
android:paddingTop="16dp" | ||
android:scrollbars="vertical" | ||
app:bulletColor="#FF2196F3" | ||
app:bulletGapWidth="8dp" | ||
app:bulletRadius="2dp" | ||
app:historyEnable="true" | ||
app:historySize="99" | ||
app:linkColor="#FF2196F3" | ||
app:linkUnderline="true" | ||
app:quoteCapWidth="2dp" | ||
app:quoteColor="#FF2196F3" | ||
app:quoteStripeWidth="8dp" /> | ||
</ScrollView> | ||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<menu xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<item | ||
android:id="@+id/undo" | ||
android:icon="@drawable/ic_action_undo" | ||
android:showAsAction="ifRoom" | ||
android:title="撤销"/> | ||
|
||
<item | ||
android:id="@+id/redo" | ||
android:icon="@drawable/ic_action_redo" | ||
android:showAsAction="ifRoom" | ||
android:title="恢复"/> | ||
|
||
<item | ||
android:id="@+id/github" | ||
android:showAsAction="collapseActionView" | ||
android:title="导出"/> | ||
|
||
</menu> |
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<resources> | ||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml | ||
(such as screen margins) for screens with more than 820dp of available width. This | ||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> | ||
<dimen name="activity_horizontal_margin">64dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#3F51B5</color> | ||
<color name="colorPrimaryDark">#303F9F</color> | ||
<color name="colorAccent">#FF4081</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<resources> | ||
<!-- Default screen margins, per the Android Design guidelines. --> | ||
<dimen name="activity_horizontal_margin">16dp</dimen> | ||
<dimen name="activity_vertical_margin">16dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">RichTextEditor</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<resources> | ||
|
||
<!-- Base application theme. --> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<!-- Customize your theme here. --> | ||
<item name="colorPrimary">@color/colorPrimary</item> | ||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
<item name="colorAccent">@color/colorAccent</item> | ||
</style> | ||
|
||
</resources> |
Oops, something went wrong.