|
1 | 1 | # AndroidAceEditor
|
2 |
| -An android interface for the Ace Editor |
| 2 | +This project is an attempt to integrate a text/code editor as a modular component of the overall UI. |
| 3 | +The aim is to provide a powerful editor that can be used just like any other View. |
| 4 | + |
| 5 | +Ace text editor has been used for this purpose because it is feature-rich, fast, and easy to modify and embed in applications. |
| 6 | + |
| 7 | + |
| 8 | +Please note that this library currently supports android version 5.0(Lollipop) and above. |
| 9 | + |
| 10 | +Integration to existing project |
| 11 | +--- |
| 12 | + |
| 13 | +### Setup |
| 14 | + |
| 15 | +##### build.gradle (project) |
| 16 | +```groovy |
| 17 | +allprojects { |
| 18 | + repositories { |
| 19 | + ... |
| 20 | + maven { |
| 21 | + url 'https://jitpack.io' |
| 22 | + } |
| 23 | + } |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +#### build.gradle (app) |
| 28 | +```groovy |
| 29 | +dependencies { |
| 30 | + ... |
| 31 | + compile 'com.github.Susmit-A:AndroidAceEditor:0.1.3' |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +### Basic Usage |
| 36 | +#### XML |
| 37 | +```xml |
| 38 | +... |
| 39 | +<com.susmit.aceeditor.AceEditor |
| 40 | + android:layout_width="match_parent" |
| 41 | + android:layout_height="match_parent" |
| 42 | + android:id="@+id/editor"/> |
| 43 | +... |
| 44 | +``` |
| 45 | + |
| 46 | +#### Java |
| 47 | +Demp Activity: |
| 48 | +```java |
| 49 | +public class MainActivity extends Activity { |
| 50 | + |
| 51 | + @Override |
| 52 | + protected void onCreate(Bundle savedInstanceState) { |
| 53 | + super.onCreate(savedInstanceState); |
| 54 | + setContentView(R.layout.activity_main); |
| 55 | + editor = findViewById(R.id.editor); |
| 56 | + |
| 57 | + //call this to set up themes or modes at load time. |
| 58 | + //If you are setting the theme or mode through another view's action, |
| 59 | + //call setTheme and/or setMode directly |
| 60 | + editor.setOnLoadedEditorListener(new OnLoadedEditorListener() { |
| 61 | + @Override |
| 62 | + public void onCreate() { |
| 63 | + editor.setTheme(AceEditor.Theme.TERMINAL); |
| 64 | + editor.setMode(AceEditor.Mode.C_Cpp); |
| 65 | + } |
| 66 | + }); |
| 67 | + |
| 68 | + //Since a WebView is used for the content, you need to set the following listener to process the text |
| 69 | + //It is also used to retrive other values, such as selected text or number of lines |
| 70 | + editor.setResultReceivedListener(new ResultReceivedListener() { |
| 71 | + @Override |
| 72 | + public void onReceived(String text, int FLAG_VALUE) { |
| 73 | + if(FLAG_VALUE == AceEditor.Request.VALUE_TEXT) |
| 74 | + { |
| 75 | + Toast.makeText(MainActivity.this, "Typed text:\n\n" + text, Toast.LENGTH_SHORT).show(); |
| 76 | + } |
| 77 | + } |
| 78 | + }); |
| 79 | + } |
| 80 | +} |
| 81 | +``` |
| 82 | + |
0 commit comments