1282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski/* 2282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * Copyright (C) 2010 The Android Open Source Project 3282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * 4282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * Licensed under the Apache License, Version 2.0 (the "License"); 5282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * you may not use this file except in compliance with the License. 6282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * You may obtain a copy of the License at 7282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * 8282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * http://www.apache.org/licenses/LICENSE-2.0 9282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * 10282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * Unless required by applicable law or agreed to in writing, software 11282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * distributed under the License is distributed on an "AS IS" BASIS, 12282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * See the License for the specific language governing permissions and 14282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * limitations under the License. 15282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski */ 16282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 17282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinskipackage android.graphics; 18282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 19282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinskiimport com.android.layoutlib.bridge.impl.DelegateManager; 2085d43f01ed0f252df7b5374593792174d50779b7Deepanshu Guptaimport com.android.layoutlib.bridge.impl.PorterDuffUtility; 21282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinskiimport com.android.tools.layoutlib.annotations.LayoutlibDelegate; 22282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 23f2af1f5d8aaff684f8cc6d8e31454c945e190976Deepanshu Guptaimport android.graphics.PorterDuff.Mode; 24f2af1f5d8aaff684f8cc6d8e31454c945e190976Deepanshu Gupta 25282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinskiimport java.awt.Composite; 26282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 27f2af1f5d8aaff684f8cc6d8e31454c945e190976Deepanshu Guptaimport static com.android.layoutlib.bridge.impl.PorterDuffUtility.getPorterDuffMode; 28f2af1f5d8aaff684f8cc6d8e31454c945e190976Deepanshu Gupta 29282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski/** 30282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * Delegate implementing the native methods of android.graphics.PorterDuffXfermode 31282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * 32282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * Through the layoutlib_create tool, the original native methods of PorterDuffXfermode have been 33282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * replaced by calls to methods of the same name in this delegate class. 34282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * 35282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * This class behaves like the original native implementation, but in Java, keeping previously 36282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * native data into its own objects and mapping them to int that are sent back and forth between 37282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * it and the original PorterDuffXfermode class. 38282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * 39282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * Because this extends {@link Xfermode_Delegate}, there's no need to use a 40282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * {@link DelegateManager}, as all the PathEffect classes will be added to the manager owned by 41282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * {@link Xfermode_Delegate}. 42282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski * 43282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski */ 44282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinskipublic class PorterDuffXfermode_Delegate extends Xfermode_Delegate { 45282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 46282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski // ---- delegate data ---- 47282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 48f2af1f5d8aaff684f8cc6d8e31454c945e190976Deepanshu Gupta private final Mode mMode; 49282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 50282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski // ---- Public Helper methods ---- 51282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 52f2af1f5d8aaff684f8cc6d8e31454c945e190976Deepanshu Gupta public Mode getMode() { 53f2af1f5d8aaff684f8cc6d8e31454c945e190976Deepanshu Gupta return mMode; 54282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski } 55282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 56282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski @Override 57282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski public Composite getComposite(int alpha) { 5885d43f01ed0f252df7b5374593792174d50779b7Deepanshu Gupta return PorterDuffUtility.getComposite(mMode, alpha); 59282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski } 60282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 61282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski @Override 62282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski public boolean isSupported() { 63282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski return true; 64282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski } 65282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 66282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski @Override 67282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski public String getSupportMessage() { 68282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski // no message since isSupported returns true; 69282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski return null; 70282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski } 71282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 72282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 73282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski // ---- native methods ---- 74282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 75282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski @LayoutlibDelegate 7688a8364c386c694f7ad56662ef89713dbf7c9d63Narayan Kamath /*package*/ static long nativeCreateXfermode(int mode) { 77282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski PorterDuffXfermode_Delegate newDelegate = new PorterDuffXfermode_Delegate(mode); 78282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski return sManager.addNewDelegate(newDelegate); 79282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski } 80282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 81282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski // ---- Private delegate/helper methods ---- 82282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski 83282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski private PorterDuffXfermode_Delegate(int mode) { 84f2af1f5d8aaff684f8cc6d8e31454c945e190976Deepanshu Gupta mMode = getPorterDuffMode(mode); 85f2af1f5d8aaff684f8cc6d8e31454c945e190976Deepanshu Gupta } 86f2af1f5d8aaff684f8cc6d8e31454c945e190976Deepanshu Gupta 87282e181b58cf72b6ca770dc7ca5f91f135444502Adam Lesinski} 88