Example usage for android.content Intent hasExtra

List of usage examples for android.content Intent hasExtra

Introduction

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

Prototype

public boolean hasExtra(String name) 

Source Link

Document

Returns true if an extra value is associated with the given name.

Usage

From source file:com.ichi2.anki.StudyOptionsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    Timber.d("onActivityResult (requestCode = %d, resultCode = %d)", requestCode, resultCode);

    // rebuild action bar
    configureToolbar();//from   ww w.j  av  a 2s. co m

    // boot back to deck picker if there was an error
    if (resultCode == DeckPicker.RESULT_DB_ERROR || resultCode == DeckPicker.RESULT_MEDIA_EJECTED) {
        closeStudyOptions(resultCode);
        return;
    }

    // perform some special actions depending on which activity we're returning from
    if (requestCode == STATISTICS || requestCode == BROWSE_CARDS) {
        // select original deck if the statistics or card browser were opened,
        // which can change the selected deck
        if (intent.hasExtra("originalDeck")) {
            getCol().getDecks().select(intent.getLongExtra("originalDeck", 0L));
        }
    }
    if (requestCode == DECK_OPTIONS) {
        if (mLoadWithDeckOptions == true) {
            mLoadWithDeckOptions = false;
            try {
                JSONObject deck = getCol().getDecks().current();
                if (deck.getInt("dyn") != 0 && deck.has("empty")) {
                    deck.remove("empty");
                }
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
            mProgressDialog = StyledProgressDialog.show(getActivity(), "",
                    getResources().getString(R.string.rebuild_cram_deck), true);
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_REBUILD_CRAM, getDeckTaskListener(true),
                    new DeckTask.TaskData(mFragmented));
        } else {
            DeckTask.waitToFinish();
            refreshInterface(true);
        }
    } else if (requestCode == AnkiActivity.REQUEST_REVIEW) {
        if (resultCode == Reviewer.RESULT_NO_MORE_CARDS) {
            // If no more cards getting returned while counts > 0 (due to learn ahead limit) then show a snackbar
            int[] counts = getCol().getSched().counts();
            if ((counts[0] + counts[1] + counts[2]) > 0 && mStudyOptionsView != null) {
                View rootLayout = mStudyOptionsView.findViewById(R.id.studyoptions_main);
                AnkiActivity activity = (AnkiActivity) getActivity();
                activity.showSnackbar(R.string.studyoptions_no_cards_due, false, 0, null, rootLayout);
            }
        }
    } else if (requestCode == STATISTICS && mCurrentContentView == CONTENT_CONGRATS) {
        mCurrentContentView = CONTENT_STUDY_OPTIONS;
        setFragmentContentView(mStudyOptionsView);
    }
}

From source file:com.concentricsky.android.khanacademy.app.VideoDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.activity_video_detail);

    Intent intent = getIntent();
    videoId = savedInstanceState != null && savedInstanceState.containsKey(PARAM_VIDEO_ID)
            ? savedInstanceState.getString(PARAM_VIDEO_ID)
            : intent != null && intent.hasExtra(PARAM_VIDEO_ID) ? intent.getStringExtra(PARAM_VIDEO_ID)
                    : DEFAULT_VIDEO_ID;/*from  w  w w . j a v  a 2 s .co m*/

    topicId = savedInstanceState != null && savedInstanceState.containsKey(PARAM_TOPIC_ID)
            ? savedInstanceState.getString(PARAM_TOPIC_ID)
            : intent != null && intent.hasExtra(PARAM_TOPIC_ID) ? intent.getStringExtra(PARAM_TOPIC_ID) : null;

    requestDataService(new ObjectCallback<KADataService>() {
        @Override
        public void call(final KADataService dataService) {

            VideoDetailActivity.this.dataService = dataService;
            dataService.getAPIAdapter().registerUserUpdateListener(userUpdateListener);

            setCurrentVideo(videoId, false);

            if (shareActionProvider != null) {
                shareActionProvider.setShareIntent(prepareShareIntent(video));
            }

            User user = getCurrentUser();
            setUserVideo(user, video);

            setupUIForCurrentVideo();
            restoreVideoProgress();
        }
    });
}

From source file:com.weebly.opus1269.copyeverywhere.ui.main.MainActivity.java

/**
 * Process intents we know about/*from   w ww .  j ava2s .  c  om*/
 */
