Hello Developers, in this Article you will get the simple text editor project for Android Studio. With the the help of this project users can easily make, edit a code file and text files. You will get the project source below. If you need any project on your intersted topic then please contact us. We will make that project as soon as possible. So, Without wasting time lets start.
How to implement this project in our project?
You can implement this easily. Just make files by the given name and copy codes tyo that files. Make sure you have downloaded the drawable images before implemented this project source.
<LinearLayout
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"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<ImageView
android:id="@+id/imageview1"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/icon"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Code Editor"
android:textSize="25sp"
android:textStyle="bold"
android:textColor="#3F51B5" />
</LinearLayout>
</LinearLayout>
<LinearLayout
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"
android:orientation="vertical">
<TextView
android:id="@+id/regex11"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:text="\\b(Uzuakoli|Amoji|Bright|Ndudirim|Ezinwanne|Lightworker|Isuochi|Abia|Ngodo)\\b"
android:textSize="12sp"
android:textColor="#000000" />
<TextView
android:id="@+id/regex1"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:text="\\b(out|print|println|valueOf|toString|concat|equals|for|while|switch|getText"
android:textSize="12sp"
android:textColor="#000000" />
<TextView
android:id="@+id/regex3"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:text="\\b(public|private|protected|void|switch|case|class|import|package|extends|Activity|TextView|EditText|LinearLayout|CharSequence|String|int|onCreate|ArrayList|float|if|else|static|Nigeria|Intent|Button|SharedPreferences"
android:textSize="12sp"
android:textColor="#000000" />
<TextView
android:id="@+id/regex4"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:text="|abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|extends|final|finally|float|for|goto|if|implements|import|instanceof|interface|long|native|new|package|private|protected|"
android:textSize="12sp"
android:textColor="#000000" />
<TextView
android:id="@+id/regex5"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:text="public|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|transient|try|void|volatile|while|true|false|null)\\b"
android:textSize="12sp"
android:textColor="#000000" />
<TextView
android:id="@+id/regex6"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:text="\\b([0-9]+)\\b"
android:textSize="12sp"
android:textColor="#000000" />
<TextView
android:id="@+id/regex7"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:text="(\\w+)(\\()+"
android:textSize="12sp"
android:textColor="#000000" />
<TextView
android:id="@+id/regex8"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:text="\\\@\\s*(\\w+)"
android:textSize="12sp"
android:textColor="#000000" />
<TextView
android:id="@+id/regex9"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:text="\"(.\?)\"|'(.\?)'"
android:textSize="12sp"
android:textColor="#000000" />
<TextView
android:id="@+id/regex10"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:text="/\\(\?:.|[\\n\\r])\?\\/|//."
android:textSize="12sp"
android:textColor="#000000" />
<TextView
android:id="@+id/regex2"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="8dp"
android:text="|println|printf|print|out|parseInt|round|sqrt|charAt|compareTo|compareToIgnoreCase|concat|contains|contentEquals|equals|length|toLowerCase|trim|toUpperCase|toString|valueOf|substring|startsWith|split|replace|replaceAll|lastIndexOf|size)\\b"
android:textSize="12sp"
android:textColor="#000000" />
<LinearLayout
android:id="@+id/linear2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:background="#3F51B5"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/save"
android:layout_width="38dp"
android:layout_height="38dp"
android:padding="8dp"
android:src="@drawable/ic_save_white"
android:scaleType="fitCenter" />
<ImageView
android:id="@+id/copy"
android:layout_width="38dp"
android:layout_height="38dp"
android:padding="8dp"
android:src="@drawable/ic_content_copy_white"
android:scaleType="fitCenter"
android:layout_weight="1" />
<ImageView
android:id="@+id/cut"
android:layout_width="38dp"
android:layout_height="38dp"
android:padding="8dp"
android:src="@drawable/ic_content_cut_white"
android:scaleType="fitCenter" />
<ImageView
android:id="@+id/export"
android:layout_width="38dp"
android:layout_height="38dp"
android:padding="8dp"
android:src="@drawable/ic_sd_storage_white"
android:scaleType="fitCenter"
android:layout_weight="1" />
<ImageView
android:id="@+id/edit"
android:layout_width="38dp"
android:layout_height="38dp"
android:padding="8dp"
android:src="@drawable/ic_create_white"
android:scaleType="fitCenter" />
</LinearLayout>
<ScrollView
android:id="@+id/vscroll1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:layout_weight="1">
<EditText
android:id="@+id/edittext1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:paddingTop="8dp"
android:paddingRight="12dp"
android:paddingBottom="8dp"
android:background="@android:color/transparent"
android:gravity="top"
android:textSize="14sp"
android:textColor="#212121"
android:textColorHint="#607D8B" />
</ScrollView>
</LinearLayout>
<LinearLayout
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"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="horizontal">
<TextView
android:id="@+id/textview1"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:paddingTop="8dp"
android:paddingRight="12dp"
android:paddingBottom="8dp"
android:text="Export"
android:textSize="20sp"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="@+id/linear3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingBottom="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/textview2"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="Enter Name"
android:textSize="12sp"
android:textColor="#3F51B5" />
<EditText
android:id="@+id/edittext1"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="8dp"
android:paddingTop="8dp"
android:paddingRight="8dp"
android:textSize="16sp"
android:textColor="#000000"
android:textColorHint="#607D8B"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:id="@+id/linear5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/cbtn"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="center_horizontal"
android:text="CANCEL"
android:textSize="14sp"
android:textColor="#3F51B5"
android:layout_weight="1" />
<TextView
android:id="@+id/xmlbtn"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="center_horizontal"
android:text="XML"
android:textSize="14sp"
android:textColor="#3F51B5"
android:layout_weight="1" />
<TextView
android:id="@+id/javabtn"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="center_horizontal"
android:text="TEXT"
android:textSize="14sp"
android:textColor="#3F51B5"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
package com.my.newproject127;
import androidx.appcompat.app.AppCompatActivity;
import androidx.annotation.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.content.res.*;
import android.graphics.*;
import android.graphics.drawable.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.text.style.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.io.*;
import java.util.*;
import java.util.regex.*;
import java.text.*;
import org.json.*;
import android.widget.LinearLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.content.Intent;
import android.net.Uri;
import java.util.Timer;
import java.util.TimerTask;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.DialogFragment;
import androidx.core.content.ContextCompat;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.content.pm.PackageManager;
public class MainActivity extends AppCompatActivity {
private Timer _timer = new Timer();
private LinearLayout linear1;
private ImageView imageview1;
private TextView textview1;
private Intent intent = new Intent();
private TimerTask timer;
@Override
protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.main);
initialize(_savedInstanceState);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED
|| ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1000);
} else {
initializeLogic();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1000) {
initializeLogic();
}
}
private void initialize(Bundle _savedInstanceState) {
linear1 = findViewById(R.id.linear1);
imageview1 = findViewById(R.id.imageview1);
textview1 = findViewById(R.id.textview1);
}
private void initializeLogic() {
timer = new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
intent.setClass(getApplicationContext(), EditorActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
});
}
};
_timer.schedule(timer, (int)(2000));
}
@Deprecated
public void showMessage(String _s) {
Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
}
@Deprecated
public int getLocationX(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[0];
}
@Deprecated
public int getLocationY(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[1];
}
@Deprecated
public int getRandom(int _min, int _max) {
Random random = new Random();
return random.nextInt(_max - _min + 1) + _min;
}
@Deprecated
public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
ArrayList<Double> _result = new ArrayList<Double>();
SparseBooleanArray _arr = _list.getCheckedItemPositions();
for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
if (_arr.valueAt(_iIdx))
_result.add((double)_arr.keyAt(_iIdx));
}
return _result;
}
@Deprecated
public float getDip(int _input) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
}
@Deprecated
public int getDisplayWidthPixels() {
return getResources().getDisplayMetrics().widthPixels;
}
@Deprecated
public int getDisplayHeightPixels() {
return getResources().getDisplayMetrics().heightPixels;
}
}
package com.my.newproject127;
import androidx.appcompat.app.AppCompatActivity;
import androidx.annotation.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.content.res.*;
import android.graphics.*;
import android.graphics.drawable.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.text.style.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.io.*;
import java.util.*;
import java.util.regex.*;
import java.text.*;
import org.json.*;
import android.widget.TextView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.ImageView;
import android.widget.EditText;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.Intent;
import android.content.ClipData;
import android.net.Uri;
import android.view.View;
import android.text.Editable;
import android.text.TextWatcher;
import android.content.ClipboardManager;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.DialogFragment;
import androidx.core.content.ContextCompat;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.content.pm.PackageManager;
public class EditorActivity extends AppCompatActivity {
public final int REQ_CD_PICK_FILE = 101;
private String secondaryColor = "";
private String primaryColor = "";
private String numbersColor = "";
private String quotesColor = "";
private String commentsColor = "";
private String charColor = "";
private String name = "";
private String prevColor = "";
private String charSeq = "";
private TextView regex11;
private TextView regex1;
private TextView regex3;
private TextView regex4;
private TextView regex5;
private TextView regex6;
private TextView regex7;
private TextView regex8;
private TextView regex9;
private TextView regex10;
private TextView regex2;
private LinearLayout linear2;
private ScrollView vscroll1;
private ImageView save;
private ImageView copy;
private ImageView cut;
private ImageView export;
private ImageView edit;
private EditText edittext1;
private SharedPreferences save_data;
private Intent pick_file = new Intent(Intent.ACTION_GET_CONTENT);
private Intent intent = new Intent();
@Override
protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.editor);
initialize(_savedInstanceState);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED
|| ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1000);
} else {
initializeLogic();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1000) {
initializeLogic();
}
}
private void initialize(Bundle _savedInstanceState) {
regex11 = findViewById(R.id.regex11);
regex1 = findViewById(R.id.regex1);
regex3 = findViewById(R.id.regex3);
regex4 = findViewById(R.id.regex4);
regex5 = findViewById(R.id.regex5);
regex6 = findViewById(R.id.regex6);
regex7 = findViewById(R.id.regex7);
regex8 = findViewById(R.id.regex8);
regex9 = findViewById(R.id.regex9);
regex10 = findViewById(R.id.regex10);
regex2 = findViewById(R.id.regex2);
linear2 = findViewById(R.id.linear2);
vscroll1 = findViewById(R.id.vscroll1);
save = findViewById(R.id.save);
copy = findViewById(R.id.copy);
cut = findViewById(R.id.cut);
export = findViewById(R.id.export);
edit = findViewById(R.id.edit);
edittext1 = findViewById(R.id.edittext1);
save_data = getSharedPreferences("save_data", Activity.MODE_PRIVATE);
pick_file.setType("/");
pick_file.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _view) {
_Ripple_Drawable(save, "#5c6bc0");
save_data.edit().putString("save_data", edittext1.getText().toString()).commit();
SketchwareUtil.showMessage(getApplicationContext(), "Saved");
}
});
copy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _view) {
_Ripple_Drawable(copy, "#5c6bc0");
if (edittext1.getText().toString().equals("")) {
SketchwareUtil.showMessage(getApplicationContext(), "Empty");
}
else {
((ClipboardManager) getSystemService(getApplicationContext().CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("clipboard", edittext1.getText().toString()));
SketchwareUtil.showMessage(getApplicationContext(), "Copied");
}
}
});
cut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _view) {
_Ripple_Drawable(cut, "#5c6bc0");
if (edittext1.getText().toString().equals("")) {
SketchwareUtil.showMessage(getApplicationContext(), "Empty");
}
else {
((ClipboardManager) getSystemService(getApplicationContext().CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("clipboard", edittext1.getText().toString()));
edittext1.setText("");
SketchwareUtil.showMessage(getApplicationContext(), "Cut");
}
}
});
export.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _view) {
_Ripple_Drawable(export, "#5c6bc0");
if (edittext1.getText().toString().equals("")) {
SketchwareUtil.showMessage(getApplicationContext(), "Empty");
}
else {
_exportbtn();
}
}
});
edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _view) {
_Ripple_Drawable(edit, "#5c6bc0");
if (edittext1.isEnabled()) {
edittext1.setEnabled(false);
edit.setImageResource(R.drawable.ic_create_white);
}
else {
edittext1.setEnabled(true);
edit.setImageResource(R.drawable.ic_check_white);
}
}
});
edittext1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence _param1, int _param2, int _param3, int _param4) {
final String _charSeq = _param1.toString();
}
@Override
public void beforeTextChanged(CharSequence _param1, int _param2, int _param3, int _param4) {
}
@Override
public void afterTextChanged(Editable _param1) {
}
});
}
private void initializeLogic() {
setTitle("Code Editor");
_setHighlighter(edittext1);
if (!save_data.getString("save_data", "").equals("")) {
edittext1.setText(save_data.getString("save_data", ""));
}
_Elevation(linear2, 5);
vscroll1.setVerticalScrollBarEnabled(false);
if (edittext1.getText().toString().equals("")) {
edittext1.setEnabled(true);
edit.setImageResource(R.drawable.ic_check_white);
}
else {
edittext1.setEnabled(false);
edit.setImageResource(R.drawable.ic_create_white);
}
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
_MENU();
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
@Override
protected void onActivityResult(int _requestCode, int _resultCode, Intent _data) {
super.onActivityResult(_requestCode, _resultCode, _data);
switch (_requestCode) {
case REQ_CD_PICK_FILE:
if (_resultCode == Activity.RESULT_OK) {
ArrayList<String> _filePath = new ArrayList<>();
if (_data != null) {
if (_data.getClipData() != null) {
for (int _index = 0; _index < _data.getClipData().getItemCount(); _index++) {
ClipData.Item _item = _data.getClipData().getItemAt(_index);
_filePath.add(FileUtil.convertUriToFilePath(getApplicationContext(), _item.getUri()));
}
}
else {
_filePath.add(FileUtil.convertUriToFilePath(getApplicationContext(), _data.getData()));
}
}
if (_filePath.get((int)(0)).endsWith(".xml")) {
edittext1.setText(FileUtil.readFile(_filePath.get((int)(0))));
}
else {
if (_filePath.get((int)(0)).endsWith(".java")) {
edittext1.setText(FileUtil.readFile(_filePath.get((int)(0))));
}
else {
if (_filePath.get((int)(0)).endsWith(".txt")) {
edittext1.setText(FileUtil.readFile(_filePath.get((int)(0))));
}
else {
SketchwareUtil.showMessage(getApplicationContext(), "Invalid file");
}
}
}
}
else {
}
break;
default:
break;
}
}
public void _setHighlighter(final TextView _view) {
secondaryColor = "#678cb1";
primaryColor = "#4caf50";
numbersColor = "#f6c921";
quotesColor = "#ff1744";
commentsColor = "#9e9e9e";
charColor = "#ff5722";
_view.addTextChangedListener(new TextWatcher() { ColorScheme keywords1 = new ColorScheme(java.util.regex.Pattern.compile(regex1.getText().toString().concat(regex2.getText().toString())), Color.parseColor(secondaryColor));
ColorScheme keywords2 = new ColorScheme(java.util.regex.Pattern.compile(regex3.getText().toString().concat(regex4.getText().toString().concat(regex5.getText().toString()))), Color.parseColor(primaryColor));
ColorScheme keywords3 = new ColorScheme(java.util.regex.Pattern.compile(regex6.getText().toString()), Color.parseColor(numbersColor));
ColorScheme keywords4 = new ColorScheme(java.util.regex.Pattern.compile(regex7.getText().toString()), Color.parseColor(secondaryColor));
ColorScheme keywords5 = new ColorScheme(java.util.regex.Pattern.compile(regex9.getText().toString()), Color.parseColor(quotesColor));
ColorScheme keywords6 = new ColorScheme(java.util.regex.Pattern.compile(regex10.getText().toString()), Color.parseColor(commentsColor));
ColorScheme keywords7 = new ColorScheme(java.util.regex.Pattern.compile(regex8.getText().toString()), Color.parseColor(numbersColor));
ColorScheme keywords8 = new ColorScheme(java.util.regex.Pattern.compile(regex11.getText().toString()), Color.parseColor(charColor));
final ColorScheme[] schemes = {keywords1, keywords2, keywords3, keywords4, keywords5, keywords6, keywords7, keywords8}; @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { removeSpans(s, android.text.style.ForegroundColorSpan.class); for(ColorScheme scheme : schemes) { for(java.util.regex.Matcher m = scheme.pattern.matcher(s);
m.find();) { if (scheme == keywords4) { s.setSpan(new android.text.style.ForegroundColorSpan(scheme.color), m.start(), m.end()-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
else { s.setSpan(new android.text.style.ForegroundColorSpan(scheme.color), m.start(), m.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } void removeSpans(Editable e, Class type) { android.text.style.CharacterStyle[] spans = e.getSpans(0, e.length(), type); for (android.text.style.CharacterStyle span : spans) { e.removeSpan(span); } } class ColorScheme { final java.util.regex.Pattern pattern; final int color; ColorScheme(java.util.regex.Pattern pattern, int color) { this.pattern = pattern; this.color = color; } } });
}
public void _MENU() {
}
@Override
public boolean onCreateOptionsMenu (Menu menu){
menu.add(0, 0, 0, "Color").setIcon(R.drawable.color).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(0, 1, 1, "Attach").setIcon(R.drawable.folder).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case 0:
_customHex();
break;
case 1:
startActivityForResult(pick_file, REQ_CD_PICK_FILE);
break;
}
return super.onOptionsItemSelected(item);
}
public void _Ripple_Drawable(final View _view, final String _c) {
android.content.res.ColorStateList clr = new android.content.res.ColorStateList(new int[][]{new int[]{}},new int[]{Color.parseColor(_c)}); android.graphics.drawable.RippleDrawable ripdr = new android.graphics.drawable.RippleDrawable(clr, null, null); _view.setBackground(ripdr);
}
public void _exportbtn() {
AlertDialog.Builder alert = new AlertDialog.Builder(EditorActivity.this);
View dialog1 = getLayoutInflater().inflate(R.layout.export_cus,null); alert.setView(dialog1);
final AlertDialog dialog = alert.create(); dialog.setCanceledOnTouchOutside(true);
dialog.setCancelable(true);
dialog.show();
final EditText text = (EditText) dialog1.findViewById(R.id.edittext1);
TextView javabtn = (TextView)dialog1.findViewById(R.id.javabtn);
TextView xmlbtn = (TextView)dialog1.findViewById(R.id.xmlbtn);
TextView cbtn = (TextView)dialog1.findViewById(R.id.cbtn);
text.setFocusableInTouchMode(true);
cbtn.setOnClickListener(new OnClickListener() { public void onClick(View view) {
dialog.dismiss();
} });
javabtn.setOnClickListener(new OnClickListener() { public void onClick(View view) {
name = text.getText().toString();
if (name.equals("")) {
text.setError("Name empty");
}
else {
FileUtil.makeDir(FileUtil.getExternalStorageDir().concat("/Code Editor/exported/"));
FileUtil.writeFile(FileUtil.getExternalStorageDir().concat("/Code Editor/exported/".concat(name.trim().concat(".txt"))), edittext1.getText().toString());
dialog.dismiss();
SketchwareUtil.showMessage(getApplicationContext(), "Exported to - Code Editor/exported/".concat(name.concat(".txt")));
}
} });
xmlbtn.setOnClickListener(new OnClickListener() { public void onClick(View view) {
name = text.getText().toString();
if (name.equals("")) {
text.setError("Name empty");
}
else {
FileUtil.makeDir(FileUtil.getExternalStorageDir().concat("/Code Editor/exported/"));
FileUtil.writeFile(FileUtil.getExternalStorageDir().concat("/Code Editor/exported/".concat(name.trim().concat(".xml"))), edittext1.getText().toString());
dialog.dismiss();
SketchwareUtil.showMessage(getApplicationContext(), "Exported to - Code Editor/exported/".concat(name.concat(".xml")));
}
} });
}
public void _Elevation(final View _view, final double _number) {
_view.setElevation((int)_number);
}
public void _customHex() {
prevColor = "#ffffff";
final AlertDialog cstmhx = new AlertDialog.Builder(EditorActivity.this).create();
cstmhx.setTitle("Color Pad");
final LinearLayout layout = new LinearLayout(EditorActivity.this);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setGravity(Gravity.CENTER_HORIZONTAL);
layout.setPadding(16,0,16,32);
final TextView tvw1 = new TextView(EditorActivity.this); tvw1.setText("#"); tvw1.setTextSize(16);
tvw1.setTextColor(Color.parseColor("#3f51b5"));
layout.addView(tvw1);
final EditText edittxt = new EditText(EditorActivity.this);
edittxt.setLayoutParams(new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f));
layout.addView(edittxt);
final LinearLayout preview = new LinearLayout(EditorActivity.this);
preview.setPadding(8,8,8,8);
preview.setLayoutParams(new LinearLayout.LayoutParams(80,android.widget.LinearLayout.LayoutParams.MATCH_PARENT));
layout.addView(preview);
cstmhx.setView(layout);
cstmhx.show();
edittxt.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence _param1, int _param2, int _param3, int _param4) {
charSeq = _param1.toString();
if (charSeq.length() > 8) {
edittxt.setTextColor(Color.parseColor("#FF0000"));
edittxt.setError("max 8 characters");
preview.setVisibility(View.INVISIBLE);
}
else {
if (!charSeq.equals("")) {
if (charSeq.matches("-?[0-9a-fA-F]+")) {
prevColor = "FFFFFFFF".concat(charSeq);
prevColor = prevColor.substring((int)(prevColor.length() - 8), (int)(prevColor.length()));
prevColor = "#".concat(prevColor);
edittxt.setTextColor(Color.parseColor("#000000"));
preview.setVisibility(View.VISIBLE);
preview.setBackgroundColor(Color.parseColor(prevColor));
} else {
edittxt.setError("Invalid format");
preview.setVisibility(View.INVISIBLE);
}
}
}
}
@Override
public void beforeTextChanged(CharSequence _param1, int _param2, int _param3, int _param4) {}
@Override
public void afterTextChanged(Editable _param1) {}
});
}
@Deprecated
public void showMessage(String _s) {
Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
}
@Deprecated
public int getLocationX(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[0];
}
@Deprecated
public int getLocationY(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[1];
}
@Deprecated
public int getRandom(int _min, int _max) {
Random random = new Random();
return random.nextInt(_max - _min + 1) + _min;
}
@Deprecated
public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
ArrayList<Double> _result = new ArrayList<Double>();
SparseBooleanArray _arr = _list.getCheckedItemPositions();
for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
if (_arr.valueAt(_iIdx))
_result.add((double)_arr.keyAt(_iIdx));
}
return _result;
}
@Deprecated
public float getDip(int _input) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
}
@Deprecated
public int getDisplayWidthPixels() {
return getResources().getDisplayMetrics().widthPixels;
}
@Deprecated
public int getDisplayHeightPixels() {
return getResources().getDisplayMetrics().heightPixels;
}
}
Before adding below code to AndroidMAnifest.xml file you must declare MainActivity and permissions.
<activity
android:name=".EditorActivity"
android:configChanges="orientation|screenSize|keyboardHidden|smallestScreenSize|screenLayout"
android:hardwareAccelerated="true"
android:supportsPictureInPicture="true"
android:theme="@style/AppTheme.FullScreen"
android:screenOrientation="portrait" />
Thank you for visiting our website and hope that you got heloped by visiting our site.
0 Comments