Example usage for android.content Intent getBooleanExtra

List of usage examples for android.content Intent getBooleanExtra

Introduction

In this page you can find the example usage for android.content Intent getBooleanExtra.

Prototype

public boolean getBooleanExtra(String name, boolean defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.android.tv.MainActivity.java

private boolean handleIntent(Intent intent) {
    // Reset the closed caption settings when the activity is 1)created or 2) restarted.
    // And do not reset while TvView is playing.
    if (!mTvView.isPlaying()) {
        mCaptionSettings = new CaptionSettings(this);
    }/*from w w  w  . jav a2  s .c om*/

    // Handle the passed key press, if any. Note that only the key codes that are currently
    // handled in the TV app will be handled via Intent.
    // TODO: Consider defining a separate intent filter as passing data of mime type
    // vnd.android.cursor.item/channel isn't really necessary here.
    int keyCode = intent.getIntExtra(Utils.EXTRA_KEY_KEYCODE, KeyEvent.KEYCODE_UNKNOWN);
    if (keyCode != KeyEvent.KEYCODE_UNKNOWN) {
        if (DEBUG)
            Log.d(TAG, "Got an intent with keycode: " + keyCode);
        KeyEvent event = new KeyEvent(KeyEvent.ACTION_UP, keyCode);
        onKeyUp(keyCode, event);
        return true;
    }
    mShouldTuneToTunerChannel = intent.getBooleanExtra(Utils.EXTRA_KEY_FROM_LAUNCHER, false);
    mInitChannelUri = null;

    String extraAction = intent.getStringExtra(Utils.EXTRA_KEY_ACTION);
    if (!TextUtils.isEmpty(extraAction)) {
        if (DEBUG)
            Log.d(TAG, "Got an extra action: " + extraAction);
        if (Utils.EXTRA_ACTION_SHOW_TV_INPUT.equals(extraAction)) {
            String lastWatchedChannelUri = Utils.getLastWatchedChannelUri(this);
            if (lastWatchedChannelUri != null) {
                mInitChannelUri = Uri.parse(lastWatchedChannelUri);
            }
            mShowSelectInputView = true;
        }
    }

    if (CommonFeatures.DVR.isEnabled(this) && BuildCompat.isAtLeastN()) {
        mRecordingUri = intent.getParcelableExtra(Utils.EXTRA_KEY_RECORDING_URI);
        if (mRecordingUri != null) {
            return true;
        }
    }

    // TODO: remove the checkState once N API is finalized.
    SoftPreconditions
            .checkState(TvInputManager.ACTION_SETUP_INPUTS.equals("android.media.tv.action.SETUP_INPUTS"));
    if (TvInputManager.ACTION_SETUP_INPUTS.equals(intent.getAction())) {
        runAfterAttachedToWindow(new Runnable() {
            @Override
            public void run() {
                mOverlayManager.showSetupFragment();
            }
        });
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        Uri uri = intent.getData();
        try {
            mSource = uri.getQueryParameter(Utils.PARAM_SOURCE);
        } catch (UnsupportedOperationException e) {
            // ignore this exception.
        }
        // When the URI points to the programs (directory, not an individual item), go to the
        // program guide. The intention here is to respond to
        // "content://android.media.tv/program", not "content://android.media.tv/program/XXX".
        // Later, we might want to add handling of individual programs too.
        if (Utils.isProgramsUri(uri)) {
            // The given data is a programs URI. Open the Program Guide.
            mShowProgramGuide = true;
            return true;
        }
        // In case the channel is given explicitly, use it.
        mInitChannelUri = uri;
        if (DEBUG)
            Log.d(TAG, "ACTION_VIEW with " + mInitChannelUri);
        if (Channels.CONTENT_URI.equals(mInitChannelUri)) {
            // Tune to default channel.
            mInitChannelUri = null;
            mShouldTuneToTunerChannel = true;
            return true;
        }
        if ((!Utils.isChannelUriForOneChannel(mInitChannelUri)
                && !Utils.isChannelUriForInput(mInitChannelUri))) {
            Log.w(TAG, "Malformed channel uri " + mInitChannelUri + " tuning to default instead");
            mInitChannelUri = null;
            return true;
        }
        mTuneParams = intent.getExtras();
        if (mTuneParams == null) {
            mTuneParams = new Bundle();
        }
        if (Utils.isChannelUriForTunerInput(mInitChannelUri)) {
            long channelId = ContentUris.parseId(mInitChannelUri);
            mTuneParams.putLong(KEY_INIT_CHANNEL_ID, channelId);
        } else if (TvContract.isChannelUriForPassthroughInput(mInitChannelUri)) {
            // If mInitChannelUri is for a passthrough TV input.
            String inputId = mInitChannelUri.getPathSegments().get(1);
            TvInputInfo input = mTvInputManagerHelper.getTvInputInfo(inputId);
            if (input == null) {
                mInitChannelUri = null;
                Toast.makeText(this, R.string.msg_no_specific_input, Toast.LENGTH_SHORT).show();
                return false;
            } else if (!input.isPassthroughInput()) {
                mInitChannelUri = null;
                Toast.makeText(this, R.string.msg_not_passthrough_input, Toast.LENGTH_SHORT).show();
                return false;
            }
        } else if (mInitChannelUri != null) {
            // Handle the URI built by TvContract.buildChannelsUriForInput().
            // TODO: Change hard-coded "input" to TvContract.PARAM_INPUT.
            String inputId = mInitChannelUri.getQueryParameter("input");
            long channelId = Utils.getLastWatchedChannelIdForInput(this, inputId);
            if (channelId == Channel.INVALID_ID) {
                String[] projection = { Channels._ID };
                try (Cursor cursor = getContentResolver().query(uri, projection, null, null, null)) {
                    if (cursor != null && cursor.moveToNext()) {
                        channelId = cursor.getLong(0);
                    }
                }
            }
            if (channelId == Channel.INVALID_ID) {
                // Couldn't find any channel probably because the input hasn't been set up.
                // Try to set it up.
                mInitChannelUri = null;
                mInputToSetUp = mTvInputManagerHelper.getTvInputInfo(inputId);
            } else {
                mInitChannelUri = TvContract.buildChannelUri(channelId);
                mTuneParams.putLong(KEY_INIT_CHANNEL_ID, channelId);
            }
        }
    }
    return true;
}

From source file:com.cyanogenmod.eleven.MusicPlaybackService.java

/**
 * {@inheritDoc}/*from  w w w  .  ja  v  a2s  .  c  om*/
 */
@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (D)
        Log.d(TAG, "Got new intent " + intent + ", startId = " + startId);
    mServiceStartId = startId;

    if (intent != null) {
        final String action = intent.getAction();

        if (SHUTDOWN.equals(action)) {
            mShutdownScheduled = false;
            releaseServiceUiAndStop();
            return START_NOT_STICKY;
        }

        handleCommandIntent(intent);
    }

    // Make sure the service will shut down on its own if it was
    // just started but not bound to and nothing is playing
    scheduleDelayedShutdown();

    if (intent != null && intent.getBooleanExtra(FROM_MEDIA_BUTTON, false)) {
        MediaButtonIntentReceiver.completeWakefulIntent(intent);
    }

    return START_STICKY;
}

