@Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    Log.e("TAG", "---requestCode-" + requestCode + "---resultCode--" + resultCode);
    // 根据选择完毕的图片返回值,直接上传文件
    if (requestCode == 1) { // 拍照
      String localStrPath = photoFile.getPath();
      byte[] compressBitmap = BitmapUtils.compressBitmap(480 * 480, localStrPath);
      if (null != compressBitmap) {
        Bitmap bmPhoto = BitmapUtils.Bytes2Bimap(compressBitmap);
        if (null != bmPhoto) {
          String strTempPhotoPath;
          try {
            strTempPhotoPath = BitmapUtils.saveFile(bmPhoto, UUID.randomUUID() + ".jpeg");
            if (bmPhoto != null) {
              bmPhoto.recycle();
              bmPhoto = null;
            }
            if (null != strTempPhotoPath && !"".equals(strTempPhotoPath)) {
              localStrPath = strTempPhotoPath;
            }
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
        localStrPath = "file://" + localStrPath;
        Uri pathUri = Uri.parse(localStrPath);
        mUploadHandler.post(new MyRunnable(pathUri));
      }
    }
  }
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.userinfo_page);
    String fqToken = new Values(this).getSavedAccessToken();

    /*
     *  Get the user info
     */
    String userURL = "https://api.foursquare.com/v2/users/self?oauth_token=" + fqToken;
    Log.d(LOGTAG, "The request url is " + userURL);
    HttpGet request = new HttpGet(userURL);
    DefaultHttpClient client = new DefaultHttpClient();

    try {
      HttpResponse resp = client.execute(request);
      int responseCode = resp.getStatusLine().getStatusCode();
      Log.d(LOGTAG, "Reponse code: " + responseCode);
      if (responseCode >= 200 && responseCode < 300) {
        String response = responseToString(resp);
        JSONObject jsonObj = new JSONObject(response);
        String name =
            jsonObj.getJSONObject("response").getJSONObject("user").getString("firstName")
                + " "
                + jsonObj.getJSONObject("response").getJSONObject("user").getString("lastName");

        ImageView photo = (ImageView) findViewById(R.id.userPhoto);
        String photoUrl =
            jsonObj.getJSONObject("response").getJSONObject("user").getString("photo");

        TextView tvLastSeen = (TextView) findViewById(R.id.userLastSeen);

        JSONArray menuitemArray =
            jsonObj
                .getJSONObject("response")
                .getJSONObject("user")
                .getJSONObject("checkins")
                .getJSONArray("items");
        String venueName = menuitemArray.getJSONObject(0).getJSONObject("venue").getString("name");
        TextView tvName = (TextView) findViewById(R.id.userName);
        tvName.setText(name);
        tvLastSeen.setText(venueName);
        photo.setImageBitmap(BitmapUtils.loadBitmap(photoUrl));
      }

      Button btnFQLogout = (Button) findViewById(R.id.btnLogoutFQ);
      btnFQLogout.setOnClickListener(
          new OnClickListener() {
            public void onClick(View v) {
              new FQOAuth2(v.getContext()).removeSavedAccessToken();
              finish();
            }
          });
    } catch (ClientProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
  public Recipe getRecipe(String name) {
    Log.d(TAG, "getRecipe Name: " + name);

    SQLiteDatabase db = getReadableDatabase();

    String statment =
        "SELECT * FROM " + TABLE_RECIPES + " WHERE " + RECIPE_COL_NAME + "='" + name + "';";

    Cursor cursor = db.rawQuery(statment, null);

    if (cursor.isAfterLast()) {
      return null;
    }
    cursor.moveToFirst();
    Recipe recipe =
        new Recipe(
            name,
            null,
            cursor.getString(1),
            cursor.getString(2),
            BitmapUtils.StringToBitMap(cursor.getString(3)));
    cursor.close();
    ArrayList<Ingredient> list = getRecipeIngredients(name);
    recipe.setIngredientList(list);

    return recipe;
  }
  // This rounds corners of image as well as textview and darkens latters background
  public void updateImage(Bitmap image) {

    LayoutParams params = new LayoutParams(width, LayoutParams.WRAP_CONTENT);

    setLayoutParams(params);

    // Image
    Bitmap bm;
    bm = BitmapUtils.getRoundedCornerBitmap(ctx, image, 0);
    mContentView.setImageBitmap(bm);

    // TextView background
    mTextView = (TextView) findViewById(R.id.mit150CorridorTV);
    bm = BitmapUtils.createRoundedBottomBitmap(ctx, width, 50, color);
    BitmapDrawable bd = new BitmapDrawable(bm);
    mTextView.setBackgroundDrawable(bd);
  }
Пример #5
0
 public Bitmap getBitmap() {
   if (bitmap == null) {
     try {
       bitmap = BitmapUtils.revisionImageSize(imagePath);
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   return bitmap;
 }
 public long insertCategory(String name, String categoryFather, Bitmap picture) {
   Log.d(TAG, "insertCategory Name: " + name);
   SQLiteDatabase db = getWritableDatabase();
   ContentValues values = new ContentValues();
   values.put(CAT_COL_NAME, name);
   values.put(CAT_COL_CATEGORY_FATHER, categoryFather);
   values.put(CAT_COL_PICTURE, BitmapUtils.BitMapToString(picture));
   long id = db.insertOrThrow(TABLE_CATEGORIES, null, values);
   return id;
 }
 public long insertRecipe(
     String name, String instructions, String categoryFather, Bitmap picture) {
   Log.d(TAG, "insertRecipe Name: " + name);
   SQLiteDatabase db = getWritableDatabase();
   ContentValues values = new ContentValues();
   values.put(RECIPE_COL_NAME, name);
   values.put(RECIPE_COL_INSTRUCTIONS, instructions);
   values.put(RECIPE_COL_CATEGORY_FATHER, categoryFather);
   new FreeMemory().run();
   values.put(RECIPE_COL_PICTURE, BitmapUtils.BitMapToString(picture));
   long id = db.insertOrThrow(TABLE_RECIPES, null, values);
   return id;
 }
  public ArrayList<Category> getCategoriesByFather(String parentCategory) {
    Log.d(TAG, "getCategoriesByFather parentCategory: " + parentCategory);

    ArrayList<Category> list = new ArrayList<>();
    SQLiteDatabase db = getReadableDatabase();
    String stament =
        "SELECT * FROM "
            + TABLE_CATEGORIES
            + " WHERE "
            + CAT_COL_CATEGORY_FATHER
            + "='"
            + parentCategory
            + "' ORDER BY "
            + CAT_COL_NAME
            + " ASC ;";
    String altStament =
        "SELECT * FROM "
            + TABLE_CATEGORIES
            + " WHERE "
            + CAT_COL_CATEGORY_FATHER
            + " IS NULL "
            + "ORDER BY "
            + CAT_COL_NAME
            + " ASC ;";

    Cursor cursor;
    if (parentCategory == null) {
      cursor = db.rawQuery(altStament, null);
    } else {
      cursor = db.rawQuery(stament, null);
    }

    if (cursor.isAfterLast()) {
      return null;
    }

    while (cursor.moveToNext()) {
      Category category =
          new Category(
              cursor.getString(0),
              BitmapUtils.StringToBitMap(cursor.getString(2)),
              cursor.getString(1),
              "");
      list.add(category);
    }
    cursor.close();

    return list;
  }
  @Override
  public void draw(Canvas canvas) {
    String file = getEnvObject().getCurrentRepresentation().getIcon();
    Path objectPath =
        DrawingUtils.freedomPolygonToPath(
            (FreedomPolygon) getEnvObject().getCurrentRepresentation().getShape());
    RectF box = new RectF();
    objectPath.computeBounds(box, true);
    System.out.print("GPT box: box widht:" + box.width() + " box heigh" + box.height());
    drawingMatrix = new Matrix();
    float rotation = (float) getEnvObject().getCurrentRepresentation().getRotation();
    drawingMatrix.postRotate(rotation);
    drawingMatrix.postTranslate(
        getEnvObject().getCurrentRepresentation().getOffset().getX(),
        getEnvObject().getCurrentRepresentation().getOffset().getY());
    Bitmap bmp = null;
    if (file != null) { // TODO: Asign the bmp in the setEnvObject
      bmp = BitmapUtils.getImage(file, (int) box.width(), (int) box.height());
    }
    if (bmp != null) {
      ghostBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.ARGB_8888);
      canvas.drawBitmap(bmp, drawingMatrix, null);

    } else {
      // TODO: Cache path
      Paint paint = new Paint();
      paint.setStyle(Style.FILL);

      ghostPath = new Path();
      objectPath.transform(drawingMatrix, ghostPath);
      int fillColor = -1;
      try {
        fillColor = Color.parseColor(getEnvObject().getCurrentRepresentation().getFillColor());
        paint.setColor(fillColor);
        canvas.drawPath(ghostPath, paint);
      } catch (IllegalArgumentException ex) {
        System.out.println("ParseColor exception in fill");
      }
      int borderColor = -1;
      try {
        borderColor = Color.parseColor(getEnvObject().getCurrentRepresentation().getBorderColor());
        paint.setColor(borderColor);
        paint.setStyle(Style.STROKE);
        canvas.drawPath(ghostPath, paint);
      } catch (IllegalArgumentException ex) {
        System.out.println("ParseColor exception in border");
      }
    }
  }
Пример #10
0
  private void onImageTaken(Bitmap pBitmap) {
    if (pBitmap == null) {
      Toast.makeText(this, "image decode error", Toast.LENGTH_LONG).show();
      return;
    }
    DisplayMetrics dm = getResources().getDisplayMetrics();

    int width = dm.widthPixels;
    int height = pBitmap.getHeight() * dm.widthPixels / pBitmap.getWidth();

    ImageView imageView = new ImageView(this);
    imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(width, height));
    imageView.setImageBitmap(BitmapUtils.resizeBitmap(pBitmap, width, height));

    imageLayout.addView(imageView);
  }
Пример #11
0
  public Category getCategory(String name) {
    Log.d(TAG, "getCategory Name: " + name);
    SQLiteDatabase db = getReadableDatabase();
    String stament =
        "SELECT * FROM " + TABLE_CATEGORIES + " WHERE " + CAT_COL_NAME + "='" + name + "';";

    Cursor cursor = db.rawQuery(stament, null);

    if (cursor.isAfterLast()) {
      return null;
    }
    cursor.moveToFirst();
    Category category =
        new Category(
            cursor.getString(0),
            BitmapUtils.StringToBitMap(cursor.getString(2)),
            cursor.getString(1),
            "");
    return category;
  }
Пример #12
0
 private Bitmap getDrawable(int resId) {
   BitmapFactory.Options options = new BitmapFactory.Options();
   options.inScaled = false;
   return BitmapUtils.decodeResource(getContext(), resId, options);
 }