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
private static List<File> getFilesInFolder(String path) { | |
List<File> files = new ArrayList<>(); | |
File folder = new File(path); | |
File[] listOfFiles = folder.listFiles(); | |
for (int i = 0; i < listOfFiles.length; i++) { | |
if (listOfFiles[i].isFile()) { | |
files.add(listOfFiles[i]); | |
} else if (listOfFiles[i].isDirectory()) { |
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
List<String> listOfLines = Files.readAllLines(Paths.get(f.getAbsolutePath())); |
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
echo 2 | sudo tee /sys/bus/usb/devices/*/power/autosuspend >/dev/null | |
echo on | sudo tee /sys/bus/usb/devices/*/power/level >/dev/null |
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
package com.jack.sparrow.mylauncher.model; | |
import android.Manifest; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.content.pm.PackageManager; | |
import android.os.Build; | |
import android.support.v4.app.ActivityCompat; | |
import android.support.v4.content.ContextCompat; | |
import android.util.Log; |
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 main(args: Array<String>) { | |
val gson = GsonBuilder().setPrettyPrinting().create() | |
val person = Person("Kolineer", 27, listOf("I am Kotlin Learner", "At Kotlination")) | |
// to json | |
val jsonPerson: String = gson.toJson(person) | |
println(jsonPerson) | |
// from json |
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 timings = TimingLogger("YOUR_TAG", "methodA") | |
// ... do some work A ... | |
timings.addSplit("work A") | |
// ... do some work B ... | |
timings.addSplit("work B") | |
// ... do some work C ... | |
timings.addSplit("work C") | |
timings.dumpToLog() | |
// adb shell setprop log.tag.YOUR_TAG VERBOSE |
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
// perform task for each element in list in many threads with rxjava2 | |
fun getAppsList2(): Single<MutableList<UserApp>>? { | |
val pm = context.packageManager | |
val packages = pm.getInstalledApplications(PackageManager.GET_META_DATA) | |
val tasks: MutableList<ApplicationInfo> = mutableListOf() | |
packages.mapTo(tasks) { it } | |
return Observable.fromIterable(tasks) | |
.map { appInfo -> |
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
private fun saveBitmap(bitmap: Bitmap, | |
name: String) { | |
val s = context.packageName | |
Timber.d("jsp bitmap is saved ") | |
MediaStore.Images.Media.insertImage(context.contentResolver, bitmap, name, s); | |
} |
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
private fun initRvActions() { | |
rvCommands.layoutManager = LinearLayoutManager(this) | |
rvCommands.adapter = AdapterCommands(model) | |
rvCommands.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL)) | |
val swipeHandler = object : SwipeToDeleteCallback(this) { | |
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { | |
val adapter = rvCommands.adapter as AdapterCommands | |
adapter.removeAt(viewHolder.adapterPosition) | |
} |
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
// set on long click listener | |
launcherGrid.setOnItemLongClickListener { parent, view, position, id -> | |
Timber.d("jsp grid item id=$id pos=$position long clicked") | |
launcherAdapter().startDrag(view, position) | |
false | |
} | |
data class DragData(val view: View, | |
val position: Int) |
OlderNewer