first commit

This commit is contained in:
aleiva
2014-06-29 21:31:05 +02:00
commit e9540e4a1d
28 changed files with 729 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
# Gradle files
.gradle/
gradle/
./gradlew.bat
./gradlew
build/
mirror/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Intellij project files
*.iws
.idea/workspace.xml
.idea/tasks.xml
.idea
*.iml
# OS
.DS_Store
+38
View File
@@ -0,0 +1,38 @@
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
# Gradle files
.gradle/
gradle/
./gradlew.bat
./gradlew
build/
mirror/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Intellij project files
*.iws
.idea/workspace.xml
.idea/tasks.xml
.idea
*.iml
# OS
.DS_Store
+26
View File
@@ -0,0 +1,26 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-L'
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.antonioleiva.recycledviewextensions.app"
minSdkVersion 'L'
targetSdkVersion 'L'
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:recyclerview-v7:21.+'
compile 'com.squareup.picasso:picasso:1.+'
}
+17
View File
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/antonio/Documentos/Desarrollo/android-sdk-linux/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
@@ -0,0 +1,13 @@
package com.antonioleiva.recycledviewextensions.example;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
+25
View File
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.antonioleiva.recycledviewextensions.example" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.antonioleiva.recycledviewextensions.example.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
@@ -0,0 +1,65 @@
package com.antonioleiva.recycledviewextensions.example;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends Activity {
private static final String MOCK_URL = "http://lorempixel.com/800/400/nightlife/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
recyclerView.setHasFixedSize(true);
final MyRecyclerAdapter adapter;
recyclerView.setAdapter(adapter = new MyRecyclerAdapter(createMockList(), R.layout.item));
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
adapter.setOnItemClickListener(new OnRecyclerViewItemClickListener<ViewModel>() {
@Override public void onItemClick(View view, ViewModel viewModel) {
adapter.remove(viewModel);
}
});
}
private List<ViewModel> createMockList() {
List<ViewModel> items = new ArrayList<ViewModel>();
for (int i = 0; i < 20; i++) {
items.add(new ViewModel(i, "Item " + (i + 1), MOCK_URL + (i % 10 + 1)));
}
return items;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
@@ -0,0 +1,76 @@
package com.antonioleiva.recycledviewextensions.example;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.util.List;
public class MyRecyclerAdapter extends RecyclerView.Adapter<MyRecyclerAdapter.ViewHolder> implements View.OnClickListener {
private List<ViewModel> items;
private OnRecyclerViewItemClickListener<ViewModel> itemClickListener;
private int itemLayout;
public MyRecyclerAdapter(List<ViewModel> items, int itemLayout) {
this.items = items;
this.itemLayout = itemLayout;
}
@Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(itemLayout, parent, false);
v.setOnClickListener(this);
return new ViewHolder(v);
}
@Override public void onBindViewHolder(ViewHolder holder, int position) {
ViewModel item = items.get(position);
holder.text.setText(item.getText());
holder.image.setImageBitmap(null);
Picasso.with(holder.image.getContext()).cancelRequest(holder.image);
Picasso.with(holder.image.getContext()).load(item.getImage()).into(holder.image);
holder.itemView.setTag(item);
}
@Override public int getItemCount() {
return items.size();
}
@Override public void onClick(View view) {
if (itemClickListener != null) {
ViewModel model = (ViewModel) view.getTag();
itemClickListener.onItemClick(view, model);
}
}
public void add(ViewModel item, int position) {
items.add(position, item);
notifyItemInserted(position);
}
public void remove(ViewModel item) {
int position = items.indexOf(item);
items.remove(position);
notifyItemRemoved(position);
}
public void setOnItemClickListener(OnRecyclerViewItemClickListener<ViewModel> listener) {
this.itemClickListener = listener;
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public ImageView image;
public TextView text;
public ViewHolder(View itemView) {
super(itemView);
image = (ImageView) itemView.findViewById(R.id.image);
text = (TextView) itemView.findViewById(R.id.text);
}
}
}
@@ -0,0 +1,7 @@
package com.antonioleiva.recycledviewextensions.example;
import android.view.View;
public interface OnRecyclerViewItemClickListener<Model> {
public void onItemClick(View view, Model model);
}
@@ -0,0 +1,38 @@
package com.antonioleiva.recycledviewextensions.example;
public class ViewModel {
private long id;
private String text;
private String image;
public ViewModel(long id, String text, String image) {
this.id = id;
this.text = text;
this.image = image;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

+10
View File
@@ -0,0 +1,10 @@
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/spacing_xsmall"
android:clipToPadding="false"
tools:context=".MainActivity"
/>
+30
View File
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_margin="@dimen/spacing_xsmall"
android:foreground="?android:attr/selectableItemBackground"
tools:layout_gravity="center">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:tint="?android:attr/colorPrimary"
tools:src="@drawable/ic_launcher"
/>
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center"
android:background="@android:color/black"
android:padding="@dimen/spacing_large"
tools:text="Hero text"
/>
</FrameLayout>
+8
View File
@@ -0,0 +1,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>
+6
View File
@@ -0,0 +1,6 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material"/>
</resources>
@@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
+7
View File
@@ -0,0 +1,7 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="spacing_large">16dp</dimen>
<dimen name="spacing_xsmall">2dp</dimen>
</resources>

Some files were not shown because too many files have changed in this diff Show More