7 package com.google.appinventor.components.runtime;
9 import android.Manifest;
30 import android.graphics.drawable.Drawable;
31 import android.util.Log;
32 import android.view.View;
33 import android.view.View.OnClickListener;
34 import android.widget.ImageView;
36 import java.io.IOException;
44 @DesignerComponent(version = YaVersion.IMAGE_COMPONENT_VERSION,
45 category = ComponentCategory.USERINTERFACE,
46 description =
"Component for displaying images. The picture to display, " +
47 "and other aspects of the Image's appearance, can be specified in the " +
48 "Designer or in the Blocks Editor.")
50 @UsesPermissions(permissionNames =
"android.permission.INTERNET," +
51 "android.permission.READ_EXTERNAL_STORAGE")
54 private final ImageView view;
56 private String picturePath =
"";
58 private double rotationAngle = 0.0;
62 private boolean clickable =
false;
72 view =
new ImageView(container.
$context()) {
74 public boolean verifyDrawable(Drawable dr) {
75 super.verifyDrawable(dr);
80 view.setFocusable(
true);
91 @
SimpleEvent(description =
"An event that occurs when an image is clicked.")
97 defaultValue =
"False")
98 @
SimpleProperty(description =
"Specifies whether the image should be clickable or not.")
99 public
void Clickable(
boolean clickable) {
100 this.clickable = clickable;
101 view.setClickable(this.clickable);
102 if (this.clickable) {
103 view.setOnClickListener(
new View.OnClickListener() {
105 public void onClick(View v) {
110 view.setOnClickListener(
null);
115 public
boolean Clickable() {
116 return this.clickable;
126 public String Picture() {
144 && container.$form().isDeniedPermission(Manifest.permission.READ_EXTERNAL_STORAGE)) {
145 container.$form().askPermission(Manifest.permission.READ_EXTERNAL_STORAGE,
148 public void HandlePermissionResponse(String permission,
boolean granted) {
152 container.$form().dispatchPermissionDeniedEvent(
Image.this,
"Picture", permission);
158 picturePath = (path ==
null) ?
"" : path;
163 }
catch (IOException ioe) {
164 Log.e(
"Image",
"Unable to load " + picturePath);
177 defaultValue =
"0.0")
180 if (this.rotationAngle == rotationAngle) {
186 container.$form().dispatchErrorOccurredEvent(
this,
"RotationAngle",
191 this.rotationAngle = rotationAngle;
194 @
SimpleProperty(description =
"The angle at which the image picture appears rotated. " +
195 "This rotation does not appear on the designer screen, only on the device.",
197 public
double RotationAngle() {
198 return rotationAngle;
202 defaultValue =
"False")
204 @
SimpleProperty(description =
"Specifies whether the image should be resized to match the size of the ImageView.")
205 public
void ScalePictureToFit(
boolean scale) {
207 view.setScaleType(ImageView.ScaleType.FIT_XY);
209 view.setScaleType(ImageView.ScaleType.FIT_CENTER);
221 @
SimpleProperty(description =
"This is a limited form of animation that can attach " +
222 "a small number of motion types to images. The allowable motions are " +
223 "ScrollRightSlow, ScrollRight, ScrollRightFast, ScrollLeftSlow, ScrollLeft, " +
224 "ScrollLeftFast, and Stop",
229 public
void Animation(String animation) {
236 @
SimpleProperty(description =
"This property determines how the picture " +
237 "scales according to the Height or Width of the Image. Scale " +
238 "proportionally (0) preserves the picture aspect ratio. Scale to fit " +
239 "(1) matches the Image area, even if the aspect ratio changes.")
240 public
void Scaling(
int mode) {
243 view.setScaleType(ImageView.ScaleType.FIT_CENTER);
246 view.setScaleType(ImageView.ScaleType.FIT_XY);