Skip to content

Instantly share code, notes, and snippets.

Avatar

chiemy chiemy

View GitHub Profile
View ViewGroup#dispatchTouchEvent.java
public boolean dispatchTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
final float xf = ev.getX();
final float yf = ev.getY();
final float scrolledXFloat = xf + mScrollX;
final float scrolledYFloat = yf + mScrollY;
final Rect frame = mTempRect;
boolean disallowIntercept = (mGroupFlags & FLAG_DISALLOW_INTERCEPT) != 0;
if (action == MotionEvent.ACTION_DOWN) {
if (mMotionTarget != null) {
View SnappingLinearLayoutManager.java
public class SnappingLinearLayoutManager extends LinearLayoutManager {
private RecyclerView.SmoothScroller smoothScroller;
public SnappingLinearLayoutManager(Context context) {
super(context, VERTICAL, false);
}
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state,
int position) {
@chiemy
chiemy / CustomSpan.java
Last active Aug 3, 2017
自定义 Span 工具类,可设置文字颜色、大小、字体、样式,字体间加横向、纵向间距
View CustomSpan.java
public class CustomSpan {
private Context mContext;
private SpannableStringBuilder mSpannableString;
private int mStart;
private int mEnd;
public CustomSpan(Context context) {
mContext = context;
mSpannableString = new SpannableStringBuilder("");
}
View CustomTypefaceSpan.java
public class CustomTypefaceSpan extends MetricAffectingSpan {
private final Typeface mTypeface;
public CustomTypefaceSpan(final Typeface typeface) {
this.mTypeface = typeface;
}
@Override
public void updateDrawState(final TextPaint drawState) {
apply(drawState);
@chiemy
chiemy / NestedFragmentHelper.java
Created Apr 25, 2017
ViewPager 内 Fragment 嵌套 ViewPager, setUserVisibleHint 方法不准确的问题的帮助类
View NestedFragmentHelper.java
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
/**
* Created: chiemy
* Date: 17/1/4
* Description: 为解决 ViewPager 内 Fragment 嵌套 ViewPager, setUserVisibleHint 方法不准确的问题的帮助类
*/
public class NestedFragmentHelper implements ViewPager.OnPageChangeListener {
View ExtendToast.java
/**
* Created: chiemy
* Date: 16/11/22
* Description: 可控制显示时长, 可点击的Toast
*/
public class ExtendToast {
public static final int LENGTH_ALWAYS = 0;
public static final int LENGTH_SHORT = 2;
private Toast toast;
View GetScreenshot of recyclerView
public Bitmap getScreenshotFromRecyclerView(RecyclerView view) {
RecyclerView.Adapter adapter = view.getAdapter();
Bitmap bigBitmap = null;
if (adapter != null) {
int size = adapter.getItemCount();
int height = 0;
Paint paint = new Paint();
int iHeight = 0;
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
View blurBitmap.java
public Bitmap blurBitmap(Bitmap bitmap){
//Let's create an empty bitmap with the same size of the bitmap we want to blur
Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
//Instantiate a new Renderscript
RenderScript rs = RenderScript.create(getApplicationContext());
//Create an Intrinsic Blur Script using the Renderscript
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
View FloatLabelLayout.java
/*
* Copyright 2014 Chris Banes
*
* 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
View Example OnAudioFocusChangeListener
private AudioManager.OnAudioFocusChangeListener mOnAudioFocusChangeListener;
//…
mOnAudioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
Log.i(TAG, "AUDIOFOCUS_GAIN");
// Set volume level to desired levels
You can’t perform that action at this time.