Example usage for android.content Intent getIntExtra

List of usage examples for android.content Intent getIntExtra

Introduction

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

Prototype

public int getIntExtra(String name, int defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.if3games.chessonline.DroidFish.java

private void handleSelectPlayersResult(int response, Intent data, int variant) {
    if (response != Activity.RESULT_OK) {
        //Log.w(TAG, "*** select players UI cancelled, " + response);
        switchToMainScreen();/*from  w ww .  ja  v a2 s. com*/
        return;
    }

    Log.d(TAG, "Select players UI succeeded.");

    // get the invitee list
    final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);
    //Log.d(TAG, "Invitee count: " + invitees.size());

    // get the automatch criteria
    Bundle autoMatchCriteria = null;
    int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
    int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);
    if (minAutoMatchPlayers > 0 || maxAutoMatchPlayers > 0) {
        autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minAutoMatchPlayers, maxAutoMatchPlayers, 0);
        //Log.d(TAG, "Automatch criteria: " + autoMatchCriteria);
    }

    // create the room
    Log.d(TAG, "Creating room...");
    RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);
    rtmConfigBuilder.addPlayersToInvite(invitees);
    rtmConfigBuilder.setMessageReceivedListener(this);
    rtmConfigBuilder.setRoomStatusUpdateListener(this);
    if (autoMatchCriteria != null) {
        rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
    }
    rtmConfigBuilder.setVariant(variant);
    switchToScreen(R.id.screen_wait);
    keepScreenOn();
    resetGameVars();
    resetGameBoolVars();
    Games.RealTimeMultiplayer.create(getApiClient(), rtmConfigBuilder.build());
    Log.d(TAG, "Room created, waiting for it to be ready...");
}

From source file:com.android.launcher3.Launcher.java

private void handleActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (isWorkspaceLoading()) {
        // process the result once the workspace has loaded.
        mPendingActivityResult = new ActivityResultInfo(requestCode, resultCode, data);
        return;//from   w w w  .  j  av  a 2  s  . co  m
    }
    mPendingActivityResult = null;

    // Reset the startActivity waiting flag
    final PendingRequestArgs requestArgs = mPendingRequestArgs;
    setWaitingForResult(null);
    if (requestArgs == null) {
        return;
    }

    final int pendingAddWidgetId = requestArgs.getWidgetId();

    Runnable exitSpringLoaded = new Runnable() {
        @Override
        public void run() {
            exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
                    EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
        }
    };

    if (requestCode == REQUEST_BIND_APPWIDGET) {
        // This is called only if the user did not previously have permissions to bind widgets
        final int appWidgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
        if (resultCode == RESULT_CANCELED) {
            completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId, requestArgs);
            mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
                    false);
        } else if (resultCode == RESULT_OK) {
            addAppWidgetImpl(appWidgetId, requestArgs, null, requestArgs.getWidgetProvider(),
                    ON_ACTIVITY_RESULT_ANIMATION_DELAY);
        }
        return;
    } else if (requestCode == REQUEST_PICK_WALLPAPER) {
        if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
            // User could have free-scrolled between pages before picking a wallpaper; make sure
            // we move to the closest one now.
            mWorkspace.setCurrentPage(mWorkspace.getPageNearestToCenterOfScreen());
            showWorkspace(false);
        }
        return;
    }

    boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || requestCode == REQUEST_CREATE_APPWIDGET);

    // We have special handling for widgets
    if (isWidgetDrop) {
        final int appWidgetId;
        int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
        if (widgetId < 0) {
            appWidgetId = pendingAddWidgetId;
        } else {
            appWidgetId = widgetId;
        }

        final int result;
        if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
            Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not "
                    + "returned from the widget configuration activity.");
            result = RESULT_CANCELED;
            completeTwoStageWidgetDrop(result, appWidgetId, requestArgs);
            final Runnable onComplete = new Runnable() {
                @Override
                public void run() {
                    exitSpringLoadedDragModeDelayed(false, 0, null);
                }
            };

            mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
                    false);
        } else {
            if (requestArgs.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
                // When the screen id represents an actual screen (as opposed to a rank)
                // we make sure that the drop page actually exists.
                requestArgs.screenId = ensurePendingDropLayoutExists(requestArgs.screenId);
            }
            final CellLayout dropLayout = mWorkspace.getScreenWithId(requestArgs.screenId);

            dropLayout.setDropPending(true);
            final Runnable onComplete = new Runnable() {
                @Override
                public void run() {
                    completeTwoStageWidgetDrop(resultCode, appWidgetId, requestArgs);
                    dropLayout.setDropPending(false);
                }
            };
            mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
                    false);
        }
        return;
    }

    if (requestCode == REQUEST_RECONFIGURE_APPWIDGET || requestCode == REQUEST_BIND_PENDING_APPWIDGET) {
        if (resultCode == RESULT_OK) {
            // Update the widget view.
            completeAdd(requestCode, data, pendingAddWidgetId, requestArgs);
        }
        // Leave the widget in the pending state if the user canceled the configure.
        return;
    }

    if (requestCode == REQUEST_CREATE_SHORTCUT) {
        // Handle custom shortcuts created using ACTION_CREATE_SHORTCUT.
        if (resultCode == RESULT_OK && requestArgs.container != ItemInfo.NO_ID) {
            completeAdd(requestCode, data, -1, requestArgs);
            mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
                    false);

        } else if (resultCode == RESULT_CANCELED) {
            mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
                    false);
        }
    }
    mDragLayer.clearAnimatedView();
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

