Skip to content

Instantly share code, notes, and snippets.

View rahulkhatri19's full-sized avatar
🎯
Focusing

Rahul Khatri rahulkhatri19

🎯
Focusing
View GitHub Profile
@rahulkhatri19
rahulkhatri19 / Android_Concept
Last active February 25, 2020 07:13
Android Basic, Interview Questions with Answers, Basic concept.
Helpful Links
------
- [Google Doc - Room Db Query](https://developer.android.com/reference/android/arch/persistence/room/Query)
- [Google Doc - Accessing data from Dao](https://developer.android.com/training/data-storage/room/accessing-data)
- [Android Room: Handling Relations Using LiveData](https://proandroiddev.com/android-room-handling-relations-using-livedata-2d892e40bd53)
- [SQLite on Android Made Simple: Room Persistence Library with a Touch of RxJava](https://android.jlelse.eu/sqlite-on-android-made-simple-room-persistence-library-with-a-touch-of-rxjava-55e8dc5301cf)
// package com.example.
import android.graphics.drawable.Drawable
import android.graphics.drawable.PictureDrawable
import android.widget.ImageView
import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.ImageViewTarget
Kotlin Basic:
1. Null safe operator (?) :
println(name?.toUpperCase()) // if upper case then print name in uppercase else print null.
in java :
if (name.toUppercase != null){
print(name.toUpperCase())
} else print("null")
2. Not null assert(!!):
// Call printHashKey(this) method in onCreate method.
fun printHashKey(context: Context) {
try {
val info =
context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES)
for (signature in info.signatures) {
val md = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
val hashKey = String(Base64.encode(md.digest(), 0))
Release hash key:
keytool -exportcert -alias alias_name -keystore keystore_path | openssl sha1 -binary | openssl base64
playstore key hash : echo SHA_1_key | xxd -r -p | openssl base64 // here playstore Sha_1_key, get by playstore console.
// Customizing title of Alertdilaog.
val builder = AlertDialog.Builder(this, R.style.CustomAlertDialog)
val tvTitle= TextView(this)
tvTitle.text = "Title of Alert Dialog!"
tvTitle.textSize = this.resources.getDimension(R.dimen.snack_bar_text_size)
builder.setCustomTitle(tvTitle)
// Cuatom default button
<style name="CustomAlertDialog" parent="@android:style/Theme.Dialog"> // for white : Theme.AppCompat.Light.Dialog.Alert
<item name="android:textSize">@dimen/snack_bar_text_size</item>
@rahulkhatri19
rahulkhatri19 / VowelsCountRecursive.kt
Created February 18, 2020 04:44
For counting vowel in a string by Recursive method.
var count = 0
fun main(args: Array<String>) {
println("Enter string to Count Vowels: ")
val inputSt: String? = readLine()!!
// val inputSt: String? = "Hi this to check"
print(checkforVowel(inputSt, inputSt?.length))
}
fun checkforVowel(inputSt: String?, length: Int?): Int {
if (length == 1){
@rahulkhatri19
rahulkhatri19 / Android_Concept
Last active February 7, 2020 12:07
Android Concept: interview preparation questions.
Dagger Dependency Injection
1. Setting Up Dagger:
app: build.gradle
apply plugin: 'kotlin-kapt'
ext {
dagger_version = '2.17'
auto_value_version = '1.6.2'
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(home: SwitchApp()));
}
class SwitchApp extends StatefulWidget {
@override
_switch createState() => new _switch();
}
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(home: SliderApp()));
}
class SliderApp extends StatefulWidget {
@override
_slider createState() => new _slider();
}