Skip to content

Commit 6ea7d72

Browse files
committed
初始化Aloading
0 parents  commit 6ea7d72

60 files changed

Lines changed: 1593 additions & 0 deletions

Some content is hidden

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

.gitignore

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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# ALoading

aloading/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

aloading/build.gradle

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android-extensions'
3+
apply plugin: 'kotlin-android'
4+
5+
android {
6+
compileSdkVersion 28
7+
8+
9+
defaultConfig {
10+
minSdkVersion 15
11+
targetSdkVersion 28
12+
versionCode 1
13+
versionName "1.0"
14+
15+
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
25+
}
26+
27+
dependencies {
28+
implementation fileTree(dir: 'libs', include: ['*.jar'])
29+
30+
implementation 'com.android.support:appcompat-v7:28.0.0'
31+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
32+
33+
}
34+
repositories {
35+
mavenCentral()
36+
}

aloading/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.baimaisu.aloading"/>
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package com.baimaisu.aloading.view
2+
3+
import android.app.Activity
4+
import android.content.Context
5+
import android.util.Log
6+
import android.view.View
7+
import android.view.ViewGroup
8+
import android.widget.FrameLayout
9+
10+
class Aloading(private var loadingViewClass: Class<out ILoadingView>) {
11+
companion object {
12+
private val loadingFactorys: MutableMap<Class<out ILoadingView>, Factory<out ILoadingView>> = mutableMapOf()
13+
14+
private val viewGroupHandlers:MutableList<ViewGroupHandler> = mutableListOf()
15+
16+
init {
17+
loadingFactorys[LoadingView::class.java] = default_factory
18+
viewGroupHandlers.add(ConstraintLayoutHandler)
19+
}
20+
21+
private var defaultLoadingViewClass: Class<out ILoadingView> = LoadingView::class.java
22+
23+
fun default(): Aloading {
24+
return Aloading(defaultLoadingViewClass)
25+
}
26+
27+
fun with(loadingViewClass: Class<out ILoadingView>): Aloading {
28+
return Aloading(loadingViewClass)
29+
}
30+
31+
}
32+
33+
class Registry {
34+
private constructor()
35+
companion object {
36+
fun setDefaultLoadingView(viewClass: Class<out ILoadingView>) {
37+
defaultLoadingViewClass = viewClass
38+
}
39+
40+
fun <T : ILoadingView> register(viewClass: Class<T>, factory: Factory<T>) {
41+
loadingFactorys[viewClass] = factory
42+
}
43+
44+
45+
fun appendViewGroupHandler(handler:ViewGroupHandler){
46+
viewGroupHandlers.add(handler)
47+
}
48+
}
49+
}
50+
51+
52+
fun wrap(act: Activity): LoadViewAdapter {
53+
return ViewWrapper(loadingFactorys[loadingViewClass]!!.create(act)).wrap(act)
54+
}
55+
56+
fun wrap(view: View): LoadViewAdapter {
57+
return ViewWrapper(loadingFactorys[loadingViewClass]!!.create(view.context)).wrap(view)
58+
}
59+
60+
61+
62+
63+
private inner class ViewWrapper(private var loadingView: ILoadingView) {
64+
65+
66+
67+
fun wrap(act: Activity): LoadViewAdapter {
68+
return wrap(act.findViewById<View>(android.R.id.content))
69+
}
70+
71+
72+
private fun wrapDefaultByFrameLayout(view: View): LoadViewAdapter {
73+
val wrapper = FrameLayout(view.context)
74+
val lp = view.layoutParams
75+
if (lp != null) {
76+
wrapper.layoutParams = lp
77+
}
78+
if (view.parent != null) {
79+
val parent = view.parent as ViewGroup
80+
val index = parent.indexOfChild(view)
81+
parent.removeView(view)
82+
parent.addView(wrapper, index)
83+
}
84+
val newLp =
85+
FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
86+
wrapper.addView(view, newLp)
87+
wrapper.addView(
88+
loadingView.getView(),
89+
FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
90+
)
91+
loadingView.getView().bringToFront()
92+
return LoadViewAdapter(loadingView, wrapper)
93+
}
94+
95+
/**
96+
* if(view not has parent){
97+
* return wrapDefaultByFrameLayout();
98+
* }else if(constraintLayoutClass.isAssignableFrom(view.getParent().getClass()){
99+
* return wrapConstraintLayout()
100+
* }else if(***.class.isAssignableFrom(view.getParent().getClass()){
101+
* return wrap***Layout();
102+
* }else{
103+
* return wrapDefaultByFrameLayout()
104+
* }
105+
*/
106+
fun wrap(view: View): LoadViewAdapter {
107+
if (FrameLayout::class.java.isAssignableFrom(view.javaClass)) {
108+
(view as FrameLayout).addView(
109+
loadingView.getView(),
110+
FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
111+
)
112+
loadingView.getView().bringToFront()
113+
return LoadViewAdapter(loadingView, view)
114+
}
115+
116+
if(view.parent != null){
117+
viewGroupHandlers.forEach {
118+
if(it.couldHandle(view)){
119+
return LoadViewAdapter(loadingView,it.handle(view,view.parent as ViewGroup))
120+
}
121+
}
122+
}
123+
124+
return wrapDefaultByFrameLayout(view)
125+
}
126+
127+
128+
129+
130+
}
131+
132+
133+
}
134+
135+
136+
137+
138+
139+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.baimaisu.aloading.view
2+
3+
import android.content.Context
4+
import android.view.View
5+
import java.lang.reflect.ParameterizedType
6+
7+
8+
interface ILoadingView {
9+
fun showLoading()
10+
fun showLoadFailed()
11+
fun showLoadSuccess()
12+
fun showLoadEmptyData()
13+
/**
14+
* return the loadingView
15+
*/
16+
fun getView(): View
17+
18+
}
19+
20+
interface Factory<T : ILoadingView>{
21+
fun create(context: Context):T
22+
}
23+
24+
val default_factory = object : Factory<LoadingView>{
25+
override fun create(context: Context): LoadingView {
26+
return LoadingView(context)
27+
}
28+
29+
30+
}
31+
32+
33+
abstract class SampleFactory<T : ILoadingView> : Factory<T>{
34+
override fun create(context: Context): T {
35+
val tClass:Class<T> = (this.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class<T>
36+
return tClass.getConstructor(Context::class.java).newInstance(context)
37+
}
38+
39+
40+
41+
}
42+
43+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.baimaisu.aloading.view
2+
3+
interface IReloadView {
4+
fun setReloadTask(reload:Runnable)
5+
}
6+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baimaisu.aloading.view
2+
3+
import android.view.View
4+
5+
interface IRootView {
6+
/**
7+
* return the root view
8+
*/
9+
fun rootView(): View
10+
}

0 commit comments

Comments
 (0)