Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit acc00f8f authored by nicolasroard's avatar nicolasroard
Browse files

Fix selected frame in looks and borders

Change-Id: Id1839a028f3044929043d7c910df30a1fcabdda1
parent ed60979e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -488,6 +488,12 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
        return mCurrentPanel;
    }

    public void updateCategories() {
        ImagePreset preset = mMasterImage.getPreset();
        mCategoryLooksAdapter.reflectImagePreset(preset);
        mCategoryBordersAdapter.reflectImagePreset(preset);
    }

    private class LoadBitmapTask extends AsyncTask<Uri, Boolean, Boolean> {
        int mBitmapSize;

+42 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ public class CategoryAdapter extends ArrayAdapter<Action> {
    private boolean mUseFilterIconButton = false;
    private int mSelectedPosition;
    int mCategory;
    private int mOrientation;

    public CategoryAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
@@ -67,8 +68,13 @@ public class CategoryAdapter extends ArrayAdapter<Action> {

    public void initializeSelection(int category) {
        mCategory = category;
        // TODO: fix this
        mSelectedPosition = -1;
        if (category == MainPanel.LOOKS) {
            mSelectedPosition = 0;
        }
        if (category == MainPanel.BORDERS) {
            mSelectedPosition = 0;
        }
    }

    @Override
@@ -95,10 +101,12 @@ public class CategoryAdapter extends ArrayAdapter<Action> {
            convertView = new CategoryView(getContext());
        }
        CategoryView view = (CategoryView) convertView;
        view.setOrientation(mOrientation);
        view.setAction(getItem(position), this);
        view.setLayoutParams(
                new ListView.LayoutParams(mItemWidth, mItemHeight));
        view.setTag(position);
        view.invalidate();
        return view;
    }

@@ -168,4 +176,37 @@ public class CategoryAdapter extends ArrayAdapter<Action> {
            }
        }
    }

    public void setOrientation(int orientation) {
        mOrientation = orientation;
    }

    public void reflectImagePreset(ImagePreset preset) {
        int selected = 0; // if nothing found, select "none" (first element)
        FilterRepresentation rep = null;
        if (mCategory == MainPanel.LOOKS) {
            int pos = preset.getPositionForType(FilterRepresentation.TYPE_FX);
            if (pos != -1) {
                rep = preset.getFilterRepresentation(pos);
            }
        } else if (mCategory == MainPanel.BORDERS) {
            int pos = preset.getPositionForType(FilterRepresentation.TYPE_BORDER);
            if (pos != -1) {
                rep = preset.getFilterRepresentation(pos);
            }
        }
        if (rep != null) {
            for (int i = 0; i < getCount(); i++) {
                if (rep.getName().equalsIgnoreCase(
                        getItem(i).getRepresentation().getName())) {
                    selected = i;
                }
            }
        }
        if (mSelectedPosition != selected) {
            mSelectedPosition = selected;
            this.notifyDataSetChanged();
        }

    }
}
+1 −0
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ public class CategoryPanel extends Fragment {
        View panelView = main.findViewById(R.id.listItems);
        if (panelView instanceof CategoryTrack) {
            CategoryTrack panel = (CategoryTrack) panelView;
            mAdapter.setOrientation(CategoryView.HORIZONTAL);
            mAdapter.setUseFilterIconButton(true);
            panel.setAdapter(mAdapter);
            mAdapter.setContainer(panel);
+18 −0
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@ package com.android.gallery3d.filtershow.category;

import android.content.Context;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import com.android.gallery3d.R;
@@ -27,6 +29,13 @@ public class CategoryTrack extends LinearLayout {

    private CategoryAdapter mAdapter;
    private int mElemSize;
    private DataSetObserver mDataSetObserver = new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            invalidate();
        }
    };

    public CategoryTrack(Context context, AttributeSet attrs) {
        super(context, attrs);
@@ -38,6 +47,7 @@ public class CategoryTrack extends LinearLayout {
        mAdapter = adapter;
        mAdapter.setItemWidth(mElemSize);
        mAdapter.setItemHeight(LayoutParams.MATCH_PARENT);
        mAdapter.registerDataSetObserver(mDataSetObserver);
        fillContent();
    }

@@ -51,4 +61,12 @@ public class CategoryTrack extends LinearLayout {
        requestLayout();
    }

    @Override
    public void invalidate() {
        for (int i = 0; i < this.getChildCount(); i++) {
            View child = getChildAt(i);
            child.invalidate();
        }
    }

}
+7 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ import com.android.gallery3d.filtershow.ui.SelectionRenderer;
public class CategoryView extends View implements View.OnClickListener {

    private static final String LOGTAG = "CategoryView";
    public static final int VERTICAL = 0;
    public static final int HORIZONTAL = 1;
    private Paint mPaint = new Paint();
    private Action mAction;
    private Rect mTextBounds = new Rect();
@@ -46,6 +48,7 @@ public class CategoryView extends View implements View.OnClickListener {
    private int mSelectionStroke;
    private Paint mBorderPaint;
    private int mBorderStroke;
    private int mOrientation = VERTICAL;

    public static void setTextSize(int size) {
        sTextSize = size;
@@ -129,4 +132,8 @@ public class CategoryView extends View implements View.OnClickListener {
        activity.showRepresentation(mAction.getRepresentation());
        mAdapter.setSelected(this);
    }

    public void setOrientation(int orientation) {
        mOrientation = orientation;
    }
}
Loading