List of usage examples for android.app Activity setResult
public final void setResult(int resultCode, Intent data)
From source file:org.kontalk.ui.GroupInfoFragment.java
void openChat(String jid) { Intent i = new Intent(); i.setData(MyMessages.Threads.getUri(jid)); Activity parent = getActivity(); parent.setResult(GroupInfoActivity.RESULT_PRIVATE_CHAT, i); parent.finish();/* w ww. jav a 2s . co m*/ }
From source file:it.geosolutions.android.map.fragment.featureinfo.FeatureInfoAttributeListFragment.java
private void returnSelectedItem() { Intent returnIntent = new Intent(); Activity activity = getSherlockActivity(); // get current markers // currentFeatures is present if (currentFeatures != null && currentFeatures.size() > 0) { returnIntent.putExtra(GetFeatureInfoLayerListActivity.RESULT_FEATURE_EXTRA, currentFeatures.get(0)); returnIntent.putExtra(GetFeatureInfoLayerListActivity.LAYER_FEATURE_EXTRA, layers.get(0)); activity.setResult(Activity.RESULT_OK, returnIntent); }/*from w w w. j av a 2 s . c o m*/ activity.finish(); }
From source file:org.sufficientlysecure.keychain.ui.CreateKeyFinalFragment.java
public void finishWithResult(OperationResult result) { Activity activity = getActivity(); if (activity == null) { mQueuedFinishResult = result;// w w w. jav a2 s .co m return; } Intent data = new Intent(); data.putExtra(OperationResult.EXTRA_RESULT, result); activity.setResult(Activity.RESULT_OK, data); activity.finish(); }
From source file:com.numenta.taurus.chart.AbstractAnomalyChartFragment.java
public void goBack() { final Activity activity = getActivity(); if (activity != null && !activity.isTaskRoot()) { final Intent data = new Intent(); if (_chartData != null) { data.putExtra(EXTRA_TYPE, _chartData.getType()); data.putExtra(EXTRA_ID, _chartData.getId()); data.putExtra(EXTRA_AGGREGATION, _chartData.getAggregation()); }//from ww w . j a v a 2 s.co m activity.setResult(Activity.RESULT_OK, data); // Go Back activity.finish(); } }
From source file:it.evilsocket.dsploit.core.System.java
public static boolean checkNetworking(final Activity current) { if (Network.isWifiConnected(mContext) == false) { AlertDialog.Builder builder = new AlertDialog.Builder(current); builder.setCancelable(false);//from w ww .ja v a2 s . c o m builder.setTitle("Error"); builder.setMessage("WiFi connectivity went down."); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Bundle bundle = new Bundle(); bundle.putBoolean(WifiScannerActivity.CONNECTED, false); Intent intent = new Intent(); intent.putExtras(bundle); current.setResult(Activity.RESULT_OK, intent); current.finish(); } }); AlertDialog alert = builder.create(); alert.show(); return false; } return true; }
From source file:org.kontalk.ui.GroupInfoFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // action mode is active - no processing if (isActionModeActive()) return true; switch (item.getItemId()) { case R.id.menu_invite: Activity parent = getActivity(); if (parent != null) { parent.setResult(GroupInfoActivity.RESULT_ADD_USERS, null); parent.finish();//from w w w . ja v a2 s.c o m } return true; } return super.onOptionsItemSelected(item); }
From source file:org.sufficientlysecure.keychain.ui.EditKeyFragment.java
@Override public void onQueuedOperationSuccess(OperationResult result) { // null-protected from Queueing*Fragment Activity activity = getActivity(); // if good -> finish, return result to showkey and display there! Intent intent = new Intent(); intent.putExtra(OperationResult.EXTRA_RESULT, result); activity.setResult(Activity.RESULT_OK, intent); activity.finish();//www. ja va2 s. c o m }
From source file:org.odk.collect.android.fragments.Camera2VideoFragment.java
private void stopRecordingVideo() { // UI/* w w w .ja v a 2 s.co m*/ isRecordingVideo = false; // Stop recording mediaRecorder.stop(); mediaRecorder.reset(); Activity activity = getActivity(); if (null != activity) { Timber.d("Video saved: " + nextVideoAbsolutePath); } Intent i = new Intent(); i.setData(Uri.fromFile(new File(nextVideoAbsolutePath))); activity.setResult(Activity.RESULT_OK, i); activity.finish(); }
From source file:felixwiemuth.lincal.ui.CalendarViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.calendar_view, container, false); TextView titleView = (TextView) rootView.findViewById(R.id.cal_title); TextView authorView = (TextView) rootView.findViewById(R.id.cal_author); notificationsEnabled = (CheckBox) rootView.findViewById(R.id.notifications_enabled); textViewEarliestNotificationTime = (TextView) rootView .findViewById(R.id.setting_earliest_notification_time); earliestNotificationTimeEnabled = (CheckBox) rootView .findViewById(R.id.setting_earliest_notification_time_enabled); entryDisplayModeDate = (Spinner) rootView.findViewById(R.id.setting_entry_display_mode_date); entryDisplayModeDescription = (Spinner) rootView.findViewById(R.id.setting_entry_display_mode_description); buttonRemoveCalendar = (Button) rootView.findViewById(R.id.button_remove_cal); if (calendar == null) { titleView.setText(R.string.cal_title_error_loading); notificationsEnabled.setEnabled(false); earliestNotificationTimeEnabled.setEnabled(false); entryDisplayModeDate.setEnabled(false); entryDisplayModeDescription.setEnabled(false); } else {/*w w w. j a va 2 s. c o m*/ titleView.setText(calendar.getTitle()); authorView.setText(calendar.getAuthor()); entryList = (RecyclerView) rootView.findViewById(R.id.entry_list_recycler_view); SimpleItemRecyclerViewAdapter adapter = new SimpleItemRecyclerViewAdapter(); entryList.setAdapter(adapter); ((TextView) rootView.findViewById(R.id.cal_descr)).setText(calendar.getDescription()); ((TextView) rootView.findViewById(R.id.cal_version)).setText(calendar.getVersion()); ((TextView) rootView.findViewById(R.id.cal_date)).setText(calendar.getDateStr()); if (calendar.hasForceEntryDisplayModeDate()) { entryDisplayModeDate.setEnabled(false); } if (calendar.hasForceEntryDisplayModeDescription()) { entryDisplayModeDescription.setEnabled(false); } } ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(getContext(), R.array.setting_entry_display_mode_options, android.R.layout.simple_spinner_item); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); entryDisplayModeDate.setAdapter(spinnerAdapter); entryDisplayModeDescription.setAdapter(spinnerAdapter); loadSettings(); // loading settings before adding listeners prevents them from firing due to initialization (e.g. Spinner) if (calendar != null) { // Set listeners final View.OnClickListener saveSettingsListener = new View.OnClickListener() { @Override public void onClick(View v) { saveSettings(); NotificationService.runWithCalendar(getContext(), Calendars.getInstance(getContext()).getConfigByPos(calendarPos).getId()); //TODO reconsider when to call } }; notificationsEnabled.setOnClickListener(saveSettingsListener); textViewEarliestNotificationTime.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadSettings(); // update earliestNotificationTime DialogFragment dialogFragment = new TimePickerFragment(); Bundle arguments = new Bundle(); arguments.putInt("hour", earliestNotificationTime.getHour()); arguments.putInt("minute", earliestNotificationTime.getMinute()); arguments.putInt("calendarPos", calendarPos); dialogFragment.setArguments(arguments); dialogFragment.show(getFragmentManager(), "timePicker"); } }); earliestNotificationTimeEnabled.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { saveSettingsListener.onClick(v); // have to update the displayed notification times (only show when enabled) entryList.getAdapter().notifyDataSetChanged(); } }); //TODO implement // onScreenOnEnabled = (CheckBox) rootView.findViewById(R.id.setting_show_notification_on_screen_on); // onScreenOnEnabled.setOnClickListener(saveSettingsListener); entryDisplayModeDate.setOnItemSelectedListener(new AdapterViewOnItemSelectedListener( entryDisplayModeDate.getSelectedItemPosition(), saveSettingsListener)); entryDisplayModeDescription.setOnItemSelectedListener(new AdapterViewOnItemSelectedListener( entryDisplayModeDescription.getSelectedItemPosition(), saveSettingsListener)); } buttonRemoveCalendar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle(R.string.dialog_remove_cal_title).setMessage(R.string.dialog_remove_cal_msg) .setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // First remove this fragment, so that it cannot be used anymore getActivity().getSupportFragmentManager().beginTransaction() .remove(CalendarViewFragment.this).commit(); Calendars calendars = Calendars.getInstance(getContext()); calendars.removeCalendarByPos(getContext(), calendarPos); // Notify calendar list that the calendar with the given position was removed and return to calendar list in case of CalendarViewActivity Activity hostActivity = getActivity(); if (hostActivity instanceof CalendarListActivity) { ((CalendarListActivity) hostActivity).notifyCalendarRemoved(calendarPos); } else if (hostActivity instanceof CalendarViewActivity) { Intent resultData = new Intent(); resultData.putExtra(CalendarListActivity.EXTRA_RESULT_CAL_REMOVED, calendarPos); hostActivity.setResult(Activity.RESULT_OK, resultData); hostActivity.finish(); } else { throw new RuntimeException( "CalendarViewFragment may only be contained in either CalendarListActivity or CalendarViewActivity."); } } }); builder.show(); } }); return rootView; }
From source file:org.thialfihar.android.apg.ui.EncryptMessageFragment.java
private void encryptStart(final boolean toClipboard) { // Send all information needed to service to edit key in other thread Intent intent = new Intent(getActivity(), ApgIntentService.class); intent.setAction(ApgIntentService.ACTION_ENCRYPT_SIGN); // fill values for this action Bundle data = new Bundle(); data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_BYTES); String message = mMessage.getText().toString(); if (mEncryptInterface.isModeSymmetric()) { Log.d(Constants.TAG, "Symmetric encryption enabled!"); String passphrase = mEncryptInterface.getPassphrase(); if (passphrase.length() == 0) { passphrase = null;/*from w w w .j av a 2 s . c om*/ } data.putString(ApgIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase); } else { data.putLong(ApgIntentService.ENCRYPT_SIGNATURE_KEY_ID, mEncryptInterface.getSignatureKey()); data.putLongArray(ApgIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, mEncryptInterface.getEncryptionKeys()); boolean signOnly = (mEncryptInterface.getEncryptionKeys() == null || mEncryptInterface.getEncryptionKeys().length == 0); if (signOnly) { message = fixBadCharactersForGmail(message); } } data.putByteArray(ApgIntentService.ENCRYPT_MESSAGE_BYTES, message.getBytes()); data.putBoolean(ApgIntentService.ENCRYPT_USE_ASCII_ARMOR, true); int compressionId = Preferences.getPreferences(getActivity()).getDefaultMessageCompression(); data.putInt(ApgIntentService.ENCRYPT_COMPRESSION_ID, compressionId); intent.putExtra(ApgIntentService.EXTRA_DATA, data); final Activity activity = getActivity(); // Message is received after encrypting is done in ApgIntentService ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(getActivity(), getString(R.string.progress_encrypting), ProgressDialog.STYLE_HORIZONTAL) { public void handleMessage(Message message) { // handle messages by standard ApgIntentServiceHandler first super.handleMessage(message); if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) { // get returned data bundle Bundle data = message.getData(); String output = new String(data.getByteArray(ApgIntentService.RESULT_BYTES)); Log.d(Constants.TAG, "output: " + output); if (mLegacyMode) { Intent result = new Intent(); result.putExtra("encryptedMessage", output); activity.setResult(activity.RESULT_OK, result); activity.finish(); return; } else if (toClipboard) { ClipboardReflection.copyToClipboard(getActivity(), output); AppMsg.makeText(getActivity(), R.string.encrypt_sign_clipboard_successful, AppMsg.STYLE_INFO).show(); } else { Intent sendIntent = new Intent(Intent.ACTION_SEND); // Type is set to text/plain so that encrypted messages can // be sent with Whatsapp, Hangouts, SMS etc... sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, output); startActivity(Intent.createChooser(sendIntent, getString(R.string.title_share_with))); } } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger); // show progress dialog saveHandler.showProgressDialog(getActivity()); // start service with intent getActivity().startService(intent); }