1166524339e9f8ad86c0922142b961776e0da3d8fJohn Hofordpackage com.android.gallery3d.filtershow.controller;
2166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford
39e0d687320eb9302b4b96f615083c31edbdeb08bJohn Hofordimport android.app.ActionBar.LayoutParams;
4166524339e9f8ad86c0922142b961776e0da3d8fJohn Hofordimport android.content.Context;
597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.content.res.Resources;
6166524339e9f8ad86c0922142b961776e0da3d8fJohn Hofordimport android.graphics.Bitmap;
7166524339e9f8ad86c0922142b961776e0da3d8fJohn Hofordimport android.view.LayoutInflater;
8166524339e9f8ad86c0922142b961776e0da3d8fJohn Hofordimport android.view.View;
9166524339e9f8ad86c0922142b961776e0da3d8fJohn Hofordimport android.view.ViewGroup;
109e0d687320eb9302b4b96f615083c31edbdeb08bJohn Hofordimport android.widget.ImageButton;
119e0d687320eb9302b4b96f615083c31edbdeb08bJohn Hofordimport android.widget.ImageView.ScaleType;
12166524339e9f8ad86c0922142b961776e0da3d8fJohn Hofordimport android.widget.LinearLayout;
13166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford
14166524339e9f8ad86c0922142b961776e0da3d8fJohn Hofordimport com.android.gallery3d.R;
15ce9ceff5776a9b0479c30cbeb2a9388b44df1865nicolasroardimport com.android.gallery3d.filtershow.pipeline.RenderingRequest;
16ce9ceff5776a9b0479c30cbeb2a9388b44df1865nicolasroardimport com.android.gallery3d.filtershow.pipeline.RenderingRequestCaller;
17166524339e9f8ad86c0922142b961776e0da3d8fJohn Hofordimport com.android.gallery3d.filtershow.editors.Editor;
18166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford
19166524339e9f8ad86c0922142b961776e0da3d8fJohn Hofordimport java.util.Vector;
20166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford
214ee3cfd8a59f5daaf271b67c2f634d72290d45d0John Hofordpublic class StyleChooser implements Control {
22166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    private final String LOGTAG = "StyleChooser";
23166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    protected ParameterStyles mParameter;
24166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    protected LinearLayout mLinearLayout;
25166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    protected Editor mEditor;
26166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    private View mTopView;
279e0d687320eb9302b4b96f615083c31edbdeb08bJohn Hoford    private Vector<ImageButton> mIconButton = new Vector<ImageButton>();
28166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    protected int mLayoutID = R.layout.filtershow_control_style_chooser;
29166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford
30166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    @Override
31166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
32166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        container.removeAllViews();
33166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        mEditor = editor;
34166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        Context context = container.getContext();
35166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        mParameter = (ParameterStyles) parameter;
36166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        LayoutInflater inflater =
37166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford                (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
38166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        mTopView = inflater.inflate(mLayoutID, container, true);
39166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        mLinearLayout = (LinearLayout) mTopView.findViewById(R.id.listStyles);
40166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        mTopView.setVisibility(View.VISIBLE);
41166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        int n = mParameter.getNumberOfStyles();
42166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        mIconButton.clear();
4397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        Resources res = context.getResources();
4497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        int dim = res.getDimensionPixelSize(R.dimen.draw_style_icon_dim);
4597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        LayoutParams lp = new LayoutParams(dim, dim);
46166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        for (int i = 0; i < n; i++) {
474ee3cfd8a59f5daaf271b67c2f634d72290d45d0John Hoford            final ImageButton button = new ImageButton(context);
489e0d687320eb9302b4b96f615083c31edbdeb08bJohn Hoford            button.setScaleType(ScaleType.CENTER_CROP);
499e0d687320eb9302b4b96f615083c31edbdeb08bJohn Hoford            button.setLayoutParams(lp);
509e0d687320eb9302b4b96f615083c31edbdeb08bJohn Hoford            button.setBackgroundResource(android.R.color.transparent);
51166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford            mIconButton.add(button);
52166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford            final int buttonNo = i;
53166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford            button.setOnClickListener(new View.OnClickListener() {
54166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford                @Override
55166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford                public void onClick(View arg0) {
56166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford                    mParameter.setSelected(buttonNo);
57166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford                }
58166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford            });
59166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford            mLinearLayout.addView(button);
60f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford            mParameter.getIcon(i, new BitmapCaller() {
614ee3cfd8a59f5daaf271b67c2f634d72290d45d0John Hoford                @Override
62f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford                public void available(Bitmap bmap) {
63f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford
644ee3cfd8a59f5daaf271b67c2f634d72290d45d0John Hoford                    if (bmap == null) {
654ee3cfd8a59f5daaf271b67c2f634d72290d45d0John Hoford                        return;
664ee3cfd8a59f5daaf271b67c2f634d72290d45d0John Hoford                    }
674ee3cfd8a59f5daaf271b67c2f634d72290d45d0John Hoford                    button.setImageBitmap(bmap);
684ee3cfd8a59f5daaf271b67c2f634d72290d45d0John Hoford                }
694ee3cfd8a59f5daaf271b67c2f634d72290d45d0John Hoford            });
70166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        }
71166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    }
72166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford
73166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    @Override
74166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    public View getTopView() {
75166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        return mTopView;
76166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    }
77166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford
78166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    @Override
79166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    public void setPrameter(Parameter parameter) {
80166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        mParameter = (ParameterStyles) parameter;
81166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        updateUI();
82166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    }
83166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford
84166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    @Override
85166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    public void updateUI() {
86166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        if (mParameter == null) {
87166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford            return;
88166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford        }
89166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford    }
90166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford
91166524339e9f8ad86c0922142b961776e0da3d8fJohn Hoford}
92