Example usage for android.content.pm ActivityInfo CONFIG_ORIENTATION

List of usage examples for android.content.pm ActivityInfo CONFIG_ORIENTATION

Introduction

In this page you can find the example usage for android.content.pm ActivityInfo CONFIG_ORIENTATION.

Prototype

int CONFIG_ORIENTATION

To view the source code for android.content.pm ActivityInfo CONFIG_ORIENTATION.

Click Source Link

Document

Bit in #configChanges that indicates that the activity can itself handle changes to the screen orientation.

Usage

From source file:com.pranavpandey.smallapp.SmallApp.java

@Override
protected boolean onSmallAppConfigurationChanged(Configuration newConfig) {
    int diff = newConfig.diff(mConfig);
    mConfig = new Configuration(getResources().getConfiguration());

    if ((diff & ActivityInfo.CONFIG_ORIENTATION | ActivityInfo.CONFIG_FONT_SCALE
            | ActivityInfo.CONFIG_SCREEN_SIZE | ActivityInfo.CONFIG_KEYBOARD) != 0) {
        return true;
    }/*from   w  ww  .  ja v a2 s. c  o  m*/
    return super.onSmallAppConfigurationChanged(newConfig);
}

From source file:com.android.mail.compose.ComposeActivity.java

protected void sendOrSave(final boolean save, final boolean showToast) {
    // Check if user is a monkey. Monkeys can compose and hit send
    // button but are not allowed to send anything off the device.
    if (ActivityManager.isUserAMonkey()) {
        return;/*ww w.j a  v a 2s .c  o  m*/
    }

    final SendOrSaveCallback callback = new SendOrSaveCallback() {
        @Override
        public void initializeSendOrSave() {
            final Intent i = new Intent(ComposeActivity.this, EmptyService.class);

            // API 16+ allows for setClipData. For pre-16 we are going to open the fds
            // on the main thread.
            if (Utils.isRunningJellybeanOrLater()) {
                // Grant the READ permission for the attachments to the service so that
                // as long as the service stays alive we won't hit PermissionExceptions.
                final ClipDescription desc = new ClipDescription("attachment_uris",
                        new String[] { ClipDescription.MIMETYPE_TEXT_URILIST });
                ClipData clipData = null;
                for (Attachment a : mAttachmentsView.getAttachments()) {
                    if (a != null && !Utils.isEmpty(a.contentUri)) {
                        final ClipData.Item uriItem = new ClipData.Item(a.contentUri);
                        if (clipData == null) {
                            clipData = new ClipData(desc, uriItem);
                        } else {
                            clipData.addItem(uriItem);
                        }
                    }
                }
                i.setClipData(clipData);
                i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            }

            synchronized (PENDING_SEND_OR_SAVE_TASKS_NUM) {
                if (PENDING_SEND_OR_SAVE_TASKS_NUM.getAndAdd(1) == 0) {
                    // Start service so we won't be killed if this app is
                    // put in the background.
                    startService(i);
                }
            }
            if (sTestSendOrSaveCallback != null) {
                sTestSendOrSaveCallback.initializeSendOrSave();
            }
        }

        @Override
        public void notifyMessageIdAllocated(SendOrSaveMessage sendOrSaveMessage, Message message) {
            synchronized (mDraftLock) {
                mDraftId = message.id;
                mDraft = message;
                if (sRequestMessageIdMap != null) {
                    sRequestMessageIdMap.put(sendOrSaveMessage.mRequestId, mDraftId);
                }
                // Cache request message map, in case the process is killed
                saveRequestMap();
            }
            if (sTestSendOrSaveCallback != null) {
                sTestSendOrSaveCallback.notifyMessageIdAllocated(sendOrSaveMessage, message);
            }
        }

        @Override
        public long getMessageId() {
            synchronized (mDraftLock) {
                return mDraftId;
            }
        }

        @Override
        public void sendOrSaveFinished(SendOrSaveMessage message, boolean success) {
            // Update the last sent from account.
            if (mAccount != null) {
                MailAppProvider.getInstance().setLastSentFromAccount(mAccount.uri.toString());
            }
            if (success) {
                // Successfully sent or saved so reset change markers
                discardChanges();
            } else {
                // A failure happened with saving/sending the draft
                // TODO(pwestbro): add a better string that should be used
                // when failing to send or save
                Toast.makeText(ComposeActivity.this, R.string.send_failed, Toast.LENGTH_SHORT).show();
            }

            synchronized (PENDING_SEND_OR_SAVE_TASKS_NUM) {
                if (PENDING_SEND_OR_SAVE_TASKS_NUM.addAndGet(-1) == 0) {
                    // Stop service so we can be killed.
                    stopService(new Intent(ComposeActivity.this, EmptyService.class));
                }
            }
            if (sTestSendOrSaveCallback != null) {
                sTestSendOrSaveCallback.sendOrSaveFinished(message, success);
            }
        }
    };
    setAccount(mReplyFromAccount.account);

    final Spanned body = removeComposingSpans(mBodyView.getText());
    callback.initializeSendOrSave();

    // For pre-JB we need to open the fds on the main thread
    final Bundle attachmentFds;
    if (!Utils.isRunningJellybeanOrLater()) {
        attachmentFds = initializeAttachmentFds(this, mAttachmentsView.getAttachments());
    } else {
        attachmentFds = null;
    }

    // Generate a unique message id for this request
    mRequestId = sRandom.nextInt();
    SEND_SAVE_TASK_HANDLER.post(new Runnable() {
        @Override
        public void run() {
            final Message msg = createMessage(mReplyFromAccount, mRefMessage, getMode(), body);
            sendOrSaveInternal(ComposeActivity.this, mRequestId, mReplyFromAccount, mDraftAccount, msg,
                    mRefMessage, mQuotedTextView.getQuotedTextIfIncluded(), callback, save, mComposeMode,
                    mExtraValues, attachmentFds);
        }
    });

    // Don't display the toast if the user is just changing the orientation,
    // but we still need to save the draft to the cursor because this is how we restore
    // the attachments when the configuration change completes.
    if (showToast && (getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) {
        Toast.makeText(this, save ? R.string.message_saved : R.string.sending_message, Toast.LENGTH_LONG)
                .show();
    }

    // Need to update variables here because the send or save completes
    // asynchronously even though the toast shows right away.
    discardChanges();
    updateSaveUi();

    // If we are sending, finish the activity
    if (!save) {
        finish();
    }
}

From source file:com.tct.mail.compose.ComposeActivity.java

protected void sendOrSave(final boolean save, final boolean showToast) {
    // Check if user is a monkey. Monkeys can compose and hit send
    // button but are not allowed to send anything off the device.
    // TS: xiaolin.li 2015-01-08 EMAIL BUGFIX-893877 DEL_S
    /*if (ActivityManager.isUserAMonkey()) {
    return;//from  www  .j  av a  2  s  .com
    }*/
    // TS: xiaolin.li 2015-01-08 EMAIL BUGFIX-893877 DEL_E
    final SendOrSaveCallback callback = new SendOrSaveCallback() {
        // FIXME: unused
        private int mRestoredRequestId;

        @Override
        public void initializeSendOrSave(SendOrSaveTask sendOrSaveTask) {
            synchronized (mActiveTasks) {
                int numTasks = mActiveTasks.size();
                if (numTasks == 0) {
                    // Start service so we won't be killed if this app is
                    // put in the background.
                    startService(new Intent(ComposeActivity.this, EmptyService.class));
                }

                mActiveTasks.add(sendOrSaveTask);
            }
            if (sTestSendOrSaveCallback != null) {
                sTestSendOrSaveCallback.initializeSendOrSave(sendOrSaveTask);
            }
        }

        @Override
        public void notifyMessageIdAllocated(SendOrSaveMessage sendOrSaveMessage, Message message) {
            synchronized (mDraftLock) {
                mDraftAccount = sendOrSaveMessage.mAccount;
                mDraftId = message.id;
                mDraft = message;
                if (sRequestMessageIdMap != null) {
                    sRequestMessageIdMap.put(sendOrSaveMessage.requestId(), mDraftId);
                }
                // Cache request message map, in case the process is killed
                saveRequestMap();
            }
            if (sTestSendOrSaveCallback != null) {
                sTestSendOrSaveCallback.notifyMessageIdAllocated(sendOrSaveMessage, message);
            }
        }

        @Override
        public Message getMessage() {
            synchronized (mDraftLock) {
                return mDraft;
            }
        }

        @Override
        public void sendOrSaveFinished(SendOrSaveTask task, boolean success) {
            // Update the last sent from account.
            if (mAccount != null) {
                MailAppProvider.getInstance().setLastSentFromAccount(mAccount.uri.toString());
            }
            // TS: zhaotianyong 2015-03-25 EMAIL BUGFIX-954496 ADD_S
            // TS: zhaotianyong 2015-03-31 EMAIL BUGFIX-963249 ADD_S
            if (doSend) {
                ConnectivityManager mConnectivityManager = (ConnectivityManager) ComposeActivity.this
                        .getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
                if (info == null) {
                    Utility.showToast(ComposeActivity.this, R.string.send_failed);
                }
            }
            // TS: zhaotianyong 2015-03-31 EMAIL BUGFIX-963249 ADD_E
            // TS: zhaotianyong 2015-03-25 EMAIL BUGFIX-954496 ADD_E
            if (success) {
                // Successfully sent or saved so reset change markers
                discardChanges();
                //TS: zheng.zou 2015-03-18 EMAIL FEATURE_996919 ADD_S
                if (!doSend && showToast) {
                    Intent intent = new Intent(DRAFT_SAVED_ACTION);
                    intent.setPackage(getString(R.string.email_package_name));
                    intent.putExtra(BaseColumns._ID, mDraftId);
                    //send ordered broadcast to execute the event in sequence in different receivers,
                    //ordered by priority
                    sendOrderedBroadcast(intent, null);
                }
                //TS: zheng.zou 2015-03-18 EMAIL FEATURE_996919 ADD_E
            } else {
                // A failure happened with saving/sending the draft
                // TODO(pwestbro): add a better string that should be used
                // when failing to send or save
                //[BUGFIX]-MOD by SCDTABLET.shujing.jin@tcl.com,08/05/2016,2635083
                Utility.showShortToast(ComposeActivity.this, R.string.send_failed);
                //Toast.makeText(ComposeActivity.this, R.string.send_failed, Toast.LENGTH_SHORT)
                //        .show();
            }

            int numTasks;
            synchronized (mActiveTasks) {
                // Remove the task from the list of active tasks
                mActiveTasks.remove(task);
                numTasks = mActiveTasks.size();
            }

            if (numTasks == 0) {
                // Stop service so we can be killed.
                stopService(new Intent(ComposeActivity.this, EmptyService.class));
            }
            if (sTestSendOrSaveCallback != null) {
                sTestSendOrSaveCallback.sendOrSaveFinished(task, success);
            }
        }

        @Override
        public void incrementRecipientsTimesContacted(final List<String> recipients) {
            ComposeActivity.this.incrementRecipientsTimesContacted(recipients);
        }
    };
    //TS: zheng.zou 2015-3-16 EMAIL BUGFIX_948927 Mod_S
    if (mReplyFromAccount == null && mAccount != null) {
        mReplyFromAccount = getDefaultReplyFromAccount(mAccount);
    }
    if (mReplyFromAccount != null) {
        setAccount(mReplyFromAccount.account);
    }
    //TS: zheng.zou 2015-3-16 EMAIL BUGFIX_948927 Mod_E
    // TS: yanhua.chen 2015-9-19 EMAIL BUGFIX_569665 ADD_S
    mIsSaveDraft = save;
    // TS: yanhua.chen 2015-9-19 EMAIL BUGFIX_569665 ADD_E

    final Spanned body = removeComposingSpans(mBodyView.getText());
    SEND_SAVE_TASK_HANDLER.post(new Runnable() {
        @Override
        public void run() {
            final Message msg = createMessage(mReplyFromAccount, mRefMessage, getMode(), body);
            // TS: kaifeng.lu 2016-4-6 EMAIL BUGFIX_1909143 ADD_S
            if (/*!mIsClickIcon &&*/ !mEditDraft && (mIsSaveDraft || doSend)) {//[BUGFIX]-MOD by SCDTABLET.shujing.jin@tcl.com,05/06/2016,2013535
                String body1 = mBodyView.getText().toString().replace("\n", "\n\r");
                SpannableString spannableString = new SpannableString(body1);
                StringBuffer bodySignature = new StringBuffer(body1);
                //[BUGFIX]-DEL begin by SCDTABLET.shujing.jin@tcl.com,05/17/2016,2013535,2148647
                //if(mCachedSettings != null){
                //    bodySignature.append(convertToPrintableSignature(mCachedSettings.signature));
                //}
                //[BUGFIX]-DEL end by SCDTABLET.shujing.jin
                spannableString = new SpannableString(bodySignature.toString());
                msg.bodyHtml = spannedBodyToHtml(spannableString, true);
                msg.bodyText = bodySignature.toString();
            }
            // TS: kaifeng.lu 2016-4-6 EMAIL BUGFIX_1909143 ADD_E
            mRequestId = sendOrSaveInternal(ComposeActivity.this, mReplyFromAccount, msg, mRefMessage,
                    mQuotedTextView.getQuotedTextIfIncluded(), callback, SEND_SAVE_TASK_HANDLER, save,
                    mComposeMode, mDraftAccount, mExtraValues);
        }
    });

    // Don't display the toast if the user is just changing the orientation,
    // but we still need to save the draft to the cursor because this is how we restore
    // the attachments when the configuration change completes.
    if (showToast && (getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) {
        //TS: xinlei.sheng 2015-01-26 EMAIL FIXBUG_886976 MOD_S
        if (mLaunchContact) {
            mLaunchContact = false;
        } else {
            //TS: zheng.zou 2015-03-18 EMAIL FEATURE_996919 MDD_S
            if (!save) {
                //[BUGFIX]-MOD by SCDTABLET.shujing.jin@tcl.com,08/05/2016,2635083
                Utility.showToast(this, R.string.sending_message);
                //Toast.makeText(this, R.string.sending_message,
                //        Toast.LENGTH_LONG).show();
            }
            //                Toast.makeText(this, save ? R.string.message_saved : R.string.sending_message,
            //                        Toast.LENGTH_LONG).show();
            //TS: zheng.zou 2015-03-18 EMAIL FEATURE_996919 MOD_E
        }
        //TS: xinlei.sheng 2015-01-26 EMAIL FIXBUG_886976 MOD_E
    }

    // Need to update variables here because the send or save completes
    // asynchronously even though the toast shows right away.
    discardChanges();
    updateSaveUi();

    // If we are sending, finish the activity
    if (!save) {
        finish();
        //TS: yanhua.chen 2015-6-15 EMAIL BUGFIX_1024081 ADD_S
        //TS: lin-zhou 2015-10-15 EMAIL BUGFIX_718388 MOD_S
        Uri soundUri = Uri.parse(
                "android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.email_sent);
        MediaPlayer player = new MediaPlayer();
        try {
            if (soundUri != null) {
                player.setDataSource(getApplicationContext(), soundUri);
            }
            player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
            player.prepare();
            player.start();
        } catch (IllegalArgumentException e) {
            LogUtils.e(LOG_TAG, "Send mail mediaPlayer get dataSource occur IllegalArgumentException");
        } catch (SecurityException e) {
            LogUtils.e(LOG_TAG, "Send mail mediaPlayer get dataSource occur SecurityException");
        } catch (IllegalStateException e) {
            LogUtils.e(LOG_TAG, "Send mail mediaPlayer get dataSource occur IllegalStateException");
        } catch (IOException e) {
            LogUtils.e(LOG_TAG, "Send mail mediaPlayer get dataSource occur IOException");
        } catch (NullPointerException e) {
            LogUtils.e(LOG_TAG, "Send mail mediaPlayer get dataSource occur NullPointerException");
        }
        //TS: lin-zhou 2015-10-15 EMAIL BUGFIX_718388 MOD_E
        //TS: yanhua.chen 2015-6-15 EMAIL BUGFIX_1024081 ADD_E
    }
}