Skip to content

Instantly share code, notes, and snippets.

View nesterchung's full-sized avatar

Nester Chung nesterchung

View GitHub Profile
@nesterchung
nesterchung / seekbar.kt
Created April 25, 2018 10:53
seekbar demo for @張順閔
class Presenter {
fun onSeekBarSelect(data: Any) {
//brabra
}
}
val list = listOf<Any>()
val presenter = Presenter()
val seekBar = SeekBar(null).apply {
setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
@nesterchung
nesterchung / scan.xml
Created April 11, 2018 10:08
QRCode Scanner Background Drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="260dp"
android:height="260dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/transparent" />
</shape>
</item>
package com.nesterchung.chart
import android.content.Context
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.text.format.DateUtils
import android.util.Log
import android.view.WindowManager
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.components.AxisBase
/**
* Class connecting the Realm lifecycle to that of LiveData objects.
* Realm will remain open for as long as any LiveData objects are being observed.
*/
abstract class LiveRealmData<T: RealmModel>(val config: RealmConfiguration) : LiveData<RealmResults<T>>() {
private val listener = RealmChangeListener<RealmResults<T>> { results -> value = results }
private lateinit var realm: Realm
private var results: RealmResults<T>? = null
@nesterchung
nesterchung / gist:0ae102c5ef19fb75fa7967c56dcccb46
Created July 12, 2017 05:01
CountDownTimer with progressBar
CountDownTimer countDownTimer = new CountDownTimer(TIME_MILLIS, 100) {
@Override
public void onTick(long millisUntilFinished) {
double i = (1 - millisUntilFinished / (double) TIME_MILLIS) * 100;
progressBar.setProgress((int) i);
}
@Override
public void onFinish() {
progressBar.setProgress(100);
@nesterchung
nesterchung / SearchViewFormatter.java
Created June 20, 2017 10:45 — forked from ademar111190/SearchViewFormatter.java
An easy way to format SearchView's
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ImageSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SearchView;
import android.widget.TextView;
@nesterchung
nesterchung / NoAttachActivity.java
Last active June 1, 2017 08:58
Reproduce attached to window manager
package com.example.nester.crachreproduce;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
public class NoAttachActivity extends AppCompatActivity {
private ProgressDialog progressDialog;
@nesterchung
nesterchung / java
Created May 12, 2017 16:52
java.text.DecimalFormat sample
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.math.RoundingMode;
DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.setDecimalSeparatorAlwaysShown(false)
decimalFormat.setMaximumFractionDigits(6)
decimalFormat.setRoundingMode(RoundingMode.HALF_UP)
@nesterchung
nesterchung / DpToPxAndPxToDp
Created October 14, 2016 04:36 — forked from laaptu/DpToPxAndPxToDp
Android convert dp to px and vice versa
public static float convertPixelsToDp(float px){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float dp = px / (metrics.densityDpi / 160f);
return Math.round(dp);
}
public static float convertDpToPixel(float dp){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float px = dp * (metrics.densityDpi / 160f);
return Math.round(px);
@nesterchung
nesterchung / Solution.java
Last active April 25, 2016 09:56
roman to int
public class Solution {
private static final String seq = "IVXLCDM";
public int romanToInt(String s) {
if (null == s || s.length() == 0) {
return 0;
}