📄 roundeddrawer.java
字号:
/*
* Funambol is a mobile platform developed by Funambol, Inc.
* Copyright (C) 2003 - 2007 Funambol, Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, see http://www.gnu.org/licenses or write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*
* You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
* 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by Funambol" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by Funambol".
*
*
*/
package com.funambol.mailclient.ui.view;
import com.funambol.mailclient.ui.controller.UIController;
import com.funambol.mailclient.ui.utils.UiUtils;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
/**
* a drawer with rounded corners
*/
public class RoundedDrawer implements Drawer {
protected GraphicalTheme graphicalTheme;
protected static final int LEFT_EDGE_MARGIN = 0;
protected static final int RIGHT_EDGE_MARGIN = 0;
protected static final int TOP_EDGE_MARGIN = 0;
protected static final int BOTTOM_EDGE_MARGIN = 2;
protected static final int BKG_COLOR_START = 0x00dcee;
protected static final int BKG_COLOR_END = 0x004a7e;
protected static final int ARC_WIDTH=0;
protected static final int ARC_HEIGHT=0;
//private static final String CONTINUE_STRING="..";
protected int titleBarHeight;
private Font font;
private int[] colors;
/** Creates a new instance of Drawer */
public RoundedDrawer() {
this.graphicalTheme = GraphicalThemeFactory.getGraphicalTheme();
}
public void drawBackground(Graphics g, int w, int h, boolean selected) {
drawBackground(g, 0, 0, w, h, selected);
}
public void drawBackground(Graphics g, int x, int y, int w, int h,
boolean selected) {
if (selected) {
g.setColor(graphicalTheme.getHighlightedBackgroundColor());
g.fillRoundRect(x + LEFT_EDGE_MARGIN, y + TOP_EDGE_MARGIN,
w - RIGHT_EDGE_MARGIN, h - BOTTOM_EDGE_MARGIN,
ARC_WIDTH,ARC_HEIGHT);
g.setColor(graphicalTheme.getHighlightedBorderColor());
g.drawRoundRect(x + LEFT_EDGE_MARGIN, y + TOP_EDGE_MARGIN,
w - RIGHT_EDGE_MARGIN - 1, h - BOTTOM_EDGE_MARGIN - 1,
ARC_WIDTH,ARC_HEIGHT);
} else {
g.setColor(graphicalTheme.getBackgroundColor());
g.fillRoundRect(x + LEFT_EDGE_MARGIN, y + TOP_EDGE_MARGIN,
w - RIGHT_EDGE_MARGIN, h - TOP_EDGE_MARGIN,
ARC_WIDTH,ARC_HEIGHT);
}
}
public GraphicalTheme getGraphicalTheme(){
return graphicalTheme;
}
public void drawString(String string, Graphics graphics, int x, int y, boolean selected) {
drawString(string, graphics, x, y, Graphics.TOP|Graphics.LEFT,selected);
}
public void drawBoldString(String string, Graphics graphics, int x, int y, boolean selected) {
Font oldfont = graphics.getFont();
graphics.setFont(getGraphicalTheme().getBoldFont());
//drawString(string, graphics, x, y, Graphics.TOP|Graphics.LEFT,selected);
if (selected) {
graphics.setColor(graphicalTheme.getHighlightedForegroundColor());
} else {
graphics.setColor(graphicalTheme.getForegroundColor());
}
graphics.drawString(string, x,y,Graphics.TOP|Graphics.LEFT);
graphics.setFont(oldfont);
}
public void drawString(String string, Graphics graphics, int x, int y, int layout, boolean selected) {
if (selected) {
graphics.setColor(graphicalTheme.getHighlightedForegroundColor());
} else {
graphics.setColor(graphicalTheme.getForegroundColor());
}
graphics.setFont(graphicalTheme.getDefaultFont());
graphics.drawString(string, x,y,layout);
}
public void drawCanvasBackground(Graphics g, int w, int h) {
g.setColor(graphicalTheme.getBackgroundColor());
g.fillRect(0,0,w,h);
}
public void drawTitleBackground(Graphics g, int w, int h) {
/*
g.setColor(graphicalTheme.getTitleBackgroundColor());
g.fillRect(0,0,w,h);
g.setColor(graphicalTheme.getTitleBorderColor());
g.drawLine(0,h,w,h);
**/
if (this.titleBarHeight != h) {
this.titleBarHeight = h;
colors = UiUtils.getGradient(BKG_COLOR_START, BKG_COLOR_END, h);
}
for (int i = 0; i<colors.length; i++) {
g.setColor(colors[i]);
g.drawLine(0,i,w,i);
}
g.setColor(graphicalTheme.getTitleBorderColor());
g.drawLine(0,h,w,h);
}
/* public int[] getGradient(int aStartColor, int aEndColor, int aLength){
int r1 = aStartColor>>16;
int g1 = aStartColor>>8;
g1 = g1 & 0x0000FF;
int b1 = aStartColor;
b1 = b1 & 0x0000FF;
int r2 = aEndColor>>16;
int g2 = aEndColor>>8;
g2 = g2 & 0x0000FF;
int b2 = aEndColor;
b2 = b2 & 0x0000FF;
int res_r = 0;
int res_g = 0;
int res_b = 0;
int gradient[] = new int[aLength];
int counter = 0;
int dif;
while(counter < aLength){
dif = (aLength-counter);
res_r = (r1 * dif + r2*counter)/aLength ;
res_g = (g1 * dif + g2*counter)/aLength ;
res_b = (b1 * dif + b2*counter)/aLength ;
res_r = res_r <<16;
res_g = res_g <<8;
gradient[counter] = (res_r | res_g | res_b);
counter++;
}
return gradient;
}
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -