Java Code Examples for android.support.v4.app.DialogFragment#setArguments()

The following examples show how to use android.support.v4.app.DialogFragment#setArguments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadProgressActivity.java    From IslamicLibraryAndroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            onBackPressed();
            return (true);
        case R.id.cancel_all_downloads:
            Bundle CancelDownloadDialogFragmentBundle = new Bundle();
            if (downlandProgressRecyclerViewAdapter != null) {
                CancelDownloadDialogFragmentBundle.putInt(KEY_NUMBER_OF_BOOKS_TO_DONLOAD,
                        downlandProgressRecyclerViewAdapter.getItemCount());

                DialogFragment CancelDownloadDialogFragment = new CancelDownloadDialogFragment();
                CancelDownloadDialogFragment.setArguments(CancelDownloadDialogFragmentBundle);
                CancelDownloadDialogFragment.show(getSupportFragmentManager(), "CancelDownloadDialogFragment");
            } else {
                Timber.d("downlandProgressRecyclerViewAdapter null");
            }
            return true;
    }

    return (super.onOptionsItemSelected(item));
}
 
Example 2
Source File: CustomCommandActivity.java    From rpicheck with MIT License 6 votes vote down vote up
private void parseNonPromptingAndShow(String keyPassphrase, CommandBean command) {
    final DialogFragment runCommandDialog = new RunCommandDialog();
    final Bundle args = new Bundle();
    String cmdString = command.getCommand();
    Map<String, String> nonPromptingPlaceholders = parseNonPromptingPlaceholders(command.getCommand(), currentDevice);
    for (Map.Entry<String, String> entry : nonPromptingPlaceholders.entrySet()) {
        cmdString = cmdString.replace(entry.getKey(), entry.getValue());
    }
    command.setCommand(cmdString);
    args.putSerializable("pi", currentDevice);
    args.putSerializable("cmd", command);
    if (keyPassphrase != null) {
        args.putString("passphrase", keyPassphrase);
    }
    runCommandDialog.setArguments(args);
    runCommandDialog.show(getSupportFragmentManager(), "runCommand");
}
 
Example 3
Source File: CustomCommandActivity.java    From rpicheck with MIT License 6 votes vote down vote up
/**
 * Opens the command dialog.
 *
 * @param keyPassphrase nullable: key passphrase
 */
private void openCommandDialog(final long commandId, final String keyPassphrase) {
    final CommandBean command = deviceDb.readCommand(commandId);
    final ArrayList<String> dynamicPlaceholders = parseDynamicPlaceholders(command.getCommand());
    if (!dynamicPlaceholders.isEmpty()) {
        // need to get replacements for dynamic placeholders first
        DialogFragment placeholderDialog = new CommandPlaceholdersDialog();
        Bundle args2 = new Bundle();
        args2.putStringArrayList(CommandPlaceholdersDialog.ARG_PLACEHOLDERS, dynamicPlaceholders);
        args2.putSerializable(CommandPlaceholdersDialog.ARG_COMMAND, command);
        args2.putString(CommandPlaceholdersDialog.ARG_PASSPHRASE, keyPassphrase);
        placeholderDialog.setArguments(args2);
        placeholderDialog.show(getSupportFragmentManager(), "placeholders");
        return;
    }
    parseNonPromptingAndShow(keyPassphrase, command);
}
 
Example 4
Source File: BaseDialog.java    From COCOFramework with Apache License 2.0 6 votes vote down vote up
public static void showForResult(final FragmentManager fm,
                                 final DialogFragment d, final int requestCode) {

    final FragmentTransaction ft = fm.beginTransaction();
    final Fragment prev = fm.findFragmentByTag("dialog");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);
    if (d.getArguments() == null) {
        d.setArguments(BaseDialog.createArguments(null, null, requestCode));
    } else {
        d.getArguments().putInt(BaseDialog.ARG_REQUEST_CODE, requestCode);
    }

    d.show(ft, null);
}
 
Example 5
Source File: ExchangeDialogFragment.java    From android with GNU General Public License v3.0 6 votes vote down vote up
public static DialogFragment newInstance(ApplicationEvents.ExchangeCredential.Type type, String message) {
    DialogFragment fragment = new ExchangeDialogFragment();

    int titleResId;
    int optionsResId;
    switch (type) {
        case broadcast:
            titleResId = R.string.credential_broadcast_share_title;
            optionsResId = R.array.credential_broadcast_share_exchange_options;
            break;
        case target:
        default:
            titleResId = R.string.credential_target_share_title;
            optionsResId = R.array.credential_target_share_exchange_options;
    }

    Bundle args = new Bundle();
    args.putInt(FRAGMENT_BUNDLE_KEY_TITLE_RES_ID, titleResId);
    args.putInt(FRAGMENT_BUNDLE_KEY_OPTIONS_RES_ID, optionsResId);
    args.putString(FRAGMENT_BUNDLE_KEY_MESSAGE, message);
    fragment.setArguments(args);

    return fragment;
}
 
