Skip to content

Instantly share code, notes, and snippets.

View brucetoo's full-sized avatar
🎧
Visualization

Bruce too brucetoo

🎧
Visualization
View GitHub Profile
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
@nickbutcher
nickbutcher / MainActivity.java
Last active August 20, 2021 16:15
A quick sample of the new physics-based animation library added in Support Library 25.3.0 docs: https://developer.android.com/reference/android/support/animation/package-summary.html output: https://twitter.com/crafty/status/842055117323026432
/*
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@oasisfeng
oasisfeng / AidlService.java
Created May 26, 2016 13:46
Service framework for friendly and efficient AIDL service binding in Android app.
package com.oasisfeng.android.service;
import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.IInterface;
import android.support.annotation.Nullable;
import android.util.Log;
@nickbutcher
nickbutcher / 1_drawable_ic_hash_io16.xml
Last active June 16, 2020 19:28
Animated Stroke. The google I/O website this year (https://google.com/io) has some funky animated lettering. I especially liked the animated stroke around the letters and wondered how you might implement that on Android. Turns out that AnimatedVectorDrawable makes this very easy! Here's how it looks: https://twitter.com/crafty/status/71077957997…
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2016 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@dlew
dlew / File.java
Created March 1, 2016 20:46
Automated onError() message generation
public static Action1<Throwable> crashOnError() {
final Throwable checkpoint = new Throwable();
return throwable -> {
StackTraceElement[] stackTrace = checkpoint.getStackTrace();
StackTraceElement element = stackTrace[1]; // First element after `crashOnError()`
String msg = String.format("onError() crash from subscribe() in %s.%s(%s:%s)",
element.getClassName(),
element.getMethodName(),
element.getFileName(),
element.getLineNumber());
@brucetoo
brucetoo / viewpager.java
Created September 14, 2015 09:44
ViewPager滚动时关闭硬件渲染(特别在ViewPager切换定义了动画时)
特别是在定义了 PageTransformer 来实现Page之间的切换动画
会调用到ViewPaper#setScrollState() -> 然后再调用 ViewPager#enableLayers()
默认就开启了硬件加速,因此在动画执行过程中,会预先执行硬件加速,可能就导致了View动画执行的时候掉帧
可以开启 Show HardWare layers updates 来锁定开启硬件加速的View
//以下是解决办法
@Override
public void onPageScrollStateChanged(int scrollState) {
// A small hack to remove the HW layer that the viewpager add to each page when scrolling.
if (scrollState != ViewPager.SCROLL_STATE_IDLE) {
@ozodrukh
ozodrukh / Fragment.java
Created January 6, 2015 18:23
Fragment Circular Reveal animation
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.AccelerateInterpolator;
@staltz
staltz / introrx.md
Last active November 14, 2024 11:27
The introduction to Reactive Programming you've been missing
@slightfoot
slightfoot / NightModeHelper.java
Last active September 24, 2024 01:44
Night Mode Helper - Helps use utilise the night and notnight resource qualifiers without being in car or dock mode.
import java.lang.ref.WeakReference;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.preference.PreferenceManager;
/**
* Night Mode Helper
@chrisbanes
chrisbanes / ForegroundLinearLayout.java
Created February 19, 2014 13:16
ForegroundLinearLayout
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software