Browse Source

auto import from //depot/cupcake/@135843

replicant-6.0
The Android Open Source Project 11 years ago
parent
commit
edbf3b6af7
100 changed files with 33162 additions and 0 deletions
  1. +0
    -0
      MODULE_LICENSE_APACHE2
  2. +222
    -0
      NOTICE
  3. +31
    -0
      awt/Android.mk
  4. +1354
    -0
      awt/com/android/internal/awt/AndroidGraphics2D.java
  5. +96
    -0
      awt/com/android/internal/awt/AndroidGraphicsConfiguration.java
  6. +87
    -0
      awt/com/android/internal/awt/AndroidGraphicsFactory.java
  7. +274
    -0
      awt/com/android/internal/awt/AndroidImageDecoder.java
  8. +536
    -0
      awt/com/android/internal/awt/AndroidJavaBlitter.java
  9. +75
    -0
      awt/com/android/internal/awt/AndroidNativeEventQueue.java
  10. +88
    -0
      awt/com/android/internal/awt/AndroidWTK.java
  11. +52
    -0
      awt/com/android/internal/awt/AwtFactory.java
  12. +66
    -0
      awt/com/android/internal/awt/ImageOutputStreamWrapper.java
  13. +681
    -0
      awt/java/awt/AWTEvent.java
  14. +47
    -0
      awt/java/awt/AWTException.java
  15. +712
    -0
      awt/java/awt/AWTKeyStroke.java
  16. +47
    -0
      awt/java/awt/AWTListenerList.java
  17. +61
    -0
      awt/java/awt/AWTPermission.java
  18. +39
    -0
      awt/java/awt/ActiveEvent.java
  19. +166
    -0
      awt/java/awt/Adjustable.java
  20. +352
    -0
      awt/java/awt/AlphaComposite.java
  21. +2443
    -0
      awt/java/awt/BasicStroke.java
  22. +195
    -0
      awt/java/awt/BufferCapabilities.java
  23. +990
    -0
      awt/java/awt/Color.java
  24. +6020
    -0
      awt/java/awt/Component.java
  25. +56
    -0
      awt/java/awt/ComponentBehavior.java
  26. +154
    -0
      awt/java/awt/ComponentOrientation.java
  27. +51
    -0
      awt/java/awt/Composite.java
  28. +54
    -0
      awt/java/awt/CompositeContext.java
  29. +427
    -0
      awt/java/awt/Cursor.java
  30. +201
    -0
      awt/java/awt/Dimension.java
  31. +723
    -0
      awt/java/awt/Dispatcher.java
  32. +165
    -0
      awt/java/awt/DisplayMode.java
  33. +596
    -0
      awt/java/awt/Event.java
  34. +118
    -0
      awt/java/awt/EventDispatchThread.java
  35. +320
    -0
      awt/java/awt/EventQueue.java
  36. +253
    -0
      awt/java/awt/EventQueueCore.java
  37. +1541
    -0
      awt/java/awt/Font.java
  38. +47
    -0
      awt/java/awt/FontFormatException.java
  39. +466
    -0
      awt/java/awt/FontMetrics.java
  40. +255
    -0
      awt/java/awt/GradientPaint.java
  41. +204
    -0
      awt/java/awt/GradientPaintContext.java
  42. +924
    -0
      awt/java/awt/Graphics.java
  43. +513
    -0
      awt/java/awt/Graphics2D.java
  44. +226
    -0
      awt/java/awt/GraphicsConfiguration.java
  45. +196
    -0
      awt/java/awt/GraphicsDevice.java
  46. +212
    -0
      awt/java/awt/GraphicsEnvironment.java
  47. +54
    -0
      awt/java/awt/HeadlessException.java
  48. +72
    -0
      awt/java/awt/HeadlessGraphicsEnvironment.java
  49. +226
    -0
      awt/java/awt/HeadlessToolkit.java
  50. +55
    -0
      awt/java/awt/IllegalComponentStateException.java
  51. +205
    -0
      awt/java/awt/Image.java
  52. +78
    -0
      awt/java/awt/ImageCapabilities.java
  53. +179
    -0
      awt/java/awt/Insets.java
  54. +59
    -0
      awt/java/awt/ItemSelectable.java
  55. +783
    -0
      awt/java/awt/MenuComponent.java
  56. +57
    -0
      awt/java/awt/MenuContainer.java
  57. +64
    -0
      awt/java/awt/ModalContext.java
  58. +418
    -0
      awt/java/awt/MouseDispatcher.java
  59. +57
    -0
      awt/java/awt/Paint.java
  60. +69
    -0
      awt/java/awt/PaintContext.java
  61. +211
    -0
      awt/java/awt/Point.java
  62. +515
    -0
      awt/java/awt/Polygon.java
  63. +723
    -0
      awt/java/awt/Rectangle.java
  64. +606
    -0
      awt/java/awt/RenderingHints.java
  65. +162
    -0
      awt/java/awt/Shape.java
  66. +50
    -0
      awt/java/awt/Stroke.java
  67. +1444
    -0
      awt/java/awt/Toolkit.java
  68. +255
    -0
      awt/java/awt/ToolkitImpl.java
  69. +57
    -0
      awt/java/awt/Transparency.java
  70. +44
    -0
      awt/java/awt/color/CMMException.java
  71. +414
    -0
      awt/java/awt/color/ColorSpace.java
  72. +468
    -0
      awt/java/awt/color/ICC_ColorSpace.java
  73. +1477
    -0
      awt/java/awt/color/ICC_Profile.java
  74. +78
    -0
      awt/java/awt/color/ICC_ProfileGray.java
  75. +154
    -0
      awt/java/awt/color/ICC_ProfileRGB.java
  76. +173
    -0
      awt/java/awt/color/ICC_ProfileStub.java
  77. +47
    -0
      awt/java/awt/color/ProfileDataException.java
  78. +8
    -0
      awt/java/awt/color/package.html
  79. +36
    -0
      awt/java/awt/event/AWTEventListener.java
  80. +58
    -0
      awt/java/awt/event/AWTEventListenerProxy.java
  81. +114
    -0
      awt/java/awt/event/ActionEvent.java
  82. +35
    -0
      awt/java/awt/event/ActionListener.java
  83. +123
    -0
      awt/java/awt/event/AdjustmentEvent.java
  84. +35
    -0
      awt/java/awt/event/AdjustmentListener.java
  85. +46
    -0
      awt/java/awt/event/ComponentAdapter.java
  86. +88
    -0
      awt/java/awt/event/ComponentEvent.java
  87. +41
    -0
      awt/java/awt/event/ComponentListener.java
  88. +40
    -0
      awt/java/awt/event/ContainerAdapter.java
  89. +89
    -0
      awt/java/awt/event/ContainerEvent.java
  90. +37
    -0
      awt/java/awt/event/ContainerListener.java
  91. +40
    -0
      awt/java/awt/event/FocusAdapter.java
  92. +96
    -0
      awt/java/awt/event/FocusEvent.java
  93. +37
    -0
      awt/java/awt/event/FocusListener.java
  94. +40
    -0
      awt/java/awt/event/HierarchyBoundsAdapter.java
  95. +37
    -0
      awt/java/awt/event/HierarchyBoundsListener.java
  96. +154
    -0
      awt/java/awt/event/HierarchyEvent.java
  97. +35
    -0
      awt/java/awt/event/HierarchyListener.java
  98. +190
    -0
      awt/java/awt/event/InputEvent.java
  99. +156
    -0
      awt/java/awt/event/InputMethodEvent.java
  100. +37
    -0
      awt/java/awt/event/InputMethodListener.java

+ 0
- 0
MODULE_LICENSE_APACHE2 View File


+ 222
- 0
NOTICE View File

@@ -0,0 +1,222 @@
=========================================================================
== NOTICE file corresponding to the section 4 d of ==
== the Apache License, Version 2.0, ==
== in this case for the Android-specific code. ==
=========================================================================

Android Code
Copyright 2005-2008 The Android Open Source Project

This product includes software developed as part of
The Android Open Source Project (http://source.android.com).

=========================================================================
== NOTICE file corresponding to the section 4 d of ==
== the Apache License, Version 2.0, ==
== in this case for Apache Commons code. ==
=========================================================================

Apache Commons
Copyright 1999-2004 The Apache Software Foundation

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).

=========================================================================
== NOTICE file corresponding to the section 4 d of ==
== the Apache License, Version 2.0, ==
== in this case for Jakarta Commons Logging. ==
=========================================================================

Jakarta Commons Logging (JCL)
Copyright 2005,2006 The Apache Software Foundation.

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).

=========================================================================
== NOTICE file corresponding to the section 4 d of ==
== the Apache License, Version 2.0, ==
== in this case for the Nuance code. ==
=========================================================================

These files are Copyright 2007 Nuance Communications, but released under
the Apache2 License.

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.

"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.

2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.

4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:

(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.

You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.

8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS


+ 31
- 0
awt/Android.mk View File

@@ -0,0 +1,31 @@
#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := $(call all-subdir-java-files)

LOCAL_JAVA_RESOURCE_DIRS := resources

LOCAL_JAVA_LIBRARIES := core framework

LOCAL_MODULE:= android.awt

LOCAL_DX_FLAGS := --core-library

include $(BUILD_JAVA_LIBRARY)

+ 1354
- 0
awt/com/android/internal/awt/AndroidGraphics2D.java
File diff suppressed because it is too large
View File


+ 96
- 0
awt/com/android/internal/awt/AndroidGraphicsConfiguration.java View File

@@ -0,0 +1,96 @@
/*
* Copyright 2007, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.internal.awt;

import com.android.internal.awt.AndroidGraphics2D;

import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.VolatileImage;

import android.graphics.Canvas;

public class AndroidGraphicsConfiguration extends GraphicsConfiguration {

@Override
public BufferedImage createCompatibleImage(int width, int height) {
// TODO Auto-generated method stub
return null;
}

@Override
public BufferedImage createCompatibleImage(int width, int height,
int transparency) {
// TODO Auto-generated method stub
return null;
}

@Override
public VolatileImage createCompatibleVolatileImage(int width, int height) {
// TODO Auto-generated method stub
return null;
}

@Override
public VolatileImage createCompatibleVolatileImage(int width, int height,
int transparency) {
// TODO Auto-generated method stub
return null;
}

@Override
public Rectangle getBounds() {
Canvas c = AndroidGraphics2D.getAndroidCanvas();
if(c != null)
return new Rectangle(0, 0, c.getWidth(), c.getHeight());
return null;
}

@Override
public ColorModel getColorModel() {
// TODO Auto-generated method stub
return null;
}

@Override
public ColorModel getColorModel(int transparency) {
// TODO Auto-generated method stub
return null;
}

@Override
public AffineTransform getDefaultTransform() {
return new AffineTransform();
}

@Override
public GraphicsDevice getDevice() {
// TODO Auto-generated method stub
return null;
}

@Override
public AffineTransform getNormalizingTransform() {
// TODO Auto-generated method stub
return null;
}

}

+ 87
- 0
awt/com/android/internal/awt/AndroidGraphicsFactory.java View File

@@ -0,0 +1,87 @@
/*
* Copyright 2007, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.internal.awt;

import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.peer.FontPeer;

import org.apache.harmony.awt.gl.MultiRectArea;
import org.apache.harmony.awt.gl.font.AndroidFont;
import org.apache.harmony.awt.gl.font.FontManager;
import org.apache.harmony.awt.gl.font.FontMetricsImpl;
import org.apache.harmony.awt.gl.font.AndroidFontManager;
import org.apache.harmony.awt.wtk.NativeWindow;
import org.apache.harmony.awt.wtk.WindowFactory;
import org.apache.harmony.awt.gl.CommonGraphics2DFactory;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.content.Context;

public class AndroidGraphicsFactory extends CommonGraphics2DFactory {
public GraphicsEnvironment createGraphicsEnvironment(WindowFactory wf) {
// TODO Auto-generated method stub
return null;
}

public Font embedFont(String fontFilePath) {
// TODO Auto-generated method stub
return null;
}

public FontManager getFontManager() {
return AndroidFontManager.inst;
}

public FontMetrics getFontMetrics(Font font) {
return new FontMetricsImpl(font);
}

public FontPeer getFontPeer(Font font) {
//return getFontManager().getFontPeer(font.getName(), font.getStyle(), font.getSize());
return new AndroidFont(font.getName(), font.getStyle(), font.getSize());
}

public Graphics2D getGraphics2D(NativeWindow win, int translateX,
int translateY, MultiRectArea clip) {
// TODO Auto-generated method stub
return null;
}

public Graphics2D getGraphics2D(NativeWindow win, int translateX,
int translateY, int width, int height) {
// TODO Auto-generated method stub
return null;
}

public Graphics2D getGraphics2D(Context ctx, Canvas c, Paint p) {
return AndroidGraphics2D.getInstance(ctx, c, p);
}

public Graphics2D getGraphics2D(Canvas c, Paint p) {
throw new RuntimeException("Not supported!");
}

public Graphics2D getGraphics2D() {
return AndroidGraphics2D.getInstance();
}

}

+ 274
- 0
awt/com/android/internal/awt/AndroidImageDecoder.java View File

@@ -0,0 +1,274 @@
/*
* Copyright 2007, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.internal.awt;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.awt.Transparency;
import java.awt.color.ColorSpace;
//import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DirectColorModel;
import java.awt.image.ImageConsumer;
import java.awt.image.IndexColorModel;
import java.io.IOException;
import java.io.InputStream;
import java.util.Hashtable;

import org.apache.harmony.awt.gl.image.DecodingImageSource;
import org.apache.harmony.awt.gl.image.ImageDecoder;
import org.apache.harmony.awt.internal.nls.Messages;

public class AndroidImageDecoder extends ImageDecoder {
private static final int hintflags =
ImageConsumer.SINGLEFRAME | // PNG is a static image
ImageConsumer.TOPDOWNLEFTRIGHT | // This order is only one possible
ImageConsumer.COMPLETESCANLINES; // Don't deliver incomplete scanlines
// Each pixel is a grayscale sample.
private static final int PNG_COLOR_TYPE_GRAY = 0;
// Each pixel is an R,G,B triple.
private static final int PNG_COLOR_TYPE_RGB = 2;
// Each pixel is a palette index, a PLTE chunk must appear.
private static final int PNG_COLOR_TYPE_PLTE = 3;
// Each pixel is a grayscale sample, followed by an alpha sample.
private static final int PNG_COLOR_TYPE_GRAY_ALPHA = 4;
// Each pixel is an R,G,B triple, followed by an alpha sample.
private static final int PNG_COLOR_TYPE_RGBA = 6;
private static final int NB_OF_LINES_PER_CHUNK = 1; // 0 = full image
Bitmap bm; // The image as decoded by Android
// Header information
int imageWidth; // Image size
int imageHeight;
int colorType; // One of the PNG_ constants from above
int bitDepth; // Number of bits per color
byte cmap[]; // The color palette for index color models
ColorModel model; // The corresponding AWT color model
boolean transferInts; // Is transfer of type int or byte?
int dataElementsPerPixel;

// Buffers for decoded image data
byte byteOut[];
int intOut[];

public AndroidImageDecoder(DecodingImageSource src, InputStream is) {
super(src, is);
dataElementsPerPixel = 1;
}

@Override
/**
* All the decoding is done in Android
*
* AWT???: Method returns only once the image is completly
* decoded; decoding is not done asynchronously
*/
public void decodeImage() throws IOException {
try {
bm = BitmapFactory.decodeStream(inputStream);
if (bm == null) {
throw new IOException("Input stream empty and no image cached");
}

// Check size
imageWidth = bm.getWidth();
imageHeight = bm.getHeight();
if (imageWidth < 0 || imageHeight < 0 ) {
throw new RuntimeException("Illegal image size: "
+ imageWidth + ", " + imageHeight);
}
// We got the image fully decoded; now send all image data to AWT
setDimensions(imageWidth, imageHeight);
model = createColorModel();
setColorModel(model);
setHints(hintflags);
setProperties(new Hashtable<Object, Object>()); // Empty
sendPixels(NB_OF_LINES_PER_CHUNK != 0 ? NB_OF_LINES_PER_CHUNK : imageHeight);
imageComplete(ImageConsumer.STATICIMAGEDONE);
} catch (IOException e) {
throw e;
} catch (RuntimeException e) {
imageComplete(ImageConsumer.IMAGEERROR);
throw e;
} finally {
closeStream();
}
}
/**
* Create the AWT color model
*
* ???AWT: Android Bitmaps are always of type: ARGB-8888-Direct color model
*
* However, we leave the code here for a more powerfull decoder
* that returns a native model, and the conversion is then handled
* in AWT. With such a decoder, we would need to get the colorType,
* the bitDepth, (and the color palette for an index color model)
* from the image and construct the correct color model here.
*/
private ColorModel createColorModel() {
ColorModel cm = null;
int bmModel = 5; // TODO This doesn't exist: bm.getColorModel();
cmap = null;
switch (bmModel) {
// A1_MODEL
case 1:
colorType = PNG_COLOR_TYPE_GRAY;
bitDepth = 1;
break;
// A8_MODEL
case 2:
colorType = PNG_COLOR_TYPE_GRAY_ALPHA;
bitDepth = 8;
break;
// INDEX8_MODEL
// RGB_565_MODEL
// ARGB_8888_MODEL
case 3:
case 4:
case 5:
colorType = bm.hasAlpha() ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB;
bitDepth = 8;
break;

default:
// awt.3C=Unknown PNG color type
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
}
switch (colorType) {
case PNG_COLOR_TYPE_GRAY: {
if (bitDepth != 8 && bitDepth != 4 && bitDepth != 2 && bitDepth != 1) {
// awt.3C=Unknown PNG color type
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
}

// Create gray color model
int numEntries = 1 << bitDepth;
int scaleFactor = 255 / (numEntries-1);
byte comps[] = new byte[numEntries];
for (int i = 0; i < numEntries; i++) {
comps[i] = (byte) (i * scaleFactor);
}
cm = new IndexColorModel(bitDepth, numEntries, comps, comps, comps);

transferInts = false;
break;
}

case PNG_COLOR_TYPE_RGB: {
if (bitDepth != 8) {
// awt.3C=Unknown PNG color type
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
}
cm = new DirectColorModel(24, 0xff0000, 0xFF00, 0xFF);
transferInts = true;
break;
}

case PNG_COLOR_TYPE_PLTE: {
if (bitDepth != 8 && bitDepth != 4 && bitDepth != 2 && bitDepth != 1) {
// awt.3C=Unknown PNG color type
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
}

if (cmap == null) {
throw new IllegalStateException("Palette color type is not supported");
}

cm = new IndexColorModel(bitDepth, cmap.length / 3, cmap, 0, false);

transferInts = false;
break;
}

case PNG_COLOR_TYPE_GRAY_ALPHA: {
if (bitDepth != 8) {
// awt.3C=Unknown PNG color type
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
}

cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY),
true, false,
Transparency.TRANSLUCENT,
DataBuffer.TYPE_BYTE);

transferInts = false;
dataElementsPerPixel = 2;
break;
}

case PNG_COLOR_TYPE_RGBA: {
if (bitDepth != 8) {
// awt.3C=Unknown PNG color type
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
}

cm = ColorModel.getRGBdefault();

transferInts = true;
break;
}
default:
// awt.3C=Unknown PNG color type
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
}
return cm;
}
private void sendPixels(int nbOfLinesPerChunk) {
int w = imageWidth;
int h = imageHeight;
int n = 1;
if (nbOfLinesPerChunk > 0 && nbOfLinesPerChunk <= h) {
n = nbOfLinesPerChunk;
}
if (transferInts) {
// Create output buffer
intOut = new int[w * n];
for (int yi = 0; yi < h; yi += n) {
// Last chunk might contain less liness
if (n > 1 && h - yi < n ) {
n = h - yi;
}
bm.getPixels(intOut, 0, w, 0, yi, w, n);
setPixels(0, yi, w, n, model, intOut, 0, w);
}
} else {
// Android bitmaps always store ints (ARGB-8888 direct model)
throw new RuntimeException("Byte transfer not supported");
}
}
}

+ 536
- 0
awt/com/android/internal/awt/AndroidJavaBlitter.java View File

@@ -0,0 +1,536 @@
/*
* Copyright 2007, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.internal.awt;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import org.apache.harmony.awt.gl.MultiRectArea;
import org.apache.harmony.awt.gl.Surface;
import org.apache.harmony.awt.gl.XORComposite;
import org.apache.harmony.awt.gl.render.Blitter;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferInt;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;

public class AndroidJavaBlitter implements Blitter {

private Canvas canvas;
private Paint paint;
private int colorCache;
public AndroidJavaBlitter(Canvas c) {
this.canvas = c;
this.paint = new Paint();
this.paint.setStrokeWidth(1);
}
/**
* Instead of multiplication and division we are using values from
* Lookup tables.
*/
static byte mulLUT[][]; // Lookup table for multiplication
static byte divLUT[][]; // Lookup table for division

static{
mulLUT = new byte[256][256];
for(int i = 0; i < 256; i++){
for(int j = 0; j < 256; j++){
mulLUT[i][j] = (byte)((float)(i * j)/255 + 0.5f);
}
}
divLUT = new byte[256][256];
for(int i = 1; i < 256; i++){
for(int j = 0; j < i; j++){
divLUT[i][j] = (byte)(((float)j / 255) / ((float)i/ 255) * 255 + 0.5f);
}
for(int j = i; j < 256; j++){
divLUT[i][j] = (byte)255;
}
}
}

final static int AlphaCompositeMode = 1;
final static int XORMode = 2;

public void blit(int srcX, int srcY, Surface srcSurf, int dstX, int dstY,
Surface dstSurf, int width, int height, AffineTransform sysxform,
AffineTransform xform, Composite comp, Color bgcolor,
MultiRectArea clip) {
if(xform == null){
blit(srcX, srcY, srcSurf, dstX, dstY, dstSurf, width, height,
sysxform, comp, bgcolor, clip);
}else{
double scaleX = xform.getScaleX();
double scaleY = xform.getScaleY();
double scaledX = dstX / scaleX;
double scaledY = dstY / scaleY;
AffineTransform at = new AffineTransform();
at.setToTranslation(scaledX, scaledY);
xform.concatenate(at);
sysxform.concatenate(xform);
blit(srcX, srcY, srcSurf, 0, 0, dstSurf, width, height,
sysxform, comp, bgcolor, clip);
}

}

public void blit(int srcX, int srcY, Surface srcSurf, int dstX, int dstY,
Surface dstSurf, int width, int height, AffineTransform sysxform,
Composite comp, Color bgcolor, MultiRectArea clip) {
if(sysxform == null) {
sysxform = new AffineTransform();
}
int type = sysxform.getType();
switch(type){
case AffineTransform.TYPE_TRANSLATION:
dstX += sysxform.getTranslateX();
dstY += sysxform.getTranslateY();
case AffineTransform.TYPE_IDENTITY:
simpleBlit(srcX, srcY, srcSurf, dstX, dstY, dstSurf,
width, height, comp, bgcolor, clip);
break;
default:
int srcW = srcSurf.getWidth();
int srcH = srcSurf.getHeight();

int w = srcX + width < srcW ? width : srcW - srcX;
int h = srcY + height < srcH ? height : srcH - srcY;

ColorModel srcCM = srcSurf.getColorModel();
Raster srcR = srcSurf.getRaster().createChild(srcX, srcY,
w, h, 0, 0, null);

ColorModel dstCM = dstSurf.getColorModel();
WritableRaster dstR = dstSurf.getRaster();

transformedBlit(srcCM, srcR, 0, 0, dstCM, dstR, dstX, dstY, w, h,
sysxform, comp, bgcolor, clip);

}
}

public void simpleBlit(int srcX, int srcY, Surface srcSurf, int dstX, int dstY,
Surface dstSurf, int width, int height, Composite comp,
Color bgcolor, MultiRectArea clip) {

// TODO It's possible, though unlikely that we might encounter non-int[]
// data buffers. In this case the following code needs to have several
// branches that take this into account.
data = (DataBufferInt)srcSurf.getRaster().getDataBuffer();
int[] pixels = data.getData();
if (!srcSurf.getColorModel().hasAlpha()) {
// This wouldn't be necessary if Android supported RGB_888.
for (int i = 0; i < pixels.length; i++) {
pixels[i] = pixels[i] | 0xff000000;
}
}
bmap = Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888);
canvas.drawBitmap(bmap, dstX, dstY, paint);
}
public void blit(int srcX, int srcY, Surface srcSurf, int dstX, int dstY,
Surface dstSurf, int width, int height, Composite comp,
Color bgcolor, MultiRectArea clip) {

javaBlt(srcX, srcY, srcSurf.getWidth(), srcSurf.getHeight(),
srcSurf.getColorModel(), srcSurf.getRaster(), dstX, dstY,
dstSurf.getWidth(), dstSurf.getHeight(),
dstSurf.getColorModel(), dstSurf.getRaster(),
width, height, comp, bgcolor, clip);

}
public void javaBlt(int srcX, int srcY, int srcW, int srcH,
ColorModel srcCM, Raster srcRast, int dstX, int dstY,
int dstW, int dstH, ColorModel dstCM, WritableRaster dstRast,
int width, int height, Composite comp, Color bgcolor,
MultiRectArea clip){
int srcX2 = srcW - 1;
int srcY2 = srcH - 1;
int dstX2 = dstW - 1;
int dstY2 = dstH - 1;

if(srcX < 0){
width += srcX;
srcX = 0;
}
if(srcY < 0){
height += srcY;
srcY = 0;
}

if(dstX < 0){
width += dstX;
srcX -= dstX;
dstX = 0;
}
if(dstY < 0){
height += dstY;
srcY -= dstY;
dstY = 0;
}

if(srcX > srcX2 || srcY > srcY2) {
return;
}
if(dstX > dstX2 || dstY > dstY2) {
return;
}

if(srcX + width > srcX2) {
width = srcX2 - srcX + 1;
}
if(srcY + height > srcY2) {
height = srcY2 - srcY + 1;
}
if(dstX + width > dstX2) {
width = dstX2 - dstX + 1;
}
if(dstY + height > dstY2) {
height = dstY2 - dstY + 1;
}

if(width <= 0 || height <= 0) {
return;
}

int clipRects[];
if(clip != null) {
clipRects = clip.rect;
} else {
clipRects = new int[]{5, 0, 0, dstW - 1, dstH - 1};
}

boolean isAlphaComp = false;
int rule = 0;
float alpha = 0;
boolean isXORComp = false;
Color xorcolor = null;
CompositeContext cont = null;

if(comp instanceof AlphaComposite){
isAlphaComp = true;
AlphaComposite ac = (AlphaComposite) comp;
rule = ac.getRule();
alpha = ac.getAlpha();
}else if(comp instanceof XORComposite){
isXORComp = true;
XORComposite xcomp = (XORComposite) comp;
xorcolor = xcomp.getXORColor();
}else{
cont = comp.createContext(srcCM, dstCM, null);
}

for(int i = 1; i < clipRects[0]; i += 4){
int _sx = srcX;
int _sy = srcY;

int _dx = dstX;
int _dy = dstY;

int _w = width;
int _h = height;

int cx = clipRects[i]; // Clipping left top X
int cy = clipRects[i + 1]; // Clipping left top Y
int cx2 = clipRects[i + 2]; // Clipping right bottom X
int cy2 = clipRects[i + 3]; // Clipping right bottom Y

if(_dx > cx2 || _dy > cy2 || dstX2 < cx || dstY2 < cy) {
continue;
}

if(cx > _dx){
int shx = cx - _dx;
_w -= shx;
_dx = cx;
_sx += shx;
}

if(cy > _dy){
int shy = cy - _dy;
_h -= shy;
_dy = cy;
_sy += shy;
}

if(_dx + _w > cx2 + 1){
_w = cx2 - _dx + 1;
}

if(_dy + _h > cy2 + 1){
_h = cy2 - _dy + 1;
}

if(_sx > srcX2 || _sy > srcY2) {
continue;
}

if(isAlphaComp){
alphaCompose(_sx, _sy, srcCM, srcRast, _dx, _dy,
dstCM, dstRast, _w, _h, rule, alpha, bgcolor);
}else if(isXORComp){
xorCompose(_sx, _sy, srcCM, srcRast, _dx, _dy,
dstCM, dstRast, _w, _h, xorcolor);
}else{
Raster sr = srcRast.createChild(_sx, _sy, _w, _h, 0, 0, null);
WritableRaster dr = dstRast.createWritableChild(_dx, _dy,
_w, _h, 0, 0, null);
cont.compose(sr, dr, dr);
}
}
}

DataBufferInt data;
Bitmap bmap, bmp;
void alphaCompose(int srcX, int srcY, ColorModel srcCM, Raster srcRast,
int dstX, int dstY, ColorModel dstCM, WritableRaster dstRast,
int width, int height, int rule, float alpha, Color bgcolor){
Object srcPixel = getTransferArray(srcRast, 1);
data = (DataBufferInt)srcRast.getDataBuffer();
int pix[] = data.getData();
bmap = Bitmap.createBitmap(pix, width, height, Bitmap.Config.RGB_565);
canvas.drawBitmap(bmap, dstX, dstY, paint);
}
void render(int[] img, int x, int y, int width, int height) {
canvas.drawBitmap(Bitmap.createBitmap(img, width, height, Bitmap.Config.ARGB_8888), x, y, paint);
}

void xorCompose(int srcX, int srcY, ColorModel srcCM, Raster srcRast,
int dstX, int dstY, ColorModel dstCM, WritableRaster dstRast,
int width, int height, Color xorcolor){

data = (DataBufferInt)srcRast.getDataBuffer();
int pix[] = data.getData();
bmap = Bitmap.createBitmap(pix, width, height, Bitmap.Config.RGB_565);
canvas.drawBitmap(bmap, dstX, dstY, paint);
}
private void transformedBlit(ColorModel srcCM, Raster srcR, int srcX, int srcY,
ColorModel dstCM, WritableRaster dstR, int dstX, int dstY,
int width, int height, AffineTransform at, Composite comp,
Color bgcolor, MultiRectArea clip) {
data = (DataBufferInt)srcR.getDataBuffer();
int[] pixels = data.getData();
if (!srcCM.hasAlpha()) {
// This wouldn't be necessary if Android supported RGB_888.
for (int i = 0; i < pixels.length; i++) {
pixels[i] = pixels[i] | 0xff000000;
}
}
bmap = Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888);
Matrix tm = new Matrix();
tm.setConcat(canvas.getMatrix(), AndroidGraphics2D.createMatrixObj(at));
if(at.getType() > 1) {
bmp = Bitmap.createBitmap(bmap, 0, 0, width, height, tm, true);
} else {
bmp = Bitmap.createBitmap(bmap, 0, 0, width, height, tm, false);
}
canvas.drawBitmap(bmp, dstX + (float)at.getTranslateX(), dstY + (float)at.getTranslateY(), paint);
}

private Rectangle2D getBounds2D(AffineTransform at, Rectangle r) {
int x = r.x;
int y = r.y;
int width = r.width;
int height = r.height;

float[] corners = {
x, y,
x + width, y,
x + width, y + height,
x, y + height
};

at.transform(corners, 0, corners, 0, 4);

Rectangle2D.Float bounds = new Rectangle2D.Float(corners[0], corners[1], 0 , 0);
bounds.add(corners[2], corners[3]);
bounds.add(corners[4], corners[5]);
bounds.add(corners[6], corners[7]);

return bounds;
}

private int compose(int srcRGB, boolean isSrcAlphaPre,
int dstRGB, boolean dstHasAlpha, boolean isDstAlphaPre,
int rule, int srcConstAlpha){

int sa, sr, sg, sb, da, dr, dg, db;

sa = (srcRGB >> 24) & 0xff;
sr = (srcRGB >> 16) & 0xff;
sg = (srcRGB >> 8) & 0xff;
sb = srcRGB & 0xff;

if(isSrcAlphaPre){
sa = mulLUT[srcConstAlpha][sa] & 0xff;
sr = mulLUT[srcConstAlpha][sr] & 0xff;
sg = mulLUT[srcConstAlpha][sg] & 0xff;
sb = mulLUT[srcConstAlpha][sb] & 0xff;
}else{
sa = mulLUT[srcConstAlpha][sa] & 0xff;
sr = mulLUT[sa][sr] & 0xff;
sg = mulLUT[sa][sg] & 0xff;
sb = mulLUT[sa][sb] & 0xff;
}

da = (dstRGB >> 24) & 0xff;
dr = (dstRGB >> 16) & 0xff;
dg = (dstRGB >> 8) & 0xff;
db = dstRGB & 0xff;

if(!isDstAlphaPre){
dr = mulLUT[da][dr] & 0xff;
dg = mulLUT[da][dg] & 0xff;
db = mulLUT[da][db] & 0xff;
}

int Fs = 0;
int Fd = 0;
switch(rule){
case AlphaComposite.CLEAR:
break;

case AlphaComposite.DST:
Fd = 255;
break;

case AlphaComposite.DST_ATOP:
Fs = 255 - da;
Fd = sa;
break;

case AlphaComposite.DST_IN:
Fd = sa;
break;

case AlphaComposite.DST_OUT:
Fd = 255 - sa;
break;

case AlphaComposite.DST_OVER:
Fs = 255 - da;
Fd = 255;
break;

case AlphaComposite.SRC:
Fs = 255;
break;

case AlphaComposite.SRC_ATOP:
Fs = da;
Fd = 255 - sa;
break;

case AlphaComposite.SRC_IN:
Fs = da;
break;

case AlphaComposite.SRC_OUT:
Fs = 255 - da;
break;

case AlphaComposite.SRC_OVER:
Fs = 255;
Fd = 255 - sa;
break;

case AlphaComposite.XOR:
Fs = 255 - da;
Fd = 255 - sa;
break;
}
dr = (mulLUT[sr][Fs] & 0xff) + (mulLUT[dr][Fd] & 0xff);
dg = (mulLUT[sg][Fs] & 0xff) + (mulLUT[dg][Fd] & 0xff);
db = (mulLUT[sb][Fs] & 0xff) + (mulLUT[db][Fd] & 0xff);

da = (mulLUT[sa][Fs] & 0xff) + (mulLUT[da][Fd] & 0xff);

if(!isDstAlphaPre){
if(da != 255){
dr = divLUT[da][dr] & 0xff;
dg = divLUT[da][dg] & 0xff;
db = divLUT[da][db] & 0xff;
}
}
if(!dstHasAlpha) {
da = 0xff;
}
dstRGB = (da << 24) | (dr << 16) | (dg << 8) | db;

return dstRGB;

}
/**
* Allocate an array that can be use to store the result for a
* Raster.getDataElements call.
* @param raster Raster (type) where the getDataElements call will be made.
* @param nbPixels How many pixels to store in the array at most
* @return the result array or null
*/
private Object getTransferArray(Raster raster, int nbPixels) {
int transferType = raster.getTransferType();
int nbDataElements = raster.getSampleModel().getNumDataElements();
int n = nbDataElements * nbPixels;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
return new byte[n];
case DataBuffer.TYPE_SHORT:
case DataBuffer.TYPE_USHORT:
return new short[n];
case DataBuffer.TYPE_INT:
return new int[n];
case DataBuffer.TYPE_FLOAT:
return new float[n];
case DataBuffer.TYPE_DOUBLE:
return new double[n];
case DataBuffer.TYPE_UNDEFINED:
default:
return null;
}
}
/**
* Draw a pixel
*/
private void dot(int x, int y, int clr) {
if (colorCache != clr) {
paint.setColor(clr);
colorCache = clr;
}
canvas.drawLine(x, y, x + 1, y + 1, paint);
}
}

+ 75
- 0
awt/com/android/internal/awt/AndroidNativeEventQueue.java View File

@@ -0,0 +1,75 @@
/*
* Copyright 2007, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.internal.awt;

import org.apache.harmony.awt.wtk.NativeEventQueue;

public class AndroidNativeEventQueue extends NativeEventQueue {
private Object eventMonitor;
public AndroidNativeEventQueue() {
super();
eventMonitor = getEventMonitor();
}

@Override
public void awake() {
synchronized (eventMonitor) {
eventMonitor.notify();
}
}

@Override
public void dispatchEvent() {
//???AWT
System.out.println(getClass()+": empty method called");
}

@Override
public long getJavaWindow() {
//???AWT
System.out.println(getClass()+": empty method called");
return 0;
}

@Override
public void performLater(Task task) {
//???AWT
System.out.println(getClass()+": empty method called");
}

@Override
public void performTask(Task task) {
//???AWT
System.out.println(getClass()+": empty method called");
}

@Override
public boolean waitEvent() {
while (isEmpty() ) {
synchronized (eventMonitor) {
try {
eventMonitor.wait(1000);
} catch (InterruptedException ignore) {
}
}
}
return false;
}

}

+ 88
- 0
awt/com/android/internal/awt/AndroidWTK.java View File

@@ -0,0 +1,88 @@
/*
* Copyright 2007, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.internal.awt;

import java.awt.GraphicsDevice;

import org.apache.harmony.awt.wtk.CursorFactory;
import org.apache.harmony.awt.wtk.GraphicsFactory;
import org.apache.harmony.awt.wtk.NativeEventQueue;
import org.apache.harmony.awt.wtk.NativeIM;
import org.apache.harmony.awt.wtk.NativeMouseInfo;
import org.apache.harmony.awt.wtk.NativeRobot;
import org.apache.harmony.awt.wtk.SystemProperties;
import org.apache.harmony.awt.wtk.WTK;
import org.apache.harmony.awt.wtk.WindowFactory;

public class AndroidWTK extends WTK {

private AndroidGraphicsFactory mAgf;
private AndroidNativeEventQueue mAneq;
@Override
public CursorFactory getCursorFactory() {
// TODO Auto-generated method stub
return null;
}

@Override
public GraphicsFactory getGraphicsFactory() {
if(mAgf == null) {
mAgf = new AndroidGraphicsFactory();
}
return mAgf;
}

@Override
public NativeEventQueue getNativeEventQueue() {
if(mAneq == null) {
mAneq = new AndroidNativeEventQueue();
}
return mAneq;
}

@Override
public NativeIM getNativeIM() {
// TODO Auto-generated method stub
return null;
}

@Override
public NativeMouseInfo getNativeMouseInfo() {
// TODO Auto-generated method stub
return null;
}

@Override
public NativeRobot getNativeRobot(GraphicsDevice screen) {
// TODO Auto-generated method stub
return null;
}

@Override
public SystemProperties getSystemProperties() {
// TODO Auto-generated method stub
return null;
}

@Override
public WindowFactory getWindowFactory() {
// TODO Auto-generated method stub
return null;
}

}

+ 52
- 0
awt/com/android/internal/awt/AwtFactory.java View File

@@ -0,0 +1,52 @@
/*
* Copyright 2007, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.internal.awt;

import java.awt.Graphics2D;
import java.awt.Toolkit;

import org.apache.harmony.awt.wtk.GraphicsFactory;

import android.graphics.Canvas;
import android.graphics.Paint;

public class AwtFactory {
private static GraphicsFactory gf;
/**
* Use this method to get acces to AWT drawing primitives and to
* render into the surface area of a Android widget. Origin and
* clip of the returned graphics object are the same as in the
* corresponding Android widget.
*
* @param c Canvas of the android widget to draw into
* @param p The default drawing parameters such as font,
* stroke, foreground and background colors, etc.
* @return The AWT Graphics object that makes all AWT
* drawing primitives available in the androind world.
*/
public static Graphics2D getAwtGraphics(Canvas c, Paint p) {
// AWT?? TODO: test it!
if (null == gf) {
Toolkit tk = Toolkit.getDefaultToolkit();
gf = tk.getGraphicsFactory();
}
return gf.getGraphics2D(c, p);
}

}

+ 66
- 0
awt/com/android/internal/awt/ImageOutputStreamWrapper.java View File

@@ -0,0 +1,66 @@
/*
* Copyright 2007, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.internal.awt;

import java.io.IOException;
import java.io.OutputStream;

import javax.imageio.stream.ImageOutputStream;

public class ImageOutputStreamWrapper extends OutputStream {
protected ImageOutputStream mIos;
private byte[] mBuff;
public ImageOutputStreamWrapper(ImageOutputStream ios) {
if (null == ios) {
throw new IllegalArgumentException("ImageOutputStream must not be null");
}
this.mIos = ios;
this.mBuff = new byte[1];
}

public ImageOutputStream getImageOutputStream() {
return mIos;
}
@Override
public void write(int oneByte) throws IOException {
mBuff[0] = (byte)oneByte;
mIos.write(mBuff, 0, 1);
}

public void write(byte[] b) throws IOException {
mIos.write(b, 0, b.length);
}
public void write(byte[] b, int off, int len) throws IOException {
mIos.write(b, off, len);
}
public void flush() throws IOException {
mIos.flush();
}
public void close() throws IOException {
if (mIos == null) {
throw new IOException("Stream already closed");
}
mIos = null;
}
}

+ 681
- 0
awt/java/awt/AWTEvent.java View File

@@ -0,0 +1,681 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @author Dmitry A. Durnev, Michael Danilov
* @version $Revision$
*/

package java.awt;

import java.util.EventObject;
import java.util.Hashtable;
import java.util.EventListener;

import java.awt.event.*;

/**
* The abstract class AWTEvent is the base class for all AWT events. This class
* and its subclasses supersede the original java.awt.Event class.
*
* @since Android 1.0
*/
public abstract class AWTEvent extends EventObject {

/**
* The Constant serialVersionUID.
*/
private static final long serialVersionUID = -1825314779160409405L;

/**
* The Constant COMPONENT_EVENT_MASK indicates the event relates to a
* component.
*/
public static final long COMPONENT_EVENT_MASK = 1;

/**
* The Constant CONTAINER_EVENT_MASK indicates the event relates to a
* container.
*/
public static final long CONTAINER_EVENT_MASK = 2;

/**
* The Constant FOCUS_EVENT_MASK indicates the event relates to the focus.
*/
public static final long FOCUS_EVENT_MASK = 4;

/**
* The Constant KEY_EVENT_MASK indicates the event relates to a key.
*/
public static final long KEY_EVENT_MASK = 8;

/**
* The Constant MOUSE_EVENT_MASK indicates the event relates to the mouse.
*/
public static final long MOUSE_EVENT_MASK = 16;

/**
* The Constant MOUSE_MOTION_EVENT_MASK indicates the event relates to a
* mouse motion.
*/
public static final long MOUSE_MOTION_EVENT_MASK = 32;

/**
* The Constant WINDOW_EVENT_MASK indicates the event relates to a window.
*/
public static final long WINDOW_EVENT_MASK = 64;

/**
* The Constant ACTION_EVENT_MASK indicates the event relates to an action.
*/
public static final long ACTION_EVENT_MASK = 128;

/**
* The Constant ADJUSTMENT_EVENT_MASK indicates the event relates to an
* adjustment.
*/
public static final long ADJUSTMENT_EVENT_MASK = 256;

/**
* The Constant ITEM_EVENT_MASK indicates the event relates to an item.
*/
public static final long ITEM_EVENT_MASK = 512;

/**
* The Constant TEXT_EVENT_MASK indicates the event relates to text.
*/
public static final long TEXT_EVENT_MASK = 1024;

/**
* The Constant INPUT_METHOD_EVENT_MASK indicates the event relates to an
* input method.
*/
public static final long INPUT_METHOD_EVENT_MASK = 2048;

/**
* The Constant PAINT_EVENT_MASK indicates the event relates to a paint
* method.
*/
public static final long PAINT_EVENT_MASK = 8192;

/**
* The Constant INVOCATION_EVENT_MASK indicates the event relates to a
* method invocation.
*/
public static final long INVOCATION_EVENT_MASK = 16384;

/**
* The Constant HIERARCHY_EVENT_MASK indicates the event relates to a
* hierarchy.
*/
public static final long HIERARCHY_EVENT_MASK = 32768;

/**
* The Constant HIERARCHY_BOUNDS_EVENT_MASK indicates the event relates to
* hierarchy bounds.
*/
public static final long HIERARCHY_BOUNDS_EVENT_MASK = 65536;

/**
* The Constant MOUSE_WHEEL_EVENT_MASK indicates the event relates to the
* mouse wheel.
*/
public static final long MOUSE_WHEEL_EVENT_MASK = 131072;

/**
* The Constant WINDOW_STATE_EVENT_MASK indicates the event relates to a
* window state.
*/
public static final long WINDOW_STATE_EVENT_MASK = 262144;

/**
* The Constant WINDOW_FOCUS_EVENT_MASK indicates the event relates to a
* window focus.
*/
public static final long WINDOW_FOCUS_EVENT_MASK = 524288;

/**
* The Constant RESERVED_ID_MAX indicates the maximum value for reserved AWT
* event IDs.
*/
public static final int RESERVED_ID_MAX = 1999;

/**
* The Constant eventsMap.
*/
private static final Hashtable<Integer, EventDescriptor> eventsMap = new Hashtable<Integer, EventDescriptor>();

/**
* The converter.
*/
private static EventConverter converter;

/**
* The ID of the event.
*/
protected int id;

/**
* The consumed indicates whether or not the event is sent back down to the
* peer once the source has processed it (false means it's sent to the peer,
* true means it's not).
*/
protected boolean consumed;

/**
* The dispatched by kfm.
*/
boolean dispatchedByKFM;

/**
* The is posted.
*/
transient boolean isPosted;

static {
eventsMap.put(new Integer(KeyEvent.KEY_TYPED), new EventDescriptor(KEY_EVENT_MASK,
KeyListener.class));
eventsMap.put(new Integer(KeyEvent.KEY_PRESSED), new EventDescriptor(KEY_EVENT_MASK,
KeyListener.class));
eventsMap.put(new Integer(KeyEvent.KEY_RELEASED), new EventDescriptor(KEY_EVENT_MASK,
KeyListener.class));
eventsMap.put(new Integer(MouseEvent.MOUSE_CLICKED), new EventDescriptor(MOUSE_EVENT_MASK,
MouseListener.class));
eventsMap.put(new Integer(MouseEvent.MOUSE_PRESSED), new EventDescriptor(MOUSE_EVENT_MASK,
MouseListener.class));
eventsMap.put(new Integer(MouseEvent.MOUSE_RELEASED), new EventDescriptor(MOUSE_EVENT_MASK,
MouseListener.class));
eventsMap.put(new Integer(MouseEvent.MOUSE_MOVED), new EventDescriptor(
MOUSE_MOTION_EVENT_MASK, MouseMotionListener.class));
eventsMap.put(new Integer(MouseEvent.MOUSE_ENTERED), new EventDescriptor(MOUSE_EVENT_MASK,
MouseListener.class));
eventsMap.put(new Integer(MouseEvent.MOUSE_EXITED), new EventDescriptor(MOUSE_EVENT_MASK,
MouseListener.class));
eventsMap.put(new Integer(MouseEvent.MOUSE_DRAGGED), new EventDescriptor(
MOUSE_MOTION_EVENT_MASK, MouseMotionListener.class));
eventsMap.put(new Integer(MouseEvent.MOUSE_WHEEL), new EventDescriptor(
MOUSE_WHEEL_EVENT_MASK, MouseWheelListener.class));
eventsMap.put(new Integer(ComponentEvent.COMPONENT_MOVED), new EventDescriptor(
COMPONENT_EVENT_MASK, ComponentListener.class));
eventsMap.put(new Integer(ComponentEvent.COMPONENT_RESIZED), new EventDescriptor(
COMPONENT_EVENT_MASK, ComponentListener.class));
eventsMap.put(new Integer(ComponentEvent.COMPONENT_SHOWN), new EventDescriptor(
COMPONENT_EVENT_MASK, ComponentListener.class));
eventsMap.put(new Integer(ComponentEvent.COMPONENT_HIDDEN), new EventDescriptor(
COMPONENT_EVENT_MASK, ComponentListener.class));
eventsMap.put(new Integer(FocusEvent.FOCUS_GAINED), new EventDescriptor(FOCUS_EVENT_MASK,
FocusListener.class));
eventsMap.put(new Integer(FocusEvent.FOCUS_LOST), new EventDescriptor(FOCUS_EVENT_MASK,
FocusListener.class));
eventsMap.put(new Integer(PaintEvent.PAINT), new EventDescriptor(PAINT_EVENT_MASK, null));
eventsMap.put(new Integer(PaintEvent.UPDATE), new EventDescriptor(PAINT_EVENT_MASK, null));
eventsMap.put(new Integer(WindowEvent.WINDOW_OPENED), new EventDescriptor(
WINDOW_EVENT_MASK, WindowListener.class));
eventsMap.put(new Integer(WindowEvent.WINDOW_CLOSING), new EventDescriptor(
WINDOW_EVENT_MASK, WindowListener.class));
eventsMap.put(new Integer(WindowEvent.WINDOW_CLOSED), new EventDescriptor(
WINDOW_EVENT_MASK, WindowListener.class));
eventsMap.put(new Integer(WindowEvent.WINDOW_DEICONIFIED), new EventDescriptor(
WINDOW_EVENT_MASK, WindowListener.class));
eventsMap.put(new Integer(WindowEvent.WINDOW_ICONIFIED), new EventDescriptor(
WINDOW_EVENT_MASK, WindowListener.class));
eventsMap.put(new Integer(WindowEvent.WINDOW_STATE_CHANGED), new EventDescriptor(
WINDOW_STATE_EVENT_MASK, WindowStateListener.class));
eventsMap.put(new Integer(WindowEvent.WINDOW_LOST_FOCUS), new EventDescriptor(
WINDOW_FOCUS_EVENT_MASK, WindowFocusListener.class));
eventsMap.put(new Integer(WindowEvent.WINDOW_GAINED_FOCUS), new EventDescriptor(
WINDOW_FOCUS_EVENT_MASK, WindowFocusListener.class));
eventsMap.put(new Integer(WindowEvent.WINDOW_DEACTIVATED), new EventDescriptor(
WINDOW_EVENT_MASK, WindowListener.class));
eventsMap.put(new Integer(WindowEvent.WINDOW_ACTIVATED), new EventDescriptor(
WINDOW_EVENT_MASK, WindowListener.class));
eventsMap.put(new Integer(HierarchyEvent.HIERARCHY_CHANGED), new EventDescriptor(
HIERARCHY_EVENT_MASK, HierarchyListener.class));
eventsMap.put(new Integer(HierarchyEvent.ANCESTOR_MOVED), new EventDescriptor(
HIERARCHY_BOUNDS_EVENT_MASK, HierarchyBoundsListener.class));
eventsMap.put(new Integer(HierarchyEvent.ANCESTOR_RESIZED), new EventDescriptor(
HIERARCHY_BOUNDS_EVENT_MASK, HierarchyBoundsListener.class));
eventsMap.put(new Integer(ContainerEvent.COMPONENT_ADDED), new EventDescriptor(
CONTAINER_EVENT_MASK, ContainerListener.class));
eventsMap.put(new Integer(ContainerEvent.COMPONENT_REMOVED), new EventDescriptor(
CONTAINER_EVENT_MASK, ContainerListener.class));
eventsMap.put(new Integer(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED), new EventDescriptor(
INPUT_METHOD_EVENT_MASK, InputMethodListener.class));
eventsMap.put(new Integer(InputMethodEvent.CARET_POSITION_CHANGED), new EventDescriptor(
INPUT_METHOD_EVENT_MASK, InputMethodListener.class));
eventsMap.put(new Integer(InvocationEvent.INVOCATION_DEFAULT), new EventDescriptor(
INVOCATION_EVENT_MASK, null));
eventsMap.put(new Integer(ItemEvent.ITEM_STATE_CHANGED), new EventDescriptor(
ITEM_EVENT_MASK, ItemListener.class));
eventsMap.put(new Integer(TextEvent.TEXT_VALUE_CHANGED), new EventDescriptor(
TEXT_EVENT_MASK, TextListener.class));
eventsMap.put(new Integer(ActionEvent.ACTION_PERFORMED), new EventDescriptor(
ACTION_EVENT_MASK, ActionListener.class));
eventsMap.put(new Integer(AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED), new EventDescriptor(
ADJUSTMENT_EVENT_MASK, AdjustmentListener.class));
converter = new EventConverter();
}

/**
* Instantiates a new AWT event from the specified Event object.
*
* @param event
* the Event object.
*/
public AWTEvent(Event event) {
this(event.target, event.id);
}

/**
* Instantiates a new AWT event with the specified object and type.
*
* @param source
* the source Object.
* @param id
* the event's type.
*/
public AWTEvent(Object source, int id) {
super(source);
this.id = id;
consumed = false;
}

/**
* Gets the event's type.
*
* @return the event type ID.
*/
public int getID() {
return id;
}

/**
* Sets a new source for the AWTEvent.
*
* @param newSource
* the new source Object for the AWTEvent.
*/
public void setSource(Object newSource) {
source = newSource;
}

/**
* Returns a String representation of the AWTEvent.
*
* @return the String representation of the AWTEvent.
*/
@Override
public String toString() {
/*
* The format is based on 1.5 release behavior which can be revealed by
* the following code: AWTEvent event = new AWTEvent(new Component(){},
* 1){}; System.out.println(event);
*/
String name = ""; //$NON-NLS-1$

if (source instanceof Component && (source != null)) {
Component comp = (Component)getSource();
name = comp.getName();
if (name == null) {
name = ""; //$NON-NLS-1$
}
}

return (getClass().getName() + "[" + paramString() + "]" //$NON-NLS-1$ //$NON-NLS-2$
+ " on " + (name.length() > 0 ? name : source)); //$NON-NLS-1$
}

/**
* Returns a string representation of the AWTEvent state.
*
* @return a string representation of the AWTEvent state.
*/
public String paramString() {
// nothing to implement: all event types must override this method
return ""; //$NON-NLS-1$
}

/**
* Checks whether or not this AWTEvent has been consumed.
*
* @return true, if this AWTEvent has been consumed, false otherwise.
*/
protected boolean isConsumed() {
return consumed;
}

/**
* Consumes the AWTEvent.
*/
protected void consume() {
consumed = true;
}

/**
* Convert AWTEvent object to a corresponding (deprecated) Event object.
*
* @return new Event object which is a converted AWTEvent object or null if
* the conversion is not possible
*/
Event getEvent() {

if (id == ActionEvent.ACTION_PERFORMED) {
ActionEvent ae = (ActionEvent)this;
return converter.convertActionEvent(ae);

} else if (id == AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED) {
AdjustmentEvent ae = (AdjustmentEvent)this;
return converter.convertAdjustmentEvent(ae);

// ???AWT
// } else if (id == ComponentEvent.COMPONENT_MOVED
// && source instanceof Window) {
// //the only type of Component events is COMPONENT_MOVED on window
// ComponentEvent ce = (ComponentEvent) this;
// return converter.convertComponentEvent(ce);

} else if (id >= FocusEvent.FOCUS_FIRST && id <= FocusEvent.FOCUS_LAST) {
// nothing to convert

// ???AWT
// } else if (id == ItemEvent.ITEM_STATE_CHANGED) {
// ItemEvent ie = (ItemEvent) this;
// return converter.convertItemEvent(ie);

} else if (id == KeyEvent.KEY_PRESSED || id == KeyEvent.KEY_RELEASED) {
KeyEvent ke = (KeyEvent)this;
return converter.convertKeyEvent(ke);
} else if (id >= MouseEvent.MOUSE_FIRST && id <= MouseEvent.MOUSE_LAST) {
MouseEvent me = (MouseEvent)this;
return converter.convertMouseEvent(me);
} else if (id == WindowEvent.WINDOW_CLOSING || id == WindowEvent.WINDOW_ICONIFIED
|| id == WindowEvent.WINDOW_DEICONIFIED) {
// nothing to convert
} else {
return null;
}
return new Event(source, id, null);
}

/**
* The class EventDescriptor.
*/
static final class EventDescriptor {

/**
* The event mask.
*/
final long eventMask;

/**
* The listener type.
*/
final Class<? extends EventListener> listenerType;

/**
* Instantiates a new event descriptor.
*
* @param eventMask
* the event mask.
* @param listenerType
* the listener type.
*/
EventDescriptor(long eventMask, Class<? extends EventListener> listenerType) {
this.eventMask = eventMask;
this.listenerType = listenerType;
}

}

/**
* The class EventTypeLookup.
*/
static final class EventTypeLookup {

/**
* The last event.
*/
private AWTEvent lastEvent = null;

/**
* The last event descriptor.
*/
private EventDescriptor lastEventDescriptor = null;

/**
* Gets the event descriptor.
*
* @param event
* the event.
* @return the event descriptor.
*/
EventDescriptor getEventDescriptor(AWTEvent event) {
synchronized (this) {
if (event != lastEvent) {
lastEvent = event;
lastEventDescriptor = eventsMap.get(new Integer(event.id));
}

return lastEventDescriptor;
}
}

/**
* Gets the event mask.
*
* @param event
* the event.
* @return the event mask.
*/
long getEventMask(AWTEvent event) {
final EventDescriptor ed = getEventDescriptor(event);
return ed == null ? -1 : ed.eventMask;
}
}

/**
* The class EventConverter.
*/
static final class EventConverter {

/**
* The constant OLD_MOD_MASK.
*/
static final int OLD_MOD_MASK = Event.ALT_MASK | Event.CTRL_MASK | Event.META_MASK
| Event.SHIFT_MASK;

/**
* Convert action event.