@SuppressWarnings("CallToStringEquals")
private void handleIntent() {
    final Intent intent = getIntent();
    final String action = intent.getAction();
    final String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && (type != null)) {
        if (ClipItem.TEXT_PLAIN.equals(type)) {
            final String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
            if (sharedText != null) {
                final ClipItem item = new ClipItem(sharedText);
                ClipContentProvider.insert(this, item);
                showClipViewer(item);
            }
        }
    } else if (intent.hasExtra(ClipItem.INTENT_EXTRA_CLIP_ITEM)) {
        final ClipItem item = (ClipItem) intent.getSerializableExtra(ClipItem.INTENT_EXTRA_CLIP_ITEM);
        intent.removeExtra(ClipItem.INTENT_EXTRA_CLIP_ITEM);
        showClipViewer(item);
    } else if (intent.hasExtra(Devices.INTENT_FILTER)) {
        showDevices();
    }
}

From source file:com.bitants.wally.activities.ImageDetailsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_details);

    setToolbar((Toolbar) findViewById(R.id.toolbar));

    if (getToolbar() != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(Color.TRANSPARENT);
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }/*from w ww .ja  va2  s .  c om*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getToolbar().setPadding(0, getStatusBarHeight(), 0, 0);
        }
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");
    }

    final Intent intent = getIntent();
    String action = intent.getAction();

    if (Intent.ACTION_VIEW.equals(action)) {
        pageUri = Uri.parse(intent.getDataString());
        if ("wally".equalsIgnoreCase(pageUri.getScheme())) {
            pageUri = pageUri.buildUpon().scheme("http").build();
        }
    }

    setupViews();
    setupHandlers();

    Size size = new Size(16, 9);

    if (intent.hasExtra(INTENT_EXTRA_IMAGE)) {
        final Image image = intent.getParcelableExtra(INTENT_EXTRA_IMAGE);
        final Bitmap thumbBitmap = WallyApplication.getBitmapThumb();

        if (thumbBitmap != null) {

            size = fitToWidthAndKeepRatio(image.getWidth(), image.getHeight());

            imageSize = size;

            photoView.getLayoutParams().width = size.getWidth();
            photoView.getLayoutParams().height = size.getHeight();

            Bitmap blurBitMap;
            try {
                blurBitMap = Blur.apply(imageHolder.getContext(), thumbBitmap);
            } catch (ArrayIndexOutOfBoundsException e) {
                //Blur couldn't be applied. Show regular thumbnail instead.
                blurBitMap = thumbBitmap;
            }
            photoView.setImageBitmap(blurBitMap);
        }
    }
    setupPaddings(size, false);

    if (savedInstanceState == null) {
        getPage(pageUri.toString());
    } else if (savedInstanceState.containsKey(STATE_IMAGE_PAGE)) {
        imagePage = savedInstanceState.getParcelable(STATE_IMAGE_PAGE);
    }

    if (imagePage != null) {
        Message msgObj = uiHandler.obtainMessage();
        msgObj.what = MSG_PAGE_FETCHED;
        msgObj.obj = imagePage;
        uiHandler.sendMessage(msgObj);
    } else {
        getPage(pageUri.toString());
    }

}

From source file:com.google.android.exoplayer2.demo.MediaPlayerFragment.java

private void initializePlayer() {
    Intent intent = fragActivity.getIntent();
    boolean needNewPlayer = player == null;
    if (needNewPlayer) {
        boolean preferExtensionDecoders = intent.getBooleanExtra(PREFER_EXTENSION_DECODERS, false);
        UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA)
                ? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA))
                : null;//w w w.  ja va 2  s .  com
        DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
        if (drmSchemeUuid != null) {
            String drmLicenseUrl = intent.getStringExtra(DRM_LICENSE_URL);
            String[] keyRequestPropertiesArray = intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES);
            try {
                drmSessionManager = buildDrmSessionManager(drmSchemeUuid, drmLicenseUrl,
                        keyRequestPropertiesArray);
            } catch (UnsupportedDrmException e) {
                int errorStringId = Util.SDK_INT < 18 ? R.string.error_drm_not_supported
                        : (e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME
                                ? R.string.error_drm_unsupported_scheme
                                : R.string.error_drm_unknown);
                showToast(errorStringId);
                return;
            }
        }

        @SimpleExoPlayer.ExtensionRendererMode
        int extensionRendererMode = ((ExplorerApplication) fragActivity.getApplication())
                .useExtensionRenderers()
                        ? (preferExtensionDecoders ? SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER
                                : SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON)
                        : SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF;
        TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
        trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
        trackSelectionHelper = new TrackSelectionHelper(trackSelector, videoTrackSelectionFactory);
        player = ExoPlayerFactory.newSimpleInstance(fragActivity, trackSelector, new DefaultLoadControl(),
                drmSessionManager, extensionRendererMode);
        player.addListener(this);

        eventLogger = new EventLogger(trackSelector);
        player.addListener(eventLogger);
        player.setAudioDebugListener(eventLogger);
        player.setVideoDebugListener(eventLogger);
        player.setMetadataOutput(eventLogger);

        simpleExoPlayerView.setPlayer(player);
        player.setPlayWhenReady(shouldAutoPlay);
        debugViewHelper = new DebugTextViewHelper(player, debugTextView);
        debugViewHelper.start();
    }
    if (needNewPlayer || needRetrySource) {
        String action = intent.getAction();
        Uri[] uris;
        String[] extensions;
        if (Intent.ACTION_VIEW.equals(action)) {
            uris = new Uri[] { intent.getData() };
            extensions = new String[] { intent.getStringExtra(EXTENSION_EXTRA) };
        } else if (ACTION_VIEW.equals(action)) {
            uris = new Uri[] { intent.getData() };
            extensions = new String[] { intent.getStringExtra(EXTENSION_EXTRA) };
        } else if (ACTION_VIEW_LIST.equals(action)) {
            String[] uriStrings = intent.getStringArrayExtra(URI_LIST_EXTRA);
            uris = new Uri[uriStrings.length];
            for (int i = 0; i < uriStrings.length; i++) {
                uris[i] = Uri.parse(uriStrings[i]);
            }
            extensions = intent.getStringArrayExtra(EXTENSION_LIST_EXTRA);
            if (extensions == null) {
                extensions = new String[uriStrings.length];
            }
        } else {
            if (!Intent.ACTION_MAIN.equals(action)) {
                showToast(getString(R.string.unexpected_intent_action, action));
            }
            return;
        }
        if (Util.maybeRequestReadExternalStoragePermission(fragActivity, uris)) {
            // The player will be reinitialized if the permission is granted.
            return;
        }
        MediaSource[] mediaSources = new MediaSource[uris.length];
        for (int i = 0; i < uris.length; i++) {
            mediaSources[i] = buildMediaSource(uris[i], extensions[i]);
        }
        MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0]
                : new ConcatenatingMediaSource(mediaSources);
        boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
        if (haveResumePosition) {
            player.seekTo(resumeWindow, resumePosition);
        }
        player.prepare(mediaSource, !haveResumePosition, false);
        needRetrySource = false;
        updateButtonVisibilities();
    }
}

From source file:com.nit.vicky.CardBrowser.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    View mainView = getLayoutInflater().inflate(R.layout.card_browser, null);
    setContentView(mainView);/*from ww  w .j a  v a  2s . co m*/
    Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER);

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }
    mDeckNames = new HashMap<String, String>();
    for (long did : mCol.getDecks().allIds()) {
        mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did));
    }
    registerExternalStorageListener();

    Intent i = getIntent();
    mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false);

    mBackground = Themes.getCardBrowserBackground();

    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);

    Resources res = getResources();
    mOrderByFields = res.getStringArray(R.array.card_browser_order_labels);
    try {
        mOrder = CARD_ORDER_NONE;
        String colOrder = mCol.getConf().getString("sortType");
        for (int c = 0; c < fSortTypes.length; ++c) {
            if (fSortTypes[c].equals(colOrder)) {
                mOrder = c;
                break;
            }
        }
        if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
            mOrder = 0;
        }
        mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false);
        // default to descending for non-text fields
        if (fSortTypes[mOrder].equals("noteFld")) {
            mOrderAsc = !mOrderAsc;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    mCards = new ArrayList<HashMap<String, String>>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);

    mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item,
            new String[] { "word", "sfld", "deck", "flags" },
            new int[] { R.id.card_word, R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize,
            sflCustomFont);
    mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                int which = BACKGROUND_NORMAL;
                if (text.equals("1")) {
                    which = BACKGROUND_SUSPENDED;
                } else if (text.equals("2")) {
                    which = BACKGROUND_MARKED;
                } else if (text.equals("3")) {
                    which = BACKGROUND_MARKED_SUSPENDED;
                }
                view.setBackgroundResource(mBackground[which]);
                return true;
            } else if (view.getId() == R.id.card_deck && text.length() > 0) {
                view.setVisibility(View.VISIBLE);
            }
            return false;
        }
    });

    //mCardsListView.setAdapter(mCardsAdapter);
    mCardsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class);
            //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
        }
    });
    registerForContextMenu(mCardsListView);

    mCardsGridView = (StaggeredGridView) findViewById(R.id.card_browser_gridview);
    mCardsGridView.setAdapter(mGridAdapter);
    mCardsGridView.setOnItemClickListener(new StaggeredGridView.OnItemClickListener() {
        @Override
        public void onItemClick(StaggeredGridView parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class);
            //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
            String imgURL = getImgURL(sCardBrowserCard);
            Toast.makeText(CardBrowser.this, imgURL, Toast.LENGTH_LONG).show();
        }
    });
    mSearchEditText = (EditText) findViewById(R.id.card_browser_search);
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                onSearch();
                return true;
            }
            return false;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button);
    mSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearch();
        }
    });

    mSearchTerms = "";
    if (mWholeCollection) {
        mRestrictOnDeck = "";
        setTitle(res.getString(R.string.card_browser_all_decks));
    } else {
        try {
            String deckName = mCol.getDecks().current().getString("name");
            mRestrictOnDeck = "deck:'" + deckName + "' ";
            setTitle(deckName);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }

    mSelectedTags = new HashSet<String>();

    if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) {
        searchCards();
    }
}

