List of usage examples for android.content Intent getSerializableExtra
public Serializable getSerializableExtra(String name)
From source file:org.mdc.chess.MDChess.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_SETTINGS: handlePrefsChange();/* w w w .j a v a2s . com*/ break; case RESULT_EDITBOARD: if (resultCode == RESULT_OK) { try { String fen = data.getAction(); ctrl.setFENOrPGN(fen); setBoardFlip(false); } catch (ChessParseError e) { Log.d("Exception", e.toString()); } } break; case RESULT_LOAD_PGN: if (resultCode == RESULT_OK) { try { String pgn = data.getAction(); int modeNr = ctrl.getGameMode().getModeNr(); if ((modeNr != GameMode.ANALYSIS) && (modeNr != GameMode.EDIT_GAME)) { newGameMode(); } ctrl.setFENOrPGN(pgn); setBoardFlip(true); } catch (ChessParseError e) { Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show(); } } break; case RESULT_SELECT_SCID: if (resultCode == RESULT_OK) { String pathName = data.getAction(); if (pathName != null) { Editor editor = settings.edit(); editor.putString("currentScidFile", pathName); editor.putInt("currFT", FT_SCID); editor.apply(); Intent i = new Intent(MDChess.this, LoadScid.class); i.setAction("org.mdc.chess.loadScid"); i.putExtra("org.mdc.chess.pathname", pathName); startActivityForResult(i, RESULT_LOAD_PGN); } } break; case RESULT_OI_PGN_LOAD: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) { loadPGNFromFile(pathName); } } break; case RESULT_OI_PGN_SAVE: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) { if ((pathName.length() > 0) && !pathName.contains(".")) { pathName += ".pgn"; } savePGNToFile(pathName); } } break; case RESULT_OI_FEN_LOAD: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) { loadFENFromFile(pathName); } } break; case RESULT_GET_FEN: if (resultCode == RESULT_OK) { String fen = data.getStringExtra(Intent.EXTRA_TEXT); if (fen == null) { String pathName = getFilePathFromUri(data.getData()); loadFENFromFile(pathName); } setFenHelper(fen); } break; case RESULT_LOAD_FEN: if (resultCode == RESULT_OK) { String fen = data.getAction(); setFenHelper(fen); } break; case RESULT_EDITOPTIONS: if (resultCode == RESULT_OK) { @SuppressWarnings("unchecked") Map<String, String> uciOpts = (Map<String, String>) data .getSerializableExtra("org.mdc.chess.ucioptions"); ctrl.setEngineUCIOptions(uciOpts); } break; } }
From source file:org.petero.droidfish.DroidFish.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_SETTINGS: handlePrefsChange();/*from w w w .j a va 2 s . co m*/ break; case RESULT_EDITBOARD: if (resultCode == RESULT_OK) { try { String fen = data.getAction(); ctrl.setFENOrPGN(fen); setBoardFlip(false); } catch (ChessParseError e) { } } break; case RESULT_LOAD_PGN: if (resultCode == RESULT_OK) { try { String pgn = data.getAction(); int modeNr = ctrl.getGameMode().getModeNr(); if ((modeNr != GameMode.ANALYSIS) && (modeNr != GameMode.EDIT_GAME)) newGameMode(GameMode.EDIT_GAME); ctrl.setFENOrPGN(pgn); setBoardFlip(true); } catch (ChessParseError e) { Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show(); } } break; case RESULT_SELECT_SCID: if (resultCode == RESULT_OK) { String pathName = data.getAction(); if (pathName != null) { Editor editor = settings.edit(); editor.putString("currentScidFile", pathName); editor.putInt("currFT", FT_SCID); editor.commit(); Intent i = new Intent(DroidFish.this, LoadScid.class); i.setAction("org.petero.droidfish.loadScid"); i.putExtra("org.petero.droidfish.pathname", pathName); startActivityForResult(i, RESULT_LOAD_PGN); } } break; case RESULT_OI_PGN_LOAD: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) loadPGNFromFile(pathName); } break; case RESULT_OI_PGN_SAVE: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) { if ((pathName.length() > 0) && !pathName.contains(".")) pathName += ".pgn"; savePGNToFile(pathName, false); } } break; case RESULT_OI_FEN_LOAD: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) loadFENFromFile(pathName); } break; case RESULT_GET_FEN: if (resultCode == RESULT_OK) { String fen = data.getStringExtra(Intent.EXTRA_TEXT); if (fen == null) { String pathName = getFilePathFromUri(data.getData()); loadFENFromFile(pathName); } setFenHelper(fen); } break; case RESULT_LOAD_FEN: if (resultCode == RESULT_OK) { String fen = data.getAction(); setFenHelper(fen); } break; case RESULT_EDITOPTIONS: if (resultCode == RESULT_OK) { @SuppressWarnings("unchecked") Map<String, String> uciOpts = (Map<String, String>) data .getSerializableExtra("org.petero.droidfish.ucioptions"); ctrl.setEngineUCIOptions(uciOpts); } break; } }
From source file:com.ibuildapp.romanblack.FanWallPlugin.FanWallPlugin.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == SHOW_PHOTOLIST_ACTIVITY || requestCode == SHOW_IMAGES_ACTIVITY) { messages.clear();/*from w ww .j a v a2 s .c o m*/ refreshMessages(); } else if (requestCode == GPS_SETTINGS_ACTIVITY) { if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, false); enableGpsCheckbox.setChecked(false); } else { enableGpsCheckbox.setChecked(true); Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, true); } } else if (requestCode == FACEBOOK_AUTHORIZATION_ACTIVITY) { if (resultCode == RESULT_OK) shareFacebook(); else if (resultCode == RESULT_CANCELED) Toast.makeText(FanWallPlugin.this, getResources().getString(R.string.alert_facebook_auth_error), Toast.LENGTH_SHORT).show(); } else if (requestCode == TWITTER_AUTHORIZATION_ACTIVITY) { if (resultCode == RESULT_OK) shareTwitter(); else if (resultCode == RESULT_CANCELED) Toast.makeText(FanWallPlugin.this, getResources().getString(R.string.alert_twitter_auth_error), Toast.LENGTH_SHORT).show(); } else if (requestCode == TWITTER_PUBLISH_ACTIVITY) { if (resultCode == RESULT_OK) { // increment sharing count new Thread(new Runnable() { @Override public void run() { if (postIdToShare != -1) { IncrementSharingStatus status = Statics.incrementSharing(Long.toString(postIdToShare)); Log.e(TAG, "Status = " + status.toString()); if (status.status_code == 0) { FanWallMessage resMsg = null; for (FanWallMessage msg : messages) { if (msg.getId() == postIdToShare) { msg.setSharingCount(msg.getSharingCount() + 1); resMsg = msg; break; } } if (resMsg != null) handler.sendEmptyMessage(SHOW_MESSAGES); } } } }).start(); Toast.makeText(FanWallPlugin.this, getResources().getString(R.string.directoryplugin_twitter_posted_success), Toast.LENGTH_LONG).show(); } else if (resultCode == RESULT_CANCELED) { Toast.makeText(FanWallPlugin.this, getResources().getString(R.string.directoryplugin_twitter_posted_error), Toast.LENGTH_LONG) .show(); } } else if (requestCode == FACEBOOK_PUBLISH_ACTIVITY) { if (resultCode == RESULT_OK) { // increment sharing count new Thread(new Runnable() { @Override public void run() { if (postIdToShare != -1) { IncrementSharingStatus status = Statics.incrementSharing(Long.toString(postIdToShare)); Log.e(TAG, "Status = " + status.toString()); if (status.status_code == 0) { FanWallMessage resMsg = null; for (FanWallMessage msg : messages) { if (msg.getId() == postIdToShare) { msg.setSharingCount(msg.getSharingCount() + 1); resMsg = msg; break; } } if (resMsg != null) handler.sendEmptyMessage(SHOW_MESSAGES); } } } }).start(); Toast.makeText(FanWallPlugin.this, getResources().getString(R.string.directoryplugin_facebook_posted_success), Toast.LENGTH_LONG).show(); } else if (resultCode == RESULT_CANCELED) { Toast.makeText(FanWallPlugin.this, getResources().getString(R.string.directoryplugin_facebook_posted_error), Toast.LENGTH_LONG) .show(); } } else if (requestCode == FACEBOOK_LIKE_AUTH) { if (resultCode == RESULT_OK) { if (!TextUtils.isEmpty(urlToLike)) { new Thread(new Runnable() { @Override public void run() { try { if (FacebookAuthorizationActivity.like(urlToLike)) refreshTop(); } catch (FacebookAuthorizationActivity.FacebookNotAuthorizedException e) { e.printStackTrace(); } catch (FacebookAuthorizationActivity.FacebookAlreadyLiked facebookAlreadyLiked) { refreshTop(); } } }).start(); } } } else if (requestCode == AUTHORIZATION_ACTIVITY) { if (resultCode == RESULT_OK) { if (action == ACTIONS.SEND_MESSAGE) { startActivityForResult(actionIntent, SEND_MESSAGE_ACTIVITY); } else if (action == ACTIONS.SEND_MESSAGE_FROM_WALL) { showProgressDialog(); new Thread(new Runnable() { @Override public void run() { FanWallMessage msg = Statics.postMessage(editMsg.getText().toString(), imagePath, 0, 0, Prefs.with(getApplicationContext()).getBoolean(Prefs.KEY_GPS, false)); if (msg != null) { imagePath = ""; handler.sendEmptyMessage(CLEAR_MSG_TEXT); if (messages.size() == 0) refreshMessages(); else refreshTop(); } else handler.sendEmptyMessage(HIDE_PROGRESS_DIALOG); } }).start(); } } } else if (requestCode == SIGN_UP_ACTIVITY) { if (resultCode == RESULT_OK) { if (action == ACTIONS.SEND_MESSAGE) { startActivityForResult(actionIntent, SEND_MESSAGE_ACTIVITY); } } } else if (requestCode == MESSAGE_VIEW_ACTIVITY) { FanWallMessage msg = (FanWallMessage) data.getSerializableExtra("message"); if (msg != null) { for (FanWallMessage s : messages) { if (s.getId() == msg.getId()) { s.setTotalComments(msg.getTotalComments()); break; } } } if (Prefs.with(FanWallPlugin.this).getBoolean(Prefs.KEY_GPS, false)) enableGpsCheckbox.setChecked(true); else enableGpsCheckbox.setChecked(false); refreshMessages(); handler.sendEmptyMessage(SHOW_MESSAGES); } else if (requestCode == IMAGE_VIEW_ACTIVITY) { } else if (requestCode == SEND_MESSAGE_ACTIVITY) { if (resultCode == RESULT_OK) { final FanWallMessage tmpMessage = (FanWallMessage) data.getSerializableExtra("message"); new Thread(new Runnable() { public void run() { boolean stop = false; ArrayList<FanWallMessage> tmpTmpMessages = new ArrayList<FanWallMessage>(); while (!stop) { ArrayList<FanWallMessage> tmpMessages = new ArrayList<FanWallMessage>(); if (messages.isEmpty()) { tmpMessages = JSONParser.parseMessagesUrl( Statics.BASE_URL + "/" + com.appbuilder.sdk.android.Statics.appId + "/" + Statics.MODULE_ID + "/" + "0" + "/" + "0" + "/" + "0" + "/" + "0" + "/" + com.appbuilder.sdk.android.Statics.appId + "/" + com.appbuilder.sdk.android.Statics.appToken); } else { tmpMessages = JSONParser.parseMessagesUrl(Statics.BASE_URL + "/" + com.appbuilder.sdk.android.Statics.appId + "/" + Statics.MODULE_ID + "/" + "0" + "/" + "0" + "/" + messages.get(0).getId() + "/" + "0" + "/" + com.appbuilder.sdk.android.Statics.appId + "/" + com.appbuilder.sdk.android.Statics.appToken); } for (int i = 0; i < tmpMessages.size(); i++) { FanWallMessage msg = tmpMessages.get(tmpMessages.size() - i - 1); tmpTmpMessages.add(msg); if (msg.getId() == tmpMessage.getId()) { stop = true; break; } } } Collections.reverse(tmpTmpMessages); tmpTmpMessages.addAll(messages); messages.clear(); messages.addAll(tmpTmpMessages); if (messages.isEmpty()) { handler.sendEmptyMessage(SHOW_NO_MESSAGES); } else { handler.sendEmptyMessage(SHOW_MESSAGES); } } }).start(); } } else if (requestCode == TAKE_A_PICTURE_ACTIVITY) { if (resultCode == RESULT_OK) { imagePath = data.getStringExtra("imagePath"); if (TextUtils.isEmpty(imagePath)) return; chooserHolder.setVisibility(View.GONE); setImage(); } } else if (requestCode == PICK_IMAGE_ACTIVITY) { if (resultCode == RESULT_OK) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); imagePath = filePath; if (TextUtils.isEmpty(imagePath)) return; if (imagePath.startsWith("http")) { Toast.makeText(this, R.string.romanblack_fanwall_alert_cant_select_image, Toast.LENGTH_LONG) .show(); return; } chooserHolder.setVisibility(View.GONE); setImage(); } } }
From source file:org.restcomm.android.olympus.CallActivity.java
private void handleCall(Intent intent) { if (intent.getAction().equals(RCDevice.ACTION_RESUME_CALL)) { String text;//from w w w . ja v a 2 s . co m connection = device.getLiveConnection(); if (connection != null) { connection.setConnectionListener(this); if (connection.isIncoming()) { // Incoming if (connection.getRemoteMediaType() == AUDIO_VIDEO) { text = "Video Call from "; } else { text = "Audio Call from "; } } else { // Outgoing if (connection.getLocalMediaType() == AUDIO_VIDEO) { text = "Video Calling "; } else { text = "Audio Calling "; } } lblCall.setText(text + connection.getPeer().replaceAll(".*?sip:", "").replaceAll("@.*$", "")); lblStatus.setText("Connected"); connection.reattachVideo((PercentFrameLayout) findViewById(R.id.local_video_layout), (PercentFrameLayout) findViewById(R.id.remote_video_layout)); // Get the time when we paused call so that now that we are resuming we can show correct time long difference = (System.currentTimeMillis() - prefs.getLong(LIVE_CALL_PAUSE_TIME, 0)); int duration = (int) (difference / 1000); startTimer(duration); // resume UI state muteAudio = connection.isAudioMuted(); muteVideo = connection.isVideoMuted(); if (connection.isAudioMuted()) { btnMuteAudio.setImageResource(R.drawable.audio_muted); } if (connection.getLocalMediaType() != AUDIO_VIDEO) { btnMuteVideo.setEnabled(false); btnMuteVideo.setColorFilter( Color.parseColor(getString(R.string.string_color_filter_video_disabled))); } else { if (connection.isVideoMuted()) { btnMuteVideo.setImageResource(R.drawable.video_muted); } } // Hide answering buttons and show mute & keypad btnAnswer.setVisibility(View.INVISIBLE); btnAnswerAudio.setVisibility(View.INVISIBLE); btnMuteAudio.setVisibility(View.VISIBLE); btnMuteVideo.setVisibility(View.VISIBLE); btnKeypad.setVisibility(View.VISIBLE); lblTimer.setVisibility(View.VISIBLE); } else { showOkAlert("Resume ongoing call", "No call to resume"); } return; } if (connection != null) { return; } isVideo = intent.getBooleanExtra(RCDevice.EXTRA_VIDEO_ENABLED, false); if (intent.getAction().equals(RCDevice.ACTION_OUTGOING_CALL)) { String text; if (isVideo) { text = "Video Calling "; } else { text = "Audio Calling "; } lblCall.setText(text + intent.getStringExtra(RCDevice.EXTRA_DID).replaceAll(".*?sip:", "").replaceAll("@.*$", "")); lblStatus.setText("Initiating Call..."); connectParams = new HashMap<String, Object>(); connectParams.put(RCConnection.ParameterKeys.CONNECTION_PEER, intent.getStringExtra(RCDevice.EXTRA_DID)); connectParams.put(RCConnection.ParameterKeys.CONNECTION_VIDEO_ENABLED, intent.getBooleanExtra(RCDevice.EXTRA_VIDEO_ENABLED, false)); connectParams.put(RCConnection.ParameterKeys.CONNECTION_LOCAL_VIDEO, (PercentFrameLayout) findViewById(R.id.local_video_layout)); connectParams.put(RCConnection.ParameterKeys.CONNECTION_REMOTE_VIDEO, (PercentFrameLayout) findViewById(R.id.remote_video_layout)); // by default we use VP8 for video as it tends to be more adopted, but you can override that and specify VP9 or H264 as follows: connectParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_AUDIO_CODEC, audioCodecString2Enum( prefs.getString(RCConnection.ParameterKeys.CONNECTION_PREFERRED_AUDIO_CODEC, ""))); connectParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_CODEC, videoCodecString2Enum( prefs.getString(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_CODEC, ""))); connectParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_RESOLUTION, resolutionString2Enum( prefs.getString(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_RESOLUTION, ""))); connectParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_FRAME_RATE, frameRateString2Enum( prefs.getString(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_FRAME_RATE, ""))); // Needed until we implement Trickle ICE connectParams.put(RCConnection.ParameterKeys.DEBUG_CONNECTION_CANDIDATE_TIMEOUT, Integer .parseInt(prefs.getString(RCConnection.ParameterKeys.DEBUG_CONNECTION_CANDIDATE_TIMEOUT, "0"))); // Here's how to set manually //connectParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_CODEC, RCConnection.VideoCodec.VIDEO_CODEC_VP8); //connectParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_RESOLUTION, RCConnection.VideoResolution.RESOLUTION_HD_1280x720); //connectParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_FRAME_RATE, RCConnection.VideoFrameRate.FPS_DEFAULT); // *** if you want to add custom SIP headers, please uncomment this //HashMap<String, String> sipHeaders = new HashMap<>(); //sipHeaders.put("X-SIP-Header1", "Value1"); //connectParams.put(RCConnection.ParameterKeys.CONNECTION_CUSTOM_SIP_HEADERS, sipHeaders); // save peer to preferences, we might need it for potential bug report (check BugReportActivity) SharedPreferences.Editor editor = prefs.edit(); editor.putString(BugReportActivity.MOST_RECENT_CALL_PEER, intent.getStringExtra(RCDevice.EXTRA_DID)); editor.apply(); handlePermissions(isVideo); } if (intent.getAction().equals(RCDevice.ACTION_INCOMING_CALL) || intent.getAction().equals(RCDevice.ACTION_INCOMING_CALL_ANSWER_AUDIO) || intent.getAction().equals(RCDevice.ACTION_INCOMING_CALL_ANSWER_VIDEO)) { String text; if (isVideo) { text = "Video Call from "; } else { text = "Audio Call from "; } lblCall.setText(text + intent.getStringExtra(RCDevice.EXTRA_DID).replaceAll(".*?sip:", "").replaceAll("@.*$", "")); lblStatus.setText("Call Received..."); //callOutgoing = false; pendingConnection = device.getPendingConnection(); // There is chance that pendingConnection is null if call activity is reopened after call has failed // but used hasn't pressed ok to the dialog so that the call activity is destroyed. Let's guard for this if (pendingConnection != null) { pendingConnection.setConnectionListener(this); // the number from which we got the call String incomingCallDid = intent.getStringExtra(RCDevice.EXTRA_DID); HashMap<String, String> customHeaders = (HashMap<String, String>) intent .getSerializableExtra(RCDevice.EXTRA_CUSTOM_HEADERS); if (customHeaders != null) { Log.i(TAG, "Got custom headers in incoming call: " + customHeaders.toString()); } // save peer to preferences, we might need it for potential bug report (check BugReportActivity) SharedPreferences.Editor editor = prefs.edit(); editor.putString(BugReportActivity.MOST_RECENT_CALL_PEER, incomingCallDid); editor.apply(); if (intent.getAction().equals(RCDevice.ACTION_INCOMING_CALL_ANSWER_AUDIO) || intent.getAction().equals(RCDevice.ACTION_INCOMING_CALL_ANSWER_VIDEO)) { // The Intent has been sent from the Notification subsystem. It can be either of type 'decline', 'video answer and 'audio answer' boolean answerVideo = intent.getAction().equals(RCDevice.ACTION_INCOMING_CALL_ANSWER_VIDEO); btnAnswer.setVisibility(View.INVISIBLE); btnAnswerAudio.setVisibility(View.INVISIBLE); acceptParams = new HashMap<String, Object>(); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_VIDEO_ENABLED, answerVideo); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_LOCAL_VIDEO, (PercentFrameLayout) findViewById(R.id.local_video_layout)); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_REMOTE_VIDEO, (PercentFrameLayout) findViewById(R.id.remote_video_layout)); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_AUDIO_CODEC, audioCodecString2Enum(prefs .getString(RCConnection.ParameterKeys.CONNECTION_PREFERRED_AUDIO_CODEC, ""))); // Needed until we implement Trickle ICE acceptParams.put(RCConnection.ParameterKeys.DEBUG_CONNECTION_CANDIDATE_TIMEOUT, Integer.parseInt(prefs.getString( RCConnection.ParameterKeys.DEBUG_CONNECTION_CANDIDATE_TIMEOUT, "0"))); if (intent.getAction().equals(RCDevice.ACTION_INCOMING_CALL_ANSWER_VIDEO)) { acceptParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_CODEC, videoCodecString2Enum(prefs.getString( RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_CODEC, ""))); acceptParams .put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_RESOLUTION, resolutionString2Enum(prefs.getString( RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_RESOLUTION, ""))); acceptParams .put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_FRAME_RATE, frameRateString2Enum(prefs.getString( RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_FRAME_RATE, ""))); } // Check permissions asynchronously and then accept the call handlePermissions(answerVideo); } } else { Log.w(TAG, "Warning: pendingConnection is null, probably reusing past intent"); } } }
From source file:com.ratebeer.android.gui.components.PosterService.java
@Override protected void onHandleIntent(Intent intent) { // Proper intent received? if (intent == null || intent.getAction() == null) { Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "No intent action to perform"); return;//from w w w. j a v a 2 s .c o m } // Proper user settings? UserSettings user = applicationSettings.getUserSettings(); if (user == null) { Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Canceling " + intent.getAction() + " intent because there are no user settings known."); return; } // Try to set the drinking status if (intent.getAction().equals(ACTION_SETDRINKINGSTATUS)) { // Get new status text String newStatus = intent.getStringExtra(EXTRA_NEWSTATUS); int beerId = intent.getIntExtra(EXTRA_BEERID, NO_BEER_EXTRA); if (newStatus == null) { Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "No new drinking status is intent; cancelling"); return; } // Synchronously set the new drinking status // During the operation a notification will be shown Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Now setting drinking status to " + newStatus); Intent recoverIntent; if (beerId == NO_BEER_EXTRA) { // If no specific beer was tight to this drinking status, assume it was from the home screen's free text // input recoverIntent = new Intent(this, Home_.class); } else { recoverIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(URI_BEER, Integer.toString(beerId)))); } createNotification(NOTIFY_SETDRINKINGSTATUS, getString(R.string.app_settingdrinking), getString(R.string.home_nowdrinking, newStatus), true, recoverIntent, null, beerId); CommandResult result = new SetDrinkingStatusCommand(user, newStatus).execute(apiConnection); if (result instanceof CommandSuccessResult) { notificationManager.cancel(NOTIFY_SETDRINKINGSTATUS); // If requested, call back the messenger, i.e. the calling activity callbackMessenger(intent, RESULT_SUCCESS); } else { String e = result instanceof CommandFailureResult ? ((CommandFailureResult) result).getException().toString() : "Unknown error"; Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Setting drinking status to " + newStatus + " failed: " + e); createNotification(NOTIFY_SETDRINKINGSTATUS, getString(R.string.app_settingdrinking), getString(R.string.error_commandfailed), true, recoverIntent, null, beerId); // If requested, call back the messenger, i.e. the calling activity callbackMessenger(intent, RESULT_FAILURE); } } // Try to add a new rating if (intent.getAction().equals(ACTION_POSTRATING)) { // Get rating details int beerId = intent.getIntExtra(EXTRA_BEERID, NO_BEER_EXTRA); String beerName = intent.getStringExtra(EXTRA_BEERNAME); int offlineId = intent.getIntExtra(EXTRA_OFFLINEID, NO_OFFLINE_EXTRA); int ratingId = intent.getIntExtra(EXTRA_ORIGRATINGID, -1); String origDate = intent.getStringExtra(EXTRA_ORIGRATINGDATE); int aroma = intent.getIntExtra(EXTRA_AROMA, -1); int appearance = intent.getIntExtra(EXTRA_APPEARANCE, -1); int taste = intent.getIntExtra(EXTRA_TASTE, -1); int palate = intent.getIntExtra(EXTRA_PALATE, -1); int overall = intent.getIntExtra(EXTRA_OVERALL, -1); String comment = intent.getStringExtra(EXTRA_COMMENT); if (beerId == NO_BEER_EXTRA || aroma <= 0 || appearance <= 0 || taste <= 0 || palate <= 0 || overall <= 0 || beerName == null || comment == null) { Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Missing extras in the POSTRATING intent; cancelling."); return; } // Synchronously post the new rating // During the operation a notification will be shown Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Now posting rating for " + beerName); Intent recoverIntent = new Intent(getApplicationContext(), Home_.class); recoverIntent.replaceExtras(intent.getExtras()); recoverIntent.setAction(ACTION_EDITRATING); createNotification(NOTIFY_POSTINGRATING, getString(R.string.app_postingrating), getString(R.string.app_rated, beerName, PostRatingCommand.calculateTotal(aroma, appearance, taste, palate, overall)), true, recoverIntent, null, beerId); CommandResult result = new PostRatingCommand(user, beerId, ratingId, origDate, beerName, aroma, appearance, taste, palate, overall, comment).execute(apiConnection); if (result instanceof CommandSuccessResult) { notificationManager.cancel(NOTIFY_POSTINGRATING); // If requested, call back the messenger, i.e. the calling activity callbackMessenger(intent, RESULT_SUCCESS); // Ratings are usually stored locally as offline rating using the ORM persistence layer // If so, it can now be removed try { if (offlineId != NO_OFFLINE_EXTRA) { OfflineRating offlineRating = getHelper().getOfflineRatingDao().queryForId(offlineId); if (offlineRating != null) { Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Deleted the offline rating for this beer as well."); getHelper().getOfflineRatingDao().delete(offlineRating); } } } catch (SQLException e) { Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Offline rating not available: " + e.toString()); } } else { String e = result instanceof CommandFailureResult ? ((CommandFailureResult) result).getException().toString() : "Unknown error"; Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Posting of rating for " + beerName + " failed: " + e); createNotification(NOTIFY_POSTINGRATING, getString(R.string.app_postingrating), getString(R.string.error_commandfailed), true, recoverIntent, null, beerId); // If requested, call back the messenger, i.e. the calling activity callbackMessenger(intent, RESULT_FAILURE); } } // Try to post a tick update if (intent.getAction().equals(ACTION_POSTTICK)) { // Get tick details int beerId = intent.getIntExtra(EXTRA_BEERID, NO_BEER_EXTRA); String beerName = intent.getStringExtra(EXTRA_BEERNAME); int userId = intent.getIntExtra(EXTRA_USERID, -1); int liked = intent.getIntExtra(EXTRA_LIKED, EXTRA_TICK_DELETE); if (beerId == NO_BEER_EXTRA || beerName == null || userId <= 0 || liked == 0 || liked > 5 || liked < -1) { Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Missing extras in the POSTRATING intent; cancelling."); return; } // Synchronously post the tick update // During the operation a notification will be shown Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Now ticking " + beerName); Intent recoverIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(URI_BEER, Integer.toString(beerId)))); // If liked (the actual tick) is set to -1 we delete this tick instead boolean del = liked == EXTRA_TICK_DELETE; createNotification(NOTIFY_POSTINGTICK, getString(del ? R.string.app_removingtick : R.string.app_postingtick), getString(R.string.app_forbeer, beerName), true, recoverIntent, null, beerId); CommandResult result; if (del) { result = new DeleteTickCommand(user, beerId, userId, beerName).execute(apiConnection); } else { result = new PostTickCommand(user, beerId, userId, beerName, liked).execute(apiConnection); } if (result instanceof CommandSuccessResult) { notificationManager.cancel(NOTIFY_POSTINGTICK); // If requested, call back the messenger, i.e. the calling activity callbackMessenger(intent, RESULT_SUCCESS); } else { String e = result instanceof CommandFailureResult ? ((CommandFailureResult) result).getException().toString() : "Unknown error"; Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, (del ? "Removing of tick for " : "Ticking of ") + beerName + " failed: " + e); createNotification(NOTIFY_POSTINGRATING, getString(del ? R.string.app_removingtick : R.string.app_postingtick), getString(R.string.error_commandfailed), true, recoverIntent, null, beerId); // If requested, call back the messenger, i.e. the calling activity callbackMessenger(intent, RESULT_FAILURE); } } // Try to add beer availability info if (intent.getAction().equals(ACTION_ADDAVAILABILITY)) { // Get beer and selected places int beerId = intent.getIntExtra(EXTRA_BEERID, -1); String beerName = intent.getStringExtra(EXTRA_BEERNAME); int placeId = intent.getIntExtra(EXTRA_PLACEID, -1); if (beerId <= 0 || beerName == null) { Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Missing extras in the ADDAVAILABILITY intent; cancelling."); return; } // Synchronously post the availability info // During the operation a notification will be shown Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Now adding availability for " + beerName); Intent recoverIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(URI_BEER, Integer.toString(beerId)))); createNotification(NOTIFY_ADDAVAILABILITY, getString(R.string.app_addingavailability), getString(R.string.app_addingforbeer, beerName), true, recoverIntent, null, beerId); CommandResult result = new AddAvailabilityCommand(user, beerId, placeId).execute(apiConnection); if (result instanceof CommandSuccessResult) { notificationManager.cancel(NOTIFY_ADDAVAILABILITY); } else { String e = result instanceof CommandFailureResult ? ((CommandFailureResult) result).getException().toString() : "Unknown error"; Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Adding of availability info for " + beerName + " failed: " + e); createNotification(NOTIFY_ADDAVAILABILITY, getString(R.string.app_addingavailability), getString(R.string.error_commandfailed), true, recoverIntent, null, beerId); } } // Try to add a beer to the cellar (a want or a have) if (intent.getAction().equals(ACTION_ADDTOCELLAR)) { // Get beer and notes int beerId = intent.getIntExtra(EXTRA_BEERID, -1); String beerName = intent.getStringExtra(EXTRA_BEERNAME); CellarType cellarType = CellarType.valueOf(intent.getStringExtra(EXTRA_CELLARTYPE)); String memo = intent.getStringExtra(EXTRA_MEMO); String vintage = intent.getStringExtra(EXTRA_VINTAGE); String quantity = intent.getStringExtra(EXTRA_QUANTITY); if (beerId <= 0 || beerName == null) { Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Missing extras in the ADDAVAILABILITY intent; cancelling."); return; } // Synchronously post the new cellar beer // During the operation a notification will be shown Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Now adding " + beerName + " to the cellar"); Intent recoverIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(URI_BEER, Integer.toString(beerId)))); createNotification(NOTIFY_ADDTOCELLAR, getString(R.string.app_addingtocellar), getString(cellarType == CellarType.Have ? R.string.app_addhave : R.string.app_addwant, beerName), true, recoverIntent, null, beerId); CommandResult result = new AddToCellarCommand(user, cellarType, beerId, memo, vintage, quantity) .execute(apiConnection); if (result instanceof CommandSuccessResult) { notificationManager.cancel(NOTIFY_ADDTOCELLAR); } else { String e = result instanceof CommandFailureResult ? ((CommandFailureResult) result).getException().toString() : "Unknown error"; Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Adding of " + beerName + " to cellar failed: " + e); createNotification(NOTIFY_ADDTOCELLAR, getString(R.string.app_addingtocellar), getString(R.string.error_commandfailed), true, recoverIntent, null, beerId); } } // Try to send a mail if (intent.getAction().equals(ACTION_SENDMAIL)) { // Get mail details String sendTo = intent.getStringExtra(EXTRA_SENDTO); String subject = intent.getStringExtra(EXTRA_SUBJECT); String body = intent.getStringExtra(EXTRA_BODY); int replyTo = intent.getIntExtra(EXTRA_REPLYTO, NO_REPLY_EXTRA); int recipient = intent.getIntExtra(EXTRA_RECIPIENT, NO_REPLY_EXTRA); // Synchronously send the mail or reply // During the operation a notification will be shown Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, (replyTo == NO_REPLY_EXTRA ? "Now sending mail to " : "Now sending reply to " + replyTo + " to ") + sendTo); Intent recoverIntent = new Intent(getApplicationContext(), Home_.class); recoverIntent.replaceExtras(intent.getExtras()); recoverIntent.setAction(ACTION_SENDMAIL); createNotification(NOTIFY_SENDMAIL, getString(R.string.mail_sendingmail), getString((replyTo == NO_REPLY_EXTRA ? R.string.mail_sendingto : R.string.mail_replyingto), sendTo), true, recoverIntent, sendTo, NO_BEER_EXTRA); CommandResult result; if (replyTo == NO_REPLY_EXTRA) result = new SendBeerMailCommand(user, sendTo, subject, body).execute(apiConnection); else result = new SendBeerReplyCommand(user, replyTo, recipient, body).execute(apiConnection); if (result instanceof CommandSuccessResult) { notificationManager.cancel(NOTIFY_SENDMAIL); } else { String e = result instanceof CommandFailureResult ? ((CommandFailureResult) result).getException().toString() : "Unknown error"; Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Sending of mail to " + sendTo + " failed: " + e); createNotification(NOTIFY_SENDMAIL, getString(R.string.mail_sendingmail), getString(R.string.error_commandfailed), true, recoverIntent, sendTo, NO_BEER_EXTRA); } } // Upload photo of a beer if (intent.getAction().equals(ACTION_UPLOADBEERPHOTO)) { // Get photo URI and beer id and name File photo = (File) intent.getSerializableExtra(EXTRA_PHOTO); int beerId = intent.getIntExtra(EXTRA_BEERID, NO_BEER_EXTRA); String beerName = intent.getStringExtra(EXTRA_BEERNAME); if (beerName == null) { beerName = "beer with ID " + Integer.toString(beerId); } if (photo == null || photo.getPath() == null || !(new File(photo.getPath()).exists())) { Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "No photo URI provided or the photo URI does not point to an existing file; cancelling"); return; } // Synchronously upload the photo for the specified beer // During the operation a notification will be shown Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Uploading photo for " + beerName); Intent recoverIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(URI_BEER, Integer.toString(beerId)))); createNotification(NOTIFY_UPLOADPHOTO, getString(R.string.app_uploadingphoto), getString(R.string.app_photofor, beerName), true, recoverIntent, null, beerId); // Make sure the photo is no bigger than 50kB try { decodeFile(photo); } catch (IOException e1) { Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Resizing of photo + " + photo.toString() + " for " + beerName + " failed: " + e1); createNotification(NOTIFY_UPLOADPHOTO, getString(R.string.app_uploadingphoto), getString(R.string.error_commandfailed), true, recoverIntent, null, beerId); // If requested, call back the messenger, i.e. the calling activity callbackMessenger(intent, RESULT_FAILURE); return; } // Start actual upload of the now-resized file CommandResult result = new UploadBeerPhotoCommand(user, beerId, photo).execute(apiConnection); if (result instanceof CommandSuccessResult) { notificationManager.cancel(NOTIFY_UPLOADPHOTO); // If requested, call back the messenger, i.e. the calling activity callbackMessenger(intent, RESULT_SUCCESS); } else { String e = result instanceof CommandFailureResult ? ((CommandFailureResult) result).getException().toString() : "Unknown error"; Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Uploading photo for " + beerName + " failed: " + e); createNotification(NOTIFY_UPLOADPHOTO, getString(R.string.app_uploadingphoto), getString(R.string.error_commandfailed), true, recoverIntent, null, beerId); // If requested, call back the messenger, i.e. the calling activity callbackMessenger(intent, RESULT_FAILURE); } } // Try to add a UPC code to some selected beer if (intent.getAction().equals(ACTION_ADDUPCCODE)) { // Get beer and upc code int beerId = intent.getIntExtra(EXTRA_BEERID, -1); String beerName = intent.getStringExtra(EXTRA_BEERNAME); String upcCode = intent.getStringExtra(EXTRA_UPCCODE); if (beerId <= 0 || beerName == null || upcCode == null || upcCode.equals("")) { Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Missing extras in the ADD_UPCCODE intent; cancelling."); return; } // Synchronously call the add UPC code method // During the operation a notification will be shown Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Adding barcode " + upcCode + " to " + beerName); Intent recoverIntent = new Intent(getApplicationContext(), Home_.class); recoverIntent.replaceExtras(intent.getExtras()); recoverIntent.setAction(ACTION_ADDUPCCODE); createNotification(NOTIFY_ADDUPCCODE, getString(R.string.app_addingupccode), getString(R.string.app_addingcodefor, beerName), true, recoverIntent, null, beerId); CommandResult result = new AddUpcCodeCommand(user, beerId, upcCode).execute(apiConnection); if (result instanceof CommandSuccessResult) { notificationManager.cancel(NOTIFY_ADDUPCCODE); } else { String e = result instanceof CommandFailureResult ? ((CommandFailureResult) result).getException().toString() : "Unknown error"; Log.d(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Adding of barcode " + upcCode + " to " + beerName + " failed: " + e); createNotification(NOTIFY_ADDUPCCODE, getString(R.string.app_addingupccode), getString(R.string.error_commandfailed), true, recoverIntent, null, beerId); } } }