diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/AutoFitGridLayout.java b/app/src/main/java/gr/thmmy/mthmmy/utils/AutoFitGridLayout.java
new file mode 100644
index 00000000..3b048c37
--- /dev/null
+++ b/app/src/main/java/gr/thmmy/mthmmy/utils/AutoFitGridLayout.java
@@ -0,0 +1,55 @@
+package gr.thmmy.mthmmy.utils;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.widget.GridLayout;
+import gr.thmmy.mthmmy.R;
+
+public class AutoFitGridLayout extends GridLayout {
+ private int columnWidth;
+ private int defaultColumnCount;
+
+ public AutoFitGridLayout(Context context) {
+ super(context);
+ init(context, null, 0);
+ }
+
+ public AutoFitGridLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(context, attrs, 0);
+ }
+
+ public AutoFitGridLayout(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ init(context, attrs, defStyleAttr);
+ }
+
+ public void init(Context context, AttributeSet attrs, int defStyleAttr) {
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AutoFitGridLayout, 0, defStyleAttr);
+ try {
+ columnWidth = a.getDimensionPixelSize(R.styleable.AutoFitGridLayout_columnWidth, 0);
+
+ int[] set = {android.R.attr.columnCount};
+ a = context.obtainStyledAttributes(attrs, set, 0, defStyleAttr);
+ defaultColumnCount = a.getInt(0, 6);
+ } finally {
+ a.recycle();
+ }
+ setColumnCount(1);
+ }
+
+ @Override
+ protected void onMeasure(int widthSpec, int heightSpec) {
+ super.onMeasure(widthSpec, heightSpec);
+
+ int width = MeasureSpec.getSize(widthSpec);
+ if (columnWidth > 0 && width > 0) {
+ int totalSpace = width - getPaddingRight() - getPaddingLeft();
+ int columnCount = Math.max(1, totalSpace / columnWidth);
+ setColumnCount(columnCount);
+ } else {
+ setColumnCount(defaultColumnCount);
+ }
+ }
+}
diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java b/app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java
index 48f2c543..f4780551 100644
--- a/app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java
+++ b/app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java
@@ -2,14 +2,17 @@ package gr.thmmy.mthmmy.utils;
import android.app.Activity;
import android.content.Context;
+import android.content.res.Resources;
import android.support.v7.widget.AppCompatImageButton;
import android.text.Editable;
import android.util.AttributeSet;
+import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
+import android.widget.GridLayout;
import android.widget.LinearLayout;
import gr.thmmy.mthmmy.R;
@@ -90,11 +93,18 @@ public class EditorView extends LinearLayout {
getText().insert(editText.getSelectionStart(), "[s][/s]");
editText.setSelection(editText.getSelectionStart() - 4);
});
- findViewById(R.id.unordered_list_button).setOnClickListener(view -> {
+ // TODO: popup menu for colors
+ findViewById(R.id.text_color_button).setOnClickListener(view -> {
if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
- getText().insert(editText.getSelectionStart(), "[list]\n[li][/li]\n[li][/li]\n[li][/li]\n[/list]");
- editText.setSelection(editText.getSelectionStart() - 33);
+ getText().insert(editText.getSelectionStart(), "[color=][/color]");
+ editText.setSelection(editText.getSelectionStart() - 8);
+ });
+ findViewById(R.id.text_size_button).setOnClickListener(view -> {
+ if (editText.hasSelection())
+ editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
+ getText().insert(editText.getSelectionStart(), "[size=10pt][/size]");
+ editText.setSelection(editText.getSelectionStart() - 7);
});
findViewById(R.id.align_left_button).setOnClickListener(view -> {
if (editText.hasSelection())
@@ -114,6 +124,12 @@ public class EditorView extends LinearLayout {
getText().insert(editText.getSelectionStart(), "[right][/right]");
editText.setSelection(editText.getSelectionStart() - 8);
});
+ findViewById(R.id.math_button).setOnClickListener(view -> {
+ if (editText.hasSelection())
+ editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
+ getText().insert(editText.getSelectionStart(), "[tex][/tex]");
+ editText.setSelection(editText.getSelectionStart() - 6);
+ });
}
public Editable getText() {
diff --git a/app/src/main/res/drawable/ic_format_color_text_36dp.xml b/app/src/main/res/drawable/ic_format_color_text_36dp.xml
new file mode 100644
index 00000000..d241a9b0
--- /dev/null
+++ b/app/src/main/res/drawable/ic_format_color_text_36dp.xml
@@ -0,0 +1,6 @@
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_format_size_black_36dp.xml b/app/src/main/res/drawable/ic_format_size_black_36dp.xml
new file mode 100644
index 00000000..54e5a142
--- /dev/null
+++ b/app/src/main/res/drawable/ic_format_size_black_36dp.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_functions_black_36dp.xml b/app/src/main/res/drawable/ic_functions_black_36dp.xml
new file mode 100644
index 00000000..5c2bf617
--- /dev/null
+++ b/app/src/main/res/drawable/ic_functions_black_36dp.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/layout/editor_view.xml b/app/src/main/res/layout/editor_view.xml
index 9387c8cc..f58d618d 100644
--- a/app/src/main/res/layout/editor_view.xml
+++ b/app/src/main/res/layout/editor_view.xml
@@ -4,67 +4,78 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">
-
+ android:orientation="horizontal"
+ app:columnWidth="36dp">
+ app:srcCompat="@drawable/ic_format_bold_grey_36dp"/>
+ app:srcCompat="@drawable/ic_format_italic_grey_36dp" />
+ app:srcCompat="@drawable/ic_format_underlined_grey_36dp" />
+ app:srcCompat="@drawable/ic_strikethrough_s_grey_36dp" />
+
+
+
+
+ app:srcCompat="@drawable/ic_format_list_bulleted_black_36dp" />
+ app:srcCompat="@drawable/ic_format_align_left_grey_36dp" />
+ app:srcCompat="@drawable/ic_format_align_center_grey_36dp" />
-
+ app:srcCompat="@drawable/ic_format_align_right_grey_36dp" />
+
+
+
+
+
+
+
+
\ No newline at end of file