-
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.
- Loading branch information
CullyCross
committed
Nov 5, 2015
1 parent
91363a2
commit 49678be
Showing
6 changed files
with
158 additions
and
12 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
66 changes: 66 additions & 0 deletions
66
app/src/main/java/me/cullycross/test4tabs/adapters/DoggyAdapter.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,66 @@ | ||
package me.cullycross.test4tabs.adapters; | ||
|
||
import android.content.Context; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import butterknife.Bind; | ||
import butterknife.ButterKnife; | ||
import com.squareup.picasso.Picasso; | ||
import java.util.Random; | ||
import me.cullycross.test4tabs.R; | ||
|
||
/** | ||
* Created by: Anton Shkurenko (cullycross) | ||
* Project: Test4tabs | ||
* Date: 11/5/15 | ||
* Code style: SquareAndroid (https://github.com/square/java-code-styles) | ||
* Follow me: @tonyshkurenko | ||
*/ | ||
public class DoggyAdapter extends RecyclerView.Adapter<DoggyAdapter.DogItem> { | ||
|
||
private static final String URL = "http://lorempixel.com/200/200/food/%d/%s"; | ||
|
||
private final Context mContext; | ||
private final Random mRandom; | ||
|
||
private int mCount = 50; | ||
|
||
public DoggyAdapter(Context ctx) { | ||
super(); | ||
mContext = ctx; | ||
mRandom = new Random(); | ||
} | ||
|
||
@Override public DogItem onCreateViewHolder(ViewGroup viewGroup, int viewType) { | ||
|
||
View v = LayoutInflater.from(viewGroup.getContext()) | ||
.inflate(R.layout.recycler_view_item_picture, viewGroup, false); | ||
|
||
return new DogItem(v); | ||
} | ||
|
||
@Override public void onBindViewHolder(DogItem holder, final int position) { | ||
|
||
Picasso.with(mContext) | ||
.load(String.format(URL, mRandom.nextInt(10) + 1, "Position " + position)) | ||
.fit() | ||
.centerCrop().placeholder(R.mipmap.ic_launcher).into(holder.mImage); | ||
} | ||
|
||
@Override public int getItemCount() { | ||
return mCount; | ||
} | ||
|
||
public static class DogItem extends RecyclerView.ViewHolder { | ||
|
||
@Bind(R.id.image) ImageView mImage; | ||
|
||
public DogItem(View itemView) { | ||
super(itemView); | ||
ButterKnife.bind(this, itemView); | ||
} | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
app/src/main/java/me/cullycross/test4tabs/views/AutofitRecyclerView.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,59 @@ | ||
package me.cullycross.test4tabs.views; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.support.v7.widget.GridLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.util.AttributeSet; | ||
|
||
/** | ||
* Created by: Anton Shkurenko (cullycross) | ||
* Project: Test4tabs | ||
* Date: 11/5/15 | ||
* Code style: SquareAndroid (https://github.com/square/java-code-styles) | ||
* Follow me: @tonyshkurenko | ||
* | ||
* see <a href="https://github.com/chiuki/android-recyclerview/blob/master/app/src/main/java/com/sqisland/android/recyclerview/AutofitRecyclerView.java"> | ||
* this</> | ||
*/ | ||
public class AutofitRecyclerView extends RecyclerView { | ||
private GridLayoutManager mManager; | ||
private int mColumnWidth = -1; | ||
|
||
public AutofitRecyclerView(Context context) { | ||
super(context); | ||
init(context, null); | ||
} | ||
|
||
public AutofitRecyclerView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
init(context, attrs); | ||
} | ||
|
||
public AutofitRecyclerView(Context context, AttributeSet attrs, int defStyle) { | ||
super(context, attrs, defStyle); | ||
init(context, attrs); | ||
} | ||
|
||
private void init(Context context, AttributeSet attrs) { | ||
if (attrs != null) { | ||
int[] attrsArray = { | ||
android.R.attr.columnWidth | ||
}; | ||
TypedArray array = context.obtainStyledAttributes(attrs, attrsArray); | ||
mColumnWidth = array.getDimensionPixelSize(0, -1); | ||
array.recycle(); | ||
} | ||
|
||
mManager = new GridLayoutManager(getContext(), 1); | ||
setLayoutManager(mManager); | ||
} | ||
|
||
@Override protected void onMeasure(int widthSpec, int heightSpec) { | ||
super.onMeasure(widthSpec, heightSpec); | ||
if (mColumnWidth > 0) { | ||
int spanCount = Math.max(1, getMeasuredWidth() / mColumnWidth); | ||
mManager.setSpanCount(spanCount); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,13 +1,9 @@ | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
<me.cullycross.test4tabs.views.AutofitRecyclerView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:id="@+id/recycler_view_images" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="me.cullycross.test4tabs.fragments.PicturesFragment"> | ||
|
||
<!-- TODO: Update blank fragment layout --> | ||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:text="@string/hello_blank_fragment"/> | ||
|
||
</FrameLayout> | ||
android:columnWidth="100dp" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior" | ||
/> |
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,8 @@ | ||
<ImageView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/image" | ||
android:layout_width="120dp" | ||
android:layout_height="120dp" | ||
android:layout_margin="4dp" | ||
android:src="@mipmap/ic_launcher" | ||
/> |