Android Open Source - BrokenDisplay My Image View






From Project

Back to project page BrokenDisplay.

License

The source code is released under:

Apache License

If you think the Android project BrokenDisplay listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.foolish.brokendisplay;
//from   w  w w .  j a  v a  2s  . co m
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Surface;
import android.widget.ImageView;

public class MyImageView extends ImageView {

  private Bitmap mSource;

  public MyImageView(Context context) {
    super(context);
    init();
  }

  private MyImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
  }

  private MyImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
  }

  private void init() {
    mSource = BitmapFactory.decodeResource(getResources(),
        R.drawable.glass_test);
  }

  public int dpToPx(int dp) {
    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    int px = Math.round(dp
        * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;
  }

  @Override
  protected void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    int rotation = getDisplay().getRotation();

    int angle = 0;
    switch (rotation) {
    case Surface.ROTATION_90:
      angle = -90;
      break;
    case Surface.ROTATION_180:
      angle = 180;
      break;
    case Surface.ROTATION_270:
      angle = 90;
      break;
    default:
      angle = 0;
      break;
    }

    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    Bitmap bmp = Bitmap.createBitmap(mSource, 0, 0, mSource.getWidth(),
        mSource.getHeight(), matrix, true);
    setImageBitmap(bmp);
  }

}




Java Source Code List

com.foolish.brokendisplay.BrokenDisplayActivity.java
com.foolish.brokendisplay.BrokenGlassService.java
com.foolish.brokendisplay.ItemDetailActivity.java
com.foolish.brokendisplay.ItemDetailFragment.java
com.foolish.brokendisplay.ItemListActivity.java
com.foolish.brokendisplay.ItemListFragment.java
com.foolish.brokendisplay.MyImageView.java
com.foolish.brokendisplay.OnSwipeTouchListener.java
com.foolish.brokendisplay.OverlayEditorActivity.java
com.foolish.brokendisplay.OverlayEditorFragment.java
com.foolish.brokendisplay.OverviewFragment.java
com.foolish.brokendisplay.dummy.DummyContent.java
com.foolish.brokendisplay.picturedialog.BitmapWorkerTask.java
com.foolish.brokendisplay.picturedialog.IOnSelectPictureDialog.java
com.foolish.brokendisplay.picturedialog.Picture_GridAdapter.java
com.foolish.brokendisplay.picturedialog.SelectPictureDialog.java