OSDN Git Service

merge in klp-release history after reset to klp-dev
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / FilterShowActivity.java
index f386b1b..9d5005e 100644 (file)
@@ -29,11 +29,17 @@ import android.content.pm.ActivityInfo;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
+import android.graphics.Color;
+import android.graphics.Matrix;
+import android.graphics.Point;
 import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Bundle;
+import android.os.CancellationSignal;
 import android.os.Handler;
 import android.os.IBinder;
 import android.support.v4.app.DialogFragment;
@@ -55,6 +61,7 @@ import android.widget.AdapterView.OnItemClickListener;
 import android.widget.FrameLayout;
 import android.widget.ShareActionProvider;
 import android.widget.ShareActionProvider.OnShareTargetSelectedListener;
+import android.widget.Spinner;
 import android.widget.Toast;
 
 import com.android.gallery3d.R;
@@ -63,12 +70,15 @@ import com.android.gallery3d.data.LocalAlbum;
 import com.android.gallery3d.filtershow.cache.ImageLoader;
 import com.android.gallery3d.filtershow.category.Action;
 import com.android.gallery3d.filtershow.category.CategoryAdapter;
+import com.android.gallery3d.filtershow.category.CategorySelected;
+import com.android.gallery3d.filtershow.category.CategoryView;
 import com.android.gallery3d.filtershow.category.MainPanel;
 import com.android.gallery3d.filtershow.category.SwipableView;
 import com.android.gallery3d.filtershow.data.UserPresetsManager;
 import com.android.gallery3d.filtershow.editors.BasicEditor;
 import com.android.gallery3d.filtershow.editors.Editor;
 import com.android.gallery3d.filtershow.editors.EditorChanSat;
+import com.android.gallery3d.filtershow.editors.EditorColorBorder;
 import com.android.gallery3d.filtershow.editors.EditorCrop;
 import com.android.gallery3d.filtershow.editors.EditorDraw;
 import com.android.gallery3d.filtershow.editors.EditorGrad;
@@ -80,9 +90,11 @@ import com.android.gallery3d.filtershow.editors.EditorRotate;
 import com.android.gallery3d.filtershow.editors.EditorStraighten;
 import com.android.gallery3d.filtershow.editors.EditorTinyPlanet;
 import com.android.gallery3d.filtershow.editors.ImageOnlyEditor;
+import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation;
 import com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation;
 import com.android.gallery3d.filtershow.filters.FilterRepresentation;
 import com.android.gallery3d.filtershow.filters.FilterRotateRepresentation;
+import com.android.gallery3d.filtershow.filters.FilterStraightenRepresentation;
 import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation;
 import com.android.gallery3d.filtershow.filters.FiltersManager;
 import com.android.gallery3d.filtershow.filters.ImageFilter;
@@ -105,16 +117,19 @@ import com.android.gallery3d.filtershow.tools.XmpPresets.XMresults;
 import com.android.gallery3d.filtershow.ui.ExportDialog;
 import com.android.gallery3d.filtershow.ui.FramedTextButton;
 import com.android.gallery3d.util.GalleryUtils;
-import com.android.gallery3d.util.UsageStatistics;
+import com.android.gallery3d.util.PrintJob;
 import com.android.photos.data.GalleryBitmapPool;
 
 import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileOutputStream;
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.Vector;
 
 public class FilterShowActivity extends FragmentActivity implements OnItemClickListener,
