Skip to content

Instantly share code, notes, and snippets.

@lvsecoto
lvsecoto / ConcatAdapter.java
Last active October 6, 2020 15:40
The is recyclerview adapter is use for concat with two adapter, by decorating
package com.yjy.recyclerviewutils.adapter;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.ViewGroup;
public class ConcatAdapter extends RecyclerView.Adapter {
private RecyclerView.Adapter mFirstAdapter;
@lvsecoto
lvsecoto / FragmentUtil.java
Created September 29, 2018 07:13
a way to create a singleton dialog fragment
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
public class FragmentUtils {
private FragmentUtils() {}
/**
* Use this method to prevent from creating dialog fragment more than one.
@lvsecoto
lvsecoto / get_selected_files_dirs_path.scpt
Created November 15, 2018 07:35 — forked from Teraflopst/get_selected_files_dirs_path.scpt
AppleScript:获取选中文件(夹)的目录路径
-- 脚本介绍
-- 功能:获取所选文件、文件夹的目录路径,支持多选
-- 如果仅仅想获取文件的目录路径,可以调用 isDirectory() 过滤掉文件夹的路径
tell application "Finder" to set selectedItems to selection as alias list
-- 没选择的话直接退出脚本
if selectedItems is {} then return
-- 获得所选文件/文件夹的父目录。
set parentPath to do shell script "dirname " & quoted form of POSIX path of (item 1 of selectedItems)
-- 用于拼接多个路径
@lvsecoto
lvsecoto / SharedPreferenceDao
Last active February 12, 2019 08:19
把SharedPreference做成LiveData,并提供类似数据库一样增删查改的功能
import android.annotation.SuppressLint;
import android.arch.lifecycle.LiveData;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
@lvsecoto
lvsecoto / TimerLiveData
Created December 26, 2018 09:03
每隔一段时间生成LiveData
import android.annotation.SuppressLint;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MediatorLiveData;
import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
@lvsecoto
lvsecoto / ConcatLiveData
Created February 12, 2019 02:09
连接两个LiveData,一开始订阅第一个LiveData,在一定条件下,改为订阅第二个LiveData
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MediatorLiveData;
import android.arch.lifecycle.Observer;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
/**
*
* 每次InputSource更新后。
* <ol>
@lvsecoto
lvsecoto / ActionLiveData
Created February 12, 2019 02:11
用于接收View的一个参数,就更新ViewModel的LiveData的情况
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.Transformations;
/**
* 每当输入一个参数{@link #input(Object)},就回调{@link OnGetLiveData},生成一个LiveData
*/
public class ActionLiveData<InputType, ResultType> {
private MutableLiveData<InputType> mInput = new EventMutableLiveData<>();
private static LifecycleOwner mockLifecycleOwner() {
LifecycleOwner owner = mock(LifecycleOwner.class);
LifecycleRegistry lifecycle = new LifecycleRegistry(owner);
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME);
when(owner.getLifecycle()).thenReturn(lifecycle);
return owner;
}
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.View;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class TKCalculateUtils {
public static long hexCharAsNumber(char c) {
if (c >= 'a') {
return c - 87;
} else {