示例#1
0
  // Resize a bitmap proportionally  (shrink or enlarge) to make it fit a maxX x maxY rectangle
  public static Bitmap getFitBitmapImage(String imagename, int maxX, int maxY) {

    EncodedImage image = EncodedImage.getEncodedImageResource(imagename);

    int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
    int currentHeightFixed32 = Fixed32.toFP(image.getHeight());

    // double ratio = (double)ratioX / (double) ratioY;
    double rx = (double) image.getWidth() / (double) maxX;
    double ry = (double) image.getHeight() / (double) maxY;
    double r = 0;
    if (rx > ry) r = rx;
    else r = ry;
    double w = (double) image.getWidth() / r;
    double h = (double) image.getHeight() / r;

    int width = (int) w;
    int height = (int) h;

    int requiredWidthFixed32 = Fixed32.toFP(width);
    int requiredHeightFixed32 = Fixed32.toFP(height);

    int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
    int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);

    image = image.scaleImage32(scaleXFixed32, scaleYFixed32);

    return image.getBitmap();
  }
示例#2
0
 public BitmapField WriteSimpleImage(
     Manager parent, String resource, long style, int size, String listener) {
   EncodedImage ei = EncodedImage.getEncodedImageResource(resource);
   EncodedImage ei2 = getScaledImage(ei, size);
   BitmapField fImg = new BitmapField(ei2.getBitmap(), style);
   parent.add(fImg);
   return fImg;
 }
  public Bitmap scaleImage(EncodedImage encodedImage, int requiredWidth, int requiredHeight) {
    int currentWidth = Fixed32.toFP(encodedImage.getWidth());
    int currentHeight = Fixed32.toFP(encodedImage.getHeight());

    int scaleXFixed32 = Fixed32.div(currentWidth, requiredWidth);
    int scaleYFixed32 = Fixed32.div(currentHeight, requiredHeight);

    EncodedImage image = encodedImage.scaleImage32(scaleXFixed32, scaleYFixed32);

    return image.getBitmap();
  }
示例#4
0
  // Resize a bitmap proportionally (shrink or enlarge) by a  ratio factor
  public static Bitmap getScaledBitmapImage(String imagename, double ratio) {

    EncodedImage image = EncodedImage.getEncodedImageResource(imagename);

    int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
    int currentHeightFixed32 = Fixed32.toFP(image.getHeight());

    double w = (double) image.getWidth() * ratio;
    double h = (double) image.getHeight() * ratio;
    int width = (int) w;
    int height = (int) h;

    int requiredWidthFixed32 = Fixed32.toFP(width);
    int requiredHeightFixed32 = Fixed32.toFP(height);

    int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
    int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);

    image = image.scaleImage32(scaleXFixed32, scaleYFixed32);

    return image.getBitmap();
  }
示例#5
0
  public Manager mainScreen(Manager parent) {
    CInterface ci = new CInterface();
    final int columnHeight0 = (int) ((Display.getHeight() / 2));
    final int columnHeight1 = (int) (Display.getHeight() / 2);
    final int btnw = (int) ((float) Display.getWidth() * .75);
    final EncodedImage buttonoff =
        ci.getScaledImage(EncodedImage.getEncodedImageResource(button), btnw);
    final EncodedImage buttonon =
        ci.getScaledImage(EncodedImage.getEncodedImageResource(button_on), btnw);
    final EncodedImage friendsoff =
        ci.getScaledImage(EncodedImage.getEncodedImageResource(friends), btnw);
    final EncodedImage friendson =
        ci.getScaledImage(EncodedImage.getEncodedImageResource(friends_on), btnw);
    int imagew = (int) ((float) Display.getWidth() * .75);
    Bitmap blankbmp = Bitmap.getBitmapResource(blank);

    VerticalFieldManager fm_MainHolder =
        new VerticalFieldManager(
            Manager.USE_ALL_WIDTH
                | Manager.USE_ALL_HEIGHT
                | Manager.NO_HORIZONTAL_SCROLL
                | Manager.NO_VERTICAL_SCROLL) {
          public int getPreferredWidth() {
            return Display.getWidth();
          }

          public int getPreferredHeight() {
            return Display.getHeight();
          }

          protected void sublayout(int width, int height) {
            width = getPreferredWidth();
            height = getPreferredHeight();
            super.sublayout(width, height);
            super.setExtent(width, height);
          }
        };
    Background back = bkg_main;
    fm_MainHolder.setBackground(back);

    // MAIN LOGO
    HorizontalFieldManager lgo =
        new HorizontalFieldManager(
            Manager.NO_VERTICAL_SCROLL
                | Manager.NO_HORIZONTAL_SCROLL
                | Manager.FIELD_HCENTER
                | Manager.FIELD_VCENTER
                | Manager.USE_ALL_WIDTH) {
          public int getPreferredHeight() {
            return columnHeight0;
          }

          protected void sublayout(int width, int height) {
            width = super.getPreferredWidth();
            height = getPreferredHeight();
            super.sublayout(width, height);
            super.setExtent(width, height);
          }
        };
    BitmapField img =
        ci.WriteSimpleImage(
            lgo, logo, BitmapField.FIELD_VCENTER | BitmapField.FIELD_HCENTER, imagew, "");
    fm_MainHolder.add(lgo);

    // BUTTON HOLDER
    VerticalFieldManager vfmButton =
        new VerticalFieldManager(
            Manager.FIELD_HCENTER | Manager.FIELD_VCENTER | Manager.USE_ALL_WIDTH) {
          public int getPreferredHeight() {
            return columnHeight1;
          }

          public int getPreferredWidth() {
            return Display.getWidth();
          }

          protected void sublayout(int width, int height) {
            width = getPreferredWidth();
            height = getPreferredHeight();
            super.sublayout(width, height);
            super.setExtent(width, height);
          }
        };

    final BitmapField bmFieldSpan = new BitmapField(blankbmp, BitmapField.NON_FOCUSABLE);

    CustomButtonField cbfFriends =
        new CustomButtonField(
            btnw,
            strings.getString("invite_friends"),
            friendsoff.getBitmap(),
            friendson.getBitmap(),
            Field.FOCUSABLE | Field.FIELD_HCENTER | Field.FIELD_VCENTER) {
          protected boolean navigationClick(int status, int time) {
            c.action_callback("web_friends", "", "");
            return true;
          }
        };

    CustomButtonField cbfButton =
        new CustomButtonField(
            btnw,
            strings.getString("read_qr"),
            buttonoff.getBitmap(),
            buttonon.getBitmap(),
            Field.FOCUSABLE | Field.FIELD_HCENTER | Field.FIELD_VCENTER) {
          protected boolean navigationClick(int status, int time) {
            c.action_callback("qr_start", "", "");
            return true;
          }
        };

    vfmButton.add(cbfButton);
    vfmButton.add(bmFieldSpan);
    vfmButton.add(cbfFriends);
    fm_MainHolder.add(vfmButton);

    parent.add(fm_MainHolder);
    return fm_MainHolder;
  }
  public void run() {
    if (URL != null && URL.length() > 0) {
      ConnectionFactory f = new ConnectionFactory();
      ConnectionDescriptor descr = f.getConnection(URL);
      String targetURL;
      targetURL = descr.getUrl();
      HttpConnection httpConnection = null;
      DataOutputStream httpDataOutput = null;
      InputStream httpInput = null;
      int rc;

      try {
        httpConnection = (HttpConnection) Connector.open(targetURL);
        rc = httpConnection.getResponseCode();
        if (rc != HttpConnection.HTTP_OK) {
          throw new IOException("HTTP response code: " + rc);
        }
        httpInput = httpConnection.openInputStream();
        InputStream inp = httpInput;
        byte[] b = IOUtilities.streamToBytes(inp);
        final EncodedImage hai = EncodedImage.createEncodedImage(b, 0, b.length);
        final Bitmap bmp = hai.getBitmap();
        System.out.println(bmp.toString());

        if (target != null) {
          UiApplication.getUiApplication()
              .invokeLater(
                  new Runnable() {

                    public void run() {
                      // TODO Auto-generated method stub
                      if (isDetailEvent == true) {
                        target.setBitmap(
                            DisplayHelper.CreateScaledCopyKeepAspectRatio(
                                bmp,
                                (int) (Display.getWidth() * 0.7),
                                (int) (Display.getHeight() * 0.3)));
                      } else {
                        target.setBitmap(
                            DisplayHelper.CreateScaledCopyKeepAspectRatio(
                                bmp, target.getBitmapWidth(), target.getBitmapHeight()));
                      }
                    }
                  });
        }

        if (localPath != null) {
          Utils.saveBitmap(localPath, bmp);
        }

        if (imageCache != null) {
          if (Utils.saveBitmap(
              ImageCacheModel.getImageCacheDirectory() + imageCache.getFileName(), bmp)) {
            //		    		   CacheUtils.getInstance().addImageCache(imageCache);
            System.out.println("image write success");
          }
        }

        if (callback != null) callback.onImageDownloaded(true, bmp);

      } catch (Exception ex) {
        System.out.println("URL Bitmap Error........" + ex.getMessage());
      } finally {
        try {
          if (httpInput != null) httpInput.close();
          if (httpDataOutput != null) httpDataOutput.close();
          if (httpConnection != null) httpConnection.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
示例#7
0
 public void DownloadedImage(EncodedImage ei, BitmapField fImg, int wsize) {
   ei = getScaledImage(ei, wsize);
   synchronized (UiApplication.getEventLock()) {
     fImg.setBitmap(ei.getBitmap());
   }
 }
示例#8
0
 public void DownloadedImage(EncodedImage ei, BitmapField fImg) {
   synchronized (UiApplication.getEventLock()) {
     fImg.setBitmap(ei.getBitmap());
   }
 }