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.android.leanlauncher.LauncherTransitionable.java

private void handleActivityResult(final int requestCode, final int resultCode, final Intent data) {
    // Reset the startActivity waiting flag
    setWaitingForResult(false);/*from  ww  w  . j av  a  2s . c om*/
    final int pendingAddWidgetId = mPendingAddWidgetId;
    mPendingAddWidgetId = -1;

    if (requestCode == REQUEST_BIND_APPWIDGET) {
        final int appWidgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
        if (resultCode == RESULT_CANCELED) {
            completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
        } else if (resultCode == RESULT_OK) {
            addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo,
                    ON_ACTIVITY_RESULT_ANIMATION_DELAY);
        }
        return;
    } else if (requestCode == REQUEST_PICK_WALLPAPER) {
        if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
            mWorkspace.exitOverviewMode(false);
        }
        return;
    }

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

    final boolean workspaceLocked = isWorkspaceLocked();
    // 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);
            final Runnable onComplete = new Runnable() {
                @Override
                public void run() {
                    exitSpringLoadedDragModeDelayed(false, 0, null);
                }
            };
            if (workspaceLocked) {
                // No need to remove the empty screen if we're mid-binding, as the
                // the bind will not add the empty screen.
                mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
            }
        } else {
            if (!workspaceLocked) {
                completeTwoStageWidgetDrop(resultCode, appWidgetId);
            } else {
                sPendingAddItem = preparePendingAddArgs(requestCode, data, appWidgetId, mPendingAddInfo);
            }
        }
        return;
    }

    if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
        if (resultCode == RESULT_OK) {
            // Update the widget view.
            PendingAddArguments args = preparePendingAddArgs(requestCode, data, pendingAddWidgetId,
                    mPendingAddInfo);
            if (workspaceLocked) {
                sPendingAddItem = args;
            } else {
                completeAdd(args);
            }
        }
        // Leave the widget in the pending state if the user canceled the configure.
        return;
    }

    // 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 && mPendingAddInfo.container != ItemInfo.NO_ID) {
        final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1, mPendingAddInfo);
        if (isWorkspaceLocked()) {
            sPendingAddItem = args;
        } else {
            completeAdd(args);
        }
    }
    mDragLayer.clearAnimatedView();

}

From source file:com.spoiledmilk.ibikecph.map.MapActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == ProfileActivity.RESULT_USER_DELETED) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(IbikeApplication.getString("account_deleted"));
        builder.setPositiveButton(IbikeApplication.getString("close"), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();// ww w.  j av  a 2s. co  m
            }
        });
        dialog = builder.create();
        dialog.show();
    } else if (resultCode == SearchActivity.RESULT_SEARCH_ROUTE) {
        if (data != null) {
            Bundle extras = data.getExtras();
            Location start = Util.locationFromCoordinates(extras.getDouble("startLat"),
                    extras.getDouble("startLng"));
            Location endLocation = Util.locationFromCoordinates(extras.getDouble("endLat"),
                    extras.getDouble("endLng"));
            if (extras.containsKey("fromName"))
                source = extras.getString("fromName");
            else
                source = IbikeApplication.getString("current_position");
            if (extras.containsKey("toName"))
                destination = extras.getString("toName");
            else
                destination = "";
            new SMHttpRequest().getRoute(start, endLocation, null, MapActivity.this);
        }
    } else if (resultCode == SearchAutocompleteActivity.RESULT_AUTOTOCMPLETE_SET) {
        try {
            ((AddFavoriteFragment) getSupportFragmentManager().findFragmentById(R.id.leftContainer))
                    .onActivityResult(requestCode, resultCode, data);
        } catch (Exception e) {
            try {
                ((EditFavoriteFragment) getSupportFragmentManager().findFragmentById(R.id.leftContainer))
                        .onActivityResult(requestCode, resultCode, data);
            } catch (Exception ex) {
            }
        }
    } else if (resultCode == RESULT_RETURN_FROM_NAVIGATION) {
        btnSaveFavorite.setImageResource(R.drawable.drop_pin_selector);
        pinInfoLayout.setVisibility(View.GONE);
        mapFragment.pinView.setVisibility(View.GONE);
        if (mapFragment.pinB != null) {
            mapFragment.mapView.getOverlayManager().remove(mapFragment.pinB);
        }
        if (data != null && data.getExtras() != null && data.getExtras().containsKey("overlaysShown")) {
            refreshOverlays(data.getIntExtra("overlaysShown", 0));
        }
    }
}

