Example usage for android.content Intent getLongExtra

List of usage examples for android.content Intent getLongExtra

Introduction

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

Prototype

public long getLongExtra(String name, long defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:mp.teardrop.LibraryActivity.java

/**
 * Builds a media query based off the data stored in the given intent.
 *
 * @param intent An intent created with//from  w w  w .  j  a  va2 s .com
 *               {@link LibraryAdapter#createData(View)}.
 * @param empty  If true, use the empty projection (only query id).
 * @param all    If true query all songs in the adapter; otherwise query based
 *               on the row selected.
 */
private QueryTask buildQueryFromIntent(Intent intent, boolean empty, boolean all) {
    int type = intent.getIntExtra("type", MediaUtils.TYPE_INVALID);

    String[] projection;
    //if (type == MediaUtils.TYPE_PLAYLIST)
    if (false) {
        projection = empty ? Song.EMPTY_PLAYLIST_PROJECTION : Song.FILLED_PLAYLIST_PROJECTION;
    } else {
        projection = empty ? Song.EMPTY_PROJECTION : Song.FILLED_PROJECTION;
    }

    long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID);
    QueryTask query;
    if (type == MediaUtils.TYPE_FILE) {
        query = MediaUtils.buildFileQuery(intent.getStringExtra("file"), projection);
    } else if (all || id == LibraryAdapter.HEADER_ID) {
        query = ((MediaAdapter) mPagerAdapter.mAdapters[type]).buildSongQuery(projection);
        query.data = id;
    } else {
        query = MediaUtils.buildQuery(type, id, projection, null);
    }

    return query;
}

From source file:com.android.calendar.AllInOneActivity.java

private void initFragments(long timeMillis, int viewType, Bundle icicle) {
    if (DEBUG) {//w  w w. ja  va2s.com
        Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
    }
    FragmentTransaction ft = getFragmentManager().beginTransaction();

    if (mShowCalendarControls) {
        Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
        ft.replace(R.id.mini_month, miniMonthFrag);
        mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);

        Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
        ft.replace(R.id.calendar_list, selectCalendarsFrag);
        mController.registerEventHandler(R.id.calendar_list, (EventHandler) selectCalendarsFrag);
    }
    if (!mShowCalendarControls || viewType == ViewType.EDIT) {
        mMiniMonth.setVisibility(View.GONE);
        mCalendarsList.setVisibility(View.GONE);
    }

    EventInfo info = null;
    if (viewType == ViewType.EDIT) {
        mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(GeneralPreferences.KEY_START_VIEW,
                GeneralPreferences.DEFAULT_START_VIEW);

        long eventId = -1;
        Intent intent = getIntent();
        Uri data = intent.getData();
        if (data != null) {
            try {
                eventId = Long.parseLong(data.getLastPathSegment());
            } catch (NumberFormatException e) {
                if (DEBUG) {
                    Log.d(TAG, "Create new event");
                }
            }
        } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
            eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
        }

        long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
        long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
        info = new EventInfo();
        if (end != -1) {
            info.endTime = new Time();
            info.endTime.set(end);
        }
        if (begin != -1) {
            info.startTime = new Time();
            info.startTime.set(begin);
        }
        info.id = eventId;
        // We set the viewtype so if the user presses back when they are
        // done editing the controller knows we were in the Edit Event
        // screen. Likewise for eventId
        mController.setViewType(viewType);
        mController.setEventId(eventId);
    } else {
        mPreviousView = viewType;
    }

    setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
    ft.commit(); // this needs to be after setMainPane()

    Time t = new Time(mTimeZone);
    t.set(timeMillis);
    if (viewType == ViewType.AGENDA && icicle != null) {
        mController.sendEvent(this, EventType.GO_TO, t, null, icicle.getLong(BUNDLE_KEY_EVENT_ID, -1),
                viewType);
    } else if (viewType != ViewType.EDIT) {
        mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
    }
}

From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java

