Android Open Source - holoaccent Scrubber Control Selector Drawable






From Project

Back to project page holoaccent.

License

The source code is released under:

Apache License

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/*from   w  w w  .j a v a  2 s  . co  m*/
 * 
 * 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.Rect;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.util.TypedValue;

import com.negusoft.holoaccent.AccentPalette;

/**
 * Seekbar's round drawable. It is drawn in a different way depending 
 * on the SelectorType.
 */
public class ScrubberControlSelectorDrawable extends Drawable {
  
  public enum SelectorType { NORMAL, DISABLED, PRESSED, FOCUSED }

  private static final float DRAWABLE_SIZE_DP = 32f;
  private static final float CENTER_RADIUS_DP = 4.5f;
  private static final float CENTER_RADIUS_SMALL_DP = 2f;
  private static final float OUTER_RADIUS_DP = 14f;
  private static final float OUTER_RADIUS_SMALL_DP = 12f;
  private static final float BORDER_RADIUS_DP = 14f;
  private static final float BORDER_WIDTH_DP = 2f;

  private static final int ALPHA_DEFAULT = 153;
  private static final int ALPHA_PRESSED = 89;
  private static final int ALPHA_FOCUSED = 0x4D;

  private static final int COLOR_DISABLED = 0x4D888888;

  private final CircleConstantState mState;
  private final Paint mCenterPaint;
  private final float mCenterRadius;
  private final Paint mOuterPaint;
  private final float mOuterRadius;
  private final Paint mBorderPaint;
  private final float mBorderRadius;
  
  public ScrubberControlSelectorDrawable(DisplayMetrics metrics, AccentPalette palette, SelectorType type) {
    mState = new CircleConstantState(metrics, palette, type);
    mCenterPaint = initCenterPaint(palette);
    mCenterRadius = initCenterRadius(metrics, type);
    mOuterPaint = initOuterPaint(palette, type);
    mOuterRadius = initOuterRadius(metrics, type);
    mBorderPaint = initBorderPaint(metrics, palette, type);
    mBorderRadius = initBorderRadius(metrics);
  }
  
  private Paint initCenterPaint(AccentPalette palette) {
        Paint result = new Paint();
    result.setColor(palette.accentColor);
    result.setStyle(Paint.Style.FILL);
    result.setAntiAlias(true);
    return result;
  }
  
  private float initCenterRadius(DisplayMetrics metrics, SelectorType type) {
    float dp = type == SelectorType.DISABLED ? CENTER_RADIUS_SMALL_DP : CENTER_RADIUS_DP;
        return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);
  }
  
  private Paint initOuterPaint(AccentPalette palette, SelectorType type) {
        Paint result = new Paint();
    result.setColor(getOuterColor(palette, type));
    result.setStyle(Paint.Style.FILL);
    result.setAntiAlias(true);
    return result;
  }
  
  private int getOuterColor(AccentPalette palette, SelectorType type) {
    if (type == SelectorType.DISABLED)
      return COLOR_DISABLED;
    if (type == SelectorType.FOCUSED)
      return palette.getAccentColor(ALPHA_FOCUSED);
    if (type == SelectorType.PRESSED)
      return palette.getAccentColor(ALPHA_PRESSED);
    return palette.getAccentColor(ALPHA_DEFAULT);
  }
  
  private float initOuterRadius(DisplayMetrics metrics, SelectorType type) {
    float dp = type == SelectorType.DISABLED || type == SelectorType.FOCUSED ? OUTER_RADIUS_SMALL_DP : OUTER_RADIUS_DP;
        return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);
  }
  
  private Paint initBorderPaint(DisplayMetrics metrics, AccentPalette palette, SelectorType type) {
    if (type != SelectorType.PRESSED)
      return null;
        Paint result = new Paint();
    result.setColor(palette.accentColor);
    result.setStyle(Paint.Style.STROKE);
    float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, BORDER_WIDTH_DP, metrics);
    result.setStrokeWidth(width);
    result.setAntiAlias(true);
    return result;
  }
  
  private float initBorderRadius(DisplayMetrics metrics) {
        return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, BORDER_RADIUS_DP, metrics);
  }

  @Override
  public void draw(Canvas canvas) {
    Rect r = getBounds();
    float centerX = r.exactCenterX();
    float centerY = r.exactCenterY();

    canvas.drawCircle(centerX, centerY, mOuterRadius, mOuterPaint);
    canvas.drawCircle(centerX, centerY, mCenterRadius, mCenterPaint);
    if (mBorderPaint != null)
      canvas.drawCircle(centerX, centerY, mBorderRadius, mBorderPaint);
  }
  
  @Override
  public int getMinimumWidth() {
        return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DRAWABLE_SIZE_DP, mState.mDisplayMetrics);
  }
  
  @Override
  public int getMinimumHeight() {
        return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DRAWABLE_SIZE_DP, mState.mDisplayMetrics);
  }
  
  @Override
  public int getIntrinsicWidth() {
        return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DRAWABLE_SIZE_DP, mState.mDisplayMetrics);
  }
  
  @Override
  public int getIntrinsicHeight() {
        return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DRAWABLE_SIZE_DP, mState.mDisplayMetrics);
  }

  @Override
  public int getOpacity() {
    return PixelFormat.TRANSLUCENT;
  }

  @Override
  public void setAlpha(int alpha) {
    // empty
  }

  @Override
  public void setColorFilter(ColorFilter cf) {
    // empty
  }

  @Override
  public final ConstantState getConstantState() {
    mState.changingConfigurationValue = super.getChangingConfigurations();
    return mState;
  }
  
  public static class CircleConstantState extends ConstantState {

    public final DisplayMetrics mDisplayMetrics;
    public final AccentPalette mPalette;
    public final SelectorType mType;
    
    int changingConfigurationValue;
    
    public CircleConstantState(DisplayMetrics metrics, AccentPalette palette, SelectorType type) {
      mDisplayMetrics = metrics;
      mPalette = palette;
      mType = type;
    }

    @Override
    public int getChangingConfigurations() {
      return changingConfigurationValue;
    }

    @Override
    public Drawable newDrawable() {
      return new ScrubberControlSelectorDrawable(mDisplayMetrics, mPalette, mType);
    }
    
  }

}