-        OnShareTargetSelectedListener {
+        OnShareTargetSelectedListener, DialogInterface.OnShowListener,
+        DialogInterface.OnDismissListener{
 
     private String mAction = "";
     MasterImage mMasterImage = null;
@@ -128,6 +143,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
     private View mSaveButton = null;
 
     private EditorPlaceHolder mEditorPlaceHolder = new EditorPlaceHolder(this);
+    private Editor mCurrentEditor = null;
 
     private static final int SELECT_PICTURE = 1;
     private static final String LOGTAG = "FilterShowActivity";
@@ -135,7 +151,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
     private boolean mShowingTinyPlanet = false;
     private boolean mShowingImageStatePanel = false;
     private boolean mShowingVersionsPanel = false;
-    private boolean mShowingInformationPanel = false;
 
     private final Vector<ImageShow> mImageViews = new Vector<ImageShow>();
 
@@ -153,6 +168,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
 
     private Uri mSelectedImageUri = null;
 
+    private ArrayList<Action> mActions = new ArrayList<Action>();
     private UserPresetsManager mUserPresetsManager = null;
     private UserPresetsAdapter mUserPresetsAdapter = null;
     private CategoryAdapter mCategoryLooksAdapter = null;
@@ -168,10 +184,14 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
     private boolean mHandlingSwipeButton = false;
     private View mHandledSwipeView = null;
     private float mHandledSwipeViewLastDelta = 0;
+    private float mSwipeStartX = 0;
     private float mSwipeStartY = 0;
 
     private ProcessingService mBoundService;
     private boolean mIsBound = false;
+    private Menu mMenu;
+    private DialogInterface mCurrentDialog = null;
+    private boolean mLoadingVisible = true;
 
     public ProcessingService getProcessingService() {
         return mBoundService;
@@ -228,17 +248,21 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         }
     }
 
-    private void setupPipeline() {
-        doBindService();
+    public void updateUIAfterServiceStarted() {
+        MasterImage.setMaster(mMasterImage);
         ImageFilter.setActivityForMemoryToasts(this);
         mUserPresetsManager = new UserPresetsManager(this);
         mUserPresetsAdapter = new UserPresetsAdapter(this);
-    }
 
-    public void updateUIAfterServiceStarted() {
+        setupMasterImage();
+        setupMenu();
+        setDefaultValues();
+        fillEditors();
+        getWindow().setBackgroundDrawable(new ColorDrawable(0));
+        loadXML();
+
         fillCategories();
         loadMainPanel();
-        setDefaultPreset();
         extractXMPData();
         processIntent();
     }
@@ -251,19 +275,11 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         if (onlyUsePortrait) {
             setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
         }
-        MasterImage.setMaster(mMasterImage);
 
         clearGalleryBitmapPool();
-        setupPipeline();
-
-        setupMasterImage();
-        setDefaultValues();
-        fillEditors();
-
-        loadXML();
-        UsageStatistics.onContentViewChanged(UsageStatistics.COMPONENT_EDITOR, "Main");
-        UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
-                UsageStatistics.CATEGORY_LIFECYCLE, UsageStatistics.LIFECYCLE_START);
+        doBindService();
+        getWindow().setBackgroundDrawable(new ColorDrawable(Color.GRAY));
+        setContentView(R.layout.filtershow_splashscreen);
     }
 
     public boolean isShowingImageStatePanel() {
@@ -318,35 +334,12 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         }
     }
 
