Last active
August 29, 2015 14:23
-
-
Save amyu/796407b54fef8c3225bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.util.AttributeSet; | |
import android.view.View; | |
public class TemplateCustomView extends View { | |
private long mLastInvalidate; | |
private boolean mIsOnDetachedFromWindow; | |
public TemplateCustomView(Context context) { | |
this(context, null, 0); | |
} | |
public TemplateCustomView(Context context, AttributeSet attrs) { | |
this(context, attrs, 0); | |
} | |
public TemplateCustomView(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
initView(); | |
} | |
private void initView() { | |
} | |
@Override | |
protected void onAttachedToWindow() { | |
mIsOnDetachedFromWindow = false; | |
super.onAttachedToWindow(); | |
} | |
@Override | |
protected void onDetachedFromWindow() { | |
//AnimatorのCancel処理 | |
mIsOnDetachedFromWindow = true; | |
super.onDetachedFromWindow(); | |
} | |
@Override | |
public void invalidate() { | |
if (SystemClock.uptimeMillis() - mLastInvalidate < 30 || mIsOnDetachedFromWindow) { | |
return; | |
} | |
mLastInvalidate = SystemClock.uptimeMillis(); | |
super.invalidate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment