Skip to content

Commit 16fe2cb

Browse files
committed
Cleanup code
1 parent 4846f4f commit 16fe2cb

Some content is hidden

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

44 files changed

+199
-190
lines changed

.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

archLintRules/src/main/java/me/ycdev/android/arch/lint/MyIssueRegistry.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ package me.ycdev.android.arch.lint
33
import com.android.tools.lint.client.api.IssueRegistry
44
import com.android.tools.lint.client.api.Vendor
55
import com.android.tools.lint.detector.api.Issue
6-
import java.util.Arrays
76

8-
@Suppress("UnstableApiUsage")
7+
@Suppress("unused")
98
class MyIssueRegistry : IssueRegistry() {
109
override val issues: List<Issue>
1110
get() {
1211
println("!!!!!!!!!!!!! ArchLib lint rules works")
13-
return Arrays.asList(
12+
return listOf(
1413
MyToastHelperDetector.ISSUE,
1514
MyBroadcastHelperDetector.ISSUE,
1615
MyBaseActivityDetector.ISSUE,

archLintRules/src/test/java/me/ycdev/android/arch/lint/MyBaseActivityDetectorTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class MyBaseActivityDetectorTest {
210210
"public class LintViolationActivity extends AppCompatActivity { // lint violation\n" +
211211
" private static final String TEST_ACTION = \"action.test\";\n" +
212212
"\n" +
213-
" private BroadcastReceiver mReceiver = new BroadcastReceiver() {\n" +
213+
" private final BroadcastReceiver mReceiver = new BroadcastReceiver() {\n" +
214214
" @Override\n" +
215215
" public void onReceive(Context context, Intent intent) {\n" +
216216
" // nothing to do\n" +
@@ -306,7 +306,7 @@ class MyBaseActivityDetectorTest {
306306
" }\n" +
307307
"\n" +
308308
" companion object {\n" +
309-
" private val TEST_ACTION = \"action.test\"\n" +
309+
" private const val TEST_ACTION = \"action.test\"\n" +
310310
" }\n" +
311311
"}\n"
312312
)

archLintRules/src/test/java/me/ycdev/android/arch/lint/MyBroadcastHelperDetectorTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class MyBroadcastHelperDetectorTest {
120120
" Foo().sendBroadcast()\n" +
121121
" }\n" +
122122
"\n" +
123-
" fun registerGood(cxt: Context, receiver: BroadcastReceiver, filter: IntentFilter): Intent? {\n" +
123+
" fun registerGood(cxt: Context, receiver: BroadcastReceiver, filter: IntentFilter): Intent {\n" +
124124
" return BroadcastHelper.registerForInternal(cxt, receiver, filter) // lint good\n" +
125125
" }\n" +
126126
"\n" +
@@ -140,15 +140,15 @@ class MyBroadcastHelperDetectorTest {
140140
" cxt: Context,\n" +
141141
" receiver: BroadcastReceiver,\n" +
142142
" filter: IntentFilter\n" +
143-
" ): Intent? {\n" +
143+
" ): Intent {\n" +
144144
" return cxt.registerReceiver(receiver, filter) // lint violation\n" +
145145
" }\n" +
146146
"\n" +
147147
" fun registerViolation2(\n" +
148148
" cxt: Context,\n" +
149149
" receiver: BroadcastReceiver,\n" +
150150
" filter: IntentFilter\n" +
151-
" ): Intent? {\n" +
151+
" ): Intent {\n" +
152152
" return cxt.registerReceiver(receiver, filter, null, null) // lint violation\n" +
153153
" }\n" +
154154
"\n" +
@@ -203,7 +203,7 @@ class MyBroadcastHelperDetectorTest {
203203
"public class LintViolationActivity extends AppCompatActivity { // lint violation\n" +
204204
" private static final String TEST_ACTION = \"action.test\";\n" +
205205
"\n" +
206-
" private BroadcastReceiver mReceiver = new BroadcastReceiver() {\n" +
206+
" private final BroadcastReceiver mReceiver = new BroadcastReceiver() {\n" +
207207
" @Override\n" +
208208
" public void onReceive(Context context, Intent intent) {\n" +
209209
" // nothing to do\n" +
@@ -303,7 +303,7 @@ class MyBroadcastHelperDetectorTest {
303303
" }\n" +
304304
"\n" +
305305
" companion object {\n" +
306-
" private val TEST_ACTION = \"action.test\"\n" +
306+
" private const val TEST_ACTION = \"action.test\"\n" +
307307
" }\n" +
308308
"}\n"
309309
)

archLintRules/src/test/java/me/ycdev/android/arch/lint/MyIntentHelperDetectorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class MyIntentHelperDetectorTest {
119119
" return IntentHelper.getBooleanExtra(intent, key, defValue) // lint good\n" +
120120
" }\n" +
121121
"\n" +
122-
" fun getBundleExtraGood(intent: Intent, key: String): Bundle? {\n" +
122+
" fun getBundleExtraGood(intent: Intent, key: String): Bundle {\n" +
123123
" return IntentHelper.getBundleExtra(intent, key) // lint good\n" +
124124
" }\n" +
125125
"\n" +

archLintRules/src/test/java/me/ycdev/android/arch/lint/utils/TestFileStubs.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ object TestFileStubs {
196196
"import android.app.Activity;\n" +
197197
"\n" +
198198
"/**\n" +
199-
" * Base class for Activity which wants to inherit {@link android.app.Activity}.\n" +
199+
" * Base class for Activity which wants to inherit android.app.Activity.\n" +
200200
" */\n" +
201201
"public abstract class BaseActivity extends Activity {\n" +
202202
" // nothing to do right now\n" +
@@ -305,7 +305,7 @@ object TestFileStubs {
305305
306306
private fun onIntentAttacked(intent: Intent, e: Throwable) {
307307
// prevent OOM for Android 5.0~?
308-
intent.replaceExtras((null as Bundle?)!!)
308+
intent.replaceExtras(null)
309309
LibLogger.w(TAG, "attacked?", e)
310310
}
311311
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package me.ycdev.android.arch.demo.activity
22

3-
import android.os.Bundle
43
import me.ycdev.android.arch.activity.BaseActivity
54

65
open class LintGood2Activity : BaseActivity() { // lint good
7-
override fun onCreate(savedInstanceState: Bundle?) {
8-
super.onCreate(savedInstanceState)
9-
}
106
}

archLintRulesTestDemo/src/main/java/me/ycdev/android/arch/demo/activity/LintGoodActivity.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package me.ycdev.android.arch.demo.activity
22

3-
import android.os.Bundle
43
import android.view.Menu
54
import android.view.MenuItem
65
import me.ycdev.android.arch.activity.AppCompatBaseActivity
76

87
class LintGoodActivity : AppCompatBaseActivity() { // lint good
98

10-
override fun onCreate(savedInstanceState: Bundle?) {
11-
super.onCreate(savedInstanceState)
12-
}
13-
149
override fun onCreateOptionsMenu(menu: Menu): Boolean {
1510
// Inflate the menu; this adds items to the action bar if it is present.
1611
return true
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package me.ycdev.android.arch.demo.activity
22

33
import android.app.Activity
4-
import android.os.Bundle
54

65
// class comment for test
76
class LintViolation2Activity : Activity() { // lint violation
8-
override fun onCreate(savedInstanceState: Bundle?) {
9-
super.onCreate(savedInstanceState)
10-
}
117
}

archLintRulesTestDemo/src/main/java/me/ycdev/android/arch/demo/activity/LintViolationActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ class LintViolationActivity : AppCompatActivity() { // lint violation
4444
}
4545

4646
companion object {
47-
private val TEST_ACTION = "action.test"
47+
private const val TEST_ACTION = "action.test"
4848
}
4949
}

archLintRulesTestDemo/src/main/java/me/ycdev/android/arch/demo/wrapper/BroadcastHelperLintCase.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("unused")
2+
13
package me.ycdev.android.arch.demo.wrapper
24

35
import android.content.BroadcastReceiver

baseLib/src/androidTest/ant.properties

Lines changed: 0 additions & 19 deletions
This file was deleted.

baseLib/src/androidTest/java/me/ycdev/android/lib/common/async/AsyncTaskQueueTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class AsyncTaskQueueTest {
9393

9494
val count = 100
9595
val latch = CountDownLatch(count)
96-
val countTask = CountTask(Runnable { latch.countDown() })
96+
val countTask = CountTask { latch.countDown() }
9797
for (i in 0 until count) {
9898
taskQueue.addTask(countTask)
9999
}
@@ -111,7 +111,7 @@ class AsyncTaskQueueTest {
111111

112112
val count = 100
113113
val latch = CountDownLatch(count)
114-
val countTask = CountTask(Runnable { latch.countDown() })
114+
val countTask = CountTask { latch.countDown() }
115115
for (i in 0 until count) {
116116
taskQueue.addTask(200, countTask)
117117
}
@@ -177,7 +177,7 @@ class AsyncTaskQueueTest {
177177

178178
val count = 100
179179
val latch = CountDownLatch(count)
180-
val countTask = CountTask(Runnable { latch.countDown() })
180+
val countTask = CountTask { latch.countDown() }
181181
for (i in 0 until count) {
182182
taskQueue.removeTask(countTask)
183183
taskQueue.addTask(200, countTask)
@@ -208,7 +208,7 @@ class AsyncTaskQueueTest {
208208
taskQueue.setWorkerThreadAutoQuitDelay(autoQuitDelay)
209209

210210
val latch = CountDownLatch(1)
211-
taskQueue.addTask(100, Runnable { latch.countDown() })
211+
taskQueue.addTask(100) { latch.countDown() }
212212
latch.await()
213213

214214
// check if task thread already quited
@@ -226,7 +226,7 @@ class AsyncTaskQueueTest {
226226
taskQueue.setWorkerThreadAutoQuitDelay(0)
227227

228228
val latch = CountDownLatch(1)
229-
taskQueue.addTask(100, Runnable { latch.countDown() })
229+
taskQueue.addTask(100) { latch.countDown() }
230230
latch.await()
231231

232232
// check if task thread already quited
@@ -266,9 +266,9 @@ class AsyncTaskQueueTest {
266266
assertThat(taskTidHolder1[0]).isNotEqualTo(taskTidHolder2[0])
267267
}
268268

269-
private class CountTask internal constructor(@param:Nullable private val mTask: Runnable?) :
269+
private class CountTask(@param:Nullable private val mTask: Runnable?) :
270270
Runnable {
271-
internal var executedCount: Int = 0
271+
var executedCount: Int = 0
272272
private set
273273

274274
override fun run() {

baseLib/src/androidTest/java/me/ycdev/android/lib/common/demo/service/LocalService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class LocalService : Service() {
2020
}
2121

2222
@Nullable
23-
override fun onBind(intent: Intent): IBinder? {
23+
override fun onBind(intent: Intent): IBinder {
2424
return BinderServer()
2525
}
2626

baseLib/src/androidTest/java/me/ycdev/android/lib/common/demo/service/RemoteService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RemoteService : Service() {
2020
}
2121

2222
@Nullable
23-
override fun onBind(intent: Intent): IBinder? {
23+
override fun onBind(intent: Intent): IBinder {
2424
return BinderServer()
2525
}
2626

baseLib/src/androidTest/java/me/ycdev/android/lib/common/ipc/ServiceConnectorTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class ServiceConnectorTest {
321321
assertThat(connector.service).isNull()
322322
}
323323

324-
private class FakeServiceConnector internal constructor(cxt: Context) :
324+
private class FakeServiceConnector(cxt: Context) :
325325
ServiceConnector<IDemoService>(cxt, "FakeService") {
326326

327327
@NonNull
@@ -334,17 +334,17 @@ class ServiceConnectorTest {
334334
}
335335
}
336336

337-
private class NoPermServiceConnector internal constructor(cxt: Context) :
337+
private class NoPermServiceConnector(cxt: Context) :
338338
RemoteServiceConnector(cxt) {
339339

340340
override fun validatePermission(permission: String?): Boolean {
341341
return false // test no permission
342342
}
343343
}
344344

345-
private class ConnectDelayServiceConnector internal constructor(
345+
private class ConnectDelayServiceConnector(
346346
cxt: Context,
347-
internal var mConnectDelay: Long
347+
var mConnectDelay: Long
348348
) : RemoteServiceConnector(cxt) {
349349

350350
override fun asInterface(service: IBinder): IDemoService {

baseLib/src/androidTest/java/me/ycdev/android/lib/common/provider/InfoProviderClientTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package me.ycdev.android.lib.common.provider
22

3-
import android.content.Context
43
import android.database.ContentObserver
54
import android.os.Handler
65
import android.os.Looper
@@ -21,7 +20,7 @@ class InfoProviderClientTest {
2120
@Before
2221
fun setup() {
2322
mInfoClient = InfoProviderClient(
24-
ApplicationProvider.getApplicationContext<Context>(),
23+
ApplicationProvider.getApplicationContext(),
2524
"me.ycdev.android.lib.common.provider.InfoProvider"
2625
)
2726

baseLib/src/main/java/me/ycdev/android/lib/common/activity/ActivityMeta.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ data class ActivityMeta(
2626
return meta
2727
}
2828

29+
@Suppress("DEPRECATION")
2930
val info = context.packageManager.getActivityInfo(activity, 0)
3031
val taskAffinity = info.taskAffinity ?: context.applicationInfo.taskAffinity
3132
val allowTaskReparenting = (info.flags and ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) > 0

baseLib/src/main/java/me/ycdev/android/lib/common/apps/AppsLoader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import java.io.File
1414
import java.util.ArrayList
1515
import java.util.HashMap
1616

17-
@Suppress("unused")
17+
@Suppress("unused", "DEPRECATION")
1818
class AppsLoader private constructor(cxt: Context) {
1919
private val appContext: Context = cxt.applicationContext
2020
private val pm: PackageManager = cxt.packageManager

baseLib/src/main/java/me/ycdev/android/lib/common/async/AsyncTaskQueue.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ class AsyncTaskQueue(private val name: String) {
7777
}
7878

7979
fun setWorkerThreadAutoQuitDelay(delay: Long) {
80-
if (delay < WORKER_THREAD_AUTO_QUIT_DELAY_MIN) {
80+
autoQuitDelay = if (delay < WORKER_THREAD_AUTO_QUIT_DELAY_MIN) {
8181
Timber.tag(TAG).w(
8282
"Ignore the requested delay [%d]. Set it to the minimum value [%d].",
8383
delay, WORKER_THREAD_AUTO_QUIT_DELAY_MIN
8484
)
85-
autoQuitDelay = WORKER_THREAD_AUTO_QUIT_DELAY_MIN
85+
WORKER_THREAD_AUTO_QUIT_DELAY_MIN
8686
} else {
87-
autoQuitDelay = delay
87+
delay
8888
}
8989
}
9090

@@ -121,9 +121,9 @@ class AsyncTaskQueue(private val name: String) {
121121
taskHandler!!.removeMessages(MSG_WORKER_THREAD_QUIT)
122122
}
123123

124-
private class TaskParams internal constructor(
125-
internal var task: Runnable,
126-
internal var delay: Long
124+
private class TaskParams(
125+
var task: Runnable,
126+
var delay: Long
127127
)
128128

129129
companion object {

baseLib/src/main/java/me/ycdev/android/lib/common/dbmgr/SQLiteDbMgr.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class SQLiteDbMgr private constructor(cxt: Context) {
1313
private val mOpenHelpers = HashMap<Class<out SQLiteDbCreator>, DbInfo>()
1414

1515
private class DbInfo {
16-
internal var db: SQLiteDatabase? = null
17-
internal var referenceCount: Int = 0
16+
var db: SQLiteDatabase? = null
17+
var referenceCount: Int = 0
1818
}
1919

2020
private fun acquireDatabase(dbInfoClass: Class<out SQLiteDbCreator>): SQLiteDatabase? {

baseLib/src/main/java/me/ycdev/android/lib/common/ipc/ServiceConnector.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger
2525
* @param connectLooper The looper used to connect/reconnect target Service.
2626
* By default, it's the main looper.
2727
*/
28+
@Suppress("DEPRECATION")
2829
abstract class ServiceConnector<IServiceInterface> protected constructor(
2930
cxt: Context,
3031
protected var serviceName: String,

0 commit comments

Comments
 (0)