Skip to content

Instantly share code, notes, and snippets.

View huuphuoc1396's full-sized avatar
🤪

Phuoc Bui huuphuoc1396

🤪
View GitHub Profile
@huuphuoc1396
huuphuoc1396 / git-change-author-commit.sh
Last active July 17, 2018 15:17
Change the author (name or email) of a commit
git commit --amend --author "your_name <[email protected]>" --no-edit && git rebase --continue
git push origin master --force
@huuphuoc1396
huuphuoc1396 / ImageLoaderWithCertificate.java
Last active July 17, 2018 15:34
Trust anchor for certification path not found when loading image from URL
package com.certpathvalidator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
@huuphuoc1396
huuphuoc1396 / permission-denied-github-ssh.sh
Last active October 19, 2020 07:52
Github - Permission denied (publickey) - Using ssh
ssh-add ~/.ssh/your_id_rsa
ssh-add -l
ssh -Tv [email protected]
@huuphuoc1396
huuphuoc1396 / Manifest.xml
Last active October 19, 2020 07:51
Secondary activity in the manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.multiplescreens">
<application
<!-- See about the taskAffinity attribute at http://bit.ly/34RKvzC -->
<activity
android:name=".SecondActivity"
android:launchMode="singleTask"
android:taskAffinity="cover.container" />
</application>
</manifest>
@huuphuoc1396
huuphuoc1396 / MainActivity.kt
Last active October 19, 2020 07:50
Get DisplayManager
val displayManager = getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
@huuphuoc1396
huuphuoc1396 / MainActivity.kt.kt
Last active October 19, 2020 07:50
Get all displays
val displays = displayManager.displays
@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(
@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 / 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 / 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,