-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from RxKotlin/modifySaveEveryNoteButton
add shareToEveryNoteButton
- Loading branch information
Showing
9 changed files
with
267 additions
and
25 deletions.
There are no files selected for viewing
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
101 changes: 101 additions & 0 deletions
101
app/src/main/java/com/kotlinchina/smallpockets/utils/AppManager.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,101 @@ | ||
package com.kotlinchina.smallpockets.utils | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
|
||
import java.util.Stack | ||
|
||
@Suppress("UNUSED_VALUE") | ||
/** | ||
* Created by junjun. | ||
*/ | ||
class AppManager private constructor() { | ||
|
||
fun addActivity(activity: Activity?) { | ||
if (activityStack == null) { | ||
activityStack = Stack<Activity>() | ||
} | ||
activityStack?.add(activity) | ||
} | ||
|
||
fun currentActivity(): Activity? { | ||
val activity = activityStack?.lastElement() | ||
return activity as? Activity | ||
} | ||
|
||
fun finishActivity() { | ||
val activity = activityStack?.lastElement() | ||
Companion.finishActivity(activity) | ||
} | ||
|
||
fun finishActivity(cls: Class<*>) { | ||
if(activityStack!=null){ | ||
activityStack?.forEach { activity: Activity -> | ||
if (activity?.javaClass == cls) { | ||
Companion.finishActivity(activity) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
fun finishAllActivity() { | ||
var i = 0 | ||
val size = activityStack?.size as Int | ||
while (i < size) { | ||
val tempActivityStack = activityStack as? Stack<Activity> | ||
if(tempActivityStack!=null && tempActivityStack?.get(i)!=null){ | ||
Companion?.finishActivity(tempActivityStack?.get(i)) | ||
break | ||
i++ | ||
} | ||
|
||
} | ||
activityStack?.clear() | ||
} | ||
|
||
fun AppExit(context: Context) { | ||
try { | ||
finishAllActivity() | ||
android.os.Process.killProcess(android.os.Process.myPid()) | ||
System.exit(0) | ||
} catch (e: Exception) { | ||
} | ||
|
||
} | ||
|
||
companion object { | ||
private var activityStack: Stack<Activity>? = null | ||
private var instance: AppManager? = null | ||
val appManager: AppManager? | ||
get() { | ||
if (instance == null) { | ||
synchronized (AppManager::class.java) { | ||
if (null == instance) { | ||
instance = AppManager() | ||
} | ||
} | ||
} | ||
return instance as? AppManager | ||
} | ||
|
||
fun getActivity(cls: Class<*>): Activity? { | ||
if (activityStack != null) | ||
activityStack?.forEach { activity:Activity -> | ||
if (activity.javaClass == cls) { | ||
return activity | ||
} | ||
} | ||
return null | ||
} | ||
|
||
fun finishActivity(activity: Activity?) { | ||
val activity = activity | ||
val canRemove = activity?.isFinishing as? Boolean | ||
if (activity != null && canRemove!=null && !canRemove) { | ||
activityStack?.remove(activity) | ||
activity?.finish() | ||
} | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
app/src/main/java/com/kotlinchina/smallpockets/utils/DoubClickExitHelper.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,53 @@ | ||
package com.kotlinchina.smallpockets.utils | ||
|
||
import android.app.Activity | ||
import android.os.Handler | ||
import android.os.Looper | ||
import android.view.KeyEvent | ||
import android.widget.Toast | ||
import com.kotlinchina.smallpockets.R | ||
|
||
/** | ||
* Created by junjun. | ||
*/ | ||
class DoubClickExitHelper(private val mActivity: Activity) { | ||
|
||
private var isOnKeyBacking: Boolean? = false | ||
private var mHandler: Handler? = null | ||
private var mBackToast: Toast? = null | ||
|
||
init { | ||
mHandler = Handler(Looper.getMainLooper()) | ||
} | ||
|
||
fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { | ||
if (keyCode != KeyEvent.KEYCODE_BACK) { | ||
return false | ||
} | ||
var isBack = isOnKeyBacking as? Boolean | ||
if (isBack!=null && isBack) { | ||
mHandler?.removeCallbacks(onBackTimeRunnable) | ||
if (mBackToast != null) { | ||
mBackToast?.cancel() | ||
} | ||
// 退出 | ||
AppManager.appManager?.AppExit(mActivity) | ||
return true | ||
} else { | ||
isOnKeyBacking = true | ||
if (mBackToast == null) { | ||
mBackToast = Toast.makeText(mActivity, R.string.double_click_exit, 2000) | ||
} | ||
mBackToast?.show() | ||
mHandler?.postDelayed(onBackTimeRunnable, 2000) | ||
return true | ||
} | ||
} | ||
|
||
private val onBackTimeRunnable = Runnable { | ||
isOnKeyBacking = false | ||
if (mBackToast != null) { | ||
mBackToast?.cancel() | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.