Browse Source

Added bold/italic to compose

Refs #49
main
M66B 6 years ago
parent
commit
b1dacae3d1
4 changed files with 75 additions and 8 deletions
  1. +34
    -6
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  2. +10
    -0
      app/src/main/res/drawable/baseline_format_bold_24.xml
  3. +10
    -0
      app/src/main/res/drawable/baseline_format_italic_24.xml
  4. +21
    -2
      app/src/main/res/layout/fragment_compose.xml

+ 34
- 6
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -25,6 +25,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@ -32,8 +33,10 @@ import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.provider.OpenableColumns;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@ -46,6 +49,7 @@ import android.webkit.MimeTypeMap;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.FilterQueryProvider;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.MultiAutoCompleteTextView;
import android.widget.ProgressBar;
@ -100,6 +104,8 @@ public class FragmentCompose extends FragmentEx {
private EditText etSubject;
private RecyclerView rvAttachment;
private EditText etBody;
private ImageButton ibBold;
private ImageButton ibItalic;
private BottomNavigationView bottom_navigation;
private ProgressBar pbWait;
private Group grpHeader;
@ -133,6 +139,8 @@ public class FragmentCompose extends FragmentEx {
etSubject = view.findViewById(R.id.etSubject);
rvAttachment = view.findViewById(R.id.rvAttachment);
etBody = view.findViewById(R.id.etBody);
ibBold = view.findViewById(R.id.ibBold);
ibItalic = view.findViewById(R.id.ibItalic);
bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait);
grpHeader = view.findViewById(R.id.grpHeader);
@ -225,6 +233,28 @@ public class FragmentCompose extends FragmentEx {
}
});
View.OnClickListener styleListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
int start = etBody.getSelectionStart();
int end = etBody.getSelectionEnd();
if (start > end) {
int tmp = start;
start = end;
end = tmp;
}
if (start != end) {
SpannableString s = new SpannableString(etBody.getText());
s.setSpan(new StyleSpan(v.getId() == ibBold.getId() ? Typeface.BOLD : Typeface.ITALIC),
start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
etBody.setText(s);
}
}
};
ibBold.setOnClickListener(styleListener);
ibItalic.setOnClickListener(styleListener);
bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
@ -521,7 +551,7 @@ public class FragmentCompose extends FragmentEx {
args.putString("cc", etCc.getText().toString());
args.putString("bcc", etBcc.getText().toString());
args.putString("subject", etSubject.getText().toString());
args.putString("body", etBody.getText().toString());
args.putString("body", Html.toHtml(etBody.getText()));
Log.i(Helper.TAG, "Run load id=" + working);
actionLoader.load(this, args);
@ -981,8 +1011,6 @@ public class FragmentCompose extends FragmentEx {
draft.subject = subject;
draft.received = new Date().getTime();
String pbody = "<pre>" + body.replaceAll("\\r?\\n", "<br />") + "</pre>";
// Execute action
if (action == R.id.action_delete) {
draft.msgid = null;
@ -993,13 +1021,13 @@ public class FragmentCompose extends FragmentEx {
} else if (action == R.id.action_save) {
db.message().updateMessage(draft);
draft.write(context, pbody);
draft.write(context, body);
EntityOperation.queue(db, draft, EntityOperation.ADD);
} else if (action == R.id.action_send) {
db.message().updateMessage(draft);
draft.write(context, pbody);
draft.write(context, body);
// Check data
if (draft.identity == null)
@ -1030,7 +1058,7 @@ public class FragmentCompose extends FragmentEx {
draft.msgid = msgid;
draft.ui_hide = false;
draft.id = db.message().insertMessage(draft);
draft.write(getContext(), pbody);
draft.write(getContext(), body);
// Restore attachments
for (EntityAttachment attachment : attachments) {


+ 10
- 0
app/src/main/res/drawable/baseline_format_bold_24.xml View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M15.6,10.79c0.97,-0.67 1.65,-1.77 1.65,-2.79 0,-2.26 -1.75,-4 -4,-4L7,4v14h7.04c2.09,0 3.71,-1.7 3.71,-3.79 0,-1.52 -0.86,-2.82 -2.15,-3.42zM10,6.5h3c0.83,0 1.5,0.67 1.5,1.5s-0.67,1.5 -1.5,1.5h-3v-3zM13.5,15.5L10,15.5v-3h3.5c0.83,0 1.5,0.67 1.5,1.5s-0.67,1.5 -1.5,1.5z"/>
</vector>

+ 10
- 0
app/src/main/res/drawable/baseline_format_italic_24.xml View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M10,4v3h2.21l-3.42,8H6v3h8v-3h-2.21l3.42,-8H18V4z"/>
</vector>

+ 21
- 2
app/src/main/res/layout/fragment_compose.xml View File

@ -154,7 +154,7 @@
android:layout_marginStart="6dp"
android:fillViewport="true"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintBottom_toTopOf="@+id/ibBold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparator">
@ -170,6 +170,25 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
</ScrollView>
<ImageButton
android:id="@+id/ibBold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:src="@drawable/baseline_format_bold_24"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/scroll" />
<ImageButton
android:id="@+id/ibItalic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/baseline_format_italic_24"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintStart_toEndOf="@id/ibBold"
app:layout_constraintTop_toBottomOf="@id/scroll" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
@ -216,5 +235,5 @@
android:id="@+id/grpMessage"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="scroll,bottom_navigation" />
app:constraint_referenced_ids="scroll,ibBold,ibItalic,bottom_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>

Loading…
Cancel
Save