forked from nickbutcher/plaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched grid dividers from item background to RV decoration. No more…
… 9-patches!
- Loading branch information
1 parent
eff9819
commit 857c311
Showing
10 changed files
with
112 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
app/src/main/java/io/plaidapp/ui/recyclerview/GridItemDividerDecoration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2015 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.plaidapp.ui.recyclerview; | ||
|
||
import android.content.Context; | ||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.support.annotation.ColorInt; | ||
import android.support.annotation.ColorRes; | ||
import android.support.annotation.DimenRes; | ||
import android.support.annotation.NonNull; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
|
||
/** | ||
* A {@link RecyclerView.ItemDecoration} which draws dividers (along the right & bottom) | ||
* for certain {@link RecyclerView.ViewHolder} types. | ||
*/ | ||
public class GridItemDividerDecoration extends RecyclerView.ItemDecoration { | ||
|
||
private final Class[] dividedClasses; | ||
private final float dividerSize; | ||
private final Paint paint; | ||
|
||
public GridItemDividerDecoration(Class[] dividedClasses, | ||
float dividerSize, | ||
@ColorInt int dividerColor) { | ||
this.dividedClasses = dividedClasses; | ||
this.dividerSize = dividerSize; | ||
paint = new Paint(); | ||
paint.setColor(dividerColor); | ||
paint.setStyle(Paint.Style.FILL); | ||
} | ||
|
||
public GridItemDividerDecoration(Class[] dividedClasses, | ||
@NonNull Context context, | ||
@DimenRes int dividerSizeResId, | ||
@ColorRes int dividerColorResId) { | ||
this(dividedClasses, | ||
context.getResources().getDimensionPixelSize(dividerSizeResId), | ||
ContextCompat.getColor(context, dividerColorResId)); | ||
} | ||
|
||
@Override | ||
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) { | ||
final int childCount = parent.getChildCount(); | ||
final RecyclerView.LayoutManager lm = parent.getLayoutManager(); | ||
for (int i = 0; i < childCount; i++) { | ||
final View child = parent.getChildAt(i); | ||
RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child); | ||
|
||
if (requiresDivider(viewHolder)) { | ||
final int right = lm.getDecoratedRight(child); | ||
final int bottom = lm.getDecoratedBottom(child); | ||
// draw the bottom divider | ||
canvas.drawRect(lm.getDecoratedLeft(child), | ||
bottom - dividerSize, | ||
right, | ||
bottom, | ||
paint); | ||
// draw the right edge divider | ||
canvas.drawRect(right - dividerSize, | ||
lm.getDecoratedTop(child), | ||
right, | ||
bottom - dividerSize, | ||
paint); | ||
} | ||
|
||
} | ||
} | ||
|
||
private boolean requiresDivider(RecyclerView.ViewHolder viewHolder) { | ||
for (int i = 0; i < dividedClasses.length; i++) { | ||
if (dividedClasses[i].isInstance(viewHolder)) return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |
Binary file not shown.
36 changes: 0 additions & 36 deletions
36
app/src/main/res/drawable-v23/designer_news_item_background.xml
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
app/src/main/res/drawable-v23/product_hunt_item_background.xml
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
app/src/main/res/drawable/designer_news_item_background.xml
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
app/src/main/res/drawable/product_hunt_item_background.xml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters