java - 我们可以在android项目中使用任何jar文件(由java代码制成)吗?

标签 java android android-library

我有一个使用如下导入的类:

import java.awt.*;
import java.awt.font.GlyphVector;
import java.awt.font.FontRenderContext;

public class FontEx{        
    public static void main(String[] args) {

    }
}

我们知道 Android 没有附带 java.awt.font.Gly​​phVector 或 font.FontRenderContext。

我可以为这个类“FontEx”制作jar文件并将其直接导入到我的android eclipse项目中并使用它吗???

...................................................... ................................ ...................................................... ................................

**package org.newdawn.slick.font;

import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.font.GlyphMetrics;
import java.awt.font.GlyphVector;

import org.newdawn.slick.Image;
import org.newdawn.slick.UnicodeFont;

/**
 * Represents the glyph in a font for a unicode codepoint.
 * 
 * @author Nathan Sweet <misc@n4te.com>
 */
public class Glyph {
    /** The code point in which this glyph is found */
    private int codePoint;
    /** The width of this glyph in pixels */
    private short width;
    /** The height of this glyph in pixels */
    private short height;
    /** The offset on the y axis to draw the glyph at */
    private short yOffset;
    /** True if the glyph isn't defined */
    private boolean isMissing;
    /** The shape drawn for this glyph */
    private Shape shape;
    /** The image generated for this glyph */
    private Image image;

    /**
     * Create a new glyph
     * 
     * @param codePoint The code point in which this glyph can be found
     * @param bounds The bounds that this glrph can fill
     * @param vector The vector this glyph is part of
     * @param index The index of this glyph within the vector
     * @param unicodeFont The font this glyph forms part of
     */
    public Glyph(int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont unicodeFont) {
        this.codePoint = codePoint;

        GlyphMetrics metrics = vector.getGlyphMetrics(index);
        int lsb = (int)metrics.getLSB();
        if (lsb > 0) lsb = 0;
        int rsb = (int)metrics.getRSB();
        if (rsb > 0) rsb = 0;

        int glyphWidth = bounds.width - lsb - rsb;
        int glyphHeight = bounds.height;
        if (glyphWidth > 0 && glyphHeight > 0) {
            int padTop = unicodeFont.getPaddingTop();
            int padRight = unicodeFont.getPaddingRight();
            int padBottom = unicodeFont.getPaddingBottom();
            int padLeft = unicodeFont.getPaddingLeft();
            int glyphSpacing = 1; // Needed to prevent filtering problems.
            width = (short)(glyphWidth + padLeft + padRight + glyphSpacing);
            height = (short)(glyphHeight + padTop + padBottom + glyphSpacing);
            yOffset = (short)(unicodeFont.getAscent() + bounds.y - padTop);
        }

        shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());

        isMissing = !unicodeFont.getFont().canDisplay((char)codePoint);
    }

    /**
     * The unicode codepoint the glyph represents.
     * 
     * @return The codepoint the glyph represents
     */
    public int getCodePoint () {
        return codePoint;
    }

    /**
     * Returns true if the font does not have a glyph for this codepoint.
     * 
     * @return True if this glyph is not defined in the given code point
     */
    public boolean isMissing () {
        return isMissing;
    }

    /**
     * The width of the glyph's image.
     * 
     * @return The width in pixels of the glyphs image
     */
    public int getWidth () {
        return width;
    }

    /**
     * The height of the glyph's image.
     * 
     * @return The height in pixels of the glyphs image
     */
    public int getHeight () {
        return height;
    }

    /**
     * The shape to use to draw this glyph. This is set to null after the glyph is stored 
     * in a GlyphPage.
     * 
     * @return The shape drawn for this glyph
     */
    public Shape getShape () {
        return shape;
    }

    /**
     * Set the shape that should be drawn for this glyph
     * 
     * @param shape The shape that should be drawn for this glyph
     */
    public void setShape(Shape shape) {
        this.shape = shape;
    }

    /**
     * The image to use for this glyph. This is null until after the glyph is stored in a 
     * GlyphPage.
     * 
     * @return The image that has been generated for this glyph
     */
    public Image getImage () {
        return image;
    }

    /**
     * Set the image that has been generated for this glyph
     * 
     * @param image The image that has been generated for this glyph
     */
    public void setImage(Image image) {
        this.image = image;
    }

    /**
     * The distance from drawing y location to top of this glyph, causing the glyph to sit 
     * on the baseline.
     * 
     * @return The offset on the y axis this glyph should be drawn at
     */
    public int getYOffset() {
        return yOffset;
    }
}**

最佳答案

如果 FontEx 类依赖于 GlyphVector 和 FontRenderContext,则不行 - 打包到 jar 文件中不会使该类变得更可用。

关于java - 我们可以在android项目中使用任何jar文件(由java代码制成)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9415378/

相关文章:

android - Android如何处理多个R.java?

android - 主项目和库项目必须共享同一个包吗?

android - 无法使用 Gradle 包含来自另一个 Android 库的 Android 库依赖项

java - 如何使用 JPA 将 SQL Server 2008 日期读取到 Java 中

java - 在Java中的不同时刻播放多种声音

java - 使用 Twitter4j 每日趋势?

java - 当滑动到不同的 viewpager 页面时,如何使以前使用 layout_scrollFlags 隐藏的工具栏再次可见

android - Webview 应用程序下载不起作用

Java - Eclipse JTextField 太大

java - REST HTTP 身份验证 - 如何?