-    private void hideInformationPanel() {
-        FrameLayout infoLayout = (FrameLayout) findViewById(R.id.central_panel_container);
-        infoLayout.setVisibility(View.GONE);
-        Fragment fragment = getSupportFragmentManager().findFragmentByTag(InfoPanel.FRAGMENT_TAG);
-        if (fragment != null) {
-            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-            transaction.remove(fragment);
-            transaction.commit();
-        }
-        mShowingInformationPanel = false;
-    }
-
-    public void showInformationPanel() {
-        mShowingInformationPanel = !mShowingInformationPanel;
-        if (!mShowingInformationPanel) {
-            hideInformationPanel();
-            showDefaultImageView();
-            return;
-        }
+    public void toggleInformationPanel() {
         FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
         transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
-        FrameLayout infoLayout = (FrameLayout) findViewById(R.id.central_panel_container);
-        infoLayout.setVisibility(View.VISIBLE);
-        mEditorPlaceHolder.hide();
-        mImageShow.setVisibility(View.GONE);
 
         InfoPanel panel = new InfoPanel();
-        transaction.replace(R.id.central_panel_container, panel, InfoPanel.FRAGMENT_TAG);
-        transaction.commit();
+        panel.show(transaction, InfoPanel.FRAGMENT_TAG);
     }
 
     private void loadXML() {
@@ -355,6 +348,8 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         ActionBar actionBar = getActionBar();
         actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
         actionBar.setCustomView(R.layout.filtershow_actionbar);
+        actionBar.setBackgroundDrawable(new ColorDrawable(
+                getResources().getColor(R.color.background_screen)));
 
         mSaveButton = actionBar.getCustomView();
         mSaveButton.setOnClickListener(new OnClickListener() {
@@ -370,7 +365,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         setupEditors();
 
         mEditorPlaceHolder.hide();
-        mImageShow.bindAsImageLoadListener();
+        mImageShow.attach();
 
         setupStatePanel();
     }
@@ -389,10 +384,27 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
     }
 
     private void fillVersions() {
+        if (mCategoryVersionsAdapter != null) {
+            mCategoryVersionsAdapter.clear();
+        }
         mCategoryVersionsAdapter = new CategoryAdapter(this);
         mCategoryVersionsAdapter.setShowAddButton(true);
     }
 
+    public void registerAction(Action action) {
+        if (mActions.contains(action)) {
+            return;
+        }
+        mActions.add(action);
+    }
+
+    private void loadActions() {
+        for (int i = 0; i < mActions.size(); i++) {
+            Action action = mActions.get(i);
+            action.setImageFrame(new Rect(0, 0, 96, 96), 0);
+        }
+    }
+
     public void updateVersions() {
         mCategoryVersionsAdapter.clear();
         FilterUserPresetRepresentation originalRep = new FilterUserPresetRepresentation(
@@ -429,16 +441,21 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
     }
 
     public void removeLook(Action action) {
-        FilterUserPresetRepresentation rep = (FilterUserPresetRepresentation) action.getRepresentation();
+        FilterUserPresetRepresentation rep =
+                (FilterUserPresetRepresentation) action.getRepresentation();
         if (rep == null) {
             return;
         }
         mUserPresetsManager.delete(rep.getId());
+        updateUserPresetsFromManager();
     }
 
     private void fillEffects() {
         FiltersManager filtersManager = FiltersManager.getManager();
         ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getEffects();
+        if (mCategoryFiltersAdapter != null) {
+            mCategoryFiltersAdapter.clear();
+        }
         mCategoryFiltersAdapter = new CategoryAdapter(this);
         for (FilterRepresentation representation : filtersRepresentations) {
             if (representation.getTextId() != 0) {
@@ -451,9 +468,22 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
     private void fillTools() {
         FiltersManager filtersManager = FiltersManager.getManager();
         ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getTools();
+        if (mCategoryGeometryAdapter != null) {
+            mCategoryGeometryAdapter.clear();
+        }
         mCategoryGeometryAdapter = new CategoryAdapter(this);
+        boolean found = false;
         for (FilterRepresentation representation : filtersRepresentations) {
             mCategoryGeometryAdapter.add(new Action(this, representation));
+            if (representation instanceof FilterDrawRepresentation) {
+                found = true;
+            }
+        }
+        if (!found) {
+            FilterRepresentation representation = new FilterDrawRepresentation();
+            Action action = new Action(this, representation);
+            action.setIsDoubleAction(true);
+            mCategoryGeometryAdapter.add(action);
         }
     }
 
@@ -486,6 +516,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         mEditorPlaceHolder.addEditor(new EditorChanSat());
         mEditorPlaceHolder.addEditor(new EditorGrad());
         mEditorPlaceHolder.addEditor(new EditorDraw());
+        mEditorPlaceHolder.addEditor(new EditorColorBorder());
         mEditorPlaceHolder.addEditor(new BasicEditor());
         mEditorPlaceHolder.addEditor(new ImageOnlyEditor());
         mEditorPlaceHolder.addEditor(new EditorTinyPlanet());
@@ -508,13 +539,14 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         int curveHandleSize = (int) res.getDimension(R.dimen.crop_indicator_size);
         Spline.setCurveHandle(curveHandle, curveHandleSize);
         Spline.setCurveWidth((int) getPixelsFromDip(3));
+
+        mOriginalImageUri = null;
     }
 
     private void startLoadBitmap(Uri uri) {
-        final View loading = findViewById(R.id.loading);
         final View imageShow = findViewById(R.id.imageShow);
         imageShow.setVisibility(View.INVISIBLE);
-        loading.setVisibility(View.VISIBLE);
+        startLoadingIndicator();
         mShowingTinyPlanet = false;
         mLoadBitmapTask = new LoadBitmapTask();
         mLoadBitmapTask.execute(uri);
@@ -532,6 +564,9 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
             }
         }
 
+        if (mCategoryBordersAdapter != null) {
+            mCategoryBordersAdapter.clear();
+        }
         mCategoryBordersAdapter = new CategoryAdapter(this);
         for (FilterRepresentation representation : borders) {
             if (representation.getTextId() != 0) {
@@ -588,21 +623,28 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
             && MasterImage.getImage().getCurrentFilterRepresentation() == filterRepresentation) {
             return;
         }
+        if (filterRepresentation instanceof FilterUserPresetRepresentation
+                || filterRepresentation instanceof FilterRotateRepresentation
+                || filterRepresentation instanceof FilterMirrorRepresentation) {
+            MasterImage.getImage().onNewLook(filterRepresentation);
+        }
         ImagePreset oldPreset = MasterImage.getImage().getPreset();
         ImagePreset copy = new ImagePreset(oldPreset);
         FilterRepresentation representation = copy.getRepresentation(filterRepresentation);
         if (representation == null) {
+            filterRepresentation = filterRepresentation.copy();
             copy.addFilter(filterRepresentation);
-        } else if (filterRepresentation.getFilterType() == FilterRepresentation.TYPE_GEOMETRY) {
-            representation.useParametersFrom(filterRepresentation);
-            filterRepresentation = representation;
         } else {
             if (filterRepresentation.allowsSingleInstanceOnly()) {
                 // Don't just update the filter representation. Centralize the
                 // logic in the addFilter(), such that we can keep "None" as
                 // null.
-                copy.removeFilter(representation);
-                copy.addFilter(filterRepresentation);
+                if (!representation.equals(filterRepresentation)) {
+                    // Only do this if the filter isn't the same
+                    // (state panel clicks can lead us here)
+                    copy.removeFilter(representation);
+                    copy.addFilter(filterRepresentation);
+                }
             }
         }
         MasterImage.getImage().setPreset(copy, filterRepresentation, true);
@@ -622,12 +664,26 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
             FilterMirrorRepresentation r = (FilterMirrorRepresentation) representation;
             r.cycle();
         }
+        if (representation.isBooleanFilter()) {
+            ImagePreset preset = MasterImage.getImage().getPreset();
+            if (preset.getRepresentation(representation) != null) {
+                // remove
+                ImagePreset copy = new ImagePreset(preset);
+                copy.removeFilter(representation);
+                FilterRepresentation filterRepresentation = representation.copy();
+                MasterImage.getImage().setPreset(copy, filterRepresentation, true);
+                MasterImage.getImage().setCurrentFilterRepresentation(null);
+                return;
+            }
+        }
         useFilterRepresentation(representation);
 
         // show representation
-        Editor mCurrentEditor = mEditorPlaceHolder.showEditor(representation.getEditorId());
+        if (mCurrentEditor != null) {
+            mCurrentEditor.detach();
+        }
+        mCurrentEditor = mEditorPlaceHolder.showEditor(representation.getEditorId());
         loadEditorPanel(representation, mCurrentEditor);
-        hideInformationPanel();
     }
 
     public Editor getEditor(int editorID) {
@@ -652,6 +708,16 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         return findViewById(id);
     }
 
+    @Override
+    public void onShow(DialogInterface dialog) {
+        mCurrentDialog = dialog;
+    }
+
+    @Override
+    public void onDismiss(DialogInterface dialogInterface) {
+        mCurrentDialog = null;
+    }
+
     private class LoadHighresBitmapTask extends AsyncTask<Void, Void, Boolean> {
         @Override
         protected Boolean doInBackground(Void... params) {
@@ -682,9 +748,26 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
                         / (float) MasterImage.getImage().getOriginalBounds().width();
                 mBoundService.setHighresPreviewScaleFactor(highResPreviewScale);
             }
+            MasterImage.getImage().warnListeners();
         }
     }
 
+    public boolean isLoadingVisible() {
+        return mLoadingVisible;
+    }
+
+    public void startLoadingIndicator() {
+        final View loading = findViewById(R.id.loading);
+        mLoadingVisible = true;
+        loading.setVisibility(View.VISIBLE);
+    }
+
+    public void stopLoadingIndicator() {
+        final View loading = findViewById(R.id.loading);
+        loading.setVisibility(View.GONE);
+        mLoadingVisible = false;
+    }
+
     private class LoadBitmapTask extends AsyncTask<Uri, Boolean, Boolean> {
         int mBitmapSize;
 
@@ -720,9 +803,16 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
             }
 
             if (!result) {
-                cannotLoadImage();
-                // TODO: We should figure out the best way preventing this from
-                // happening, e.g: early checking.
+                if (mOriginalImageUri != null
+                        && !mOriginalImageUri.equals(mSelectedImageUri)) {
+                    mOriginalImageUri = mSelectedImageUri;
+                    mOriginalPreset = null;
+                    Toast.makeText(FilterShowActivity.this,
+                            R.string.cannot_edit_original, Toast.LENGTH_SHORT).show();
+                    startLoadBitmap(mOriginalImageUri);
+                } else {
+                    cannotLoadImage();
+                }
                 return;
             }
 
@@ -730,14 +820,12 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
                 Log.v(LOGTAG,"RenderScript context destroyed during load");
                 return;
             }
-            final View loading = findViewById(R.id.loading);
-            loading.setVisibility(View.GONE);
             final View imageShow = findViewById(R.id.imageShow);
             imageShow.setVisibility(View.VISIBLE);
 
+
             Bitmap largeBitmap = MasterImage.getImage().getOriginalBitmapLarge();
             mBoundService.setOriginalBitmap(largeBitmap);
-            MasterImage.getImage().resetGeometryImages();
 
             float previewScale = (float) largeBitmap.getWidth()
                     / (float) MasterImage.getImage().getOriginalBounds().width();
@@ -751,18 +839,26 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
             mCategoryFiltersAdapter.imageLoaded();
             mLoadBitmapTask = null;
 
+            MasterImage.getImage().warnListeners();
+            loadActions();
+
             if (mOriginalPreset != null) {
                 MasterImage.getImage().setLoadedPreset(mOriginalPreset);
                 MasterImage.getImage().setPreset(mOriginalPreset,
                         mOriginalPreset.getLastRepresentation(), true);
                 mOriginalPreset = null;
+            } else {
+                setDefaultPreset();
             }
 
+            MasterImage.getImage().resetGeometryImages(true);
+
             if (mAction == TINY_PLANET_ACTION) {
                 showRepresentation(mCategoryFiltersAdapter.getTinyPlanet());
             }
             LoadHighresBitmapTask highresLoad = new LoadHighresBitmapTask();
             highresLoad.execute();
+            MasterImage.getImage().warnListeners();
             super.onPostExecute(result);
         }
 
