Skip to content

Commit 08276d3

Browse files
committed
架构搭建
0 parents  commit 08276d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+758
-0
lines changed

.gitignore

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild
10+
### Android template
11+
# Built application files
12+
*.apk
13+
*.ap_
14+
15+
# Files for the ART/Dalvik VM
16+
*.dex
17+
18+
# Java class files
19+
*.class
20+
21+
# Generated files
22+
bin/
23+
gen/
24+
out/
25+
26+
# Gradle files
27+
.gradle/
28+
build/
29+
30+
# Local configuration file (sdk path, etc)
31+
local.properties
32+
33+
# Proguard folder generated by Eclipse
34+
proguard/
35+
36+
# Log Files
37+
*.log
38+
39+
# Android Studio Navigation editor temp files
40+
.navigation/
41+
42+
# Android Studio captures folder
43+
captures/
44+
45+
# Intellij
46+
*.iml
47+
.idea/workspace.xml
48+
.idea/tasks.xml
49+
.idea/gradle.xml
50+
.idea/dictionaries
51+
.idea/libraries
52+
53+
# Keystore files
54+
*.jks
55+
56+
# External native build folder generated in Android Studio 2.2 and later
57+
.externalNativeBuild
58+
59+
# Google Services (e.g. APIs or Firebase)
60+
google-services.json
61+
62+
# Freeline
63+
freeline.py
64+
freeline/
65+
freeline_project_description.json
66+

.idea/gradle.xml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apply plugin: 'com.android.application'
2+
3+
apply plugin: 'kotlin-android'
4+
5+
apply plugin: 'kotlin-android-extensions'
6+
7+
android {
8+
compileSdkVersion 26
9+
buildToolsVersion "26.0.0"
10+
defaultConfig {
11+
applicationId "com.example.stack"
12+
minSdkVersion 16
13+
targetSdkVersion 26
14+
versionCode 1
15+
versionName "1.0"
16+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17+
}
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
}
25+
26+
dependencies {
27+
implementation fileTree(dir: 'libs', include: ['*.jar'])
28+
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
29+
exclude group: 'com.android.support', module: 'support-annotations'
30+
})
31+
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
32+
implementation 'org.jetbrains.anko:anko-commons:0.10.1'
33+
34+
implementation 'com.android.support:appcompat-v7:26+'
35+
testImplementation 'junit:junit:4.12'
36+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
37+
38+
39+
implementation 'com.android.support:design:26.0.2'
40+
implementation 'com.android.support:cardview-v7:26.0.2'
41+
}

app/proguard-rules.pro

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in F:\AndroidStudio\sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.stack
2+
3+
import android.support.test.InstrumentationRegistry
4+
import android.support.test.runner.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getTargetContext()
22+
assertEquals("com.example.stack", appContext.packageName)
23+
}
24+
}

app/src/main/AndroidManifest.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.stack">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.example.stack
2+
3+
import android.os.Bundle
4+
import android.support.v7.app.AppCompatActivity
5+
import android.support.v7.widget.LinearLayoutManager
6+
import android.support.v7.widget.RecyclerView
7+
import android.support.v7.widget.helper.ItemTouchHelper
8+
9+
class MainActivity : AppCompatActivity() {
10+
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
super.onCreate(savedInstanceState)
13+
14+
RecyclerView(this).run {
15+
setContentView(this)
16+
17+
layoutManager = LinearLayoutManager(context)
18+
val mAdapter = StackAdapter()
19+
adapter = mAdapter
20+
21+
ItemTouchHelper(StackCallBack(this,mAdapter,mAdapter.list)).attachToRecyclerView(this)
22+
}
23+
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.example.stack
2+
3+
import android.support.v7.widget.RecyclerView
4+
import android.view.View
5+
import android.view.ViewGroup
6+
import kotlinx.android.synthetic.main.item_stack.view.*
7+
import org.jetbrains.anko.toast
8+
9+
/**
10+
* Created by yanchunlan on 2017/9/3.
11+
*/
12+
class StackAdapter(val list: ArrayList<StackEntity> = arrayListOf())
13+
: RecyclerView.Adapter<StackAdapter.StackViewHolder>() {
14+
15+
private val drawables = arrayOf(R.mipmap.stack1, R.mipmap.stack2,
16+
R.mipmap.stack3, R.mipmap.stack4,
17+
R.mipmap.stack5, R.mipmap.stack6)
18+
19+
init {
20+
drawables.forEachIndexed { index, item ->
21+
list.add(StackEntity(item, index))
22+
}
23+
}
24+
25+
override fun onBindViewHolder(holder: StackViewHolder, position: Int) {
26+
with(holder.itemView) {
27+
val item=list[position]
28+
item_stack_iv.setBackgroundResource(item.mipmap)
29+
item_stack_tv.text = String.format(context.getString(R.string.item_tv), item.description)
30+
}
31+
}
32+
33+
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): StackViewHolder
34+
= StackViewHolder(View.inflate(parent?.context, R.layout.item_stack, null))
35+
36+
override fun getItemCount(): Int = list.size
37+
38+
39+
class StackViewHolder(item: View) : RecyclerView.ViewHolder(item) {
40+
init {
41+
item.setOnClickListener {
42+
it.context.toast("position: $layoutPosition 被点击了")
43+
}
44+
}
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.example.stack
2+
3+
import android.support.v7.widget.RecyclerView
4+
import android.support.v7.widget.helper.ItemTouchHelper
5+
import org.jetbrains.anko.toast
6+
7+
/**
8+
* Created by yanchunlan on 2017/9/3.
9+
*
10+
* 相对于 callback 少实现 getMovementFlags(RecyclerView recyclerView, ViewHolder viewHolder) 方法
11+
* int dragDirs, int swipeDirs
12+
* 不支持拖拽 ,支持滑动
13+
*
14+
*/
15+
class StackCallBack(val mRecyclerView: RecyclerView,
16+
val mAdapter: StackAdapter,
17+
val mData: ArrayList<StackEntity>) :
18+
ItemTouchHelper.SimpleCallback(0,
19+
ItemTouchHelper.DOWN or ItemTouchHelper.UP or ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) {
20+
21+
/**
22+
* 拖动置位 true 置位 false 不置位
23+
*/
24+
override fun onMove(recyclerView: RecyclerView?,
25+
viewHolder: RecyclerView.ViewHolder?,
26+
target: RecyclerView.ViewHolder?): Boolean = false
27+
28+
29+
/**
30+
*滑动删除
31+
*/
32+
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
33+
viewHolder.run {
34+
val item = mData.removeAt(layoutPosition)
35+
when (direction) {
36+
ItemTouchHelper.DOWN -> itemView.context.toast("方向:下,滑掉的第${item.description}个美女")
37+
ItemTouchHelper.UP -> itemView.context.toast("方向:上,滑掉的第${item.description}个美女")
38+
ItemTouchHelper.LEFT -> itemView.context.toast("方向:左,滑掉的第${item.description}个美女")
39+
ItemTouchHelper.RIGHT -> itemView.context.toast("方向:右,滑掉的第${item.description}个美女")
40+
}
41+
// 加到顶部,数据重复利用
42+
mData.add(0, item)
43+
mAdapter.notifyDataSetChanged()
44+
}
45+
}
46+
47+
48+
49+
50+
51+
52+
}
53+
54+

0 commit comments

Comments
 (0)