limitations under the License.
-->
-<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
+ android:id="@+id/imageStatePanel"
+ android:layout_width="200dip"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:visibility="invisible"
+ android:layout_gravity="right">
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="@android:color/transparent"
+ android:gravity="center"
+ android:padding="2dip"
+ android:text="@string/imageState"
+ android:textColor="@android:color/white"
+ android:textSize="24sp"
+ android:textStyle="bold" />
+
+ <ListView
+ android:id="@+id/imageStateList"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1" >
+ </ListView>
+ </LinearLayout>
+
+ <LinearLayout
android:id="@+id/historyPanel"
android:layout_width="200dip"
android:layout_height="match_parent"
android:orientation="vertical"
- android:visibility="invisible" >
+ android:visibility="invisible"
+ android:layout_gravity="right">
<TextView
android:layout_width="match_parent"
android:orientation="horizontal" >
<Button
+ android:gravity="center"
android:id="@+id/resetOperationsButton"
style="@style/FilterShowHistoryButton"
android:text="@string/reset" />
<Button
android:id="@+id/saveOperationsButton"
style="@style/FilterShowHistoryButton"
+ android:visibility="gone"
android:text="@string/save" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
-</AbsoluteLayout>
\ No newline at end of file
+</FrameLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:background="@drawable/filtershow_button_background">
+
+ <TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/imagestate_label"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:gravity="left"
+ android:padding="10dip"
+ android:textSize="16dip" >
+ </TextView>
+
+ <TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/imagestate_parameter"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:gravity="right"
+ android:padding="10dip"
+ android:textSize="16dip"
+ android:textStyle="bold" >
+ </TextView>
+
+</LinearLayout>
\ No newline at end of file
<item
android:id="@+id/undoButton"
android:icon="@drawable/filtershow_button_undo"
- android:showAsAction="always"
+ android:showAsAction="never"
android:title="@string/filtershow_undo"/>
<item
android:id="@+id/redoButton"
android:icon="@drawable/filtershow_button_redo"
- android:showAsAction="always"
+ android:showAsAction="never"
android:title="@string/filtershow_redo"/>
<item
android:id="@+id/operationsButton"
android:icon="@drawable/filtershow_button_operations"
- android:showAsAction="ifRoom"
+ android:showAsAction="never"
android:title="@string/show_history_panel"/>
<item
+ android:id="@+id/showImageStateButton"
+ android:showAsAction="never"
+ android:title="@string/show_imagestate_panel" />
+ <item
android:id="@+id/menu_settings"
android:enabled="false"
+ android:showAsAction="never"
android:orderInCategory="100"
android:title="@string/menu_settings"/>
<resources>
+ <!-- Name for the image editor activity [CHAR LIMIT=NONE]-->
<string name="app_name">FilterShow</string>
- <string name="menu_settings">Settings</string>
+ <!-- Title for the image editor activity [CHAR LIMIT=NONE]-->
<string name="title_activity_filter_show">FilterShowActivity</string>
- <string name="save">Save</string>
+
+ <!-- actionbar menu -->
+
+ <!-- Text for the actionbar confirmation button [CHAR LIMIT=20] -->
<string name="done">Done</string>
- <string name="history">History</string>
+ <!-- Text for the undo menu item [CHAR LIMIT=20] -->
+ <string name="filtershow_undo">Undo</string>
+ <!-- Text for redo menu item [CHAR LIMIT=20] -->
+ <string name="filtershow_redo">Redo</string>
+ <!-- Text for the history panel menu item [CHAR LIMIT=20] -->
<string name="show_history_panel">Show History</string>
+ <!-- Text for the history panel menu item [CHAR LIMIT=20] -->
<string name="hide_history_panel">Hide History</string>
+ <!-- Text for the image state panel menu item [CHAR LIMIT=20] -->
+ <string name="show_imagestate_panel">Show Image State</string>
+ <!-- Text for the image state panel menu item [CHAR LIMIT=20] -->
+ <string name="hide_imagestate_panel">Hide Image State</string>
+ <!-- Name for the overflow menu item for settings [CHAR LIMIT=20] -->
+ <string name="menu_settings">Settings</string>
+
+ <!-- History Panel -->
+
+ <!-- Text for the history panel title [CHAR LIMIT=50] -->
+ <string name="history">History</string>
+ <!-- Text for the history panel reset button [CHAR LIMIT=20]-->
<string name="reset">Reset</string>
- <string name="filtershow_undo">Undo</string>
- <string name="filtershow_redo">Redo</string>
- <string name="straighten">Straighten</string>
- <string name="crop">Crop</string>
- <string name="rotate">Rotate</string>
- <string name="flip">Flip</string>
- <string name="vignette">Vignette</string>
- <string name="curvesRGB">Curves</string>
- <string name="curvesRed">Curves (Red)</string>
- <string name="curvesGreen">Curves (Green)</string>
- <string name="curvesBlue">Curves (Blue)</string>
+
+ <!-- Image state panel -->
+
+ <!-- Text for the image state panel title [CHAR LIMIT=50] -->
+ <string name="imageState">Current Image State</string>
+
+ <!-- Filters buttons -->
+
+ <!-- Label for the exposure filter button [CHAR LIMIT=15] -->
+ <string name="exposure">Exposure</string>
+ <!-- Label for the sharpen filter button [CHAR LIMIT=15] -->
<string name="sharpen">Sharpen</string>
+ <!-- Label for the contrast filter button [CHAR LIMIT=15] -->
<string name="contrast">Contrast</string>
+ <!-- Label for the vibrance filter button [CHAR LIMIT=15] -->
<string name="vibrance">Vibrance</string>
- <string name="exposure">Exposure</string>
+ <!-- Label for the saturation filter button [CHAR LIMIT=15] -->
<string name="saturation">Saturation</string>
+ <!-- Label for the tint filter button [CHAR LIMIT=15] -->
<string name="tint">Tint</string>
- <string name="shadow_recovery">Shadow Recovery</string>
- <string name="curves_channel">Channel</string>
+ <!-- Label for the shadow recovery filter button [CHAR LIMIT=15] -->
+ <string name="shadow_recovery">Shadows</string>
+ <!-- Label for the curves filter button [CHAR LIMIT=15] -->
+ <string name="curvesRGB">Curves</string>
+ <!-- Label for the vignette filter button [CHAR LIMIT=15] -->
+ <string name="vignette">Vignette</string>
+
+ <!-- Labels for the curves tool -->
+
+ <!-- Label for the curves tool, all channels (RGB) [CHAR LIMIT=3] -->
<string name="curves_channel_rgb">RGB</string>
+ <!-- Label for the curves tool, Red color channel [CHAR LIMIT=10] -->
<string name="curves_channel_red">Red</string>
+ <!-- Label for the curves tool, Green color channel [CHAR LIMIT=10] -->
<string name="curves_channel_green">Green</string>
+ <!-- Label for the curves tool, Blue color channel [CHAR LIMIT=10] -->
<string name="curves_channel_blue">Blue</string>
</resources>
\ No newline at end of file
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
+import android.widget.FrameLayout;
+import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
protected static final boolean ANIMATE_PANELS = false;
private boolean mShowingHistoryPanel = false;
+ private boolean mShowingImageStatePanel = false;
+
private Vector<ImageShow> mImageViews = new Vector<ImageShow>();
private Vector<View> mListViews = new Vector<View>();
private Vector<ImageButton> mBottomPanelButtons = new Vector<ImageButton>();
createOnClickResetOperationsButton());
ListView operationsList = (ListView) findViewById(R.id.operationsList);
- operationsList.setAdapter(mImageShow.getListAdapter());
+ operationsList.setAdapter(mImageShow.getHistoryAdapter());
operationsList.setOnItemClickListener(this);
- mImageLoader.setAdapter((HistoryAdapter) mImageShow.getListAdapter());
+ ListView imageStateList = (ListView) findViewById(R.id.imageStateList);
+ imageStateList.setAdapter(mImageShow.getImageStateAdapter());
+ mImageLoader.setAdapter((HistoryAdapter) mImageShow.getHistoryAdapter());
fillListImages(listFilters);
fillListBorders(listBorders);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.filtershow_activity_menu, menu);
- MenuItem item = menu.findItem(R.id.operationsButton);
+ MenuItem showHistory = menu.findItem(R.id.operationsButton);
if (mShowingHistoryPanel) {
- item.setTitle(R.string.hide_history_panel);
+ showHistory.setTitle(R.string.hide_history_panel);
+ } else {
+ showHistory.setTitle(R.string.show_history_panel);
+ }
+ MenuItem showState = menu.findItem(R.id.showImageStateButton);
+ if (mShowingImageStatePanel) {
+ showState.setTitle(R.string.hide_imagestate_panel);
} else {
- item.setTitle(R.string.show_history_panel);
+ showState.setTitle(R.string.show_imagestate_panel);
}
return true;
}
switch (item.getItemId()) {
case R.id.undoButton: {
HistoryAdapter adapter = (HistoryAdapter) mImageShow
- .getListAdapter();
+ .getHistoryAdapter();
int position = adapter.undo();
mImageShow.onItemClick(position);
mImageShow.showToast("Undo");
}
case R.id.redoButton: {
HistoryAdapter adapter = (HistoryAdapter) mImageShow
- .getListAdapter();
+ .getHistoryAdapter();
int position = adapter.redo();
mImageShow.onItemClick(position);
mImageShow.showToast("Redo");
invalidateViews();
return true;
}
+ case R.id.showImageStateButton: {
+ toggleImageStatePanel();
+ return true;
+ }
case R.id.operationsButton: {
toggleHistoryPanel();
return true;
filter.setImageFilter(borders[i]);
filter.setController(this);
filter.setImageLoader(mImageLoader);
+ filter.setShowTitle(false);
listBorders.addView(filter);
}
}
}
// //////////////////////////////////////////////////////////////////////////////
+ // imageState panel...
+
+ private void toggleImageStatePanel() {
+ final View view = findViewById(R.id.mainPanel);
+ final View viewList = findViewById(R.id.imageStatePanel);
+
+ if (mShowingHistoryPanel) {
+ findViewById(R.id.historyPanel).setVisibility(View.INVISIBLE);
+ mShowingHistoryPanel = false;
+ }
+
+ if (!mShowingImageStatePanel) {
+ mShowingImageStatePanel = true;
+ view.animate().setDuration(200).x(-viewList.getWidth())
+ .withLayer().withEndAction(new Runnable() {
+ public void run() {
+ viewList.setAlpha(0);
+ viewList.setVisibility(View.VISIBLE);
+ viewList.animate().setDuration(100)
+ .alpha(1.0f).start();
+ }
+ }).start();
+ } else {
+ mShowingImageStatePanel = false;
+ viewList.setVisibility(View.INVISIBLE);
+ view.animate().setDuration(200).x(0).withLayer()
+ .start();
+ }
+ invalidateOptionsMenu();
+ }
+
+ // //////////////////////////////////////////////////////////////////////////////
// history panel...
private void toggleHistoryPanel() {
final View view = findViewById(R.id.mainPanel);
final View viewList = findViewById(R.id.historyPanel);
- View rootView = viewList.getRootView();
-
- // TODO: use a custom layout instead of absolutelayout...
- final AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) view
- .getLayoutParams();
- final AbsoluteLayout.LayoutParams lph = (AbsoluteLayout.LayoutParams) viewList
- .getLayoutParams();
- final int positionHistoryPanel = (int) (rootView.getWidth() - viewList
- .getWidth());
+
+ if (mShowingImageStatePanel) {
+ findViewById(R.id.imageStatePanel).setVisibility(View.INVISIBLE);
+ mShowingImageStatePanel = false;
+ }
+
if (!mShowingHistoryPanel) {
mShowingHistoryPanel = true;
view.animate().setDuration(200).x(-viewList.getWidth())
.withLayer().withEndAction(new Runnable() {
public void run() {
- view.setLayoutParams(lp);
- lph.x = positionHistoryPanel;
- viewList.setLayoutParams(lph);
viewList.setAlpha(0);
viewList.setVisibility(View.VISIBLE);
viewList.animate().setDuration(100)
mShowingHistoryPanel = false;
viewList.setVisibility(View.INVISIBLE);
view.animate().setDuration(200).x(0).withLayer()
- .withEndAction(new Runnable() {
- public void run() {
- lp.x = 0;
- view.setLayoutParams(lp);
- }
- }).start();
+ .start();
}
invalidateOptionsMenu();
}
private void resetHistory() {
HistoryAdapter adapter = (HistoryAdapter) mImageShow
- .getListAdapter();
+ .getHistoryAdapter();
adapter.reset();
ImagePreset original = new ImagePreset(adapter.getItem(0));
mImageShow.setImagePreset(original);
ImageFilterVignette vignette = new ImageFilterVignette();
ImagePreset copy = new ImagePreset(preset);
copy.add(vignette);
- copy.setHistoryName(vignette.name());
+ copy.setHistoryName(vignette.getName());
copy.setIsFx(false);
filter = copy.getFilter("Vignette");
mImageShow.setImagePreset(copy);
ImageFilterContrast contrast = new ImageFilterContrast();
ImagePreset copy = new ImagePreset(preset);
copy.add(contrast);
- copy.setHistoryName(contrast.name());
+ copy.setHistoryName(contrast.getName());
copy.setIsFx(false);
filter = copy.getFilter("Contrast");
mImageShow.setImagePreset(copy);
ImageFilterSaturated sat = new ImageFilterSaturated();
ImagePreset copy = new ImagePreset(preset);
copy.add(sat);
- copy.setHistoryName(sat.name());
+ copy.setHistoryName(sat.getName());
copy.setIsFx(false);
filter = copy.getFilter("Saturated");
mImageShow.setImagePreset(copy);
ImageFilterHue contrast = new ImageFilterHue();
ImagePreset copy = new ImagePreset(preset);
copy.add(contrast);
- copy.setHistoryName(contrast.name());
+ copy.setHistoryName(contrast.getName());
copy.setIsFx(false);
filter = copy.getFilter("Hue");
mImageShow.setImagePreset(copy);
ImageFilterHue contrast = new ImageFilterHue();
ImagePreset copy = new ImagePreset(preset);
copy.add(contrast);
- copy.setHistoryName(contrast.name());
+ copy.setHistoryName(contrast.getName());
copy.setIsFx(false);
filter = copy.getFilter("Hue");
mImageShow.setImagePreset(copy);
ImageFilterBrightness bright = new ImageFilterBrightness();
ImagePreset copy = new ImagePreset(preset);
copy.add(bright);
- copy.setHistoryName(bright.name());
+ copy.setHistoryName(bright.getName());
copy.setIsFx(false);
filter = copy.getFilter("Brightness");
mImageShow.setImagePreset(copy);
ImageFilterHue contrast = new ImageFilterHue();
ImagePreset copy = new ImagePreset(preset);
copy.add(contrast);
- copy.setHistoryName(contrast.name());
+ copy.setHistoryName(contrast.getName());
copy.setIsFx(false);
filter = copy.getFilter("Hue");
mImageShow.setImagePreset(copy);
ImagePreset oldPreset = mImageShow.getImagePreset();
ImagePreset copy = new ImagePreset(oldPreset);
// TODO: use a numerical constant instead.
- if (imageFilter.name().equalsIgnoreCase("Border")) {
+ if (imageFilter.getName().equalsIgnoreCase("Border")) {
copy.remove("Border");
copy.setHistoryName("Border");
}
copy.add(imageFilter);
+ mImageShow.setImagePreset(copy);
invalidateViews();
}
if (item != null) {
TextView itemView = (TextView) view.findViewById(R.id.rowTextView);
if (itemView != null) {
- // do whatever you want with your string and long
itemView.setText(item.historyName());
}
ImageView markView = (ImageView) view.findViewById(R.id.selectedMark);
--- /dev/null
+
+package com.android.gallery3d.filtershow;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.filters.ImageFilter;
+import com.android.gallery3d.filtershow.presets.ImagePreset;
+
+import android.content.Context;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+public class ImageStateAdapter extends ArrayAdapter<ImageFilter> {
+ private static final String LOGTAG = "ImageStateAdapter";
+
+ public ImageStateAdapter(Context context, int textViewResourceId) {
+ super(context, textViewResourceId);
+ }
+
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View view = convertView;
+ if (view == null) {
+ LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
+ Context.LAYOUT_INFLATER_SERVICE);
+ view = inflater.inflate(R.layout.filtershow_imagestate_row, null);
+ }
+ ImageFilter filter = getItem(position);
+ if (filter != null) {
+ TextView itemLabel = (TextView) view.findViewById(R.id.imagestate_label);
+ itemLabel.setText(filter.getName());
+ TextView itemParameter = (TextView) view.findViewById(R.id.imagestate_parameter);
+ itemParameter.setText("" + filter.getParameter());
+ }
+ return view;
+ }
+}
import java.util.Arrays;
public class ColorSpaceMatrix {
- private final float[] matrix = new float[16];
+ private final float[] mMatrix = new float[16];
private static final float RLUM = 0.3086f;
private static final float GLUM = 0.6094f;
private static final float BLUM = 0.0820f;
}
/**
+ * Copy constructor
+ *
+ * @param matrix
+ */
+ public ColorSpaceMatrix(ColorSpaceMatrix matrix) {
+ System.arraycopy(matrix.mMatrix, 0, mMatrix, 0, matrix.mMatrix.length);
+ }
+
+ /**
* get the matrix
*
* @return the internal matrix
*/
public float[] getMatrix() {
- return matrix;
+ return mMatrix;
}
/**
* set matrix to identity
*/
public void identity() {
- Arrays.fill(matrix, 0);
- matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1;
+ Arrays.fill(mMatrix, 0);
+ mMatrix[0] = mMatrix[5] = mMatrix[10] = mMatrix[15] = 1;
}
public void convertToLuminance() {
- matrix[0] = matrix[1] = matrix[2] = 0.3086f;
- matrix[4] = matrix[5] = matrix[6] = 0.6094f;
- matrix[8] = matrix[9] = matrix[10] = 0.0820f;
+ mMatrix[0] = mMatrix[1] = mMatrix[2] = 0.3086f;
+ mMatrix[4] = mMatrix[5] = mMatrix[6] = 0.6094f;
+ mMatrix[8] = mMatrix[9] = mMatrix[10] = 0.0820f;
}
private void multiply(float[] a)
for (y = 0; y < 4; y++) {
int y4 = y * 4;
for (x = 0; x < 4; x++) {
- temp[y4 + x] = matrix[y4 + 0] * a[x]
- + matrix[y4 + 1] * a[4 + x]
- + matrix[y4 + 2] * a[8 + x]
- + matrix[y4 + 3] * a[12 + x];
+ temp[y4 + x] = mMatrix[y4 + 0] * a[x]
+ + mMatrix[y4 + 1] * a[4 + x]
+ + mMatrix[y4 + 2] * a[8 + x]
+ + mMatrix[y4 + 3] * a[12 + x];
}
}
for (int i = 0; i < 16; i++)
- matrix[i] = temp[i];
+ mMatrix[i] = temp[i];
}
private void xRotateMatrix(float rs, float rc)
{
ColorSpaceMatrix c = new ColorSpaceMatrix();
- float[] tmp = c.matrix;
+ float[] tmp = c.mMatrix;
tmp[5] = rc;
tmp[6] = rs;
private void yRotateMatrix(float rs, float rc)
{
ColorSpaceMatrix c = new ColorSpaceMatrix();
- float[] tmp = c.matrix;
+ float[] tmp = c.mMatrix;
tmp[0] = rc;
tmp[2] = -rs;
private void zRotateMatrix(float rs, float rc)
{
ColorSpaceMatrix c = new ColorSpaceMatrix();
- float[] tmp = c.matrix;
+ float[] tmp = c.mMatrix;
tmp[0] = rc;
tmp[1] = rs;
private void zShearMatrix(float dx, float dy)
{
ColorSpaceMatrix c = new ColorSpaceMatrix();
- float[] tmp = c.matrix;
+ float[] tmp = c.mMatrix;
tmp[2] = dx;
tmp[6] = dy;
* @param s
*/
public void changeSaturation(float s) {
- matrix[0] = (1 - s) * RLUM + s;
- matrix[1] = (1 - s) * RLUM;
- matrix[2] = (1 - s) * RLUM;
- matrix[4] = (1 - s) * GLUM;
- matrix[5] = (1 - s) * GLUM + s;
- matrix[6] = (1 - s) * GLUM;
- matrix[8] = (1 - s) * BLUM;
- matrix[9] = (1 - s) * BLUM;
- matrix[10] = (1 - s) * BLUM + s;
+ mMatrix[0] = (1 - s) * RLUM + s;
+ mMatrix[1] = (1 - s) * RLUM;
+ mMatrix[2] = (1 - s) * RLUM;
+ mMatrix[4] = (1 - s) * GLUM;
+ mMatrix[5] = (1 - s) * GLUM + s;
+ mMatrix[6] = (1 - s) * GLUM;
+ mMatrix[8] = (1 - s) * BLUM;
+ mMatrix[9] = (1 - s) * BLUM;
+ mMatrix[10] = (1 - s) * BLUM + s;
}
/**
* @return computed red pixel value
*/
public float getRed(int r, int g, int b) {
- return r * matrix[0] + g * matrix[4] + b * matrix[8] + matrix[12];
+ return r * mMatrix[0] + g * mMatrix[4] + b * mMatrix[8] + mMatrix[12];
}
/**
* @return computed green pixel value
*/
public float getGreen(int r, int g, int b) {
- return r * matrix[1] + g * matrix[5] + b * matrix[9] + matrix[13];
+ return r * mMatrix[1] + g * mMatrix[5] + b * mMatrix[9] + mMatrix[13];
}
/**
* @return computed blue pixel value
*/
public float getBlue(int r, int g, int b) {
- return r * matrix[2] + g * matrix[6] + b * matrix[10] + matrix[14];
+ return r * mMatrix[2] + g * mMatrix[6] + b * mMatrix[10] + mMatrix[14];
}
private float getRedf(float r, float g, float b) {
- return r * matrix[0] + g * matrix[4] + b * matrix[8] + matrix[12];
+ return r * mMatrix[0] + g * mMatrix[4] + b * mMatrix[8] + mMatrix[12];
}
private float getGreenf(float r, float g, float b) {
- return r * matrix[1] + g * matrix[5] + b * matrix[9] + matrix[13];
+ return r * mMatrix[1] + g * mMatrix[5] + b * mMatrix[9] + mMatrix[13];
}
private float getBluef(float r, float g, float b) {
- return r * matrix[2] + g * matrix[6] + b * matrix[10] + matrix[14];
+ return r * mMatrix[2] + g * mMatrix[6] + b * mMatrix[10] + mMatrix[14];
}
}
import android.graphics.Bitmap;
-public class ImageFilter {
+public class ImageFilter implements Cloneable {
protected int mParameter = 0;
+ protected String mName = "Original";
- public String name() {
- return "Original";
+ @Override
+ public ImageFilter clone() throws CloneNotSupportedException {
+ ImageFilter filter = (ImageFilter) super.clone();
+ filter.setName(getName());
+ filter.setParameter(getParameter());
+ return filter;
}
- // TODO: maybe use clone instead?
- public ImageFilter copy() {
- ImageFilter filter = new ImageFilter();
- filter.setParameter(mParameter);
- return filter;
+ public void setName(String name) {
+ mName = name;
+ }
+
+ public String getName() {
+ return mName;
}
public void apply(Bitmap bitmap) {
// do nothing here, subclasses will implement filtering here
}
+ public int getParameter() {
+ return mParameter;
+ }
+
public void setParameter(int value) {
mParameter = value;
}
public boolean same(ImageFilter filter) {
- if (!filter.name().equalsIgnoreCase(name())) {
+ if (!filter.getName().equalsIgnoreCase(getName())) {
return false;
}
return true;
public class ImageFilterBW extends ImageFilter {
- public String name() {
- return "Black & White";
- }
-
- public ImageFilter copy() {
- return new ImageFilterBW();
+ public ImageFilterBW() {
+ mName = "Black & White";
}
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h);
public class ImageFilterBWBlue extends ImageFilter {
- public String name() {
- return "Black & White (Blue)";
- }
-
- public ImageFilter copy() {
- return new ImageFilterBWBlue();
+ public ImageFilterBWBlue() {
+ mName = "Black & White (Blue)";
}
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h);
public class ImageFilterBWGreen extends ImageFilter {
- public String name() {
- return "Black & White (Green)";
- }
-
- public ImageFilter copy() {
- return new ImageFilterBWGreen();
+ public ImageFilterBWGreen() {
+ mName = "Black & White (Green)";
}
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h);
public class ImageFilterBWRed extends ImageFilter {
- public String name() {
- return "Black & White (Red)";
- }
-
- public ImageFilter copy() {
- return new ImageFilterBWRed();
+ public ImageFilterBWRed() {
+ mName = "Black & White (Red)";
}
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h);
public class ImageFilterBorder extends ImageFilter {
Drawable mNinePatch = null;
- public ImageFilterBorder(Drawable ninePatch) {
- mNinePatch = ninePatch;
- }
-
- public String name() {
- return "Border";
+ @Override
+ public ImageFilter clone() throws CloneNotSupportedException {
+ ImageFilterBorder filter = (ImageFilterBorder) super.clone();
+ filter.setDrawable(mNinePatch);
+ return filter;
}
- public ImageFilter copy() {
- return new ImageFilterBorder(mNinePatch);
+ public ImageFilterBorder(Drawable ninePatch) {
+ mName = "Border";
+ mNinePatch = ninePatch;
}
public boolean same(ImageFilter filter) {
public class ImageFilterBrightness extends ImageFilter {
- public String name() {
- return "Brightness";
- }
-
- public ImageFilter copy() {
- return new ImageFilterBrightness();
+ public ImageFilterBrightness() {
+ mName = "Brightness";
}
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float bright);
public class ImageFilterContrast extends ImageFilter {
- public String name() {
- return "Contrast";
- }
-
- public ImageFilter copy() {
- return new ImageFilterContrast();
+ public ImageFilterContrast() {
+ mName = "Contrast";
}
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float strength);
private boolean mUseRed = true;
private boolean mUseGreen = true;
private boolean mUseBlue = true;
- private String mName = "Curves";
private Spline mSpline = null;
- public String name() {
- return mName;
+ public ImageFilterCurves() {
+ mName = "Curves";
}
- public void setName(String name) {
- mName = name;
+ @Override
+ public ImageFilter clone() throws CloneNotSupportedException {
+ ImageFilterCurves filter = (ImageFilterCurves) super.clone();
+ filter.setCurve(mCurve);
+ filter.setSpline(new Spline(mSpline));
+ return filter;
}
public void setUseRed(boolean value) {
return true;
}
- public ImageFilter copy() {
- ImageFilterCurves curves = new ImageFilterCurves();
- curves.setCurve(mCurve);
- curves.setName(mName);
- curves.setSpline(new Spline(mSpline));
- return curves;
- }
-
public void populateArray(int[] array) {
for (int i = 0; i < 256; i++) {
array[i] = (int) (mCurve[i]);
import android.graphics.Paint.Style;
import android.graphics.Shader.TileMode;
+import com.android.gallery3d.filtershow.ui.Spline;
+
public class ImageFilterGradient extends ImageFilter {
private Bitmap mGradientBitmap = null;
private int[] mColors = null;
private float[] mPositions = null;
- public String name() {
- return "Gradient";
+ public ImageFilterGradient() {
+ mName = "Gradient";
}
- public ImageFilter copy() {
- ImageFilterGradient gradient = new ImageFilterGradient();
+ @Override
+ public ImageFilter clone() throws CloneNotSupportedException {
+ ImageFilterGradient filter = (ImageFilterGradient) super.clone();
for (int i = 0; i < mColors.length; i++) {
- gradient.addColor(mColors[i], mPositions[i]);
+ filter.addColor(mColors[i], mPositions[i]);
}
- return gradient;
+ return filter;
}
public void addColor(int color, float position) {
import android.graphics.Bitmap;
public class ImageFilterHue extends ImageFilter {
- private ColorSpaceMatrix cmatrix = new ColorSpaceMatrix();
+ private ColorSpaceMatrix cmatrix = null;
- public String name() {
- return "Hue";
+ public ImageFilterHue() {
+ mName = "Hue";
+ cmatrix = new ColorSpaceMatrix();
}
- public ImageFilter copy() {
- return new ImageFilterHue();
+ @Override
+ public ImageFilter clone() throws CloneNotSupportedException {
+ ImageFilterHue filter = (ImageFilterHue) super.clone();
+ filter.cmatrix = new ColorSpaceMatrix(cmatrix);
+ return filter;
}
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float []matrix);
public class ImageFilterSaturated extends ImageFilter {
- public String name() {
- return "Saturated";
- }
-
- public ImageFilter copy() {
- return new ImageFilterSaturated();
+ public ImageFilterSaturated() {
+ mName = "Saturated";
}
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float saturation);
private float mRotation;
private float mZoomFactor;
- public String name() {
- return "Straighten";
+ public ImageFilterStraighten() {
+ mName = "Straighten";
}
- public void setRotation(float rotation) {
- mRotation = rotation;
+ @Override
+ public ImageFilter clone() throws CloneNotSupportedException {
+ ImageFilterStraighten filter = (ImageFilterStraighten) super.clone();
+ filter.mRotation = mRotation;
+ filter.mZoomFactor = mZoomFactor;
+ return filter;
}
- public void setRotationZoomFactor(float zoomFactor) {
+ public ImageFilterStraighten(float rotation, float zoomFactor) {
+ mRotation = rotation;
mZoomFactor = zoomFactor;
}
- public ImageFilterStraighten(float rotation, float zoomFactor) {
+ public void setRotation(float rotation) {
mRotation = rotation;
- mZoomFactor = zoomFactor;
}
- public ImageFilter copy() {
- return new ImageFilterStraighten(mRotation, mZoomFactor);
+ public void setRotationZoomFactor(float zoomFactor) {
+ mZoomFactor = zoomFactor;
}
public void apply(Bitmap bitmap) {
public class ImageFilterVignette extends ImageFilter {
- public String name() {
- return "Vignette";
- }
-
- public ImageFilter copy() {
- return new ImageFilterVignette();
+ public ImageFilterVignette() {
+ mName = "Vignette";
}
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float strength);
import com.android.gallery3d.filtershow.FilterShowActivity;
import com.android.gallery3d.filtershow.HistoryAdapter;
+import com.android.gallery3d.filtershow.ImageStateAdapter;
import com.android.gallery3d.filtershow.cache.ImageLoader;
import com.android.gallery3d.filtershow.filters.ImageFilter;
import com.android.gallery3d.filtershow.presets.ImagePreset;
protected SliderController mSliderController = new SliderController();
- private HistoryAdapter mAdapter = null;
+ private HistoryAdapter mHistoryAdapter = null;
+ private ImageStateAdapter mImageStateAdapter = null;
protected Rect mImageBounds = null;
protected float mImageRotation = 0;
if (mCurrentFilter != null) {
mCurrentFilter.setParameter(value);
}
- mImageLoader.resetImageForPreset(getImagePreset(), this);
+ if (mImagePreset != null) {
+ mImageLoader.resetImageForPreset(mImagePreset, this);
+ mImagePreset.fillImageStateAdapter(mImageStateAdapter);
+ }
invalidate();
}
public ImageShow(Context context, AttributeSet attrs) {
super(context, attrs);
mSliderController.setListener(this);
- mAdapter = new HistoryAdapter(context, R.layout.filtershow_history_operation_row,
+ mHistoryAdapter = new HistoryAdapter(context, R.layout.filtershow_history_operation_row,
R.id.rowTextView);
+ mImageStateAdapter = new ImageStateAdapter(context,
+ R.layout.filtershow_imagestate_row);
}
public ImageShow(Context context) {
super(context);
mSliderController.setListener(this);
- mAdapter = new HistoryAdapter(context, R.layout.filtershow_history_operation_row,
+ mHistoryAdapter = new HistoryAdapter(context, R.layout.filtershow_history_operation_row,
R.id.rowTextView);
}
}
public void setAdapter(HistoryAdapter adapter) {
- mAdapter = adapter;
+ mHistoryAdapter = adapter;
}
public void showToast(String text) {
if (mImageLoader != null) {
filteredImage = mImageLoader.getImageForPreset(this,
getImagePreset(), showHires());
-// Log.v(LOGTAG, "getImageForPreset " + getImagePreset() + " is: " + filteredImage);
}
if (filteredImage == null) {
public void setImagePreset(ImagePreset preset, boolean addToHistory) {
mImagePreset = preset;
if (getImagePreset() != null) {
-// Log.v(LOGTAG, "add " + getImagePreset().name() + " " + getImagePreset());
if (addToHistory) {
- mAdapter.insert(getImagePreset(), 0);
+ mHistoryAdapter.insert(getImagePreset(), 0);
}
getImagePreset().setEndpoint(this);
updateImage();
}
-// Log.v(LOGTAG, "invalidate from setImagePreset");
+ mImagePreset.fillImageStateAdapter(mImageStateAdapter);
invalidate();
}
public void updateFilteredImage(Bitmap bitmap) {
mFilteredImage = bitmap;
- // Log.v(LOGTAG, "invalidate from updateFilteredImage");
- // invalidate();
}
public void saveImage(FilterShowActivity filterShowActivity) {
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
mSliderController.onTouchEvent(event);
- // Log.v(LOGTAG, "invalidate from onTouchEvent");
invalidate();
return true;
}
// listview stuff
- public ArrayAdapter getListAdapter() {
- return mAdapter;
+ public ArrayAdapter getHistoryAdapter() {
+ return mHistoryAdapter;
+ }
+
+ public ArrayAdapter getImageStateAdapter() {
+ return mImageStateAdapter;
}
public void onItemClick(int position) {
- Log.v(LOGTAG, "Click on item " + position);
- Log.v(LOGTAG, "item " + position + " is " + mAdapter.getItem(position));
- setImagePreset(new ImagePreset(mAdapter.getItem(position)), false); // we
- // need
- // a
- // copy
- // from
- // the
- // history
- mAdapter.setCurrentPreset(position);
+ setImagePreset(new ImagePreset(mHistoryAdapter.getItem(position)), false);
+ // we need a copy from the history
+ mHistoryAdapter.setCurrentPreset(position);
}
public void showOriginal(boolean show) {
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.View;
import android.view.View.MeasureSpec;
public class ImageSmallFilter extends ImageShow implements View.OnClickListener {
+ private static final String LOGTAG = "ImageSmallFilter";
private FilterShowActivity mController = null;
private ImageFilter mImageFilter = null;
+ private boolean mShowTitle = true;
public ImageSmallFilter(Context context, AttributeSet attrs) {
super(context, attrs);
setMeasuredDimension(parentHeight, parentHeight);
}
- /*
- * protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- * setMeasuredDimension(256, 256); }
- */
-
public void onClick(View v) {
if (mController != null) {
if (mImageFilter != null) {
return mImageLoader.getOriginalBitmapSmall();
}
+ public void setShowTitle(boolean value) {
+ mShowTitle = value;
+ invalidate();
+ }
+
public boolean showTitle() {
- return true;
+ return mShowTitle;
}
public boolean showControls() {
import android.graphics.RectF;
import android.util.Log;
+import com.android.gallery3d.filtershow.ImageStateAdapter;
import com.android.gallery3d.filtershow.filters.ImageFilter;
import com.android.gallery3d.filtershow.filters.ImageFilterStraighten;
import com.android.gallery3d.filtershow.imageshow.ImageShow;
}
public ImagePreset(ImagePreset source) {
- for (int i = 0; i < source.mFilters.size(); i++) {
- add(source.mFilters.elementAt(i).copy());
+ try {
+ for (int i = 0; i < source.mFilters.size(); i++) {
+ add(source.mFilters.elementAt(i).clone());
+ }
+ } catch (java.lang.CloneNotSupportedException e) {
+ Log.v(LOGTAG, "Exception trying to clone: " + e);
}
mName = source.name();
mHistoryName = source.name();
// TODO
}
-// Log.v(LOGTAG, "applyGeometry with rotate " + mStraightenRotate + " and zoom "
- // + mStraightenZoom);
-
if (mStraightenRotate != 0) {
// TODO: keep the instances around
ImageFilter straighten = new ImageFilterStraighten(mStraightenRotate, mStraightenZoom);
return mHistoryName;
}
- public void add(ImageFilter preset) {
- mFilters.add(preset);
+ public void add(ImageFilter filter) {
+ mFilters.add(filter);
}
public void remove(String filterName) {
public ImageFilter getFilter(String name) {
for (int i = 0; i < mFilters.size(); i++) {
ImageFilter filter = mFilters.elementAt(i);
- if (filter.name().equalsIgnoreCase(name)) {
+ if (filter.getName().equalsIgnoreCase(name)) {
return filter;
}
}
ImageFilter borderFilter = null;
for (int i = 0; i < mFilters.size(); i++) {
ImageFilter filter = mFilters.elementAt(i);
- if (filter.name().equalsIgnoreCase("Border")) {
+ if (filter.getName().equalsIgnoreCase("Border")) {
// TODO don't use the name as an id
borderFilter = filter;
} else {
return bitmap;
}
- }
+ public void fillImageStateAdapter(ImageStateAdapter imageStateAdapter) {
+ if (imageStateAdapter == null) {
+ return;
+ }
+ imageStateAdapter.clear();
+ imageStateAdapter.addAll(mFilters);
+ imageStateAdapter.notifyDataSetChanged();
+ }
+
+}