idx
int64
0
41.2k
question
stringlengths
74
4.04k
target
stringlengths
7
750
24,200
public static JScrollPane createVerticalScrollPane ( final JComponent component ) { JScrollPane scrollPane = new JScrollPane ( component ) { private static final long serialVersionUID = - 177913025197077320L ; public Dimension getPreferredSize ( ) { Dimension d = super . getPreferredSize ( ) ; if ( super . isPreferredSizeSet ( ) ) { return d ; } JScrollBar scrollBar = getVerticalScrollBar ( ) ; Dimension sd = scrollBar . getPreferredSize ( ) ; d . width += sd . width ; return d ; } public boolean isValidateRoot ( ) { return false ; } } ; return scrollPane ; }
Creates a JScrollPane for vertically scrolling the given component . The scroll pane will take into account that the vertical scroll bar will be shown when needed and return a preferred size that takes the width of this scroll bar into account so that when the vertical scroll bar appears the contained component can still have its preferred width .
24,201
public boolean addSorted ( E element ) { boolean added = false ; added = super . add ( element ) ; Comparable < E > cmp = ( Comparable < E > ) element ; for ( int i = size ( ) - 1 ; i > 0 && cmp . compareTo ( get ( i - 1 ) ) < 0 ; i -- ) Collections . swap ( this , i , i - 1 ) ; return added ; }
adds an element to the list in its place based on natural order . allows duplicates .
24,202
public boolean addSorted ( E element , boolean allowDuplicates ) { boolean added = false ; if ( ! allowDuplicates ) { if ( this . contains ( element ) ) { System . err . println ( "item is a duplicate" ) ; return added ; } } added = super . add ( element ) ; Comparable < E > cmp = ( Comparable < E > ) element ; for ( int i = size ( ) - 1 ; i > 0 && cmp . compareTo ( get ( i - 1 ) ) < 0 ; i -- ) Collections . swap ( this , i , i - 1 ) ; return added ; }
adds an element to the list in its place based on natural order .
24,203
private void prepareMenu ( Container menu , Component component , int x , int y ) { int n = menu . getComponentCount ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Component menuComponent = popupMenu . getComponent ( i ) ; if ( menuComponent instanceof JMenu ) { JMenu subMenu = ( JMenu ) menuComponent ; prepareMenu ( subMenu , component , x , y ) ; } if ( menuComponent instanceof AbstractButton ) { AbstractButton abstractButton = ( AbstractButton ) menuComponent ; Action action = abstractButton . getAction ( ) ; if ( action != null && action instanceof LocationBasedAction ) { LocationBasedAction locationBasedAction = ( LocationBasedAction ) action ; locationBasedAction . prepareShow ( component , x , y ) ; } } } }
Prepare the given menu recursively with the given parameters
24,204
private void removeColumn ( int index ) { TableColumn column = tableColumns . get ( index ) ; column . removePropertyChangeListener ( widthListener ) ; tableColumns . remove ( index ) ; JComponent component = customComponents . remove ( index ) ; remove ( component ) ; if ( componentRemover != null ) { componentRemover . accept ( index ) ; } }
Remove the column and the custom component at the given index
24,205
private void addColumn ( int index ) { TableColumnModel columnModel = getColumnModel ( ) ; TableColumn column = columnModel . getColumn ( index ) ; while ( tableColumns . size ( ) - 1 < index ) { tableColumns . add ( null ) ; } tableColumns . set ( index , column ) ; column . addPropertyChangeListener ( widthListener ) ; JComponent component = componentFactory . apply ( index ) ; while ( customComponents . size ( ) - 1 < index ) { customComponents . add ( null ) ; } customComponents . set ( index , component ) ; add ( component ) ; }
Add the column and the custom component at the given index
24,206
private void updateCustomComponentBounds ( ) { if ( customComponents == null ) { return ; } if ( table == null ) { return ; } for ( int i = 0 ; i < customComponents . size ( ) ; i ++ ) { JComponent component = customComponents . get ( i ) ; Rectangle rect = getHeaderRect ( i ) ; rect . height = customComponentHeight ; component . setBounds ( rect ) ; } revalidate ( ) ; }
Update the bounds of all custom components based on the current column widths
24,207
private void initialiseLifecycleObserver ( Application application ) { LifeCycleController . registerLifeCycleObserver ( application , new LifecycleListener ( ) { public void onForegrounded ( Context context ) { for ( LifecycleListener listener : lifecycleListeners ) { listener . onForegrounded ( context ) ; } } public void onBackgrounded ( Context context ) { for ( LifecycleListener listener : lifecycleListeners ) { listener . onBackgrounded ( context ) ; } } } ) ; }
Register for application lifecycle callbacks .
24,208
public Session getSession ( ) { return state . get ( ) > GlobalState . INITIALISING ? new Session ( dataMgr . getSessionDAO ( ) . session ( ) ) : new Session ( ) ; }
Gets the active session data .
24,209
private Observable < SessionData > loadSession ( final Boolean initialised ) { if ( initialised ) { final SessionData session = dataMgr . getSessionDAO ( ) . session ( ) ; if ( session != null ) { if ( session . getExpiresOn ( ) > System . currentTimeMillis ( ) ) { state . compareAndSet ( GlobalState . INITIALISED , GlobalState . SESSION_ACTIVE ) ; } else { state . compareAndSet ( GlobalState . INITIALISED , GlobalState . SESSION_OFF ) ; return service . reAuthenticate ( ) . onErrorReturn ( throwable -> { log . w ( "Authentication failure during init." ) ; return session ; } ) ; } } return Observable . create ( sub -> { sub . onNext ( session ) ; sub . onCompleted ( ) ; } ) ; } return Observable . just ( null ) ; }
Loads local session state .
24,210
public final AbstractMeter [ ] getMeters ( ) { final AbstractMeter [ ] returnVal = new AbstractMeter [ meters . length ] ; System . arraycopy ( meters , 0 , returnVal , 0 , returnVal . length ) ; return returnVal ; }
Getter for member meters
24,211
public final AbstractOutput [ ] getListener ( ) { final AbstractOutput [ ] returnVal = new AbstractOutput [ listeners . length ] ; System . arraycopy ( listeners , 0 , returnVal , 0 , returnVal . length ) ; return returnVal ; }
Getter for member listeners
24,212
public < T > void adapt ( final Observable < T > subscriber , final Callback < T > callback ) { subscriber . subscribeOn ( Schedulers . io ( ) ) . observeOn ( AndroidSchedulers . mainThread ( ) ) . subscribe ( new Subscriber < T > ( ) { public void onCompleted ( ) { } public void onError ( Throwable e ) { if ( callback != null ) { callback . error ( e ) ; } } public void onNext ( T result ) { if ( callback != null ) { callback . success ( result ) ; } } } ) ; }
Changes observables into callbacks .
24,213
private void setSelectionStateOfAll ( State state ) { Objects . requireNonNull ( state , "The state may not be null" ) ; List < Object > allNodes = JTrees . getAllNodes ( getModel ( ) ) ; for ( Object node : allNodes ) { setSelectionState ( node , state ) ; } }
Set the selection state of all nodes to the given state
24,214
private void setSelectionState ( Object node , State state , boolean propagate ) { Objects . requireNonNull ( state , "The state may not be null" ) ; Objects . requireNonNull ( node , "The node may not be null" ) ; State oldState = selectionStates . put ( node , state ) ; if ( ! state . equals ( oldState ) ) { fireStateChanged ( node , oldState , state ) ; if ( propagate ) { updateSelection ( node ) ; } } repaint ( ) ; }
Set the selection state of the given node
24,215
private void handleMousePress ( MouseEvent e ) { int row = getRowForLocation ( e . getX ( ) , e . getY ( ) ) ; TreePath path = getPathForLocation ( e . getX ( ) , e . getY ( ) ) ; if ( path == null ) { return ; } TreeCellRenderer cellRenderer = getCellRenderer ( ) ; TreeNode node = ( TreeNode ) path . getLastPathComponent ( ) ; Component cellRendererComponent = cellRenderer . getTreeCellRendererComponent ( CheckBoxTree . this , null , true , true , node . isLeaf ( ) , row , true ) ; Rectangle bounds = getRowBounds ( row ) ; Point localPoint = new Point ( ) ; localPoint . x = e . getX ( ) - bounds . x ; localPoint . y = e . getY ( ) - bounds . y ; Container container = ( Container ) cellRendererComponent ; Component clickedComponent = null ; for ( Component component : container . getComponents ( ) ) { Rectangle b = component . getBounds ( ) ; if ( b . contains ( localPoint ) ) { clickedComponent = component ; } } if ( clickedComponent != null ) { if ( clickedComponent instanceof JCheckBox ) { toggleSelection ( path ) ; repaint ( ) ; } } }
Handle a mouse press and possibly toggle the selection state
24,216
private void toggleSelection ( TreePath path ) { Object node = path . getLastPathComponent ( ) ; State state = getSelectionState ( node ) ; if ( state == null ) { return ; } if ( state == State . SELECTED ) { setSelectionState ( node , State . UNSELECTED ) ; updateSelection ( node ) ; } else if ( state == State . UNSELECTED ) { setSelectionState ( node , State . SELECTED ) ; updateSelection ( node ) ; } else { setSelectionState ( node , State . SELECTED ) ; updateSelection ( node ) ; } }
Toggle the selection of the given path due to a mouse click
24,217
private void updateSelection ( Object node ) { State newState = getSelectionState ( node ) ; List < Object > descendants = JTrees . getAllDescendants ( getModel ( ) , node ) ; for ( Object descendant : descendants ) { setSelectionState ( descendant , newState , false ) ; } Object ancestor = JTrees . getParent ( getModel ( ) , node ) ; while ( ancestor != null ) { List < Object > childrenOfAncestor = JTrees . getChildren ( getModel ( ) , ancestor ) ; State stateForAncestor = computeState ( childrenOfAncestor ) ; setSelectionState ( ancestor , stateForAncestor , false ) ; ancestor = JTrees . getParent ( getModel ( ) , ancestor ) ; } }
Update the selection state of the given node based on the state of its children
24,218
private State computeState ( List < Object > nodes ) { Set < State > set = new LinkedHashSet < State > ( ) ; for ( Object node : nodes ) { set . add ( getSelectionState ( node ) ) ; } while ( set . contains ( null ) ) { logger . warning ( "null found in selection states" ) ; set . remove ( null ) ; } if ( set . size ( ) == 0 ) { logger . warning ( "Empty selection states" ) ; return State . SELECTED ; } if ( set . size ( ) > 1 ) { return State . MIXED ; } return set . iterator ( ) . next ( ) ; }
Compute the state for a node with the given children
24,219
public void removeFromAccordion ( JComponent component ) { CollapsiblePanel collapsiblePanel = collapsiblePanels . get ( component ) ; if ( collapsiblePanel != null ) { contentPanel . remove ( collapsiblePanel ) ; collapsiblePanels . remove ( component ) ; revalidate ( ) ; } }
Remove the given component from this accordion
24,220
public void connectSocket ( ) { synchronized ( lock ) { if ( isForegrounded ) { if ( socketConnection == null ) { SocketFactory factory = new SocketFactory ( socketURI , new SocketEventDispatcher ( listener , new Parser ( ) ) . setLogger ( log ) , log ) ; socketConnection = new SocketConnectionController ( new Handler ( Looper . getMainLooper ( ) ) , dataMgr , factory , listener , new RetryStrategy ( 60 , 60000 ) , log ) ; socketConnection . setProxy ( proxyURI ) ; socketConnection . connect ( ) ; } else { socketConnection . connect ( ) ; } socketConnection . setManageReconnection ( true ) ; } lock . notifyAll ( ) ; } }
Create and connect socket .
24,221
public void disconnectSocket ( ) { synchronized ( lock ) { if ( socketConnection != null ) { socketConnection . setManageReconnection ( false ) ; socketConnection . disconnect ( ) ; } lock . notifyAll ( ) ; } }
Disconnect socket .
24,222
public LifecycleListener createLifecycleListener ( ) { return new LifecycleListener ( ) { public void onForegrounded ( Context context ) { synchronized ( lock ) { if ( ! isForegrounded ) { isForegrounded = true ; connectSocket ( ) ; if ( receiver == null ) { receiver = new InternetConnectionReceiver ( socketConnection ) ; } context . registerReceiver ( receiver , new IntentFilter ( ConnectivityManager . CONNECTIVITY_ACTION ) ) ; } lock . notifyAll ( ) ; } } public void onBackgrounded ( Context context ) { synchronized ( lock ) { if ( isForegrounded ) { isForegrounded = false ; disconnectSocket ( ) ; if ( receiver != null && ! isForegrounded ) { context . unregisterReceiver ( receiver ) ; } } lock . notifyAll ( ) ; } } } ; }
creates application lifecycle and network connectivity callbacks .
24,223
public boolean initProgressView ( final Map < BenchmarkMethod , Integer > mapping ) throws SocketViewException { if ( mapping != null ) { final Set < BenchmarkMethod > methodSet = mapping . keySet ( ) ; final Map < String , Integer > finalMap = new HashMap < String , Integer > ( ) ; for ( BenchmarkMethod benchmarkMethod : methodSet ) { finalMap . put ( benchmarkMethod . getMethodWithClassName ( ) , mapping . get ( benchmarkMethod ) ) ; } viewStub . initTotalBenchProgress ( finalMap ) ; } return true ; }
This method initializes the values of the eclipse view and resets the progress bar .
24,224
public boolean updateCurrentElement ( final AbstractMeter meter , final String name ) throws SocketViewException { if ( meter != null && ! regMeterHash ) { registerFirstMeterHash ( meter ) ; } if ( name != null && meter . hashCode ( ) == ( getRegMeter ( ) ) ) { viewStub . updateCurrentRun ( name ) ; } return true ; }
This method notifies the eclipse view which element is currently benched .
24,225
public boolean updateErrorInElement ( final String name , final Exception exception ) throws SocketViewException { if ( name != null && exception != null ) { if ( exception instanceof AbstractPerfidixMethodException ) { final AbstractPerfidixMethodException exc = ( AbstractPerfidixMethodException ) exception ; viewStub . updateError ( name , exc . getExec ( ) . getClass ( ) . getSimpleName ( ) ) ; } if ( exception instanceof SocketViewException ) { final SocketViewException viewException = ( SocketViewException ) exception ; viewStub . updateError ( name , viewException . getExc ( ) . getClass ( ) . getSimpleName ( ) ) ; } } return true ; }
This method informs the view that an error occurred while benching the current element .
24,226
static String getLevelTag ( final int logLevel ) { switch ( logLevel ) { case LogLevelConst . FATAL : return LogConstants . TAG_FATAL ; case LogLevelConst . ERROR : return LogConstants . TAG_ERROR ; case LogLevelConst . WARNING : return LogConstants . TAG_WARNING ; case LogLevelConst . INFO : return LogConstants . TAG_INFO ; case LogLevelConst . DEBUG : return LogConstants . TAG_DEBUG ; default : return "[DEFAULT]" ; } }
Gets the string representation of the log level .
24,227
public String getMessageId ( ) { return ( data != null && data . payload != null ) ? data . payload . messageId : null ; }
Gets id of the updated message .
24,228
public String getConversationId ( ) { return ( data != null && data . payload != null ) ? data . payload . conversationId : null ; }
Gets id of the conversation for which message was updated .
24,229
public String getProfileId ( ) { return ( data != null && data . payload != null ) ? data . payload . profileId : null ; }
Gets profile id of the user that changed the message status .
24,230
public String getTimestamp ( ) { return ( data != null && data . payload != null ) ? data . payload . timestamp : null ; }
Gets time when the message status changed .
24,231
static String combine ( final String ... args ) { final StringBuilder builder = new StringBuilder ( ) ; for ( final String arg : args ) { builder . append ( arg ) ; } return builder . toString ( ) ; }
Combines an unknown number of Strings to one String .
24,232
static String implode ( final String glue , final String [ ] what ) { final StringBuilder builder = new StringBuilder ( ) ; for ( int i = 0 ; i < what . length ; i ++ ) { builder . append ( what [ i ] ) ; if ( i + 1 != what . length ) { builder . append ( glue ) ; } } return builder . toString ( ) ; }
Concantenate a String array what with glue glue .
24,233
static String repeat ( final String toBeRepeated , final int numTimes ) { final StringBuilder builder = new StringBuilder ( ) ; for ( int i = 0 ; i < numTimes ; i ++ ) { builder . append ( toBeRepeated ) ; } return builder . toString ( ) ; }
a str_repeat function .
24,234
private static int numNewLines ( final String toExamine ) { final char [ ] arr = toExamine . toCharArray ( ) ; int result = 0 ; for ( char ch : arr ) { if ( AbstractTabularComponent . NEWLINE . equals ( new String ( new char [ ] { ch } ) ) ) { result ++ ; } } return result ; }
Returns how many new lines are in the string .
24,235
public static String [ ] [ ] createMatrix ( final String [ ] data ) { int maxNewLines = 0 ; for ( final String col : data ) { maxNewLines = Math . max ( maxNewLines , Util . numNewLines ( col ) ) ; } final String [ ] [ ] matrix = new String [ maxNewLines + 1 ] [ data . length ] ; for ( int col = 0 ; col < data . length ; col ++ ) { final String [ ] exploded = Util . explode ( data [ col ] ) ; for ( int row = 0 ; row < maxNewLines + 1 ; row ++ ) { if ( exploded . length > row ) { matrix [ row ] [ col ] = exploded [ row ] ; } else { matrix [ row ] [ col ] = "" ; } } } return matrix ; }
Creates a matrix according to the number of new lines given into the method .
24,236
private void handleCommand ( byte b ) throws IOException { if ( b == SE ) { telnetCommand += ( char ) b ; handleNegotiation ( ) ; reset ( ) ; } else if ( isWill || isDo ) { if ( isWill && b == TERMINAL_TYPE ) { socketChannel . write ( ByteBuffer . wrap ( new byte [ ] { IAC , SB , TERMINAL_TYPE , ECHO , IAC , SE } ) ) ; } else if ( b != ECHO && b != GA && b != NAWS ) { telnetCommand += ( char ) b ; socketChannel . write ( ByteBuffer . wrap ( telnetCommand . getBytes ( ) ) ) ; } reset ( ) ; } else if ( isWont || isDont ) { telnetCommand += ( char ) b ; socketChannel . write ( ByteBuffer . wrap ( telnetCommand . getBytes ( ) ) ) ; reset ( ) ; } else if ( isSb ) { telnetCommand += ( char ) b ; } }
Handle telnet command
24,237
private void handleNegotiation ( ) throws IOException { if ( telnetCommand . contains ( new String ( new byte [ ] { TERMINAL_TYPE } ) ) ) { boolean isSuccess = false ; clientTerminalType = telnetCommand . substring ( 4 , telnetCommand . length ( ) - 2 ) ; for ( String terminalType : terminalTypeMapping . keySet ( ) ) { if ( clientTerminalType . contains ( terminalType ) ) { isSuccess = true ; clientTerminalType = terminalType ; echoPrompt ( ) ; break ; } } if ( ! isSuccess ) { socketChannel . write ( ByteBuffer . wrap ( "TerminalType negotiate failed." . getBytes ( ) ) ) ; throw new RuntimeException ( "TerminalType negotiate failed." ) ; } } }
Handle negotiation of terminal type
24,238
public String normalizeNumber ( final String number ) { try { final BigDecimal normalizedNumber = parseNumber ( new NumberBuffer ( number ) ) ; if ( normalizedNumber == null ) { return number ; } return normalizedNumber . toBigIntegerExact ( ) . toString ( ) ; } catch ( NumberFormatException | ArithmeticException e ) { return number ; } }
Normalizes a Japanese number
24,239
private BigDecimal parseNumber ( final NumberBuffer buffer ) { BigDecimal sum = BigDecimal . ZERO ; BigDecimal result = parseLargePair ( buffer ) ; if ( result == null ) { return null ; } while ( result != null ) { sum = sum . add ( result ) ; result = parseLargePair ( buffer ) ; } return sum ; }
Parses a Japanese number
24,240
public boolean isNumeralPunctuation ( final String input ) { for ( int i = 0 ; i < input . length ( ) ; i ++ ) { if ( ! isNumeralPunctuation ( input . charAt ( i ) ) ) { return false ; } } return true ; }
Numeral punctuation predicate
24,241
public void adaptHeightToChildren ( ) { DividableGridAdapter adapter = ( DividableGridAdapter ) getAdapter ( ) ; if ( adapter != null ) { int height = getPaddingTop ( ) + getPaddingBottom ( ) ; for ( int i = 0 ; i < adapter . getCount ( ) ; i += adapter . getColumnCount ( ) ) { AbstractItem item = adapter . getItem ( i ) ; if ( item instanceof Divider ) { height += getResources ( ) . getDimensionPixelSize ( TextUtils . isEmpty ( item . getTitle ( ) ) ? R . dimen . bottom_sheet_divider_height : R . dimen . bottom_sheet_divider_title_height ) ; } else { height += getResources ( ) . getDimensionPixelSize ( adapter . getStyle ( ) == BottomSheet . Style . GRID ? R . dimen . bottom_sheet_grid_item_size : R . dimen . bottom_sheet_list_item_height ) ; } } ViewGroup . LayoutParams params = getLayoutParams ( ) ; params . height = height ; setLayoutParams ( params ) ; requestLayout ( ) ; } }
Adapts the height of the grid view to the height of its children .
24,242
private List < AbstractItem > getRawItems ( ) { if ( rawItems == null ) { rawItems = new ArrayList < > ( ) ; for ( int i = 0 ; i < items . size ( ) ; i ++ ) { AbstractItem item = items . get ( i ) ; if ( item instanceof Divider && columnCount > 1 ) { for ( int j = 0 ; j < rawItems . size ( ) % columnCount ; j ++ ) { rawItems . add ( null ) ; } rawItems . add ( item ) ; for ( int j = 0 ; j < columnCount - 1 ; j ++ ) { rawItems . add ( new Divider ( ) ) ; } } else { rawItems . add ( item ) ; } } } return rawItems ; }
Returns a list which contains the items of the adapter including placeholders .
24,243
private View inflateItemView ( final ViewGroup parent ) { LayoutInflater layoutInflater = LayoutInflater . from ( context ) ; View view = layoutInflater . inflate ( style == Style . GRID ? R . layout . grid_item : R . layout . list_item , parent , false ) ; ItemViewHolder viewHolder = new ItemViewHolder ( ) ; viewHolder . iconImageView = view . findViewById ( android . R . id . icon ) ; viewHolder . titleTextView = view . findViewById ( android . R . id . title ) ; view . setTag ( viewHolder ) ; return view ; }
Inflates the view which is used to visualize an item .
24,244
@ SuppressWarnings ( "PrimitiveArrayArgumentToVariableArgMethod" ) private void visualizeItem ( final Item item , final ItemViewHolder viewHolder ) { viewHolder . iconImageView . setVisibility ( iconCount > 0 ? View . VISIBLE : View . GONE ) ; viewHolder . iconImageView . setEnabled ( item . isEnabled ( ) ) ; if ( item . getIcon ( ) != null && item . getIcon ( ) instanceof StateListDrawable ) { StateListDrawable stateListDrawable = ( StateListDrawable ) item . getIcon ( ) ; try { int [ ] currentState = viewHolder . iconImageView . getDrawableState ( ) ; Method getStateDrawableIndex = StateListDrawable . class . getMethod ( "getStateDrawableIndex" , int [ ] . class ) ; Method getStateDrawable = StateListDrawable . class . getMethod ( "getStateDrawable" , int . class ) ; int index = ( int ) getStateDrawableIndex . invoke ( stateListDrawable , currentState ) ; Drawable drawable = ( Drawable ) getStateDrawable . invoke ( stateListDrawable , index ) ; viewHolder . iconImageView . setImageDrawable ( drawable ) ; } catch ( Exception e ) { viewHolder . iconImageView . setImageDrawable ( item . getIcon ( ) ) ; } } else { viewHolder . iconImageView . setImageDrawable ( item . getIcon ( ) ) ; } viewHolder . titleTextView . setText ( item . getTitle ( ) ) ; viewHolder . titleTextView . setEnabled ( item . isEnabled ( ) ) ; if ( getItemColor ( ) != - 1 ) { viewHolder . titleTextView . setTextColor ( getItemColor ( ) ) ; } }
Visualizes a specific item .
24,245
private View inflateDividerView ( final ViewGroup parent , final Divider divider , final int position ) { LayoutInflater layoutInflater = LayoutInflater . from ( context ) ; View view = layoutInflater . inflate ( R . layout . divider , parent , false ) ; DividerViewHolder viewHolder = new DividerViewHolder ( ) ; viewHolder . leftDivider = view . findViewById ( R . id . left_divider ) ; viewHolder . rightDivider = view . findViewById ( R . id . right_divider ) ; viewHolder . titleTextView = view . findViewById ( android . R . id . title ) ; view . setTag ( viewHolder ) ; if ( ! TextUtils . isEmpty ( divider . getTitle ( ) ) || ( position % columnCount > 0 && ! TextUtils . isEmpty ( getRawItems ( ) . get ( position - ( position % columnCount ) ) . getTitle ( ) ) ) ) { view . getLayoutParams ( ) . height = context . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_divider_title_height ) ; } return view ; }
Inflates the view which is used to visualize a divider .
24,246
private void visualizeDivider ( final Divider divider , final DividerViewHolder viewHolder ) { if ( ! TextUtils . isEmpty ( divider . getTitle ( ) ) ) { viewHolder . titleTextView . setText ( divider . getTitle ( ) ) ; viewHolder . titleTextView . setVisibility ( View . VISIBLE ) ; viewHolder . leftDivider . setVisibility ( View . VISIBLE ) ; } else { viewHolder . titleTextView . setVisibility ( View . GONE ) ; viewHolder . leftDivider . setVisibility ( View . GONE ) ; } if ( dividerColor != - 1 ) { viewHolder . titleTextView . setTextColor ( dividerColor ) ; viewHolder . leftDivider . setBackgroundColor ( dividerColor ) ; viewHolder . rightDivider . setBackgroundColor ( dividerColor ) ; } }
Visualizes a specific divider .
24,247
public final void setStyle ( final Style style ) { Condition . INSTANCE . ensureNotNull ( style , "The style may not be null" ) ; this . style = style ; this . rawItems = null ; notifyDataSetChanged ( ) ; }
Sets the style which should be used to display the adapter s items .
24,248
public final void setWidth ( final int width ) { if ( style == Style . LIST_COLUMNS && ( getDeviceType ( context ) == DeviceType . TABLET || getOrientation ( context ) == Orientation . LANDSCAPE ) ) { columnCount = 2 ; } else if ( style == Style . GRID ) { int padding = context . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_item_horizontal_padding ) ; int itemSize = context . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_item_size ) ; columnCount = ( ( getDeviceType ( context ) != DeviceType . TABLET && context . getResources ( ) . getConfiguration ( ) . orientation == Configuration . ORIENTATION_PORTRAIT ? context . getResources ( ) . getDisplayMetrics ( ) . widthPixels : width ) - 2 * padding ) / itemSize ; } else { columnCount = 1 ; } rawItems = null ; notifyDataSetChanged ( ) ; }
Sets the width of the bottom sheet the items which are displayed by the adapter belong to .
24,249
public final void add ( final AbstractItem item ) { Condition . INSTANCE . ensureNotNull ( item , "The item may not be null" ) ; items . add ( item ) ; if ( item instanceof Item && ( ( Item ) item ) . getIcon ( ) != null ) { iconCount ++ ; } else if ( item instanceof Divider ) { dividerCount ++ ; } rawItems = null ; notifyOnDataSetChanged ( ) ; }
Adds a new item to the adapter .
24,250
public final void set ( final int index , final AbstractItem item ) { Condition . INSTANCE . ensureNotNull ( item , "The item may not be null" ) ; AbstractItem replacedItem = items . set ( index , item ) ; if ( replacedItem instanceof Item && ( ( Item ) replacedItem ) . getIcon ( ) != null ) { iconCount -- ; } else if ( replacedItem instanceof Divider ) { dividerCount -- ; } if ( item instanceof Item && ( ( Item ) item ) . getIcon ( ) != null ) { iconCount ++ ; } else if ( item instanceof Divider ) { dividerCount ++ ; } rawItems = null ; notifyOnDataSetChanged ( ) ; }
Replaces the item with at a specific index
24,251
public final void remove ( final int index ) { AbstractItem removedItem = items . remove ( index ) ; if ( removedItem instanceof Item && ( ( Item ) removedItem ) . getIcon ( ) != null ) { iconCount -- ; } else if ( removedItem instanceof Divider ) { dividerCount -- ; } rawItems = null ; notifyOnDataSetChanged ( ) ; }
Removes the item at a specific index .
24,252
public final void clear ( ) { items . clear ( ) ; iconCount = 0 ; dividerCount = 0 ; if ( rawItems != null ) { rawItems . clear ( ) ; } notifyOnDataSetChanged ( ) ; }
Removes all items from the adapter .
24,253
public final boolean isItemEnabled ( final int index ) { AbstractItem item = items . get ( index ) ; return item instanceof Item && ( ( Item ) item ) . isEnabled ( ) ; }
Returns whether the item at a specific index is enabled or not .
24,254
public final void setItemEnabled ( final int index , final boolean enabled ) { AbstractItem item = items . get ( index ) ; if ( item instanceof Item ) { ( ( Item ) item ) . setEnabled ( enabled ) ; rawItems = null ; notifyOnDataSetChanged ( ) ; } }
Sets whether the item at a specific index should be enabled or not .
24,255
public final void setTitle ( final Context context , final int resourceId ) { setTitle ( context . getText ( resourceId ) ) ; }
Sets the divider s title .
24,256
private boolean isScrollUpEvent ( final float x , final float y , final ViewGroup viewGroup ) { int location [ ] = new int [ 2 ] ; viewGroup . getLocationOnScreen ( location ) ; if ( x >= location [ 0 ] && x <= location [ 0 ] + viewGroup . getWidth ( ) && y >= location [ 1 ] && y <= location [ 1 ] + viewGroup . getHeight ( ) ) { for ( int i = 0 ; i < viewGroup . getChildCount ( ) ; i ++ ) { View view = viewGroup . getChildAt ( i ) ; if ( view . canScrollVertically ( - 1 ) ) { return true ; } else if ( view instanceof ViewGroup ) { return isScrollUpEvent ( x , y , ( ViewGroup ) view ) ; } } } return false ; }
Returns whether a touch event at a specific position targets a view which can be scrolled up .
24,257
private boolean handleDrag ( ) { if ( ! isAnimationRunning ( ) ) { if ( dragHelper . hasThresholdBeenReached ( ) ) { int margin = Math . round ( isMaximized ( ) ? dragHelper . getDragDistance ( ) : initialMargin + dragHelper . getDragDistance ( ) ) ; margin = Math . max ( Math . max ( margin , minMargin ) , 0 ) ; setTopMargin ( margin ) ; } return true ; } return false ; }
Handles when a drag gesture is performed by the user .
24,258
private void handleRelease ( ) { float speed = Math . max ( dragHelper . getDragSpeed ( ) , animationSpeed ) ; if ( getTopMargin ( ) > initialMargin || ( dragHelper . getDragSpeed ( ) > animationSpeed && dragHelper . getDragDistance ( ) > 0 ) || ( getDeviceType ( getContext ( ) ) == DeviceType . TABLET && isMaximized ( ) && getTopMargin ( ) > minMargin ) ) { animateHideView ( parentHeight - getTopMargin ( ) , speed , new DecelerateInterpolator ( ) , true ) ; } else { animateShowView ( - ( getTopMargin ( ) - minMargin ) , speed , new DecelerateInterpolator ( ) ) ; } }
Handles when a drag gesture has been ended by the user .
24,259
private void setTopMargin ( final int margin ) { FrameLayout . LayoutParams layoutParams = ( FrameLayout . LayoutParams ) getLayoutParams ( ) ; layoutParams . topMargin = margin ; setLayoutParams ( layoutParams ) ; }
Set the top margin of the view .
24,260
private void animateShowView ( final int diff , final float animationSpeed , final Interpolator interpolator ) { animateView ( diff , animationSpeed , createAnimationListener ( true , false ) , interpolator ) ; }
Animates the view to become show .
24,261
private void animateHideView ( final int diff , final float animationSpeed , final Interpolator interpolator , final boolean cancel ) { animateView ( diff , animationSpeed , createAnimationListener ( false , cancel ) , interpolator ) ; }
Animates the view to become hidden .
24,262
private void animateView ( final int diff , final float animationSpeed , final AnimationListener animationListener , final Interpolator interpolator ) { if ( ! isDragging ( ) && ! isAnimationRunning ( ) ) { long duration = calculateAnimationDuration ( diff , animationSpeed ) ; Animation animation = new DraggableViewAnimation ( this , diff , duration , animationListener ) ; animation . setInterpolator ( interpolator ) ; startAnimation ( animation ) ; } }
Animates the view to become shown or hidden .
24,263
private AnimationListener createAnimationListener ( final boolean show , final boolean cancel ) { return new AnimationListener ( ) { public void onAnimationStart ( final Animation animation ) { } public void onAnimationEnd ( final Animation animation ) { clearAnimation ( ) ; maximized = show ; if ( maximized ) { notifyOnMaximized ( ) ; } else { notifyOnHidden ( cancel ) ; } } public void onAnimationRepeat ( final Animation animation ) { } } ; }
Creates and returns a listener which allows to handle the end of an animation which has been used to show or hide the view .
24,264
public final void setIcon ( final Context context , final int resourceId ) { setIcon ( ContextCompat . getDrawable ( context , resourceId ) ) ; }
Sets the item s icon .
24,265
public final void setTitle ( final Context context , final int resourceId ) { Condition . INSTANCE . ensureNotNull ( context , "The context may not be null" ) ; setTitle ( context . getText ( resourceId ) ) ; }
Sets the title of the item .
24,266
private void initialize ( ) { width = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . default_width ) ; maximize = false ; adapter = new DividableGridAdapter ( getContext ( ) , Style . LIST , width ) ; super . setOnShowListener ( createOnShowListener ( ) ) ; }
Initializes the bottom sheet .
24,267
private WindowManager . LayoutParams createLayoutParams ( ) { WindowManager . LayoutParams layoutParams = getWindow ( ) . getAttributes ( ) ; layoutParams . width = ViewGroup . LayoutParams . MATCH_PARENT ; layoutParams . height = ViewGroup . LayoutParams . MATCH_PARENT ; return layoutParams ; }
Creates and returns the layout params which should be used to show the bottom sheet .
24,268
private FrameLayout . LayoutParams createRootViewLayoutParams ( ) { FrameLayout . LayoutParams layoutParams = new FrameLayout . LayoutParams ( FrameLayout . LayoutParams . MATCH_PARENT , FrameLayout . LayoutParams . MATCH_PARENT ) ; layoutParams . gravity = Gravity . BOTTOM | Gravity . CENTER_HORIZONTAL ; return layoutParams ; }
Creates and returns the layout params which should be used to show the bottom sheet s root view .
24,269
private void inflateRootView ( ) { ViewGroup contentView = findViewById ( android . R . id . content ) ; contentView . removeAllViews ( ) ; LayoutInflater layoutInflater = LayoutInflater . from ( getContext ( ) ) ; rootView = ( DraggableView ) layoutInflater . inflate ( R . layout . bottom_sheet , contentView , false ) ; rootView . setCallback ( this ) ; contentView . addView ( rootView , createRootViewLayoutParams ( ) ) ; }
Initializes the bottom sheet s root view .
24,270
private void inflateTitleView ( ) { titleContainer = rootView . findViewById ( R . id . title_container ) ; titleContainer . removeAllViews ( ) ; if ( customTitleView != null ) { titleContainer . addView ( customTitleView ) ; } else if ( customTitleViewId != - 1 ) { LayoutInflater layoutInflater = LayoutInflater . from ( getContext ( ) ) ; View view = layoutInflater . inflate ( customTitleViewId , titleContainer , false ) ; titleContainer . addView ( view ) ; } else { LayoutInflater layoutInflater = LayoutInflater . from ( getContext ( ) ) ; View view = layoutInflater . inflate ( R . layout . bottom_sheet_title , titleContainer , false ) ; titleContainer . addView ( view ) ; } if ( getStyle ( ) == Style . LIST ) { int padding = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_list_item_horizontal_padding ) ; titleContainer . setPadding ( padding , 0 , padding , 0 ) ; } else { int padding = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_item_horizontal_padding ) ; titleContainer . setPadding ( padding , 0 , padding , 0 ) ; } View titleView = titleContainer . findViewById ( android . R . id . title ) ; titleTextView = titleView instanceof TextView ? ( TextView ) titleView : null ; }
Inflates the layout which is used to show the bottom sheet s title . The layout may either be the default one or a custom view if one has been set before .
24,271
private void inflateContentView ( ) { contentContainer = rootView . findViewById ( R . id . content_container ) ; contentContainer . removeAllViews ( ) ; if ( customView != null ) { contentContainer . setVisibility ( View . VISIBLE ) ; contentContainer . addView ( customView ) ; } else if ( customViewId != - 1 ) { contentContainer . setVisibility ( View . VISIBLE ) ; LayoutInflater layoutInflater = LayoutInflater . from ( getContext ( ) ) ; View view = layoutInflater . inflate ( customViewId , contentContainer , false ) ; contentContainer . addView ( view ) ; } else { LayoutInflater layoutInflater = LayoutInflater . from ( getContext ( ) ) ; View view = layoutInflater . inflate ( R . layout . bottom_sheet_grid_view , contentContainer , false ) ; contentContainer . addView ( view ) ; } showGridView ( ) ; }
Inflates the layout which is used to show the bottom sheet s content . The layout may either be the default one or a custom view if one has been set before .
24,272
private void showGridView ( ) { gridView = contentContainer . findViewById ( R . id . bottom_sheet_grid_view ) ; if ( gridView != null ) { contentContainer . setVisibility ( View . VISIBLE ) ; if ( getStyle ( ) == Style . GRID ) { int horizontalPadding = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_item_horizontal_padding ) ; int paddingBottom = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_padding_bottom ) ; gridView . setPadding ( horizontalPadding , 0 , horizontalPadding , paddingBottom ) ; gridView . setNumColumns ( GridView . AUTO_FIT ) ; gridView . setColumnWidth ( getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_item_size ) ) ; } else { int paddingBottom = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_list_padding_bottom ) ; gridView . setPadding ( 0 , 0 , 0 , paddingBottom ) ; gridView . setNumColumns ( getStyle ( ) == Style . LIST_COLUMNS && ( getDeviceType ( getContext ( ) ) == DisplayUtil . DeviceType . TABLET || getOrientation ( getContext ( ) ) == DisplayUtil . Orientation . LANDSCAPE ) ? 2 : 1 ) ; } gridView . setOnItemClickListener ( createItemClickListener ( ) ) ; gridView . setOnItemLongClickListener ( createItemLongClickListener ( ) ) ; gridView . setAdapter ( adapter ) ; } }
Shows the grid view which is used to show the bottom sheet s items .
24,273
private void adaptRootView ( ) { if ( rootView != null ) { if ( getStyle ( ) == Style . LIST ) { int paddingTop = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_list_padding_top ) ; rootView . setPadding ( 0 , paddingTop , 0 , 0 ) ; } else { int paddingTop = getContext ( ) . getResources ( ) . getDimensionPixelSize ( R . dimen . bottom_sheet_grid_padding_top ) ; rootView . setPadding ( 0 , paddingTop , 0 , 0 ) ; } } }
Adapts the root view .
24,274
private void adaptIcon ( ) { if ( titleTextView != null ) { titleTextView . setCompoundDrawablesWithIntrinsicBounds ( icon , null , null , null ) ; } adaptTitleContainerVisibility ( ) ; }
Adapts the bottom sheet s icon .
24,275
private void adaptTitleContainerVisibility ( ) { if ( titleContainer != null ) { if ( customTitleView == null && customTitleViewId == - 1 ) { titleContainer . setVisibility ( ! TextUtils . isEmpty ( title ) || icon != null ? View . VISIBLE : View . GONE ) ; } else { titleContainer . setVisibility ( View . VISIBLE ) ; } } }
Adapts the visibility of the layout which is used to show the bottom sheet s title .
24,276
private void adaptWidth ( ) { adapter . setWidth ( width ) ; if ( rootView != null ) { rootView . setWidth ( width ) ; rootView . requestLayout ( ) ; } }
Adapts the width of the bottom sheet .
24,277
@ TargetApi ( VERSION_CODES . FROYO ) private OnShowListener createOnShowListener ( ) { return new OnShowListener ( ) { public void onShow ( final DialogInterface dialog ) { if ( onShowListener != null ) { onShowListener . onShow ( dialog ) ; } if ( maximize ) { maximize = false ; rootView . maximize ( new DecelerateInterpolator ( ) ) ; } } } ; }
Creates and returns a listener which allows to immediately maximize the bottom sheet after it has been shown .
24,278
private View . OnTouchListener createCancelOnTouchListener ( ) { return new View . OnTouchListener ( ) { public boolean onTouch ( final View v , final MotionEvent event ) { if ( cancelable && canceledOnTouchOutside ) { cancel ( ) ; v . performClick ( ) ; return true ; } return false ; } } ; }
Creates and returns a listener which allows to cancel the bottom sheet when the decor view is touched .
24,279
private OnItemClickListener createItemClickListener ( ) { return new OnItemClickListener ( ) { public void onItemClick ( final AdapterView < ? > parent , final View view , final int position , final long id ) { if ( itemClickListener != null && ! rootView . isDragging ( ) && ! rootView . isAnimationRunning ( ) ) { int index = position ; if ( adapter . containsDividers ( ) ) { for ( int i = position ; i >= 0 ; i -- ) { if ( adapter . getItem ( i ) == null || ( adapter . getItem ( i ) instanceof Divider && i % adapter . getColumnCount ( ) > 0 ) ) { index -- ; } } } itemClickListener . onItemClick ( parent , view , index , getId ( position ) ) ; } dismiss ( ) ; } } ; }
Creates and returns a listener which allows to observe when the items of a bottom sheet have been clicked .
24,280
private OnItemLongClickListener createItemLongClickListener ( ) { return new OnItemLongClickListener ( ) { public boolean onItemLongClick ( final AdapterView < ? > parent , final View view , final int position , final long id ) { if ( ! rootView . isDragging ( ) && ! rootView . isAnimationRunning ( ) && itemLongClickListener != null ) { int index = position ; if ( adapter . containsDividers ( ) ) { for ( int i = position ; i >= 0 ; i -- ) { if ( adapter . getItem ( i ) == null || ( adapter . getItem ( i ) instanceof Divider && i % adapter . getColumnCount ( ) > 0 ) ) { index -- ; } } } return itemLongClickListener . onItemLongClick ( parent , view , index , getId ( position ) ) ; } return false ; } } ; }
Creates and returns a listener which allows to observe when the items of a bottom sheet have been long - clicked .
24,281
private OnItemClickListener createIntentClickListener ( final Activity activity , final Intent intent , final List < ResolveInfo > resolveInfos ) { return new OnItemClickListener ( ) { public void onItemClick ( final AdapterView < ? > parent , final View view , final int position , final long id ) { ActivityInfo activityInfo = resolveInfos . get ( position ) . activityInfo ; ComponentName componentName = new ComponentName ( activityInfo . applicationInfo . packageName , activityInfo . name ) ; intent . setFlags ( Intent . FLAG_ACTIVITY_NEW_TASK | Intent . FLAG_ACTIVITY_RESET_TASK_IF_NEEDED ) ; intent . setComponent ( componentName ) ; activity . startActivity ( intent ) ; dismiss ( ) ; } } ; }
Creates and returns a listener which allows to start an app when an item of the bottom sheet has been clicked .
24,282
public final GridView getGridView ( ) { return ( gridView != null && gridView . getVisibility ( ) == View . VISIBLE ) ? gridView : null ; }
Returns the grid view which is contained by the bottom sheet .
24,283
public final void setIcon ( final int resourceId ) { this . icon = ContextCompat . getDrawable ( getContext ( ) , resourceId ) ; this . iconBitmap = null ; this . iconId = resourceId ; this . iconAttributeId = - 1 ; adaptIcon ( ) ; }
Sets the icon of the bottom sheet .
24,284
public final void setIconAttribute ( final int attributeId ) { TypedArray typedArray = getContext ( ) . getTheme ( ) . obtainStyledAttributes ( new int [ ] { attributeId } ) ; this . icon = typedArray . getDrawable ( 0 ) ; this . iconBitmap = null ; this . iconId = - 1 ; this . iconAttributeId = attributeId ; adaptIcon ( ) ; }
Set the icon of the bottom sheet .
24,285
public final void setBackgroundColor ( final int color ) { this . background = new ColorDrawable ( color ) ; this . backgroundBitmap = null ; this . backgroundId = - 1 ; this . backgroundColor = color ; adaptBackground ( ) ; }
Sets the background color of the bottom sheet .
24,286
public final void setDragSensitivity ( final float dragSensitivity ) { Condition . INSTANCE . ensureAtLeast ( dragSensitivity , 0 , "The drag sensitivity must be at least 0" ) ; Condition . INSTANCE . ensureAtMaximum ( dragSensitivity , 1 , "The drag sensitivity must be at maximum 1" ) ; this . dragSensitivity = dragSensitivity ; adaptDragSensitivity ( ) ; }
Sets the sensitivity which specifies the distance after which dragging has an effect on the bottom sheet in relation to an internal value range .
24,287
public final void setDimAmount ( final float dimAmount ) { Condition . INSTANCE . ensureAtLeast ( dimAmount , 0 , "The dim amount must be at least 0" ) ; Condition . INSTANCE . ensureAtMaximum ( dimAmount , 1 , "The dim amount must be at maximum 1" ) ; this . dimAmount = dimAmount ; getWindow ( ) . getAttributes ( ) . dimAmount = dimAmount ; }
Sets the dim amount which should be used to darken the area outside the bottom sheet .
24,288
public final int indexOf ( final int id ) { Condition . INSTANCE . ensureAtLeast ( id , 0 , "The id must be at least 0" ) ; for ( int i = 0 ; i < getItemCount ( ) ; i ++ ) { AbstractItem item = adapter . getItem ( i ) ; if ( item . getId ( ) == id ) { return i ; } } return - 1 ; }
Returns the index of the item which corresponds to a specific id .
24,289
public final void setIntent ( final Activity activity , final Intent intent ) { Condition . INSTANCE . ensureNotNull ( activity , "The activity may not be null" ) ; Condition . INSTANCE . ensureNotNull ( intent , "The intent may not be null" ) ; removeAllItems ( ) ; PackageManager packageManager = activity . getPackageManager ( ) ; List < ResolveInfo > resolveInfos = packageManager . queryIntentActivities ( intent , 0 ) ; for ( int i = 0 ; i < resolveInfos . size ( ) ; i ++ ) { ResolveInfo resolveInfo = resolveInfos . get ( i ) ; addItem ( i , resolveInfo . loadLabel ( packageManager ) , resolveInfo . loadIcon ( packageManager ) ) ; } setOnItemClickListener ( createIntentClickListener ( activity , ( Intent ) intent . clone ( ) , resolveInfos ) ) ; }
Adds the apps which are able to handle a specific intent as items to the bottom sheet . This causes all previously added items to be removed . When an item is clicked the corresponding app is started .
24,290
@ TargetApi ( VERSION_CODES . FROYO ) public final void maximize ( ) { if ( ! isMaximized ( ) ) { if ( ! isShowing ( ) ) { maximize = true ; show ( ) ; } else { rootView . maximize ( new AccelerateDecelerateInterpolator ( ) ) ; } } }
Maximizes the bottom sheet .
24,291
public final void setStyle ( final Style style ) { Condition . INSTANCE . ensureNotNull ( style , "The style may not be null" ) ; adapter . setStyle ( style ) ; adaptRootView ( ) ; adaptTitleView ( ) ; adaptContentView ( ) ; adaptGridViewHeight ( ) ; }
Sets the style which should be used to display the bottom sheet s items .
24,292
private void initializeBottomSheet ( ) { BottomSheet . Builder builder = createBottomSheetBuilder ( ) ; addItems ( builder ) ; bottomSheet = builder . create ( ) ; }
Initializes the regular bottom sheet containing list items .
24,293
private void initializeCustomBottomSheet ( ) { BottomSheet . Builder builder = createBottomSheetBuilder ( ) ; builder . setView ( R . layout . custom_view ) ; customBottomSheet = builder . create ( ) ; }
Initializes the bottom sheet containing a custom view .
24,294
private void initializeIntentBottomSheet ( ) { BottomSheet . Builder builder = createBottomSheetBuilder ( ) ; Intent intent = new Intent ( ) ; intent . setAction ( Intent . ACTION_SEND ) ; intent . putExtra ( Intent . EXTRA_TEXT , "This is my text to send." ) ; intent . setType ( "text/plain" ) ; builder . setIntent ( getActivity ( ) , intent ) ; intentBottomSheet = builder . create ( ) ; }
Initializes the bottom sheet containing possible receivers for an intent .
24,295
private void initializeShowBottomSheetPreference ( ) { Preference showBottomSheetPreference = findPreference ( getString ( R . string . show_bottom_sheet_preference_key ) ) ; showBottomSheetPreference . setOnPreferenceClickListener ( new OnPreferenceClickListener ( ) { public boolean onPreferenceClick ( final Preference preference ) { initializeBottomSheet ( ) ; bottomSheet . show ( ) ; return true ; } } ) ; }
Initializes the preference which allows to show a bottom sheet .
24,296
private void initializeShowCustomBottomSheetPreference ( ) { Preference showCustomBottomSheetPreference = findPreference ( getString ( R . string . show_custom_bottom_sheet_preference_key ) ) ; showCustomBottomSheetPreference . setOnPreferenceClickListener ( new OnPreferenceClickListener ( ) { public boolean onPreferenceClick ( final Preference preference ) { initializeCustomBottomSheet ( ) ; customBottomSheet . show ( ) ; return true ; } } ) ; }
Initializes the preference which allows to show a bottom sheet with custom content .
24,297
private void initializeShowIntentBottmSheetPreference ( ) { Preference showIntentBottomSheetPreference = findPreference ( getString ( R . string . show_intent_bottom_sheet_preference_key ) ) ; showIntentBottomSheetPreference . setOnPreferenceClickListener ( new OnPreferenceClickListener ( ) { public boolean onPreferenceClick ( Preference preference ) { initializeIntentBottomSheet ( ) ; intentBottomSheet . show ( ) ; return true ; } } ) ; }
Initializes the preference which allows to display the applications which are suited for handling an intent .
24,298
private BottomSheet . Builder createBottomSheetBuilder ( ) { BottomSheet . Builder builder = new BottomSheet . Builder ( getActivity ( ) ) ; builder . setStyle ( getStyle ( ) ) ; if ( shouldTitleBeShown ( ) ) { builder . setTitle ( getBottomSheetTitle ( ) ) ; } if ( shouldIconBeShown ( ) ) { builder . setIcon ( android . R . drawable . ic_dialog_alert ) ; } return builder ; }
Creates and returns a builder which allows to create bottom sheets depending on the app s settings .
24,299
private void addItems ( final BottomSheet . Builder builder ) { int dividerCount = getDividerCount ( ) ; boolean showDividerTitle = shouldDividerTitleBeShown ( ) ; int itemCount = getItemCount ( ) ; boolean showIcon = shouldItemIconsBeShown ( ) ; boolean disableItems = shouldItemsBeDisabled ( ) ; int index = 0 ; for ( int i = 0 ; i < dividerCount + 1 ; i ++ ) { if ( i > 0 ) { builder . addDivider ( showDividerTitle ? getString ( R . string . divider_title , i ) : null ) ; index ++ ; } for ( int j = 0 ; j < itemCount ; j ++ ) { String title = getString ( R . string . item_title , i * itemCount + j + 1 ) ; Drawable icon ; if ( isDarkThemeSet ( ) ) { icon = showIcon ? ContextCompat . getDrawable ( getActivity ( ) , getStyle ( ) == Style . GRID ? R . drawable . grid_item_dark : R . drawable . list_item_dark ) : null ; } else { icon = showIcon ? ContextCompat . getDrawable ( getActivity ( ) , getStyle ( ) == Style . GRID ? R . drawable . grid_item : R . drawable . list_item ) : null ; } builder . addItem ( i * dividerCount + j , title , icon ) ; if ( disableItems ) { builder . setItemEnabled ( index , false ) ; } index ++ ; } } builder . setOnItemClickListener ( createItemClickListener ( ) ) ; }
Adds items depending on the app s settings to a builder which allows to create a bottom sheet .