TestActivity.kt 72.5 KB
Newer Older
1
2
package foundation.e.blisslauncher.features.test

Amit Kumar's avatar
Amit Kumar committed
3
4
5
6
7
import android.Manifest
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
8
import android.animation.ValueAnimator
9
import android.app.ActivityOptions
Amit Kumar's avatar
Amit Kumar committed
10
import android.app.AlertDialog
Amit Kumar's avatar
Amit Kumar committed
11
import android.app.WallpaperManager
Amit Kumar's avatar
Amit Kumar committed
12
13
14
15
import android.app.usage.UsageStats
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProviderInfo
import android.content.BroadcastReceiver
Amit Kumar's avatar
Amit Kumar committed
16
import android.content.ComponentName
Amit Kumar's avatar
Amit Kumar committed
17
18
import android.content.Context
import android.content.ContextWrapper
Amit Kumar's avatar
Amit Kumar committed
19
import android.content.Intent
Amit Kumar's avatar
Amit Kumar committed
20
import android.content.IntentFilter
Amit Kumar's avatar
Amit Kumar committed
21
import android.content.pm.ActivityInfo
22
23
24
import android.content.pm.ApplicationInfo
import android.content.pm.LauncherActivityInfo
import android.content.pm.LauncherApps
Amit Kumar's avatar
Amit Kumar committed
25
import android.content.pm.PackageManager
26
import android.content.res.Configuration
Amit Kumar's avatar
Amit Kumar committed
27
import android.graphics.Point
Amit Kumar's avatar
Amit Kumar committed
28
import android.location.LocationManager
29
import android.net.Uri
30
import android.os.Bundle
Amit Kumar's avatar
Amit Kumar committed
31
import android.os.Handler
32
import android.os.Looper
33
import android.os.Process
34
35
import android.os.StrictMode
import android.os.StrictMode.VmPolicy
Amit Kumar's avatar
Amit Kumar committed
36
37
38
import android.provider.Settings
import android.text.Editable
import android.text.TextWatcher
39
40
import android.util.Log
import android.view.ContextThemeWrapper
Amit Kumar's avatar
Amit Kumar committed
41
import android.view.KeyEvent
42
import android.view.LayoutInflater
Amit Kumar's avatar
Amit Kumar committed
43
import android.view.MotionEvent
44
import android.view.View
Amit Kumar's avatar
Amit Kumar committed
45
import android.view.View.OnAttachStateChangeListener
46
import android.view.View.OnFocusChangeListener
Amit Kumar's avatar
Amit Kumar committed
47
import android.view.ViewGroup
48
import android.view.animation.AccelerateDecelerateInterpolator
Amit Kumar's avatar
Amit Kumar committed
49
50
51
52
53
54
55
56
57
58
import android.view.animation.LinearInterpolator
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.GridLayout
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.SeekBar
import android.widget.TextView
import android.widget.Toast
Amit Kumar's avatar
Amit Kumar committed
59
import androidx.core.app.ActivityCompat
Amit Kumar's avatar
Amit Kumar committed
60
61
62
63
64
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.jakewharton.rxbinding3.widget.textChanges
Amit Kumar's avatar
Amit Kumar committed
65
import foundation.e.blisslauncher.BlissLauncher
66
import foundation.e.blisslauncher.R
Amit Kumar's avatar
Amit Kumar committed
67
68
import foundation.e.blisslauncher.core.Preferences
import foundation.e.blisslauncher.core.Utilities
Amit Kumar's avatar
Amit Kumar committed
69
70
import foundation.e.blisslauncher.core.blur.BlurWallpaperProvider
import foundation.e.blisslauncher.core.broadcast.WallpaperChangeReceiver
Amit Kumar's avatar
Amit Kumar committed
71
import foundation.e.blisslauncher.core.customviews.AbstractFloatingView
Amit Kumar's avatar
Amit Kumar committed
72
73
import foundation.e.blisslauncher.core.customviews.BlissFrameLayout
import foundation.e.blisslauncher.core.customviews.BlissInput
74
import foundation.e.blisslauncher.core.customviews.LauncherPagedView
Amit Kumar's avatar
Amit Kumar committed
75
76
77
78
import foundation.e.blisslauncher.core.customviews.RoundedWidgetView
import foundation.e.blisslauncher.core.customviews.SquareFrameLayout
import foundation.e.blisslauncher.core.customviews.WidgetHost
import foundation.e.blisslauncher.core.database.DatabaseManager
79
import foundation.e.blisslauncher.core.database.model.ApplicationItem
Amit Kumar's avatar
Amit Kumar committed
80
import foundation.e.blisslauncher.core.database.model.LauncherItem
81
import foundation.e.blisslauncher.core.database.model.ShortcutItem
Amit Kumar's avatar
Amit Kumar committed
82
83
import foundation.e.blisslauncher.core.executors.AppExecutors
import foundation.e.blisslauncher.core.utils.AppUtils
Amit Kumar's avatar
Amit Kumar committed
84
import foundation.e.blisslauncher.core.utils.Constants
85
86
import foundation.e.blisslauncher.core.utils.IntSet
import foundation.e.blisslauncher.core.utils.IntegerArray
Amit Kumar's avatar
Amit Kumar committed
87
import foundation.e.blisslauncher.core.utils.ListUtil
Amit Kumar's avatar
Amit Kumar committed
88
import foundation.e.blisslauncher.core.utils.PackageUserKey
Amit Kumar's avatar
Amit Kumar committed
89
import foundation.e.blisslauncher.core.utils.UserHandle
90
import foundation.e.blisslauncher.features.launcher.AppsRepository
Amit Kumar's avatar
Amit Kumar committed
91
import foundation.e.blisslauncher.features.launcher.Hotseat
Amit Kumar's avatar
Amit Kumar committed
92
import foundation.e.blisslauncher.features.launcher.SearchInputDisposableObserver
Amit Kumar's avatar
Amit Kumar committed
93
94
95
import foundation.e.blisslauncher.features.notification.DotInfo
import foundation.e.blisslauncher.features.notification.NotificationDataProvider
import foundation.e.blisslauncher.features.notification.NotificationListener
96
97
import foundation.e.blisslauncher.features.shortcuts.DeepShortcutManager
import foundation.e.blisslauncher.features.shortcuts.ShortcutKey
Amit Kumar's avatar
Amit Kumar committed
98
99
100
import foundation.e.blisslauncher.features.suggestions.AutoCompleteAdapter
import foundation.e.blisslauncher.features.suggestions.SearchSuggestionUtil
import foundation.e.blisslauncher.features.suggestions.SuggestionsResult
Amit Kumar's avatar
Amit Kumar committed
101
102
import foundation.e.blisslauncher.features.test.LauncherState.*
import foundation.e.blisslauncher.features.test.RotationHelper.REQUEST_NONE
103
104
import foundation.e.blisslauncher.features.test.dragndrop.DragController
import foundation.e.blisslauncher.features.test.dragndrop.DragLayer
Amit Kumar's avatar
Amit Kumar committed
105
import foundation.e.blisslauncher.features.test.graphics.RotationMode
Amit Kumar's avatar
Amit Kumar committed
106
107
108
109
110
111
112
import foundation.e.blisslauncher.features.usagestats.AppUsageStats
import foundation.e.blisslauncher.features.weather.DeviceStatusService
import foundation.e.blisslauncher.features.weather.ForecastBuilder
import foundation.e.blisslauncher.features.weather.WeatherPreferences
import foundation.e.blisslauncher.features.weather.WeatherSourceListenerService
import foundation.e.blisslauncher.features.weather.WeatherUpdateService
import foundation.e.blisslauncher.features.widgets.WidgetManager
Amit Kumar's avatar
Amit Kumar committed
113
import foundation.e.blisslauncher.features.widgets.WidgetPageLayer
Amit Kumar's avatar
Amit Kumar committed
114
115
import foundation.e.blisslauncher.features.widgets.WidgetViewBuilder
import foundation.e.blisslauncher.features.widgets.WidgetsActivity
116
import foundation.e.blisslauncher.features.widgets.WidgetsRootView
Amit Kumar's avatar
Amit Kumar committed
117
import foundation.e.blisslauncher.uioverrides.OverlayCallbackImpl
118
import foundation.e.blisslauncher.uioverrides.UiFactory
Amit Kumar's avatar
Amit Kumar committed
119
120
import io.reactivex.Observable
import io.reactivex.ObservableSource
Amit Kumar's avatar
Amit Kumar committed
121
122
123
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.observers.DisposableObserver
Amit Kumar's avatar
Amit Kumar committed
124
import io.reactivex.schedulers.Schedulers
125
import java.net.URISyntaxException
126
import java.util.ArrayList
Amit Kumar's avatar
Amit Kumar committed
127
128
129
130
import java.util.Arrays
import java.util.Comparator
import java.util.Locale
import java.util.concurrent.TimeUnit
Amit Kumar's avatar
Amit Kumar committed
131
import java.util.function.Predicate
132

