-
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
yangfeng
committed
Mar 17, 2022
1 parent
2154cfe
commit be2d451
Showing
56 changed files
with
1,583 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
/build |
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,44 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'kotlin-android' | ||
} | ||
|
||
android { | ||
compileSdk 31 | ||
|
||
defaultConfig { | ||
applicationId "com.yf.dialogmanager" | ||
minSdk 26 | ||
targetSdk 31 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.3.2' | ||
implementation 'androidx.appcompat:appcompat:1.2.0' | ||
implementation 'com.google.android.material:material:1.3.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' | ||
implementation project(path: ':dialogqueue') | ||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
} |
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# 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 |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/yf/dialogmanager/ExampleInstrumentedTest.kt
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,24 @@ | ||
package com.yf.dialogmanager | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.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.getInstrumentation().targetContext | ||
assertEquals("com.yf.dialogmanager", appContext.packageName) | ||
} | ||
} |
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,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.yf.dialogmanager"> | ||
|
||
<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/Theme.Dialogmanager"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name=".FistActivity"/> | ||
</application> | ||
|
||
</manifest> |
139 changes: 139 additions & 0 deletions
139
app/src/main/java/com/yf/dialogmanager/BaseDialogFragment.kt
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,139 @@ | ||
package com.yf.dialogmanager | ||
|
||
|
||
import android.content.DialogInterface | ||
import android.graphics.Color | ||
import android.graphics.drawable.ColorDrawable | ||
import android.graphics.drawable.Drawable | ||
import android.os.Bundle | ||
import android.view.Gravity | ||
import android.view.KeyEvent | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.view.WindowManager | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.fragment.app.FragmentManager | ||
|
||
|
||
/** | ||
* dialog的基类 | ||
*/ | ||
|
||
abstract class BaseDialogFragment : DialogFragment() { | ||
|
||
open var isShow = false | ||
|
||
override fun onDismiss(dialog: DialogInterface) { | ||
super.onDismiss(dialog) | ||
isShow = false | ||
mOnDismissListener?.onDismiss(dialog) | ||
} | ||
|
||
private var mOnDismissListener: DialogInterface.OnDismissListener? = null | ||
|
||
open fun setOnDismissListener(listener: DialogInterface.OnDismissListener?) { | ||
mOnDismissListener = listener | ||
} | ||
|
||
protected abstract val layoutRes: Int | ||
|
||
open fun isCancelableOutside(): Boolean { | ||
return true | ||
} | ||
|
||
open fun getDialogWidth(): Int { | ||
return WindowManager.LayoutParams.MATCH_PARENT | ||
} | ||
|
||
open fun getDialogHeight(): Int { | ||
return WindowManager.LayoutParams.WRAP_CONTENT | ||
} | ||
|
||
|
||
open fun dimAmount(): Float { | ||
return 0.3f | ||
} | ||
|
||
|
||
open fun getGravity(): Int { | ||
return Gravity.CENTER | ||
} | ||
|
||
open fun animRes(): Int { | ||
return 0 | ||
} | ||
|
||
open fun getBackgroundDrawable(): Drawable { | ||
return ColorDrawable(Color.TRANSPARENT) | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
return if (layoutRes > 0) { | ||
//调用方通过xml获取view | ||
inflater.inflate(layoutRes, container, false) | ||
} else { | ||
super.onCreateView(inflater, container, savedInstanceState) | ||
} | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
dialog?.let { | ||
//如果isCancelable()是false 则会屏蔽物理返回键 | ||
it.setCancelable(isCancelable) | ||
//如果isCancelableOutside()为false 点击屏幕外Dialog不会消失;反之会消失 | ||
it.setCanceledOnTouchOutside(isCancelableOutside()) | ||
//如果isCancelable()设置的是false 会屏蔽物理返回键 | ||
it.setOnKeyListener { _, keyCode, event -> keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN && !isCancelable } | ||
} | ||
onInitFastData() | ||
} | ||
|
||
/** | ||
* 初始化数据 | ||
*/ | ||
protected abstract fun onInitFastData() | ||
|
||
|
||
override fun onStart() { | ||
super.onStart() | ||
dialog?.let { | ||
val window = it.window ?: return | ||
//设置背景色透明 | ||
window.setBackgroundDrawable(getBackgroundDrawable()) | ||
//设置Dialog动画效果 | ||
if (animRes() > 0) { | ||
window.setWindowAnimations(animRes()) | ||
} | ||
val params = window.attributes | ||
//设置Dialog的Width | ||
params.width = getDialogWidth() | ||
//设置Dialog的Height | ||
params.height = getDialogHeight() | ||
//设置屏幕透明度 0.0f~1.0f(完全透明~完全不透明) | ||
params.dimAmount = dimAmount() | ||
params.gravity = getGravity() | ||
window.attributes = params | ||
} | ||
} | ||
|
||
override fun show(manager: FragmentManager, tag: String?) { | ||
super.show(manager, tag) | ||
isShow = true | ||
} | ||
|
||
|
||
|
||
open fun isShowing(): Boolean { | ||
dialog?.let { | ||
return it.isShowing && !isRemoving | ||
} | ||
return false | ||
} | ||
|
||
} |
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,50 @@ | ||
package com.yf.dialogmanager | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.os.Handler | ||
import android.os.Looper | ||
import androidx.fragment.app.FragmentManager | ||
import androidx.lifecycle.Lifecycle | ||
import com.dialog.queue.ActivityController | ||
import com.dialog.queue.DialogManager | ||
|
||
class FistActivity : AppCompatActivity(), ActivityController { | ||
val dialogManager = DialogManager.getInstance() | ||
val mHandler = Handler(Looper.getMainLooper()) | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_fist) | ||
dialogManager.addLifecycle(this) | ||
showDialog() | ||
} | ||
|
||
override fun getControllerLifecycle(): Lifecycle { | ||
return lifecycle | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
dialogManager.removeLifecycle(this) | ||
mHandler.removeCallbacksAndMessages(null) | ||
} | ||
|
||
override fun getControllerClass(): Class<*> { | ||
return this.javaClass | ||
} | ||
|
||
override fun getControllerFragmentManager(): FragmentManager { | ||
return supportFragmentManager | ||
} | ||
|
||
private fun showDialog() { | ||
mHandler.postDelayed({ | ||
val mFistDialogFragment = FistDialogFragment.newInstance(1) | ||
dialogManager.addQueue(1,false, mFistDialogFragment, this) | ||
}, 2000) | ||
mHandler.postDelayed({ | ||
val mFistDialogFragment = FistDialogFragment.newInstance(2) | ||
dialogManager.addQueue(0, mFistDialogFragment, this) | ||
}, 3000) | ||
} | ||
} |
Oops, something went wrong.