From source file:com.kaichaohulian.baocms.ecdemo.ui.chatting.ChattingFragment.java

@Override
protected void handleReceiver(Context context, Intent intent) {
    super.handleReceiver(context, intent);
    if (IMessageSqlManager.ACTION_GROUP_DEL.equals(intent.getAction()) && intent.hasExtra("group_id")) {
        String id = intent.getStringExtra("group_id");
        if (id != null && id.equals(mRecipients)) {
            setIsFinish(true);// w  ww . j ava 2  s.  c  o m
            finish();
        }
    } else if (IMChattingHelper.INTENT_ACTION_CHAT_USER_STATE.equals(intent.getAction())) {

        String state = intent.getStringExtra(IMChattingHelper.USER_STATE);
        if (!TextUtils.isEmpty(state) && Integer.parseInt(state) == ImUserState.WRITE.ordinal()) {
            setActionBarTitle("...");
        } else if (!TextUtils.isEmpty(state) && Integer.parseInt(state) == ImUserState.RECORDE.ordinal()) {
            setActionBarTitle("...");
        } else {
            setActionBarTitle(mUsername);
        }

    } else if (IMChattingHelper.INTENT_ACTION_CHAT_EDITTEXT_FOUCU.equals(intent.getAction())) {

        boolean hasFoucs = intent.getBooleanExtra("hasFoucs", false);
        if (hasFoucs) {
            handleSendUserStateMessage("1");
        } else {
            handleSendUserStateMessage("0");
        }

    }
}

From source file:com.chen.mail.ui.AbstractActivityController.java

/**
 * Handle an intent to open the app. This method is called only when there is no saved state,
 * so we need to set state that wasn't set before. It is correct to change the viewmode here
 * since it has not been previously set.
 *
 * This method is called for a subset of the reasons mentioned in
 * {@link #onCreate(android.os.Bundle)}. Notably, this is called when launching the app from
 * notifications, widgets, and shortcuts.
 * @param intent intent passed to the activity.
 *///ww w .  j av a2  s.c  o m
private void handleIntent(Intent intent) {
    LogUtils.d(LOG_TAG, "IN AAC.handleIntent. action=%s", intent.getAction());
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            setAccount(Account.newinstance(intent.getStringExtra(Utils.EXTRA_ACCOUNT)));
        }
        if (mAccount == null) {
            return;
        }
        final boolean isConversationMode = intent.hasExtra(Utils.EXTRA_CONVERSATION);

        if (intent.getBooleanExtra(Utils.EXTRA_FROM_NOTIFICATION, false)) {
            Analytics.getInstance().setCustomDimension(Analytics.CD_INDEX_ACCOUNT_TYPE,
                    AnalyticsUtils.getAccountTypeForAccount(mAccount.getEmailAddress()));
            Analytics.getInstance().sendEvent("notification_click",
                    isConversationMode ? "conversation" : "conversation_list", null, 0);
        }

        if (isConversationMode && mViewMode.getMode() == ViewMode.UNKNOWN) {
            mViewMode.enterConversationMode();
        } else {
            mViewMode.enterConversationListMode();
        }
        // Put the folder and conversation, and ask the loader to create this folder.
        final Bundle args = new Bundle();

        final Uri folderUri;
        if (intent.hasExtra(Utils.EXTRA_FOLDER_URI)) {
            folderUri = (Uri) intent.getParcelableExtra(Utils.EXTRA_FOLDER_URI);
        } else if (intent.hasExtra(Utils.EXTRA_FOLDER)) {
            final Folder folder = Folder.fromString(intent.getStringExtra(Utils.EXTRA_FOLDER));
            folderUri = folder.folderUri.fullUri;
        } else {
            final Bundle extras = intent.getExtras();
            LogUtils.d(LOG_TAG, "Couldn't find a folder URI in the extras: %s",
                    extras == null ? "null" : extras.toString());
            folderUri = mAccount.settings.defaultInbox;
        }

        args.putParcelable(Utils.EXTRA_FOLDER_URI, folderUri);
        args.putParcelable(Utils.EXTRA_CONVERSATION, intent.getParcelableExtra(Utils.EXTRA_CONVERSATION));
        restartOptionalLoader(LOADER_FIRST_FOLDER, mFolderCallbacks, args);
    } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            mHaveSearchResults = false;
            // Save this search query for future suggestions.
            final String query = intent.getStringExtra(SearchManager.QUERY);
            final String authority = mContext.getString(R.string.suggestions_authority);
            final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(mContext, authority,
                    SuggestionsProvider.MODE);
            suggestions.saveRecentQuery(query, null);
            setAccount((Account) intent.getParcelableExtra(Utils.EXTRA_ACCOUNT));
            fetchSearchFolder(intent);
            if (shouldEnterSearchConvMode()) {
                mViewMode.enterSearchResultsConversationMode();
            } else {
                mViewMode.enterSearchResultsListMode();
            }
        } else {
            LogUtils.e(LOG_TAG, "Missing account extra from search intent.  Finishing");
            mActivity.finish();
        }
    }
    if (mAccount != null) {
        restartOptionalLoader(LOADER_ACCOUNT_UPDATE_CURSOR, mAccountCallbacks, Bundle.EMPTY);
    }
}

From source file:com.android.mail.ui.AbstractActivityController.java

/**
 * Handle an intent to open the app. This method is called only when there is no saved state,
 * so we need to set state that wasn't set before. It is correct to change the viewmode here
 * since it has not been previously set.
 *
 * This method is called for a subset of the reasons mentioned in
 * {@link #onCreate(android.os.Bundle)}. Notably, this is called when launching the app from
 * notifications, widgets, and shortcuts.
 * @param intent intent passed to the activity.
 */// w w  w. j av a2s . c om
private void handleIntent(Intent intent) {
    LogUtils.d(LOG_TAG, "IN AAC.handleIntent. action=%s", intent.getAction());
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            setAccount(Account.newInstance(intent.getStringExtra(Utils.EXTRA_ACCOUNT)));
        }
        if (mAccount == null) {
            return;
        }
        final boolean isConversationMode = intent.hasExtra(Utils.EXTRA_CONVERSATION);

        if (intent.getBooleanExtra(Utils.EXTRA_FROM_NOTIFICATION, false)) {
            Analytics.getInstance().setEmail(mAccount.getEmailAddress(), mAccount.getType());
            Analytics.getInstance().sendEvent("notification_click",
                    isConversationMode ? "conversation" : "conversation_list", null, 0);
        }

        if (isConversationMode && mViewMode.getMode() == ViewMode.UNKNOWN) {
            mViewMode.enterConversationMode();
        } else {
            mViewMode.enterConversationListMode();
        }
        // Put the folder and conversation, and ask the loader to create this folder.
        final Bundle args = new Bundle();

        final Uri folderUri;
        if (intent.hasExtra(Utils.EXTRA_FOLDER_URI)) {
            folderUri = intent.getParcelableExtra(Utils.EXTRA_FOLDER_URI);
        } else if (intent.hasExtra(Utils.EXTRA_FOLDER)) {
            final Folder folder = Folder.fromString(intent.getStringExtra(Utils.EXTRA_FOLDER));
            folderUri = folder.folderUri.fullUri;
        } else {
            final Bundle extras = intent.getExtras();
            LogUtils.d(LOG_TAG, "Couldn't find a folder URI in the extras: %s",
                    extras == null ? "null" : extras.toString());
            folderUri = mAccount.settings.defaultInbox;
        }

        // Check if we should load all conversations instead of using
        // the default behavior which loads an initial subset.
        mIgnoreInitialConversationLimit = intent.getBooleanExtra(Utils.EXTRA_IGNORE_INITIAL_CONVERSATION_LIMIT,
                false);

        args.putParcelable(Utils.EXTRA_FOLDER_URI, folderUri);
        args.putParcelable(Utils.EXTRA_CONVERSATION, intent.getParcelableExtra(Utils.EXTRA_CONVERSATION));
        restartOptionalLoader(LOADER_FIRST_FOLDER, mFolderCallbacks, args);
    } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            mHaveSearchResults = false;
            // Save this search query for future suggestions
            final String query = intent.getStringExtra(SearchManager.QUERY);
            mSearchViewController.saveRecentQuery(query);
            setAccount((Account) intent.getParcelableExtra(Utils.EXTRA_ACCOUNT));
            fetchSearchFolder(intent);
            if (shouldEnterSearchConvMode()) {
                mViewMode.enterSearchResultsConversationMode();
            } else {
                mViewMode.enterSearchResultsListMode();
            }
        } else {
            LogUtils.e(LOG_TAG, "Missing account extra from search intent.  Finishing");
            mActivity.finish();
        }
    }
    if (mAccount != null) {
        restartOptionalLoader(LOADER_ACCOUNT_UPDATE_CURSOR, mAccountCallbacks, Bundle.EMPTY);
    }
}

From source file:com.av.remusic.service.MediaService.java