Amit Kumar's avatar
Amit Kumar committed
133
class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionClickListener,
134
    LauncherModel.Callbacks {
135

136
    private var mIsEditingName: Boolean = false
Amit Kumar's avatar
Amit Kumar committed
137
    private var mModel: LauncherModel? = null
138
139
140
    private lateinit var widgetRootView: WidgetsRootView
    private lateinit var overlayCallbackImpl: OverlayCallbackImpl

141
142
    // Folder start scale
    private var startScaleFinal: Float = 0f
143
    private var mCancelTouchController: Runnable? = null
Amit Kumar's avatar
Amit Kumar committed
144
145
    private var mOnResumeCallback: OnResumeCallback? = null
    private lateinit var mAppTransitionManager: LauncherAppTransitionManager
146
    lateinit var dragController: DragController
147
    private lateinit var mOldConfig: Configuration
Amit Kumar's avatar
Amit Kumar committed
148
149
    private var mCompositeDisposable: CompositeDisposable? = null

Amit Kumar's avatar
Amit Kumar committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
    // Type: int
    private val RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"

    // Type: int
    private val RUNTIME_STATE = "launcher.state"

    // Type: PendingRequestArgs
    private val RUNTIME_STATE_PENDING_REQUEST_ARGS = "launcher.request_args"

    // Type: int
    private val RUNTIME_STATE_PENDING_REQUEST_CODE = "launcher.request_code"

    // Type: ActivityResultInfo
    private val RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result"

165
166
167
168
    private lateinit var launcherView: View
    private lateinit var dragLayer: DragLayer
    private lateinit var workspace: LauncherPagedView
    private lateinit var hotseat: Hotseat
Amit Kumar's avatar
Amit Kumar committed
169
    private lateinit var widgetPage: WidgetPageLayer
Amit Kumar's avatar
Amit Kumar committed
170
171
172
173

    private lateinit var mSearchInput: BlissInput

    private val REQUEST_LOCATION_SOURCE_SETTING = 267
Amit Kumar's avatar
Amit Kumar committed
174

Amit Kumar's avatar
Amit Kumar committed
175
    private lateinit var rotationHelper: RotationHelper
Amit Kumar's avatar
Amit Kumar committed
176
    private var mRotationMode = RotationMode.NORMAL
Amit Kumar's avatar
Amit Kumar committed
177
178
179
180
181
    private lateinit var mStateManager: LauncherStateManager

    // UI and state for the overview panel
    private lateinit var overviewPanel: View

182
    private val mOnResumeCallbacks = ArrayList<OnResumeCallback>()
Amit Kumar's avatar
Amit Kumar committed
183

Amit Kumar's avatar
Amit Kumar committed
184
185
    private lateinit var mAppWidgetManager: AppWidgetManager
    private lateinit var mAppWidgetHost: WidgetHost
186
    private lateinit var widgetContainer: LinearLayout
Amit Kumar's avatar
Amit Kumar committed
187
188
189
190
191
192
193
194
195
196
197
198
199
    private var activeRoundedWidgetView: RoundedWidgetView? = null

    private lateinit var mWeatherPanel: View
    private lateinit var mWeatherSetupTextView: View
    private val allAppsDisplayed = false
    private val forceRefreshSuggestedApps = false

    private var mUsageStats: List<UsageStats>? = null

    private var enableLocationDialog: AlertDialog? = null

    private var currentAnimator: AnimatorSet? = null

200
201
    private val mainHandler = Handler(Looper.getMainLooper())

Amit Kumar's avatar
Amit Kumar committed
202
203
204
205
206
207
208
209
    private val mWeatherReceiver: BroadcastReceiver = object : BroadcastReceiver() {
        override fun onReceive(context: Context, intent: Intent) {
            if (!intent.getBooleanExtra(WeatherUpdateService.EXTRA_UPDATE_CANCELLED, false)) {
                updateWeatherPanel()
            }
        }
    }

Amit Kumar's avatar
Amit Kumar committed
210
211
212
213
214
    private lateinit var notificationDataProvider: NotificationDataProvider
    val mHandler = Handler()
    private val mHandleDeferredResume = Runnable { this.handleDeferredResume() }
    private var mDeferredResumePending = false

Amit Kumar's avatar
Amit Kumar committed
215
216
    private val TAG = "TestActivity"

Amit Kumar's avatar
Amit Kumar committed
217
218
    private var wallpaperChangeReceiver: WallpaperChangeReceiver? = null

219
    override fun onCreate(savedInstanceState: Bundle?) {
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
        if (DEBUG_STRICT_MODE) {
            StrictMode.setThreadPolicy(
                StrictMode.ThreadPolicy.Builder()
                    .detectDiskReads()
                    .detectDiskWrites()
                    .detectNetwork() // or .detectAll() for all detectable problems
                    .penaltyLog()
                    .build()
            )
            StrictMode.setVmPolicy(
                VmPolicy.Builder()
                    .detectLeakedSqlLiteObjects()
                    .detectLeakedClosableObjects()
                    .penaltyLog()
                    .penaltyDeath()
                    .build()
            )
        }
        TraceHelper.beginSection("Launcher-onCreate")

240
        super.onCreate(savedInstanceState)
241
242
        TraceHelper.partitionSection("Launcher-onCreate", "super call")

Amit Kumar's avatar
Amit Kumar committed
243
        val app = LauncherAppState.getInstance(this)
Amit Kumar's avatar
Amit Kumar committed
244
        mModel = app.setLauncher(this)
245
        mOldConfig = Configuration(resources.configuration)
Amit Kumar's avatar
Amit Kumar committed
246
247
248
249

        mAppWidgetManager = BlissLauncher.getApplication(this).appWidgetManager
        mAppWidgetHost = BlissLauncher.getApplication(this).appWidgetHost

Amit Kumar's avatar
Amit Kumar committed
250
        initDeviceProfile(BlissLauncher.getApplication(this).invariantDeviceProfile)
Amit Kumar's avatar
Amit Kumar committed
251
252
        val wm = getSystemService(WALLPAPER_SERVICE) as WallpaperManager
        wm.suggestDesiredDimensions(mDeviceProfile.widthPx, mDeviceProfile.heightPx)
253
        dragController = DragController(this)
254
        rotationHelper = RotationHelper(this)
Amit Kumar's avatar
Amit Kumar committed
255
        mStateManager = LauncherStateManager(this)
256
257
        launcherView = LayoutInflater.from(this).inflate(R.layout.activity_test, null)
        setupViews()
Amit Kumar's avatar
Amit Kumar committed
258

Amit Kumar's avatar
Amit Kumar committed
259
260
261
262
        askForNotificationIfFirstTime()

        notificationDataProvider = NotificationDataProvider(this)

Amit Kumar's avatar
Amit Kumar committed
263
        mAppTransitionManager = LauncherAppTransitionManager.newInstance(this)
264

Amit Kumar's avatar
Amit Kumar committed
265
266
267
268
269
270
271
        val internalStateHandled = InternalStateHandler.handleCreate(this, intent)
        if (internalStateHandled) {
            savedInstanceState?.remove(RUNTIME_STATE)
        }
        restoreState(savedInstanceState)
        mStateManager.reapplyState()

272
        setContentView(launcherView)
Amit Kumar's avatar
Amit Kumar committed
273
274
275
276
        rootView.dispatchInsets()

        systemUiController.updateUiState(
            SystemUiController.UI_STATE_BASE_WINDOW,
Amit Kumar's avatar
Amit Kumar committed
277
            false
Amit Kumar's avatar
Amit Kumar committed
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
        )
        rotationHelper.initialize()
        TraceHelper.endSection("Launcher-onCreate")
        mStateManager.addStateListener(object : LauncherStateManager.StateListener {
            override fun onStateTransitionStart(toState: LauncherState?) {}
            override fun onStateTransitionComplete(finalState: LauncherState) {
                if (finalState === NORMAL) {
                    // TODO: may use later
                } else if (finalState === OVERVIEW || finalState === OVERVIEW_PEEK) {
                    // TODO: may use later
                } else {
                    // TODO: may use later
                }
            }
        })
Amit Kumar's avatar
Amit Kumar committed
293
294
295
296
297
298
299
300
301
302
303

        if (ActivityCompat.checkSelfPermission(
                this,
                Manifest.permission.READ_EXTERNAL_STORAGE
            ) != PackageManager.PERMISSION_GRANTED
        ) {
            requestPermissions(
                arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
                STORAGE_PERMISSION_REQUEST_CODE
            )
        }
Amit Kumar's avatar
Amit Kumar committed
304
        createOrUpdateIconGrid()
305
306
        overlayCallbackImpl = OverlayCallbackImpl(this)
        setLauncherOverlay(overlayCallbackImpl)
Amit Kumar's avatar
Amit Kumar committed
307
308
    }

Amit Kumar's avatar
Amit Kumar committed
309
310
311
312
313
    private fun askForNotificationIfFirstTime() {
        if (Preferences.shouldAskForNotificationAccess(this)) {
            val cr = contentResolver
            val setting = "enabled_notification_listeners"
            var permissionString = Settings.Secure.getString(cr, setting)
314
315
            val cn = ComponentName(this, NotificationListener::class.java)

316
317
318
319
            val enabled =
                permissionString != null && (permissionString.contains(cn.flattenToString()) || permissionString.contains(
                    cn.flattenToShortString()
                ))
320
321

            if (!enabled) {
322
323
324
325
                val launcherApps: LauncherApps =
                    getSystemService(LAUNCHER_APPS_SERVICE) as LauncherApps
                val launcherInfo =
                    launcherApps.getApplicationInfo(packageName, 0, Process.myUserHandle())
326
                if (launcherInfo.flags and ApplicationInfo.FLAG_SYSTEM == 0) {
327
328
329
330
331
332
                    val args = Bundle()
                    args.putString(":settings:fragment_args_key", cn.flattenToString())
                    val intent = Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        .putExtra(":settings:fragment_args_key", cn.flattenToString())
                        .putExtra(":settings:show_fragment_args", args)
Amit Kumar's avatar
Amit Kumar committed
333
                    startActivity(
334
                        intent
Amit Kumar's avatar
Amit Kumar committed
335
                    )
336
                } else {
Amit Kumar's avatar
Amit Kumar committed
337
338
339
340
341
342
                    if (permissionString == null) {
                        permissionString = ""
                    } else {
                        permissionString += ":"
                    }
                    permissionString += cn.flattenToString()
343
344
345

                    // Requires WRITE_SECURE_SETTINGS permission.
                    Settings.Secure.putString(cr, setting, permissionString)
Amit Kumar's avatar
Amit Kumar committed
346
347
                }
            }
348
            Preferences.setNotToAskForNotificationAccess(this)
Amit Kumar's avatar
Amit Kumar committed
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
        }
    }

    private fun handleDeferredResume() {
        mDeferredResumePending = if (hasBeenResumed() && !mStateManager.state.disableInteraction) {
            UiFactory.onLauncherStateOrResumeChanged(this)

            // Process any items that were added while Launcher was away.
            // TODO: Enable it when adding folder support
            /*InstallShortcutReceiver.disableAndFlushInstallQueue(
                InstallShortcutReceiver.FLAG_ACTIVITY_PAUSED, this
            )*/

            // Refresh shortcuts if the permission changed.
            // mModel.refreshShortcutsIfRequired()

            // Set the notification listener and fetch updated notifications when we resume
            NotificationListener.setNotificationsChangedListener(notificationDataProvider)
            false
        } else {
            true
        }
    }

    fun onStateSet(state: LauncherState) {
        if (mDeferredResumePending) {
            handleDeferredResume()
        }
    }

Amit Kumar's avatar
Amit Kumar committed
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
    /**
     * Restores the previous state, if it exists.
     *
     * @param savedState The previous state.
     */
    private fun restoreState(savedState: Bundle?) {
        if (savedState == null) {
            return
        }
        val stateOrdinal =
            savedState.getInt(RUNTIME_STATE, NORMAL.ordinal)
        val stateValues = LauncherState.values()
        val state = stateValues[stateOrdinal]
        if (!state.disableRestore) {
            mStateManager.goToState(state, false /* animated */)
        }
    }

    override fun onEnterAnimationComplete() {
        super.onEnterAnimationComplete()
        UiFactory.onEnterAnimationComplete(this)
        rotationHelper.setCurrentTransitionRequest(REQUEST_NONE)
    }

    override fun onConfigurationChanged(newConfig: Configuration) {
        val diff = newConfig.diff(mOldConfig)

        if (diff and ActivityInfo.CONFIG_LOCALE != 0) {
Amit Kumar's avatar
Amit Kumar committed
407
            // Folder.setLocaleDependentFields(resources, true /* force */)
Amit Kumar's avatar
Amit Kumar committed
408
409
410
411
            // TODO: Update folder here.
        }

        if (diff and (ActivityInfo.CONFIG_ORIENTATION or ActivityInfo.CONFIG_SCREEN_SIZE) != 0) {
Amit Kumar's avatar
Amit Kumar committed
412
            // onIdpChanged(mDeviceProfile.inv)
Amit Kumar's avatar
Amit Kumar committed
413
414
415
416
417
418
419
420
            // TODO: update device profile here.
        }

        mOldConfig.setTo(newConfig)
        UiFactory.onLauncherStateOrResumeChanged(this)
        super.onConfigurationChanged(newConfig)
    }

421
422
423
424
    private fun setupViews() {
        dragLayer = findViewById(R.id.drag_layer)
        workspace = dragLayer.findViewById(R.id.workspace)
        workspace.initParentViews(dragLayer)
Amit Kumar's avatar
Amit Kumar committed
425
        overviewPanel = findViewById(R.id.overview_panel)
426
        hotseat = findViewById(R.id.hotseat)
427

428
429
430
431
        launcherView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
        dragLayer.setup(dragController, workspace)
432
        mCancelTouchController = UiFactory.enableLiveUIChanges(this)
433
        workspace.setup(dragController)
Amit Kumar's avatar
Amit Kumar committed
434
        setupWidgetPage()
435
436
437
        workspace.bindAndInitFirstScreen(null)
        dragController.addDragListener(workspace)
        dragController.addDropTarget(workspace)
Amit Kumar's avatar
Amit Kumar committed
438
439
440

        // Setup the drag controller (drop targets have to be added in reverse order in priority)
        dragController.setMoveTarget(workspace)
Amit Kumar's avatar
Amit Kumar committed
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482

        wallpaperChangeReceiver = WallpaperChangeReceiver(workspace)
        workspace.addOnAttachStateChangeListener(object : OnAttachStateChangeListener {
            override fun onViewAttachedToWindow(v: View) {
                wallpaperChangeReceiver?.setWindowToken(v.windowToken)
            }

            override fun onViewDetachedFromWindow(v: View) {
                wallpaperChangeReceiver?.setWindowToken(null)
            }
        })
    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        if (requestCode == WeatherPreferences.LOCATION_PERMISSION_REQUEST_CODE) {
            if (grantResults.isNotEmpty() &&
                grantResults[0] == PackageManager.PERMISSION_GRANTED
            ) {
                // We only get here if user tried to enable the preference,
                // hence safe to turn it on after permission is granted
                val lm = getSystemService(LOCATION_SERVICE) as LocationManager
                if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
                    showLocationEnableDialog()
                    Preferences.setEnableLocation(this)
                } else {
                    startService(
                        Intent(this, WeatherUpdateService::class.java)
                            .setAction(WeatherUpdateService.ACTION_FORCE_UPDATE)
                    )
                }
            }
        } else if (requestCode == STORAGE_PERMISSION_REQUEST_CODE) {
            if (grantResults.isNotEmpty() &&
                grantResults[0] == PackageManager.PERMISSION_GRANTED
            ) {
                BlurWallpaperProvider.getInstance(applicationContext).updateAsync()
            }
        } else super.onRequestPermissionsResult(requestCode, permissions, grantResults)
483
484
    }

Amit Kumar's avatar
Amit Kumar committed
485
    private fun setupWidgetPage() {
486
        widgetPage =
Amit Kumar's avatar
Amit Kumar committed
487
            layoutInflater.inflate(R.layout.widgets_page, rootView, false) as WidgetPageLayer
Amit Kumar's avatar
Amit Kumar committed
488
        rootView.addView(widgetPage)
489
490
491

        widgetContainer = widgetPage.findViewById(R.id.widget_container)

492
493
494
        widgetPage.visibility = View.VISIBLE
        widgetPage.post {
            widgetPage.translationX = -(widgetPage.measuredWidth * 1.00f)
Amit Kumar's avatar
Amit Kumar committed
495
        }
496
        widgetRootView = widgetPage.findViewById(R.id.widgets_scroll_container)
Amit Kumar's avatar
Amit Kumar committed
497
        widgetPage.findViewById<View>(R.id.used_apps_layout).clipToOutline = true
498
        widgetPage.tag = "Widget page"
Amit Kumar's avatar
Amit Kumar committed
499
500
501
502

        // TODO: replace with app predictions
        // Prepare app suggestions view
        // [[BEGIN]]
503
504
505
506
        widgetPage.findViewById<View>(R.id.openUsageAccessSettings).setOnClickListener {
            startActivity(
                Intent(
                    Settings.ACTION_USAGE_ACCESS_SETTINGS
Amit Kumar's avatar
Amit Kumar committed
507
                )
508
509
            )
        }
Amit Kumar's avatar
Amit Kumar committed
510
511

        // divided by 2 because of left and right padding.
512
513
514
515
516
        val emptySpace = mDeviceProfile.availableWidthPx - 2 * Utilities.pxFromDp(16, this) - 4 *
            mDeviceProfile.cellWidthPx
        val padding = emptySpace / 10
        widgetPage.findViewById<View>(R.id.suggestedAppGrid)
            .setPadding(padding.toInt(), 0, padding.toInt(), 0)
Amit Kumar's avatar
Amit Kumar committed
517
518
519
520
521
522
523
        // [[END]]

        // Prepare search suggestion view
        // [[BEGIN]]
        mSearchInput = widgetPage.findViewById(R.id.search_input)
        val clearSuggestions: ImageView =
            widgetPage.findViewById(R.id.clearSuggestionImageView)
524
        clearSuggestions.setOnClickListener {
Amit Kumar's avatar
Amit Kumar committed
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
            mSearchInput.setText("")
            mSearchInput.clearFocus()
        }

        mSearchInput.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
            override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
                if (s.toString().trim { it <= ' ' }.isEmpty()) {
                    clearSuggestions.visibility = View.GONE
                } else {
                    clearSuggestions.visibility = View.VISIBLE
                }
            }

            override fun afterTextChanged(s: Editable) {}
        })
        val suggestionRecyclerView: RecyclerView =
            widgetPage.findViewById(R.id.suggestionRecyclerView)
        val suggestionAdapter = AutoCompleteAdapter(this)
        suggestionRecyclerView.setHasFixedSize(true)
        suggestionRecyclerView.layoutManager =
            LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
        suggestionRecyclerView.adapter = suggestionAdapter
        val dividerItemDecoration = DividerItemDecoration(
            this,
            DividerItemDecoration.VERTICAL
        )
        suggestionRecyclerView.addItemDecoration(dividerItemDecoration)
        getCompositeDisposable().add(
            mSearchInput.textChanges()
                .debounce(300, TimeUnit.MILLISECONDS)
                .map { obj: CharSequence -> obj.toString() }
                .distinctUntilChanged()
558
                .switchMap { charSequence: String? ->
Amit Kumar's avatar
Amit Kumar committed
559
560
561
562
563
564
565
                    if (charSequence != null && charSequence.isNotEmpty()) {
                        searchForQuery(charSequence)
                    } else {
                        Observable.just(
                            SuggestionsResult(charSequence)
                        )
                    }
566
                }
Amit Kumar's avatar
Amit Kumar committed
567
568
569
570
571
572
573
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(
                    SearchInputDisposableObserver(this, suggestionAdapter, widgetPage)
                )
        )

574
        mSearchInput.onFocusChangeListener =
575
            OnFocusChangeListener { v: View, hasFocus: Boolean ->
576
577
578
                if (!hasFocus) {
                    hideKeyboard(v)
                }
Amit Kumar's avatar
Amit Kumar committed
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
            }

        mSearchInput.setOnEditorActionListener { _: TextView?, action: Int, _: KeyEvent? ->
            if (action == EditorInfo.IME_ACTION_SEARCH) {
                hideKeyboard(mSearchInput)
                runSearch(mSearchInput.text.toString())
                mSearchInput.setText("")
                mSearchInput.clearFocus()
                return@setOnEditorActionListener true
            }
            false
        }
        // [[END]]

        // Prepare edit widgets button
        findViewById<View>(R.id.edit_widgets_button).setOnClickListener { view: View? ->
            startActivity(
                Intent(
                    this,
                    WidgetsActivity::class.java
                )
            )
        }

        // Prepare weather widget view
        // [[BEGIN]]
        findViewById<View>(R.id.weather_setting_imageview).setOnClickListener { v: View? ->
            startActivity(
                Intent(
                    this,
                    WeatherPreferences::class.java
                )
            )
        }

        mWeatherSetupTextView = findViewById<View>(R.id.weather_setup_textview)
        mWeatherPanel = findViewById(R.id.weather_panel)
        mWeatherPanel.setOnClickListener(View.OnClickListener { v: View? ->
            val launchIntent =
                packageManager.getLaunchIntentForPackage(
                    "foundation.e.weather"
                )
            if (launchIntent != null) {
                launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                startActivity(launchIntent)
            }
        })
        updateWeatherPanel()

        if (foundation.e.blisslauncher.features.weather.WeatherUtils.isWeatherServiceAvailable(
                this
            )
        ) {
            startService(Intent(this, WeatherSourceListenerService::class.java))
            startService(Intent(this, DeviceStatusService::class.java))
        }

        LocalBroadcastManager.getInstance(this).registerReceiver(
            mWeatherReceiver, IntentFilter(
                WeatherUpdateService.ACTION_UPDATE_FINISHED
            )
        )

        if (!Preferences.useCustomWeatherLocation(this)) {
            if (!WeatherPreferences.hasLocationPermission(this)) {
                val permissions = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)
                requestPermissions(
                    permissions,
                    WeatherPreferences.LOCATION_PERMISSION_REQUEST_CODE
                )
            } else {
                val lm = getSystemService(LOCATION_SERVICE) as LocationManager
                if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER) &&
                    Preferences.getEnableLocation(this)
                ) {
                    showLocationEnableDialog()
                    Preferences.setEnableLocation(this)
                } else {
                    startService(
                        Intent(this, WeatherUpdateService::class.java)
                            .setAction(WeatherUpdateService.ACTION_FORCE_UPDATE)
                    )
                }
            }
        } else {
            startService(
                Intent(this, WeatherUpdateService::class.java)
                    .setAction(WeatherUpdateService.ACTION_FORCE_UPDATE)
            )
        }
        // [[END]]

