Editor.java revision f4b659334750a5aa75f929d18857a2ab93c9d939
15aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford/* 25aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * Copyright (C) 2012 The Android Open Source Project 35aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * 45aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * Licensed under the Apache License, Version 2.0 (the "License"); 55aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * you may not use this file except in compliance with the License. 65aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * You may obtain a copy of the License at 75aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * 85aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * http://www.apache.org/licenses/LICENSE-2.0 95aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * 105aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * Unless required by applicable law or agreed to in writing, software 115aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * distributed under the License is distributed on an "AS IS" BASIS, 125aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * See the License for the specific language governing permissions and 145aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * limitations under the License. 155aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford */ 165aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 175aa08941bda0cfbcfba522c53937dd66867f890dJohn Hofordpackage com.android.gallery3d.filtershow.editors; 185aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 195aa08941bda0cfbcfba522c53937dd66867f890dJohn Hofordimport android.content.Context; 20235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.util.AttributeSet; 215aa08941bda0cfbcfba522c53937dd66867f890dJohn Hofordimport android.view.LayoutInflater; 226a07dfbe03c8396cc43840a1630ea480a2cff663John Hofordimport android.view.Menu; 232ff0e04ddcf770a782f94ddee936a1c205e1f322nicolasroardimport android.view.MenuItem; 245aa08941bda0cfbcfba522c53937dd66867f890dJohn Hofordimport android.view.View; 255aa08941bda0cfbcfba522c53937dd66867f890dJohn Hofordimport android.view.ViewGroup; 26235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.widget.Button; 27235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.widget.FrameLayout; 28235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.widget.LinearLayout; 29235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.widget.PopupMenu; 30235d2179374bec14040f20af91dc753e38ea3639John Hofordimport android.widget.SeekBar; 316a07dfbe03c8396cc43840a1630ea480a2cff663John Hofordimport android.widget.SeekBar.OnSeekBarChangeListener; 325aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 336a07dfbe03c8396cc43840a1630ea480a2cff663John Hofordimport com.android.gallery3d.R; 34235d2179374bec14040f20af91dc753e38ea3639John Hofordimport com.android.gallery3d.filtershow.controller.Control; 35cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroardimport com.android.gallery3d.filtershow.filters.FilterRepresentation; 365aa08941bda0cfbcfba522c53937dd66867f890dJohn Hofordimport com.android.gallery3d.filtershow.imageshow.ImageShow; 37cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroardimport com.android.gallery3d.filtershow.imageshow.MasterImage; 38ce9ceff5776a9b0479c30cbeb2a9388b44df1865nicolasroardimport com.android.gallery3d.filtershow.pipeline.ImagePreset; 395aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 40b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport java.util.ArrayList; 41b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport java.util.Collection; 42b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 435aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford/** 445aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * Base class for Editors Must contain a mImageShow and a top level view 455aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford */ 462ff0e04ddcf770a782f94ddee936a1c205e1f322nicolasroardpublic class Editor implements OnSeekBarChangeListener, SwapButton.SwapButtonListener { 475aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford protected Context mContext; 485aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford protected View mView; 495aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford protected ImageShow mImageShow; 505aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford protected FrameLayout mFrameLayout; 516a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford protected SeekBar mSeekBar; 52235d2179374bec14040f20af91dc753e38ea3639John Hoford Button mEditTitle; 53f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard protected Button mFilterTitle; 545aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford protected int mID; 555aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford private final String LOGTAG = "Editor"; 56b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk protected boolean mChangesGeometry = false; 57cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard protected FilterRepresentation mLocalRepresentation = null; 586a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford protected byte mShowParameter = SHOW_VALUE_UNDEFINED; 59f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard private Button mButton; 606a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford public static byte SHOW_VALUE_UNDEFINED = -1; 616a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford public static byte SHOW_VALUE_OFF = 0; 626a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford public static byte SHOW_VALUE_INT = 1; 635aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 647638772c0ceb5528b12c9943bad5391658d6c78dJohn Reck public static void hackFixStrings(Menu menu) { 657638772c0ceb5528b12c9943bad5391658d6c78dJohn Reck int count = menu.size(); 667638772c0ceb5528b12c9943bad5391658d6c78dJohn Reck for (int i = 0; i < count; i++) { 677638772c0ceb5528b12c9943bad5391658d6c78dJohn Reck MenuItem item = menu.getItem(i); 687638772c0ceb5528b12c9943bad5391658d6c78dJohn Reck item.setTitle(item.getTitle().toString().toUpperCase()); 697638772c0ceb5528b12c9943bad5391658d6c78dJohn Reck } 707638772c0ceb5528b12c9943bad5391658d6c78dJohn Reck } 717638772c0ceb5528b12c9943bad5391658d6c78dJohn Reck 726a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford public String calculateUserMessage(Context context, String effectName, Object parameterValue) { 7333de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford return effectName.toUpperCase() + " " + parameterValue; 746a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford } 756a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 765aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford protected Editor(int id) { 775aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford mID = id; 785aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 796a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 805aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford public int getID() { 815aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford return mID; 825aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 835aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 846a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford public byte showParameterValue() { 856a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford return mShowParameter; 866a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford } 876a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 8891be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard public boolean showsSeekBar() { 8991be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard return true; 9091be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard } 9191be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard 92f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard public void setUpEditorUI(View actionButton, View editControl, 93f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard Button editTitle, Button stateButton) { 94f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard mEditTitle = editTitle; 95f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard mFilterTitle = stateButton; 96f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard mButton = editTitle; 97430e46b06f8e7ee1ca3e7ecdcef3e0a978637c03nicolasroard MasterImage.getImage().resetGeometryImages(); 98235d2179374bec14040f20af91dc753e38ea3639John Hoford setMenuIcon(true); 99235d2179374bec14040f20af91dc753e38ea3639John Hoford setUtilityPanelUI(actionButton, editControl); 100235d2179374bec14040f20af91dc753e38ea3639John Hoford } 101235d2179374bec14040f20af91dc753e38ea3639John Hoford 102be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard public boolean showsPopupIndicator() { 103be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard return true; 104be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard } 105be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard 1066a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford /** 1076a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford * @param actionButton the would be the area for menu etc 1086a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford * @param editControl this is the black area for sliders etc 1096a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford */ 1106a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford public void setUtilityPanelUI(View actionButton, View editControl) { 111235d2179374bec14040f20af91dc753e38ea3639John Hoford 112235d2179374bec14040f20af91dc753e38ea3639John Hoford AttributeSet aset; 113235d2179374bec14040f20af91dc753e38ea3639John Hoford Context context = editControl.getContext(); 114235d2179374bec14040f20af91dc753e38ea3639John Hoford LayoutInflater inflater = 115235d2179374bec14040f20af91dc753e38ea3639John Hoford (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 116235d2179374bec14040f20af91dc753e38ea3639John Hoford LinearLayout lp = (LinearLayout) inflater.inflate( 117235d2179374bec14040f20af91dc753e38ea3639John Hoford R.layout.filtershow_seekbar, (ViewGroup) editControl, true); 118235d2179374bec14040f20af91dc753e38ea3639John Hoford mSeekBar = (SeekBar) lp.findViewById(R.id.primarySeekBar); 119235d2179374bec14040f20af91dc753e38ea3639John Hoford mSeekBar.setOnSeekBarChangeListener(this); 120235d2179374bec14040f20af91dc753e38ea3639John Hoford 12191be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard if (showsSeekBar()) { 12291be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard mSeekBar.setOnSeekBarChangeListener(this); 12391be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard mSeekBar.setVisibility(View.VISIBLE); 12491be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard } else { 12591be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard mSeekBar.setVisibility(View.INVISIBLE); 12691be98c35f6c5f19d7629bb29e7261970b2f4c67nicolasroard } 127235d2179374bec14040f20af91dc753e38ea3639John Hoford 128f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard if (mButton != null) { 129be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard if (showsPopupIndicator()) { 130f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard mButton.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 131235d2179374bec14040f20af91dc753e38ea3639John Hoford R.drawable.filtershow_menu_marker, 0); 132be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard } else { 133f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard mButton.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0); 134be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard } 135be31e587c1485fb8e3d7c8b079250ffbdc26e1b9nicolasroard } 1366a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford } 1376a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 1386a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford @Override 1396a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) { 1406a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 1416a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford } 1426a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 1436a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford public void setPanel() { 1446a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 1456a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford } 1466a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 147f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford public void createEditor(Context context, FrameLayout frameLayout) { 1485aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford mContext = context; 1495aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford mFrameLayout = frameLayout; 150cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard mLocalRepresentation = null; 1515aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 1525aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 1535aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford protected void unpack(int viewid, int layoutid) { 1545aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 1555aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford if (mView == null) { 1565aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford mView = mFrameLayout.findViewById(viewid); 1575aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford if (mView == null) { 1585aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford LayoutInflater inflater = (LayoutInflater) mContext.getSystemService 1595aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford (Context.LAYOUT_INFLATER_SERVICE); 1605aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford mView = inflater.inflate(layoutid, mFrameLayout, false); 1615aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford mFrameLayout.addView(mView, mView.getLayoutParams()); 1625aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 1635aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 1645aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford mImageShow = findImageShow(mView); 1655aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 1665aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 1675aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford private ImageShow findImageShow(View view) { 1685aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford if (view instanceof ImageShow) { 1695aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford return (ImageShow) view; 1705aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 1715aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford if (!(view instanceof ViewGroup)) { 1725aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford return null; 1735aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 1745aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford ViewGroup vg = (ViewGroup) view; 1755aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford int n = vg.getChildCount(); 1765aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford for (int i = 0; i < n; i++) { 1775aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford View v = vg.getChildAt(i); 1785aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford if (v instanceof ImageShow) { 1795aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford return (ImageShow) v; 1805aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } else if (v instanceof ViewGroup) { 1815aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford return findImageShow(v); 1825aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 1835aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 1845aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford return null; 1855aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 1865aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 1875aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford public View getTopLevelView() { 1885aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford return mView; 1895aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 1905aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 1915aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford public ImageShow getImageShow() { 1925aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford return mImageShow; 1935aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 1945aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 1955aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford public void setVisibility(int visible) { 1965aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford mView.setVisibility(visible); 1975aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 1985aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 199cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard public FilterRepresentation getLocalRepresentation() { 200cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard if (mLocalRepresentation == null) { 201cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard ImagePreset preset = MasterImage.getImage().getPreset(); 202cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard FilterRepresentation filterRepresentation = MasterImage.getImage().getCurrentFilterRepresentation(); 203cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard mLocalRepresentation = preset.getFilterRepresentationCopyFrom(filterRepresentation); 2045d24515190c1664f944b7950d1a75b0df0de2ff8nicolasroard if (mShowParameter == SHOW_VALUE_UNDEFINED && filterRepresentation != null) { 2056a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford boolean show = filterRepresentation.showParameterValue(); 2066a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford mShowParameter = show ? SHOW_VALUE_INT : SHOW_VALUE_OFF; 2076a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford } 2086a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 209f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard } 210cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard return mLocalRepresentation; 211cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard } 212cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard 213b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk /** 214f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * Call this to update the preset in MasterImage with the current representation 215f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * returned by getLocalRepresentation. This causes the preview bitmap to be 216f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * regenerated. 217b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk */ 218cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard public void commitLocalRepresentation() { 219b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk commitLocalRepresentation(getLocalRepresentation()); 220b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 221b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 222b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk /** 223f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * Call this to update the preset in MasterImage with a given representation. 224f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * This causes the preview bitmap to be regenerated. 225b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk */ 226b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public void commitLocalRepresentation(FilterRepresentation rep) { 227b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk ArrayList<FilterRepresentation> filter = new ArrayList<FilterRepresentation>(1); 228b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk filter.add(rep); 229b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk commitLocalRepresentation(filter); 230b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 231b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 232b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk /** 233f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * Call this to update the preset in MasterImage with a collection of FilterRepresentations. 234f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford * This causes the preview bitmap to be regenerated. 235b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk */ 236b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public void commitLocalRepresentation(Collection<FilterRepresentation> reps) { 237cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard ImagePreset preset = MasterImage.getImage().getPreset(); 238b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk preset.updateFilterRepresentations(reps); 239f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard if (mButton != null) { 240f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard updateText(); 241f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard } 242b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk if (mChangesGeometry) { 243b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk // Regenerate both the filtered and the geometry-only bitmaps 244430e46b06f8e7ee1ca3e7ecdcef3e0a978637c03nicolasroard MasterImage.getImage().resetGeometryImages(); 245b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } else { 246b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk // Regenerate only the filtered bitmap. 247b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk MasterImage.getImage().invalidateFiltersOnly(); 248b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 249b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk preset.fillImageStateAdapter(MasterImage.getImage().getState()); 250b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 251b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 252b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk /** 253b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * This is called in response to a click to apply and leave the editor. 254b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk */ 255b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public void finalApplyCalled() { 256b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk commitLocalRepresentation(); 257f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard } 258f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard 259f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard protected void updateText() { 260f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard String s = ""; 261f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard if (mLocalRepresentation != null) { 262f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard s = mContext.getString(mLocalRepresentation.getTextId()); 2637112720bc6100049d24845cfbf3de69cdbd4fdebJohn Hoford } 264f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard mButton.setText(calculateUserMessage(mContext, s, "")); 265cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard } 266cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard 2675aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford /** 2685aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford * called after the filter is set and the select is called 2695aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford */ 2705aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford public void reflectCurrentFilter() { 271cf0b2aad3bc5d80c51316ae10e1cf2c3476259aanicolasroard mLocalRepresentation = null; 272f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard FilterRepresentation representation = getLocalRepresentation(); 273f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard if (representation != null && mFilterTitle != null && representation.getTextId() != 0) { 274f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard String text = mContext.getString(representation.getTextId()).toUpperCase(); 275f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard mFilterTitle.setText(text); 276f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard updateText(); 277f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard } 2785aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 2795aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 2805aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford public boolean useUtilityPanel() { 281001283a72d451999e3308f45dc365d4defc0af39John Hoford return true; 2825aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 2835aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 2845aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford public void openUtilityPanel(LinearLayout mAccessoryViewList) { 285235d2179374bec14040f20af91dc753e38ea3639John Hoford setMenuIcon(false); 2865aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford if (mImageShow != null) { 2875aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford mImageShow.openUtilityPanel(mAccessoryViewList); 2885aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 2895aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford } 2905aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford 291235d2179374bec14040f20af91dc753e38ea3639John Hoford protected void setMenuIcon(boolean on) { 292235d2179374bec14040f20af91dc753e38ea3639John Hoford mEditTitle.setCompoundDrawablesRelativeWithIntrinsicBounds( 293235d2179374bec14040f20af91dc753e38ea3639John Hoford 0, 0, on ? R.drawable.filtershow_menu_marker : 0, 0); 294235d2179374bec14040f20af91dc753e38ea3639John Hoford } 295f5eedf1635eba7edfa7d41fd4e991cced978c4b2nicolasroard 2966a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford protected void createMenu(int[] strId, View button) { 2976a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford PopupMenu pmenu = new PopupMenu(mContext, button); 2986a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford Menu menu = pmenu.getMenu(); 2996a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford for (int i = 0; i < strId.length; i++) { 3006a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford menu.add(Menu.NONE, Menu.FIRST + i, 0, mContext.getString(strId[i])); 3016a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford } 302235d2179374bec14040f20af91dc753e38ea3639John Hoford setMenuIcon(true); 303235d2179374bec14040f20af91dc753e38ea3639John Hoford 3046a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford } 3056a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 306235d2179374bec14040f20af91dc753e38ea3639John Hoford public Control[] getControls() { 307235d2179374bec14040f20af91dc753e38ea3639John Hoford return null; 308235d2179374bec14040f20af91dc753e38ea3639John Hoford } 309f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford 3106a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford @Override 3116a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford public void onStartTrackingTouch(SeekBar arg0) { 3126a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 3136a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford } 3146a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 3156a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford @Override 3166a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford public void onStopTrackingTouch(SeekBar arg0) { 3176a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 3186a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford } 3196a07dfbe03c8396cc43840a1630ea480a2cff663John Hoford 3202ff0e04ddcf770a782f94ddee936a1c205e1f322nicolasroard @Override 3212ff0e04ddcf770a782f94ddee936a1c205e1f322nicolasroard public void swapLeft(MenuItem item) { 3222ff0e04ddcf770a782f94ddee936a1c205e1f322nicolasroard 3232ff0e04ddcf770a782f94ddee936a1c205e1f322nicolasroard } 3242ff0e04ddcf770a782f94ddee936a1c205e1f322nicolasroard 3252ff0e04ddcf770a782f94ddee936a1c205e1f322nicolasroard @Override 3262ff0e04ddcf770a782f94ddee936a1c205e1f322nicolasroard public void swapRight(MenuItem item) { 3272ff0e04ddcf770a782f94ddee936a1c205e1f322nicolasroard 3282ff0e04ddcf770a782f94ddee936a1c205e1f322nicolasroard } 3297668544ee3e8ba3b14d127b9ecd1cf4a3b2f3e11nicolasroard 3307668544ee3e8ba3b14d127b9ecd1cf4a3b2f3e11nicolasroard public void detach() { 3317668544ee3e8ba3b14d127b9ecd1cf4a3b2f3e11nicolasroard } 3325aa08941bda0cfbcfba522c53937dd66867f890dJohn Hoford} 333