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:com.android.contacts.ContactSaveService.java

private void sleepForDebugging(Intent intent) {
    long duration = intent.getLongExtra(EXTRA_SLEEP_DURATION, 1000);
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "sleeping for " + duration + "ms");
    }/*from  w  w w . jav  a 2  s. com*/
    try {
        Thread.sleep(duration);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "finished sleeping");
    }
}

From source file:com.android.contacts.ContactSaveService.java

private void deleteGroup(Intent intent) {
    long groupId = intent.getLongExtra(EXTRA_GROUP_ID, -1);
    if (groupId == -1) {
        Log.e(TAG, "Invalid arguments for deleteGroup request");
        return;//from w w w .  j  a  v a 2s .c  o  m
    }
    final Uri groupUri = ContentUris.withAppendedId(Groups.CONTENT_URI, groupId);

    final Intent callbackIntent = new Intent(BROADCAST_GROUP_DELETED);
    final Bundle undoData = mGroupsDao.captureDeletionUndoData(groupUri);
    callbackIntent.putExtra(EXTRA_UNDO_ACTION, ACTION_DELETE_GROUP);
    callbackIntent.putExtra(EXTRA_UNDO_DATA, undoData);

    mGroupsDao.delete(groupUri);

    LocalBroadcastManager.getInstance(this).sendBroadcast(callbackIntent);
}

From source file:com.android.contacts.ContactSaveService.java

private void renameGroup(Intent intent) {
    long groupId = intent.getLongExtra(EXTRA_GROUP_ID, -1);
    String label = intent.getStringExtra(EXTRA_GROUP_LABEL);

    if (groupId == -1) {
        Log.e(TAG, "Invalid arguments for renameGroup request");
        return;/*from  w  w  w  .  j  a v a 2s. c  o  m*/
    }

    ContentValues values = new ContentValues();
    values.put(Groups.TITLE, label);
    final Uri groupUri = ContentUris.withAppendedId(Groups.CONTENT_URI, groupId);
    getContentResolver().update(groupUri, values, null, null);

    Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT);
    callbackIntent.setData(groupUri);
    deliverCallback(callbackIntent);
}

From source file:ch.teamuit.android.soundplusplus.LibraryActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() != 0)
        return super.onContextItemSelected(item);

    final Intent intent = item.getIntent();
    switch (item.getItemId()) {
    case CTX_MENU_EXPAND:
        expand(intent);/*from  ww  w  . ja v a  2 s .  c  o  m*/
        if (mDefaultAction == ACTION_LAST_USED && mLastAction != ACTION_EXPAND) {
            mLastAction = ACTION_EXPAND;
            updateHeaders();
        }
        break;
    case CTX_MENU_ENQUEUE:
        pickSongs(intent, ACTION_ENQUEUE);
        break;
    case CTX_MENU_PLAY:
        pickSongs(intent, ACTION_PLAY);
        break;
    case CTX_MENU_PLAY_ALL:
        pickSongs(intent, ACTION_PLAY_ALL);
        break;
    case CTX_MENU_ENQUEUE_ALL:
        pickSongs(intent, ACTION_ENQUEUE_ALL);
        break;
    case CTX_MENU_ENQUEUE_AS_NEXT:
        pickSongs(intent, ACTION_ENQUEUE_AS_NEXT);
        break;
    case CTX_MENU_RENAME_PLAYLIST: {
        final String playlistName = intent.getStringExtra("title");
        final long playlistId = intent.getLongExtra("id", -1);
        PlaylistInputDialog dialog = new PlaylistInputDialog(new PlaylistInputDialog.Callback() {
            @Override
            public void onSuccess(String input) {
                PlaylistTask playlistTask = new PlaylistTask(playlistId, input);
                mHandler.sendMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, playlistTask));
            }
        }, playlistName, R.string.rename);
        dialog.show(getFragmentManager(), "RenamePlaylistInputDialog");
        break;
    }
    case CTX_MENU_DELETE:
        String delete_message = getString(R.string.delete_item, intent.getStringExtra("title"));
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle(R.string.delete);
        dialog.setMessage(delete_message)
                .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        mHandler.sendMessage(mHandler.obtainMessage(MSG_DELETE, intent));
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    }
                });
        dialog.create().show();
        break;
    case CTX_MENU_OPEN_EXTERNAL: {
        FileUtils.dispatchIntent(this, intent);
        break;
    }
    case CTX_MENU_MORE_FROM_ARTIST: {
        String selection;
        if (intent.getIntExtra(LibraryAdapter.DATA_TYPE, -1) == MediaUtils.TYPE_ALBUM) {
            selection = "album_id=";
        } else {
            selection = "_id=";
        }
        selection += intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID);
        setLimiter(MediaUtils.TYPE_ARTIST, selection);
        updateLimiterViews();
        break;
    }
    case CTX_MENU_MORE_FROM_ALBUM:
        setLimiter(MediaUtils.TYPE_ALBUM,
                "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID));
        updateLimiterViews();
        break;
    case CTX_MENU_ADD_TO_PLAYLIST:
        long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID);
        PlaylistDialog plDialog = new PlaylistDialog(this, intent,
                (id == LibraryAdapter.HEADER_ID ? (MediaAdapter) mCurrentAdapter : null));
        plDialog.show(getFragmentManager(), "PlaylistDialog");
        break;
    default:
        return super.onContextItemSelected(item);
    }

    return true;
}

From source file:com.android.contacts.ContactSaveService.java

private void updateGroup(Intent intent) {
    long groupId = intent.getLongExtra(EXTRA_GROUP_ID, -1);
    String label = intent.getStringExtra(EXTRA_GROUP_LABEL);
    long[] rawContactsToAdd = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_ADD);
    long[] rawContactsToRemove = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_REMOVE);

    if (groupId == -1) {
        Log.e(TAG, "Invalid arguments for updateGroup request");
        return;//from w w  w . j a  v a  2 s. co  m
    }

    final ContentResolver resolver = getContentResolver();
    final Uri groupUri = ContentUris.withAppendedId(Groups.CONTENT_URI, groupId);

    // Update group name if necessary
    if (label != null) {
        ContentValues values = new ContentValues();
        values.put(Groups.TITLE, label);
        resolver.update(groupUri, values, null, null);
    }

    // Add and remove members if necessary
    addMembersToGroup(resolver, rawContactsToAdd, groupId);
    removeMembersFromGroup(resolver, rawContactsToRemove, groupId);

    Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT);
    callbackIntent.setData(groupUri);
    deliverCallback(callbackIntent);
}

From source file:website.openeng.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
    getActivity().supportInvalidateOptionsMenu();

    // boot back to deck picker if there was an error
    if (resultCode == DeckPicker.RESULT_DB_ERROR || resultCode == DeckPicker.RESULT_MEDIA_EJECTED) {
        closeStudyOptions(resultCode);/*ww w  . j  a va  2  s.c  o m*/
        return;
    }

    // check that the collection is open before doing anything
    if (!colOpen()) {
        startLoadingCollection();
        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 == REQUEST_REVIEW) {
        if (resultCode == Reviewer.RESULT_NO_MORE_CARDS) {
            // If no more cards getting returned while counts > 0 then show a toast
            int[] counts = getCol().getSched().counts();
            if ((counts[0] + counts[1] + counts[2]) > 0) {
                Toast.makeText(getActivity(), R.string.studyoptions_no_cards_due, Toast.LENGTH_LONG).show();
            }
        }
    } else if (requestCode == STATISTICS && mCurrentContentView == CONTENT_CONGRATS) {
        mCurrentContentView = CONTENT_STUDY_OPTIONS;
        setFragmentContentView(mStudyOptionsView);
    }
}