From source file:com.openerp.addons.messages.MessageComposeActivty.java

/**
 * Handle message intent filter for attachments
 * //from  w ww.  j  ava  2s .c om
 * @param intent
 */
private void handleIntentFilter(Intent intent) {
    attachments_type.put(ATTACHMENT_TYPE.IMAGE, "image/*");
    attachments_type.put(ATTACHMENT_TYPE.TEXT_FILE, "application/*");

    String action = intent.getAction();
    String type = intent.getType();

    // Single attachment
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        Uri fileUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
        file_uris.add(fileUri);
        handleReceivedFile();
    }

    // Multiple Attachments
    if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        ArrayList<Uri> fileUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        file_uris.addAll(fileUris);
        handleReceivedFile();

    }

    // note.note send as mail
    if (intent.hasExtra("note_body")) {
        EditText edtBody = (EditText) findViewById(R.id.edtMessageBody);
        String body = intent.getExtras().getString("note_body");
        edtBody.setText(HTMLHelper.stringToHtml(body));
        is_note_body = true;
    }

}

From source file:com.mobicage.rogerthat.MainService.java

@Override
public void onRebind(Intent intent) {
    T.UI();// w w  w.  ja  v  a 2  s .c o m
    L.d("MainService bound to " + (intent.hasExtra("clazz") ? intent.getStringExtra("clazz") : "unkown"));
}