Java Source Code List

com.negusoft.holoaccent.AccentHelper.java
com.negusoft.holoaccent.AccentPalette.java
com.negusoft.holoaccent.AccentResources.java
com.negusoft.holoaccent.activity.AccentActivity.java
com.negusoft.holoaccent.dialog.AccentAlertDialog.java
com.negusoft.holoaccent.dialog.AccentDatePickerDialog.java
com.negusoft.holoaccent.dialog.AccentDialogFragment.java
com.negusoft.holoaccent.dialog.AccentTimePickerDialog.java
com.negusoft.holoaccent.dialog.DividerPainter.java
com.negusoft.holoaccent.dialog.NumberPickerPainter.java
com.negusoft.holoaccent.drawable.ActionBarBackgroundDrawable.java
com.negusoft.holoaccent.drawable.CircleDrawable.java
com.negusoft.holoaccent.drawable.ContactBadgeDrawable.java
com.negusoft.holoaccent.drawable.FastScrollDrawable.java
com.negusoft.holoaccent.drawable.IndeterminedProgressDrawable.java
com.negusoft.holoaccent.drawable.IndeterminedProgressLegacyDrawable.java
com.negusoft.holoaccent.drawable.RectDrawable.java
com.negusoft.holoaccent.drawable.RoundRectDrawable.java
com.negusoft.holoaccent.drawable.ScrubberControlSelectorDrawable.java
com.negusoft.holoaccent.drawable.ScrubberProgressDrawable.java
com.negusoft.holoaccent.drawable.SearchViewDrawable.java
com.negusoft.holoaccent.drawable.SpinnerDrawable.java
com.negusoft.holoaccent.drawable.ToggleForegroundDrawable.java
com.negusoft.holoaccent.drawable.UnderlineDrawable.java
com.negusoft.holoaccent.example.activity.AccentFragmentActivity.java
com.negusoft.holoaccent.example.activity.DialogActivity.java
com.negusoft.holoaccent.example.activity.MainActivity.java
com.negusoft.holoaccent.example.activity.PreferencesActivity.java
com.negusoft.holoaccent.example.activity.SpinnerActivity.java
com.negusoft.holoaccent.example.activity.TabbedActivity.java
com.negusoft.holoaccent.example.activity.TabbedStripActivity.java
com.negusoft.holoaccent.example.activity.themed.DialogActivityLight.java
com.negusoft.holoaccent.example.activity.themed.PreferencesActivityColoredABInverse.java
com.negusoft.holoaccent.example.activity.themed.PreferencesActivityColoredAB.java
com.negusoft.holoaccent.example.activity.themed.PreferencesActivityLightColoredABInverse.java
com.negusoft.holoaccent.example.activity.themed.PreferencesActivityLightColoredAB.java
com.negusoft.holoaccent.example.activity.themed.PreferencesActivityLightDarkAB.java
com.negusoft.holoaccent.example.activity.themed.PreferencesActivityLight.java
com.negusoft.holoaccent.example.activity.themed.SpinnerActivityColoredABInverse.java
com.negusoft.holoaccent.example.activity.themed.SpinnerActivityColoredAB.java
com.negusoft.holoaccent.example.activity.themed.SpinnerActivityLightColoredABInverse.java
com.negusoft.holoaccent.example.activity.themed.SpinnerActivityLightColoredAB.java
com.negusoft.holoaccent.example.activity.themed.SpinnerActivityLightDarkAB.java
com.negusoft.holoaccent.example.activity.themed.SpinnerActivityLight.java
com.negusoft.holoaccent.example.activity.themed.TabbedActivityColoredABInverse.java
com.negusoft.holoaccent.example.activity.themed.TabbedActivityColoredAB.java
com.negusoft.holoaccent.example.activity.themed.TabbedActivityLightColoredABInverse.java
com.negusoft.holoaccent.example.activity.themed.TabbedActivityLightColoredAB.java
com.negusoft.holoaccent.example.activity.themed.TabbedActivityLightDarkAB.java
com.negusoft.holoaccent.example.activity.themed.TabbedActivityLight.java
com.negusoft.holoaccent.example.activity.themed.TabbedStripActivityColoredABInverse.java
com.negusoft.holoaccent.example.activity.themed.TabbedStripActivityColoredAB.java
com.negusoft.holoaccent.example.activity.themed.TabbedStripActivityLightColoredABInverse.java
com.negusoft.holoaccent.example.activity.themed.TabbedStripActivityLightColoredAB.java
com.negusoft.holoaccent.example.activity.themed.TabbedStripActivityLightDarkAB.java
com.negusoft.holoaccent.example.activity.themed.TabbedStripActivityLight.java
com.negusoft.holoaccent.example.fragment.AccentSupportDialogFragment.java
com.negusoft.holoaccent.example.fragment.ButtonFragment.java
com.negusoft.holoaccent.example.fragment.ChoicesFragment.java
com.negusoft.holoaccent.example.fragment.ListFragment.java
com.negusoft.holoaccent.example.fragment.PickersFragment.java
com.negusoft.holoaccent.example.fragment.ProgressFragment.java
com.negusoft.holoaccent.example.fragment.SimpleDialogFragment.java
com.negusoft.holoaccent.example.fragment.TextviewFragment.java
com.negusoft.holoaccent.example.model.ColorOverrideConfig.java
com.negusoft.holoaccent.example.preference.CustomDialogPreference.java
com.negusoft.holoaccent.example.view.CheckableTextView.java
com.negusoft.holoaccent.interceptor.AccentColorInterceptor.java
com.negusoft.holoaccent.interceptor.ActionBarBackgroundInterceptor.java
com.negusoft.holoaccent.interceptor.CircleInterceptor.java
com.negusoft.holoaccent.interceptor.ContactBadgeInterceptor.java
com.negusoft.holoaccent.interceptor.FastScrollInterceptor.java
com.negusoft.holoaccent.interceptor.IndeterminateInterceptor.java
com.negusoft.holoaccent.interceptor.NativeInterceptor.java
com.negusoft.holoaccent.interceptor.PagerTabStripInterceptor.java
com.negusoft.holoaccent.interceptor.RectInterceptor.java
com.negusoft.holoaccent.interceptor.RoundRectInterceptor.java
com.negusoft.holoaccent.interceptor.ScrubberInterceptor.java
com.negusoft.holoaccent.interceptor.SearchViewTextFieldInterceptor.java
com.negusoft.holoaccent.interceptor.SolidColorInterceptor.java
com.negusoft.holoaccent.interceptor.SpinnerInterceptor.java
com.negusoft.holoaccent.interceptor.ToggleInterceptor.java
com.negusoft.holoaccent.interceptor.UnderlineInterceptor.java
com.negusoft.holoaccent.preference.DialogPreference.java
com.negusoft.holoaccent.preference.EditTextPreference.java
com.negusoft.holoaccent.preference.ListPreference.java
com.negusoft.holoaccent.preference.MultiSelectListPreference.java
com.negusoft.holoaccent.preference.SwitchPreference.java
com.negusoft.holoaccent.util.BitmapUtils.java
com.negusoft.holoaccent.util.NativeResources.java
com.negusoft.holoaccent.widget.AccentDatePicker.java
com.negusoft.holoaccent.widget.AccentNumberPicker.java
com.negusoft.holoaccent.widget.AccentQuickContactBadge.java
com.negusoft.holoaccent.widget.AccentRatingBar.java
com.negusoft.holoaccent.widget.AccentSearchView.java
com.negusoft.holoaccent.widget.AccentSwitch.java
com.negusoft.holoaccent.widget.AccentTimePicker.java