Example usage for android.content Intent getParcelableExtra

List of usage examples for android.content Intent getParcelableExtra

Introduction

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

Prototype

public <T extends Parcelable> T getParcelableExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.github.pockethub.android.ui.gist.GistFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (RESULT_OK != resultCode || data == null) {
        return;//from   w  w  w.  j a  va  2s  .c  o m
    }

    switch (requestCode) {
    case COMMENT_CREATE:
        GitHubComment comment = data.getParcelableExtra(EXTRA_COMMENT);
        if (comments != null) {
            comments.add(comment);
            gist = gist.toBuilder().comments(gist.comments() + 1).build();
            updateList(gist, comments);
        } else {
            refreshGist();
        }
        return;
    case COMMENT_EDIT:
        comment = data.getParcelableExtra(EXTRA_COMMENT);
        if (comments != null && comment != null) {
            int position = Collections.binarySearch(comments, comment,
                    (lhs, rhs) -> Integer.valueOf(lhs.id()).compareTo(rhs.id()));
            imageGetter.removeFromCache(comment.id());
            comments.set(position, comment);
            updateList(gist, comments);
        } else {
            refreshGist();
        }
        return;
    }

    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.bluros.music.helpers.MediaButtonIntentReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
        if (PreferencesUtility.getInstance(context).pauseEnabledOnDetach())
            startService(context, MusicService.CMDPAUSE);
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return;
        }/*from  w  ww. j  a v  a 2s  .c  o m*/

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventtime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = MusicService.CMDSTOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = MusicService.CMDTOGGLEPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = MusicService.CMDNEXT;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = MusicService.CMDPREVIOUS;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = MusicService.CMDPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = MusicService.CMDPLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (mDown) {
                    if (MusicService.CMDTOGGLEPAUSE.equals(command) || MusicService.CMDPLAY.equals(command)) {
                        if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) {
                            acquireWakeLockAndSendMessage(context,
                                    mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0);
                        }
                    }
                } else if (event.getRepeatCount() == 0) {

                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventtime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG)
                            Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventtime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    mLaunched = false;
                    mDown = true;
                }
            } else {
                mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT);
                mDown = false;
            }
            if (isOrderedBroadcast()) {
                abortBroadcast();
            }
            releaseWakeLockIfHandlerIdle();
        }
    }
}

From source file:com.github.pockethub.ui.gist.GistFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (RESULT_OK != resultCode || data == null)
        return;/*from w  w w  . j  av a2 s .  co m*/

    switch (requestCode) {
    case COMMENT_CREATE:
        GithubComment comment = (GithubComment) data.getParcelableExtra(EXTRA_COMMENT);
        if (comments != null) {
            comments.add(comment);
            gist.comments = gist.comments + 1;
            updateList(gist, comments);
        } else
            refreshGist();
        return;
    case COMMENT_EDIT:
        comment = (GithubComment) data.getParcelableExtra(EXTRA_COMMENT);
        if (comments != null && comment != null) {
            int position = Collections.binarySearch(comments, comment, new Comparator<GithubComment>() {
                public int compare(GithubComment lhs, GithubComment rhs) {
                    return String.valueOf(lhs.id).compareTo(rhs.id);
                }
            });
            imageGetter.removeFromCache(comment.id);
            comments.set(position, comment);
            updateList(gist, comments);
        } else
            refreshGist();
        return;
    }

    super.onActivityResult(requestCode, resultCode, data);
}

From source file:org.metawatch.manager.Monitors.java

private static void createWifiReceiver(final Context context) {
    if (wifiReceiver != null)
        return;//from   www.  ja  v  a 2s  .  com
    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wm.getConnectionInfo();
    if (info != null)
        SignalData.wifiBars = 1 + WifiManager.calculateSignalLevel(info.getRssi(), 4);
    wifiReceiver = new BroadcastReceiver() {
        int wifiBars = 0;

        @Override
        public void onReceive(Context c, Intent intent) {
            String action = intent.getAction();
            if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
                if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
                        WifiManager.WIFI_STATE_UNKNOWN) != WifiManager.WIFI_STATE_ENABLED) {
                    wifiBars = 0;
                }
            } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
                if (!intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, false)) {
                    wifiBars = 0;
                }
            } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
                NetworkInfo netInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
                if (netInfo.getState() != NetworkInfo.State.CONNECTED) {
                    wifiBars = 0;
                } else {
                    WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
                    if (wifiInfo == null) {
                        wifiBars = 0;
                    } else {
                        wifiBars = 1 + WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 4);
                    }
                }
            } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
                final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200);
                wifiBars = 1 + WifiManager.calculateSignalLevel(newRssi, 4);
            }
            if (wifiBars != SignalData.wifiBars) {
                SignalData.wifiBars = wifiBars;
                Idle.updateIdle(context, true);
            }
        }
    };
    IntentFilter f = new IntentFilter();
    f.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    f.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
    f.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    f.addAction(WifiManager.RSSI_CHANGED_ACTION);
    context.registerReceiver(wifiReceiver, f);
}

From source file:com.kubotaku.android.sample.sensordataviewer.SensorDataActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sensor_data);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//  w w w.  j a  v a 2 s.c o  m

    // Set for activity transit
    ImageView topBackImageView = (ImageView) findViewById(R.id.data_view_image_back);
    ViewCompat.setTransitionName(topBackImageView, VIEW_NAME_HEADER_IMAGE);

    lineChart = (LineChart) findViewById(R.id.sensor_data_chart);

    Intent intent = getIntent();
    if (intent != null) {

        channelEntity = intent.getParcelableExtra(PARAM_CHANNEL);

        channel = channelEntity.getChannel();

        channelName = channelEntity.getChannel_name();
        getSupportActionBar().setTitle(channelName);

        apiToken = AppPreferences.getApiToken(this);

        weatherPlaceSettings = AppPreferences.getWeatherPlaceSettings(this);

        setupTopBackImage();
        getSensorData();
    }
}

From source file:com.battlelancer.seriesguide.api.SeriesGuideExtension.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null) {
        return;// w w w.  j  a va  2 s  . co  m
    }

    String action = intent.getAction();
    if (ACTION_SUBSCRIBE.equals(action)) {
        // just subscribing or unsubscribing
        handleSubscribe((ComponentName) intent.getParcelableExtra(EXTRA_SUBSCRIBER_COMPONENT),
                intent.getStringExtra(EXTRA_TOKEN));
    } else if (ACTION_UPDATE.equals(action)) {
        // subscriber requests an updated action
        if (intent.hasExtra(EXTRA_ENTITY_IDENTIFIER) && intent.hasExtra(EXTRA_EPISODE)) {
            handleEpisodeRequest(intent.getIntExtra(EXTRA_ENTITY_IDENTIFIER, 0),
                    intent.getBundleExtra(EXTRA_EPISODE));
        }
    }
}

From source file:be.brunoparmentier.wifikeyshare.ui.activities.WifiNetworkActivity.java

private void handleIntent(Intent intent) {
    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    String action = intent.getAction();
    Log.d(TAG, "handleIntent: action=" + action);
    if (isInWriteMode) {
        /* Write tag */
        Log.d(TAG, "Writing tag");
        if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
                || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {

            if (NfcUtils.writeTag(wifiNetwork, tag)) {
                Toast.makeText(this, R.string.nfc_tag_written, Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(this, R.string.error_nfc_tag_write, Toast.LENGTH_LONG).show();
            }//from  ww  w  .ja  va2s  . co m
            disableTagWriteMode();
        }
    } else {
        /* Read tag */
        Log.d(TAG, "Reading tag");

        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
            if (NfcUtils.NFC_TOKEN_MIME_TYPE.equals(intent.getType())) {
                Intent configureNetworkIntent = new Intent(intent)
                        .setClass(this, ConfirmConnectToWifiNetworkActivity.class)
                        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(configureNetworkIntent);
            } else {
                Log.d(TAG, "Not a Wi-Fi configuration tag");
            }
        }
    }
}

From source file:ee.ria.DigiDoc.activity.OpenExternalFileActivity.java

private void handleIntentAction() {
    Intent intent = getIntent();
    ContainerFacade container = null;/* w ww  .  ja  v  a 2s  . com*/
    Timber.d("Handling action: %s ", intent.getAction());
    switch (intent.getAction()) {
    case Intent.ACTION_VIEW:
        try {
            container = createContainer(intent.getData());
        } catch (Exception e) {
            Timber.e(e, "Error creating container from uri %s", intent.getData().toString());
        }
        break;
    case Intent.ACTION_SEND:
        Uri sendUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (sendUri != null) {
            container = createContainer(sendUri);
        }
        break;
    case Intent.ACTION_SEND_MULTIPLE:
        ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        if (uris != null) {
            container = createContainer(uris);
        }
        break;
    }

    if (container != null) {
        createContainerDetailsFragment(container);
    } else {
        createErrorFragment();
    }
}

From source file:com.gecq.musicwave.player.MediaButtonIntentReceiver.java

/**
 * {@inheritDoc}//from   w  w w.jav a 2 s . c  o  m
 */
@Override
public void onReceive(final Context context, final Intent intent) {
    if (DEBUG)
        Log.v(TAG, "Received intent: " + intent);
    final String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
        startService(context, PlayerService.CMDPAUSE);
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return;
        }

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventtime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = PlayerService.CMDSTOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = PlayerService.CMDTOGGLEPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = PlayerService.CMDNEXT;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = PlayerService.CMDPREVIOUS;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = PlayerService.CMDPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = PlayerService.CMDPLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (mDown) {
                    if (PlayerService.CMDTOGGLEPAUSE.equals(command) || PlayerService.CMDPLAY.equals(command)) {
                        if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) {
                            acquireWakeLockAndSendMessage(context,
                                    mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0);
                        }
                    }
                } else if (event.getRepeatCount() == 0) {
                    // Only consider the first event in a sequence, not the repeat events,
                    // so that we don't trigger in cases where the first event went to
                    // a different app (e.g. when the user ends a phone call by
                    // long pressing the headset button)

                    // The service may or may not be running, but we need to send it
                    // a command.
                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventtime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG)
                            Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventtime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    mLaunched = false;
                    mDown = true;
                }
            } else {
                mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT);
                mDown = false;
            }
            if (isOrderedBroadcast()) {
                abortBroadcast();
            }
            releaseWakeLockIfHandlerIdle();
        }
    }
}

From source file:com.ekumen.tangobot.application.MainActivity.java

private void onUsbDeviceAttached(Intent intent) {
    if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
        UsbDevice usbDevice = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
        onDeviceReady(usbDevice);/*w ww  .  j  av  a2s .co  m*/
    }
}