private void handleCommandIntent(Intent intent) {
    final String action = intent.getAction();
    final String command = SERVICECMD.equals(action) ? intent.getStringExtra(CMDNAME) : null;

    if (D)//from  w  w w  . j av a  2 s .c om
        Log.d(TAG, "handleCommandIntent: action = " + action + ", command = " + command);

    if (CMDNEXT.equals(command) || NEXT_ACTION.equals(action)) {
        gotoNext(true);
    } else if (CMDPREVIOUS.equals(command) || PREVIOUS_ACTION.equals(action)
            || PREVIOUS_FORCE_ACTION.equals(action)) {
        prev(PREVIOUS_FORCE_ACTION.equals(action));
    } else if (CMDTOGGLEPAUSE.equals(command) || TOGGLEPAUSE_ACTION.equals(action)) {
        if (isPlaying()) {
            pause();
            mPausedByTransientLossOfFocus = false;
        } else {
            play();
        }
    } else if (CMDPAUSE.equals(command) || PAUSE_ACTION.equals(action)) {
        pause();
        mPausedByTransientLossOfFocus = false;
    } else if (CMDPLAY.equals(command)) {
        play();
    } else if (CMDSTOP.equals(command) || STOP_ACTION.equals(action)) {
        pause();
        mPausedByTransientLossOfFocus = false;
        seek(0);
        releaseServiceUiAndStop();
    } else if (REPEAT_ACTION.equals(action)) {
        cycleRepeat();
    } else if (SHUFFLE_ACTION.equals(action)) {
        cycleShuffle();
    } else if (TRY_GET_TRACKINFO.equals(action)) {
        getLrc(mPlaylist.get(mPlayPos).mId);
    } else if (Intent.ACTION_SCREEN_OFF.equals(action)) {

        if (isPlaying() && !mIsLocked) {
            Intent lockscreen = new Intent(this, LockActivity.class);
            lockscreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(lockscreen);
        }
    } else if (LOCK_SCREEN.equals(action)) {
        mIsLocked = intent.getBooleanExtra("islock", true);
        L.D(D, TAG, "isloced = " + mIsLocked);
    } else if (SEND_PROGRESS.equals(action)) {
        if (isPlaying() && !mIsSending) {
            mPlayerHandler.post(sendDuration);
            mIsSending = true;
        } else if (!isPlaying()) {
            mPlayerHandler.removeCallbacks(sendDuration);
            mIsSending = false;
        }

    } else if (SETQUEUE.equals(action)) {
        Log.e("playab", "action");
        setQueuePosition(intent.getIntExtra("position", 0));
    }
}

From source file:com.mobicage.rogerthat.plugins.friends.ActionScreenActivity.java

