Skip to content

Instantly share code, notes, and snippets.

@rasheedsulayman
rasheedsulayman / ResourceExtension.kt
Created December 19, 2019 14:12
A set of common extensions methods. Expecially for getting resources and setting the resource values to various View widgets
@SuppressLint("InlinedApi")
internal fun Context.getThemeBackgroundColor(): Int {
val attributes = theme.obtainStyledAttributes(intArrayOf(android.R.attr.colorBackgroundFloating))
try {
return attributes.getColor(0, Color.WHITE)
} finally {
attributes.recycle()
}
}
@rasheedsulayman
rasheedsulayman / Oauth1SigningInterceptor.kt
Created October 25, 2019 12:32 — forked from polson/Oauth1SigningInterceptor.kt
An OkHttp interceptor written in Kotlin that does OAuth 1.0a signing
/*
* Copyright (C) 2015 Jake Wharton
* Modified work Copyright 2019 Phil Olson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
<?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>
//https://stackoverflow.com/a/9989900/6484427
private String getRealPathFromURI(Uri contentURI , Context context) {
String result;
Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null);
if (cursor == null) { // Source is Dropbox or other similar local file path
result = contentURI.getPath();
} else {
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
result = cursor.getString(idx);