Exemplo n.º 1
0
  public void scaleView() {
    // instantiate the views
    View top_view = findViewById(R.id.topView);
    View bottom_view = findViewById(R.id.bottomView);
    LinearLayout footer = (LinearLayout) findViewById(R.id.llFooter);
    LinearLayout crop_frame = (LinearLayout) findViewById(R.id.llCropFrame);
    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();

    // 90% of width
    crop_container_size = (int) ((float) width * (1f - (10f / 100f)));

    // 10% margins
    float margin = ((float) width * (1f - (90f / 100f)));

    // Parameters for white crop border
    LinearLayout.LayoutParams par =
        new LinearLayout.LayoutParams(crop_container_size, crop_container_size);
    par.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
    par.setMargins((int) (margin / 2f), 0, (int) (margin / 2f), 0);
    crop_frame.setLayoutParams(par);

    // Margins for other transparent views
    float top_view_height =
        ((float) (height - crop_container_size - footer.getHeight())) / (float) 2;
    top_view.setLayoutParams(
        new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) top_view_height));
    bottom_view.setLayoutParams(
        new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) top_view_height));

    // Image container
    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(crop_container_size, crop_container_size);
    params.setMargins((int) (margin / 2f), (int) top_view_height, (int) (margin / 2f), 0);
    mImageView.setLayoutParams(params);
    mImageView.setImageBitmap(mBitmap);
    mImageView.setMaxZoom(4f);
  }
Exemplo n.º 2
0
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    String pManufacturer = android.os.Build.MANUFACTURER;
    String pModel = android.os.Build.MODEL;

    if ("GT-I9300".equals(pModel) && "samsung".equals(pManufacturer)) {

      RelativeLayout main = (RelativeLayout) findViewById(R.id.relativeLayout_main);
      main.invalidate();

      setContentView(R.layout.activity_camera_crop);

      mImageView = (CroppedImageView) findViewById(R.id.ivCameraCropPhoto);
      mImageView.setDrawingCacheEnabled(true);

      scaleView();

      // Cancel button
      findViewById(R.id.btnCameraCancel)
          .setOnClickListener(
              new OnClickListener() {

                @Override
                public void onClick(View v) {

                  finish();
                  if (getIntent().getStringExtra("type").equals("gallery")) {
                    Intent intent = new Intent(CameraCropActivity.this, CameraCropActivity.class);
                    intent.putExtra("type", "gallery");
                    startActivity(intent);
                  } else {
                    Intent intent = new Intent(CameraCropActivity.this, CameraCropActivity.class);
                    intent.putExtra("type", "camera");
                    startActivity(intent);
                  }
                }
              });

      // Next button
      findViewById(R.id.btnCameraOk)
          .setOnClickListener(
              new OnClickListener() {

                @Override
                public void onClick(View v) {
                  Bitmap resizedBitmap = getBitmapFromView(mImageView);

                  ByteArrayOutputStream bs = new ByteArrayOutputStream();
                  resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bs);

                  if (saveBitmapToFile(resizedBitmap, mFilePath) == true) {

                    if (mForProfile == true) {
                      MyProfileActivity.gProfileImage = getBitmapFromView(mImageView);
                      MyProfileActivity.gProfileImagePath = mFilePath;
                    } else if (mForGroup == true) {
                      CreateGroupActivity.gGroupImage = getBitmapFromView(mImageView);
                      CreateGroupActivity.gGroupImagePath = mFilePath;
                    } else if (mForGroupUpdate == true) {
                      GroupProfileActivity.gGroupImage = getBitmapFromView(mImageView);
                      GroupProfileActivity.gGroupImagePath = mFilePath;
                    } else {
                      fileUploadAsync(mFilePath);

                      //									new FileUploadAsync(CameraCropActivity.this)
                      //											.execute(mFilePath);
                      // new
                      // SendMessageAsync(getApplicationContext(),
                      // SendMessageAsync.TYPE_PHOTO)
                      // .execute(resizedBitmap);
                    }
                  } else {
                    Toast.makeText(
                            CameraCropActivity.this, "Failed to send photo", Toast.LENGTH_LONG)
                        .show();
                  }
                }
              });

      File file = new File(_path);
      boolean exists = file.exists();
      if (exists) onPhotoTaken(_path);
      else
        Toast.makeText(
                getBaseContext(),
                "Something went wrong while taking picture, please try again.",
                Toast.LENGTH_SHORT)
            .show();
    }
  }
Exemplo n.º 3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera_crop);

    getImageIntents();
    mImageView = (CroppedImageView) findViewById(R.id.ivCameraCropPhoto);
    mImageView.setDrawingCacheEnabled(true);

    return_flag = false;

    Button btnBack = (Button) findViewById(R.id.btnBack);
    btnBack.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            finish();
          }
        });

    // Cancel button
    findViewById(R.id.btnCameraCancel)
        .setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                finish();
                if (getIntent().getStringExtra("type").equals("gallery")) {
                  Intent intent = new Intent(CameraCropActivity.this, CameraCropActivity.class);
                  intent.putExtra("type", "gallery");
                  startActivity(intent);
                } else {
                  Intent intent = new Intent(CameraCropActivity.this, CameraCropActivity.class);
                  intent.putExtra("type", "camera");
                  startActivity(intent);
                }
              }
            });

    // Next button
    findViewById(R.id.btnCameraOk)
        .setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                Bitmap resizedBitmap = getBitmapFromView(mImageView);
                ByteArrayOutputStream bs = new ByteArrayOutputStream();
                resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bs);

                if (saveBitmapToFile(resizedBitmap, mFilePath) == true) {

                  if (mForProfile == true) {
                    MyProfileActivity.gProfileImage = getBitmapFromView(mImageView);
                    MyProfileActivity.gProfileImagePath = mFilePath;
                    finish();
                  } else if (mForGroup == true) {
                    CreateGroupActivity.gGroupImage = getBitmapFromView(mImageView);
                    CreateGroupActivity.gGroupImagePath = mFilePath;
                    finish();
                  } else if (mForGroupUpdate == true) {
                    GroupProfileActivity.gGroupImage = getBitmapFromView(mImageView);
                    GroupProfileActivity.gGroupImagePath = mFilePath;
                    finish();
                  } else {
                    fileUploadAsync(mFilePath);

                    //								new FileUploadAsync(CameraCropActivity.this)
                    //										.execute(mFilePath);
                    // new SendMessageAsync(getApplicationContext(),
                    // SendMessageAsync.TYPE_PHOTO)
                    // .execute(resizedBitmap);
                  }

                } else {
                  Toast.makeText(CameraCropActivity.this, "Failed to send photo", Toast.LENGTH_LONG)
                      .show();
                }
              }
            });
  }