Example 6
Source File: SettingsFragment.java    From RememBirthday with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDisplayPreferenceDialog(Preference preference) {
    DialogFragment dialogFragment = null;
    if (preference instanceof TimePreference) {
        dialogFragment = new TimePreferenceDialogFragmentCompat();
        Bundle bundle = new Bundle(1);
        bundle.putString("key", preference.getKey());
        dialogFragment.setArguments(bundle);
    }

    // Show dialog
    if (dialogFragment != null) {
        dialogFragment.setTargetFragment(this, 0);
        dialogFragment.show(getChildFragmentManager(), TAG_FRAGMENT_DIALOG);
    } else {
        super.onDisplayPreferenceDialog(preference);
    }
}
 
Example 7
Source File: ChameleonMiniRevERebootedActivity.java    From Walrus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDisplayPreferenceDialog(Preference preference) {
    if (preference instanceof ChameleonMiniSlotPickerPreference) {
        DialogFragment dialogFragment =
                new ChameleonMiniSlotPickerPreference.NumberPickerFragment();
        final Bundle b = new Bundle();
        b.putString("key", preference.getKey());
        dialogFragment.setArguments(b);
        dialogFragment.show(this.getChildFragmentManager(),
                "settings_dialog");
    } else {
        super.onDisplayPreferenceDialog(preference);
    }
}
 
Example 8
Source File: GameActivity.java    From open_flood with MIT License 5 votes vote down vote up
private void showEndGameDialog() {
    DialogFragment endGameDialog = new EndGameDialogFragment();
    Bundle args = new Bundle();
    args.putInt("steps", game.getSteps());
    args.putBoolean("game_won", game.checkWin());
    args.putString("seed", game.getSeed());
    endGameDialog.setArguments(args);
    endGameDialog.show(getSupportFragmentManager(), "EndGameDialog");
    return;
}
 
Example 9
Source File: ChameleonMiniRevGActivity.java    From Walrus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDisplayPreferenceDialog(Preference preference) {
    if (preference instanceof ChameleonMiniSlotPickerPreference) {
        DialogFragment dialogFragment =
                new ChameleonMiniSlotPickerPreference.NumberPickerFragment();
        final Bundle b = new Bundle();
        b.putString("key", preference.getKey());
        dialogFragment.setArguments(b);
        dialogFragment.show(this.getChildFragmentManager(),
                "settings_dialog");
    } else {
        super.onDisplayPreferenceDialog(preference);
    }
}
 
Example 10
Source File: EditRecipeActivity.java    From biermacht with Apache License 2.0 5 votes vote down vote up
@Override
public void onMissedClick(View v) {
  super.onMissedClick(v);

  AlertDialog alert;
  if (v.equals(measuredFGView)) {
    alert = alertBuilder.editTextFloatAlert(measuredFGViewText, measuredFGViewTitle).create();
  }
  else if (v.equals(measuredOGView)) {
    alert = alertBuilder.editTextFloatAlert(measuredOGViewText, measuredOGViewTitle).create();
  }
  else if (v.equals(measuredBatchSizeView)) {
    alert = alertBuilder.editTextFloatAlert(measuredBatchSizeViewText,
                                            measuredBatchSizeViewTitle).create();
  }
  else if (v.equals(brewDateView)) {
    // Show the brew date picker and return.
    DialogFragment newFragment = new DatePickerFragment();
    Bundle args = new Bundle();
    newFragment.setArguments(args);
    newFragment.show(this.getSupportFragmentManager(), "datePicker");
    return;
  }
  else {
    Log.d("EditRecipeActivity", "onMissedClick did not handle the clicked view");
    return; // In case its none of those views...
  }

  // Force keyboard open and show popup
  alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
  alert.show();
}
 
Example 11
Source File: ConnectionsDialogFragment.java    From android with GNU General Public License v3.0 5 votes vote down vote up
public static DialogFragment newInstance(int peerId) {
    DialogFragment fragment = new ConnectionsDialogFragment();

    Bundle args = new Bundle();
    args.putInt(FRAGMENT_BUNDLE_KEY_PEER_ID, peerId);
    fragment.setArguments(args);

    return fragment;
}
 
