Browse Source

Added option to insert links from clipboard

Refs #49
main
M66B 6 years ago
parent
commit
8fdeccea98
6 changed files with 51 additions and 9 deletions
  1. +26
    -2
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  2. +10
    -0
      app/src/main/res/drawable/baseline_insert_link_24.xml
  3. +10
    -4
      app/src/main/res/menu/menu_compose.xml
  4. +1
    -1
      app/src/main/res/menu/menu_list.xml
  5. +2
    -2
      app/src/main/res/menu/menu_view.xml
  6. +2
    -0
      app/src/main/res/values/strings.xml

+ 26
- 2
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -20,6 +20,7 @@ package eu.faircode.email;
*/ */
import android.Manifest; import android.Manifest;
import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@ -37,6 +38,7 @@ import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.text.style.URLSpan;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -396,6 +398,7 @@ public class FragmentCompose extends FragmentEx {
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_bold).setVisible(free && working >= 0); menu.findItem(R.id.menu_bold).setVisible(free && working >= 0);
menu.findItem(R.id.menu_italic).setVisible(free && working >= 0); menu.findItem(R.id.menu_italic).setVisible(free && working >= 0);
menu.findItem(R.id.menu_link).setVisible(free && working >= 0);
menu.findItem(R.id.menu_attachment).setVisible(!free && working >= 0); menu.findItem(R.id.menu_attachment).setVisible(!free && working >= 0);
menu.findItem(R.id.menu_attachment).setEnabled(etBody.isEnabled()); menu.findItem(R.id.menu_attachment).setEnabled(etBody.isEnabled());
menu.findItem(R.id.menu_addresses).setVisible(!free && working >= 0); menu.findItem(R.id.menu_addresses).setVisible(!free && working >= 0);
@ -404,6 +407,7 @@ public class FragmentCompose extends FragmentEx {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.menu_link:
case R.id.menu_bold: case R.id.menu_bold:
case R.id.menu_italic: case R.id.menu_italic:
onMenuStyle(item.getItemId()); onMenuStyle(item.getItemId());
@ -429,8 +433,28 @@ public class FragmentCompose extends FragmentEx {
} }
if (start != end) { if (start != end) {
SpannableString s = new SpannableString(etBody.getText()); SpannableString s = new SpannableString(etBody.getText());
s.setSpan(new StyleSpan(id == R.id.menu_bold ? Typeface.BOLD : Typeface.ITALIC),
start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
switch (id) {
case R.id.menu_bold:
s.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
case R.id.menu_italic:
s.setSpan(new StyleSpan(Typeface.ITALIC), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
case R.id.menu_link:
Uri uri = null;
ClipboardManager cbm = getContext().getSystemService(ClipboardManager.class);
if (cbm.hasPrimaryClip()) {
String link = cbm.getPrimaryClip().getItemAt(0).coerceToText(getContext()).toString();
uri = Uri.parse(link);
if (uri.getScheme() == null)
uri = null;
}
if (uri == null)
Snackbar.make(view, R.string.title_clipboard_empty, Snackbar.LENGTH_LONG).show();
else
s.setSpan(new URLSpan(uri.toString()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
}
etBody.setText(s); etBody.setText(s);
etBody.setSelection(end); etBody.setSelection(end);
} }


+ 10
- 0
app/src/main/res/drawable/baseline_insert_link_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="M3.9,12c0,-1.71 1.39,-3.1 3.1,-3.1h4L11,7L7,7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5h4v-1.9L7,15.1c-1.71,0 -3.1,-1.39 -3.1,-3.1zM8,13h8v-2L8,11v2zM17,7h-4v1.9h4c1.71,0 3.1,1.39 3.1,3.1s-1.39,3.1 -3.1,3.1h-4L13,17h4c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5z"/>
</vector>

+ 10
- 4
app/src/main/res/menu/menu_compose.xml View File

@ -6,23 +6,29 @@
android:id="@+id/menu_bold" android:id="@+id/menu_bold"
android:icon="@drawable/baseline_format_bold_24" android:icon="@drawable/baseline_format_bold_24"
android:title="@string/title_style_bold" android:title="@string/title_style_bold"
app:showAsAction="always" />
app:showAsAction="ifRoom" />
<item <item
android:id="@+id/menu_italic" android:id="@+id/menu_italic"
android:icon="@drawable/baseline_format_italic_24" android:icon="@drawable/baseline_format_italic_24"
android:title="@string/title_style_italic" android:title="@string/title_style_italic"
app:showAsAction="always" />
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_link"
android:icon="@drawable/baseline_insert_link_24"
android:title="@string/title_style_link"
app:showAsAction="ifRoom" />
<item <item
android:id="@+id/menu_attachment" android:id="@+id/menu_attachment"
android:icon="@drawable/baseline_attachment_24" android:icon="@drawable/baseline_attachment_24"
android:title="@string/title_add_attachment" android:title="@string/title_add_attachment"
app:showAsAction="always" />
app:showAsAction="ifRoom" />
<item <item
android:id="@+id/menu_addresses" android:id="@+id/menu_addresses"
android:icon="@drawable/baseline_people_24" android:icon="@drawable/baseline_people_24"
android:title="@string/title_show_addresses" android:title="@string/title_show_addresses"
app:showAsAction="always" />
app:showAsAction="ifRoom" />
</menu> </menu>

+ 1
- 1
app/src/main/res/menu/menu_list.xml View File

@ -13,5 +13,5 @@
android:id="@+id/menu_folders" android:id="@+id/menu_folders"
android:icon="@drawable/baseline_folder_24" android:icon="@drawable/baseline_folder_24"
android:title="@string/title_folder_primary" android:title="@string/title_folder_primary"
app:showAsAction="always" />
app:showAsAction="ifRoom" />
</menu> </menu>

+ 2
- 2
app/src/main/res/menu/menu_view.xml View File

@ -6,13 +6,13 @@
android:id="@+id/menu_addresses" android:id="@+id/menu_addresses"
android:icon="@drawable/baseline_people_24" android:icon="@drawable/baseline_people_24"
android:title="@string/title_show_addresses" android:title="@string/title_show_addresses"
app:showAsAction="always" />
app:showAsAction="ifRoom" />
<item <item
android:id="@+id/menu_thread" android:id="@+id/menu_thread"
android:icon="@drawable/baseline_message_24" android:icon="@drawable/baseline_message_24"
android:title="@string/title_thread" android:title="@string/title_thread"
app:showAsAction="always" />
app:showAsAction="ifRoom" />
<item <item
android:id="@+id/menu_forward" android:id="@+id/menu_forward"


+ 2
- 0
app/src/main/res/values/strings.xml View File

@ -182,6 +182,8 @@
<string name="title_save">Save</string> <string name="title_save">Save</string>
<string name="title_send">Send</string> <string name="title_send">Send</string>
<string name="title_clipboard_empty">Clipboard empty</string>
<string name="title_style_link">Insert link</string>
<string name="title_style_bold">Bold</string> <string name="title_style_bold">Bold</string>
<string name="title_style_italic">Italic</string> <string name="title_style_italic">Italic</string>
<string name="title_show_addresses">Show CC/BCC</string> <string name="title_show_addresses">Show CC/BCC</string>


Loading…
Cancel
Save