static PersonaLiveFolderInfo addLiveFolder(Context context, Intent data, PersonaCellLayout.CellInfo cellInfo,
        boolean notify) {

    Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
    String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);

    Drawable icon = null;/*from   w w  w  .j  av  a 2  s  . c  o m*/
    boolean filtered = false;
    Intent.ShortcutIconResource iconResource = null;

    Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
    if (extra != null && extra instanceof Intent.ShortcutIconResource) {
        try {
            iconResource = (Intent.ShortcutIconResource) extra;
            final PackageManager packageManager = context.getPackageManager();
            Resources resources = packageManager.getResourcesForApplication(iconResource.packageName);
            final int id = resources.getIdentifier(iconResource.resourceName, null, null);
            icon = resources.getDrawable(id);
        } catch (Exception e) {
            PersonaLog.w(LOG_TAG, "Could not load live folder icon: " + extra);
        }
    }

    if (icon == null) {
        icon = context.getResources().getDrawable(R.drawable.pr_ic_launcher_folder);
    }

    final PersonaLiveFolderInfo info = new PersonaLiveFolderInfo();
    info.icon = icon;
    info.filtered = filtered;
    info.title = name;
    info.iconResource = iconResource;
    info.uri = data.getData();
    info.baseIntent = baseIntent;
    info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
            LiveFolders.DISPLAY_MODE_GRID);

    PersonaLauncherModel.addItemToDatabase(context, info, PersonaLauncherSettings.Favorites.CONTAINER_DESKTOP,
            cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
    sModel.addFolder(info);

    return info;
}