Example 12
Source File: CardActivity.java    From Walrus with GNU General Public License v3.0 5 votes vote down vote up
public void onViewCardDataClick(View view) {
    if (card.cardData == null) {
        return;
    }

    CardData.Metadata cardDataMetadata = card.cardData.getClass().getAnnotation(
            CardData.Metadata.class);

    Class<? extends DialogFragment> viewDialogFragmentClass =
            cardDataMetadata.viewDialogFragmentClass();
    if (viewDialogFragmentClass == DialogFragment.class) {
        Toast.makeText(CardActivity.this, R.string.no_view_card_dialog,
                Toast.LENGTH_SHORT).show();
        return;
    }

    DialogFragment viewDialogFragment;
    try {
        viewDialogFragment = viewDialogFragmentClass.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }

    Bundle args = new Bundle();
    args.putString("title", getString(R.string.view_card_data_title, cardDataMetadata.name()));
    args.putParcelable("source_and_sink", Parcels.wrap(card.cardData));
    args.putBoolean("editable", false);
    viewDialogFragment.setArguments(args);

    viewDialogFragment.show(getSupportFragmentManager(), "card_data_view_dialog");
}
 
Example 13
Source File: BrowsingActivity.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
boolean onActionItemClicked(@NonNull MenuItem item) {
    if (item.getItemId() == R.id.batch_download) {
        mBooksToDownload.clear();
        mBooksToDownload.addAll(selectedBooksIds);
        HashSet<Integer> downloadedHashSet = mBooksInformationDbHelper.getBooksIdsFilteredOnDownloadStatus(
                BooksInformationDBContract.StoredBooks.COLUMN_NAME_STATUS + ">?",
                new String[]{String.valueOf(DownloadsConstants.STATUS_DOWNLOAD_STARTED)}
        );
        boolean isSelectionModified = mBooksToDownload.removeAll(downloadedHashSet);

        if (mBooksToDownload.size() != 0) {
            if (mBooksToDownload.size() == 1) {
                startBatchDownload();
                onDestroyActionMode();
            } else {
                if (isSelectionModified) {
                    Toast.makeText(BrowsingActivity.this, R.string.removed_selection_of_downloaded_books, Toast.LENGTH_LONG).show();
                }

                Bundle confirmBatchDownloadDialogFragmentBundle = new Bundle();
                confirmBatchDownloadDialogFragmentBundle.putInt(KEY_NUMBER_OF_BOOKS_TO_DONLOAD, mBooksToDownload.size());
                DialogFragment confirmBatchDownloadDialogFragment = new ConfirmBatchDownloadDialogFragment();
                confirmBatchDownloadDialogFragment.setArguments(confirmBatchDownloadDialogFragmentBundle);
                confirmBatchDownloadDialogFragment.show(getSupportFragmentManager(), "ConfirmBatchDownloadDialogFragment");
                onDestroyActionMode();
            }
        } else {
            Toast.makeText(BrowsingActivity.this, R.string.toast_all_selected_books_already_downlaoded, Toast.LENGTH_LONG).show();
        }

    } else if (item.getItemId() == R.id.select_all) {
        addAllBooksToSelection(shouldDisplayDownloadedOnly());
    } else if (item.getItemId() == R.id.clear_selection) {
        removeAllSelectedBooks();
    }

    return false;
}
 
Example 14
Source File: CustomCommandActivity.java    From rpicheck with MIT License 5 votes vote down vote up
private void runCommand(long commandId) {
    this.commandId = commandId;
    ConnectivityManager connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        if (currentDevice.usesAuthentificationMethod(RaspberryDeviceBean.AUTH_PUBLIC_KEY)
                || currentDevice.usesAuthentificationMethod(RaspberryDeviceBean.AUTH_PUBLIC_KEY_WITH_PASSWORD)) {
            // need permission to read keyfile
            final String keyfilePath = currentDevice.getKeyfilePath();
            if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                LOGGER.debug("Requesting permission to read private key file from storage...");
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        REQUEST_READ_PERMISSION_FOR_COMMAND);
                return;
            }
            if (currentDevice.usesAuthentificationMethod(RaspberryDeviceBean.AUTH_PUBLIC_KEY_WITH_PASSWORD)
                    && Strings.isNullOrEmpty(currentDevice.getKeyfilePass())) {
                // must ask for key passphrase first
                LOGGER.debug("Asking for key passphrase.");
                // dirty hack, saving commandId as "dialog type"
                final String dialogType = commandId + "";
                final DialogFragment passphraseDialog = new PassphraseDialog();
                final Bundle args = new Bundle();
                args.putString(PassphraseDialog.KEY_TYPE, dialogType);
                passphraseDialog.setArguments(args);
                passphraseDialog.setCancelable(false);
                passphraseDialog.show(getSupportFragmentManager(), "passphrase");
                return;
            }
        }
        LOGGER.debug("Opening command dialog.");
        openCommandDialog(commandId, currentDevice.getKeyfilePass());
    } else {
        Toast.makeText(this, R.string.no_connection, Toast.LENGTH_SHORT).show();
    }
}
 