From source file:com.androzic.MapActivity.java

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

    switch (requestCode) {
    case RESULT_MANAGE_WAYPOINTS: {
        application.waypointsOverlay.clearBitmapCache();
        application.saveWaypoints();/*from  www  . ja v a 2  s  .  c om*/
        break;
    }
    case RESULT_LOAD_WAYPOINTS: {
        if (resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            int count = extras.getInt("count");
            if (count > 0) {
                application.waypointsOverlay.clearBitmapCache();
            }
        }
        break;
    }
    case RESULT_SAVE_WAYPOINT: {
        if (resultCode == RESULT_OK) {
            application.waypointsOverlay.clearBitmapCache();
            application.saveWaypoints();
            if (data != null && data.hasExtra("index")
                    && PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
                            getString(R.string.pref_waypoint_visible),
                            getResources().getBoolean(R.bool.def_waypoint_visible)))
                application.ensureVisible(application.getWaypoint(data.getIntExtra("index", -1)));
        }
        break;
    }
    case RESULT_SAVE_WAYPOINTS:
        if (resultCode == RESULT_OK) {
            application.saveDefaultWaypoints();
        }
        break;
    case RESULT_MANAGE_TRACKS:
        for (Iterator<TrackOverlay> iter = application.fileTrackOverlays.iterator(); iter.hasNext();) {
            TrackOverlay to = iter.next();
            to.onTrackPropertiesChanged();
            if (to.getTrack().removed) {
                to.onBeforeDestroy();
                iter.remove();
            }
        }
        if (resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            int index = extras.getInt("index");
            startEditTrack(application.getTrack(index));
        }
        break;
    case RESULT_MANAGE_ROUTES: {
        for (Iterator<RouteOverlay> iter = application.routeOverlays.iterator(); iter.hasNext();) {
            RouteOverlay ro = iter.next();
            ro.onRoutePropertiesChanged();
            if (ro.getRoute().removed) {
                ro.onBeforeDestroy();
                iter.remove();
            }
        }
        if (resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            int index = extras.getInt("index");
            int dir = extras.getInt("dir");
            if (dir != 0)
                startService(
                        new Intent(this, NavigationService.class).setAction(NavigationService.NAVIGATE_ROUTE)
                                .putExtra(NavigationService.EXTRA_ROUTE_INDEX, index)
                                .putExtra(NavigationService.EXTRA_ROUTE_DIRECTION, dir));
            else
                startEditRoute(application.getRoute(index));
        }
        break;
    }
    case RESULT_EDIT_ROUTE:
        for (Iterator<RouteOverlay> iter = application.routeOverlays.iterator(); iter.hasNext();) {
            RouteOverlay ro = iter.next();
            if (ro.getRoute().editing)
                ro.onRoutePropertiesChanged();
        }
        break;
    case RESULT_LOAD_MAP:
        if (resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            final int id = extras.getInt("id");
            synchronized (map) {
                application.loadMap(id);
                map.suspendBestMap();
                setFollowing(false);
                map.updateMapInfo();
                map.update();
            }
        }
        break;
    case RESULT_LOAD_MAP_ATPOSITION:
        if (resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            final int id = extras.getInt("id");
            if (application.selectMap(id)) {
                map.suspendBestMap();
                map.updateMapInfo();
                map.update();
            } else {
                map.update();
            }
        }
        break;
    }
}

From source file:com.google.example.eightbitartist.DrawingActivity.java

@Override
public void onActivityResult(int request, int response, Intent data) {
    super.onActivityResult(request, response, data);
    Log.i(TAG, "onActivityResult: code = " + request + ", response = " + response);

    // Coming back from resolving a sign-in request
    if (request == RC_SIGN_IN) {
        mSignInClicked = false;//w  ww .  j a va 2s . c  om
        mResolvingConnectionFailure = false;
        if (response == RESULT_OK) {
            mGoogleApiClient.connect();
        } else {
            BaseGameUtils.showActivityResultError(this, request, response, R.string.sign_in_failed);
        }
    }

    // Coming back from a RealTime Multiplayer waiting room
    if (request == RC_WAITING_ROOM) {
        dismissSpinner();

        Room room = data.getParcelableExtra(Multiplayer.EXTRA_ROOM);
        if (response == RESULT_OK) {
            Log.d(TAG, "Waiting Room: Success");
            mRoom = room;
            startMatch();
        } else if (response == RESULT_CANCELED) {
            Log.d(TAG, "Waiting Room: Canceled");
            leaveRoom();
        } else if (response == GamesActivityResultCodes.RESULT_LEFT_ROOM) {
            Log.d(TAG, "Waiting Room: Left Room");
            leaveRoom();
        } else if (response == GamesActivityResultCodes.RESULT_INVALID_ROOM) {
            Log.d(TAG, "Waiting Room: Invalid Room");
            leaveRoom();
        }
    }

    // We are coming back from the player selection UI, in preparation to start a match.
    if (request == RC_SELECT_PLAYERS) {
        if (response != Activity.RESULT_OK) {
            // user canceled
            Log.d(TAG, "onActivityResult: user canceled player selection.");
            return;
        }

        // Create a basic room configuration
        RoomConfig.Builder roomConfigBuilder = RoomConfig.builder(this).setMessageReceivedListener(this)
                .setRoomStatusUpdateListener(this);

        // Set the auto match criteria
        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) {
            Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minAutoMatchPlayers,
                    maxAutoMatchPlayers, 0);
            roomConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
        }

        // Set the invitees
        final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);
        if (invitees != null && invitees.size() > 0) {
            roomConfigBuilder.addPlayersToInvite(invitees);
        }

        // Build the room and start the match
        showSpinner();
        Games.RealTimeMultiplayer.create(mGoogleApiClient, roomConfigBuilder.build());
    }
}

