(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| 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. |
| /* | |
| * 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 |
| 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; |
| <?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 |
| 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()); |
| 特别是在定义了 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) { |
| 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; |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| 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 |
| /* | |
| * 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 |