Example 15
Source File: BrowsingActivity.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void showRenameDialog(@NonNull BooksCollection booksCollection) {
    Bundle confirmBatchDownloadDialogFragmentBundle = new Bundle();
    confirmBatchDownloadDialogFragmentBundle.putString(KEY_OLD_NAME, booksCollection.getName());
    Gson gson = new Gson();
    String json = gson.toJson(booksCollection);
    confirmBatchDownloadDialogFragmentBundle.putString(KEY_COLLECTION_GSON, json);
    DialogFragment renameCollectionDialogFragment = new RenameCollectionDialogFragment();
    renameCollectionDialogFragment.setArguments(confirmBatchDownloadDialogFragmentBundle);
    renameCollectionDialogFragment.show(getSupportFragmentManager(), "renameCollectionDialogFragment");

}
 
Example 16
Source File: BaseDialog.java    From COCOFramework with Apache License 2.0 4 votes vote down vote up
public static void show(final FragmentManager fm, final DialogFragment d,
                        final Bundle arg) {
    d.setArguments(arg);
    BaseDialog.show(fm, d);
}
 
Example 17
Source File: MainActivity.java    From rpicheck with MIT License 4 votes vote down vote up
private void doRebootOrHalt(String type) {
    LOGGER.info("Doing {} on {}...", type, currentDevice.getName());
    if (isNetworkAvailable()) {
        // get connection settings from shared preferences
        final String host = currentDevice.getHost();
        final String user = currentDevice.getUser();
        final String port = currentDevice.getPort() + "";
        final String sudoPass = currentDevice.getSudoPass();
        if (currentDevice.usesAuthentificationMethod(RaspberryDeviceBean.AUTH_PASSWORD)) {
            final String pass = currentDevice.getPass();
            if (pass != null) {
                new SSHShutdownTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, host, user, pass, port, sudoPass, type, null, null);
            } else {
                Toast.makeText(this, R.string.no_password_specified, Toast.LENGTH_LONG).show();
            }
        } else if (currentDevice.usesAuthentificationMethod(RaspberryDeviceBean.AUTH_PUBLIC_KEY) || currentDevice.usesAuthentificationMethod(RaspberryDeviceBean.AUTH_PUBLIC_KEY_WITH_PASSWORD)) {
            // keyfile must be present and readable
            final String keyfilePath = currentDevice.getKeyfilePath();
            if (keyfilePath != null) {
                if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    LOGGER.debug("Requesting permission to read private key file from storage...");
                    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                            type.equals(Constants.TYPE_HALT) ? REQUEST_PERMISSION_READ_FOR_HALT : REQUEST_PERMISSION_READ_FOR_REBOOT);
                    return;
                } else {
                    final File privateKey = new File(keyfilePath);
                    if (privateKey.exists()) {
                        new SSHShutdownTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, host, user, null, port, sudoPass, type, keyfilePath, null);
                    } else {
                        Toast.makeText(this, "Cannot find keyfile at location: " + keyfilePath, Toast.LENGTH_LONG).show();
                    }
                }
            } else {
                Toast.makeText(this, "No keyfile specified!", Toast.LENGTH_LONG).show();
            }
            if (currentDevice.usesAuthentificationMethod(RaspberryDeviceBean.AUTH_PUBLIC_KEY_WITH_PASSWORD)) {
                if (!Strings.isNullOrEmpty(currentDevice.getKeyfilePass())) {
                    final String passphrase = currentDevice.getKeyfilePass();
                    new SSHShutdownTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, host, user, null, port, sudoPass, type, keyfilePath, passphrase);
                } else {
                    final String dialogType = type.equals(Constants.TYPE_REBOOT) ? PassphraseDialog.SSH_SHUTDOWN : PassphraseDialog.SSH_HALT;
                    final DialogFragment passphraseDialog = new PassphraseDialog();
                    final Bundle args = new Bundle();
                    args.putString(PassphraseDialog.KEY_TYPE, dialogType);
                    passphraseDialog.setArguments(args);
                    passphraseDialog.setCancelable(false);
                    passphraseDialog.show(getSupportFragmentManager(), "passphrase");
                }
            }
        }
    } else {
        // no network available
        Toast.makeText(this, R.string.no_connection, Toast.LENGTH_SHORT).show();
    }
}
 
