Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
w0330t committed Aug 26, 2017
0 parents commit 6e6c24d
Show file tree
Hide file tree
Showing 54 changed files with 818 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
36 changes: 36 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "net.blueness.recyclerviewtest"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'org.jetbrains.anko:anko-common:0.10.1'
implementation 'com.android.support:appcompat-v7:26.0.1'
implementation 'com.android.support:recyclerview-v7:26.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.0'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.0'
}
25 changes: 25 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\Blueness\AppData\Local\Android\Sdk/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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.blueness.recyclerviewtest

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("net.blueness.recyclerviewtest", appContext.packageName)
}
}
21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.blueness.recyclerviewtest">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
7 changes: 7 additions & 0 deletions app/src/main/java/net/blueness/recyclerviewtest/Fruit.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.blueness.listviewtest

/**
* Created by Blueness on 2017/8/25.
*/

class Fruit(val name: String, val imageId: Int)
38 changes: 38 additions & 0 deletions app/src/main/java/net/blueness/recyclerviewtest/FruitAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.blueness.recyclerviewtest

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 net.blueness.listviewtest.Fruit
import org.jetbrains.anko.find

/**
* Created by Blueness on 2017/8/26.
*/

class FruitAdapter(private val mFruitList: MutableList<Fruit>):
RecyclerView.Adapter<FruitAdapter.ViewHolder>() {

class ViewHolder(val view: View): RecyclerView.ViewHolder(view) {
val fruitImage: ImageView = view.find(R.id.fruit_image)
val fruitName: TextView = view.find(R.id.fruit_name)
}

override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder{
val view = LayoutInflater.from(parent!!.context).inflate(R.layout.fruit_item, parent, false)
return ViewHolder(view)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val fruit = mFruitList.get(position)
holder.fruitImage.setImageResource(fruit.imageId)
holder.fruitName.setText(fruit.name)
}

override fun getItemCount(): Int {
return mFruitList.size
}
}
63 changes: 63 additions & 0 deletions app/src/main/java/net/blueness/recyclerviewtest/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package net.blueness.recyclerviewtest

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.StaggeredGridLayoutManager
import net.blueness.listviewtest.Fruit
import org.jetbrains.anko.find
import java.util.*

class MainActivity : AppCompatActivity() {

private val fruitList: MutableList<Fruit> = arrayListOf()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

initFruitLists();
val recyclerView: RecyclerView = find(R.id.recycler_view)
// val layoutManager = LinearLayoutManager(this)
// layoutManager.orientation = LinearLayoutManager.HORIZONTAL
val layoutManager = StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL)
recyclerView.layoutManager = layoutManager
val fruitAdapter = FruitAdapter(fruitList)
recyclerView.adapter = fruitAdapter
}

private fun initFruitLists() {
for (i in 0..2){
val apple = Fruit(getRandomLengthName("Apple"), R.drawable.apple_pic)
fruitList.add(apple)
val banana = Fruit(getRandomLengthName("Banana"), R.drawable.banana_pic)
fruitList.add(banana)
val orange = Fruit(getRandomLengthName("Orange"), R.drawable.orange_pic)
fruitList.add(orange)
val watermelon = Fruit(getRandomLengthName("Watermelon"), R.drawable.watermelon_pic)
fruitList.add(watermelon)
val pear = Fruit(getRandomLengthName("Pear"), R.drawable.pear_pic)
fruitList.add(pear)
val grape = Fruit(getRandomLengthName("Grape"), R.drawable.grape_pic)
fruitList.add(grape)
val pineapple = Fruit(getRandomLengthName("Pineapple"), R.drawable.pineapple_pic)
fruitList.add(pineapple)
val strawberry = Fruit(getRandomLengthName("Strawberry"), R.drawable.strawberry_pic)
fruitList.add(strawberry)
val cherry = Fruit(getRandomLengthName("Cherry"), R.drawable.cherry_pic)
fruitList.add(cherry)
val mango = Fruit(getRandomLengthName("Mango"), R.drawable.mango_pic)
fruitList.add(mango)
}
}

private fun getRandomLengthName(name:String): String{
val lenght = Random().nextInt(20) + 1
val builder = StringBuilder()
for(i in 0..lenght){
builder.append(name + "\n")
}
return builder.toString()
}
}
Binary file added app/src/main/res/drawable-hdpi/apple_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/banana_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/cherry_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/grape_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/mango_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/orange_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/pear_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/pineapple_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/watermelon_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6e6c24d

Please sign in to comment.