@@ -55,24 +55,23 @@ private static class FixedViewInfo {
5555 * The view to add to the grid
5656 */
5757 public View view ;
58- public ViewGroup viewContainer ;
58+ ViewGroup viewContainer ;
5959 /**
6060 * The data backing the view. This is returned from {@link android.widget.ListAdapter#getItem(int)}.
6161 */
6262 public Object data ;
6363 /**
6464 * <code>true</code> if the fixed view should be selectable in the grid
6565 */
66- public boolean isSelectable ;
66+ boolean isSelectable ;
6767 }
6868
69- private int mNumColumns = AUTO_FIT ;
7069 private View mViewForMeasureRowHeight = null ;
7170 private int mRowHeight = -1 ;
72- private static final String LOG_TAG = "grid-view-with- header-and -footer" ;
71+ private static final String LOG_TAG = "grid-view-header-footer" ;
7372
74- private ArrayList <FixedViewInfo > mHeaderViewInfos = new ArrayList <FixedViewInfo >();
75- private ArrayList <FixedViewInfo > mFooterViewInfos = new ArrayList <FixedViewInfo >();
73+ private ArrayList <FixedViewInfo > mHeaderViewInfos = new ArrayList <>();
74+ private ArrayList <FixedViewInfo > mFooterViewInfos = new ArrayList <>();
7675
7776 private void initHeaderGridView () {
7877 }
@@ -96,7 +95,7 @@ public GridViewWithHeaderAndFooter(Context context, AttributeSet attrs, int defS
9695 protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
9796 super .onMeasure (widthMeasureSpec , heightMeasureSpec );
9897 ListAdapter adapter = getAdapter ();
99- if (adapter != null && adapter instanceof HeaderViewGridAdapter ) {
98+ if (adapter instanceof HeaderViewGridAdapter ) {
10099 ((HeaderViewGridAdapter ) adapter ).setNumColumns (getNumColumnsCompatible ());
101100 invalidateRowHeight ();
102101 ((HeaderViewGridAdapter ) adapter ).setRowHeight (getRowHeight ());
@@ -108,15 +107,6 @@ public void setClipChildren(boolean clipChildren) {
108107 // Ignore, since the header rows depend on not being clipped
109108 }
110109
111- /**
112- * Do not call this method unless you know how it works.
113- *
114- * @param clipChildren
115- */
116- public void setClipChildrenSupper (boolean clipChildren ) {
117- super .setClipChildren (false );
118- }
119-
120110 /**
121111 * Add a fixed view to appear at the top of the grid. If addHeaderView is
122112 * called more than once, the views will appear in the order they were
@@ -263,23 +253,8 @@ private void removeFixedViewInfo(View v, ArrayList<FixedViewInfo> where) {
263253 }
264254 }
265255
266- @ TargetApi (11 )
267256 private int getNumColumnsCompatible () {
268- if (Build .VERSION .SDK_INT >= 11 ) {
269- return super .getNumColumns ();
270- } else {
271- try {
272- Field numColumns = getClass ().getSuperclass ().getDeclaredField ("mNumColumns" );
273- numColumns .setAccessible (true );
274- return numColumns .getInt (this );
275- } catch (Exception e ) {
276- if (mNumColumns != -1 ) {
277- return mNumColumns ;
278- }
279- throw new RuntimeException ("Can not determine the mNumColumns for this API platform, please call " +
280- "setNumColumns to set it." );
281- }
282- }
257+ return super .getNumColumns ();
283258 }
284259
285260 @ TargetApi (16 )
@@ -337,24 +312,14 @@ public int getRowHeight() {
337312 return mRowHeight ;
338313 }
339314
340- @ TargetApi (11 )
341315 public void tryToScrollToBottomSmoothly () {
342316 int lastPos = getAdapter ().getCount () - 1 ;
343- if (Build .VERSION .SDK_INT >= 11 ) {
344- smoothScrollToPositionFromTop (lastPos , 0 );
345- } else {
346- setSelection (lastPos );
347- }
317+ smoothScrollToPositionFromTop (lastPos , 0 );
348318 }
349319
350- @ TargetApi (11 )
351320 public void tryToScrollToBottomSmoothly (int duration ) {
352321 int lastPos = getAdapter ().getCount () - 1 ;
353- if (Build .VERSION .SDK_INT >= 11 ) {
354- smoothScrollToPositionFromTop (lastPos , 0 , duration );
355- } else {
356- setSelection (lastPos );
357- }
322+ smoothScrollToPositionFromTop (lastPos , 0 , duration );
358323 }
359324
360325 @ Override
@@ -406,9 +371,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
406371 @ Override
407372 public void setNumColumns (int numColumns ) {
408373 super .setNumColumns (numColumns );
409- mNumColumns = numColumns ;
410374 ListAdapter adapter = getAdapter ();
411- if (adapter != null && adapter instanceof HeaderViewGridAdapter ) {
375+ if (adapter instanceof HeaderViewGridAdapter ) {
412376 ((HeaderViewGridAdapter ) adapter ).setNumColumns (numColumns );
413377 }
414378 }
@@ -426,7 +390,7 @@ private static class HeaderViewGridAdapter implements WrapperListAdapter, Filter
426390 private final DataSetObservable mDataSetObservable = new DataSetObservable ();
427391 private final ListAdapter mAdapter ;
428392 static final ArrayList <FixedViewInfo > EMPTY_INFO_LIST =
429- new ArrayList <FixedViewInfo >();
393+ new ArrayList <>();
430394
431395 // This ArrayList is assumed to NOT be null.
432396 ArrayList <FixedViewInfo > mHeaderViewInfos ;
@@ -458,7 +422,7 @@ public HeaderViewGridAdapter(ArrayList<FixedViewInfo> headerViewInfos, ArrayList
458422 && areAllListInfosSelectable (mFooterViewInfos );
459423 }
460424
461- public void setNumColumns (int numColumns ) {
425+ void setNumColumns (int numColumns ) {
462426 if (numColumns < 1 ) {
463427 return ;
464428 }
@@ -468,15 +432,15 @@ public void setNumColumns(int numColumns) {
468432 }
469433 }
470434
471- public void setRowHeight (int height ) {
435+ void setRowHeight (int height ) {
472436 mRowHeight = height ;
473437 }
474438
475439 public int getHeadersCount () {
476440 return mHeaderViewInfos .size ();
477441 }
478442
479- public int getFootersCount () {
443+ int getFootersCount () {
480444 return mFooterViewInfos .size ();
481445 }
482446
@@ -496,7 +460,7 @@ private boolean areAllListInfosSelectable(ArrayList<FixedViewInfo> infos) {
496460 return true ;
497461 }
498462
499- public boolean removeHeader (View v ) {
463+ boolean removeHeader (View v ) {
500464 for (int i = 0 ; i < mHeaderViewInfos .size (); i ++) {
501465 FixedViewInfo info = mHeaderViewInfos .get (i );
502466 if (info .view == v ) {
@@ -510,7 +474,7 @@ public boolean removeHeader(View v) {
510474 return false ;
511475 }
512476
513- public boolean removeFooter (View v ) {
477+ boolean removeFooter (View v ) {
514478 for (int i = 0 ; i < mFooterViewInfos .size (); i ++) {
515479 FixedViewInfo info = mFooterViewInfos .get (i );
516480 if (info .view == v ) {
@@ -543,8 +507,7 @@ public boolean areAllItemsEnabled() {
543507 }
544508
545509 private int getAdapterAndPlaceHolderCount () {
546- final int adapterCount = (int ) (Math .ceil (1f * mAdapter .getCount () / mNumColumns ) * mNumColumns );
547- return adapterCount ;
510+ return (int ) (Math .ceil (1f * mAdapter .getCount () / mNumColumns ) * mNumColumns );
548511 }
549512
550513 @ Override
@@ -657,8 +620,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
657620 adapterCount = getAdapterAndPlaceHolderCount ();
658621 if (adjPosition < adapterCount ) {
659622 if (adjPosition < mAdapter .getCount ()) {
660- View view = mAdapter .getView (adjPosition , convertView , parent );
661- return view ;
623+ return mAdapter .getView (adjPosition , convertView , parent );
662624 } else {
663625 if (convertView == null ) {
664626 convertView = new View (parent .getContext ());
0 commit comments