@@ -881,12 +977,19 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
                 .getActionProvider();
         mShareActionProvider.setShareIntent(getDefaultShareIntent());
         mShareActionProvider.setOnShareTargetSelectedListener(this);
+        mMenu = menu;
+        setupMenu();
+        return true;
+    }
 
-        MenuItem undoItem = menu.findItem(R.id.undoButton);
-        MenuItem redoItem = menu.findItem(R.id.redoButton);
-        MenuItem resetItem = menu.findItem(R.id.resetHistoryButton);
+    private void setupMenu(){
+        if (mMenu == null || mMasterImage == null) {
+            return;
+        }
+        MenuItem undoItem = mMenu.findItem(R.id.undoButton);
+        MenuItem redoItem = mMenu.findItem(R.id.redoButton);
+        MenuItem resetItem = mMenu.findItem(R.id.resetHistoryButton);
         mMasterImage.getHistory().setMenuItems(undoItem, redoItem, resetItem);
-        return true;
     }
 
     @Override
@@ -914,8 +1017,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
                 mMasterImage.onHistoryItemClick(position);
                 backToMain();
                 invalidateViews();
-                UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
-                        UsageStatistics.CATEGORY_BUTTON_PRESS, "Undo");
                 return true;
             }
             case R.id.redoButton: {
@@ -923,21 +1024,14 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
                 int position = adapter.redo();
                 mMasterImage.onHistoryItemClick(position);
                 invalidateViews();
-                UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
-                        UsageStatistics.CATEGORY_BUTTON_PRESS, "Redo");
                 return true;
             }
             case R.id.resetHistoryButton: {
                 resetHistory();
-                UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
-                        UsageStatistics.CATEGORY_BUTTON_PRESS, "ResetHistory");
                 return true;
             }
             case R.id.showImageStateButton: {
                 toggleImageStatePanel();
-                UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
-                        UsageStatistics.CATEGORY_BUTTON_PRESS,
-                        mShowingImageStatePanel ? "ShowPanel" : "HidePanel");
                 return true;
             }
             case R.id.exportFlattenButton: {
@@ -953,13 +1047,22 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
                 return true;
             }
             case R.id.showInfoPanel: {
-                showInformationPanel();
+                toggleInformationPanel();
+                return true;
+            }
+            case R.id.printButton: {
+                print();
                 return true;
             }
         }
         return false;
     }
 
