This file contains 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 storeImage(image: Bitmap): Uri? { | |
var pictureFile: File = File(Environment.getExternalStorageDirectory().path + "/Folder") | |
val timeStamp = SimpleDateFormat("yyyy-MM-dd_HHmm").format(Date()) | |
val name = "$timeStamp.jpg" | |
pictureFile = File(pictureFile.path + File.separator + name) | |
try { | |
val fos = FileOutputStream(pictureFile) | |
image.compress(Bitmap.CompressFormat.JPEG, 90, fos) | |
fos.close() |
This file contains 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
public class ExternalStorage { | |
public static final String SD_CARD = "sdCard"; | |
public static final String EXTERNAL_SD_CARD = "externalSdCard"; | |
/** | |
* @return True if the external storage is available. False otherwise. | |
*/ | |
public static boolean isAvailable() { | |
String state = Environment.getExternalStorageState(); |
This file contains 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 factory = LayoutInflater.from(this) | |
val deleteDialogView = factory.inflate(R.layout.mylayout, null) | |
val deleteDialog = AlertDialog.Builder(this).create() | |
deleteDialog.setView(deleteDialogView) | |
// anything you wish to do on views | |
deleteDialogView.findViewById(R.id.yes).setOnClickListener(object:OnClickListener() { | |
fun onClick(v:View) { | |
//your business logic | |
deleteDialog.dismiss() | |
} |
This file contains 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
Gson().fromJson("", Array<ClassName>::class.java)) |
This file contains 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
// credits - https://github.com/sinonjs/sinon/issues/1358#issuecomment-288566305 | |
// first install babel-plugin-rewire | |
// then add plugin to .babelrc as | |
// "plugins" : ["rewire"] | |
import token, {clientToken} from '../../../../app/util/token' | |
import * as esat from 'esat' | |
import * as proxyquire from 'proxyquire' |
This file contains 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
// credits - https://www.codexpedia.com/node-js/node-js-getting-files-from-a-directory-including-sub-directories/ | |
var fs = require('fs'); | |
var path = require('path'); | |
// Return a list of files of the specified fileTypes in the provided dir, | |
// with the file path relative to the given dir | |
// dir: path of the directory you want to search the files for | |
// fileTypes: array of file types you are search files, ex: ['.txt', '.jpg'] |
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<set xmlns:android="http://schemas.android.com/apk/res/android" | |
android:shareInterpolator="false"> | |
<translate | |
android:fromXDelta="-100%" android:toXDelta="0%" | |
android:fromYDelta="0%" android:toYDelta="0%" | |
android:duration="200"/> | |
</set> |
This file contains 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
// this will be a descending sort | |
fun sortLabels(labels: List<FirebaseVisionLabel>): List<FirebaseVisionLabel> { | |
Collections.sort(labels) { o1, o2 -> | |
o2.confidence.compareTo(o1.confidence) | |
} | |
return labels | |
} |
This file contains 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
// creating a layout which wrap image view based on text width | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="fill_parent" | |
android:layout_height="match_parent" > | |
<ImageView | |
android:id="@+id/img" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_above="@+id/txt" |
This file contains 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 capWord(string: String): String { | |
val result = StringBuilder(string.length) | |
val words = string.split("\\ ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() | |
for (i in words.indices) { | |
result.append(Character.toUpperCase(words[i][0])).append(words[i].substring(1)).append(" ") | |
} | |
return result.toString() | |
} |