-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActivityx.kt
200 lines (159 loc) · 7.08 KB
/
Activityx.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* Copyright (C) 2018 Peng fei Pan <panpfpanpf@outlook.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("NOTHING_TO_INLINE", "DEPRECATION")
package me.panpf.androidxkt.app
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.support.annotation.RequiresApi
import android.support.v4.app.FragmentActivity
import android.view.View
import me.panpf.androidx.app.Activityx
/**
* Return true if the activity has been destroyed
*/
inline fun Activity.isDestroyedCompat(): Boolean = Activityx.isDestroyedCompat(this)
/**
* Return true if the activity has been destroyed
*/
inline fun FragmentActivity.isDestroyedCompat(): Boolean = Activityx.isDestroyedCompat(this)
/**
* Convert a translucent themed Activity
* [android.R.attr.windowIsTranslucent] back from opaque to
* translucent following a call to
* [.convertActivityFromTranslucent] .
*
*
* Calling this allows the Activity behind this one to be seen again. Once
* all such Activities have been redrawn
*
*
* This call has no effect on non-translucent activities or on activities
* with the [android.R.attr.windowIsFloating] attribute.
*/
@RequiresApi(Build.VERSION_CODES.KITKAT)
inline fun Activity.convertToTranslucentCompat(): Boolean = Activityx.convertToTranslucentCompat(this)
/**
* Convert a translucent themed Activity
* [android.R.attr.windowIsTranslucent] to a fullscreen opaque
* Activity.
*
* Call this whenever the background of a translucent Activity has changed
* to become opaque. Doing so will allow the [android.view.Surface] of
* the Activity behind to be released.
*
* This call has no effect on non-translucent activities or on activities
* with the [android.R.attr.windowIsFloating] attribute.
*/
@RequiresApi(Build.VERSION_CODES.KITKAT)
inline fun Activity.convertFromTranslucentCompat(): Boolean = Activityx.convertFromTranslucentCompat(this)
/**
* If the own or parent activity implements the specified [clazz], it returns its implementation.
*/
inline fun <T> Activity.getImplWithParent(clazz: Class<T>): T? = Activityx.getImplWithParent(this, clazz)
inline fun Activity.appContext(): Context = Activityx.appContext(this)
/* ************************************* start ***************************************** */
/**
* Test if you can start Activity
*/
inline fun Context.canStartActivity(intent: Intent): Boolean = Activityx.canStart(this, intent)
/**
* Start the activity of the specified Class
*/
inline fun View.startActivity(intent: Intent) = Activityx.start(this, intent)
/**
* Start the activity of the specified Class
*/
inline fun Context.startActivity(clazz: Class<out Activity>, args: Bundle?) = Activityx.start(this, clazz, args)
/**
* Start the activity of the specified Class
*/
inline fun Context.startActivity(clazz: Class<out Activity>) = Activityx.start(this, clazz)
/**
* Start the activity of the specified Class
*/
inline fun android.support.v4.app.Fragment.startActivity(clazz: Class<out Activity>, args: Bundle?) = Activityx.start(this, clazz, args)
/**
* Start the activity of the specified Class
*/
inline fun android.support.v4.app.Fragment.startActivity(clazz: Class<out Activity>) = Activityx.start(this, clazz)
/**
* Start the activity of the specified Class
*/
inline fun android.app.Fragment.startActivity(clazz: Class<out Activity>, args: Bundle?) = Activityx.start(this, clazz, args)
/**
* Start the activity of the specified Class
*/
inline fun android.app.Fragment.startActivity(clazz: Class<out Activity>) = Activityx.start(this, clazz)
/**
* Start the activity of the specified Class
*/
inline fun View.startActivity(clazz: Class<out Activity>, args: Bundle?) = Activityx.start(this, clazz, args)
/**
* Start the activity of the specified Class
*/
inline fun View.startActivity(clazz: Class<out Activity>) = Activityx.start(this, clazz)
/* ************************************* safeStart ***************************************** */
/**
* Safely launch an Activity, catch ActivityNotFoundException and return false
*/
inline fun Context.safeStartActivity(intent: Intent): Boolean = Activityx.safeStart(this, intent)
/**
* Safely launch an Activity, catch ActivityNotFoundException and return false
*/
inline fun android.support.v4.app.Fragment.safeStartActivity(intent: Intent): Boolean = Activityx.safeStart(this, intent)
/**
* Safely launch an Activity, catch ActivityNotFoundException and return false
*/
inline fun android.app.Fragment.safeStartActivity(intent: Intent): Boolean = Activityx.safeStart(this, intent)
/**
* Safely launch an Activity, catch ActivityNotFoundException and return false
*/
inline fun View.safeStartActivity(intent: Intent): Boolean = Activityx.safeStart(this, intent)
/**
* Safely launch the activity of the specified Class, catch ActivityNotFoundException and return false
*/
inline fun Context.safeStartActivity(clazz: Class<out Activity>, args: Bundle?): Boolean = Activityx.safeStart(this, clazz, args)
/**
* Safely launch the activity of the specified Class, catch ActivityNotFoundException and return false
*/
inline fun Context.safeStartActivity(clazz: Class<out Activity>): Boolean = Activityx.safeStart(this, clazz)
/**
* Safely launch the activity of the specified Class, catch ActivityNotFoundException and return false
*/
inline fun android.support.v4.app.Fragment.safeStartActivity(clazz: Class<out Activity>, args: Bundle?): Boolean = Activityx.safeStart(this, clazz, args)
/**
* Safely launch the activity of the specified Class, catch ActivityNotFoundException and return false
*/
inline fun android.support.v4.app.Fragment.safeStartActivity(clazz: Class<out Activity>): Boolean = Activityx.safeStart(this, clazz)
/**
* Safely launch the activity of the specified Class, catch ActivityNotFoundException and return false
*/
inline fun android.app.Fragment.safeStartActivity(clazz: Class<out Activity>, args: Bundle?): Boolean = Activityx.safeStart(this, clazz, args)
/**
* Safely launch the activity of the specified Class, catch ActivityNotFoundException and return false
*/
inline fun android.app.Fragment.safeStartActivity(clazz: Class<out Activity>): Boolean = Activityx.safeStart(this, clazz)
/**
* Safely launch the activity of the specified Class, catch ActivityNotFoundException and return false
*/
inline fun View.safeStartActivity(clazz: Class<out Activity>, args: Bundle?): Boolean = Activityx.safeStart(this, clazz, args)
/**
* Safely launch the activity of the specified Class, catch ActivityNotFoundException and return false
*/
inline fun View.safeStartActivity(clazz: Class<out Activity>): Boolean = Activityx.safeStart(this, clazz)