diff options
Diffstat (limited to 'src/main/java/de/pixart')
7 files changed, 108 insertions, 27 deletions
diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java index dc7262135..ac99b1709 100644 --- a/src/main/java/de/pixart/messenger/Config.java +++ b/src/main/java/de/pixart/messenger/Config.java @@ -86,6 +86,8 @@ public final class Config { public static final Bitmap.CompressFormat IMAGE_FORMAT = Bitmap.CompressFormat.JPEG; public static final int IMAGE_QUALITY = 75; + public static final boolean QUICK_SHARE_ATTACHMENT_CHOICE = true; // set to true to use attachment choice instead of quick share for send button + public static final int DEFAULT_ZOOM = 15; //for locations public final static long LOCATION_FIX_TIME_DELTA = 1000 * 10; // ms public final static float LOCATION_FIX_SPACE_DELTA = 10; // m diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index f1ebb0d63..dfc1d4d78 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -30,6 +30,9 @@ import android.support.media.ExifInterface; import android.support.v13.view.inputmethod.InputConnectionCompat; import android.support.v13.view.inputmethod.InputContentInfoCompat; import android.support.v7.app.AlertDialog; +import android.support.v7.view.menu.MenuBuilder; +import android.support.v7.view.menu.MenuPopupHelper; +import android.support.v7.widget.PopupMenu; import android.text.Editable; import android.util.Log; import android.view.ContextMenu; @@ -53,7 +56,6 @@ import android.widget.CheckBox; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; -import android.widget.PopupMenu; import android.widget.TextView.OnEditorActionListener; import android.widget.Toast; @@ -136,6 +138,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke public static final int REQUEST_TRUST_KEYS_MENU = 0x0209; public static final int REQUEST_START_DOWNLOAD = 0x0210; public static final int REQUEST_ADD_EDITOR_CONTENT = 0x0211; + public static final int ATTACHMENT_CHOICE = 0x0300; public static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301; public static final int ATTACHMENT_CHOICE_TAKE_FROM_CAMERA = 0x0302; public static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303; @@ -449,6 +452,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke if (tag instanceof SendButtonAction) { SendButtonAction action = (SendButtonAction) tag; switch (action) { + case CHOOSE_ATTACHMENT: + choose_attachment(v); case TAKE_FROM_CAMERA: case SEND_LOCATION: case RECORD_VOICE: @@ -477,6 +482,31 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } }; + + @SuppressLint("RestrictedApi") + private void choose_attachment(View v) { + PopupMenu popup = new PopupMenu(activity, v); + popup.inflate(R.menu.choose_attachment); + Menu menu = popup.getMenu(); + ConversationMenuConfigurator.configureQuickShareAttachmentMenu(conversation, menu); + popup.setOnMenuItemClickListener(attachmentItem -> { + switch (attachmentItem.getItemId()) { + case R.id.attach_choose_picture: + case R.id.attach_take_picture: + case R.id.attach_choose_file: + case R.id.attach_record_voice: + case R.id.attach_location: + Log.d(Config.LOGTAG, "ATTACHMENT: " + attachmentItem.getTitle()); + handleAttachmentSelection(attachmentItem); + default: + return false; + } + }); + MenuPopupHelper menuHelper = new MenuPopupHelper(getActivity(), (MenuBuilder) menu, v); + menuHelper.setForceShowIcon(true); + menuHelper.show(); + } + private View.OnLongClickListener mSendButtonLongListener = new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { @@ -1147,7 +1177,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } menuNeedHelp.setVisible(true); menuSearchUpdates.setVisible(false); - ConversationMenuConfigurator.configureAttachmentMenu(conversation, menu); + ConversationMenuConfigurator.configureAttachmentMenu(conversation, menu, Config.QUICK_SHARE_ATTACHMENT_CHOICE); ConversationMenuConfigurator.configureEncryptionMenu(conversation, menu); } else { menuNeedHelp.setVisible(false); diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java index f2e4dc2b6..6067d03f9 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java @@ -842,22 +842,19 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio } PopupMenu popup = new PopupMenu(this, view); popup.inflate(R.menu.verification_choices); - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { - Intent intent = new Intent(ConversationsActivity.this, VerifyOTRActivity.class); - intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT); - intent.putExtra("contact", conversation.getContact().getJid().asBareJid().toString()); - intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().asBareJid().toString()); - switch (menuItem.getItemId()) { - case R.id.ask_question: - intent.putExtra("mode", VerifyOTRActivity.MODE_ASK_QUESTION); - break; - } - startActivity(intent); - overridePendingTransition(R.animator.fade_in, R.animator.fade_out); - return true; + popup.setOnMenuItemClickListener(menuItem -> { + Intent intent = new Intent(ConversationsActivity.this, VerifyOTRActivity.class); + intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT); + intent.putExtra("contact", conversation.getContact().getJid().asBareJid().toString()); + intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().asBareJid().toString()); + switch (menuItem.getItemId()) { + case R.id.ask_question: + intent.putExtra("mode", VerifyOTRActivity.MODE_ASK_QUESTION); + break; } + startActivity(intent); + overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + return true; }); popup.show(); } diff --git a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java index 5f10ceea6..9ee11bd0b 100644 --- a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java @@ -116,6 +116,7 @@ public class SettingsActivity extends XmppActivity implements } PreferenceScreen mainPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("main_screen"); + PreferenceScreen UIPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("userinterface"); //this feature is only available on Huawei Android 6. PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei"); @@ -172,6 +173,12 @@ public class SettingsActivity extends XmppActivity implements quickAction.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()])); } + if (Config.QUICK_SHARE_ATTACHMENT_CHOICE) { + if (UIPreferenceScreen != null && quickAction != null) { + UIPreferenceScreen.removePreference(quickAction); + } + } + final Preference removeCertsPreference = mSettingsFragment.findPreference("remove_trusted_certificates"); if (removeCertsPreference != null) { removeCertsPreference.setOnPreferenceClickListener(preference -> { diff --git a/src/main/java/de/pixart/messenger/ui/util/ConversationMenuConfigurator.java b/src/main/java/de/pixart/messenger/ui/util/ConversationMenuConfigurator.java index 03f7638e3..98a73addc 100644 --- a/src/main/java/de/pixart/messenger/ui/util/ConversationMenuConfigurator.java +++ b/src/main/java/de/pixart/messenger/ui/util/ConversationMenuConfigurator.java @@ -53,9 +53,21 @@ public class ConversationMenuConfigurator { locationAvailable = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS) || context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_NETWORK); } - public static void configureAttachmentMenu(@NonNull Conversation conversation, Menu menu) { - final MenuItem menuAttach = menu.findItem(R.id.action_attach_file); + public static void configureQuickShareAttachmentMenu(@NonNull Conversation conversation, Menu menu) { + final boolean visible = SendButtonTool.AttachmentsVisible(conversation); + if (!visible) { + return; + } + menu.findItem(R.id.attach_record_voice).setVisible(microphoneAvailable); + menu.findItem(R.id.attach_location).setVisible(locationAvailable); + } + public static void configureAttachmentMenu(@NonNull Conversation conversation, Menu menu, Boolean Quick_share_attachment_choice) { + final MenuItem menuAttach = menu.findItem(R.id.action_attach_file); + if (Quick_share_attachment_choice) { + menuAttach.setVisible(false); + return; + } final boolean visible; if (conversation.getMode() == Conversation.MODE_MULTI) { visible = conversation.getAccount().httpUploadAvailable() && conversation.getMucOptions().participating(); diff --git a/src/main/java/de/pixart/messenger/ui/util/SendButtonAction.java b/src/main/java/de/pixart/messenger/ui/util/SendButtonAction.java index 6258b49c6..9f9fabc5a 100644 --- a/src/main/java/de/pixart/messenger/ui/util/SendButtonAction.java +++ b/src/main/java/de/pixart/messenger/ui/util/SendButtonAction.java @@ -29,13 +29,14 @@ package de.pixart.messenger.ui.util; +import static de.pixart.messenger.ui.ConversationFragment.ATTACHMENT_CHOICE; import static de.pixart.messenger.ui.ConversationFragment.ATTACHMENT_CHOICE_CHOOSE_IMAGE; import static de.pixart.messenger.ui.ConversationFragment.ATTACHMENT_CHOICE_LOCATION; import static de.pixart.messenger.ui.ConversationFragment.ATTACHMENT_CHOICE_RECORD_VOICE; import static de.pixart.messenger.ui.ConversationFragment.ATTACHMENT_CHOICE_TAKE_FROM_CAMERA; public enum SendButtonAction { - TEXT, TAKE_FROM_CAMERA, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE; + TEXT, TAKE_FROM_CAMERA, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE, CHOOSE_ATTACHMENT; public static SendButtonAction valueOfOrDefault(String setting, SendButtonAction text) { try { @@ -55,6 +56,8 @@ public enum SendButtonAction { return TAKE_FROM_CAMERA; case ATTACHMENT_CHOICE_CHOOSE_IMAGE: return CHOOSE_PICTURE; + case ATTACHMENT_CHOICE: + return CHOOSE_ATTACHMENT; default: throw new IllegalArgumentException("Not a known attachment choice"); } @@ -70,6 +73,8 @@ public enum SendButtonAction { return ATTACHMENT_CHOICE_RECORD_VOICE; case CHOOSE_PICTURE: return ATTACHMENT_CHOICE_CHOOSE_IMAGE; + case CHOOSE_ATTACHMENT: + return ATTACHMENT_CHOICE; default: return 0; } diff --git a/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java b/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java index fdff0b4dc..291edb822 100644 --- a/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java +++ b/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java @@ -40,6 +40,8 @@ import de.pixart.messenger.entities.Presence; import de.pixart.messenger.ui.ConversationFragment; import de.pixart.messenger.utils.UIHelper; +import static de.pixart.messenger.Config.QUICK_SHARE_ATTACHMENT_CHOICE; + public class SendButtonTool { public static SendButtonAction getAction(Activity activity, Conversation c, String text) { @@ -59,15 +61,21 @@ public class SendButtonTool { if (conference && c.getNextCounterpart() != null) { return SendButtonAction.CANCEL; } else { - String setting = preferences.getString("quick_action", activity.getResources().getString(R.string.quick_action)); - if (!setting.equals("none") && UIHelper.receivedLocationQuestion(c.getLatestMessage())) { - return SendButtonAction.SEND_LOCATION; + if (QUICK_SHARE_ATTACHMENT_CHOICE && AttachmentsVisible(c)) { + return SendButtonAction.CHOOSE_ATTACHMENT; + } else if (QUICK_SHARE_ATTACHMENT_CHOICE && !AttachmentsVisible(c)) { + return SendButtonAction.TEXT; } else { - if (setting.equals("recent")) { - setting = preferences.getString(ConversationFragment.RECENTLY_USED_QUICK_ACTION, SendButtonAction.TEXT.toString()); - return SendButtonAction.valueOfOrDefault(setting, SendButtonAction.TEXT); + String setting = preferences.getString("quick_action", activity.getResources().getString(R.string.quick_action)); + if (!setting.equals("none") && UIHelper.receivedLocationQuestion(c.getLatestMessage())) { + return SendButtonAction.SEND_LOCATION; } else { - return SendButtonAction.valueOfOrDefault(setting, SendButtonAction.TEXT); + if (setting.equals("recent")) { + setting = preferences.getString(ConversationFragment.RECENTLY_USED_QUICK_ACTION, SendButtonAction.TEXT.toString()); + return SendButtonAction.valueOfOrDefault(setting, SendButtonAction.TEXT); + } else { + return SendButtonAction.valueOfOrDefault(setting, SendButtonAction.TEXT); + } } } } @@ -77,6 +85,12 @@ public class SendButtonTool { } } + public static boolean AttachmentsVisible(Conversation conversation) { + final boolean visible; + visible = conversation.getMode() != Conversation.MODE_MULTI || conversation.getAccount().httpUploadAvailable() && conversation.getMucOptions().participating(); + return visible; + } + public static int getSendButtonImageResource(Activity activity, SendButtonAction action, Presence.Status status) { switch (action) { case TEXT: @@ -157,6 +171,20 @@ public class SendButtonTool { default: return getThemeResource(activity, R.attr.ic_send_picture_offline, R.drawable.ic_send_picture_offline); } + + case CHOOSE_ATTACHMENT: + switch (status) { + case CHAT: + case ONLINE: + return R.drawable.ic_send_attachment_online; + case AWAY: + return R.drawable.ic_send_attachment_away; + case XA: + case DND: + return R.drawable.ic_send_attachment_dnd; + default: + return getThemeResource(activity, R.attr.ic_send_attachment_offline, R.drawable.ic_send_attachment_offline); + } } return getThemeResource(activity, R.attr.ic_send_text_offline, R.drawable.ic_send_text_offline); } |