@SuppressLint({ "SetJavaScriptEnabled", "JavascriptInterface", "NewApi" })
@Override//from w  w  w .  j  av  a2s. co m
public void onCreate(Bundle savedInstanceState) {
    if (CloudConstants.isContentBrandingApp()) {
        super.setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.action_screen);
    mBranding = (WebView) findViewById(R.id.branding);
    WebSettings brandingSettings = mBranding.getSettings();
    brandingSettings.setJavaScriptEnabled(true);
    brandingSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        brandingSettings.setAllowFileAccessFromFileURLs(true);
    }
    mBrandingHttp = (WebView) findViewById(R.id.branding_http);
    mBrandingHttp.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    WebSettings brandingSettingsHttp = mBrandingHttp.getSettings();
    brandingSettingsHttp.setJavaScriptEnabled(true);
    brandingSettingsHttp.setCacheMode(WebSettings.LOAD_DEFAULT);

    if (CloudConstants.isContentBrandingApp()) {
        mSoundThread = new HandlerThread("rogerthat_actionscreenactivity_sound");
        mSoundThread.start();
        Looper looper = mSoundThread.getLooper();
        mSoundHandler = new Handler(looper);

        int cameraPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
        if (cameraPermission == PackageManager.PERMISSION_GRANTED) {
            mQRCodeScanner = QRCodeScanner.getInstance(this);
            final LinearLayout previewHolder = (LinearLayout) findViewById(R.id.preview_view);
            previewHolder.addView(mQRCodeScanner.view);
        }
        mBranding.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                initFullScreenForContentBranding();
            }
        });

        mBrandingHttp.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                initFullScreenForContentBranding();
            }
        });
    }

    final View brandingHeader = findViewById(R.id.branding_header_container);

    final ImageView brandingHeaderClose = (ImageView) findViewById(R.id.branding_header_close);
    final TextView brandingHeaderText = (TextView) findViewById(R.id.branding_header_text);
    brandingHeaderClose
            .setColorFilter(UIUtils.imageColorFilter(getResources().getColor(R.color.mc_homescreen_text)));

    brandingHeaderClose.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mQRCodeScanner != null) {
                mQRCodeScanner.onResume();
            }
            brandingHeader.setVisibility(View.GONE);
            mBrandingHttp.setVisibility(View.GONE);
            mBranding.setVisibility(View.VISIBLE);
            mBrandingHttp.loadUrl("about:blank");
        }
    });

    final View brandingFooter = findViewById(R.id.branding_footer_container);

    if (CloudConstants.isContentBrandingApp()) {
        brandingHeaderClose.setVisibility(View.GONE);
        final ImageView brandingFooterClose = (ImageView) findViewById(R.id.branding_footer_close);
        final TextView brandingFooterText = (TextView) findViewById(R.id.branding_footer_text);
        brandingFooterText.setText(getString(R.string.back));
        brandingFooterClose
                .setColorFilter(UIUtils.imageColorFilter(getResources().getColor(R.color.mc_homescreen_text)));

        brandingFooter.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mQRCodeScanner != null) {
                    mQRCodeScanner.onResume();
                }
                brandingHeader.setVisibility(View.GONE);
                brandingFooter.setVisibility(View.GONE);
                mBrandingHttp.setVisibility(View.GONE);
                mBranding.setVisibility(View.VISIBLE);
                mBrandingHttp.loadUrl("about:blank");
            }
        });
    }

    final RelativeLayout openPreview = (RelativeLayout) findViewById(R.id.preview_holder);

    openPreview.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mQRCodeScanner != null) {
                mQRCodeScanner.previewHolderClicked();
            }
        }
    });

    mBranding.addJavascriptInterface(new JSInterface(this), "__rogerthat__");
    mBranding.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onConsoleMessage(String message, int lineNumber, String sourceID) {
            if (sourceID != null) {
                try {
                    sourceID = new File(sourceID).getName();
                } catch (Exception e) {
                    L.d("Could not get fileName of sourceID: " + sourceID, e);
                }
            }
            if (mIsHtmlContent) {
                L.i("[BRANDING] " + sourceID + ":" + lineNumber + " | " + message);
            } else {
                L.d("[BRANDING] " + sourceID + ":" + lineNumber + " | " + message);
            }
        }
    });
    mBranding.setWebViewClient(new WebViewClient() {
        private boolean isExternalUrl(String url) {
            for (String regularExpression : mBrandingResult.externalUrlPatterns) {
                if (url.matches(regularExpression)) {
                    return true;
                }
            }
            return false;
        }

        @SuppressLint("DefaultLocale")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            L.i("Branding is loading url: " + url);
            Uri uri = Uri.parse(url);
            String lowerCaseUrl = url.toLowerCase();
            if (lowerCaseUrl.startsWith("tel:") || lowerCaseUrl.startsWith("mailto:") || isExternalUrl(url)) {
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
                return true;
            } else if (lowerCaseUrl.startsWith(POKE)) {
                String tag = url.substring(POKE.length());
                poke(tag);
                return true;
            } else if (lowerCaseUrl.startsWith("http://") || lowerCaseUrl.startsWith("https://")) {
                if (mQRCodeScanner != null) {
                    mQRCodeScanner.onPause();
                }
                brandingHeaderText.setText(getString(R.string.loading));
                brandingHeader.setVisibility(View.VISIBLE);
                if (CloudConstants.isContentBrandingApp()) {
                    brandingFooter.setVisibility(View.VISIBLE);
                }
                mBranding.setVisibility(View.GONE);
                mBrandingHttp.setVisibility(View.VISIBLE);
                mBrandingHttp.loadUrl(url);
                return true;
            } else {
                brandingHeader.setVisibility(View.GONE);
                brandingFooter.setVisibility(View.GONE);
                mBrandingHttp.setVisibility(View.GONE);
                mBranding.setVisibility(View.VISIBLE);
            }
            return false;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            L.i("onPageFinished " + url);
            if (!mInfoSet && mService != null && mIsHtmlContent) {
                Map<String, Object> info = mFriendsPlugin.getRogerthatUserAndServiceInfo(mServiceEmail,
                        mServiceFriend);

                executeJS(true, "if (typeof rogerthat !== 'undefined') rogerthat._setInfo(%s)",
                        JSONValue.toJSONString(info));
                mInfoSet = true;
            }
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
            L.i("Checking access to: '" + url + "'");
            final URL parsedUrl;
            try {
                parsedUrl = new URL(url);
            } catch (MalformedURLException e) {
                L.d("Webview tried to load malformed URL");
                return new WebResourceResponse("text/plain", "UTF-8", null);
            }
            if (!parsedUrl.getProtocol().equals("file")) {
                return null;
            }
            File urlPath = new File(parsedUrl.getPath());
            if (urlPath.getAbsolutePath().startsWith(mBrandingResult.dir.getAbsolutePath())) {
                return null;
            }
            L.d("404: Webview tries to load outside its sandbox.");
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }
    });

    mBrandingHttp.setWebViewClient(new WebViewClient() {
        @SuppressLint("DefaultLocale")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            L.i("BrandingHttp is loading url: " + url);
            return false;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            brandingHeaderText.setText(view.getTitle());
            L.i("onPageFinished " + url);
        }
    });

    Intent intent = getIntent();
    mBrandingKey = intent.getStringExtra(BRANDING_KEY);
    mServiceEmail = intent.getStringExtra(SERVICE_EMAIL);
    mItemTagHash = intent.getStringExtra(ITEM_TAG_HASH);
    mItemLabel = intent.getStringExtra(ITEM_LABEL);
    mItemCoords = intent.getLongArrayExtra(ITEM_COORDS);
    mRunInBackground = intent.getBooleanExtra(RUN_IN_BACKGROUND, true);
}

From source file:com.kaichaohulian.baocms.ecdemo.ui.chatting.ChattingFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    LogUtil.d(TAG,/*  ww w . j  a v  a2 s  .c o  m*/
            "onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode + ", data=" + data);

    // If there's no data (because the user didn't select a picture and
    // just hit BACK, for example), there's nothing to do.

    if (requestCode == 111 && resultCode == 111) {
        ContactFriendsEntity data1 = (ContactFriendsEntity) data.getSerializableExtra("data");
        handleSendIDCardMessage(data1.getUsername(), data1.getAvatar(), data1.getId() + "", data1.getId());

    }

    if (requestCode == 0x2a || requestCode == SELECT_AT_SOMONE) {
        if (data == null) {
            return;
        }
    } else if (resultCode != ChattingActivity.RESULT_OK) {
        LogUtil.d("onActivityResult: bail due to resultCode=" + resultCode);
        isFireMsg = false;
        return;
    }

    if (data != null && 0x2a == requestCode) {
        handleAttachUrl(data.getStringExtra("choosed_file_path"));
        return;
    }

    if (requestCode == REQUEST_CODE_TAKE_PICTURE || requestCode == REQUEST_CODE_LOAD_IMAGE) {
        if (requestCode == REQUEST_CODE_LOAD_IMAGE) {
            ArrayList<String> result = data.getStringArrayListExtra(PhotoPickerActivity.KEY_RESULT);
            if (result != null && !result.isEmpty()) {
                mFilePath = result.get(0);
            } else {
                mFilePath = DemoUtils.resolvePhotoFromIntent(this.getActivity(), data,
                        FileAccessor.IMESSAGE_IMAGE);
            }
        }
        if (TextUtils.isEmpty(mFilePath)) {
            return;
        }
        File file = new File(mFilePath);
        if (file == null || !file.exists()) {

            return;
        }
        try {
            ECPreferences.savePreference(ECPreferenceSettings.SETTINGS_CROPIMAGE_OUTPUTPATH,
                    file.getAbsolutePath(), true);
            Intent intent = new Intent(getChattingActivity(), ImagePreviewActivity.class);
            getActivity().startActivityForResult(intent, REQUEST_CODE_IMAGE_CROP);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        return;
    }
    if (requestCode == REQUEST_VIEW_CARD && data != null) {
        boolean exit = data.getBooleanExtra(GroupInfoActivity.EXTRA_QUEIT, false);
        if (exit) {
            finish();
            return;
        }
        boolean reload = data.getBooleanExtra(GroupInfoActivity.EXTRA_RELOAD, false);
        if (reload) {
            mThread = mChattingAdapter.setUsername(mRecipients);
            queryUIMessage();
        }
    }

    if (requestCode == SELECT_AT_SOMONE) {
        String selectUser = data.getStringExtra(AtSomeoneUI.EXTRA_SELECT_CONV_USER);
        if (TextUtils.isEmpty(selectUser)) {
            mChattingFooter.setAtSomebody("");
            LogUtil.d(TAG, "@ [nobody]");
            return;
        }
        LogUtil.d(TAG, "@ " + selectUser);
        ECContacts contact = ContactSqlManager.getContact(selectUser);
        if (contact == null) {
            return;
        }
        if (TextUtils.isEmpty(contact.getNickname())) {
            contact.setNickname(contact.getContactid());
        }
        mChattingFooter.setAtSomebody(contact.getNickname());
        mChattingFooter.putSomebody(contact);
        postSetAtSome();
        return;
    }
    if (requestCode == GlobalConstant.ACTIVITY_FOR_RESULT_VIDEORECORD) {
        handleVideoRecordSend(data);
    }
    if (requestCode == REQUEST_CODE_TAKE_LOCATION) {
        locationInfo = (LocationInfo) data.getSerializableExtra("location");
        handleSendLocationMessage(locationInfo);
    }
    if (requestCode == REQUEST_CODE_REDPACKET) {
        if (data != null) {
            handlesendRedPacketMessage(data);
        }
    }
}

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

private void finishCreate() {
    final Bundle savedState = mInnerSavedState;
    findViews();/*from   w  w w. j  a va 2 s  .  com*/
    final Intent intent = getIntent();
    final Message message;
    final ArrayList<AttachmentPreview> previews;
    mShowQuotedText = false;
    final CharSequence quotedText;
    int action;
    // Check for any of the possibly supplied accounts.;
    final Account account;
    if (hadSavedInstanceStateMessage(savedState)) {
        action = savedState.getInt(EXTRA_ACTION, COMPOSE);
        account = savedState.getParcelable(Utils.EXTRA_ACCOUNT);
        message = savedState.getParcelable(EXTRA_MESSAGE);

        previews = savedState.getParcelableArrayList(EXTRA_ATTACHMENT_PREVIEWS);
        mRefMessage = savedState.getParcelable(EXTRA_IN_REFERENCE_TO_MESSAGE);
        quotedText = savedState.getCharSequence(EXTRA_QUOTED_TEXT);

        mExtraValues = savedState.getParcelable(EXTRA_VALUES);

        // Get the draft id from the request id if there is one.
        if (savedState.containsKey(EXTRA_REQUEST_ID)) {
            final int requestId = savedState.getInt(EXTRA_REQUEST_ID);
            if (sRequestMessageIdMap.containsKey(requestId)) {
                synchronized (mDraftLock) {
                    mDraftId = sRequestMessageIdMap.get(requestId);
                }
            }
        }
    } else {
        account = obtainAccount(intent);
        action = intent.getIntExtra(EXTRA_ACTION, COMPOSE);
        // Initialize the message from the message in the intent
        message = intent.getParcelableExtra(ORIGINAL_DRAFT_MESSAGE);
        previews = intent.getParcelableArrayListExtra(EXTRA_ATTACHMENT_PREVIEWS);
        mRefMessage = intent.getParcelableExtra(EXTRA_IN_REFERENCE_TO_MESSAGE);
        mRefMessageUri = intent.getParcelableExtra(EXTRA_IN_REFERENCE_TO_MESSAGE_URI);
        quotedText = null;

        if (Analytics.isLoggable()) {
            if (intent.getBooleanExtra(Utils.EXTRA_FROM_NOTIFICATION, false)) {
                Analytics.getInstance().sendEvent("notification_action", "compose", getActionString(action), 0);
            }
        }
    }
    mAttachmentsView.setAttachmentPreviews(previews);

    setAccount(account);
    if (mAccount == null) {
        return;
    }

    initRecipients();

    // Clear the notification and mark the conversation as seen, if necessary
    final Folder notificationFolder = intent.getParcelableExtra(EXTRA_NOTIFICATION_FOLDER);

    if (notificationFolder != null) {
        final Uri conversationUri = intent.getParcelableExtra(EXTRA_NOTIFICATION_CONVERSATION);
        Intent actionIntent;
        if (conversationUri != null) {
            actionIntent = new Intent(MailIntentService.ACTION_RESEND_NOTIFICATIONS_WEAR);
            actionIntent.putExtra(Utils.EXTRA_CONVERSATION, conversationUri);
        } else {
            actionIntent = new Intent(MailIntentService.ACTION_CLEAR_NEW_MAIL_NOTIFICATIONS);
            actionIntent.setData(Utils.appendVersionQueryParameter(this, notificationFolder.folderUri.fullUri));
        }
        actionIntent.setPackage(getPackageName());
        actionIntent.putExtra(Utils.EXTRA_ACCOUNT, account);
        actionIntent.putExtra(Utils.EXTRA_FOLDER, notificationFolder);

        startService(actionIntent);
    }

    if (intent.getBooleanExtra(EXTRA_FROM_EMAIL_TASK, false)) {
        mLaunchedFromEmail = true;
    } else if (Intent.ACTION_SEND.equals(intent.getAction())) {
        final Uri dataUri = intent.getData();
        if (dataUri != null) {
            final String dataScheme = intent.getData().getScheme();
            final String accountScheme = mAccount.composeIntentUri.getScheme();
            mLaunchedFromEmail = TextUtils.equals(dataScheme, accountScheme);
        }
    }

    if (mRefMessageUri != null) {
        mShowQuotedText = true;
        mComposeMode = action;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
            String wearReply = null;
            if (remoteInput != null) {
                LogUtils.d(LOG_TAG, "Got remote input from new api");
                CharSequence input = remoteInput.getCharSequence(NotificationActionUtils.WEAR_REPLY_INPUT);
                if (input != null) {
                    wearReply = input.toString();
                }
            } else {
                // TODO: remove after legacy code has been removed.
                LogUtils.d(LOG_TAG, "No remote input from new api, falling back to compatibility mode");
                ClipData clipData = intent.getClipData();
                if (clipData != null && LEGACY_WEAR_EXTRA.equals(clipData.getDescription().getLabel())) {
                    Bundle extras = clipData.getItemAt(0).getIntent().getExtras();
                    if (extras != null) {
                        wearReply = extras.getString(NotificationActionUtils.WEAR_REPLY_INPUT);
                    }
                }
            }

            if (!TextUtils.isEmpty(wearReply)) {
                createWearReplyTask(this, mRefMessageUri, UIProvider.MESSAGE_PROJECTION, mComposeMode,
                        wearReply).execute();
                finish();
                return;
            } else {
                LogUtils.w(LOG_TAG, "remote input string is null");
            }
        }

        getLoaderManager().initLoader(INIT_DRAFT_USING_REFERENCE_MESSAGE, null, this);
        return;
    } else if (message != null && action != EDIT_DRAFT) {
        initFromDraftMessage(message);
        initQuotedTextFromRefMessage(mRefMessage, action);
        mShowQuotedText = message.appendRefMessageContent;
        // if we should be showing quoted text but mRefMessage is null
        // and we have some quotedText, display that
        if (mShowQuotedText && mRefMessage == null) {
            if (quotedText != null) {
                initQuotedText(quotedText, false /* shouldQuoteText */);
            } else if (mExtraValues != null) {
                initExtraValues(mExtraValues);
                return;
            }
        }
    } else if (action == EDIT_DRAFT) {
        if (message == null) {
            throw new IllegalStateException("Message must not be null to edit draft");
        }
        initFromDraftMessage(message);
        // Update the action to the draft type of the previous draft
        switch (message.draftType) {
        case UIProvider.DraftType.REPLY:
            action = REPLY;
            break;
        case UIProvider.DraftType.REPLY_ALL:
            action = REPLY_ALL;
            break;
        case UIProvider.DraftType.FORWARD:
            action = FORWARD;
            break;
        case UIProvider.DraftType.COMPOSE:
        default:
            action = COMPOSE;
            break;
        }
        LogUtils.d(LOG_TAG, "Previous draft had action type: %d", action);

        mShowQuotedText = message.appendRefMessageContent;
        if (message.refMessageUri != null) {
            // If we're editing an existing draft that was in reference to an existing message,
            // still need to load that original message since we might need to refer to the
            // original sender and recipients if user switches "reply <-> reply-all".
            mRefMessageUri = message.refMessageUri;
            mComposeMode = action;
            getLoaderManager().initLoader(REFERENCE_MESSAGE_LOADER, null, this);
            return;
        }
    } else if ((action == REPLY || action == REPLY_ALL || action == FORWARD)) {
        if (mRefMessage != null) {
            initFromRefMessage(action);
            mShowQuotedText = true;
        }
    } else {
        if (initFromExtras(intent)) {
            return;
        }
    }

    mComposeMode = action;
    finishSetup(action, intent, savedState);
}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

