Advertisement
Guest User

FragmentImageView

a guest
Jan 2nd, 2015
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 KB | None | 0 0
  1. package com.anesthetize.deliveryappl;
  2.  
  3.  
  4. import android.app.ProgressDialog;
  5. import android.graphics.Bitmap;
  6. import android.graphics.BitmapFactory;
  7. import android.os.Bundle;
  8. import android.support.v4.app.Fragment;
  9. import android.view.LayoutInflater;
  10. import android.view.View;
  11. import android.view.View.OnClickListener;
  12. import android.view.animation.Animation;
  13. import android.view.animation.AnimationUtils;
  14. import android.view.ViewGroup;
  15. import android.widget.Button;
  16. import android.widget.ImageView;
  17.  
  18. public class FragmentImageView extends Fragment {
  19.  
  20.     private Integer itemData;
  21.     private Bitmap myBitmap;
  22.     public ProgressDialog pd;
  23.     private ImageView ivImage;
  24.     public Button btn_register;  //we define the button in the fragment so that it is bound to the page!
  25.  
  26.  
  27.    
  28.    
  29.     //constructor
  30.     public static FragmentImageView newInstance() {
  31.         FragmentImageView f = new FragmentImageView();
  32.         return f;
  33.     }
  34.    
  35.  
  36.  
  37.  
  38.     @Override
  39.     public void onCreate(Bundle savedInstanceState) {
  40.         super.onCreate(savedInstanceState);
  41.        
  42.     }
  43.  
  44.     @Override
  45.     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  46.         View root = inflater.inflate(R.layout.imageview, container, false);
  47.         ivImage = (ImageView) root.findViewById(R.id.ivImageView);
  48.  
  49.         btn_register = (Button) root.findViewById(R.id.button_register);
  50.        
  51.         if( ((WelcomeActivity) this.getActivity()).test()>=3){// && disableButtonUpdate==false){
  52.             btn_register.setVisibility(View.VISIBLE);
  53.         }
  54.        
  55.         setImageInViewPager();
  56.         return root;
  57.     }
  58.  
  59.     /*
  60.     public void onAttach(){
  61.         if(((WelcomeActivity) getActivity()).getSelectedPagePosition() >= 3){
  62.             btn_register.setVisibility(View.VISIBLE);
  63.         }else{
  64.             btn_register.setVisibility(View.INVISIBLE);
  65.         }
  66.     }*/
  67.    
  68.     public void setImageList(Integer integer) {
  69.         this.itemData = integer;
  70.     }
  71.  
  72.     public void setImageInViewPager() {
  73.         try {
  74.             BitmapFactory.Options options = new BitmapFactory.Options();
  75.             options.inJustDecodeBounds = true;
  76.             myBitmap = BitmapFactory.decodeResource(getResources(), itemData,
  77.                     options);
  78.             if (options.outWidth > 3000 || options.outHeight > 2000) {
  79.                 options.inSampleSize = 4;
  80.             } else if (options.outWidth > 2000 || options.outHeight > 1500) {
  81.                 options.inSampleSize = 3;
  82.             } else if (options.outWidth > 1000 || options.outHeight > 1000) {
  83.                 options.inSampleSize = 2;
  84.             }
  85.             options.inJustDecodeBounds = false;
  86.             myBitmap = BitmapFactory.decodeResource(getResources(), itemData,
  87.                     options);
  88.             if (myBitmap != null) {
  89.                 try {
  90.                     if (ivImage != null) {
  91.                         ivImage.setImageBitmap(myBitmap);
  92.                     }
  93.                 } catch (Exception e) {
  94.                     e.printStackTrace();
  95.                 }
  96.             }
  97.         } catch (OutOfMemoryError e) {
  98.             e.printStackTrace();
  99.             System.gc();
  100.         }
  101.     }
  102.    
  103.  
  104.     @Override
  105.     public void onDestroyView() {
  106.         super.onDestroyView();
  107.         if (myBitmap != null) {
  108.             myBitmap.recycle();
  109.             myBitmap = null;
  110.         }
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement