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
private fun drawGlasses(canvas: Canvas, face: FirebaseVisionFace) { | |
val leftEye = face.getLandmark(FirebaseVisionFaceLandmark.LEFT_EYE) | |
val rightEye = face.getLandmark(FirebaseVisionFaceLandmark.RIGHT_EYE) | |
if (leftEye != null && rightEye != null) { | |
val eyeDistance = leftEye.position.x - rightEye.position.x | |
val delta = (widthScaleFactor * eyeDistance / 2).toInt() | |
val glassesRect = Rect( | |
translateX(leftEye.position.x).toInt() - delta, | |
translateY(leftEye.position.y).toInt() - delta, |
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
/** | |
* Adjusts the x coordinate from the preview's coordinate system to the view coordinate system. | |
*/ | |
private fun translateX(x: Float): Float { | |
return width - scaleX(x) | |
} | |
/** | |
* Adjusts the y coordinate from the preview's coordinate system to the view coordinate system. | |
*/ |
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
// Perform face detection | |
detector.detectInImage(firebaseVisionImage).addOnSuccessListener { faceList -> | |
if (faceList.size > 0) { | |
// We just need the first face | |
val face = faceList[0] | |
// Draw the bitmaps on the detected faces | |
} | |
} |
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( |
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
/*** | |
* 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
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
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
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
<!-- 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"/> |