BitmapView.java revision 9c6ac19d4a3d39b7c2992060957920118ff56a65
1/* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.example.bitmapsample; 18 19import android.content.Context; 20import android.util.AttributeSet; 21 22import com.android.bitmap.drawable.BasicBitmapDrawable; 23import com.android.bitmap.view.BitmapDrawableImageView; 24 25public class BitmapView extends BitmapDrawableImageView { 26 private float mDensity; 27 28 public BitmapView(Context c) { 29 this(c, null); 30 } 31 32 public BitmapView(Context c, AttributeSet attrs) { 33 super(c, attrs); 34 mDensity = getResources().getDisplayMetrics().density; 35 } 36 37 @Override 38 protected int getSuggestedMinimumHeight() { 39 return (int) (100 * mDensity); 40 } 41 42 @Override 43 protected void onSizeChanged(final int w, final int h, int oldw, int oldh) { 44 getBasicBitmapDrawable().setDecodeDimensions(w, h); 45 } 46}