This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Request background permission | |
ActivityCompat.requestPermissions( | |
this@MainActivity, | |
arrayOf(Manifest.permission.ACCESS_BACKGROUND_LOCATION), | |
REQUEST_BACKGROUND_ONLY_PERMISSIONS_REQUEST_CODE | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Request permission | |
ActivityCompat.requestPermissions( | |
this@MainActivity, | |
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), | |
REQUEST_FOREGROUND_ONLY_PERMISSIONS_REQUEST_CODE | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onDraw(canvas: Canvas?) { | |
super.onDraw(canvas) | |
... | |
drawGlasses(canvas, face) | |
drawCigarette(canvas, face) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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( |
NewerOlder