private boolean handleDefaultIntent(final Intent intent) {
    if (intent == null)
        return false;
    final String action = intent.getAction();
    final boolean hasAccountIds;
    if (intent.hasExtra(EXTRA_ACCOUNT_IDS)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongArrayExtra(EXTRA_ACCOUNT_IDS));
        hasAccountIds = true;/*  w  w w.  ja v a 2  s.com*/
    } else if (intent.hasExtra(EXTRA_ACCOUNT_ID)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongExtra(EXTRA_ACCOUNT_ID, -1));
        hasAccountIds = true;
    } else {
        hasAccountIds = false;
    }
    mShouldSaveAccounts = !Intent.ACTION_SEND.equals(action) && !Intent.ACTION_SEND_MULTIPLE.equals(action)
            && !hasAccountIds;
    final Uri data = intent.getData();
    final CharSequence extraSubject = intent.getCharSequenceExtra(Intent.EXTRA_SUBJECT);
    final CharSequence extraText = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
    final Uri extraStream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
    //TODO handle share_screenshot extra (Bitmap)
    if (extraStream != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, extraStream, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (data != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, data, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (intent.hasExtra(EXTRA_SHARE_SCREENSHOT) && Utils.useShareScreenshot()) {
        final Bitmap bitmap = intent.getParcelableExtra(EXTRA_SHARE_SCREENSHOT);
        if (bitmap != null) {
            try {
                AsyncTaskUtils.executeTask(
                        new AddBitmapTask(this, bitmap, createTempImageUri(), ParcelableMedia.TYPE_IMAGE));
            } catch (IOException e) {
                // ignore
                bitmap.recycle();
            }
        }
    }
    mEditText.setText(getShareStatus(this, extraSubject, extraText));
    final int selection_end = mEditText.length();
    mEditText.setSelection(selection_end);
    return true;
}

From source file:com.newtifry.android.UpdaterService.java

public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);

    // Null intent? Weird, but deal with it.
    if (intent == null) {
        return;//from   w w w. ja  v a2  s.com
    }

    // Fetch a wakelock if we don't already have one.
    // TODO: This is disabled until I can figure out the "under locked" exception.
    /*if( this.wakelock == null )
    {
       PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
       this.wakelock = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
       this.wakelock.acquire(60000); // Max 60 seconds.
    }*/

    // We need to make some kind of backend request.
    String type = intent.getExtras().getString("type");

    if (type.equals("registration")) {
        // We want to update our registration key with the server.
        // Get a list of accounts. We need to send it to any enabled ones on the backend.
        ArrayList<NewtifryAccount> accounts = NewtifryAccount.FACTORY.listAll(this);

        String newRegistration = intent.getExtras().getString("registration");

        // TODO: Notify the user if this fails.
        for (NewtifryAccount account : accounts) {
            if (account.getEnabled()) {
                HashMap<String, Object> metadata = new HashMap<String, Object>();
                metadata.put("account", account);
                metadata.put("operation", "register");
                metadata.put("registration", newRegistration);
                account.registerWithBackend(this, newRegistration, true, null, handler, metadata);
            }
        }
    } else if (type.equals("sourcechange")) {
        // Somewhere, a source has changed or been added. We should pull down a local one.
        Long serverSourceId = intent.getLongExtra("sourceId", 0);
        Long serverDeviceId = intent.getLongExtra("deviceId", 0);

        BackendRequest request = new BackendRequest("/sources/get");
        request.add("id", serverSourceId.toString());
        request.addMeta("operation", "updatedSource");
        request.addMeta("context", this);
        request.addMeta("source_id", serverSourceId);
        request.addMeta("account_id", serverDeviceId);

        // Where to come back when we're done.
        request.setHandler(handler);

        NewtifryAccount account = NewtifryAccount.FACTORY.getByServerId(this, serverDeviceId);

        // Start a thread to make the request.
        // But if there was no account to match that device, don't bother.
        if (account != null) {
            request.startInThread(this, null, account.getAccountName());
        }
    }
}

From source file:com.nononsenseapps.notepad.ActivityMain.java

/**
 * Returns a list id from an intent if it contains one, either as part of
 * its URI or as an extra/*w  w  w . jav a  2 s  . co m*/
 * <p/>
 * Returns -1 if no id was contained, this includes insert actions
 */
