Skip to content

Instantly share code, notes, and snippets.

@seven332
Created October 15, 2016 17:37
Show Gist options
  • Select an option

  • Save seven332/fd94eaeeb2f530fd894366337a724678 to your computer and use it in GitHub Desktop.

Select an option

Save seven332/fd94eaeeb2f530fd894366337a724678 to your computer and use it in GitHub Desktop.
/*
* Copyright 2016 Hippo Seven
*
* 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
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.jsouptest;
/*
* Created by Hippo on 10/16/2016.
*/
import android.graphics.Color;
import android.text.TextPaint;
import android.text.style.CharacterStyle;
import android.text.style.UpdateAppearance;
import android.view.View;
public class HideSpan extends CharacterStyle implements UpdateAppearance {
private boolean mUseTextColor;
private int mColor;
private boolean mHide;
/**
* Create a new HideSpan with text color as hide color and true hide state.
*/
public HideSpan() {
this(true, 0, true);
}
/**
* Create a new HideSpan with very text color and true hide state.
*/
public HideSpan(int color) {
this(false, color, true);
}
/**
* Create a new HideSpan with text color as hide color and very hide state.
*/
public HideSpan(boolean hide) {
this(true, 0, hide);
}
/**
* Create a new HideSpan with very text color and very hide state.
*/
public HideSpan(int color, boolean hide) {
this(false, color, hide);
}
private HideSpan(boolean useTextColor, int color, boolean hide) {
mUseTextColor = useTextColor;
mColor = color;
mHide = hide;
}
/**
* Set hide state for this HideSpan.
* <p>
* Call {@link View#invalidate()} to become effective.
*/
public void setHide(boolean hide) {
mHide = hide;
}
/**
* Return hide state of this HideSpan.
*/
public boolean isHide() {
return mHide;
}
/**
* Toggle hide state of this HideSpan.
* <p>
* Call {@link View#invalidate()} to become effective.
*/
public boolean toggleHide() {
return mHide = !mHide;
}
/**
* Set hide color.
* <p>
* Call {@link View#invalidate()} to become effective.
*/
public void setColor(int color) {
mUseTextColor = false;
mColor = color;
}
/**
* Use text color as hide color.
* <p>
* Call {@link View#invalidate()} to become effective.
*/
public void useTextColor() {
mUseTextColor = true;
}
@Override
public void updateDrawState(TextPaint tp) {
if (mHide) {
tp.bgColor = mUseTextColor ? tp.getColor() : mColor;
tp.setColor(Color.TRANSPARENT);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment