Skip to content

Instantly share code, notes, and snippets.

// Empty checks
//-----------------------------------------------------------------------
/**
* <p>Checks if a CharSequence is empty ("") or null.</p>
*
* <pre>
* StringUtils.isEmpty(null) = true
* StringUtils.isEmpty("") = true
* StringUtils.isEmpty(" ") = false
* StringUtils.isEmpty("bob") = false
@qishi604
qishi604 / IntentUtil
Created December 12, 2017 09:11
Android Intent
// capture photo
static final int REQUEST_IMAGE_CAPTURE = 1;
static final Uri mLocationForPhotos;
public void capturePhoto(String targetFilename) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.withAppendedPath(mLocationForPhotos, targetFilename);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
@qishi604
qishi604 / Kotlin Handler
Last active June 13, 2018 03:42
一般情况下,如果直接在Activity 使用Handler,会导致内存泄漏。正确的用法是让Handler 持有Activity的弱引用
class MyActivity: Activity() {
companion object {
private const val MSG_SEARCH = 1
}
val handler = SearchHandler(this)
override fun oncreate(bundle Bundle?) {
v.setOnclickListener{
@qishi604
qishi604 / Activitys
Created June 13, 2018 07:09
Activity 栈
object Activitys : Application.ActivityLifecycleCallbacks {
private val list: LinkedList<SoftReference<Activity>> = LinkedList()
fun first(): Activity? {
if (list.size > 0) {
list.forEach{
if (null != it.get()) {
return it.get()
@qishi604
qishi604 / Clickable EditText style
Created June 14, 2018 14:32
How to make a EditText disable but clickable?
<style name="ClickDisableEditText">
<item name="android:cursorVisible">false</item>
<item name="android:clickable">true</item>
<item name="android:focusable">false</item>
</style>
@qishi604
qishi604 / retrofit upload image
Created June 25, 2018 09:47
Retrofit2 upload image file
private fun uploadPicture(path: String) {
showProgress(Strings.loading)
val reqFile = RequestBody.create(MediaType.parse("image/*"), File(path))
val params = MultipartBody.Part.createFormData("imageFile", path, reqFile)
val call = apiService.upload(params)
val callback = object : SimpleCallback<StringResponse>() {
override fun onFinish() {
@qishi604
qishi604 / gist:75c21215b746a8c7423a5523264fca40
Created September 19, 2018 02:55
Android Gift Image View
class GiftImageView : ImageView {
var gifDrawable: GifDrawable? = null
set(value) {
field = value
setImageDrawable(gifDrawable)
}
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
@qishi604
qishi604 / latency.markdown
Created February 13, 2019 16:37 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@qishi604
qishi604 / Toolbar.java
Last active March 2, 2019 13:27
Android Toolbar
package com.lanayru.views.widget;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.v7.widget.TooltipCompat;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;