long getListId(final Intent intent) {
    long retval = -1;
    if (intent != null && intent.getData() != null
            && (Intent.ACTION_EDIT.equals(intent.getAction()) || Intent.ACTION_VIEW.equals(intent.getAction())
                    || Intent.ACTION_INSERT.equals(intent.getAction()))) {
        if ((intent.getData().getPath().startsWith(NotePad.Lists.PATH_VISIBLE_LISTS)
                || intent.getData().getPath().startsWith(NotePad.Lists.PATH_LISTS)
                || intent.getData().getPath().startsWith(TaskList.URI.getPath()))) {
            try {
                retval = Long.parseLong(intent.getData().getLastPathSegment());
            } catch (NumberFormatException e) {
                retval = -1;
            }
        } else if (-1 != intent.getLongExtra(LegacyDBHelper.NotePad.Notes.COLUMN_NAME_LIST, -1)) {
            retval = intent.getLongExtra(LegacyDBHelper.NotePad.Notes.COLUMN_NAME_LIST, -1);
        } else if (-1 != intent.getLongExtra(TaskDetailFragment.ARG_ITEM_LIST_ID, -1)) {
            retval = intent.getLongExtra(TaskDetailFragment.ARG_ITEM_LIST_ID, -1);
        } else if (-1 != intent.getLongExtra(Task.Columns.DBLIST, -1)) {
            retval = intent.getLongExtra(Task.Columns.DBLIST, -1);
        }
    }
    return retval;
}

From source file:org.mariotaku.twidere.activity.support.ComposeActivity.java

private boolean handleDefaultIntent(final Intent intent) {
    if (intent == null)
        return false;
    final String action = intent.getAction();
    final boolean hasAccountIds;
    if (intent.hasExtra(EXTRA_ACCOUNT_IDS)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongArrayExtra(EXTRA_ACCOUNT_IDS));
        hasAccountIds = true;/*from  www .  j  a va2s . c  o m*/
    } else if (intent.hasExtra(EXTRA_ACCOUNT_ID)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongExtra(EXTRA_ACCOUNT_ID, -1));
        hasAccountIds = true;
    } else {
        hasAccountIds = false;
    }
    mShouldSaveAccounts = !Intent.ACTION_SEND.equals(action) && !Intent.ACTION_SEND_MULTIPLE.equals(action)
            && !hasAccountIds;
    final Uri data = intent.getData();
    final CharSequence extraSubject = intent.getCharSequenceExtra(Intent.EXTRA_SUBJECT);
    final CharSequence extraText = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
    final Uri extraStream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
    //TODO handle share_screenshot extra (Bitmap)
    if (extraStream != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, extraStream, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (data != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, data, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (intent.hasExtra(EXTRA_SHARE_SCREENSHOT) && Utils.useShareScreenshot()) {
        final Bitmap bitmap = intent.getParcelableExtra(EXTRA_SHARE_SCREENSHOT);
        if (bitmap != null) {
            try {
                AsyncTaskUtils.executeTask(
                        new AddBitmapTask(this, bitmap, createTempImageUri(), ParcelableMedia.TYPE_IMAGE));
            } catch (IOException e) {
                // ignore
                bitmap.recycle();
            }
        }
    }
    mEditText.setText(Utils.getShareStatus(this, extraSubject, extraText));
    final int selectionEnd = mEditText.length();
    mEditText.setSelection(selectionEnd);
    return true;
}

From source file:com.notifry.android.UpdaterService.java

@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);

    // Null intent? Weird, but deal with it.
    if (intent == null) {
        return;/*from w  ww. j av  a 2 s .  co  m*/
    }

    // Fetch a wakelock if we don't already have one.
    // TODO: This is disabled until I can figure out the "under locked"
    // exception.
    /*
     * if( this.wakelock == null ) { PowerManager manager = (PowerManager)
     * getSystemService(Context.POWER_SERVICE); this.wakelock =
     * manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
     * this.wakelock.acquire(60000); // Max 60 seconds. }
     */

    // We need to make some kind of backend request.
    String type = intent.getExtras().getString("type");

    if (type.equals("registration")) {
        // We want to update our registration key with the server.
        // Get a list of accounts. We need to send it to any enabled ones on
        // the backend.
        ArrayList<NotifryAccount> accounts = NotifryAccount.FACTORY.listAll(this);

        String newRegistration = intent.getExtras().getString("registration");

        // TODO: Notify the user if this fails.
        for (NotifryAccount account : accounts) {
            if (account.getEnabled().booleanValue()) {
                HashMap<String, Object> metadata = new HashMap<String, Object>();
                metadata.put("account", account);
                metadata.put("operation", "register");
                metadata.put("registration", newRegistration);
                account.registerWithBackend(this, newRegistration, true, null, handler, metadata);
            }
        }
    } else if (type.equals("sourcechange")) {
        // Somewhere, a source has changed or been added. We should pull
        // down a local one.
        Long serverSourceId = Long.valueOf(intent.getLongExtra("sourceId", 0));
        Long serverDeviceId = Long.valueOf(intent.getLongExtra("deviceId", 0));

        BackendRequest request = new BackendRequest("/sources/get");
        request.add("id", serverSourceId.toString());
        request.addMeta("operation", "updatedSource");
        request.addMeta("context", this);
        request.addMeta("source_id", serverSourceId);
        request.addMeta("account_id", serverDeviceId);

        // Where to come back when we're done.
        request.setHandler(handler);

        NotifryAccount account = NotifryAccount.FACTORY.getByServerId(this, serverDeviceId);

        // Start a thread to make the request.
        // But if there was no account to match that device, don't bother.
        if (account != null) {
            request.startInThread(this, null, account.getAccountName());
        }
    }
}

