public void show ( ) { if ( title == null || message == null ) { throw new RuntimeException ( "Title or message cannot be null." ) ; } dialogView = layoutInflater . inflate ( R . layout . password_dialog , null ) ; ( ( TextView ) dialogView . findViewById ( R . id . password_dialog_title ) ) . setText ( title ) ; ( ( TextView ) dialogView . findViewById ( R . id . password_dialog_message ) ) . setText ( message ) ; final EditText input = dialogView . findViewById ( R . id . password_dialog_input ) ; input . setInputType ( passwordType ) ; dialog = builder . setView ( dialogView ) . setPositiveButton ( R . string . password_confirm , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialogInterface , int i ) { // have to override this listener, otherwise it will close the dialog } } ) . setNegativeButton ( R . string . password_cancel , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialogInterface , int i ) { if ( callback != null ) { callback . onPasswordCancel ( ) ; } } } ) . create ( ) ; if ( dialog . getWindow ( ) != null ) { if ( enterAnimation != DialogAnimation . Enter . APPEAR || exitAnimation != DialogAnimation . Exit . DISAPPEAR ) { int style = DialogAnimation . getStyle ( enterAnimation , exitAnimation ) ; if ( style != - 1 ) { dialog . getWindow ( ) . getAttributes ( ) . windowAnimations = style ; } else { Log . w ( TAG , "The animation selected is not available. Default animation will be used." ) ; } } if ( ! dimBackground ) { dialog . getWindow ( ) . clearFlags ( WindowManager . LayoutParams . FLAG_DIM_BEHIND ) ; } } else { Log . w ( TAG , "Could not get window from dialog" ) ; } dialog . setCanceledOnTouchOutside ( cancelOnTouchOutside ) ; dialog . setCancelable ( cancelOnPressBack ) ; dialog . show ( ) ; dialog . getButton ( AlertDialog . BUTTON_POSITIVE ) . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View v ) { if ( callback != null ) { String password = input . getText ( ) . toString ( ) ; if ( callback . onPasswordCheck ( password ) ) { dialog . dismiss ( ) ; if ( token != null ) { token . validate ( ) ; } callback . onPasswordSucceeded ( ) ; } else { input . setText ( "" ) ; input . setError ( context . getResources ( ) . getString ( R . string . password_incorrect ) ) ; } } } } ) ; }
Show the password dialog