From source file:com.mobilyzer.MeasurementScheduler.java

@Override
public void onCreate() {
    Logger.d("MeasurementScheduler -> onCreate called");
    PhoneUtils.setGlobalContext(this.getApplicationContext());

    phoneUtils = PhoneUtils.getPhoneUtils();
    phoneUtils.registerSignalStrengthListener();

    this.measurementExecutor = Executors.newSingleThreadExecutor();
    this.mainQueue = new PriorityBlockingQueue<MeasurementTask>(Config.MAX_TASK_QUEUE_SIZE,
            new TaskComparator());
    this.waitingTasksQueue = new PriorityBlockingQueue<MeasurementTask>(Config.MAX_TASK_QUEUE_SIZE,
            new WaitingTasksComparator());
    this.pendingTasks = new ConcurrentHashMap<MeasurementTask, Future<MeasurementResult[]>>();
    this.tasksStatus = new ConcurrentHashMap<String, MeasurementScheduler.TaskStatus>();
    this.alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    this.resourceCapManager = new ResourceCapManager(Config.DEFAULT_BATTERY_THRESH_PRECENT, this);

    this.serverTasks = new HashMap<String, Date>();
    // this.currentSchedule = new HashMap<String, MeasurementTask>();

    this.idToClientKey = new ConcurrentHashMap<String, String>();

    messenger = new Messenger(new APIRequestHandler(this));

    gcmManager = new GCMManager(this.getApplicationContext());

    this.setCurrentTask(null);
    this.setCurrentTaskStartTime(null);

    this.checkin = new Checkin(this);
    this.checkinRetryIntervalSec = Config.MIN_CHECKIN_RETRY_INTERVAL_SEC;
    this.checkinRetryCnt = 0;
    this.checkinTask = new CheckinTask();

    this.batteryThreshold = -1;
    this.checkinIntervalSec = -1;
    this.dataUsageProfile = DataUsageProfile.NOTASSIGNED;

    //    loadSchedulerState();//TODO(ASHKAN)

    // Register activity specific BroadcastReceiver here
    IntentFilter filter = new IntentFilter();
    filter.addAction(UpdateIntent.CHECKIN_ACTION);
    filter.addAction(UpdateIntent.CHECKIN_RETRY_ACTION);
    filter.addAction(UpdateIntent.MEASUREMENT_ACTION);
    filter.addAction(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION);
    filter.addAction(UpdateIntent.GCM_MEASUREMENT_ACTION);
    filter.addAction(UpdateIntent.PLT_MEASUREMENT_ACTION);

    broadcastReceiver = new BroadcastReceiver() {

        @Override/*from  w  w w  . ja  v  a2s . c o m*/
        public void onReceive(Context context, Intent intent) {
            Logger.d(intent.getAction() + " RECEIVED");
            if (intent.getAction().equals(UpdateIntent.MEASUREMENT_ACTION)) {
                handleMeasurement();

            } else if (intent.getAction().equals(UpdateIntent.GCM_MEASUREMENT_ACTION)) {
                try {
                    JSONObject json = new JSONObject(
                            intent.getExtras().getString(UpdateIntent.MEASUREMENT_TASK_PAYLOAD));
                    Logger.d("MeasurementScheduler -> GCMManager: json task Value is " + json);
                    if (json != null && MeasurementTask.getMeasurementTypes().contains(json.get("type"))) {

                        try {
                            MeasurementTask task = MeasurementJsonConvertor.makeMeasurementTaskFromJson(json);
                            task.getDescription().priority = MeasurementTask.GCM_PRIORITY;
                            task.getDescription().startTime = new Date(System.currentTimeMillis() - 1000);
                            task.getDescription().endTime = new Date(System.currentTimeMillis() + (600 * 1000));
                            task.generateTaskID();
                            task.getDescription().key = Config.SERVER_TASK_CLIENT_KEY;
                            submitTask(task);
                        } catch (IllegalArgumentException e) {
                            Logger.w("MeasurementScheduler -> GCM : Could not create task from JSON: " + e);
                        }
                    }

                } catch (JSONException e) {
                    Logger.e(
                            "MeasurementSchedule -> GCMManager : Got exception during converting GCM json to MeasurementTask",
                            e);
                }

            } else if (intent.getAction().equals(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION)) {
                String taskid = intent.getStringExtra(UpdateIntent.TASKID_PAYLOAD);
                String taskKey = intent.getStringExtra(UpdateIntent.CLIENTKEY_PAYLOAD);
                int priority = intent.getIntExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD,
                        MeasurementTask.INVALID_PRIORITY);

                Logger.e(
                        intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD) + " " + taskid + " " + taskKey);
                if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD).equals(Config.TASK_FINISHED)) {
                    tasksStatus.put(taskid, TaskStatus.FINISHED);
                    Parcelable[] results = intent.getParcelableArrayExtra(UpdateIntent.RESULT_PAYLOAD);
                    if (results != null) {
                        sendResultToClient(results, priority, taskKey, taskid);

                        for (Object obj : results) {
                            try {
                                MeasurementResult result = (MeasurementResult) obj;
                                /**
                                 * Nullify the additional parameters in MeasurmentDesc, or the results won't be
                                 * accepted by GAE server
                                 */
                                result.getMeasurementDesc().parameters = null;
                                String jsonResult = MeasurementJsonConvertor.encodeToJson(result).toString();
                                saveResultToFile(jsonResult);
                            } catch (JSONException e) {
                                Logger.e("Error converting results to json format", e);
                            }
                        }
                    }
                    handleMeasurement();
                } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD).equals(Config.TASK_PAUSED)) {
                    tasksStatus.put(taskid, TaskStatus.PAUSED);
                } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD)
                        .equals(Config.TASK_STOPPED)) {
                    tasksStatus.put(taskid, TaskStatus.SCHEDULED);
                } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD)
                        .equals(Config.TASK_CANCELED)) {
                    tasksStatus.put(taskid, TaskStatus.CANCELLED);
                    Parcelable[] results = intent.getParcelableArrayExtra(UpdateIntent.RESULT_PAYLOAD);
                    if (results != null) {
                        sendResultToClient(results, priority, taskKey, taskid);
                    }
                } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD)
                        .equals(Config.TASK_STARTED)) {
                    tasksStatus.put(taskid, TaskStatus.RUNNING);
                } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD)
                        .equals(Config.TASK_RESUMED)) {
                    tasksStatus.put(taskid, TaskStatus.RUNNING);
                }
            } else if (intent.getAction().equals(UpdateIntent.CHECKIN_ACTION)
                    || intent.getAction().equals(UpdateIntent.CHECKIN_RETRY_ACTION)) {
                Logger.d("Checkin intent received");
                handleCheckin();
            }
        }
    };
    this.registerReceiver(broadcastReceiver, filter);
}

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.j  av a2  s  . co 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.kaichaohulian.baocms.ecdemo.ui.chatting.ChattingFragment.java

