📄 roundeddrawer.java
字号:
/*
* Copyright (C) 2006-2007 Funambol
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
*/
package com.funambol.mailclient.ui.view;
import com.funambol.util.Log;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
/**
* a drawer with rounded corners
*/
public class RoundedDrawer implements Drawer {
private GraphicalTheme graphicalTheme;
private static final int ARC_WIDTH=15;
private static final int ARC_HEIGHT=10;
//private static final String CONTINUE_STRING="..";
private Font font;
private int[] colors;
private int titleBarHeight;
private int BKG_COLOR_START = 0x00dcee;
private int BKG_COLOR_END = 0x004a7e;
/** Creates a new instance of Drawer */
public RoundedDrawer() {
this.graphicalTheme=new BasicGraphicalTheme();
}
public RoundedDrawer(GraphicalTheme graphicalTheme){
this.graphicalTheme=graphicalTheme;
this.font=graphicalTheme.getDefaultFont();
}
public void drawBackground(Graphics g, int w, int h, boolean selected) {
//g.setColor(graphicalTheme.getBackgroundColor());
//g.fillRect(0,0,w,h);
if (selected) {
g.setColor(graphicalTheme.getHighlightedBackgroundColor());
g.fillRoundRect(1,1,w-2,h-2,ARC_WIDTH,ARC_HEIGHT);
g.setColor(graphicalTheme.getHighlightedBorderColor());
g.drawRoundRect(1,1,w-3,h-3,ARC_WIDTH,ARC_HEIGHT);
} else {
g.setColor(graphicalTheme.getBackgroundColor());
g.fillRoundRect(1,1,w-2,h-2,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 = 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 + -