From source file:com.mobicage.rogerthat.MainService.java

@Override
public boolean onUnbind(Intent intent) {
    T.UI();//from   w w w  . ja v a2 s  . c  o m
    L.d("MainService unbound from " + (intent.hasExtra("clazz") ? intent.getStringExtra("clazz") : "unkown"));
    return true;
}

From source file:com.irccloud.android.activity.LoginActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_RESOLVE_ERROR) {
        mResolvingError = false;//from w  w  w.  j  av a 2s  .  c  om
        if (resultCode == RESULT_OK) {
            if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
                mGoogleApiClient.connect();
            }
        }
    } else if (requestCode == REQUEST_RESOLVE_CREDENTIALS) {
        if (resultCode == RESULT_OK && data.hasExtra(Credential.EXTRA_KEY)) {
            Credential c = data.getParcelableExtra(Credential.EXTRA_KEY);
            name.setText(c.getName());
            email.setText(c.getId());
            password.setText(c.getPassword());
            loading.setVisibility(View.GONE);
            login.setVisibility(View.VISIBLE);
            loginHintClickListener.onClick(null);
            new LoginTask().execute((Void) null);
        } else {
            loading.setVisibility(View.GONE);
            login.setVisibility(View.VISIBLE);
        }
    } else if (requestCode == REQUEST_RESOLVE_SAVE_CREDENTIALS) {
        if (resultCode == RESULT_OK) {
            Log.e("IRCCloud", "Credentials result: OK");
        }
        Intent i = new Intent(LoginActivity.this, MainActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH)
            i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        if (getIntent() != null) {
            if (getIntent().getData() != null)
                i.setData(getIntent().getData());
            if (getIntent().getExtras() != null)
                i.putExtras(getIntent().getExtras());
        }
        startActivity(i);
        finish();
    }
}