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