Skip to content

Instantly share code, notes, and snippets.

View huuphuoc1396's full-sized avatar
🤪

Phuoc Bui huuphuoc1396

🤪
View GitHub Profile
import android.view.View
import android.widget.HorizontalScrollView
import android.widget.ListView
import android.widget.ScrollView
import androidx.core.widget.NestedScrollView
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers.*
import org.hamcrest.Matcher
import org.hamcrest.Matchers
@huuphuoc1396
huuphuoc1396 / RecyclerViewItemCountAssertion.kt
Created October 8, 2020 04:46
RecyclerView testing - Using assert item count of RecyclerView adapter
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.ViewAssertion
import androidx.test.espresso.matcher.ViewMatchers.assertThat
import org.hamcrest.Matcher
import org.hamcrest.Matchers.`is`
/**
* Using assert item count of RecyclerView adapter
@huuphuoc1396
huuphuoc1396 / RecyclerViewMatcher.kt
Created October 8, 2020 04:44
RecyclerView testing - Performing actions and matches on items by position
import android.content.res.Resources
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher
/**
* Performing actions and matches on items by position.
* @see <a href="https://github.com/dannyroa/espresso-samples">Android Espresso Samples by Danny Roa</a>
@huuphuoc1396
huuphuoc1396 / dpToPx.java
Created September 17, 2020 02:41
Convert dp, px, sp among each other (ref: https://bit.ly/35Qqyx4)
public static int dpToPx(float dp, Context context) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
}
@huuphuoc1396
huuphuoc1396 / MainActivity.kt
Created January 13, 2020 17:03
Transform and scale animation on a View
package com.android.moveandscale
import android.animation.ObjectAnimator
import android.graphics.Point
import android.os.Bundle
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.RelativeLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
@huuphuoc1396
huuphuoc1396 / MainActivity.kt
Last active October 19, 2020 07:45
Remove all callbacks when this activity is destroyed
override fun onDestroy() {
// Remove all callbacks when this activity is destroyed
displayManagerHelper?.unregisterCoverDisplayEnabledCallback(applicationContext.packageName)
displayManagerHelper?.unregisterSmartCoverCallback(smartCoverCallback)
super.onDestroy()
}
@huuphuoc1396
huuphuoc1396 / MainActivity.kt
Last active October 19, 2020 07:46
Construct DisplayManagerHelper
try {
// Try to construct the DisplayMangerHelper.
// If it isn't successful, this device isn't LG dual screens
displayManagerHelper = DisplayManagerHelper(applicationContext)
coverDisplayCallback = MainCoverDisplayCallback()
smartCoverCallback = MainSmartCoverCallback()
// Register the callbacks for covers
displayManagerHelper?.registerCoverDisplayEnabledCallback(
applicationContext.packageName,
@huuphuoc1396
huuphuoc1396 / MainSmartCoverCallback.kt
Last active October 19, 2020 07:47
MainSmartCoverCallback
private inner class MainSmartCoverCallback : DisplayManagerHelper.SmartCoverCallback() {
override fun onTypeChanged(type: Int) {
Log.i(TAG, "SmartCoverCallback type: ${displayManagerHelper?.coverType}")
}
override fun onStateChanged(state: Int) {
displayManagerHelper?.coverState?.let {
Log.i(TAG, "Current SmartCoverCallback state: ${smartCoverStateToString(it)}")
}
when (state) {
@huuphuoc1396
huuphuoc1396 / MainCoverDisplayCallback.kt
Last active October 19, 2020 07:47
MainCoverDisplayCallback
private inner class MainCoverDisplayCallback : DisplayManagerHelper.CoverDisplayCallback() {
override fun onCoverDisplayEnabledChangedCallback(state: Int) {
displayManagerHelper?.coverDisplayState?.let {
Log.i(TAG, "Current DualScreen Callback state: ${coverDisplayStateToString(it)}")
}
if (prevDualScreenState != state) {
when (state) {
DisplayManagerHelper.STATE_UNMOUNT -> {
Log.i(TAG, "Changed DualScreen State to STATE_UNMOUNT")
}
@huuphuoc1396
huuphuoc1396 / MainActivity.kt
Last active October 19, 2020 07:49
Start secondary activity
if (displays.size > 1) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Activity options are used to select the display screen.
val options = ActivityOptions.makeBasic()
// Select the display screen that you want to show the second activity
options.launchDisplayId = displays[1].displayId
// To display on the second screen that your intent must be set flag to make
// single task (combine FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_NEW_TASK)
// or you also set it in the manifest (see more at the manifest file)
startActivity(