idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
1,600
private void adaptWindowBackgroundAndInset ( ) { DialogRootView rootView = getRootView ( ) ; if ( rootView != null ) { rootView . setWindowBackgroundAndInset ( windowBackground , windowInsets ) ; } }
Adapts the background and inset of the dialog s window .
1,601
private void adaptLayoutParams ( ) { DialogRootView rootView = getRootView ( ) ; if ( getWindow ( ) != null && rootView != null ) { rootView . setLayoutParams ( createLayoutParams ( ) ) ; rootView . setFullscreen ( isFullscreen ( ) ) ; rootView . setMaxWidth ( getMaxWidth ( ) ) ; rootView . setMaxHeight ( getMaxHeight ( ) ) ; } }
Adapts the layout params of the dialog .
1,602
private void adaptPadding ( ) { ViewGroup dialogRootView = getRootView ( ) ; if ( dialogRootView != null ) { dialogRootView . setPadding ( getPaddingLeft ( ) , getPaddingTop ( ) , getPaddingRight ( ) , getPaddingBottom ( ) ) ; } }
Adapts the padding of the dialog .
1,603
private void adaptIcon ( ) { if ( iconImageView != null ) { ImageViewCompat . setImageTintList ( iconImageView , iconTintList ) ; ImageViewCompat . setImageTintMode ( iconImageView , iconTintMode ) ; iconImageView . setImageDrawable ( icon ) ; iconImageView . setVisibility ( icon != null ? View . VISIBLE : View . GONE ) ; } adaptTitleContainerVisibility ( ) ; }
Adapts the dialog s icon .
1,604
private void adaptTitleContainerVisibility ( ) { if ( titleContainer != null ) { boolean visible = isCustomTitleUsed ( ) || ! TextUtils . isEmpty ( title ) || icon != null ; if ( visible ) { titleContainer . setVisibility ( View . VISIBLE ) ; notifyOnAreaShown ( Area . TITLE ) ; } else { titleContainer . setVisibility ( View . GONE ) ; notifyOnAreaHidden ( Area . TITLE ) ; } } }
Adapts the visibility of the parent view of the text view which is used to show the title of the dialog .
1,605
private void adaptMessage ( ) { if ( messageTextView != null ) { messageTextView . setText ( message ) ; messageTextView . setVisibility ( ! TextUtils . isEmpty ( message ) ? View . VISIBLE : View . GONE ) ; } adaptMessageContainerVisibility ( ) ; }
Adapts the dialog s message .
1,606
private void adaptMessageContainerVisibility ( ) { if ( titleContainer != null ) { boolean visible = isCustomMessageUsed ( ) || ! TextUtils . isEmpty ( message ) ; if ( visible ) { messageContainer . setVisibility ( View . VISIBLE ) ; notifyOnAreaShown ( Area . MESSAGE ) ; } else { messageContainer . setVisibility ( View . GONE ) ; notifyOnAreaHidden ( Area . MESSAGE ) ; } } }
Adapts the visibility of the parent view of the text view which is used to show the message of the dialog .
1,607
private void adaptBackground ( final BackgroundAnimation animation ) { if ( getRootView ( ) != null && getWindow ( ) != null ) { Drawable newBackground = background ; if ( animation != null && newBackground != null ) { View animatedView = isFullscreen ( ) ? getWindow ( ) . getDecorView ( ) : getRootView ( ) ; Drawable previousBackground = animatedView . getBackground ( ) ; if ( previousBackground != null ) { if ( previousBackground instanceof AbstractTransitionDrawable ) { previousBackground = ( ( AbstractTransitionDrawable ) previousBackground ) . getDrawable ( 1 ) ; } if ( animation instanceof CircleTransitionAnimation ) { CircleTransitionAnimation circleTransitionAnimation = ( CircleTransitionAnimation ) animation ; CircleTransitionDrawable transition = new CircleTransitionDrawable ( new Drawable [ ] { previousBackground , newBackground } ) ; transition . setRadius ( circleTransitionAnimation . getRadius ( ) ) ; transition . setListener ( circleTransitionAnimation . getListener ( ) ) ; if ( circleTransitionAnimation . getX ( ) != null ) { transition . setX ( circleTransitionAnimation . getX ( ) ) ; } if ( circleTransitionAnimation . getY ( ) != null ) { transition . setY ( circleTransitionAnimation . getY ( ) ) ; } transition . startTransition ( circleTransitionAnimation . getDuration ( ) ) ; newBackground = transition ; } else if ( animation instanceof CrossFadeTransitionAnimation ) { CrossFadeTransitionDrawable transition = new CrossFadeTransitionDrawable ( new Drawable [ ] { previousBackground , newBackground } ) ; transition . setListener ( animation . getListener ( ) ) ; transition . startTransition ( animation . getDuration ( ) ) ; newBackground = transition ; } else { throw new RuntimeException ( "Unknown type of animation: " + animation . getClass ( ) . getSimpleName ( ) ) ; } } } getWindow ( ) . setBackgroundDrawable ( new ColorDrawable ( Color . TRANSPARENT ) ) ; ViewUtil . setBackground ( getRootView ( ) , isFullscreen ( ) ? null : newBackground ) ; ViewUtil . setBackground ( getWindow ( ) . getDecorView ( ) , isFullscreen ( ) ? newBackground : null ) ; } }
Adapts the dialog s background .
1,608
private void adaptContentContainerVisibility ( ) { if ( contentContainer != null ) { if ( isCustomViewUsed ( ) ) { contentContainer . setVisibility ( View . VISIBLE ) ; notifyOnAreaShown ( Area . CONTENT ) ; } else { contentContainer . setVisibility ( View . GONE ) ; notifyOnAreaHidden ( Area . CONTENT ) ; } } }
Adapts the visibility of the parent view of the view which is used to show the dialog s content .
1,609
private void obtainItemColor ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogItemColor } ) ; int defaultColor = ThemeUtil . getColor ( getContext ( ) , themeResourceId , android . R . attr . textColorSecondary ) ; setItemColor ( typedArray . getColor ( 0 , defaultColor ) ) ; }
Obtains the item color from a specific theme .
1,610
public final BuilderType setOnItemSelectedListener ( final ListDialog . OnItemSelectedListener listener ) { getProduct ( ) . setOnItemSelectedListener ( listener ) ; return self ( ) ; }
Sets the listener which should be notified when an item which is shown by the dialog which is created by the builder is selected .
1,611
private void addAreas ( ) { if ( areas != null ) { removeAllViews ( ) ; scrollView = null ; topDivider = null ; bottomDivider = null ; Area previousArea = null ; boolean canAddTopDivider = false ; for ( Map . Entry < Area , View > entry : areas . entrySet ( ) ) { Area area = entry . getKey ( ) ; View view = entry . getValue ( ) ; if ( scrollableArea . isScrollable ( area ) ) { if ( topDivider == null && canAddTopDivider && ! scrollableArea . isScrollable ( previousArea ) ) { topDivider = addDivider ( ) ; } inflateScrollView ( scrollableArea ) ; ViewGroup scrollContainer = scrollView . getChildCount ( ) > 0 ? ( ViewGroup ) scrollView . getChildAt ( 0 ) : scrollView ; view . getViewTreeObserver ( ) . addOnGlobalLayoutListener ( createScrollViewChildLayoutListener ( ) ) ; scrollContainer . addView ( view ) ; } else { if ( bottomDivider == null && previousArea != null && scrollableArea . getBottomScrollableArea ( ) != null && scrollableArea . getBottomScrollableArea ( ) . getIndex ( ) < area . getIndex ( ) && view . getVisibility ( ) == View . VISIBLE && area != Area . BUTTON_BAR ) { bottomDivider = addDivider ( ) ; } addView ( view ) ; } canAddTopDivider |= area != Area . HEADER && view . getVisibility ( ) == View . VISIBLE ; previousArea = area ; } adaptAreaPadding ( ) ; findListView ( ) ; } }
Adds the areas which are contained by the dialog to the root view .
1,612
private void addDividers ( ) { for ( Map . Entry < DividerLocation , Divider > entry : dividers . entrySet ( ) ) { if ( entry . getKey ( ) == DividerLocation . BOTTOM && bottomDivider == null && ! scrollableArea . isScrollable ( Area . BUTTON_BAR ) ) { bottomDivider = entry . getValue ( ) ; } else if ( entry . getKey ( ) == DividerLocation . TOP && topDivider == null && ! scrollableArea . isScrollable ( Area . CONTENT ) ) { topDivider = entry . getValue ( ) ; } } }
Adds the dividers which are contained by the dialog to the root view .
1,613
private Divider addDivider ( ) { Divider divider = new Divider ( getContext ( ) ) ; divider . setVisibility ( View . INVISIBLE ) ; divider . setBackgroundColor ( dividerColor ) ; LayoutParams layoutParams = new LayoutParams ( LayoutParams . MATCH_PARENT , dpToPixels ( getContext ( ) , 1 ) ) ; layoutParams . leftMargin = dividerMargin ; layoutParams . rightMargin = dividerMargin ; addView ( divider , layoutParams ) ; return divider ; }
Adds a divider to the view .
1,614
private void adaptAreaPadding ( ) { if ( areas != null ) { boolean paddingTopApplied = false ; Area previousArea = null ; View previousView = null ; int scrollViewPaddingTop = 0 ; int scrollViewMarginBottom = 0 ; Iterator < Map . Entry < Area , View > > iterator = areas . entrySet ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { Map . Entry < Area , View > entry = iterator . next ( ) ; Area area = entry . getKey ( ) ; View view = entry . getValue ( ) ; applyDialogPaddingLeft ( area , view ) ; applyDialogPaddingRight ( area , view ) ; if ( ! paddingTopApplied ) { paddingTopApplied = applyDialogPaddingTop ( area , view ) ; } if ( ! iterator . hasNext ( ) ) { applyDialogPaddingBottom ( area , view ) ; } if ( previousArea != null ) { if ( area == Area . BUTTON_BAR ) { applyDialogPaddingBottom ( previousArea , previousView ) ; } Pair < Integer , Integer > pair = addViewSpacing ( previousArea , previousView , area ) ; scrollViewPaddingTop += pair . first != null ? pair . first : 0 ; scrollViewMarginBottom += pair . second != null ? pair . second : 0 ; } previousArea = area ; previousView = view ; } if ( scrollView != null ) { LinearLayout . LayoutParams layoutParams = ( LayoutParams ) scrollView . getLayoutParams ( ) ; layoutParams . bottomMargin = scrollViewMarginBottom ; scrollView . setPadding ( scrollView . getPaddingLeft ( ) , scrollView . getPaddingTop ( ) + scrollViewPaddingTop , scrollView . getPaddingRight ( ) , scrollView . getPaddingBottom ( ) ) ; } } }
Adapts the padding of the areas which are contained by the dialog .
1,615
private void adaptDividerVisibilities ( ) { if ( scrollView != null ) { adaptDividerVisibilities ( scrollView . isScrolledToTop ( ) , scrollView . isScrolledToBottom ( ) , false ) ; } else if ( listView != null ) { adaptDividerVisibilities ( isListViewScrolledToTop ( listView ) , isListViewScrolledToBottom ( listView ) , false ) ; } }
Adapts the visibility of the top and bottom divider depending on the state of the dialog s scroll view .
1,616
private boolean isListViewScrolledToBottom ( final AbsListView scrollView ) { if ( scrollView . getCount ( ) > 0 && scrollView . getChildCount ( ) > 0 ) { if ( scrollView . getLastVisiblePosition ( ) == scrollView . getCount ( ) - 1 ) { View child = scrollView . getChildAt ( scrollView . getChildCount ( ) - 1 ) ; return child == null || child . getBottom ( ) <= scrollView . getHeight ( ) ; } } else { return true ; } return false ; }
Returns whether a specific list view is scrolled to the bottom or not .
1,617
private boolean isListViewScrolledToTop ( final AbsListView listView ) { if ( listView . getFirstVisiblePosition ( ) == 0 ) { if ( listView . getChildCount ( ) == 0 ) { return true ; } else { View child = listView . getChildAt ( 0 ) ; return child == null || child . getTop ( ) == 0 ; } } return false ; }
Returns whether a specific list view is scrolled to the top or not .
1,618
private void applyDialogPaddingLeft ( final Area area , final View view ) { int padding = area != Area . HEADER && area != Area . BUTTON_BAR && area != Area . CONTENT ? dialogPadding [ 0 ] : 0 ; view . setPadding ( padding , view . getPaddingTop ( ) , view . getPaddingRight ( ) , view . getPaddingBottom ( ) ) ; }
Applies the dialog s left padding to the view of a specific area .
1,619
private boolean applyDialogPaddingTop ( final Area area , final View view ) { if ( area != Area . HEADER && area != Area . CONTENT && area != Area . BUTTON_BAR && view . getVisibility ( ) == View . VISIBLE ) { view . setPadding ( view . getPaddingLeft ( ) , dialogPadding [ 1 ] , view . getPaddingRight ( ) , view . getPaddingBottom ( ) ) ; return true ; } return false ; }
Applies the dialog s top padding to the view of a specific area .
1,620
private void applyDialogPaddingRight ( final Area area , final View view ) { int padding = area != Area . HEADER && area != Area . BUTTON_BAR && area != Area . CONTENT ? dialogPadding [ 2 ] : 0 ; view . setPadding ( view . getPaddingLeft ( ) , view . getPaddingTop ( ) , padding , view . getPaddingBottom ( ) ) ; }
Applies the dialog s right padding to the view of a specific area .
1,621
private void applyDialogPaddingBottom ( final Area area , final View view ) { if ( area != Area . HEADER && area != Area . BUTTON_BAR ) { view . setPadding ( view . getPaddingLeft ( ) , view . getPaddingTop ( ) , view . getPaddingRight ( ) , dialogPadding [ 3 ] ) ; } }
Applies the dialog s bottom padding to the view of a specific area .
1,622
private Pair < Integer , Integer > addViewSpacing ( final Area previousArea , final View previousView , final Area area ) { int scrollViewPaddingTop = 0 ; int scrollViewMarginBottom = 0 ; int padding = - 1 ; if ( previousArea == Area . TITLE ) { padding = getResources ( ) . getDimensionPixelSize ( R . dimen . dialog_title_bottom_padding ) ; } else if ( previousArea == Area . MESSAGE ) { padding = getResources ( ) . getDimensionPixelSize ( R . dimen . dialog_message_bottom_padding ) ; } if ( previousArea != Area . HEADER && ! scrollableArea . isScrollable ( previousArea ) && scrollableArea . isScrollable ( area ) ) { int originalPadding = padding ; padding = originalPadding / 2 ; scrollViewPaddingTop = originalPadding - padding ; } else if ( area == Area . BUTTON_BAR && scrollableArea . isScrollable ( previousArea ) && ! scrollableArea . isScrollable ( area ) ) { int originalPadding = padding ; padding = originalPadding / 2 ; scrollViewMarginBottom = originalPadding - padding ; } if ( padding != - 1 ) { previousView . setPadding ( previousView . getPaddingLeft ( ) , previousView . getPaddingTop ( ) , previousView . getPaddingRight ( ) , previousView . getPaddingBottom ( ) + padding ) ; } return Pair . create ( scrollViewPaddingTop , scrollViewMarginBottom ) ; }
Adds spacing to the view of a specific area . The spacing is added to the view s current bottom padding .
1,623
private void inflateScrollView ( final ScrollableArea scrollableArea ) { if ( scrollView == null ) { LayoutInflater layoutInflater = LayoutInflater . from ( getContext ( ) ) ; scrollView = ( ScrollView ) layoutInflater . inflate ( R . layout . material_dialog_scroll_view , this , false ) ; scrollView . addScrollListener ( createScrollViewScrollListener ( ) ) ; scrollView . setDescendantFocusability ( ViewGroup . FOCUS_BEFORE_DESCENDANTS ) ; scrollView . setFocusableInTouchMode ( true ) ; if ( scrollableArea . getBottomScrollableArea ( ) . getIndex ( ) - scrollableArea . getTopScrollableArea ( ) . getIndex ( ) > 0 ) { LinearLayout scrollContainer = new LinearLayout ( getContext ( ) ) ; scrollContainer . setOrientation ( LinearLayout . VERTICAL ) ; scrollView . addView ( scrollContainer , ScrollView . LayoutParams . MATCH_PARENT , ScrollView . LayoutParams . MATCH_PARENT ) ; } addView ( scrollView ) ; } }
Inflates the scroll view which contains the dialog s scrollable areas if it has not been inflated yet .
1,624
private OnGlobalLayoutListener createScrollViewChildLayoutListener ( ) { return new OnGlobalLayoutListener ( ) { public void onGlobalLayout ( ) { View child = scrollView . getChildAt ( 0 ) ; int childHeight = child . getHeight ( ) ; int containerHeight = scrollView . getHeight ( ) - scrollView . getPaddingTop ( ) - scrollView . getPaddingBottom ( ) ; if ( containerHeight > childHeight ) { LinearLayout . LayoutParams layoutParams = ( LinearLayout . LayoutParams ) scrollView . getLayoutParams ( ) ; layoutParams . height = childHeight ; layoutParams . weight = 0 ; scrollView . requestLayout ( ) ; } ViewUtil . removeOnGlobalLayoutListener ( child . getViewTreeObserver ( ) , this ) ; } } ; }
Creates and returns a listener which allows to observe when the child of the dialog s scroll view has been layouted . If the scroll view s height is greater than necessary its height is reduced to match the height of its child .
1,625
private ScrollListener createScrollViewScrollListener ( ) { return new ScrollListener ( ) { public void onScrolled ( final boolean scrolledToTop , final boolean scrolledToBottom ) { adaptDividerVisibilities ( scrolledToTop , scrolledToBottom , true ) ; } } ; }
Creates and returns a listener which allows to observe when the scroll view which is contained by the dialog is scrolled .
1,626
private AbsListView . OnScrollListener createListViewScrollListener ( ) { return new AbsListView . OnScrollListener ( ) { public void onScrollStateChanged ( final AbsListView view , final int scrollState ) { } public void onScroll ( final AbsListView view , final int firstVisibleItem , final int visibleItemCount , final int totalItemCount ) { adaptDividerVisibilities ( isListViewScrolledToTop ( view ) , isListViewScrolledToBottom ( view ) , true ) ; } } ; }
Creates and returns a listener which allows to observe the list view which is contained by the dialog is scrolled .
1,627
private void adaptDividerColor ( ) { adaptDividerColor ( topDivider ) ; adaptDividerColor ( bottomDivider ) ; if ( dividers != null ) { for ( Divider divider : dividers . values ( ) ) { adaptDividerColor ( divider ) ; } } }
Adapts the color of dividers .
1,628
private void adaptDividerMargin ( ) { adaptDividerMargin ( topDivider ) ; adaptDividerMargin ( bottomDivider ) ; if ( dividers != null ) { for ( Divider divider : dividers . values ( ) ) { adaptDividerMargin ( divider ) ; } } }
Adapts the left and right margin of dividers .
1,629
private void adaptDividerMargin ( final Divider divider ) { if ( divider != null ) { ViewGroup . LayoutParams layoutParams = divider . getLayoutParams ( ) ; if ( layoutParams instanceof LayoutParams ) { ( ( LayoutParams ) layoutParams ) . leftMargin = dividerMargin ; ( ( LayoutParams ) layoutParams ) . rightMargin = dividerMargin ; } } }
Adapts the left and right margin of a specific divider .
1,630
public final void setWindowBackgroundAndInset ( final Drawable windowBackground , final Rect windowInsets ) { this . windowBackground = windowBackground ; this . windowInsets = windowInsets ; adaptWindowBackgroundAndInsets ( ) ; }
Sets the background and inset of the dialog s window .
1,631
public final void setMaxWidth ( final int maxWidth ) { if ( maxWidth != - 1 ) { Condition . INSTANCE . ensureAtLeast ( maxWidth , 1 , "The maximum width must be at least 1" ) ; } this . maxWidth = maxWidth ; requestLayout ( ) ; }
Sets the maximum width of the view .
1,632
public final void setMaxHeight ( final int maxHeight ) { if ( maxHeight != - 1 ) { Condition . INSTANCE . ensureAtLeast ( maxHeight , 1 , "The maximum height must be at least 1" ) ; } this . maxHeight = maxHeight ; requestLayout ( ) ; }
Sets the maximum height of the view .
1,633
public final void setScrollableArea ( final ScrollableArea scrollableArea ) { Condition . INSTANCE . ensureNotNull ( scrollableArea , "The scrollable area may not be null" ) ; this . scrollableArea = scrollableArea ; addAreas ( ) ; }
Sets the scrollable area of the dialog .
1,634
public final void addAreas ( final Map < ViewType , View > areas ) { this . areas = new TreeMap < > ( new AreaComparator ( ) ) ; this . dividers = new HashMap < > ( ) ; for ( Map . Entry < ViewType , View > entry : areas . entrySet ( ) ) { ViewType viewType = entry . getKey ( ) ; View view = entry . getValue ( ) ; if ( viewType instanceof AreaViewType ) { this . areas . put ( ( ( AreaViewType ) viewType ) . getArea ( ) , view ) ; } else if ( viewType instanceof DividerViewType && view instanceof Divider ) { this . dividers . put ( ( ( DividerViewType ) viewType ) . getLocation ( ) , ( Divider ) view ) ; } } addAreas ( ) ; addDividers ( ) ; registerScrollLayoutListener ( ) ; }
Adds the different areas of a dialog to the root view .
1,635
public final void setDialog ( final MaterialDialog dialog ) { Condition . INSTANCE . ensureNotNull ( dialog , "The dialog may not be null" ) ; this . dialog = dialog ; }
Sets the dialog which contains the view pager .
1,636
private void inflateEditText ( ) { LayoutInflater inflater = LayoutInflater . from ( getContext ( ) ) ; View view = inflater . inflate ( R . layout . edit_text_dialog , getRootView ( ) , false ) ; getDialog ( ) . setView ( view ) ; View textInputLayoutView = view . findViewById ( R . id . text_input_layout ) ; textInputLayout = textInputLayoutView instanceof TextInputLayout ? ( TextInputLayout ) textInputLayoutView : null ; View editTextView = view . findViewById ( R . id . edit_text ) ; editText = editTextView instanceof EditText ? ( EditText ) editTextView : null ; adaptHint ( ) ; adaptErrorColor ( ) ; adaptHelperTextColor ( ) ; adaptHelperText ( ) ; adaptText ( ) ; validate ( ) ; adaptTextChangedListener ( ) ; adaptFocusChangeListener ( ) ; }
Inflates the dialog s edit text widget .
1,637
private void adaptText ( ) { if ( editText != null ) { editText . setText ( text ) ; if ( text != null ) { editText . setSelection ( text . length ( ) ) ; } } }
Adapts the text of the edit text widget which is contained by the dialog .
1,638
private void adaptHint ( ) { if ( textInputLayout != null ) { textInputLayout . setHint ( hint ) ; } else if ( editText != null ) { editText . setHint ( hint ) ; } }
Adapts the hint of the dialog s edit text widget .
1,639
private void adaptHelperText ( ) { if ( textInputLayout != null && TextUtils . isEmpty ( getText ( ) ) ) { textInputLayout . setHelperText ( helperText ) ; textInputLayout . setHelperTextEnabled ( true ) ; } }
Adapts the helper text of the dialog s edit text widget .
1,640
private void showErrorText ( final CharSequence errorText ) { if ( textInputLayout != null ) { if ( TextUtils . isEmpty ( errorText ) ) { textInputLayout . setError ( null ) ; textInputLayout . setErrorEnabled ( false ) ; adaptHelperTextColor ( ) ; } else { textInputLayout . setHelperText ( null ) ; textInputLayout . setHelperTextEnabled ( false ) ; textInputLayout . setError ( errorText ) ; textInputLayout . setErrorEnabled ( true ) ; } } }
Shows an error text .
1,641
private void requestFocus ( ) { Window window = getWindow ( ) ; if ( window != null ) { window . setSoftInputMode ( WindowManager . LayoutParams . SOFT_INPUT_STATE_ALWAYS_VISIBLE ) ; } if ( editText != null ) { editText . requestFocus ( ) ; } }
Requests the focus and displays the keyboard .
1,642
private void adaptPositiveButtonEnableState ( final boolean enabled ) { Button button = getDialog ( ) . getButton ( DialogInterface . BUTTON_POSITIVE ) ; if ( button != null ) { button . setEnabled ( enabled ) ; } }
Adapts the enable state of the dialog s positive button .
1,643
private TextWatcher createTextChangedListener ( ) { return new TextWatcher ( ) { public void beforeTextChanged ( final CharSequence text , final int start , final int count , final int after ) { } public void afterTextChanged ( final Editable text ) { } public void onTextChanged ( final CharSequence text , final int start , final int before , final int count ) { EditTextDialogDecorator . this . text = text ; if ( validateOnValueChange ) { validate ( ) ; } } } ; }
Creates and returns a listener which allows to observe when the text of the dialog s edit text has changed .
1,644
private View . OnFocusChangeListener createFocusChangeListener ( ) { return new View . OnFocusChangeListener ( ) { public void onFocusChange ( final View v , final boolean hasFocus ) { if ( ! hasFocus && validateOnFocusLost ) { validate ( ) ; } } } ; }
Creates and returns a listener which allows to validate the dialog s edit text widget when its focus got lost .
1,645
private void notifyOnValidationFailure ( final Validator < CharSequence > validator ) { for ( ValidationListener < CharSequence > validationListener : validationListeners ) { validationListener . onValidationFailure ( this , validator ) ; } }
Notifies the listeners that the validation of the dialog s edit text widget has failed .
1,646
private void inflateListView ( final ViewGroup contentContainer ) { View listView = contentContainer . findViewById ( android . R . id . list ) ; this . listView = listView instanceof RecyclerView ? ( RecyclerView ) listView : null ; if ( this . listView == null && ! getDialog ( ) . isCustomViewUsed ( ) ) { LayoutInflater layoutInflater = LayoutInflater . from ( getContext ( ) ) ; View view = layoutInflater . inflate ( R . layout . material_dialog_list_view , contentContainer , false ) ; this . listView = view . findViewById ( android . R . id . list ) ; getDialog ( ) . setView ( view ) ; this . inflatedCustomView = true ; } else { this . inflatedCustomView = false ; } View divider = contentContainer . findViewById ( R . id . list_divider ) ; this . listDivider = divider instanceof Divider ? ( Divider ) divider : null ; }
Inflates the list view which is used to show the dialog s list items .
1,647
private void attachAdapter ( ) { if ( listView != null ) { if ( adapter != null ) { listView . setHasFixedSize ( false ) ; listView . setLayoutManager ( layoutManager ) ; listView . setAdapter ( adapter ) ; listView . setVisibility ( adapter != null ? View . VISIBLE : View . GONE ) ; adapter . setOnItemSelectedListener ( listViewItemSelectedListener ) ; initializeSelectionListener ( ) ; initializeCheckedItems ( ) ; adaptItemColor ( ) ; adaptItemTypeface ( ) ; } else { if ( inflatedCustomView ) { getDialog ( ) . setView ( null ) ; } listView = null ; } } }
Attaches the adapter to the dialog s list view .
1,648
private void initializeCheckedItems ( ) { if ( checkedItems != null ) { for ( int i = 0 ; i < checkedItems . length ; i ++ ) { adapter . setItemChecked ( i , checkedItems [ i ] ) ; } } }
Initializes the list items which are checked by default .
1,649
private boolean [ ] getCheckedItems ( ) { if ( listView != null && adapter != null ) { boolean [ ] result = new boolean [ adapter . getItemCount ( ) ] ; for ( int i = 0 ; i < result . length ; i ++ ) { result [ i ] = adapter . isItemChecked ( i ) ; } return result ; } else { return checkedItems ; } }
Returns an array which identifies the currently checked list items .
1,650
private void initializeSelectionListener ( ) { ChoiceMode choiceMode = adapter . getChoiceMode ( ) ; if ( choiceMode instanceof MultipleChoiceMode ) { adapter . setOnItemClickListener ( new OnMultiChoiceClickListenerWrapper ( multiChoiceListener , getDialog ( ) , 0 ) ) ; } else if ( choiceMode instanceof SingleChoiceMode ) { adapter . setOnItemClickListener ( new OnItemClickListenerWrapper ( singleChoiceListener , getDialog ( ) , 0 ) ) ; } else { adapter . setOnItemClickListener ( new OnItemClickListenerWrapper ( singleChoiceListener , getDialog ( ) , DialogInterface . BUTTON_POSITIVE ) ) ; } }
Initializes the listener which should be notified when the selection of a list item of the dialog has been changed .
1,651
private void adaptItemColor ( ) { if ( adapter != null ) { RecyclerView . Adapter < ? > wrappedAdapter = adapter . getWrappedAdapter ( ) ; if ( wrappedAdapter instanceof ArrayRecyclerViewAdapter ) { ( ( ArrayRecyclerViewAdapter ) wrappedAdapter ) . setItemColor ( itemColor ) ; } } }
Adapts the color of the dialog s list items .
1,652
private void adaptItemTypeface ( ) { if ( adapter != null && itemTypeface != null ) { RecyclerView . Adapter < ? > wrappedAdapter = adapter . getWrappedAdapter ( ) ; if ( wrappedAdapter instanceof ArrayRecyclerViewAdapter ) { ( ( ArrayRecyclerViewAdapter ) wrappedAdapter ) . setItemTypeface ( itemTypeface ) ; } } }
Adapts the typeface of the dialog s list items .
1,653
private void adaptButtonBar ( ) { if ( buttonBarContainer != null ) { inflateButtonBar ( ) ; adaptPositiveButton ( ) ; adaptNegativeButton ( ) ; adaptNeutralButton ( ) ; adaptButtonTextColor ( ) ; adaptButtonTypeface ( ) ; adaptButtonBarContainerVisibility ( ) ; adaptButtonBarDividerVisibility ( ) ; } }
Adapts the button bar .
1,654
private void adaptButtonTypeface ( ) { if ( buttonTypeface != null ) { if ( positiveButton != null ) { positiveButton . setTypeface ( buttonTypeface ) ; } if ( neutralButton != null ) { neutralButton . setTypeface ( buttonTypeface ) ; } if ( negativeButton != null ) { negativeButton . setTypeface ( buttonTypeface ) ; } } }
Adapts the typeface of the dialog s buttons .
1,655
private void adaptPositiveButton ( ) { if ( positiveButton != null ) { positiveButton . setText ( positiveButtonText != null ? positiveButtonText . toString ( ) . toUpperCase ( Locale . getDefault ( ) ) : null ) ; OnClickListenerWrapper onClickListener = new OnClickListenerWrapper ( positiveButtonListener , true , getDialog ( ) , DialogInterface . BUTTON_POSITIVE ) ; positiveButton . setOnClickListener ( onClickListener ) ; positiveButton . setVisibility ( ! TextUtils . isEmpty ( positiveButtonText ) ? View . VISIBLE : View . GONE ) ; adaptButtonBarContainerVisibility ( ) ; } }
Adapts the dialog s positive button .
1,656
private void adaptNeutralButton ( ) { if ( neutralButton != null ) { neutralButton . setText ( neutralButtonText != null ? neutralButtonText . toString ( ) . toUpperCase ( Locale . getDefault ( ) ) : null ) ; OnClickListenerWrapper onClickListener = new OnClickListenerWrapper ( neutralButtonListener , false , getDialog ( ) , DialogInterface . BUTTON_NEUTRAL ) ; neutralButton . setOnClickListener ( onClickListener ) ; neutralButton . setVisibility ( ! TextUtils . isEmpty ( neutralButtonText ) ? View . VISIBLE : View . GONE ) ; adaptButtonBarContainerVisibility ( ) ; } }
Adapts the dialog s neutral button .
1,657
private void adaptNegativeButton ( ) { if ( negativeButton != null ) { negativeButton . setText ( negativeButtonText != null ? negativeButtonText . toString ( ) . toUpperCase ( Locale . getDefault ( ) ) : null ) ; OnClickListenerWrapper onClickListener = new OnClickListenerWrapper ( negativeButtonListener , false , getDialog ( ) , DialogInterface . BUTTON_NEGATIVE ) ; negativeButton . setOnClickListener ( onClickListener ) ; negativeButton . setVisibility ( ! TextUtils . isEmpty ( negativeButtonText ) ? View . VISIBLE : View . GONE ) ; adaptButtonBarContainerVisibility ( ) ; } }
Adapts the dialog s negative button .
1,658
private void adaptButtonBarContainerVisibility ( ) { if ( buttonBarContainer != null ) { if ( TextUtils . isEmpty ( positiveButtonText ) && TextUtils . isEmpty ( neutralButtonText ) && TextUtils . isEmpty ( negativeButtonText ) ) { buttonBarContainer . setVisibility ( View . GONE ) ; } else { buttonBarContainer . setVisibility ( View . VISIBLE ) ; } } }
Adapts the visibility of the parent view which contains the dialog s buttons .
1,659
private void adaptButtonBarDividerVisibility ( ) { if ( buttonBarDivider != null ) { buttonBarDivider . setVisibility ( showButtonBarDivider ? View . VISIBLE : View . GONE ) ; buttonBarDivider . setVisibleByDefault ( showButtonBarDivider ) ; } }
Adapts the visibility of the divider which is shown above the dialog s buttons .
1,660
public void setItemTypeface ( final Typeface typeface ) { Condition . INSTANCE . ensureNotNull ( typeface , "The typeface may not be null" ) ; this . itemTypeface = typeface ; notifyDataSetChanged ( ) ; }
Sets the typeface of the adapter s items .
1,661
private void initialize ( final int themeResourceId ) { int themeId = themeResourceId ; if ( themeId == 0 ) { TypedValue typedValue = new TypedValue ( ) ; getContext ( ) . getTheme ( ) . resolveAttribute ( R . attr . materialDialogTheme , typedValue , true ) ; themeId = typedValue . resourceId ; themeId = themeId != 0 ? themeId : R . style . MaterialDialog_Light ; } setContext ( new ContextThemeWrapper ( getContext ( ) , themeId ) ) ; this . themeResourceId = themeId ; obtainStyledAttributes ( themeId ) ; }
Initializes the builder .
1,662
private void obtainFullscreen ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogFullscreen } ) ; setFullscreen ( typedArray . getBoolean ( 0 , false ) ) ; }
Obtains the boolean value which specified whether the dialog should be shown fullscreen or not from a specific theme .
1,663
private void obtainGravity ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogGravity } ) ; setGravity ( typedArray . getInteger ( 0 , Dialog . Gravity . CENTER ) ) ; }
Obtains the gravity from a specific theme .
1,664
private void obtainWidth ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogWidth } ) ; int defaultValue = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . dialog_width ) ; try { setWidth ( typedArray . getDimensionPixelSize ( 0 , defaultValue ) ) ; } catch ( Resources . NotFoundException | UnsupportedOperationException e ) { setWidth ( typedArray . getInteger ( 0 , defaultValue ) ) ; } }
Obtains the width from a specific theme .
1,665
private void obtainHeight ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogHeight } ) ; int defaultValue = Dialog . WRAP_CONTENT ; try { setHeight ( typedArray . getDimensionPixelSize ( 0 , defaultValue ) ) ; } catch ( Resources . NotFoundException | UnsupportedOperationException e ) { setHeight ( typedArray . getInteger ( 0 , defaultValue ) ) ; } }
Obtains the height from a specific theme .
1,666
private void obtainMaxWidth ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogMaxWidth } ) ; int defaultValue ; try { defaultValue = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . dialog_max_width ) ; } catch ( Resources . NotFoundException | UnsupportedOperationException e ) { defaultValue = - 1 ; } try { setMaxWidth ( typedArray . getDimensionPixelSize ( 0 , defaultValue ) ) ; } catch ( Resources . NotFoundException | UnsupportedOperationException e ) { setMaxWidth ( - 1 ) ; } }
Obtains the maximum width from a specific theme .
1,667
private void obtainMaxHeight ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogMaxHeight } ) ; int defaultValue ; try { defaultValue = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . dialog_max_height ) ; } catch ( Resources . NotFoundException | UnsupportedOperationException e ) { defaultValue = - 1 ; } try { setMaxHeight ( typedArray . getDimensionPixelSize ( 0 , defaultValue ) ) ; } catch ( Resources . NotFoundException | UnsupportedOperationException e ) { setMaxHeight ( - 1 ) ; } }
Obtains the maximum height from a specific theme .
1,668
private void obtainMargin ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogMarginLeft , R . attr . materialDialogMarginTop , R . attr . materialDialogMarginRight , R . attr . materialDialogMarginBottom } ) ; int defaultHorizontalMargin = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . dialog_horizontal_margin ) ; int defaultVerticalMargin = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . dialog_vertical_margin ) ; int left = typedArray . getDimensionPixelSize ( 0 , defaultHorizontalMargin ) ; int top = typedArray . getDimensionPixelSize ( 1 , defaultVerticalMargin ) ; int right = typedArray . getDimensionPixelSize ( 2 , defaultHorizontalMargin ) ; int bottom = typedArray . getDimensionPixelSize ( 3 , defaultVerticalMargin ) ; setMargin ( left , top , right , bottom ) ; }
Obtains the margin from a specific theme .
1,669
private void obtainFitsSystemWindows ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogFitsSystemWindowsLeft , R . attr . materialDialogFitsSystemWindowsTop , R . attr . materialDialogFitsSystemWindowsRight , R . attr . materialDialogFitsSystemWindowsBottom } ) ; boolean left = typedArray . getBoolean ( 0 , true ) ; boolean top = typedArray . getBoolean ( 1 , true ) ; boolean right = typedArray . getBoolean ( 2 , true ) ; boolean bottom = typedArray . getBoolean ( 3 , true ) ; setFitsSystemWindows ( left , top , right , bottom ) ; }
Obtains whether the dialog s content should be inset from a specific theme .
1,670
private void obtainWindowBackground ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogWindowBackground } ) ; int resourceId = typedArray . getResourceId ( 0 , 0 ) ; if ( resourceId != 0 ) { setWindowBackground ( resourceId ) ; } else { setWindowBackground ( R . drawable . material_dialog_background ) ; } }
Obtains the window background from a specific theme .
1,671
private void obtainBackground ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogBackground } ) ; int resourceId = typedArray . getResourceId ( 0 , 0 ) ; if ( resourceId != 0 ) { setBackground ( resourceId ) ; } else { setBackgroundColor ( ContextCompat . getColor ( getContext ( ) , R . color . dialog_background_light ) ) ; } }
Obtains the background from a specific theme .
1,672
private void obtainMessageColor ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogMessageColor } ) ; int defaultColor = ThemeUtil . getColor ( getContext ( ) , themeResourceId , android . R . attr . textColorSecondary ) ; setMessageColor ( typedArray . getColor ( 0 , defaultColor ) ) ; }
Obtains the message color from a specific theme .
1,673
private void obtainTitleColor ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogTitleColor } ) ; int defaultColor = ThemeUtil . getColor ( getContext ( ) , themeResourceId , android . R . attr . textColorPrimary ) ; setTitleColor ( typedArray . getColor ( 0 , defaultColor ) ) ; }
Obtains the title color from a specific theme .
1,674
private void obtainIconTintList ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogIconTint } ) ; setIconTintList ( typedArray . getColorStateList ( 0 ) ) ; }
Obtains the color state list which is used to tint the icon of the dialog from a specific theme .
1,675
private void obtainScrollableArea ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogScrollableAreaTop , R . attr . materialDialogScrollableAreaBottom } ) ; int topIndex = typedArray . getInt ( 0 , - 1 ) ; int bottomIndex = typedArray . getInt ( 1 , - 1 ) ; if ( topIndex != - 1 ) { Area top = Area . fromIndex ( topIndex ) ; if ( bottomIndex != - 1 ) { Area bottom = Area . fromIndex ( bottomIndex ) ; setScrollableArea ( top , bottom ) ; } else { setScrollableArea ( top ) ; } } else { setScrollableArea ( null , null ) ; } }
Obtains the scrollable area from a specific theme .
1,676
private void obtainShowDividersOnScroll ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogShowDividersOnScroll } ) ; showDividersOnScroll ( typedArray . getBoolean ( 0 , true ) ) ; }
Obtains whether the dividers which are located above and below the dialog s scrollable areas should be shown when scrolling or not from a specific theme .
1,677
private void obtainDividerColor ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogDividerColor } ) ; int defaultColor = ContextCompat . getColor ( getContext ( ) , R . color . divider_color_light ) ; setDividerColor ( typedArray . getColor ( 0 , defaultColor ) ) ; }
Obtains the color of dividers from a specific theme .
1,678
private void obtainDividerMargin ( final int themeResourceId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( themeResourceId , new int [ ] { R . attr . materialDialogDividerMargin } ) ; setDividerMargin ( typedArray . getDimensionPixelSize ( 0 , 0 ) ) ; }
Obtains the left and right margin of dividers from a specific theme .
1,679
protected void obtainStyledAttributes ( final int themeResourceId ) { obtainFullscreen ( themeResourceId ) ; obtainGravity ( themeResourceId ) ; obtainWidth ( themeResourceId ) ; obtainHeight ( themeResourceId ) ; obtainMaxWidth ( themeResourceId ) ; obtainMaxHeight ( themeResourceId ) ; obtainMargin ( themeResourceId ) ; obtainPadding ( themeResourceId ) ; obtainFitsSystemWindows ( themeResourceId ) ; obtainWindowBackground ( themeResourceId ) ; obtainBackground ( themeResourceId ) ; obtainMessageColor ( themeResourceId ) ; obtainTitleColor ( themeResourceId ) ; obtainIconTintList ( themeResourceId ) ; obtainScrollableArea ( themeResourceId ) ; obtainShowDividersOnScroll ( themeResourceId ) ; obtainDividerColor ( themeResourceId ) ; obtainDividerMargin ( themeResourceId ) ; }
Obtains all relevant attributes from the current theme .
1,680
public BuilderType setOnShowListener ( final DialogInterface . OnShowListener listener ) { getProduct ( ) . setOnShowListener ( listener ) ; return self ( ) ; }
Sets the listener which should be notified when the dialog has been shown .
1,681
public final BuilderType setOnDismissListener ( final DialogInterface . OnDismissListener listener ) { getProduct ( ) . setOnDismissListener ( listener ) ; return self ( ) ; }
Sets the listener which should be notified when the dialog which is created by the builder is dismissed for any reason .
1,682
public final BuilderType setMargin ( final int left , final int top , final int right , final int bottom ) { getProduct ( ) . setMargin ( left , top , right , bottom ) ; return self ( ) ; }
Sets the margin of the dialog which is created by the builder .
1,683
public final BuilderType setPadding ( final int left , final int top , final int right , final int bottom ) { getProduct ( ) . setPadding ( left , top , right , bottom ) ; return self ( ) ; }
Sets the padding of the dialog which is created by the builder .
1,684
public final BuilderType setFitsSystemWindows ( final boolean left , final boolean top , final boolean right , final boolean bottom ) { getProduct ( ) . setFitsSystemWindows ( left , top , right , bottom ) ; return self ( ) ; }
Sets whether the dialog which is created by the builder should account for system screen decorations such as the status bar and inset its content or not .
1,685
public final BuilderType setScrollableArea ( final Area top , final Area bottom ) { getProduct ( ) . setScrollableArea ( top , bottom ) ; return self ( ) ; }
Sets the areas of the dialog which is created by the builder which should be scrollable .
1,686
protected final void setInterpolator ( final Interpolator interpolator ) { Condition . INSTANCE . ensureNotNull ( interpolator , "The interpolator may not be null" ) ; this . interpolator = interpolator ; }
Sets the interpolator which should be used by the animation .
1,687
protected final void setAlpha ( final float alpha ) { Condition . INSTANCE . ensureAtLeast ( alpha , 0 , "The alpha must be at least 0" ) ; Condition . INSTANCE . ensureAtMaximum ( alpha , 1 , "The alpha must be at maximum 1" ) ; this . alpha = alpha ; }
Sets the alpha which should be used by the animation .
1,688
private View . OnTouchListener createCanceledOnTouchListener ( ) { return new View . OnTouchListener ( ) { @ SuppressLint ( "ClickableViewAccessibility" ) public boolean onTouch ( final View v , final MotionEvent event ) { return isCanceledOnTouchOutside ( ) && ! isFullscreen ( ) && onCanceledOnTouchOutside ( ) ; } } ; }
Creates and returns a listener which allows to cancel the dialog when touched outside the window .
1,689
private Map < ViewType , View > attachDecorators ( final Window window , final DialogRootView rootView , final View view ) { Map < ViewType , View > result = new HashMap < > ( ) ; for ( AbstractDecorator < ? , ? > decorator : decorators ) { result . putAll ( decorator . attach ( window , view , result , null ) ) ; decorator . addAreaListener ( rootView ) ; } return result ; }
Attaches all registered decorators to the dialog .
1,690
private void initializeFloatingActionButton ( ) { floatingActionButton = findViewById ( R . id . floating_action_button ) ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . LOLLIPOP ) { floatingActionButton . show ( ) ; floatingActionButton . setOnClickListener ( createFloatingActionButtonListener ( ) ) ; } else { floatingActionButton . hide ( ) ; } }
Initializes the floating action button which allows to show an alert dialog using a circle reveal animation .
1,691
private OnClickListener createFloatingActionButtonListener ( ) { return new OnClickListener ( ) { public void onClick ( final View v ) { fragment . showAlertDialog ( v ) ; } } ; }
Creates and returns a listener which allows to show an alert dialog using a circle reveal animation when the corresponding floating action button is clicked .
1,692
private RecyclerView . OnScrollListener createScrollListener ( ) { return new RecyclerView . OnScrollListener ( ) { private boolean scrollingUp ; public void onScrollStateChanged ( final RecyclerView recyclerView , final int newState ) { } public void onScrolled ( final RecyclerView recyclerView , final int dx , final int dy ) { boolean isScrollingUp = dy < 0 ; if ( scrollingUp != isScrollingUp ) { scrollingUp = isScrollingUp ; if ( scrollingUp ) { floatingActionButton . show ( ) ; } else { floatingActionButton . hide ( ) ; } } } } ; }
Creates and returns a listener which allows to hide or show the activity s floating action button when the preferences which are shown by the activity s fragment are scrolled .
1,693
private ViewPropertyAnimator createAnimator ( final View animatedView , final FadeAnimation animation , final AnimatorListener listener , final boolean show ) { if ( animation . getAlpha ( ) != null ) { ViewPropertyAnimator animator = animatedView . animate ( ) . setInterpolator ( animation . getInterpolator ( ) ) . setDuration ( getDuration ( animatedView , animation ) ) . setStartDelay ( animation . getStartDelay ( ) ) . setListener ( listener ) ; if ( show ) { animatedView . setAlpha ( animation . getAlpha ( ) ) ; animator . alpha ( 1 ) ; } else { animatedView . setAlpha ( 1f ) ; animator . alpha ( animation . getAlpha ( ) ) ; } return animator ; } return null ; }
Creates an animator which should be used for a fade animation .
1,694
private ViewPropertyAnimator createAnimator ( final View animatedView , final RectangleRevealAnimation animation , final AnimatorListener listener ) { if ( animation . getX ( ) != null || animation . getY ( ) != null || animation . getWidth ( ) != null || animation . getHeight ( ) != null || animation . getAlpha ( ) != null ) { return animatedView . animate ( ) . setInterpolator ( animation . getInterpolator ( ) ) . setDuration ( getDuration ( animatedView , animation ) ) . setStartDelay ( animation . getStartDelay ( ) ) . setListener ( listener ) ; } return null ; }
Creates an animator which should be used for a rectangular reveal animation .
1,695
private void configureShowAnimator ( final View animatedView , final RectangleRevealAnimation animation , final ViewPropertyAnimator animator ) { int horizontalWindowInset = getDialog ( ) . getWindowInsetLeft ( ) + getDialog ( ) . getWindowInsetRight ( ) ; int verticalWindowInset = getDialog ( ) . getWindowInsetTop ( ) + getDialog ( ) . getWindowInsetBottom ( ) ; float translationX = 0 ; float translationY = 0 ; if ( animation . getX ( ) != null ) { translationX = animation . getX ( ) - animatedView . getLeft ( ) - horizontalWindowInset ; } if ( animation . getY ( ) != null ) { translationY = animation . getY ( ) - animatedView . getTop ( ) - verticalWindowInset ; } if ( animation . getWidth ( ) != null ) { int viewWidth = animatedView . getWidth ( ) - horizontalWindowInset ; translationX -= ( float ) ( viewWidth - animation . getWidth ( ) ) / 2f ; animatedView . setScaleX ( ( float ) animation . getWidth ( ) / ( float ) viewWidth ) ; animator . scaleX ( 1 ) ; } if ( animation . getHeight ( ) != null ) { int viewHeight = animatedView . getHeight ( ) - verticalWindowInset ; translationY -= ( float ) ( viewHeight - animation . getHeight ( ) ) / 2f ; animatedView . setScaleY ( ( float ) animation . getHeight ( ) / ( float ) viewHeight ) ; animator . scaleY ( 1 ) ; } if ( animation . getAlpha ( ) != null ) { animatedView . setAlpha ( animation . getAlpha ( ) ) ; animator . alpha ( 1 ) ; } if ( translationX != 0 ) { animatedView . setTranslationX ( translationX ) ; animator . translationX ( 0 ) ; } if ( translationY != 0 ) { animatedView . setTranslationY ( translationY ) ; animator . translationY ( 0 ) ; } }
Configures an animator which should be used to show the dialog using a rectangular reveal animation .
1,696
private Animator createAnimator ( final View animatedView , final View rootView , final CircleRevealAnimation animation , final AnimatorListener listener , final boolean show ) { if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . LOLLIPOP ) { long duration = getDuration ( animatedView , animation ) ; int horizontalDistance = Math . max ( Math . abs ( rootView . getLeft ( ) - animation . getX ( ) ) , Math . abs ( rootView . getRight ( ) - animation . getX ( ) ) ) ; int verticalDistance = Math . max ( Math . abs ( rootView . getTop ( ) - animation . getY ( ) ) , Math . abs ( rootView . getBottom ( ) - animation . getY ( ) ) ) ; float maxRadius = ( float ) Math . sqrt ( Math . pow ( horizontalDistance , 2 ) + Math . pow ( verticalDistance , 2 ) ) ; Animator animator = ViewAnimationUtils . createCircularReveal ( animatedView , animation . getX ( ) , animation . getY ( ) , show ? animation . getRadius ( ) : maxRadius , show ? maxRadius : animation . getRadius ( ) ) ; animator . setInterpolator ( animation . getInterpolator ( ) ) ; animator . setStartDelay ( animation . getStartDelay ( ) ) ; animator . setDuration ( duration ) ; if ( listener != null ) { animator . addListener ( listener ) ; } if ( animation . getAlpha ( ) != null ) { ObjectAnimator alphaAnimator = ObjectAnimator . ofFloat ( animatedView , "alpha" , show ? animation . getAlpha ( ) : 1 , show ? 1 : animation . getAlpha ( ) ) ; alphaAnimator . setInterpolator ( animation . getInterpolator ( ) ) ; alphaAnimator . setStartDelay ( animation . getStartDelay ( ) ) ; alphaAnimator . setDuration ( duration ) ; AnimatorSet animatorSet = new AnimatorSet ( ) ; animatorSet . playTogether ( animator , alphaAnimator ) ; return animatorSet ; } return animator ; } return null ; }
Creates an animator which should be used for a circle reveal animation .
1,697
private long getDuration ( final View animatedView , final DialogAnimation animation ) { double scale = 1 ; if ( animatedView . getAnimation ( ) != null ) { scale = ( double ) ( System . currentTimeMillis ( ) - animatedView . getAnimation ( ) . getStartTime ( ) ) / ( double ) animatedView . getAnimation ( ) . getDuration ( ) ; animatedView . getAnimation ( ) . cancel ( ) ; } return Math . round ( animation . getDuration ( ) * scale ) ; }
Returns the duration which should be used for an animation depending on whether a previous animation is still running or not .
1,698
private AnimatorListener createHideAnimationListener ( final View animatedView , final AnimatorListener listener ) { return new AnimatorListener ( ) { public void onAnimationStart ( final Animator animation ) { if ( listener != null ) { listener . onAnimationStart ( animation ) ; } } public void onAnimationEnd ( final Animator animation ) { animatedView . setVisibility ( View . GONE ) ; if ( listener != null ) { listener . onAnimationEnd ( animation ) ; } } public void onAnimationCancel ( final Animator animation ) { if ( listener != null ) { listener . onAnimationCancel ( animation ) ; } } public void onAnimationRepeat ( final Animator animation ) { if ( listener != null ) { listener . onAnimationRepeat ( animation ) ; } } } ; }
Creates and returns an animation listener which allows to hide the animated view once the animation is finished .
1,699
public final boolean showAnimated ( final DialogAnimation animation , final AnimatorListener listener ) { hidden = false ; if ( animation != null ) { Window window = getWindow ( ) ; View view = getRootView ( ) ; if ( view != null && window != null ) { View animatedView = getDialog ( ) . isFullscreen ( ) ? window . getDecorView ( ) : view ; if ( animation instanceof FadeAnimation ) { FadeAnimation fadeAnimation = ( FadeAnimation ) animation ; ViewPropertyAnimator animator = createAnimator ( animatedView , fadeAnimation , listener , true ) ; if ( animator != null ) { animator . start ( ) ; return true ; } } else if ( animation instanceof RectangleRevealAnimation ) { RectangleRevealAnimation rectangleRevealAnimation = ( RectangleRevealAnimation ) animation ; ViewPropertyAnimator animator = createAnimator ( animatedView , rectangleRevealAnimation , listener ) ; if ( animator != null ) { configureShowAnimator ( animatedView , rectangleRevealAnimation , animator ) ; animator . start ( ) ; return true ; } } else if ( animation instanceof CircleRevealAnimation ) { CircleRevealAnimation circleRevealAnimation = ( CircleRevealAnimation ) animation ; Animator animator = createAnimator ( window . getDecorView ( ) , animatedView , circleRevealAnimation , listener , true ) ; if ( animator != null ) { animator . start ( ) ; return true ; } } else { throw new RuntimeException ( "Unknown type of animation: " + animation . getClass ( ) . getSimpleName ( ) ) ; } } } return false ; }
Shows the dialog in an animated manner according to a specific animation .