/**
 * ???/*from  www  . ja  va  2  s .c  o  m*/
 */
private void handlesendRedPacketMessage(Intent data) {
    //TODO
    data = RedpacketManager.redpacketCacheData;

    //        String greetings = data.getStringExtra(RedPacketConstant.EXTRA_RED_PACKET_GREETING);
    String greetings = RedpacketManager.greeting;
    int moneyID = data.getIntExtra(RedPacketConstant.EXTRA_RED_PACKET_ID, -1);
    String specialReceiveId = data.getStringExtra(RedPacketConstant.EXTRA_RED_PACKET_RECEIVER_ID);
    String redPacketType = data.getStringExtra(RedPacketConstant.EXTRA_RED_PACKET_TYPE);

    //        String greetings = RedpacketManager.greeting;
    //        String moneyID = RedpacketManager.redid + "";
    //        String specialReceiveId = RedpacketManager.specialReceiveId;
    //        String redPacketType = RedpacketManager.type+"";

    String text = "[]" + greetings;

    com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
    jsonObject.put(RedPacketConstant.MESSAGE_ATTR_IS_RED_PACKET_MESSAGE, true);//??
    jsonObject.put(RedPacketConstant.EXTRA_SPONSOR_NAME, "");//sponsor name
    jsonObject.put(RedPacketConstant.EXTRA_RED_PACKET_GREETING, greetings);//??
    jsonObject.put(RedPacketConstant.EXTRA_RED_PACKET_ID, moneyID);//id
    jsonObject.put(RedPacketConstant.MESSAGE_ATTR_RED_PACKET_TYPE, redPacketType);//?
    jsonObject.put(RedPacketConstant.MESSAGE_ATTR_SPECIAL_RECEIVER_ID, specialReceiveId);//
    // ??ECMessage
    ECMessage msg = ECMessage.createECMessage(ECMessage.Type.TXT);
    // ?
    msg.setTo(mRecipients);
    msg.setUserData(jsonObject.toJSONString());
    // ??
    ECTextMessageBody msgBody = new ECTextMessageBody(text.toString());
    msg.setBody(msgBody);
    String[] at = mChattingFooter.getAtSomeBody();
    msgBody.setAtMembers(at);
    mChattingFooter.clearSomeBody();
    try {
        // ????
        long rowId = -1;
        if (mCustomerService) {
            rowId = CustomerServiceHelper.sendMCMessage(msg);
        } else {
            rowId = IMChattingHelper.sendECMessage(msg);
        }
        // 
        msg.setId(rowId);
        notifyIMessageListView(msg);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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 w  w  . j  a  va 2 s  .  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:cm.aptoide.com.facebook.android.Facebook.java

/**
 * IMPORTANT: This method must be invoked at the top of the calling
 * activity's onActivityResult() function or Facebook authentication will
 * not function properly!/*from  w  w w. jav a 2s .c  o m*/
 *
 * If your calling activity does not currently implement onActivityResult(),
 * you must implement it and include a call to this method if you intend to
 * use the authorize() method in this SDK.
 *
 * For more information, see
 * http://developer.android.com/reference/android/app/
 *   Activity.html#onActivityResult(int, int, android.content.Intent)
 */
public void authorizeCallback(int requestCode, int resultCode, Intent data) {
    if (requestCode == mAuthActivityCode) {

        // Successfully redirected.
        if (resultCode == Activity.RESULT_OK) {

            // Check OAuth 2.0/2.10 error code.
            String error = data.getStringExtra("error");
            if (error == null) {
                error = data.getStringExtra("error_type");
            }

            // A Facebook error occurred.
            if (error != null) {
                if (error.equals(SINGLE_SIGN_ON_DISABLED) || error.equals("AndroidAuthKillSwitchException")) {
                    Util.logd("Facebook-authorize",
                            "Hosted auth currently " + "disabled. Retrying dialog auth...");
                    startDialogAuth(mAuthActivity, mAuthPermissions);
                } else if (error.equals("access_denied") || error.equals("OAuthAccessDeniedException")) {
                    Util.logd("Facebook-authorize", "Login canceled by user.");
                    mAuthDialogListener.onCancel();
                } else {
                    String description = data.getStringExtra("error_description");
                    if (description != null) {
                        error = error + ":" + description;
                    }
                    Util.logd("Facebook-authorize", "Login failed: " + error);
                    mAuthDialogListener.onFacebookError(new FacebookError(error));
                }

                // No errors.
            } else {
                setAccessToken(data.getStringExtra(TOKEN));
                setAccessExpiresIn(data.getStringExtra(EXPIRES));
                if (isSessionValid()) {
                    Util.logd("Facebook-authorize", "Login Success! access_token=" + getAccessToken()
                            + " expires=" + getAccessExpires());
                    mAuthDialogListener.onComplete(data.getExtras());
                } else {
                    mAuthDialogListener.onFacebookError(new FacebookError("Failed to receive access token."));
                }
            }

            // An error occurred before we could be redirected.
        } else if (resultCode == Activity.RESULT_CANCELED) {

            // An Android error occured.
            if (data != null) {
                Util.logd("Facebook-authorize", "Login failed: " + data.getStringExtra("error"));
                mAuthDialogListener.onError(new DialogError(data.getStringExtra("error"),
                        data.getIntExtra("error_code", -1), data.getStringExtra("failing_url")));

                // User pressed the 'back' button.
            } else {
                Util.logd("Facebook-authorize", "Login canceled by user.");
                mAuthDialogListener.onCancel();
            }
        }
    }
}