+    public void print() {
+        Bitmap bitmap = MasterImage.getImage().getHighresImage();
+        PrintJob.printBitmap(this, "ImagePrint", bitmap);
+    }
+
     public void addNewPreset() {
         DialogFragment dialog = new PresetManagementDialog();
         dialog.show(getSupportFragmentManager(), "NoticeDialogFragment");
@@ -993,6 +1096,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
 
     public void loadUserPresets() {
         mUserPresetsManager.load();
+        updateUserPresetsFromManager();
     }
 
     public void updateUserPresetsFromManager() {
@@ -1016,6 +1120,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         if (presets.size() > 0) {
             mCategoryLooksAdapter.add(new Action(this, Action.ADD_ACTION));
         }
+        mCategoryLooksAdapter.notifyDataSetChanged();
         mCategoryLooksAdapter.notifyDataSetInvalidated();
     }
 
@@ -1041,6 +1146,9 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         FiltersManager filtersManager = FiltersManager.getManager();
         ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getLooks();
 
+        if (mCategoryLooksAdapter != null) {
+            mCategoryLooksAdapter.clear();
+        }
         mCategoryLooksAdapter = new CategoryAdapter(this);
         int verticalItemHeight = (int) getResources().getDimension(R.dimen.action_item_height);
         mCategoryLooksAdapter.setItemHeight(verticalItemHeight);
@@ -1051,6 +1159,14 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
             || mUserPresetsManager.getRepresentations().size() == 0) {
             mCategoryLooksAdapter.add(new Action(this, Action.ADD_ACTION));
         }
