Android Open Source - wally Color Panel View






From Project

Back to project page wally.

License

The source code is released under:

Apache License

If you think the Android project wally 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 (C) 2010 Daniel Nilsson/*from  ww w .  j a  v  a 2  s. c om*/
 *
 * 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 net.margaritov.preference.colorpicker.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import net.margaritov.preference.colorpicker.drawable.AlphaPatternDrawable;

/**
 * This class draws a panel which which will be filled with a color which can be set.
 * It can be used to show the currently selected color which you will get from
 * the {@link ColorPickerView}.
 * @author Daniel Nilsson
 *
 */
public class ColorPanelView extends View{

  /**
   * The width in pixels of the border 
   * surrounding the color panel.
   */
  private final static float  BORDER_WIDTH_PX = 1;
  
  private static float mDensity = 1f;
  
  private int     mBorderColor = 0xff6E6E6E;
  private int     mColor = 0xff000000;
  
  private Paint    mBorderPaint;
  private Paint    mColorPaint;
  
  private RectF    mDrawingRect;
  private RectF    mColorRect;

  private AlphaPatternDrawable mAlphaPattern;
  
  
  public ColorPanelView(Context context){
    this(context, null);
  }
  
  public ColorPanelView(Context context, AttributeSet attrs){
    this(context, attrs, 0);
  }
  
  public ColorPanelView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    
    init();
  }
  
  private void init(){
    mBorderPaint = new Paint();
    mColorPaint = new Paint();
    mDensity = getContext().getResources().getDisplayMetrics().density;
  }
  
  
  @Override
  protected void onDraw(Canvas canvas) {
    
    final RectF  rect = mColorRect;
        
    if(BORDER_WIDTH_PX > 0){
      mBorderPaint.setColor(mBorderColor);
      canvas.drawRect(mDrawingRect, mBorderPaint);    
    }
    
    if(mAlphaPattern != null){
      mAlphaPattern.draw(canvas);
    }
          
    mColorPaint.setColor(mColor);
    
    canvas.drawRect(rect, mColorPaint);
  }
    
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);
    
    setMeasuredDimension(width, height);
  }
  
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    
    mDrawingRect = new RectF();    
    mDrawingRect.left =  getPaddingLeft();
    mDrawingRect.right  = w - getPaddingRight();
    mDrawingRect.top = getPaddingTop();
    mDrawingRect.bottom = h - getPaddingBottom();
    
    setUpColorRect();
    
  }
  
  private void setUpColorRect(){
    final RectF  dRect = mDrawingRect;    
    
    float left = dRect.left + BORDER_WIDTH_PX;
    float top = dRect.top + BORDER_WIDTH_PX;
    float bottom = dRect.bottom - BORDER_WIDTH_PX;
    float right = dRect.right - BORDER_WIDTH_PX;
    
    mColorRect = new RectF(left,top, right, bottom);
    
    mAlphaPattern = new AlphaPatternDrawable((int)(5 * mDensity));
    
    mAlphaPattern.setBounds(Math.round(mColorRect.left), 
        Math.round(mColorRect.top), 
        Math.round(mColorRect.right), 
        Math.round(mColorRect.bottom));
    
  }
  
  /**
   * Set the color that should be shown by this view.
   * @param color
   */
  public void setColor(int color){
    mColor = color;
    invalidate();
  }
  
  /**
   * Get the color currently show by this view.
   * @return
   */
  public int getColor(){
    return mColor;
  }
  
  /**
   * Set the color of the border surrounding the panel.
   * @param color
   */
  public void setBorderColor(int color){
    mBorderColor = color;
    invalidate();
  }

  /**
   * Get the color of the border surrounding the panel.
   */
  public int getBorderColor(){
    return mBorderColor;
  }
  
}




Java Source Code List

com.musenkishi.wally.activities.ImageDetailsActivity.java
com.musenkishi.wally.activities.MainActivity.java
com.musenkishi.wally.adapters.RecyclerImagesAdapter.java
com.musenkishi.wally.adapters.RecyclerSavedImagesAdapter.java
com.musenkishi.wally.adapters.SmartFragmentPagerAdapter.java
com.musenkishi.wally.adapters.SmartFragmentStatePagerAdapter.java
com.musenkishi.wally.anim.BaseItemAnimator.java
com.musenkishi.wally.anim.ScaleInOutItemAnimator.java
com.musenkishi.wally.anim.interpolator.EaseInOutBezierInterpolator.java
com.musenkishi.wally.anim.interpolator.FastOutLinearInInterpolator.java
com.musenkishi.wally.anim.interpolator.FastOutSlowInInterpolator.java
com.musenkishi.wally.anim.interpolator.LinearOutSlowInInterpolator.java
com.musenkishi.wally.base.BaseActivity.java
com.musenkishi.wally.base.BaseFragment.java
com.musenkishi.wally.base.GridFragment.java
com.musenkishi.wally.base.WallyApplication.java
com.musenkishi.wally.dataprovider.DataProvider.java
com.musenkishi.wally.dataprovider.FileManager.java
com.musenkishi.wally.dataprovider.NetworkDataProvider.java
com.musenkishi.wally.dataprovider.SharedPreferencesDataProvider.java
com.musenkishi.wally.dataprovider.models.DataProviderError.java
com.musenkishi.wally.dataprovider.models.SaveImageRequest.java
com.musenkishi.wally.dataprovider.okhttp.OkHttpStreamFetcher.java
com.musenkishi.wally.dataprovider.okhttp.OkHttpUrlLoader.java
com.musenkishi.wally.dataprovider.util.Parser.java
com.musenkishi.wally.fragments.CustomResolutionDialogFragment.java
com.musenkishi.wally.fragments.FilterDialogFragment.java
com.musenkishi.wally.fragments.ImageZoomFragment.java
com.musenkishi.wally.fragments.LatestFragment.java
com.musenkishi.wally.fragments.MaterialDialogFragment.java
com.musenkishi.wally.fragments.RandomImagesFragment.java
com.musenkishi.wally.fragments.SavedImagesFragment.java
com.musenkishi.wally.fragments.SearchFragment.java
com.musenkishi.wally.fragments.ToplistFragment.java
com.musenkishi.wally.models.Author.java
com.musenkishi.wally.models.ExceptionReporter.java
com.musenkishi.wally.models.Filter.java
com.musenkishi.wally.models.ImagePage.java
com.musenkishi.wally.models.Image.java
com.musenkishi.wally.models.ListFilterGroup.java
com.musenkishi.wally.models.Rating.java
com.musenkishi.wally.models.SavedImageData.java
com.musenkishi.wally.models.Size.java
com.musenkishi.wally.models.Tag.java
com.musenkishi.wally.models.filters.FilterAspectRatioKeys.java
com.musenkishi.wally.models.filters.FilterBoardsKeys.java
com.musenkishi.wally.models.filters.FilterBoards.java
com.musenkishi.wally.models.filters.FilterGroup.java
com.musenkishi.wally.models.filters.FilterGroupsStructure.java
com.musenkishi.wally.models.filters.FilterPurityKeys.java
com.musenkishi.wally.models.filters.FilterPurity.java
com.musenkishi.wally.models.filters.FilterResOptKeys.java
com.musenkishi.wally.models.filters.FilterResOpt.java
com.musenkishi.wally.models.filters.FilterResolutionKeys.java
com.musenkishi.wally.models.filters.FilterTimeSpanKeys.java
com.musenkishi.wally.muzei.WallyArtSource.java
com.musenkishi.wally.notification.NotificationProvider.java
com.musenkishi.wally.observers.FileChangeReceiver.java
com.musenkishi.wally.observers.FiltersChangeReceiver.java
com.musenkishi.wally.util.Blur.java
com.musenkishi.wally.util.PaletteLoader.java
com.musenkishi.wally.util.PaletteRequest.java
com.musenkishi.wally.util.SparseBooleanArrayParcelable.java
com.musenkishi.wally.util.TextClickableSpan.java
com.musenkishi.wally.util.TextLinkBuilder.java
com.musenkishi.wally.util.TypefaceSpan.java
com.musenkishi.wally.views.AutoGridView.java
com.musenkishi.wally.views.GridRecyclerView.java
com.musenkishi.wally.views.ObservableScrollView.java
com.musenkishi.wally.views.TabBarView.java
com.musenkishi.wally.views.TabView.java
com.musenkishi.wally.views.swipeclearlayout.SwipeClearLayout.java
net.margaritov.preference.colorpicker.dialog.ColorPickerDialogFragment.java
net.margaritov.preference.colorpicker.drawable.AlphaPatternDrawable.java
net.margaritov.preference.colorpicker.preference.ColorPickerPreference.java
net.margaritov.preference.colorpicker.view.ColorPanelView.java
net.margaritov.preference.colorpicker.view.ColorPickerView.java
nl.codesoup.cubicbezier.CubicBezierInterpolator.java