Skip to content

Instantly share code, notes, and snippets.

View WrathChaos's full-sized avatar
❤️‍🔥
Working Hard

WrathChaos WrathChaos

❤️‍🔥
Working Hard
View GitHub Profile
@WrathChaos
WrathChaos / gist:d1b5ab433bffaa214cd8045ca257230f
Created February 20, 2018 09:13
Android Kotlin : How to change FAB’s background tint on pre-lollipop?
fun setButtonTint(button: FloatingActionButton, tint: ColorStateList) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
button.backgroundTintList = tint
} else {
ViewCompat.setBackgroundTintList(button, tint)
}
}
@WrathChaos
WrathChaos / gist:e36b315118b9e80fcd7ab45cc8689da8
Created February 2, 2018 09:07
StompClientAndroid onError not Implemented Problem
java.lang.IllegalStateException: Exception thrown on Scheduler.Worker thread. Add `onError` handling.
at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:112)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5624)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
extension UIApplication {
    // Get the app's version
    class func appVersion() -> String {
        return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
    }
    // Get the app's build
    class func appBuild() -> String {
        return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as! String
 }
@WrathChaos
WrathChaos / gist:d938328b6fa296f2b9590c2092733eae
Created January 29, 2018 09:24
Android Kotlin: How to get drawable from Uri?
val inputStream = activity.contentResolver.openInputStream(uri)
val drawable = Drawable.createFromStream(inputStream, uri.toString())
@WrathChaos
WrathChaos / gist:2bdac5c2235914adf968aa49f1083f4d
Last active January 29, 2018 09:02
Android Kotlin: How to clear StringBuilder?
var stringBuilder = StringBuilder(100) // Initialization Example
stringBuilder.setLength(0) // Set length of buffer to 0 for clearing the StringBuilder
stringBuilder.trimToSize() // Trim the underlying buffer
@WrathChaos
WrathChaos / gist:0504320fd967504f02eae878be25e7fb
Created January 17, 2018 09:23
How to extract filename from Uri?
Uri uri = getImageUri(bitmap);
String path = getRealPathFromURI(uri);
String filename = path.substring(path.lastIndexOf("/")+1);
String fileWOExtension;
if (filename.indexOf(".") > 0) {
fileWOExtension = filename.substring(0, filename.lastIndexOf("."));
} else {
fileWOExtension = filename;
}
Log.d(TAG, "Real Path: " + path);
private String getRealPathFromURI(Context context, Uri contentUri) {
   Cursor cursor = null;
   try {
       String[] proj = { MediaStore.Images.Media.DATA };
       cursor = context.getContentResolver().query(contentUri,  proj, null, null, null);
       int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
       cursor.moveToFirst();
       return cursor.getString(column_index);
} catch (Exception e) {
@WrathChaos
WrathChaos / UriToBitmap.md
Last active July 6, 2023 19:29
Android: How to convert Bitmap to Uri?
fun getImageUriFromBitmap(context: Context, bitmap: Bitmap): Uri{
    val bytes = ByteArrayOutputStream()
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes)
    val path = MediaStore.Images.Media.insertImage(context.contentResolver, bitmap, "Title", null)
    return Uri.parse(path.toString())
 }
@WrathChaos
WrathChaos / gist:1ee9a715457fc5a89d79abd567406d6e
Created January 16, 2018 11:22
Android how to change button's border color
// Button Border XML
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#FFFFFF"
android:endColor="#46A4EF"
android:angle="180" />
<corners android:radius="5dp" />
<stroke android:width="5px" android:color="#000000" />
</shape>
@WrathChaos
WrathChaos / gist:d22a4315a6e2b97342d09a3de53ed67e
Created January 6, 2018 16:38
Swift Load Image from URL
func getPhoto(_ url: String){
// If hhtp is missing from the url
//let tempUrl: String = "http:" + url.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
let tempUrl: String = url.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
if let mURL = URL(string: tempUrl) {
//print(mURL)
if let mData = try? Data(contentsOf: mURL) {