From source file:com.nextgis.mobile.fragment.MapFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (mMode == MODE_INFO || resultCode != Activity.RESULT_OK) {
        mEditLayerOverlay.setHasEdits(true);
        return;//  ww w .  j av  a  2s  .c  o  m
    }

    if (requestCode == IVectorLayerUI.MODIFY_REQUEST && data != null) {
        long id = data.getLongExtra(ConstantsUI.KEY_FEATURE_ID, NOT_FOUND);

        if (id != NOT_FOUND) {
            mEditLayerOverlay.setSelectedFeature(id);
            if (mSelectedLayer != null)
                mSelectedLayer.showFeature(id);
            setMode(MODE_SELECT_ACTION);
        }
    } else if (mEditLayerOverlay.getSelectedFeatureGeometry() != null)
        mEditLayerOverlay.setHasEdits(true);
}

From source file:de.vanita5.twittnuker.fragment.support.StatusFragment.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {
    case REQUEST_SET_COLOR: {
        if (mStatus == null)
            return;
        if (resultCode == Activity.RESULT_OK) {
            if (data == null)
                return;
            final int color = data.getIntExtra(EXTRA_COLOR, Color.TRANSPARENT);
            setUserColor(getActivity(), mStatus.user_id, color);
        } else if (resultCode == ColorPickerDialogActivity.RESULT_CLEARED) {
            clearUserColor(getActivity(), mStatus.user_id);
        }//from   ww  w  .  jav  a  2s.  c  om
        break;
    }
    case REQUEST_SELECT_ACCOUNT: {
        if (mStatus == null)
            return;
        if (resultCode == Activity.RESULT_OK) {
            if (data == null || !data.hasExtra(EXTRA_ID))
                return;
            final long accountId = data.getLongExtra(EXTRA_ID, -1);
            openStatus(getActivity(), accountId, mStatus.id);
        }
        break;
    }
    }
}

From source file:com.xunlei.shortvideo.activity.VideoPublishLocal3Activity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_VIDEO_COVER && resultCode == RESULT_OK && data != null) {
        VideoSliceConfig config = (VideoSliceConfig) data
                .getSerializableExtra(VideoSliceConfig.VIDEO_SLICE_CONFIG);
        //            setThumb(config.getPath(), config.getIndex(), config.getTotal());
        mConfig.setIndex(config.getIndex());
        mConfig.setTotal(config.getTotal());
        mConfig.setCoverOffset(config.getTime());
        mConfig.setUseCover(true);/*from  w ww  .j ava2s  .c  o m*/
    }

    if (requestCode == REQUEST_CODE_VIDEO_PERMISSION && resultCode == RESULT_OK && data != null) {
        mMiscConfig = (VideoMiscConfig) data.getSerializableExtra(VideoMiscConfig.VIDEO_MISC_CONFIG);
    }

    if (requestCode == RenderRequest.RENDER_MODE_EXPORT_VIDEO && resultCode == RESULT_OK && data != null) {
        long duration = data.getLongExtra("duration", 0);
        String path = data.getStringExtra("path");
        File file = new File(path);
        loadExportedVideo(duration, file.getAbsolutePath());
    }
}