From source file:com.android.cts.verifier.managedprovisioning.ByodHelperActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        Log.w(TAG, "Restored state");
        mOriginalSettings = savedInstanceState.getBundle(ORIGINAL_SETTINGS_NAME);
    } else {/*from  w  w w. j  a  v  a 2  s  .  com*/
        mOriginalSettings = new Bundle();
    }

    mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName());
    mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Intent intent = getIntent();
    String action = intent.getAction();
    Log.d(TAG, "ByodHelperActivity.onCreate: " + action);

    // we are explicitly started by {@link DeviceAdminTestReceiver} after a successful provisioning.
    if (action.equals(ACTION_PROFILE_PROVISIONED)) {
        // Jump back to CTS verifier with result.
        Intent response = new Intent(ACTION_PROFILE_OWNER_STATUS);
        response.putExtra(EXTRA_PROVISIONED, isProfileOwner());
        startActivityInPrimary(response);
        // Queried by CtsVerifier in the primary side using startActivityForResult.
    } else if (action.equals(ACTION_QUERY_PROFILE_OWNER)) {
        Intent response = new Intent();
        response.putExtra(EXTRA_PROVISIONED, isProfileOwner());
        setResult(RESULT_OK, response);
        // Request to delete work profile.
    } else if (action.equals(ACTION_REMOVE_MANAGED_PROFILE)) {
        if (isProfileOwner()) {
            Log.d(TAG, "Clearing cross profile intents");
            mDevicePolicyManager.clearCrossProfileIntentFilters(mAdminReceiverComponent);
            mDevicePolicyManager.wipeData(0);
            showToast(R.string.provisioning_byod_profile_deleted);
        }
    } else if (action.equals(ACTION_INSTALL_APK)) {
        boolean allowNonMarket = intent.getBooleanExtra(EXTRA_ALLOW_NON_MARKET_APPS, false);
        boolean wasAllowed = getAllowNonMarket();

        // Update permission to install non-market apps
        setAllowNonMarket(allowNonMarket);
        mOriginalSettings.putBoolean(INSTALL_NON_MARKET_APPS, wasAllowed);

        // Request to install a non-market application- easiest way is to reinstall ourself
        final Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE)
                .setData(Uri.parse("package:" + getPackageName()))
                .putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true).putExtra(Intent.EXTRA_RETURN_RESULT, true);
        startActivityForResult(installIntent, REQUEST_INSTALL_PACKAGE);

        // Not yet ready to finish- wait until the result comes back
        return;
        // Queried by CtsVerifier in the primary side using startActivityForResult.
    } else if (action.equals(ACTION_CHECK_INTENT_FILTERS)) {
        final boolean intentFiltersSetForManagedIntents = new IntentFiltersTestHelper(this)
                .checkCrossProfileIntentFilters(IntentFiltersTestHelper.FLAG_INTENTS_FROM_MANAGED);
        setResult(intentFiltersSetForManagedIntents ? RESULT_OK : RESULT_FAILED, null);
    } else if (action.equals(ACTION_CAPTURE_AND_CHECK_IMAGE)) {
        // We need the camera permission to send the image capture intent.
        grantCameraPermissionToSelf();
        Intent captureImageIntent = getCaptureImageIntent();
        Pair<File, Uri> pair = getTempUri("image.jpg");
        mImageFile = pair.first;
        mImageUri = pair.second;
        captureImageIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
        if (captureImageIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(captureImageIntent, REQUEST_IMAGE_CAPTURE);
        } else {
            Log.e(TAG, "Capture image intent could not be resolved in managed profile.");
            showToast(R.string.provisioning_byod_capture_media_error);
            finish();
        }
        return;
    } else if (action.equals(ACTION_CAPTURE_AND_CHECK_VIDEO_WITH_EXTRA_OUTPUT)
            || action.equals(ACTION_CAPTURE_AND_CHECK_VIDEO_WITHOUT_EXTRA_OUTPUT)) {
        // We need the camera permission to send the video capture intent.
        grantCameraPermissionToSelf();
        Intent captureVideoIntent = getCaptureVideoIntent();
        int videoCaptureRequestId;
        if (action.equals(ACTION_CAPTURE_AND_CHECK_VIDEO_WITH_EXTRA_OUTPUT)) {
            mVideoUri = getTempUri("video.mp4").second;
            captureVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mVideoUri);
            videoCaptureRequestId = REQUEST_VIDEO_CAPTURE_WITH_EXTRA_OUTPUT;
        } else {
            videoCaptureRequestId = REQUEST_VIDEO_CAPTURE_WITHOUT_EXTRA_OUTPUT;
        }
        if (captureVideoIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(captureVideoIntent, videoCaptureRequestId);
        } else {
            Log.e(TAG, "Capture video intent could not be resolved in managed profile.");
            showToast(R.string.provisioning_byod_capture_media_error);
            finish();
        }
        return;
    } else if (action.equals(ACTION_CAPTURE_AND_CHECK_AUDIO)) {
        Intent captureAudioIntent = getCaptureAudioIntent();
        if (captureAudioIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(captureAudioIntent, REQUEST_AUDIO_CAPTURE);
        } else {
            Log.e(TAG, "Capture audio intent could not be resolved in managed profile.");
            showToast(R.string.provisioning_byod_capture_media_error);
            finish();
        }
        return;
    } else if (ACTION_KEYGUARD_DISABLED_FEATURES.equals(action)) {
        final int value = intent.getIntExtra(EXTRA_PARAMETER_1,
                DevicePolicyManager.KEYGUARD_DISABLE_FEATURES_NONE);
        mDevicePolicyManager.setKeyguardDisabledFeatures(mAdminReceiverComponent, value);
    } else if (ACTION_LOCKNOW.equals(action)) {
        mDevicePolicyManager.lockNow();
        setResult(RESULT_OK);
    } else if (action.equals(ACTION_TEST_NFC_BEAM)) {
        Intent testNfcBeamIntent = new Intent(this, NfcTestActivity.class);
        testNfcBeamIntent.putExtras(intent);
        startActivity(testNfcBeamIntent);
        finish();
        return;
    } else if (action.equals(ACTION_TEST_CROSS_PROFILE_INTENTS_DIALOG)) {
        sendIntentInsideChooser(new Intent(CrossProfileTestActivity.ACTION_CROSS_PROFILE_TO_PERSONAL));
    } else if (action.equals(ACTION_TEST_APP_LINKING_DIALOG)) {
        mDevicePolicyManager.addUserRestriction(DeviceAdminTestReceiver.getReceiverComponentName(),
                UserManager.ALLOW_PARENT_PROFILE_APP_LINKING);
        Intent toSend = new Intent(Intent.ACTION_VIEW);
        toSend.setData(Uri.parse("http://com.android.cts.verifier"));
        sendIntentInsideChooser(toSend);
    } else if (action.equals(ACTION_SET_USER_RESTRICTION)) {
        final String restriction = intent.getStringExtra(EXTRA_PARAMETER_1);
        if (restriction != null) {
            mDevicePolicyManager.addUserRestriction(DeviceAdminTestReceiver.getReceiverComponentName(),
                    restriction);
        }
    } else if (action.equals(ACTION_CLEAR_USER_RESTRICTION)) {
        final String restriction = intent.getStringExtra(EXTRA_PARAMETER_1);
        if (restriction != null) {
            mDevicePolicyManager.clearUserRestriction(DeviceAdminTestReceiver.getReceiverComponentName(),
                    restriction);
        }
    } else if (action.equals(ACTION_BYOD_SET_LOCATION_AND_CHECK_UPDATES)) {
        handleLocationAction();
        return;
    } else if (action.equals(ACTION_NOTIFICATION)) {
        showNotification(Notification.VISIBILITY_PUBLIC);
    } else if (ACTION_NOTIFICATION_ON_LOCKSCREEN.equals(action)) {
        mDevicePolicyManager.lockNow();
        showNotification(Notification.VISIBILITY_PRIVATE);
    } else if (ACTION_CLEAR_NOTIFICATION.equals(action)) {
        mNotificationManager.cancel(NOTIFICATION_ID);
    } else if (ACTION_TEST_SELECT_WORK_CHALLENGE.equals(action)) {
        mDevicePolicyManager.setOrganizationColor(mAdminReceiverComponent, Color.BLUE);
        mDevicePolicyManager.setOrganizationName(mAdminReceiverComponent,
                getResources().getString(R.string.provisioning_byod_confirm_work_credentials_header));
        startActivity(new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD));
    } else if (ACTION_LAUNCH_CONFIRM_WORK_CREDENTIALS.equals(action)) {
        KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        Intent launchIntent = keyguardManager.createConfirmDeviceCredentialIntent(null, null);
        startActivity(launchIntent);
    } else if (ACTION_SET_ORGANIZATION_INFO.equals(action)) {
        if (intent.hasExtra(OrganizationInfoTestActivity.EXTRA_ORGANIZATION_NAME)) {
            final String organizationName = intent
                    .getStringExtra(OrganizationInfoTestActivity.EXTRA_ORGANIZATION_NAME);
            mDevicePolicyManager.setOrganizationName(mAdminReceiverComponent, organizationName);
        }
        final int organizationColor = intent.getIntExtra(OrganizationInfoTestActivity.EXTRA_ORGANIZATION_COLOR,
                mDevicePolicyManager.getOrganizationColor(mAdminReceiverComponent));
        mDevicePolicyManager.setOrganizationColor(mAdminReceiverComponent, organizationColor);
    } else if (ACTION_TEST_PARENT_PROFILE_PASSWORD.equals(action)) {
        startActivity(new Intent(DevicePolicyManager.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD));
    }
    // This activity has no UI and is only used to respond to CtsVerifier in the primary side.
    finish();
}

