This file contains hidden or 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
| fun printKeyHash(context: Activity): String? { | |
| val packageInfo: PackageInfo | |
| var key: String? = null | |
| try { | |
| //getting application package name, as defined in manifest | |
| val packageName = context.applicationContext.packageName | |
| //Retriving package info | |
| packageInfo = context.packageManager.getPackageInfo(packageName, | |
| PackageManager.GET_SIGNATURES) |
This file contains hidden or 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
| val options = arrayOf<CharSequence>("Share", "Copy URL","Cancel") | |
| val builder = AlertDialog.Builder(this) | |
| builder.setTitle("") | |
| builder.setCancelable(false) | |
| builder.setItems(options) { dialog: DialogInterface, item: Int -> | |
| if (options[item].equals("Share")) { | |
| val intent = Intent(Intent.ACTION_SEND) | |
| intent.type = "text/plain" | |
| intent.putExtra(Intent.EXTRA_TEXT, YOUR_LINK) | |
| startActivity(Intent.createChooser(intent, "Share")) |
This file contains hidden or 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
| /* | |
| * Microphone Item click to record | |
| */ | |
| yourmicrophoneuicon.setOnClickListener { | |
| // Get the Intent action | |
| val sttIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH) | |
| // Language model defines the purpose, there are special models for other use cases, like search. | |
| sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM) | |
| // Adding an extra language, you can use any language from the Locale class. | |
| sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()) |
This file contains hidden or 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
| fun readHtmlFile(section: String, fileName: String, context: Context): String? { | |
| val returnString = StringBuilder() | |
| var fIn: InputStream? = null | |
| var isr: InputStreamReader? = null | |
| var input: BufferedReader? = null | |
| try { | |
| fIn = context.resources.assets | |
| .open(section + fileName) | |
| isr = InputStreamReader(fIn) | |
| input = BufferedReader(isr) |
This file contains hidden or 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
| fun saveImageToGallery(context: Context, fileName: String, photoView: PhotoView) { | |
| val bitmapDrawable = photoView.drawable as BitmapDrawable | |
| val bitmap = bitmapDrawable.bitmap | |
| val filename = String.format("%s.png", fileName) | |
| if (Build.VERSION.SDK_INT >= 29) { | |
| val values = contentValues(filename) | |
| values.put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_PICTURES + "/" + "YOUR_FOLDER_NAME") | |
| values.put(MediaStore.Images.Media.IS_PENDING, true) | |
| // RELATIVE_PATH and IS_PENDING are introduced in API 29. |
This file contains hidden or 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
| val textView = findViewById<TextView>(R.id.textview) | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | |
| textView.text = Html.fromHtml(readTxt(), Html.FROM_HTML_MODE_LEGACY) | |
| } else { | |
| textView.text = HtmlCompat.fromHtml(readTxt()!!, HtmlCompat.FROM_HTML_MODE_LEGACY) | |
| } | |
| } |
This file contains hidden or 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 MyFireBaseMessagingService : FirebaseMessagingService() { | |
| var mtitle: String? = null | |
| var mmessage: String? = null | |
| override fun onMessageReceived(remoteMessage: RemoteMessage) { | |
| super.onMessageReceived(remoteMessage) | |
| mtitle = remoteMessage.data["title"] | |
| mmessage = remoteMessage.data["message"] | |
| showNotificationMessage(mtitle, mmessage) | |
| } |
This file contains hidden or 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
| object RandomIntGenerator { | |
| fun generate(): Int { | |
| val rnd = Random() | |
| val number = rnd.nextInt(999999) | |
| return number | |
| } | |
| } |
This file contains hidden or 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
| object DistanceCalculations { | |
| fun CalculationByDistance(StartP: LatLng, EndP: LatLng): Double { | |
| val Radius = 6371 // radius of earth in Km | |
| val lat1 = StartP.latitude | |
| val lat2 = EndP.latitude | |
| val lon1 = StartP.longitude | |
| val lon2 = EndP.longitude | |
| val dLat = Math.toRadians(lat2 - lat1) | |
| val dLon = Math.toRadians(lon2 - lon1) |
This file contains hidden or 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
| object DateTimeUtils { | |
| fun convertDateToLong(date : String) : Long | |
| { | |
| val dateFormat = SimpleDateFormat("yyyy/MM/dd") | |
| val date = dateFormat.parse(date) | |
| val dateInLong = date.time | |
| return dateInLong | |
| } |