Skip to content

Instantly share code, notes, and snippets.

View seventhmoon's full-sized avatar

Fung Lam seventhmoon

View GitHub Profile
@seventhmoon
seventhmoon / SensorActivity
Created March 20, 2017 04:01
Sample for Reading Sensor Value on Android
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorEventListener2;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
@seventhmoon
seventhmoon / Util.java
Created February 20, 2018 00:58
Helper Utility for Android
import android.content.Context;
import android.graphics.Point;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;
/**
* A collection of utility methods, all static.
*/
public class Utils {
@seventhmoon
seventhmoon / Util.java
Created February 20, 2018 00:58
Helper Utility for Android
import android.content.Context;
import android.graphics.Point;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;
/**
* A collection of utility methods, all static.
*/
public class Utils {
//curl 'https://hkt-mobile-api.nowtv.now.com/09/1/getLiveURL' -H 'Accept: */*' -H 'Referer: https://news.now.com/home/live331a' -H 'Origin: https://news.now.com' -H 'User-Agent: Mozilla/5.0 (X11; CrOS x86_64 12105.75.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.102 Safari/537.36' -H 'Content-Type: application/json' --data-binary '{"channelno":"331","mode":"prod","audioCode":"","format":"HLS","callerReferenceNo":"20140702122500"}' --compressed
{"asset":{"hls":{"fix":{"2":["http://ewcdnsite06.nowe.com/session/09-66f7223b8ba659a79719d70a1aeee/Content/HLS/LIVE/Channel(HLS_CH331)/Stream(02)/index.m3u8?token=0425484f980b53d36d0293acc69c55b2_1562399934"],"1":["http://ewcdnsite06.nowe.com/session/09-66f7223b8ba659a79719d70a1aeee/Content/HLS/LIVE/Channel(HLS_CH331)/Stream(01)/index.m3u8?token=d3db0393451ab9b83b4d738376c7e979_1562399934"]},"adaptive":["http://ewcdnsite06.nowe.com/session/09-66f7223b8ba659a79719d70a1aeee/Content/HLS/LIVE/Channel(HLS_CH331)/index.m3u8?token=37c2269e3eff183d98c4c3084ac72060_
@seventhmoon
seventhmoon / Streams.kt
Created May 23, 2020 13:19
Kotlin in Kotlin
val supportedHardwareAcceleratedDecodeType = MediaCodecList(MediaCodecList.REGULAR_CODECS).codecInfos
.filter { !it.isEncoder && it.isHardwareAccelerated }
.map { it.supportedTypes.toList() }
.flatten()
.toSortedSet()
@seventhmoon
seventhmoon / AndroidViewModelKtx.kt
Created July 18, 2020 15:16
AndroidViewModel KTX
protected open fun AndroidViewModel.getString(@StringRes resId: Int) =
getApplication<Application>().resources.getString(resId)
protected open fun AndroidViewModel.getStringArray(@ArrayRes resId: Int): Array<String> =
getApplication<Application>().resources.getStringArray(resId)
@seventhmoon
seventhmoon / TvDeviceTypes.kt
Last active March 31, 2023 14:22
TvDeviceTypes
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import androidx.annotation.IntDef
//Make sure you have the following declared in Manifest when running on Android 11+
//<queries>
//<package android:name="com.google.android.tvlauncher" />
//<package android:name="com.google.android.leanbacklauncher" />
@seventhmoon
seventhmoon / HkidValidator.kt
Last active April 12, 2021 00:53
HkidValidator
import java.lang.IllegalArgumentException
class HkidValidator {
private val acceptedChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "
private val hkidRegex = Regex("[A-Z]{1,2}\\d{6}")
@ExperimentalStdlibApi
fun calcCheckDigit(input: String): Char {
return if (input.matches(hkidRegex)) {
val id = if (input.length == 7) " $input" else input
@seventhmoon
seventhmoon / logcat.txt
Created May 1, 2021 11:48
Logcat of hk.gov.ogcio.covidresultqrscanner.full
2021-05-01 19:45:38.015 20205-20205/hk.gov.ogcio.covidresultqrscanner.full D/CODE_SCANNER: QR Code detected: HKSARG|VAC|3|1|TC21221-188-4|****456(8)|CHUK, K** K***|24-01-2021|CoronaVac COVID-19 Vaccine (Vero Cell), Inactivated|2019冠狀病毒病疫苗 (克爾來福)|||21-02-2021|CoronaVac COVID-19 Vaccine (Vero Cell), Inactivated|2019冠狀病毒病疫苗 (克爾來福)|||21-02-2021 02:42|MEYCIQDE5j+yB4HK0ERAtSyKe2Svj+2NQsxBfD1/xTzcjECFsQIhAL+aWsEzqbOh2ZWROfQ4IT7iYxmmntQkpemz/K7pNvMd
2021-05-01 19:45:38.015 20205-20205/hk.gov.ogcio.covidresultqrscanner.full D/CODE_SCANNER: digitalSignature: MEYCIQDE5j+yB4HK0ERAtSyKe2Svj+2NQsxBfD1/xTzcjECFsQIhAL+aWsEzqbOh2ZWROfQ4IT7iYxmmntQkpemz/K7pNvMd
2021-05-01 19:45:38.016 20205-20205/hk.gov.ogcio.covidresultqrscanner.full D/CODE_SCANNER: stringToBeSigned: HKSARG|VAC|3|1|TC21221-188-4|****456(8)|CHUK, K** K***|24-01-2021|CoronaVac COVID-19 Vaccine (Vero Cell), Inactivated|2019冠狀病毒病疫苗 (克爾來福)|||21-02-2021|CoronaVac COVID-19 Vaccine (Vero Cell), Inactivated|2019冠狀病毒病疫苗 (克爾來福)|||21-02-2021 02:42|
2021-05-01 19:45:38.01
@seventhmoon
seventhmoon / BuildIdHelper.kt
Created January 17, 2024 15:20
BuildIdHelper to get the QPR version information
import android.os.Build
//Ref: https://source.android.com/docs/setup/reference/build-numbers#build-ids-defined
object BuildHelper {
fun getQprNumber(): Int {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return 0
else {
when (Build.ID.substring(1, 2)) {