671
        val widgetIds: IntArray = mAppWidgetHost.appWidgetIds
Amit Kumar's avatar
Amit Kumar committed
672
673
        Arrays.sort(widgetIds)
        for (id in widgetIds) {
674
            val appWidgetInfo: AppWidgetProviderInfo? = mAppWidgetManager.getAppWidgetInfo(id)
Amit Kumar's avatar
Amit Kumar committed
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
            if (appWidgetInfo != null) {
                val hostView: RoundedWidgetView = mAppWidgetHost.createView(
                    applicationContext, id,
                    appWidgetInfo
                ) as RoundedWidgetView
                hostView.setAppWidget(id, appWidgetInfo)
                getCompositeDisposable().add(DatabaseManager.getManager(this).getHeightOfWidget(id)
                    .subscribeOn(Schedulers.from(AppExecutors.getInstance().diskIO()))
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe({ height: Int ->
                        val widgetView = WidgetViewBuilder.create(this, hostView)
                        if (height != 0) {
                            val minHeight = hostView.appWidgetInfo.minResizeHeight
                            val maxHeight = mDeviceProfile.availableHeightPx * 3 / 4
                            val normalisedDifference = (maxHeight - minHeight) / 100
                            val newHeight = minHeight + normalisedDifference * height
                            widgetView.layoutParams.height = newHeight
                        }
                        addWidgetToContainer(widgetView)
                    }) { obj: Throwable -> obj.printStackTrace() })
            }
        }
    }

    private fun addWidgetToContainer(widgetView: RoundedWidgetView) {
        widgetView.setPadding(0, 0, 0, 0)
701
        widgetContainer.addView(widgetView)
Amit Kumar's avatar
Amit Kumar committed
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
    }

    private fun updateWeatherPanel() {
        if (Preferences.getCachedWeatherInfo(this) == null) {
            mWeatherSetupTextView.visibility = View.VISIBLE
            mWeatherPanel.visibility = View.GONE
            mWeatherSetupTextView.setOnClickListener { v: View? ->
                startActivity(
                    Intent(this, WeatherPreferences::class.java)
                )
            }
            return
        }
        mWeatherSetupTextView.visibility = View.GONE
        mWeatherPanel.visibility = View.VISIBLE
        ForecastBuilder.buildLargePanel(
            this, mWeatherPanel,
            Preferences.getCachedWeatherInfo(this)
        )
    }

    private fun showLocationEnableDialog() {
        val builder = AlertDialog.Builder(this)
        // Build and show the dialog
        builder.setTitle(R.string.weather_retrieve_location_dialog_title)
        builder.setMessage(R.string.weather_retrieve_location_dialog_message)
        builder.setCancelable(false)
        builder.setPositiveButton(
            R.string.weather_retrieve_location_dialog_enable_button
        ) { dialog1, whichButton ->
            val intent =
                Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
            startActivityForResult(
                intent, REQUEST_LOCATION_SOURCE_SETTING
            )
        }
        builder.setNegativeButton(R.string.cancel, null)
        enableLocationDialog = builder.create()
        enableLocationDialog?.show()
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (requestCode == REQUEST_LOCATION_SOURCE_SETTING) {
            val lm = getSystemService(LOCATION_SERVICE) as LocationManager
            if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
                Toast.makeText(
                    this, "Set custom location in weather settings.",
                    Toast.LENGTH_SHORT
                ).show()
            } else {
                startService(
                    Intent(this, WeatherUpdateService::class.java)
                        .setAction(WeatherUpdateService.ACTION_FORCE_UPDATE)
                )
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data)
        }
    }

    private fun searchForQuery(
        charSequence: CharSequence
    ): ObservableSource<SuggestionsResult?>? {
        val launcherItems = searchForLauncherItems(
            charSequence.toString()
        ).subscribeOn(Schedulers.io())
        val networkItems = searchForNetworkItems(
            charSequence
        ).subscribeOn(Schedulers.io())
        return launcherItems.mergeWith(networkItems)
    }

    private fun searchForLauncherItems(
        charSequence: CharSequence
    ): Observable<SuggestionsResult?> {
778
        val query = charSequence.toString().lowercase(Locale.getDefault())
Amit Kumar's avatar
Amit Kumar committed
779
780
781
782
        val suggestionsResult = SuggestionsResult(
            query
        )
        val launcherItems: MutableList<LauncherItem> = ArrayList()
783
784
785
786
        workspace.mapOverItems(true) { item, _, _ ->
            Log.i(TAG, "searchForLauncherItems: ${item.title}")
            if (item.title.toString().lowercase(Locale.getDefault()).contains(query)) {
                launcherItems.add(item)
Amit Kumar's avatar
Amit Kumar committed
787
            }
788
            false
Amit Kumar's avatar
Amit Kumar committed
789
790
        }
        launcherItems.sortWith(Comparator.comparing { launcherItem: LauncherItem ->
791
            launcherItem.title.toString().lowercase(Locale.getDefault()).indexOf(query)
Amit Kumar's avatar
Amit Kumar committed
792
793
794
795
796
797
        })
        if (launcherItems.size > 4) {
            suggestionsResult.launcherItems = launcherItems.subList(0, 4)
        } else {
            suggestionsResult.launcherItems = launcherItems
        }
798
        Log.i(TAG, "searchForLauncherItems: $suggestionsResult")
Amit Kumar's avatar
Amit Kumar committed
799
        return Observable.just(suggestionsResult)
800
801
            .onErrorReturn {
                it.printStackTrace()
Amit Kumar's avatar
Amit Kumar committed
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
                suggestionsResult.launcherItems = ArrayList()
                suggestionsResult
            }
    }

    private fun searchForNetworkItems(charSequence: CharSequence): Observable<SuggestionsResult?> {
        val query = charSequence.toString().lowercase(Locale.getDefault()).trim { it <= ' ' }
        val suggestionProvider = SearchSuggestionUtil().getSuggestionProvider(
            this
        )
        return suggestionProvider.query(query).toObservable()
    }

    fun hideWidgetResizeContainer() {
        val widgetResizeContainer: RelativeLayout = widgetPage.findViewById<RelativeLayout>(
            R.id.widget_resizer_container
        )
        if (widgetResizeContainer.visibility == View.VISIBLE) {
            currentAnimator?.cancel()
            val set = AnimatorSet()
            set.play(
                ObjectAnimator.ofFloat(
                    widgetResizeContainer, View.Y,
                    mDeviceProfile.availableHeightPx
                        .toFloat()
                )
            )
            set.duration = 200
            set.interpolator = LinearInterpolator()
            set.addListener(object : AnimatorListenerAdapter() {
                override fun onAnimationStart(animation: Animator) {
                    super.onAnimationStart(animation)
                    (widgetPage.findViewById<View>(
                        R.id.widget_resizer_seekbar
                    ) as SeekBar).setOnSeekBarChangeListener(null)
                }

                override fun onAnimationCancel(animation: Animator) {
                    super.onAnimationCancel(animation)
                    currentAnimator = null
                    widgetResizeContainer.visibility = View.VISIBLE
                }

                override fun onAnimationEnd(animation: Animator) {
                    super.onAnimationEnd(animation)
                    currentAnimator = null
                    widgetResizeContainer.visibility = View.GONE
                    activeRoundedWidgetView?.removeBorder()
                }
            }
            )
            set.start()
            currentAnimator = set
        }
    }

    fun hideKeyboard(view: View) {
        val inputMethodManager = (getSystemService(
            INPUT_METHOD_SERVICE
        ) as InputMethodManager)
        inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
    }

    fun showKeyboard(view: View?) {
        val inputMethodManager = (getSystemService(
            INPUT_METHOD_SERVICE
        ) as InputMethodManager)
        inputMethodManager.showSoftInput(view, 0)
    }

    private fun runSearch(query: String) {
        val intent = Intent(
            Intent.ACTION_VIEW,
            SearchSuggestionUtil().getUriForQuery(this, query)
        )
        startActivity(intent)
    }

    fun showWidgetResizeContainer(roundedWidgetView: RoundedWidgetView) {
        val widgetResizeContainer: RelativeLayout = widgetPage.findViewById<RelativeLayout>(
            R.id.widget_resizer_container
        )
        if (widgetResizeContainer.visibility != View.VISIBLE) {
            activeRoundedWidgetView = roundedWidgetView
            val seekBar = widgetResizeContainer.findViewById<SeekBar>(R.id.widget_resizer_seekbar)
            if (currentAnimator != null) {
                currentAnimator!!.cancel()
            }
            seekBar.setOnTouchListener { v: View?, event: MotionEvent? ->
                seekBar.parent.requestDisallowInterceptTouchEvent(true)
                false
            }
            val set = AnimatorSet()
            set.play(
                ObjectAnimator.ofFloat(
                    widgetResizeContainer, View.Y,
                    mDeviceProfile.availableHeightPx.toFloat(),
                    mDeviceProfile.availableHeightPx - Utilities.pxFromDp(48, this)
                )
            )
            set.duration = 200
            set.interpolator = LinearInterpolator()
            set.addListener(object : AnimatorListenerAdapter() {
                override fun onAnimationStart(animation: Animator) {
                    super.onAnimationStart(animation)
                    widgetResizeContainer.visibility = View.VISIBLE
                }

                override fun onAnimationCancel(animation: Animator) {
                    super.onAnimationCancel(animation)
                    currentAnimator = null
                    widgetResizeContainer.visibility = View.GONE
                    roundedWidgetView.removeBorder()
                }

                override fun onAnimationEnd(animation: Animator) {
                    super.onAnimationEnd(animation)
                    currentAnimator = null
                    prepareWidgetResizeSeekBar(seekBar)
                    roundedWidgetView.addBorder()
                }
            }
            )
            set.start()
            currentAnimator = set
        }
    }

    private fun prepareWidgetResizeSeekBar(seekBar: SeekBar) {
        val minHeight = activeRoundedWidgetView!!.appWidgetInfo.minResizeHeight
        val maxHeight = mDeviceProfile.availableHeightPx * 3 / 4
        val normalisedDifference = (maxHeight - minHeight) / 100
        val defaultHeight = activeRoundedWidgetView!!.height
        val currentProgress = (defaultHeight - minHeight) * 100 / (maxHeight - minHeight)
        seekBar.max = 100
        seekBar.progress = currentProgress
        seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
            override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
                val newHeight = minHeight + normalisedDifference * progress
941
942
                val layoutParams =
                    activeRoundedWidgetView!!.layoutParams as LinearLayout.LayoutParams
Amit Kumar's avatar
Amit Kumar committed
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
                layoutParams.height = newHeight
                activeRoundedWidgetView!!.layoutParams = layoutParams
                val newOps = Bundle()
                newOps.putInt(
                    AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
                    mDeviceProfile.maxWidgetWidth
                )
                newOps.putInt(
                    AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
                    mDeviceProfile.maxWidgetWidth
                )
                newOps.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, newHeight)
                newOps.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, newHeight)
                activeRoundedWidgetView!!.updateAppWidgetOptions(newOps)
                activeRoundedWidgetView!!.requestLayout()
            }

            override fun onStartTrackingTouch(seekBar: SeekBar) {}
            override fun onStopTrackingTouch(seekBar: SeekBar) {
                DatabaseManager.getManager(this@TestActivity).saveWidget(
                    activeRoundedWidgetView!!.appWidgetId, seekBar.progress
                )
            }
        })
    }

969
970
971
972
    override fun <T : View> findViewById(id: Int): T {
        return launcherView.findViewById(id)
    }

Amit Kumar's avatar
Amit Kumar committed
973
974
    fun getRotationHelper() = rotationHelper

Amit Kumar's avatar
Amit Kumar committed
975
976
    private fun initDeviceProfile(idp: InvariantDeviceProfile) {
        // Load device specific profile
977
        mDeviceProfile = idp.getDeviceProfile(this)
Amit Kumar's avatar
Amit Kumar committed
978
979
980
981
982
983
984
        if (isInMultiWindowMode) {
            val display = windowManager.defaultDisplay
            val mwSize = Point()
            display.getSize(mwSize)
            mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize)
        }
        mRotationMode = RotationMode.NORMAL
Amit Kumar's avatar
Amit Kumar committed
985
986
987
        onDeviceProfileInitiated()
    }

Amit Kumar's avatar
Amit Kumar committed
988
989
990
991
992
993
    override fun onPause() {
        super.onPause()
        dragController.cancelDrag()
        dragController.resetLastGestureUpTime()
    }

994
995
    override fun onResume() {
        super.onResume()
Amit Kumar's avatar
Amit Kumar committed
996
997
998
        mHandler.removeCallbacks(mHandleDeferredResume)
        Utilities.postAsyncCallback(mHandler, mHandleDeferredResume)

999
1000
        if (mOnResumeCallbacks.isNotEmpty()) {
            val resumeCallbacks = ArrayList(mOnResumeCallbacks)