From source file:com.bluros.music.MusicService.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. ja v  a  2  s  . c o  m*/
        Log.d(TAG, "handleCommandIntent: action = " + action + ", command = " + command);

    if (NotificationHelper.checkIntent(intent)) {
        goToPosition(mPlayPos + NotificationHelper.getPosition(intent));
        return;
    }

    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 (SLEEP_MODE_STOP_ACTION.equals(action)) {
        setSleepMode(false);
        pause();
        mPausedByTransientLossOfFocus = false;
        seek(0);
        releaseServiceUiAndStop();
    } else if (REPEAT_ACTION.equals(action)) {
        cycleRepeat();
    } else if (SHUFFLE_ACTION.equals(action)) {
        cycleShuffle();
    } else if (RemoteSelectDialog.REMOTE_START_SCAN.equals(action)) {
        if (mRemoteScanFound == null) {
            mRemoteScanFound = new IRemoteScanFound() {
                @Override
                public void onRenderFound(final IRemote rend) {
                    Log.d("Found", rend.getName());
                    remoteObjects.add(rend);
                    Intent intent = new Intent(RemoteSelectDialog.REMOTE_FOUND);
                    intent.putExtra("Remote", new RemoteObject(remoteObjects.size(), rend.getName(),
                            rend.getImage(), rend.getType()));

                    sendBroadcast(intent);
                }
            };
        }

        if (upnpRendererScanner == null)
            upnpRendererScanner = new UpnpRendererScanner();
        upnpRendererScanner.startScan(mRemoteScanFound);

        if (chromeCastScanner == null)
            chromeCastScanner = new ChromeCastScanner(this);
        chromeCastScanner.startScan(mRemoteScanFound);

        if (airPlayScanner == null)
            airPlayScanner = new AirPlayScanner();
        airPlayScanner.startScan(mRemoteScanFound, this);

    } else if (RemoteSelectDialog.REMOTE_STOP_SCAN.equals(action)) {

        if (upnpRendererScanner != null)
            upnpRendererScanner.stopScan();
        if (chromeCastScanner != null)
            chromeCastScanner.stopScan();
        if (airPlayScanner != null)
            airPlayScanner.stopScan();
    } else if (RemoteSelectDialog.REMOTE_CONNECT.equals(action)) {
        int id = intent.getIntExtra(RemoteSelectDialog.REMOTE_ID, 0);
        if (upnpRendererScanner != null)
            upnpRendererScanner.stopScan();
        if (chromeCastScanner != null)
            chromeCastScanner.stopScan();
        IRemote rend = (id == 0) ? null : remoteObjects.get(id - 1);
        if (mPlayer.remote != rend) {
            Intent intentChange = new Intent(RemoteSelectDialog.REMOTE_STATE_CHANGE);
            intentChange.putExtra(RemoteSelectDialog.REMOTE_ID, id);
            intentChange.putExtra(RemoteSelectDialog.REMOTE_STATE, RemoteSelectDialog.REMOTE_CONNECTED);
            sendBroadcast(intentChange);
            mPlayer.setRemote(rend);

        }

    }
}

From source file:com.nest5.businessClient.Initialactivity.java

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    // ////Log.i(TAG, String.valueOf(redeemCoupon));
    if (scanResult != null) {

    }/*from  w  ww .j a v a2  s  . com*/

    if (requestCode == RETURN_FROM_DESIGN_TABLE) {
        String result = null;
        if (resultCode == RESULT_OK) {
            result = intent.getStringExtra(Setup.SAVED_TABLES);
        }
        if (resultCode == RESULT_CANCELED) {
            //Write your code if there's no result
        }
        if (result != null) {
            //load tables view and allow to make order for it
            showMesasLayout();
        }
    }

    if (requestCode == RETURN_FROM_OPENCLOSE_TABLE) {
        Table actual = null;
        int clientes = 0;
        if (resultCode == RESULT_OK) {
            actual = intent.getParcelableExtra("MIMESA");
            clientes = intent.getIntExtra("MIMESACLIENTES", 0);
            if (actual != null) {
                //load tables view and allow to make order for it
                currentTable = new CurrentTable<Table, Integer>(actual, clientes);
                statusText.setVisibility(View.VISIBLE);
                statusText.setText(actual.getName() + " con " + clientes + " Clientes.");
                //Log.i("MISPRUEBAS",currentTable.getTable().getName());
            }
        }
        if (resultCode == RESULT_CANCELED) {
            //Write your code if there's no result
        }

        if (resultCode == Setup.CLOSE_TABLE) {
            //Log.i("MISPRUEBAS","volviendo de cerrar mesa");
            actual = intent.getParcelableExtra("MIMESA");
            //tomar mesa que se cierra, preguntar si es cancelar venta o pagar, si es cancelar borra de opentables, de orders etc y si es pagar, pone en currentsale y abre dialogo pagar
            if (actual != null) {
                //Log.i("MISPRUEBAS","volviendo de cerrar mesa y no esta nulo");
                //load tables view and allow to make order for it
                currentTable = new CurrentTable<Table, Integer>(actual, 0);
                //Log.i("MISPRUEBAS","regreasa de dar clic en cerrar mesa con: "+currentTable.getTable().getName());
                statusText.setVisibility(View.VISIBLE);
                statusText.setText("Cerrando: " + actual.getName());
                openOtherWindow = true;
                openOtherWindowAction = OPEN_TABLE_ACTION;
            }
        }

    }

    // else continue with any other code you need in the method

    SharedPreferences defaultprefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    boolean layouttables = defaultprefs.getBoolean("arrange_tables", false);
    MenuItem tablelayouts = mMenu.findItem(R.id.layouttables);
    MenuItem showtables = mMenu.findItem(R.id.menu_show_tables);
    boolean change = false;
    if (tablelayouts.isVisible() != layouttables)
        change = true;
    tablelayouts.setVisible(layouttables);
    showtables.setVisible(layouttables);
    if (change) {
        invalidateOptionsMenu();
    }

}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    mWaitingForResult = false;/*from  w  w  w . java  2s .  c o m*/
    // The pattern used here is that a user PICKs a specific application,
    // which, depending on the target, might need to CREATE the actual
    // target.

    // For example, the user would PICK_SHORTCUT for "Music playlist", and
    // we
    // launch over to the Music app to actually CREATE_SHORTCUT.

    if (resultCode == RESULT_OK && mAddItemCellInfo != null) {
        switch (requestCode) {
        case REQUEST_PICK_APPLICATION:
            completeAddApplication(this, data, mAddItemCellInfo, !mDesktopLocked);
            break;
        case REQUEST_PICK_SHORTCUT:

            PersonaLog.e("data: ", "" + data);
            processShortcut(data, REQUEST_PICK_APPLICATION, REQUEST_CREATE_SHORTCUT);
            break;
        case REQUEST_CREATE_SHORTCUT:
            completeAddShortcut(data, mAddItemCellInfo, !mDesktopLocked);
            break;
        case REQUEST_PICK_LIVE_FOLDER:
            addLiveFolder(data);
            break;
        case REQUEST_CREATE_LIVE_FOLDER:
            completeAddLiveFolder(data, mAddItemCellInfo, !mDesktopLocked);
            break;
        case REQUEST_PICK_APPWIDGET:
            addAppWidget(data);
            break;
        case REQUEST_CREATE_APPWIDGET:
            completeAddAppWidget(data, mAddItemCellInfo, !mDesktopLocked);
            break;
        case REQUEST_PICK_ANYCUT:
            completeAddShortcut(data, mAddItemCellInfo, !mDesktopLocked);
            break;
        case REQUEST_EDIT_SHIRTCUT:
            completeEditShirtcut(data);
            break;
        // Trumobi changes for custom widget picker 290661
        case REQUEST_BIND_APPWIDGET:
            addAppWidget(data);
            break;
        }
    } else if (resultCode == RESULT_OK) {
        switch (requestCode) {
        case REQUEST_SHOW_APP_LIST: {
            mAllAppsGrid.updateAppGrp();
            showAllApps(true, null);
        }
            break;
        case REQUEST_EDIT_SHIRTCUT:
            completeEditShirtcut(data);
            break;
        }
    } else if ((requestCode == REQUEST_PICK_APPWIDGET || requestCode == REQUEST_CREATE_APPWIDGET)
            && resultCode == RESULT_CANCELED && data != null) {
        // Clean up the appWidgetId if we canceled
        int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
        if (appWidgetId != -1) {
            mAppWidgetHost.deleteAppWidgetId(appWidgetId);
        }
    }
}

