Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Marcos Davalos mdavalos1993

🏠
Working from home
View GitHub Profile
@mdavalos1993
mdavalos1993 / database.rules.json
Created Sep 28, 2020 — forked from codediodeio/database.rules.json
Common Database Rules for Firebase
View database.rules.json
// No Security
{
"rules": {
".read": true,
".write": true
}
}
View StoreBitmap.kt
private fun storeImage(bitmap: Bitmap, fileName: String){
val wrapper = ContextWrapper(context)
var file = wrapper.getDir("images", Context.MODE_PRIVATE)
file = File(file, "${fileName}.jpg")
try{
val stream: OutputStream = FileOutputStream(file)
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream)
stream.flush()
stream.close()
imageUri = Uri.parse(file.absolutePath)
View OnGlideResourceReady.kt
Glide.with(this)
.load("imageUrl")
.into(object : CustomTarget<Drawable>(850, 850) {
override fun onLoadCleared(placeholder: Drawable?) {
// called when imageView is cleared. If you are referencing the bitmap
// somewhere else too other than this imageView clear it here
}
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
img_view.setImageDrawable(resource)
//do any aditional action
View ShareImageToFacebook.kt
// import facebook sdk
// import facebook sharing sdk
private fun onShareFacebook(bitmap: Bitmap) {
val photoToShare = SharePhoto.Builder().setBitmap(bitmap).build()
val contentToShare = SharePhotoContent.Builder().addPhoto(photoToShare)
.setShareHashtag(ShareHashtag.Builder().setHashtag("#MarcosDavalos").build())
.build()
@mdavalos1993
mdavalos1993 / CopyToClipboard.kt
Created Jun 10, 2020
Copy text to Clipboard in Android - Kotlin
View CopyToClipboard.kt
private fun copyToClipboard(text: String){
val clipboard = requireActivity().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText(UUID.randomUUID().toString(), text)
clipboard.setPrimaryClip(clip)
}
@mdavalos1993
mdavalos1993 / ViewToBitmap.kt
Last active Jun 10, 2020
Convert any view to bitmap in Android Kotlin
View ViewToBitmap.kt
package me.marcosdavalos.util
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import android.view.View
val View.toBitmap: Bitmap get(){
val bitmap = Bitmap.createBitmap(this.width, this.height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
View android_colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#000000</color>
<color name="white">#FFFFFF</color>
<color name="red_50">#FFEBEE</color>
<color name="red_100">#FFCDD2</color>
<color name="red_200">#EF9A9A</color>
<color name="red_300">#E57373</color>
View item_read_chapter.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="@+id/card_view"
@mdavalos1993
mdavalos1993 / appbar_demo.dart
Created Oct 25, 2018 — forked from slightfoot/appbar_demo.dart
Demonstrate how to change the AppBar from within a PageView.
View appbar_demo.dart
import 'package:flutter/material.dart';
void main() => runApp(TestApp());
class TestApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: Colors.green[900],
View android_material_design_colours.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- google's material design colours from
http://www.google.com/design/spec/style/color.html#color-ui-color-palette -->
<!--reds-->
<color name="md_red_50">#FFEBEE</color>
<color name="md_red_100">#FFCDD2</color>
<color name="md_red_200">#EF9A9A</color>