public class

PdfPasswordDialog

extends PasswordDialog

Gradle dependencies

compile group: 'androidx.pdf', name: 'pdf-viewer', version: '1.0.0-alpha02'

  • groupId: androidx.pdf
  • artifactId: pdf-viewer
  • version: 1.0.0-alpha02

Artifact androidx.pdf:pdf-viewer:1.0.0-alpha02 it located at Google repository (https://maven.google.com/)

Overview

This instance requires a Fragment.getTargetFragment() to be set to give back the typed password. Currently, this target Fragment must be a PdfViewer.

Summary

Fields
public PdfPasswordDialog.PasswordDialogEventsListenermListener

from DialogFragmentSTYLE_NO_FRAME, STYLE_NO_INPUT, STYLE_NO_TITLE, STYLE_NORMAL
from FragmentmPreviousWho
Constructors
publicPdfPasswordDialog()

Methods
public abstract voidsendPassword(EditText textField)

Set the password input by the user.

public voidsetListener(PdfPasswordDialog.PasswordDialogEventsListener listener)

public abstract voidshowErrorOnDialogCancel()

Show error when user cancels password prompt dialog.

from PasswordDialogonCancel, onCreateDialog, onStart, retry, setFinishOnCancel
from DialogFragmentdismiss, dismissAllowingStateLoss, dismissNow, getDialog, getShowsDialog, getTheme, isCancelable, onActivityCreated, onAttach, onCreate, onDestroyView, onDetach, onDismiss, onGetLayoutInflater, onSaveInstanceState, onStop, onViewStateRestored, requireComponentDialog, requireDialog, setCancelable, setShowsDialog, setStyle, setupDialog, show, show, showNow
from Fragmentdump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getDefaultViewModelCreationExtras, getDefaultViewModelProviderFactory, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLayoutInflater, getLifecycle, getLoaderManager, getParentFragment, getParentFragmentManager, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSavedStateRegistry, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, getViewLifecycleOwner, getViewLifecycleOwnerLiveData, getViewModelStore, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isStateSaved, isVisible, onActivityResult, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onCreateView, onDestroy, onDestroyOptionsMenu, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPause, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onRequestPermissionsResult, onResume, onViewCreated, postponeEnterTransition, postponeEnterTransition, registerForActivityResult, registerForActivityResult, registerForContextMenu, requestPermissions, requireActivity, requireArguments, requireContext, requireFragmentManager, requireHost, requireParentFragment, requireView, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startActivity, startActivity, startActivityForResult, startActivityForResult, startIntentSenderForResult, startPostponedEnterTransition, toString, unregisterForContextMenu
from java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait

Fields

Constructors

public PdfPasswordDialog()

Methods

public void setListener(PdfPasswordDialog.PasswordDialogEventsListener listener)

public abstract void sendPassword(EditText textField)

Set the password input by the user.

public abstract void showErrorOnDialogCancel()

Show error when user cancels password prompt dialog.

Source

/*
 * Copyright 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.pdf.viewer;

import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.pdf.viewer.password.PasswordDialog;

/**
 * This instance requires a {@link #getTargetFragment} to be set to give back the typed password.
 * Currently, this target Fragment must be a {@link PdfViewer}.
 */
@RestrictTo(RestrictTo.Scope.LIBRARY)
@SuppressWarnings("deprecation")
public class PdfPasswordDialog extends PasswordDialog {

    @Nullable
    public PasswordDialogEventsListener mListener;

    public void setListener(@NonNull PasswordDialogEventsListener listener) {
        mListener = listener;
    }

    @Override
    public void sendPassword(@NonNull EditText textField) {
        if (mListener != null) {
            mListener.onPasswordTextChange(textField.getText().toString());
        }
    }

    @Override
    public void showErrorOnDialogCancel() {
        if (mListener != null) {
            mListener.onDialogCancelled();
        }
    }

    public interface PasswordDialogEventsListener {
        /**
         * Callback to pass the password to the fragment.
         */
        void onPasswordTextChange(@NonNull String password);

        /**
         * Callback to handle the cancellation of this dialog.
         */
        void onDialogCancelled();
    }
}