+
+        Fragment panel = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG);
+        if (panel != null) {
+            if (panel instanceof MainPanel) {
+                MainPanel mainPanel = (MainPanel) panel;
+                mainPanel.loadCategoryLookPanel(true);
+            }
+        }
     }
 
     public void setDefaultPreset() {
@@ -1107,17 +1223,24 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
     public void onConfigurationChanged(Configuration newConfig)
     {
         super.onConfigurationChanged(newConfig);
+
         setDefaultValues();
+        if (mMasterImage == null) {
+            return;
+        }
         loadXML();
         fillCategories();
         loadMainPanel();
 
+        if (mCurrentDialog != null) {
+            mCurrentDialog.dismiss();
+            mCurrentDialog = null;
+        }
         // mLoadBitmapTask==null implies you have looked at the intent
         if (!mShowingTinyPlanet && (mLoadBitmapTask == null)) {
             mCategoryFiltersAdapter.removeTinyPlanet();
         }
-        final View loading = findViewById(R.id.loading);
-        loading.setVisibility(View.GONE);
+        stopLoadingIndicator();
     }
 
     public void setupMasterImage() {
@@ -1148,7 +1271,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
     }
 
     public void showDefaultImageView() {
-        hideInformationPanel();
         mEditorPlaceHolder.hide();
         mImageShow.setVisibility(View.VISIBLE);
         MasterImage.getImage().setCurrentFilter(null);
@@ -1267,7 +1389,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         return mSelectedImageUri;
     }
 
-    public void setHandlesSwipeForView(View view, float startY) {
+    public void setHandlesSwipeForView(View view, float startX, float startY) {
         if (view != null) {
             mHandlingSwipeButton = true;
         } else {
@@ -1276,25 +1398,42 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         mHandledSwipeView = view;
         int[] location = new int[2];
         view.getLocationInWindow(location);
+        mSwipeStartX = location[0] + startX;
         mSwipeStartY = location[1] + startY;
     }
 
     public boolean dispatchTouchEvent (MotionEvent ev) {
         if (mHandlingSwipeButton) {
+            int direction = CategoryView.HORIZONTAL;
+            if (mHandledSwipeView instanceof CategoryView) {
+                direction = ((CategoryView) mHandledSwipeView).getOrientation();
+            }
             if (ev.getActionMasked() == MotionEvent.ACTION_MOVE) {
                 float delta = ev.getY() - mSwipeStartY;
-                mHandledSwipeView.setTranslationY(delta);
+                float distance = mHandledSwipeView.getHeight();
+                if (direction == CategoryView.VERTICAL) {
+                    delta = ev.getX() - mSwipeStartX;
+                    mHandledSwipeView.setTranslationX(delta);
+                    distance = mHandledSwipeView.getWidth();
+                } else {
+                    mHandledSwipeView.setTranslationY(delta);
+                }
                 delta = Math.abs(delta);
-                float transparency = Math.min(1, delta / mHandledSwipeView.getHeight());
+                float transparency = Math.min(1, delta / distance);
                 mHandledSwipeView.setAlpha(1.f - transparency);
                 mHandledSwipeViewLastDelta = delta;
             }
             if (ev.getActionMasked() == MotionEvent.ACTION_CANCEL
                     || ev.getActionMasked() == MotionEvent.ACTION_UP) {
+                mHandledSwipeView.setTranslationX(0);
                 mHandledSwipeView.setTranslationY(0);
                 mHandledSwipeView.setAlpha(1.f);
                 mHandlingSwipeButton = false;
-                if (mHandledSwipeViewLastDelta > mHandledSwipeView.getHeight()) {
+                float distance = mHandledSwipeView.getHeight();
+                if (direction == CategoryView.VERTICAL) {
+                    distance = mHandledSwipeView.getWidth();
+                }
+                if (mHandledSwipeViewLastDelta > distance) {
                     ((SwipableView) mHandledSwipeView).delete();
                 }
             }
@@ -1302,4 +1441,39 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         }
         return super.dispatchTouchEvent(ev);
     }
+
+    public Point mHintTouchPoint = new Point();
+
+    public Point hintTouchPoint(View view) {
+        int location[] = new int[2];
+        view.getLocationOnScreen(location);
+        int x = mHintTouchPoint.x - location[0];
+        int y = mHintTouchPoint.y - location[1];
+        return new Point(x, y);
+    }
+
+    public void startTouchAnimation(View target, float x, float y) {
+        final CategorySelected hint =
+                (CategorySelected) findViewById(R.id.categorySelectedIndicator);
+        int location[] = new int[2];
+        target.getLocationOnScreen(location);
+        mHintTouchPoint.x = (int) (location[0] + x);
+        mHintTouchPoint.y = (int) (location[1] + y);
+        int locationHint[] = new int[2];
+        ((View)hint.getParent()).getLocationOnScreen(locationHint);
+        int dx = (int) (x - (hint.getWidth())/2);
+        int dy = (int) (y - (hint.getHeight())/2);
+        hint.setTranslationX(location[0] - locationHint[0] + dx);
+        hint.setTranslationY(location[1] - locationHint[1] + dy);
+        hint.setVisibility(View.VISIBLE);
+        hint.animate().scaleX(2).scaleY(2).alpha(0).withEndAction(new Runnable() {
+            @Override
+            public void run() {
+                hint.setVisibility(View.INVISIBLE);
+                hint.setScaleX(1);
+                hint.setScaleY(1);
+                hint.setAlpha(1);
+            }
+        });
+    }
 }