From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() != 0)
        return super.onContextItemSelected(item);

    final Intent intent = item.getIntent();
    switch (item.getItemId()) {
    case CTX_MENU_EXPAND:
        expand(intent);//  w  ww .  j  av  a 2s.  c om
        if (mDefaultAction == ACTION_LAST_USED && mLastAction != ACTION_EXPAND) {
            mLastAction = ACTION_EXPAND;
            updateHeaders();
        }
        break;
    case CTX_MENU_ENQUEUE:
        pickSongs(intent, ACTION_ENQUEUE);
        break;
    case CTX_MENU_PLAY:
        pickSongs(intent, ACTION_PLAY);
        break;
    case CTX_MENU_PLAY_ALL:
        pickSongs(intent, ACTION_PLAY_ALL);
        break;
    case CTX_MENU_ENQUEUE_ALL:
        pickSongs(intent, ACTION_ENQUEUE_ALL);
        break;
    case CTX_MENU_ENQUEUE_AS_NEXT:
        pickSongs(intent, ACTION_ENQUEUE_AS_NEXT);
        break;
    case CTX_MENU_RENAME_PLAYLIST: {
        final String playlistName = intent.getStringExtra("title");
        final long playlistId = intent.getLongExtra("id", -1);
        PlaylistInputDialog dialog = PlaylistInputDialog.newInstance(new PlaylistInputDialog.Callback() {
            @Override
            public void onSuccess(String input) {
                PlaylistTask playlistTask = new PlaylistTask(playlistId, input);
                mHandler.sendMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, playlistTask));
            }
        }, playlistName, R.string.rename);
        dialog.show(getFragmentManager(), "RenamePlaylistInputDialog");
        break;
    }
    case CTX_MENU_DELETE:
        String delete_message = getString(R.string.delete_item, intent.getStringExtra("title"));
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle(R.string.delete);
        dialog.setMessage(delete_message)
                .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        mHandler.sendMessage(mHandler.obtainMessage(MSG_DELETE, intent));
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    }
                });
        dialog.create().show();
        break;
    case CTX_MENU_OPEN_EXTERNAL: {
        FileUtils.dispatchIntent(this, intent);
        break;
    }
    case CTX_MENU_PLUGINS: {
        queryPluginsForIntent(intent);
        break;
    }
    case CTX_MENU_MORE_FROM_ARTIST: {
        String selection;
        if (intent.getIntExtra(LibraryAdapter.DATA_TYPE, -1) == MediaUtils.TYPE_ALBUM) {
            selection = "album_id=";
        } else {
            selection = "_id=";
        }
        selection += intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID);
        setLimiter(MediaUtils.TYPE_ARTIST, selection);
        updateLimiterViews();
        break;
    }
    case CTX_MENU_MORE_FROM_ALBUM:
        setLimiter(MediaUtils.TYPE_ALBUM,
                "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID));
        updateLimiterViews();
        break;
    case CTX_MENU_ADD_TO_PLAYLIST:
        long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID);
        PlaylistDialog plDialog = PlaylistDialog.newInstance(this, intent,
                (id == LibraryAdapter.HEADER_ID ? mCurrentAdapter : null));
        plDialog.show(getFragmentManager(), "PlaylistDialog");
        break;
    default:
        return super.onContextItemSelected(item);
    }

    return true;
}

From source file:eu.power_switch.gui.fragment.configure_receiver.ConfigureReceiverDialogPage4TabbedSummaryFragment.java

