⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gradientroundeddrawer.java

📁 moblie syncml mail javame
💻 JAVA
字号:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.funambol.mailclient.ui.view;

import com.funambol.mailclient.ui.utils.UiUtils;
import com.funambol.util.Log;
import javax.microedition.lcdui.Graphics;

public class GradientRoundedDrawer extends RoundedDrawer {
    private int gradientLastH;
    private int[] gradientBackground;

    protected int highlightedMiddleColor = -1;

    public void drawBackground(Graphics g, int x, int y, int w, int h,
            boolean selected) {

        if (selected) {

            // find the radius of the corner            
            int radius = ARC_HEIGHT / 2;

             //border
            g.setColor(graphicalTheme.getHighlightedBorderColor());
            g.setColor(0xff0000);
            g.drawLine(x+LEFT_EDGE_MARGIN, y + TOP_EDGE_MARGIN, 
                    x + w - RIGHT_EDGE_MARGIN, y + h - BOTTOM_EDGE_MARGIN);
            
            
            // bg color
            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.fillRect(1,1,w-2,h-2);
            // the middle color
            g.setColor(getHighlightedMiddleColor());
            g.fillRoundRect(x+LEFT_EDGE_MARGIN, y + TOP_EDGE_MARGIN + h / 2, 
                    w - RIGHT_EDGE_MARGIN, h  / 2 - BOTTOM_EDGE_MARGIN,
                    ARC_WIDTH, ARC_HEIGHT);
            // g.fillRect(1,h/2,w-2,h/2);


            // fill the gradient and paint it
            getGradientBackground( (h - 2 * radius) );
            for (int i = 0; i < gradientBackground.length; i++) {
                g.setColor(gradientBackground[i]);
                g.drawLine(x+LEFT_EDGE_MARGIN,y + TOP_EDGE_MARGIN +ARC_HEIGHT/2 +i, 
                        x + LEFT_EDGE_MARGIN + w - RIGHT_EDGE_MARGIN, 
                        y + TOP_EDGE_MARGIN +ARC_HEIGHT/2 +i);
            }

            // this fills the central line, 
            // that can be skipped in the previous loop due to some
            // "obscure" math rule (something about a division by 2)
          /*  if (gradientBackground.length * 2 < h) {
                int i = gradientBackground.length;
                g.drawLine(1, i + radius, w - 2, i + radius);
            }
        */

        /*g.setColor(graphicalTheme.getHighlightedBorderColor());
        g.drawRoundRect(x + LEFT_EDGE_MARGIN-1,      y + TOP_EDGE_MARGIN-1,
        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);

        /*  g.setColor(getHighlightedMiddleColor());
        g.drawLine(x,y+h, w, y+h);
         */
        }
    }

    private int getHighlightedMiddleColor() {
        if (highlightedMiddleColor == -1) {

            highlightedMiddleColor = UiUtils.getMiddleColor(
                    graphicalTheme.getHighlightedBackgroundColor(),
                    graphicalTheme.getBackgroundColor());
        }
        return highlightedMiddleColor;

    }

    private int[] getGradientBackground(int h) {
        if (gradientBackground == null || h != gradientLastH) {
            gradientLastH = h;
            gradientBackground = UiUtils.getGradient(
                     graphicalTheme.getHighlightedBackgroundColor(), getHighlightedMiddleColor(), h);
        }
        return gradientBackground;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -