Home | History | Annotate | Download | only in xy
      1 /*
      2  * Copyright 2012 AndroidPlot.com
      3  *
      4  *    Licensed under the Apache License, Version 2.0 (the "License");
      5  *    you may not use this file except in compliance with the License.
      6  *    You may obtain a copy of the License at
      7  *
      8  *        http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  *    Unless required by applicable law or agreed to in writing, software
     11  *    distributed under the License is distributed on an "AS IS" BASIS,
     12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  *    See the License for the specific language governing permissions and
     14  *    limitations under the License.
     15  */
     16 
     17 package com.androidplot.xy;
     18 
     19 import android.content.Context;
     20 import android.graphics.Paint;
     21 import com.androidplot.util.Configurator;
     22 
     23 /**
     24  * Base class of all XYRegionFormatters.
     25  */
     26 public class XYRegionFormatter {
     27 
     28     //private int color;
     29     private Paint paint = new Paint();
     30 
     31     {
     32         paint.setStyle(Paint.Style.FILL);
     33         paint.setAntiAlias(true);
     34     }
     35 
     36     /**
     37      * Provided as a convenience to users; allows instantiation and xml configuration
     38      * to take place in a single line
     39      *
     40      * @param ctx
     41      * @param xmlCfgId Id of the xml config file within /res/xml
     42      */
     43     public XYRegionFormatter(Context ctx, int xmlCfgId) {
     44         // prevent configuration of classes derived from this one:
     45         if (getClass().equals(XYRegionFormatter.class)) {
     46             Configurator.configure(ctx, this, xmlCfgId);
     47         }
     48     }
     49 
     50     public XYRegionFormatter(int color) {
     51         //paint = new Paint();
     52         paint.setColor(color);
     53         //paint.setStyle(Paint.Style.FILL);
     54         //paint.setAntiAlias(true);
     55         //this.color = color;
     56     }
     57 
     58     public int getColor() {
     59         return paint.getColor();
     60     }
     61 
     62     public void setColor(int color) {
     63         paint.setColor(color);
     64     }
     65 
     66     /**
     67      * Advanced users can use this method to access the Paint instance to add transparency etc.
     68      * @return
     69      */
     70     public Paint getPaint() {
     71         return paint;
     72     }
     73 }
     74