Home | History | Annotate | Download | only in graphics
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      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 android.graphics;
     18 
     19 import com.android.layoutlib.bridge.impl.DelegateManager;
     20 import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
     21 
     22 import java.awt.BasicStroke;
     23 import java.awt.Stroke;
     24 
     25 /**
     26  * Delegate implementing the native methods of android.graphics.DashPathEffect
     27  *
     28  * Through the layoutlib_create tool, the original native methods of DashPathEffect have been
     29  * replaced by calls to methods of the same name in this delegate class.
     30  *
     31  * This class behaves like the original native implementation, but in Java, keeping previously
     32  * native data into its own objects and mapping them to int that are sent back and forth between
     33  * it and the original DashPathEffect class.
     34  *
     35  * Because this extends {@link PathEffect_Delegate}, there's no need to use a
     36  * {@link DelegateManager}, as all the PathEffect classes will be added to the manager owned by
     37  * {@link PathEffect_Delegate}.
     38  *
     39  * @see PathEffect_Delegate
     40  *
     41  */
     42 public final class DashPathEffect_Delegate extends PathEffect_Delegate {
     43 
     44     // ---- delegate data ----
     45 
     46     private final float[] mIntervals;
     47     private final float mPhase;
     48 
     49     // ---- Public Helper methods ----
     50 
     51     @Override
     52     public Stroke getStroke(Paint_Delegate paint) {
     53         return new BasicStroke(
     54                 paint.getStrokeWidth(),
     55                 paint.getJavaCap(),
     56                 paint.getJavaJoin(),
     57                 paint.getJavaStrokeMiter(),
     58                 mIntervals,
     59                 mPhase);
     60     }
     61 
     62     @Override
     63     public boolean isSupported() {
     64         return true;
     65     }
     66 
     67     @Override
     68     public String getSupportMessage() {
     69         // no message since isSupported returns true;
     70         return null;
     71     }
     72 
     73     // ---- native methods ----
     74 
     75     @LayoutlibDelegate
     76     /*package*/ static int nativeCreate(float intervals[], float phase) {
     77         DashPathEffect_Delegate newDelegate = new DashPathEffect_Delegate(intervals, phase);
     78         return sManager.addNewDelegate(newDelegate);
     79     }
     80 
     81     // ---- Private delegate/helper methods ----
     82 
     83     private DashPathEffect_Delegate(float intervals[], float phase) {
     84         mIntervals = new float[intervals.length];
     85         System.arraycopy(intervals, 0, mIntervals, 0, intervals.length);
     86         mPhase = phase;
     87     }
     88 }
     89 
     90