From source file:com.rainmakerlabs.bleepsample.BleepService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "onStartCommand");
    String actionName = intent.getStringExtra("actionName");
    if (intent == null || intent.getExtras() == null) {//just removing these checks
    } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_PROCESS)
            && intent.getExtras().containsKey(BLEepService.INTENT_BLEEP_PASSED_LIST)) {
        ArrayList<Bleep> bleeps = (ArrayList<Bleep>) intent.getExtras()
                .getSerializable(BLEepService.INTENT_BLEEP_PASSED_LIST);
        for (final Bleep bleep : bleeps) {
            String msgType = bleep.getType();
            String atts = bleep.getAtts();
            try {
                JSONObject objMsg = new JSONObject(atts);
                //thisBleepService.addExtraLog(bleep, "FEEDBACK", "good");//use this when you want to send a custom log to BMS. for instance, you could display a feedback dialog, and ask users to give a rating, and BMS will help you collate the information. put this where necessary, it's just here for example
                Log.d(TAG, "Message Received of Type: " + msgType);
                if (msgType.equalsIgnoreCase("image")) {
                    final String strImgUrl = objMsg.optString(APIKeyDefineCommand.MSG_IMG);
                    final String adAspect = objMsg.optString(APIKeyDefineCommand.MSG_IMGASP);
                    String strImgMsgTemp = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    //putting the default message above would only work for missing key, not in case of empty string. empty string will prevent the notification, so fix below
                    if (strImgMsgTemp.equalsIgnoreCase(""))
                        strImgMsgTemp = "No Message";
                    final String strImgMsg = strImgMsgTemp;
                    if (checkIfClosed()) {
                        if (oldcodeon)
                            localNotification("", strImgMsg, 0);
                        continue;
                    }/*from  w  w w . ja va  2 s. c  o  m*/
                    if (MainActivity.adlib.get(strImgMsg) == null && !strImgMsg.equalsIgnoreCase("No Message"))
                        Log.d(TAG, "image url start download for key: " + strImgMsg + ", url = " + strImgUrl);
                    else {
                        Log.d(TAG, "Image exists, or no message, not downloading..., key: " + strImgMsg);
                        continue;
                    }

                    if (strImgMsg.equalsIgnoreCase("$28")) {
                        Log.d("Portal", "Image exists, loading from cache");
                        imgShow(BitmapFactory.decodeResource(getResources(), R.drawable.singtel), strImgMsg);
                        continue;
                    } else if (strImgMsg.equalsIgnoreCase("$4.50")) {
                        Log.d("Portal", "Heineken Image exists, loading from cache");
                        imgShow(BitmapFactory.decodeResource(getResources(), R.drawable.heineken), strImgMsg);
                        continue;
                    }

                    ShutterbugManager.getSharedImageManager(BleepActivity.currentBleepActivity)
                            .download(strImgUrl, new ShutterbugManagerListener() {
                                @Override
                                public void onImageSuccess(ShutterbugManager imageManager, Bitmap bitmap,
                                        String url) {
                                    Log.d(TAG, "image url end download " + strImgUrl);
                                    if (strImgUrl.equalsIgnoreCase(AdDialog.getCurrentAdUrl()))
                                        return;
                                    if (AdDialog.howManyAdDialogsShowing == 1) {
                                        AdDialog.closeOnlyAdDialog();
                                    }
                                    final Bitmap bitmap2 = bitmap;

                                    imgShow(bitmap, strImgMsg);

                                    if (oldcodeon) {
                                        BleepActivity.currentBleepActivity.runOnUiThread(new Runnable() {
                                            public void run() {
                                                if (BleepActivity.isBackground)
                                                    localNotification("", strImgMsg, 0);
                                                AdDialog.showAdsDialog(BleepActivity.currentBleepActivity,
                                                        bitmap2, strImgUrl, adAspect);
                                            }
                                        });
                                    }
                                }

                                @Override
                                public void onImageFailure(ShutterbugManager imageManager, String url) {
                                    thisBleepService.eraseTriggerLog(bleep);//to cancel trigger log when trigger is cancelled
                                }
                            });
                } else if (oldcodeon == false) {//don't run anything else
                } else if (msgType.equalsIgnoreCase("alert") && oldcodeon) {

                    // show alert message
                    if (checkIfClosed() || BleepActivity.isBackground) {
                        localNotification(objMsg.optString(APIKeyDefineCommand.MSG_TITLE),
                                objMsg.optString(APIKeyDefineCommand.MSG_CONTENT), 1);
                    } else {
                        showAlert(objMsg.optString(APIKeyDefineCommand.MSG_TITLE),
                                objMsg.optString(APIKeyDefineCommand.MSG_CONTENT));
                    }
                } else if (msgType.equalsIgnoreCase("launch")) {
                    String intentAction = objMsg.optString(APIKeyDefineCommand.MSG_APP_INTENT);
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_APP_URI);
                    String intentType = "";
                    String intentExtras = objMsg.optString(APIKeyDefineCommand.MSG_APP_EXTRAS);
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_CFM);
                    String failMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_FAIL);
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 2);
                } else if (msgType.equalsIgnoreCase("url")) {
                    String intentAction = Intent.ACTION_VIEW;
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    String intentType = "";
                    String intentExtras = "";
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_CFM);
                    String failMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_FAIL);
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 3);
                } else if (msgType.equalsIgnoreCase("webview")) {
                    String intentAction = Intent.ACTION_VIEW;
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    String intentType = "";
                    String intentExtras = "";
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    if (cfmMsg.equalsIgnoreCase(""))
                        cfmMsg = "View webpage?";
                    String failMsg = "";
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 4);
                } else if (msgType.equalsIgnoreCase("video")) {
                    String strVidUrl = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    Intent vidIntent = new Intent(this, VideoActivity.class);
                    vidIntent.putExtra("url", strVidUrl);
                    String notifMsg = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    if (notifMsg.equalsIgnoreCase(""))
                        notifMsg = "Play video?";
                    if (!checkIfClosed() && BleepActivity.isVideoActivityOpen) {
                        thisBleepService.eraseTriggerLog(bleep);//to cancel trigger log when trigger is cancelled
                    } else if (checkIfClosed() || BleepActivity.isBackground) {
                        vidIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        vidIntent.setAction(Intent.ACTION_MAIN);
                        vidIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                        localNotification("", notifMsg, vidIntent, "Video opening failed!", 5);
                    } else {
                        BleepActivity.currentBleepActivity.startActivity(vidIntent);
                    }
                } else if (msgType.equalsIgnoreCase("audio")) {
                    String url = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    mediaPlayer = new MediaPlayer();
                    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    try {
                        mediaPlayer.setDataSource(url);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    mediaPlayer.prepareAsync();
                    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                        @Override
                        public void onPrepared(MediaPlayer mp) {
                            mp.start();
                        }
                    });
                    mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                        @Override
                        public boolean onError(MediaPlayer mp, int what, int extra) {
                            return false;
                        }
                    });
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        //      } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_EXIT) && intent.getExtras().containsKey(BLEepService.INTENT_MSG_NAME)) {
        //         HashMap<String, Object> beaconOutInfo = (HashMap<String, Object>)intent.getSerializableExtra(BLEepService.INTENT_MSG_NAME);   
        //         //Log.d("debug!","debug! this beacon just went out "+beaconOutInfo.get("uuid")+" "+beaconOutInfo.get("major")+" "+beaconOutInfo.get("minor")+" "+beaconOutInfo.get("tag")+" "+beaconOutInfo.get("beaconID"));
    } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_STATE)
            && intent.getExtras().containsKey(BLEepService.INTENT_MSG_NAME)) {
        int beaconState = intent.getIntExtra(BLEepService.INTENT_MSG_NAME, 99);
    }

    return START_NOT_STICKY;
}