If you think the Android project holoaccent listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*******************************************************************************
* Copyright 2013 NEGU Soft//fromwww.java2s.com
*
* 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.negusoft.holoaccent.drawable;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import com.negusoft.holoaccent.AccentPalette;
publicclass FastScrollDrawable extends Drawable {
privatestaticfinalfloat WIDTH_DP = 30f;
privatestaticfinalfloat HEIGHT_DP = 54f;
privatestaticfinalfloat FILL_WIDTH_DP = 6f;
privatestaticfinalfloat FILL_HEIGHT_DP = 30f;
privatestaticfinalfloat FILL_RADIUS_DP = 1f;
privatestaticfinalfloat GLOW_WIDTH_DP = 14f;
privatestaticfinalfloat GLOW_HEIGHT_DP = 37f;
privatestaticfinalfloat GLOW_RADIUS_DP = 5f;
privatestaticfinalint FILL_ALPHA = 156;
privatestaticfinalint GLOW_ALPHA = 63;
privatefinal DisplayMetrics mMetrics;
privatefinal AccentPalette mPalette;
privatefinalboolean mPressed;
privatefinal Paint mFillPaint;
privatefinalfloat mFillWidth;
privatefinalfloat mFillHeight;
privatefinalfloat mFillRadius;
privatefinal Paint mGlowPaint;
privatefinalfloat mGlowWidth;
privatefinalfloat mGlowHeight;
privatefinalfloat mGlowRadius;
privateint mAlpha = 255;
public FastScrollDrawable(DisplayMetrics metrics, AccentPalette palette, boolean pressed) {
mMetrics = metrics;
mPalette = palette;
mPressed = pressed;
mFillPaint = initFillPaint(palette, pressed);
mFillWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, FILL_WIDTH_DP, metrics);
mFillHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, FILL_HEIGHT_DP, metrics);
mFillRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, FILL_RADIUS_DP, metrics);
mGlowPaint = initGlowPaint(palette, pressed);
mGlowWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, GLOW_WIDTH_DP, metrics);
mGlowHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, GLOW_HEIGHT_DP, metrics);
mGlowRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, GLOW_RADIUS_DP, metrics);
}
private Paint initFillPaint(AccentPalette palette, boolean pressed) {
Paint result = new Paint();
result.setStyle(Paint.Style.FILL);
int color = getFillColor(palette, pressed, 255);
result.setColor(color);
result.setAntiAlias(true);
return result;
}
private Paint initGlowPaint(AccentPalette palette, boolean pressed) {
if (!pressed)
return null;
Paint result = new Paint();
result.setStyle(Paint.Style.FILL);
result.setColor(getGlowColor(palette, pressed, 255));
result.setAntiAlias(true);
return result;
}
privateint getFillColor(AccentPalette palette, boolean pressed, int alpha) {
if (!pressed)
return palette.getDarkAccentColor(alpha);
int resultAlpha = FILL_ALPHA * alpha / 255;
return palette.getAccentColor(resultAlpha);
}
privateint getGlowColor(AccentPalette palette, boolean pressed, int alpha) {
int resultAlpha = GLOW_ALPHA * alpha / 255;
return palette.getAccentColor(resultAlpha);
}
@Override
publicint getIntrinsicWidth() {
return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, WIDTH_DP, mMetrics);
}
@Override
publicint getIntrinsicHeight() {
return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, HEIGHT_DP, mMetrics);
}
@Override
publicvoid draw(Canvas canvas) {
float centerX = getBounds().exactCenterX();
float centerY = getBounds().exactCenterY();
if (mGlowPaint != null) {
float halfWidth = mGlowWidth / 2f;
float halfHeight = mGlowHeight / 2f;
RectF rect = new RectF(centerX - halfWidth,
centerY - halfHeight,
centerX + halfWidth,
centerY + halfHeight);
mGlowPaint.setColor(getGlowColor(mPalette, mPressed, mAlpha));
canvas.drawRoundRect(rect, mGlowRadius, mGlowRadius, mGlowPaint);
}
float halfWidth = mFillWidth / 2f;
float halfHeight = mFillHeight / 2f;
RectF rect = new RectF(centerX - halfWidth,
centerY - halfHeight,
centerX + halfWidth,
centerY + halfHeight);
mFillPaint.setColor(getFillColor(mPalette, mPressed, mAlpha));
canvas.drawRoundRect(rect, mFillRadius, mFillRadius, mFillPaint);
}
@Override
publicint getOpacity() {
return PixelFormat.TRANSLUCENT;
}
@Override
publicvoid setAlpha(int alpha) {
mAlpha = alpha;
invalidateSelf();
}
@Override
publicvoid setColorFilter(ColorFilter cf) {
// empty
}
}