Home | History | Annotate | Download | only in controller
      1 package com.android.gallery3d.filtershow.controller;
      2 
      3 import android.app.ActionBar.LayoutParams;
      4 import android.content.Context;
      5 import android.content.res.Resources;
      6 import android.graphics.Bitmap;
      7 import android.view.LayoutInflater;
      8 import android.view.View;
      9 import android.view.ViewGroup;
     10 import android.widget.ImageButton;
     11 import android.widget.ImageView.ScaleType;
     12 import android.widget.LinearLayout;
     13 
     14 import com.android.gallery3d.R;
     15 import com.android.gallery3d.filtershow.pipeline.RenderingRequest;
     16 import com.android.gallery3d.filtershow.pipeline.RenderingRequestCaller;
     17 import com.android.gallery3d.filtershow.editors.Editor;
     18 
     19 import java.util.Vector;
     20 
     21 public class StyleChooser implements Control {
     22     private final String LOGTAG = "StyleChooser";
     23     protected ParameterStyles mParameter;
     24     protected LinearLayout mLinearLayout;
     25     protected Editor mEditor;
     26     private View mTopView;
     27     private Vector<ImageButton> mIconButton = new Vector<ImageButton>();
     28     protected int mLayoutID = R.layout.filtershow_control_style_chooser;
     29 
     30     @Override
     31     public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
     32         container.removeAllViews();
     33         mEditor = editor;
     34         Context context = container.getContext();
     35         mParameter = (ParameterStyles) parameter;
     36         LayoutInflater inflater =
     37                 (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     38         mTopView = inflater.inflate(mLayoutID, container, true);
     39         mLinearLayout = (LinearLayout) mTopView.findViewById(R.id.listStyles);
     40         mTopView.setVisibility(View.VISIBLE);
     41         int n = mParameter.getNumberOfStyles();
     42         mIconButton.clear();
     43         Resources res = context.getResources();
     44         int dim = res.getDimensionPixelSize(R.dimen.draw_style_icon_dim);
     45         LayoutParams lp = new LayoutParams(dim, dim);
     46         for (int i = 0; i < n; i++) {
     47             final ImageButton button = new ImageButton(context);
     48             button.setScaleType(ScaleType.CENTER_CROP);
     49             button.setLayoutParams(lp);
     50             button.setBackgroundResource(android.R.color.transparent);
     51             mIconButton.add(button);
     52             final int buttonNo = i;
     53             button.setOnClickListener(new View.OnClickListener() {
     54                 @Override
     55                 public void onClick(View arg0) {
     56                     mParameter.setSelected(buttonNo);
     57                 }
     58             });
     59             mLinearLayout.addView(button);
     60             mParameter.getIcon(i, new BitmapCaller() {
     61                 @Override
     62                 public void available(Bitmap bmap) {
     63 
     64                     if (bmap == null) {
     65                         return;
     66                     }
     67                     button.setImageBitmap(bmap);
     68                 }
     69             });
     70         }
     71     }
     72 
     73     @Override
     74     public View getTopView() {
     75         return mTopView;
     76     }
     77 
     78     @Override
     79     public void setPrameter(Parameter parameter) {
     80         mParameter = (ParameterStyles) parameter;
     81         updateUI();
     82     }
     83 
     84     @Override
     85     public void updateUI() {
     86         if (mParameter == null) {
     87             return;
     88         }
     89     }
     90 
     91 }
     92