Skip to content

Instantly share code, notes, and snippets.

View qichuan's full-sized avatar

Qichuan (Sean) ZHANG qichuan

View GitHub Profile
@qichuan
qichuan / location_request_permission_background.kt
Created July 14, 2021 14:10
android_location_request_background
// Request background permission
ActivityCompat.requestPermissions(
this@MainActivity,
arrayOf(Manifest.permission.ACCESS_BACKGROUND_LOCATION),
REQUEST_BACKGROUND_ONLY_PERMISSIONS_REQUEST_CODE
)
@qichuan
qichuan / AndroidManifest.xml
Created July 14, 2021 13:50
android_location_manifest_android_10
<!-- Specify the permissions that you are using -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Specify the background location permission. -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<!-- Declare a foreground service, if applicable -->
<service
android:name="MyForgroundService"
android:foregroundServiceType="location">
@qichuan
qichuan / location_request_permission_foreground.kt
Last active July 14, 2021 14:11
android_location_request_foreground
// Request permission
ActivityCompat.requestPermissions(
this@MainActivity,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
REQUEST_FOREGROUND_ONLY_PERMISSIONS_REQUEST_CODE
)
@qichuan
qichuan / AndroidManifest.xml
Created July 14, 2021 13:06
android_location_manifest
<!-- Specify the permissions that you are using -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
class LessNumerousGCRecyclerViewAdapter(private val context: Context,
private val numbers: List<Int>): RecyclerView.Adapter<NumerousGCViewHolder>() {
val bitBitmap = BitmapFactory.decodeResource(context.resources, R.drawable.big_bitmap)
val smallBitmap = BitmapFactory.decodeResource(context.resources, R.drawable.small_bitmap)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NumerousGCViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_numerous_gc, parent, false)
return NumerousGCViewHolder(view)
class NumerousGCActivity: AppCompatActivity() {
val NO_OF_VIEWS = 100000
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_numerous_gc)
btn_start.setOnClickListener {
setupRecyclerView()
/***
* In order to stress the memory usage,
* this activity creates 100000 rows of TextView when user clicks on the start button
*/
class HighMemoryUsageActivity : AppCompatActivity() {
val NO_OF_TEXTVIEWS_ADDED = 100000
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Read the pinned certificate from local (i.e., assets folder)
val inputStream = context.assets.open("google.crt")
val pinnedCertificate = CertificateFactory.getInstance("X.509")
.generateCertificate(inputStream)
// Create a request to www.google.com
val url = URL("https://www.google.com")
val httpsUrlConnection = url.openConnection() as HttpsURLConnection
// Establish the connection
override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
...
drawGlasses(canvas, face)
drawCigarette(canvas, face)
}
/**
* Draw cigarette at the left mouth
*/
private fun drawCigarette(canvas: Canvas, face: FirebaseVisionFace) {
val rightMouth = face.getLandmark(FirebaseVisionFaceLandmark.RIGHT_MOUTH)
val leftMouth = face.getLandmark(FirebaseVisionFaceLandmark.LEFT_MOUTH)
if (leftMouth != null && rightMouth != null) {
val mouthLength = ((leftMouth.position.x - rightMouth.position.x) * widthScaleFactor).toInt()
val cigaretteRect = Rect(