protected SafeBroadcastReceiver getBroadcastReceiver() {

    return new SafeBroadcastReceiver() {
        @Override/*  w  w w  .  j  a v a  2  s  .  com*/
        public String[] onSafeReceive(Context context, Intent intent) {
            T.UI();
            String action = intent.getAction();
            if (MessagingPlugin.MESSAGE_MEMBER_STATUS_UPDATE_RECEIVED_INTENT.equals(action)
                    || MessagingPlugin.MESSAGE_LOCKED_INTENT.equals(action)
                    || MessagingPlugin.MESSAGE_PROCESSED_INTENT.equals(action)) {
                if (mCurrentMessage != null && intent.hasExtra("message")
                        && intent.getStringExtra("message").equals(mCurrentMessage.key)) {
                    updateView(true);

                    return UPDATE_VIEW_INTENT_ACTIONS;
                }
            }
            if (FriendsPlugin.FRIEND_UPDATE_INTENT.equals(action)
                    || IdentityStore.IDENTITY_CHANGED_INTENT.equals(action)
                    || FriendsPlugin.FRIENDS_LIST_REFRESHED.equals(action)
                    || FriendsPlugin.FRIEND_AVATAR_CHANGED_INTENT.equals(action)) {
                updateView(true);

                return UPDATE_VIEW_INTENT_ACTIONS;
            }
            if (MessagingPlugin.NEW_MESSAGE_RECEIVED_INTENT.equals(action)) {
                String trasferFailedMessage = "DASHBOARD_" + mCurrentMessage.key;
                if (mTransfering && trasferFailedMessage.equals(intent.getStringExtra("context"))) {
                    final Intent i = new Intent(context, ServiceMessageDetailActivity.class);
                    i.putExtra("message", intent.getStringExtra("message"));
                    startActivity(i);
                    overridePendingTransition(R.anim.slide_in_bottom, R.anim.slide_out_up);
                    dismissTransferingDialog();
                    finish();
                    return new String[] { action };
                }

                if (mContext != null && mContext.equals(intent.getStringExtra("context"))) {
                    L.d("Showing broadcast flow");
                } else {

                    if (mExpectNextTimer == null) // Not interested in NEW_MESSAGE_RECEIVED_INTENTS at this moment
                        return new String[] { action };

                    // We are expecting a reply on this thread!
                    String pKey = mCurrentMessage.getThreadKey();
                    if (!pKey.equals(intent.getStringExtra("parent"))) {
                        L.d("New message is from another thread");
                        return null; // New message is from another thread
                    }

                    // We received the reply!
                    mExpectNextTimer.cancel();
                    mExpectNextTimer = null;
                }

                final Intent i = new Intent(context, ServiceMessageDetailActivity.class);
                i.putExtra("message", intent.getStringExtra("message"));
                startActivity(i);

                overridePendingTransition(R.anim.slide_in_bottom, R.anim.slide_out_up);

                dismissTransferingDialog();
                finish();
                return new String[] { action };
            }
            if (MessagingPlugin.MESSAGE_JSMFR_ERROR.equals(action)) {
                if (mExpectNextTimer == null) // Not interested in MESSAGE_JSMFR_ERROR at this moment
                    return new String[] { action };

                String threadKey = mCurrentMessage.getThreadKey();
                if (!threadKey.equals(intent.getStringExtra("parent_message_key"))
                        && !threadKey.equals(intent.getStringExtra("message_key"))) {
                    return null; // Intent is for another thread
                }

                mExpectNextTimer.cancel();
                mExpectNextTimer = null;

                dismissTransferingDialog();

                Bundle extras = new Bundle();
                extras.putBoolean(ServiceActionMenuActivity.SHOW_ERROR_POPUP, true);
                jumpToServiceHomeScreen(null, extras);
                updateView(false);
                return new String[] { action };
            }
            if (MessagingPlugin.MESSAGE_FLOW_ENDED_INTENT.equals(action)) {
                if (mExpectNextTimer == null) // Not interested in MESSAGE_JSMFR_ERROR at this moment
                    return new String[] { action };

                String threadKey = mCurrentMessage.getThreadKey();
                if (!threadKey.equals(intent.getStringExtra("parent_message_key"))) {
                    return null; // Intent is for another thread
                }

                if (intent.getBooleanExtra("wait_for_followup", false)) {
                    return null; // We must keep on waiting
                }

                mExpectNextTimer.cancel();
                mExpectNextTimer = null;

                dismissTransferingDialog();

                jumpToServiceHomeScreen(null, null);
                return new String[] { action };
            }
            if (BrandingMgr.GENERIC_BRANDING_AVAILABLE_INTENT.equals(intent.getAction())) {
                if (intent.getStringExtra(BrandingMgr.BRANDING_KEY).equals(mCurrentMessage.branding)) {
                    updateView(false);
                    return new String[] { action };
                }
            }
            if (MessagingPlugin.MESSAGE_SUBMIT_PHOTO_UPLOAD.equals(action)) {
                L.d("MessagingPlugin.MESSAGE_SUBMIT_PHOTO_UPLOAD.equals(action)");
                if (intent.hasExtra("submitToJSMFR"))
                    messageSubmitToJsMfr(intent, action);
                String messageKey = intent.getStringExtra("message_key");
                if (mCurrentMessage.key.equals(messageKey)) {
                    transferComplete();
                }

                return null;
            }
            return null;
        }
    };
}