@Nullable
@Override//from  ww w. ja  v a2 s . com
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.dialog_fragment_configure_receiver_page_4_summary, container, false);

    // BroadcastReceiver to get notifications from background service if room data has changed
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(LocalBroadcastConstants.INTENT_BRAND_MODEL_CHANGED)) {
                String brand = intent.getStringExtra("brand");
                String model = intent.getStringExtra("model");

                currentBrand = Receiver.Brand.getEnum(brand);
                currentModel = model;

                try {
                    Receiver receiver = ReceiverReflectionMagic.getDummy(getActivity(),
                            Receiver.getJavaPath(currentModel));
                    currentType = receiver.getType();
                } catch (Exception e) {
                    StatusMessageHandler.showErrorMessage(getActivity(), e);
                }
            } else if (intent.getAction().equals(LocalBroadcastConstants.INTENT_NAME_ROOM_CHANGED)) {
                String name = intent.getStringExtra("name");
                String roomName = intent.getStringExtra("roomName");

                currentName = name;
                currentRoomName = roomName;
            } else if (intent.getAction().equals(LocalBroadcastConstants.INTENT_CHANNEL_DETAILS_CHANGED)) {
                char channelMaster = intent.getCharExtra("channelMaster", 'A');
                int channelSlave = intent.getIntExtra("channelSlave", 0);
                ArrayList<DipSwitch> dips = (ArrayList<DipSwitch>) intent.getSerializableExtra("dips");

                long seed = intent.getLongExtra("seed", -1);

                ArrayList<UniversalButton> universalButtons = (ArrayList<UniversalButton>) intent
                        .getSerializableExtra("universalButtons");

                currentMaster = channelMaster;
                currentSlave = channelSlave;
                currentDips = dips;
                currentSeed = seed;
                currentUniversalButtons = universalButtons;
            }

            updateUi();
            notifyConfigurationChanged();
        }
    };

    name = (TextView) rootView.findViewById(R.id.textView_name);
    roomName = (TextView) rootView.findViewById(R.id.textView_roomName);
    brand = (TextView) rootView.findViewById(R.id.textView_brand);
    model = (TextView) rootView.findViewById(R.id.textView_model);
    channelMaster = (TextView) rootView.findViewById(R.id.textView_channelMaster);
    channelSlave = (TextView) rootView.findViewById(R.id.textView_channelSlave);

    linearLayoutMasterSlaveReceiver = (LinearLayout) rootView
            .findViewById(R.id.linearLayout_masterSlaveReceiver);

    linearLayoutDipReceiver = (LinearLayout) rootView.findViewById(R.id.linearLayout_dipReceiver);
    linearLayoutDips = (LinearLayout) rootView.findViewById(R.id.linearLayout_dips);

    linearLayoutAutoPairReceiver = (LinearLayout) rootView.findViewById(R.id.linearLayout_autoPair);
    seed = (TextView) rootView.findViewById(R.id.textView_seed);

    linearLayoutUniversalReceiver = (LinearLayout) rootView.findViewById(R.id.linearLayout_universalReceiver);
    linearLayoutUniversalButtons = (LinearLayout) rootView.findViewById(R.id.linearLayout_universalButtons);

    updateUi();

    Bundle args = getArguments();
    if (args != null && args.containsKey(ConfigureReceiverDialog.RECEIVER_ID_KEY)) {
        long receiverId = args.getLong(ConfigureReceiverDialog.RECEIVER_ID_KEY);
        currentId = receiverId;
        initializeReceiverData(receiverId);
    }

    return rootView;
}

From source file:com.android.contacts.ContactSaveService.java

private void joinContacts(Intent intent) {
    long contactId1 = intent.getLongExtra(EXTRA_CONTACT_ID1, -1);
    long contactId2 = intent.getLongExtra(EXTRA_CONTACT_ID2, -1);

    // Load raw contact IDs for all raw contacts involved - currently edited and selected
    // in the join UIs.
    long rawContactIds[] = getRawContactIdsForAggregation(contactId1, contactId2);
    if (rawContactIds == null) {
        Log.e(TAG, "Invalid arguments for joinContacts request");
        return;/*from   ww  w . j  a  va 2 s.co  m*/
    }

    ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();

    // For each pair of raw contacts, insert an aggregation exception
    for (int i = 0; i < rawContactIds.length; i++) {
        for (int j = 0; j < rawContactIds.length; j++) {
            if (i != j) {
                buildJoinContactDiff(operations, rawContactIds[i], rawContactIds[j]);
            }
        }
    }

    final ContentResolver resolver = getContentResolver();

    // Use the name for contactId1 as the name for the newly aggregated contact.
    final Uri contactId1Uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId1);
    final Uri entityUri = Uri.withAppendedPath(contactId1Uri, Contacts.Entity.CONTENT_DIRECTORY);
    Cursor c = resolver.query(entityUri, ContactEntityQuery.PROJECTION, ContactEntityQuery.SELECTION, null,
            null);
    if (c == null) {
        Log.e(TAG, "Unable to open Contacts DB cursor");
        showToast(R.string.contactSavedErrorToast);
        return;
    }
    long dataIdToAddSuperPrimary = -1;
    try {
        if (c.moveToFirst()) {
            dataIdToAddSuperPrimary = c.getLong(ContactEntityQuery.DATA_ID);
        }
    } finally {
        c.close();
    }

    // Mark the name from contactId1 IS_SUPER_PRIMARY to make sure that the contact
    // display name does not change as a result of the join.
    if (dataIdToAddSuperPrimary != -1) {
        Builder builder = ContentProviderOperation
                .newUpdate(ContentUris.withAppendedId(Data.CONTENT_URI, dataIdToAddSuperPrimary));
        builder.withValue(Data.IS_SUPER_PRIMARY, 1);
        builder.withValue(Data.IS_PRIMARY, 1);
        operations.add(builder.build());
    }

    // Apply all aggregation exceptions as one batch
    final boolean success = applyOperations(resolver, operations);

    final String name = queryNameOfLinkedContacts(new long[] { contactId1, contactId2 });
    Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT);
    if (success && name != null) {
        if (TextUtils.isEmpty(name)) {
            showToast(R.string.contactsJoinedMessage);
        } else {
            showToast(R.string.contactsJoinedNamedMessage, name);
        }
        Uri uri = RawContacts.getContactLookupUri(resolver,
                ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactIds[0]));
        callbackIntent.setData(uri);
        LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(BROADCAST_LINK_COMPLETE));
    }
    deliverCallback(callbackIntent);
}

From source file:com.github.jvanhie.discogsscrobbler.util.NowPlayingService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent.getBooleanExtra(NEXT_TRACK_MODE, false)) {
        /*request to start scrobbling the next track, check if it is sound*/
        int pos = intent.getIntExtra(NEXT_TRACK_ID, 0);
        String title = intent.getStringExtra(NEXT_TRACK_TITLE);
        if (trackList != null && trackList.size() > 0) {
            //done listening to the previous track -> scrobble the previous track
            int now = (int) (System.currentTimeMillis() / 1000);
            mLastfm.scrobbleTrack(track, now, new Lastfm.LastfmWaiter() {
                @Override//w  ww.  j  a  va  2 s  . c om
                public void onResult(boolean success) {
                    //the user already sees the notification, no need for extras notifications atm.
                }
            });
            mTrackDone = 0;

            if (pos == -1 && trackList.get(0).title.equals(title)) {
                //stop requested
                stop();
            } else if (pos < trackList.size() && trackList.get(pos).title.equals(title)) {
                //ok, this is a valid request, make it happen
                play(pos);
            }
        }
        /*release the wakelock if it was called via the now playing alarm*/
        NowPlayingAlarm.completeWakefulIntent(intent);
    } else {
        /*we have received a playlist, start playing*/
        trackList = intent.getParcelableArrayListExtra(TRACK_LIST);
        thumb = intent.getStringExtra(THUMB_URL);
        albumArtURL = intent.getStringExtra(ALBUM_ART_URL);
        releaseId = intent.getLongExtra(RELEASE_ID, 0);
        currentTrack = 0;
        /*first try to load the album art, then start playing*/
        mImageLoader.loadImage(this, thumb, new ImageLoadingListener() {
            @Override
            public void onLoadingStarted() {
            }

            @Override
            public void onLoadingCancelled() {
            }

            @Override
            public void onLoadingFailed(FailReason failReason) {
                mNotificationBuilder.setLargeIcon(null);
                play(currentTrack);
            }

            @Override
            public void onLoadingComplete(Bitmap loadedImage) {
                mNotificationBuilder.setLargeIcon(loadedImage);
                play(currentTrack);
            }
        });
    }

    return (START_NOT_STICKY);
}