Example 18
Source File: MainActivity.java    From rpicheck with MIT License 4 votes vote down vote up
private void doQuery(boolean initByPullToRefresh) {
    if (currentDevice == null) {
        // no device available, show hint for user
        Toast.makeText(this, R.string.no_device_available, Toast.LENGTH_LONG).show();
        // stop refresh animation from pull-to-refresh
        swipeRefreshLayout.setRefreshing(false);
        return;
    }
    if (isNetworkAvailable()) {
        // get connection settings from shared preferences
        String host = currentDevice.getHost();
        String user = currentDevice.getUser();
        String port = currentDevice.getPort() + "";
        String pass = null;
        // reading process preference
        final Boolean hideRoot = sharedPrefs.getBoolean(SettingsActivity.KEY_PREF_QUERY_HIDE_ROOT_PROCESSES, true);
        String keyPath = null;
        String keyPass = null;
        boolean canConnect = false;
        // check authentification method
        if (currentDevice.usesAuthentificationMethod(RaspberryDeviceBean.AUTH_PASSWORD)) {
            pass = currentDevice.getPass();
            if (pass != null) {
                canConnect = true;
            } else {
                Toast.makeText(this, R.string.no_password_specified, Toast.LENGTH_LONG).show();
            }
        } else if (currentDevice.usesAuthentificationMethod(RaspberryDeviceBean.AUTH_PUBLIC_KEY) ||
                currentDevice.usesAuthentificationMethod(RaspberryDeviceBean.AUTH_PUBLIC_KEY_WITH_PASSWORD)) {
            // keyfile must be present and readable
            final String keyfilePath = currentDevice.getKeyfilePath();
            if (keyfilePath != null) {
                if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    LOGGER.debug("Requesting permission to read private key file from storage...");
                    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                            initByPullToRefresh ? REQUEST_PERMISSION_READ_FOR_QUERY_PULL : REQUEST_PERMISSION_READ_FOR_QUERY_NO_PULL);
                    return;
                } else {
                    final File privateKey = new File(keyfilePath);
                    if (privateKey.exists()) {
                        keyPath = keyfilePath;
                        canConnect = true;
                    } else {
                        Toast.makeText(this, "Cannot find keyfile at location: " + keyfilePath, Toast.LENGTH_LONG).show();
                    }
                }
            } else {
                Toast.makeText(this, "No keyfile specified!", Toast.LENGTH_LONG).show();
            }
            if (currentDevice.usesAuthentificationMethod(RaspberryDeviceBean.AUTH_PUBLIC_KEY_WITH_PASSWORD)) {
                // keypass must be present
                final String keyfilePass = currentDevice.getKeyfilePass();
                if (keyfilePass != null) {
                    canConnect = true;
                    keyPass = keyfilePass;
                } else {
                    final DialogFragment newFragment = new PassphraseDialog();
                    final Bundle args = new Bundle();
                    args.putString(PassphraseDialog.KEY_TYPE, PassphraseDialog.SSH_QUERY);
                    newFragment.setArguments(args);
                    newFragment.setCancelable(false);
                    newFragment.show(getSupportFragmentManager(), "passphrase");
                    canConnect = false;
                }
            }
        }
        if (canConnect) {
            if (!initByPullToRefresh) {
                // show hint that user can use pull-to-refresh
                showPullToRefreshHint();
            }
            // execute query in background
            new SSHQueryTask(this, getLoadAveragePreference()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, host, user, pass, port, hideRoot.toString(), keyPath, keyPass);
        }
    } else {
        // no network available
        Toast.makeText(this, R.string.no_connection, Toast.LENGTH_SHORT).show();
        // stop refresh animation from pull-to-refresh
        swipeRefreshLayout.setRefreshing(false);
    }
}
 
Example 19
Source File: DialogsManager.java    From dependency-injection-in-android-course with Apache License 2.0 4 votes vote down vote up
private void setId(DialogFragment dialog, String id) {
    Bundle args = dialog.getArguments() != null ? dialog.getArguments() : new Bundle(1);
    args.putString(ARGUMENT_DIALOG_ID, id);
    dialog.setArguments(args);
}