@Override public void onBackPressed() { // Check if we're not the default SMS app if (!Utils.isDefaultSmsApp(this)) { // Ask to become the default SMS app new DefaultSmsHelper(this, R.string.not_default_send) .showIfNotDefault((ViewGroup) getWindow().getDecorView().getRootView()); } else if (mComposeFragment != null && !mComposeFragment.isReplyTextEmpty() && mComposeFragment.getRecipientAddresses().length == 0) { // If there is Draft message and no recipients are set new QKDialog() .setContext(this) .setMessage(R.string.discard_message_reason) .setPositiveButton( R.string.yes, v -> { super.onBackPressed(); }) .setNegativeButton(R.string.cancel, null) .show(); } else { super.onBackPressed(); } }
private void handleComposeButtonClick() { switch (mButtonState) { case ATTACH: mAttachmentPanel.setVisibility(VISIBLE); updateButtonState(); break; case SEND: // If the API version is less than KitKat, they can send an SMS; so do this. if (Build.VERSION.SDK_INT < 19) { if (mDelayedMessagingEnabled) { sendDelayedSms(); } else { sendSms(); } } else { // Otherwise... check if we're not the default SMS app boolean isDefaultSmsApp = Utils.isDefaultSmsApp(mContext); // Now make sure that a client hasn't blocked sending, i.e. in the welcome // screen when we have a demo conversation. if (mIsSendingBlocked) { // Show the sending blocked message (if it exists) Toast.makeText(mContext, mSendingBlockedMessage, Toast.LENGTH_SHORT).show(); } else if (!isDefaultSmsApp) { // Ask to become the default SMS app new DefaultSmsHelper(mContext, R.string.not_default_send).showIfNotDefault(this); } else if (!TextUtils.isEmpty(mReplyText.getText()) || mAttachment.hasAttachment()) { if (mDelayedMessagingEnabled) { sendDelayedSms(); } else { sendSms(); } } } break; case CLOSE: mAttachmentPanel.setVisibility(GONE); updateButtonState(); break; case CANCEL: mSendingCancelled = true; mProgressAnimator.end(); // updateButtonState(); break; } }