List of usage examples for android.content Intent getIntExtra
public int getIntExtra(String name, int defaultValue)
From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragment.java
/** * Get data retrieved with the intent, or restore state * @param savedInstanceState the previously saved state *//*from w w w . j a va 2 s. c om*/ @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // initialize the producten & vaste producten values String[] productParams = getResources().getStringArray(R.array.array_product_param); for (String product : productParams) { mProducten.put(product, -1); mProductenVast.put(product, -1); } // get settings from the shared preferences SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); mMarktId = settings.getInt(getString(R.string.sharedpreferences_key_markt_id), 0); mActiveAccountId = settings.getInt(getString(R.string.sharedpreferences_key_account_id), 0); mActiveAccountNaam = settings.getString(getString(R.string.sharedpreferences_key_account_naam), null); // get the date of today for the dag param SimpleDateFormat sdf = new SimpleDateFormat(getString(R.string.date_format_dag)); mDagToday = sdf.format(new Date()); // only on fragment creation, not on rotation/re-creation if (savedInstanceState == null) { // check if we are editing an existing dagvergunning or making a new one Intent intent = getActivity().getIntent(); if ((intent != null) && (intent.hasExtra( MakkelijkeMarktProvider.mTableDagvergunning + MakkelijkeMarktProvider.Dagvergunning.COL_ID))) { int dagvergunningId = intent.getIntExtra( MakkelijkeMarktProvider.mTableDagvergunning + MakkelijkeMarktProvider.Dagvergunning.COL_ID, 0); if (dagvergunningId != 0) { mId = dagvergunningId; } } // init loader if an existing dagvergunning was selected if (mId > 0) { // create an argument bundle with the dagvergunning id and initialize the loader Bundle args = new Bundle(); args.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_ID, mId); getLoaderManager().initLoader(DAGVERGUNNING_LOADER, args, this); // show the progressbar (because we are fetching the koopman from the api later in the onloadfinished) mProgressbar.setVisibility(View.VISIBLE); } else { // check time in hours since last fetched the sollicitaties for selected markt long diffInHours = getResources() .getInteger(R.integer.makkelijkemarkt_api_sollicitaties_fetch_interval_hours); if (settings .contains(getContext().getString(R.string.sharedpreferences_key_sollicitaties_last_fetched) + mMarktId)) { long lastFetchTimestamp = settings.getLong( getContext().getString(R.string.sharedpreferences_key_sollicitaties_last_fetched) + mMarktId, 0); long differenceMs = new Date().getTime() - lastFetchTimestamp; diffInHours = TimeUnit.MILLISECONDS.toHours(differenceMs); } // if last sollicitaties fetched more than 12 hours ago, fetch them again if (diffInHours >= getResources() .getInteger(R.integer.makkelijkemarkt_api_sollicitaties_fetch_interval_hours)) { // show progress dialog mGetSollicitatiesProcessDialog.show(); ApiGetSollicitaties getSollicitaties = new ApiGetSollicitaties(getContext()); getSollicitaties.setMarktId(mMarktId); getSollicitaties.enqueue(); } } } else { // restore dagvergunning data from saved state mMarktId = savedInstanceState.getInt(MakkelijkeMarktProvider.Dagvergunning.COL_MARKT_ID); mDag = savedInstanceState.getString(MakkelijkeMarktProvider.Dagvergunning.COL_DAG); mId = savedInstanceState.getInt(MakkelijkeMarktProvider.Dagvergunning.COL_ID); mErkenningsnummer = savedInstanceState .getString(MakkelijkeMarktProvider.Dagvergunning.COL_ERKENNINGSNUMMER_INVOER_WAARDE); mErkenningsnummerInvoerMethode = savedInstanceState .getString(MakkelijkeMarktProvider.Dagvergunning.COL_ERKENNINGSNUMMER_INVOER_METHODE); mRegistratieDatumtijd = savedInstanceState .getString(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_DATUMTIJD); mRegistratieGeolocatieLatitude = savedInstanceState .getDouble(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_GEOLOCATIE_LAT); mRegistratieGeolocatieLongitude = savedInstanceState .getDouble(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_GEOLOCATIE_LONG); mTotaleLengte = savedInstanceState.getInt(MakkelijkeMarktProvider.Dagvergunning.COL_TOTALE_LENGTE); mSollicitatieStatus = savedInstanceState .getString(MakkelijkeMarktProvider.Dagvergunning.COL_STATUS_SOLLICITATIE); mKoopmanAanwezig = savedInstanceState.getString(MakkelijkeMarktProvider.Dagvergunning.COL_AANWEZIG); mKoopmanId = savedInstanceState.getInt(MakkelijkeMarktProvider.Dagvergunning.COL_KOOPMAN_ID); mKoopmanVoorletters = savedInstanceState.getString(MakkelijkeMarktProvider.Koopman.COL_VOORLETTERS); mKoopmanAchternaam = savedInstanceState.getString(MakkelijkeMarktProvider.Koopman.COL_ACHTERNAAM); mKoopmanFoto = savedInstanceState.getString(MakkelijkeMarktProvider.Koopman.COL_FOTO_URL); mRegistratieAccountId = savedInstanceState .getInt(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_ACCOUNT_ID); mRegistratieAccountNaam = savedInstanceState.getString(MakkelijkeMarktProvider.Account.COL_NAAM); mSollicitatieId = savedInstanceState.getInt(MakkelijkeMarktProvider.Dagvergunning.COL_SOLLICITATIE_ID); mSollicitatieNummer = savedInstanceState .getInt(MakkelijkeMarktProvider.Sollicitatie.COL_SOLLICITATIE_NUMMER); mNotitie = savedInstanceState.getString(MakkelijkeMarktProvider.Dagvergunning.COL_NOTITIE); mProducten = (HashMap<String, Integer>) savedInstanceState.getSerializable(STATE_BUNDLE_KEY_PRODUCTS); mProductenVast = (HashMap<String, Integer>) savedInstanceState .getSerializable(STATE_BUNDLE_KEY_PRODUCTS_VAST); mVervangerId = savedInstanceState.getInt(MakkelijkeMarktProvider.Dagvergunning.COL_VERVANGER_ID); mVervangerErkenningsnummer = savedInstanceState .getString(MakkelijkeMarktProvider.Dagvergunning.COL_VERVANGER_ERKENNINGSNUMMER); // select tab of viewpager from saved fragment state (if it's different) if (mViewPager.getCurrentItem() != mCurrentTab) { mViewPager.setCurrentItem(mCurrentTab); } } // set the right wizard menu depending on the current tab position setWizardMenu(mCurrentTab); // prevent the keyboard from popping up on first pager fragment load Utility.hideKeyboard(getActivity()); // // TODO: get credentials and payleven api-key from mm api // // decrypt loaded credentials // String paylevenMerchantEmail = "marco@langebeeke.com"; // String paylevenMerchantPassword = "unknown"; // String paylevenApiKey = "unknown"; // // // register with payleven api // PaylevenFactory.registerAsync( // getContext(), // paylevenMerchantEmail, // paylevenMerchantPassword, // paylevenApiKey, // new PaylevenRegistrationListener() { // @Override // public void onRegistered(Payleven payleven) { // mPaylevenApi = payleven; // Utility.log(getContext(), LOG_TAG, "Payleven Registered!"); // } // @Override // public void onError(PaylevenError error) { // Utility.log(getContext(), LOG_TAG, "Payleven registration Error: " + error.getMessage()); // } // }); // TODO: in the overzicht step change 'Opslaan' into 'Afrekenen' and show a payment dialog when clicked // TODO: if the bluetooth payleven cardreader has not been paired yet inform the toezichthouder, show instructions and open the bluetooth settings // TODO: give the toezichthouder the option in the payment dialog to save without payleven and make the payment with an old pin device? // TODO: the payment dialog shows: // - logo's of the accepted debit card standards // - total amount to pay // (this can be the difference between a changed dagvergunning and an already paid amount, // or the total amount if it is a new dagvergunning. we don't pay refunds using the app? // refunds can be done by the beheerder using the dashboard? // or do we allow refunds in the app? In that case we need to inform the toezichthouder // that a refund will be made, and keep him informed about the status of the trasnaction) // - 'start payment/refund' button? // - instructions for making the payment using the payleven cardreader // - optionally a selection list to select the bluetooth cardreader if it was not yet selected before // (if it was already selected before, show the selected reader with a 'wiebertje' in front. when // clicked it will show the list of cardreaders that can be selected) // - status of the transaction // TODO: when the payment is done succesfully we safe the dagvergunning and close the dialog and the dagvergunning activity }
From source file:com.android.contacts.ContactSaveService.java
private void saveContact(Intent intent) { RawContactDeltaList state = intent.getParcelableExtra(EXTRA_CONTACT_STATE); boolean isProfile = intent.getBooleanExtra(EXTRA_SAVE_IS_PROFILE, false); Bundle updatedPhotos = intent.getParcelableExtra(EXTRA_UPDATED_PHOTOS); if (state == null) { Log.e(TAG, "Invalid arguments for saveContact request"); return;/* w w w.j ava 2s. c o m*/ } int saveMode = intent.getIntExtra(EXTRA_SAVE_MODE, -1); // Trim any empty fields, and RawContacts, before persisting final AccountTypeManager accountTypes = AccountTypeManager.getInstance(this); RawContactModifier.trimEmpty(state, accountTypes); Uri lookupUri = null; final ContentResolver resolver = getContentResolver(); boolean succeeded = false; // Keep track of the id of a newly raw-contact (if any... there can be at most one). long insertedRawContactId = -1; // Attempt to persist changes int tries = 0; while (tries++ < PERSIST_TRIES) { try { // Build operations and try applying final ArrayList<CPOWrapper> diffWrapper = state.buildDiffWrapper(); final ArrayList<ContentProviderOperation> diff = Lists.newArrayList(); for (CPOWrapper cpoWrapper : diffWrapper) { diff.add(cpoWrapper.getOperation()); } if (DEBUG) { Log.v(TAG, "Content Provider Operations:"); for (ContentProviderOperation operation : diff) { Log.v(TAG, operation.toString()); } } int numberProcessed = 0; boolean batchFailed = false; final ContentProviderResult[] results = new ContentProviderResult[diff.size()]; while (numberProcessed < diff.size()) { final int subsetCount = applyDiffSubset(diff, numberProcessed, results, resolver); if (subsetCount == -1) { Log.w(TAG, "Resolver.applyBatch failed in saveContacts"); batchFailed = true; break; } else { numberProcessed += subsetCount; } } if (batchFailed) { // Retry save continue; } final long rawContactId = getRawContactId(state, diffWrapper, results); if (rawContactId == -1) { throw new IllegalStateException("Could not determine RawContact ID after save"); } // We don't have to check to see if the value is still -1. If we reach here, // the previous loop iteration didn't succeed, so any ID that we obtained is bogus. insertedRawContactId = getInsertedRawContactId(diffWrapper, results); if (isProfile) { // Since the profile supports local raw contacts, which may have been completely // removed if all information was removed, we need to do a special query to // get the lookup URI for the profile contact (if it still exists). Cursor c = resolver.query(Profile.CONTENT_URI, new String[] { Contacts._ID, Contacts.LOOKUP_KEY }, null, null, null); if (c == null) { continue; } try { if (c.moveToFirst()) { final long contactId = c.getLong(0); final String lookupKey = c.getString(1); lookupUri = Contacts.getLookupUri(contactId, lookupKey); } } finally { c.close(); } } else { final Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); lookupUri = RawContacts.getContactLookupUri(resolver, rawContactUri); } if (lookupUri != null && Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "Saved contact. New URI: " + lookupUri); } // We can change this back to false later, if we fail to save the contact photo. succeeded = true; break; } catch (RemoteException e) { // Something went wrong, bail without success FeedbackHelper.sendFeedback(this, TAG, "Problem persisting user edits", e); break; } catch (IllegalArgumentException e) { // This is thrown by applyBatch on malformed requests FeedbackHelper.sendFeedback(this, TAG, "Problem persisting user edits", e); showToast(R.string.contactSavedErrorToast); break; } catch (OperationApplicationException e) { // Version consistency failed, re-parent change and try again Log.w(TAG, "Version consistency failed, re-parenting: " + e.toString()); final StringBuilder sb = new StringBuilder(RawContacts._ID + " IN("); boolean first = true; final int count = state.size(); for (int i = 0; i < count; i++) { Long rawContactId = state.getRawContactId(i); if (rawContactId != null && rawContactId != -1) { if (!first) { sb.append(','); } sb.append(rawContactId); first = false; } } sb.append(")"); if (first) { throw new IllegalStateException("Version consistency failed for a new contact", e); } final RawContactDeltaList newState = RawContactDeltaList.fromQuery( isProfile ? RawContactsEntity.PROFILE_CONTENT_URI : RawContactsEntity.CONTENT_URI, resolver, sb.toString(), null, null); state = RawContactDeltaList.mergeAfter(newState, state); // Update the new state to use profile URIs if appropriate. if (isProfile) { for (RawContactDelta delta : state) { delta.setProfileQueryUri(); } } } } // Now save any updated photos. We do this at the end to ensure that // the ContactProvider already knows about newly-created contacts. if (updatedPhotos != null) { for (String key : updatedPhotos.keySet()) { Uri photoUri = updatedPhotos.getParcelable(key); long rawContactId = Long.parseLong(key); // If the raw-contact ID is negative, we are saving a new raw-contact; // replace the bogus ID with the new one that we actually saved the contact at. if (rawContactId < 0) { rawContactId = insertedRawContactId; } // If the save failed, insertedRawContactId will be -1 if (rawContactId < 0 || !saveUpdatedPhoto(rawContactId, photoUri, saveMode)) { succeeded = false; } } } Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT); if (callbackIntent != null) { if (succeeded) { // Mark the intent to indicate that the save was successful (even if the lookup URI // is now null). For local contacts or the local profile, it's possible that the // save triggered removal of the contact, so no lookup URI would exist.. callbackIntent.putExtra(EXTRA_SAVE_SUCCEEDED, true); } callbackIntent.setData(lookupUri); deliverCallback(callbackIntent); } }
From source file:com.android.deskclock.timer.TimerReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { if (Timers.LOGGING) { Log.v(TAG, "Received intent " + intent.toString()); }/*from www.j a v a2 s . c o m*/ String actionType = intent.getAction(); // This action does not need the timers data if (Timers.NOTIF_IN_USE_CANCEL.equals(actionType)) { cancelInUseNotification(context); return; } // Get the updated timers data. if (mTimers == null) { mTimers = new ArrayList<>(); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); TimerObj.getTimersFromSharedPrefs(prefs, mTimers); if (AlarmService.PRE_SHUTDOWN_ACTION.equals(actionType)) { // Stop Ringtone if all timers are not in times-up status TimerObj timerRing = Timers.findExpiredTimer(mTimers); if (timerRing != null) { timerRing.mState = TimerObj.STATE_STOPPED; stopRingtoneIfNoTimesup(context); } return; } // These actions do not provide a timer ID, but do use the timers data if (Timers.NOTIF_IN_USE_SHOW.equals(actionType)) { showInUseNotification(context); return; } else if (Timers.NOTIF_TIMES_UP_SHOW.equals(actionType)) { showTimesUpNotification(context); return; } else if (Timers.NOTIF_TIMES_UP_CANCEL.equals(actionType)) { cancelTimesUpNotification(context); return; } // Remaining actions provide a timer Id if (!intent.hasExtra(Timers.TIMER_INTENT_EXTRA)) { // No data to work with, do nothing Log.e(TAG, "got intent without Timer data"); return; } // Get the timer out of the Intent int timerId = intent.getIntExtra(Timers.TIMER_INTENT_EXTRA, -1); if (timerId == -1) { Log.d(TAG, "OnReceive:intent without Timer data for " + actionType); } TimerObj t = Timers.findTimer(mTimers, timerId); if (Timers.TIMES_UP.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, " timer not found in list - do nothing"); return; } t.setState(TimerObj.STATE_TIMESUP); t.writeToSharedPref(prefs); Events.sendEvent(R.string.category_timer, R.string.action_fire, 0); /// M: We acquire the lock here because in some rare scenario, the wake lock is release /// by alarm before it could be acquired by Timer activity causing state to be suspended AlarmAlertWakeLock.acquireScreenCpuWakeLock(context); // Play ringtone by using TimerRingService service with a default alarm. Log.d(TAG, "playing ringtone"); Intent si = new Intent(); si.setClass(context, TimerRingService.class); context.startService(si); // Update the in-use notification if (getNextRunningTimer(mTimers, false, Utils.getTimeNow()) == null) { // Found no running timers. cancelInUseNotification(context); } else { showInUseNotification(context); } /** * M: To show time up notification to avoid the case: pausing the * current activity(eg: touch home key) when time is up, it cause * the TimerAlertFullScreen can not be started, and this cause no * notification in status bar but the timer has sound. @{ */ Utils.showTimesUpNotifications(context); /** @} */ // Start the TimerAlertFullScreen activity. Intent timersAlert = new Intent(context, TimerAlertFullScreen.class); timersAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); context.startActivity(timersAlert); } else if (Timers.RESET_TIMER.equals(actionType) || Timers.DELETE_TIMER.equals(actionType) || Timers.TIMER_DONE.equals(actionType)) { // Stop Ringtone if all timers are not in times-up status stopRingtoneIfNoTimesup(context); if (t != null) { cancelTimesUpNotification(context, t); } } else if (Timers.NOTIF_TIMES_UP_STOP.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, "timer to stop not found in list - do nothing"); return; } else if (t.mState != TimerObj.STATE_TIMESUP) { Log.d(TAG, "action to stop but timer not in times-up state - do nothing"); return; } // Update timer state t.setState(t.getDeleteAfterUse() ? TimerObj.STATE_DELETED : TimerObj.STATE_RESTART); t.mTimeLeft = t.mOriginalLength = t.mSetupLength; t.writeToSharedPref(prefs); // Flag to tell DeskClock to re-sync with the database prefs.edit().putBoolean(Timers.REFRESH_UI_WITH_LATEST_DATA, true).apply(); cancelTimesUpNotification(context, t); // Done with timer - delete from data base if (t.getDeleteAfterUse()) { t.deleteFromSharedPref(prefs); } // Stop Ringtone if no timers are in times-up status stopRingtoneIfNoTimesup(context); } else if (Timers.NOTIF_TIMES_UP_PLUS_ONE.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, "timer to +1m not found in list - do nothing"); return; } else if (t.mState != TimerObj.STATE_TIMESUP) { Log.d(TAG, "action to +1m but timer not in times up state - do nothing"); return; } // Restarting the timer with 1 minute left. t.setState(TimerObj.STATE_RUNNING); t.mStartTime = Utils.getTimeNow(); t.mTimeLeft = t.mOriginalLength = TimerObj.MINUTE_IN_MILLIS; t.writeToSharedPref(prefs); // Flag to tell DeskClock to re-sync with the database prefs.edit().putBoolean(Timers.REFRESH_UI_WITH_LATEST_DATA, true).apply(); cancelTimesUpNotification(context, t); // If the app is not open, refresh the in-use notification if (!prefs.getBoolean(Timers.NOTIF_APP_OPEN, false)) { showInUseNotification(context); } // Stop Ringtone if no timers are in times-up status stopRingtoneIfNoTimesup(context); } else if (Timers.TIMER_UPDATE.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, " timer to update not found in list - do nothing"); return; } // Refresh buzzing notification if (t.mState == TimerObj.STATE_TIMESUP) { // Must cancel the previous notification to get all updates displayed correctly cancelTimesUpNotification(context, t); showTimesUpNotification(context, t); } } if (intent.getBooleanExtra(Timers.UPDATE_NEXT_TIMESUP, true)) { // Update the next "Times up" alarm unless explicitly told not to. updateNextTimesup(context); } }
From source file:com.ieeton.agency.activity.ChatActivity.java
/** * onActivityResult/*from w w w. j a va 2s. c o m*/ */ protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Utils.logd("requestCode:" + requestCode); Utils.logd("resultCode:" + resultCode); if (resultCode == RESULT_CODE_EXIT_GROUP) { setResult(RESULT_OK); finish(); return; } if (requestCode == REQUEST_CODE_CONTEXT_MENU) { switch (resultCode) { case RESULT_CODE_COPY: // ?? EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1))); if (copyMsg.getType() == EMMessage.Type.IMAGE) { ImageMessageBody imageBody = (ImageMessageBody) copyMsg.getBody(); // ??? clipboard.setText(COPY_IMAGE + imageBody.getLocalUrl()); } else { // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this, // ((TextMessageBody) copyMsg.getBody()).getMessage())); clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage()); } break; case RESULT_CODE_DELETE: // ? EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1)); conversation.removeMessage(deleteMsg.getMsgId()); adapter.refresh(); listView.setSelection(data.getIntExtra("position", adapter.getCount()) - 1); break; case RESULT_CODE_FORWARD: // ?? EMMessage forwardMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", 0)); Intent intent = new Intent(this, ForwardMessageActivity.class); intent.putExtra("forward_msg_id", forwardMsg.getMsgId()); startActivity(intent); break; default: break; } } if (resultCode == RESULT_OK) { // ? if (requestCode == REQUEST_CODE_EMPTY_HISTORY) { // ? EMChatManager.getInstance().clearConversation(toChatUsername); adapter.refresh(); } else if (requestCode == REQUEST_CODE_CAMERA) { // ?? if (cameraFile != null && cameraFile.exists()) sendPicture(cameraFile.getAbsolutePath()); } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ?? int duration = data.getIntExtra("dur", 0); String videoPath = data.getStringExtra("path"); File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis()); Bitmap bitmap = null; FileOutputStream fos = null; try { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3); if (bitmap == null) { EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon"); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon); } fos = new FileOutputStream(file); bitmap.compress(CompressFormat.JPEG, 100, fos); } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } fos = null; } if (bitmap != null) { bitmap.recycle(); bitmap = null; } } sendVideo(videoPath, file.getAbsolutePath(), duration / 1000); } else if (requestCode == REQUEST_CODE_LOCAL) { // ?? if (data != null) { Uri selectedImage = data.getData(); if (selectedImage != null) { sendPicByUri(selectedImage); } } } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ?? if (data != null) { Uri uri = data.getData(); if (uri != null) { sendFile(uri); } } } else if (requestCode == REQUEST_CODE_MAP) { // double latitude = data.getDoubleExtra("latitude", 0); double longitude = data.getDoubleExtra("longitude", 0); String locationAddress = data.getStringExtra("address"); if (locationAddress != null && !locationAddress.equals("")) { more(more); sendLocationMsg(latitude, longitude, "", locationAddress); } else { Toast.makeText(this, "????", 0).show(); } // ??? } else if (requestCode == REQUEST_CODE_TEXT) { resendMessage(); } else if (requestCode == REQUEST_CODE_VOICE) { resendMessage(); } else if (requestCode == REQUEST_CODE_PICTURE) { resendMessage(); } else if (requestCode == REQUEST_CODE_LOCATION) { resendMessage(); } else if (requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) { resendMessage(); } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) { // if (!TextUtils.isEmpty(clipboard.getText())) { String pasteText = clipboard.getText().toString(); if (pasteText.startsWith(COPY_IMAGE)) { // ??path sendPicture(pasteText.replace(COPY_IMAGE, "")); } } } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ??? EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1)); addUserToBlacklist(deleteMsg.getFrom()); } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) { adapter.refresh(); } else if (requestCode == REQUEST_CODE_QUICK_REPLY) { String content = data.getStringExtra(EXTRA_QUICK_REPLY); Utils.logd("content:" + content); sendText(content); } else if (conversation.getMsgCount() > 0) { adapter.refresh(); setResult(RESULT_OK); } } }
From source file:com.grass.caishi.cc.activity.main.MainActivity.java
/** * onActivityResult//from www . j av a2 s . c o m */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == MAIN_MESSAGE_LOGIN_OUT) { // ? logout(); } else if (resultCode == MAIN_MESSAGE_SYSTEM_OUT) { // ? MainActivity.this.finish(); android.os.Process.killProcess(android.os.Process.myPid()); // ?PID System.exit(0); // java?c#0 } else if (resultCode == 888) { settingFragment.InitData(true); } else if (resultCode == 369) { add_code = data.getIntExtra("id", 0); selectCityFrament.setAddress(add_code, data.getStringExtra("name")); } }
From source file:com.fullteem.yueba.app.ui.ChatActivity.java
/** * onActivityResult/*from w w w. j a va 2 s . co m*/ */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_CODE_EXIT_GROUP) { setResult(RESULT_OK); finish(); return; } if (requestCode == REQUEST_CODE_CONTEXT_MENU) { switch (resultCode) { case RESULT_CODE_COPY: // ?? EMMessage copyMsg = (adapter.getItem(data.getIntExtra("position", -1))); // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this, // ((TextMessageBody) copyMsg.getBody()).getMessage())); clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage()); break; case RESULT_CODE_DELETE: // ? EMMessage deleteMsg = adapter.getItem(data.getIntExtra("position", -1)); conversation.removeMessage(deleteMsg.getMsgId()); adapter.refresh(); listView.setSelection(data.getIntExtra("position", adapter.getCount()) - 1); break; case RESULT_CODE_FORWARD: // ?? // EMMessage forwardMsg = (EMMessage) // adapter.getItem(data.getIntExtra("position", 0)); // Intent intent = new Intent(this, // ForwardMessageActivity.class); // intent.putExtra("forward_msg_id", forwardMsg.getMsgId()); // startActivity(intent); break; default: break; } } if (resultCode == RESULT_OK) { // ? if (requestCode == REQUEST_CODE_EMPTY_HISTORY) { // ? EMChatManager.getInstance().clearConversation(toChatUsername); adapter.refresh(); } else if (requestCode == REQUEST_CODE_CAMERA) { // ?? if (cameraFile != null && cameraFile.exists()) sendPicture(cameraFile.getAbsolutePath()); } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ?? int duration = data.getIntExtra("dur", 0); String videoPath = data.getStringExtra("path"); File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis()); Bitmap bitmap = null; FileOutputStream fos = null; try { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3); if (bitmap == null) { EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon"); bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon); } fos = new FileOutputStream(file); bitmap.compress(CompressFormat.JPEG, 100, fos); } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } fos = null; } if (bitmap != null) { bitmap.recycle(); bitmap = null; } } sendVideo(videoPath, file.getAbsolutePath(), duration / 1000); } else if (requestCode == REQUEST_CODE_LOCAL) { // ?? if (data != null) { Uri selectedImage = data.getData(); if (selectedImage != null) { sendPicByUri(selectedImage); } } } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ?? if (data != null) { Uri uri = data.getData(); if (uri != null) { sendFile(uri); } } } else if (requestCode == REQUEST_CODE_MAP) { // double latitude = data.getDoubleExtra("latitude", 0); double longitude = data.getDoubleExtra("longitude", 0); String locationAddress = data.getStringExtra("address"); if (locationAddress != null && !locationAddress.equals("")) { more(more); sendLocationMsg(latitude, longitude, "", locationAddress); } else { Toast.makeText(this, "????", 0).show(); } // ??? } else if (requestCode == REQUEST_CODE_TEXT) { resendMessage(); } else if (requestCode == REQUEST_CODE_VOICE) { resendMessage(); } else if (requestCode == REQUEST_CODE_PICTURE) { resendMessage(); } else if (requestCode == REQUEST_CODE_LOCATION) { resendMessage(); } else if (requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) { resendMessage(); } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) { // if (!TextUtils.isEmpty(clipboard.getText())) { String pasteText = clipboard.getText().toString(); if (pasteText.startsWith(COPY_IMAGE)) { // ??path sendPicture(pasteText.replace(COPY_IMAGE, "")); } } } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ??? EMMessage deleteMsg = adapter.getItem(data.getIntExtra("position", -1)); addUserToBlacklist(deleteMsg.getFrom()); } else if (conversation.getMsgCount() > 0) { adapter.refresh(); setResult(RESULT_OK); } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) { adapter.refresh(); } } }
From source file:android_network.hetnet.vpn_service.ServiceSinkhole.java
private void set(Intent intent) { // Get arguments int uid = intent.getIntExtra(EXTRA_UID, 0); String network = intent.getStringExtra(EXTRA_NETWORK); String pkg = intent.getStringExtra(EXTRA_PACKAGE); boolean blocked = intent.getBooleanExtra(EXTRA_BLOCKED, false); Log.i(TAG, "Set " + pkg + " " + network + "=" + blocked); // Get defaults SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(ServiceSinkhole.this); boolean default_wifi = settings.getBoolean("whitelist_wifi", true); boolean default_other = settings.getBoolean("whitelist_other", true); // Update setting SharedPreferences prefs = getSharedPreferences(network, Context.MODE_PRIVATE); if (blocked == ("wifi".equals(network) ? default_wifi : default_other)) prefs.edit().remove(pkg).apply(); else/*from ww w .jav a2 s . com*/ prefs.edit().putBoolean(pkg, blocked).apply(); // Apply rules ServiceSinkhole.reload("notification", ServiceSinkhole.this); // Update notification Receiver.notifyNewApplication(uid, ServiceSinkhole.this); // Update UI Intent ruleset = new Intent(MainActivity.ACTION_RULES_CHANGED); LocalBroadcastManager.getInstance(ServiceSinkhole.this).sendBroadcast(ruleset); }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent dataIntent) { super.onActivityResult(requestCode, resultCode, dataIntent); if (requestCode == ACTIVITY_LICENSE) { // License check if (dataIntent != null) { int code = dataIntent.getIntExtra("Code", -1); int reason = dataIntent.getIntExtra("Reason", -1); String sReason;/*from www .ja va 2s .c o m*/ if (reason == LICENSED) sReason = "LICENSED"; else if (reason == NOT_LICENSED) sReason = "NOT_LICENSED"; else if (reason == RETRY) sReason = "RETRY"; else if (reason == ERROR_CONTACTING_SERVER) sReason = "ERROR_CONTACTING_SERVER"; else if (reason == ERROR_INVALID_PACKAGE_NAME) sReason = "ERROR_INVALID_PACKAGE_NAME"; else if (reason == ERROR_NON_MATCHING_UID) sReason = "ERROR_NON_MATCHING_UID"; else sReason = Integer.toString(reason); Util.log(null, Log.WARN, "Licensing: code=" + code + " reason=" + sReason); if (code > 0) { Util.setPro(true); invalidateOptionsMenu(); Toast.makeText(this, getString(R.string.menu_pro), Toast.LENGTH_LONG).show(); } else if (reason == RETRY) { Util.setPro(false); mProHandler.postDelayed(new Runnable() { @Override public void run() { checkLicense(); } }, 30 * 1000); } } } }
From source file:com.mantz_it.rfanalyzer.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // err_info from RTL2832U: String[] rtlsdrErrInfo = { "permission_denied", "root_required", "no_devices_found", "unknown_error", "replug", "already_running" }; switch (requestCode) { case RTL2832U_RESULT_CODE: // This happens if the RTL2832U driver was started. // We check for errors and print them: if (resultCode == RESULT_OK) Log.i(LOGTAG, "onActivityResult: RTL2832U driver was successfully started."); else {/*from w ww . j av a 2 s . c o m*/ int errorId = -1; int exceptionCode = 0; String detailedDescription = null; if (data != null) { errorId = data.getIntExtra("marto.rtl_tcp_andro.RtlTcpExceptionId", -1); exceptionCode = data.getIntExtra("detailed_exception_code", 0); detailedDescription = data.getStringExtra("detailed_exception_message"); } String errorMsg = "ERROR NOT SPECIFIED"; if (errorId >= 0 && errorId < rtlsdrErrInfo.length) errorMsg = rtlsdrErrInfo[errorId]; Log.e(LOGTAG, "onActivityResult: RTL2832U driver returned with error: " + errorMsg + " (" + errorId + ")" + (detailedDescription != null ? ": " + detailedDescription + " (" + exceptionCode + ")" : "")); if (source != null && source instanceof RtlsdrSource) { Toast.makeText(MainActivity.this, "Error with Source [" + source.getName() + "]: " + errorMsg + " (" + errorId + ")" + (detailedDescription != null ? ": " + detailedDescription + " (" + exceptionCode + ")" : ""), Toast.LENGTH_LONG).show(); source.close(); } } break; } }