├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── stealthcopter
│ │ └── colourmatrixexample
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── stealthcopter
│ │ │ └── colourmatrixexample
│ │ │ ├── ColorMatrixHelpers
│ │ │ ├── ColorMatrixAndSaturation.java
│ │ │ └── ColorMatrixPresets.java
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable
│ │ └── default_image.jpg
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── dialog_code.xml
│ │ ├── menu
│ │ └── menu_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_action_github.png
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── stealthcopter
│ └── colourmatrixexample
│ └── ExampleUnitTest.java
├── art
├── screenshot_001.png
├── screenshot_002.png
├── screenshot_003.png
├── screenshot_004.png
└── web_hi_res_512.png
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── readme.md
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.stealthcopter.colourmatrixexample"
8 | minSdkVersion 16
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.2.0'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.1'
29 | testCompile 'junit:junit:4.12'
30 | }
31 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/matthew/android/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/stealthcopter/colourmatrixexample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.stealthcopter.colourmatrixexample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.stealthcopter.colourmatrixexample", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stealthcopter/colourmatrixexample/ColorMatrixHelpers/ColorMatrixAndSaturation.java:
--------------------------------------------------------------------------------
1 | package com.stealthcopter.colourmatrixexample.ColorMatrixHelpers;
2 |
3 | /**
4 | * Created by matthew on 09/03/17.
5 | */
6 |
7 | public class ColorMatrixAndSaturation{
8 |
9 | float[] colorMatrix;
10 | Float saturation;
11 |
12 | public ColorMatrixAndSaturation(float[] colorMatrix, Float saturation){
13 | this.colorMatrix = colorMatrix;
14 | this.saturation = saturation;
15 | }
16 |
17 | public float[] getColorMatrix() {
18 | return colorMatrix;
19 | }
20 |
21 | public Float getSaturation() {
22 | return saturation;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stealthcopter/colourmatrixexample/ColorMatrixHelpers/ColorMatrixPresets.java:
--------------------------------------------------------------------------------
1 | package com.stealthcopter.colourmatrixexample.ColorMatrixHelpers;
2 |
3 | /**
4 | * Created by matthew on 09/03/17.
5 | */
6 |
7 | public class ColorMatrixPresets {
8 |
9 | private static final String NAME_IDENTITY = "Identify (Reset)";
10 | private static final String NAME_BLACK_AND_WHITE = "Greyscale";
11 | private static final String NAME_INVERT = "Invert";
12 |
13 | public static String[] getPresetNames() {
14 | return new String[]{NAME_IDENTITY, NAME_BLACK_AND_WHITE, NAME_INVERT};
15 | }
16 |
17 | public static ColorMatrixAndSaturation getPresetColorMatrix(String name) {
18 | switch (name) {
19 | case NAME_BLACK_AND_WHITE:
20 | return new ColorMatrixAndSaturation(new float[]{
21 | 1, 0, 0, 0, 0,
22 | 0, 1, 0, 0, 0,
23 | 0, 0, 1, 0, 0,
24 | 0, 0, 0, 1, 0
25 | }, 0f);
26 | case NAME_INVERT:
27 | return new ColorMatrixAndSaturation(new float[]{
28 | -1, 0, 0, 0, 255,
29 | 0, -1, 0, 0, 255,
30 | 0, 0, -1, 0, 255,
31 | 0, 0, 0, 1, 0
32 | }, null);
33 | case NAME_IDENTITY:
34 | default:
35 | return new ColorMatrixAndSaturation(new float[]{
36 | 1, 0, 0, 0, 0,
37 | 0, 1, 0, 0, 0,
38 | 0, 0, 1, 0, 0,
39 | 0, 0, 0, 1, 0
40 | }, null);
41 | }
42 |
43 |
44 | }
45 |
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stealthcopter/colourmatrixexample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.stealthcopter.colourmatrixexample;
2 |
3 | import android.content.ClipData;
4 | import android.content.ClipboardManager;
5 | import android.content.Context;
6 | import android.content.DialogInterface;
7 | import android.content.Intent;
8 | import android.graphics.ColorMatrix;
9 | import android.graphics.ColorMatrixColorFilter;
10 | import android.net.Uri;
11 | import android.os.Bundle;
12 | import android.support.annotation.Nullable;
13 | import android.support.v7.app.AlertDialog;
14 | import android.support.v7.app.AppCompatActivity;
15 | import android.text.Editable;
16 | import android.text.TextWatcher;
17 | import android.view.LayoutInflater;
18 | import android.view.Menu;
19 | import android.view.MenuInflater;
20 | import android.view.MenuItem;
21 | import android.view.View;
22 | import android.widget.ArrayAdapter;
23 | import android.widget.CheckBox;
24 | import android.widget.CompoundButton;
25 | import android.widget.EditText;
26 | import android.widget.ImageView;
27 | import android.widget.TextView;
28 | import android.widget.Toast;
29 |
30 | import com.stealthcopter.colourmatrixexample.ColorMatrixHelpers.ColorMatrixAndSaturation;
31 | import com.stealthcopter.colourmatrixexample.ColorMatrixHelpers.ColorMatrixPresets;
32 |
33 | public class MainActivity extends AppCompatActivity implements TextWatcher, View.OnClickListener {
34 |
35 | private EditText editTextR1;
36 | private EditText editTextR2;
37 | private EditText editTextR3;
38 | private EditText editTextR4;
39 | private EditText editTextG1;
40 | private EditText editTextG2;
41 | private EditText editTextG3;
42 | private EditText editTextG4;
43 | private EditText editTextB1;
44 | private EditText editTextB2;
45 | private EditText editTextB3;
46 | private EditText editTextB4;
47 | private EditText editTextA1;
48 | private EditText editTextA2;
49 | private EditText editTextA3;
50 | private EditText editTextA4;
51 | private EditText editTextW1;
52 | private EditText editTextW2;
53 | private EditText editTextW3;
54 | private EditText editTextW4;
55 | private EditText editTextSaturation;
56 |
57 | private ImageView imageView;
58 | private CheckBox saturationCheckbox;
59 |
60 | @Override
61 | protected void onCreate(Bundle savedInstanceState) {
62 | super.onCreate(savedInstanceState);
63 | setContentView(R.layout.activity_main);
64 |
65 | imageView = (ImageView) findViewById(R.id.imageView);
66 |
67 | editTextR1 = (EditText) findViewById(R.id.editTextR1);
68 | editTextR2 = (EditText) findViewById(R.id.editTextR2);
69 | editTextR3 = (EditText) findViewById(R.id.editTextR3);
70 | editTextR4 = (EditText) findViewById(R.id.editTextR4);
71 | editTextG1 = (EditText) findViewById(R.id.editTextG1);
72 | editTextG2 = (EditText) findViewById(R.id.editTextG2);
73 | editTextG3 = (EditText) findViewById(R.id.editTextG3);
74 | editTextG4 = (EditText) findViewById(R.id.editTextG4);
75 | editTextB1 = (EditText) findViewById(R.id.editTextB1);
76 | editTextB2 = (EditText) findViewById(R.id.editTextB2);
77 | editTextB3 = (EditText) findViewById(R.id.editTextB3);
78 | editTextB4 = (EditText) findViewById(R.id.editTextB4);
79 | editTextA1 = (EditText) findViewById(R.id.editTextA1);
80 | editTextA2 = (EditText) findViewById(R.id.editTextA2);
81 | editTextA3 = (EditText) findViewById(R.id.editTextA3);
82 | editTextA4 = (EditText) findViewById(R.id.editTextA4);
83 | editTextW1 = (EditText) findViewById(R.id.editTextW1);
84 | editTextW2 = (EditText) findViewById(R.id.editTextW2);
85 | editTextW3 = (EditText) findViewById(R.id.editTextW3);
86 | editTextW4 = (EditText) findViewById(R.id.editTextW4);
87 | editTextSaturation = (EditText) findViewById(R.id.editTextSaturation);
88 | saturationCheckbox = (CheckBox) findViewById(R.id.saturationCheckbox);
89 |
90 | editTextR1.addTextChangedListener(this);
91 | editTextR2.addTextChangedListener(this);
92 | editTextR3.addTextChangedListener(this);
93 | editTextR4.addTextChangedListener(this);
94 | editTextG1.addTextChangedListener(this);
95 | editTextG2.addTextChangedListener(this);
96 | editTextG3.addTextChangedListener(this);
97 | editTextG4.addTextChangedListener(this);
98 | editTextB1.addTextChangedListener(this);
99 | editTextB2.addTextChangedListener(this);
100 | editTextB3.addTextChangedListener(this);
101 | editTextB4.addTextChangedListener(this);
102 | editTextA1.addTextChangedListener(this);
103 | editTextA2.addTextChangedListener(this);
104 | editTextA3.addTextChangedListener(this);
105 | editTextA4.addTextChangedListener(this);
106 | editTextW1.addTextChangedListener(this);
107 | editTextW2.addTextChangedListener(this);
108 | editTextW3.addTextChangedListener(this);
109 | editTextW4.addTextChangedListener(this);
110 | editTextSaturation.addTextChangedListener(this);
111 |
112 | findViewById(R.id.presetButton).setOnClickListener(this);
113 | findViewById(R.id.getCodeButton).setOnClickListener(this);
114 |
115 | saturationCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
116 | @Override
117 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
118 | editTextSaturation.setVisibility(isChecked ? View.VISIBLE : View.GONE);
119 |
120 | setColourFilter();
121 | }
122 | });
123 |
124 | setColourFilter();
125 | }
126 |
127 | @Override
128 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {
129 |
130 | }
131 |
132 | @Override
133 | public void onTextChanged(CharSequence s, int start, int before, int count) {
134 |
135 | }
136 |
137 | @Override
138 | public void afterTextChanged(Editable s) {
139 | setColourFilter();
140 | }
141 |
142 | @Nullable
143 | private float[] getColourMatrix() {
144 | try {
145 | return new float[]{
146 | Float.valueOf(editTextR1.getText().toString()), Float.valueOf(editTextG1.getText().toString()), Float.valueOf(editTextB1.getText().toString()), Float.valueOf(editTextA1.getText().toString()), Float.valueOf(editTextW1.getText().toString()),
147 | Float.valueOf(editTextR2.getText().toString()), Float.valueOf(editTextG2.getText().toString()), Float.valueOf(editTextB2.getText().toString()), Float.valueOf(editTextA2.getText().toString()), Float.valueOf(editTextW2.getText().toString()),
148 | Float.valueOf(editTextR3.getText().toString()), Float.valueOf(editTextG3.getText().toString()), Float.valueOf(editTextB3.getText().toString()), Float.valueOf(editTextA3.getText().toString()), Float.valueOf(editTextW3.getText().toString()),
149 | Float.valueOf(editTextR4.getText().toString()), Float.valueOf(editTextG4.getText().toString()), Float.valueOf(editTextB4.getText().toString()), Float.valueOf(editTextA4.getText().toString()), Float.valueOf(editTextW4.getText().toString())
150 | };
151 | } catch (NumberFormatException e) {
152 | e.printStackTrace();
153 | }
154 | return null;
155 | }
156 |
157 | private void setColorMatrix(ColorMatrixAndSaturation colorMatrixAndSaturation) {
158 |
159 | float[] colorMatrix = colorMatrixAndSaturation.getColorMatrix();
160 |
161 | if (colorMatrix.length != 20) {
162 | throw new IllegalArgumentException("Error colorMatrix must be of length 20");
163 | }
164 |
165 | int i = 0;
166 |
167 | editTextR1.setText(String.valueOf(colorMatrix[i++]));
168 | editTextG1.setText(String.valueOf(colorMatrix[i++]));
169 | editTextB1.setText(String.valueOf(colorMatrix[i++]));
170 | editTextA1.setText(String.valueOf(colorMatrix[i++]));
171 | editTextW1.setText(String.valueOf(colorMatrix[i++]));
172 | editTextR2.setText(String.valueOf(colorMatrix[i++]));
173 | editTextG2.setText(String.valueOf(colorMatrix[i++]));
174 | editTextB2.setText(String.valueOf(colorMatrix[i++]));
175 | editTextA2.setText(String.valueOf(colorMatrix[i++]));
176 | editTextW2.setText(String.valueOf(colorMatrix[i++]));
177 | editTextR3.setText(String.valueOf(colorMatrix[i++]));
178 | editTextG3.setText(String.valueOf(colorMatrix[i++]));
179 | editTextB3.setText(String.valueOf(colorMatrix[i++]));
180 | editTextA3.setText(String.valueOf(colorMatrix[i++]));
181 | editTextW3.setText(String.valueOf(colorMatrix[i++]));
182 | editTextR4.setText(String.valueOf(colorMatrix[i++]));
183 | editTextG4.setText(String.valueOf(colorMatrix[i++]));
184 | editTextB4.setText(String.valueOf(colorMatrix[i++]));
185 | editTextA4.setText(String.valueOf(colorMatrix[i++]));
186 | editTextW4.setText(String.valueOf(colorMatrix[i]));
187 |
188 | if (colorMatrixAndSaturation.getSaturation() == null) {
189 | saturationCheckbox.setChecked(false);
190 | } else {
191 | editTextSaturation.setText(String.valueOf(colorMatrixAndSaturation.getSaturation()));
192 | saturationCheckbox.setChecked(true);
193 | }
194 | }
195 |
196 | private void setColourFilter() {
197 |
198 | float[] colorMatrix = getColourMatrix();
199 |
200 | if (colorMatrix == null) {
201 | return;
202 | }
203 |
204 | ColorMatrix matrix = new ColorMatrix();
205 | matrix.set(colorMatrix);
206 |
207 | if (saturationCheckbox.isChecked()) {
208 |
209 | float sat = 0.5f;
210 |
211 | try {
212 | sat = Float.valueOf(editTextSaturation.getText().toString());
213 | } catch (NumberFormatException e) {
214 | e.printStackTrace();
215 | }
216 |
217 | ColorMatrix saturationMatrix = new ColorMatrix();
218 | saturationMatrix.setSaturation(sat);
219 |
220 | // Only set saturation if checkbox is ticked
221 | matrix.postConcat(saturationMatrix);
222 | }
223 |
224 | ColorMatrixColorFilter cf = new ColorMatrixColorFilter(matrix);
225 | imageView.setColorFilter(cf);
226 | }
227 |
228 | private void showGetCodeDialog() {
229 |
230 | float[] colorMatrix = getColourMatrix();
231 |
232 | if (colorMatrix == null) {
233 | Toast.makeText(this, "Error creating colour matrix", Toast.LENGTH_SHORT).show();
234 | return;
235 | }
236 |
237 | int saturation = 1;
238 |
239 | try {
240 | Integer.parseInt(editTextSaturation.getText().toString());
241 | } catch (NumberFormatException e) {
242 | e.printStackTrace();
243 | Toast.makeText(this, "Invalid saturation value", Toast.LENGTH_SHORT).show();
244 | return;
245 | }
246 |
247 | AlertDialog.Builder builder = new AlertDialog.Builder(this);
248 | builder.setTitle("Get Code");
249 |
250 | final View view = LayoutInflater.from(this).inflate(R.layout.dialog_code, null);
251 |
252 | int i = 0;
253 | final TextView codeText = (TextView) view.findViewById(R.id.codeText);
254 | codeText.setTextIsSelectable(true);
255 |
256 | StringBuilder sb = new StringBuilder();
257 |
258 | sb.append("\nColorMatrix matrix = new ColorMatrix();\n" + "\n" + "matrix.set(new float[] {\n ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(",\n").append(" ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(",\n").append(" ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(",\n").append(" ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i++]).append(", ").append(colorMatrix[i]).append("\n").append("});\n").append("\n");
259 |
260 | if (saturationCheckbox.isChecked()) {
261 | sb.append("\n//Post apply the saturation matrix\nColorMatrix saturationMatrix \n = new ColorMatrix();\nsaturationMatrix.setSaturation(").append(saturation).append(");\nmatrix.postConcat(saturationMatrix);\n");
262 | }
263 |
264 | sb.append("\nColorMatrixColorFilter cf \n = new ColorMatrixColorFilter(matrix);\n\nimageView.setColorFilter(cf);");
265 |
266 | codeText.setText(sb.toString());
267 |
268 | builder.setView(view);
269 |
270 | builder.setPositiveButton("Copy to clipboard", new DialogInterface.OnClickListener() {
271 | @Override
272 | public void onClick(DialogInterface dialog, int which) {
273 |
274 | ClipboardManager clipboard = (ClipboardManager)
275 | getSystemService(Context.CLIPBOARD_SERVICE);
276 |
277 | ClipData clip = ClipData.newPlainText("simple text", codeText.getText().toString());
278 | clipboard.setPrimaryClip(clip);
279 |
280 | Toast.makeText(MainActivity.this, "Copied", Toast.LENGTH_SHORT).show();
281 | }
282 | });
283 |
284 | AlertDialog dialog = builder.create();
285 | dialog.show();
286 | }
287 |
288 | private void showPresetDialog() {
289 | AlertDialog.Builder builder = new AlertDialog.Builder(this);
290 | builder.setTitle("Select Preset");
291 |
292 | final ArrayAdapter arrayAdapter = new ArrayAdapter<>(this, android.R.layout.select_dialog_singlechoice);
293 |
294 | for (String presetName : ColorMatrixPresets.getPresetNames()) {
295 | arrayAdapter.add(presetName);
296 | }
297 |
298 | builder.setNegativeButton("cancel", null);
299 | builder.setCancelable(true);
300 | builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
301 | @Override
302 | public void onClick(DialogInterface dialog, int which) {
303 | String strName = arrayAdapter.getItem(which);
304 | setColorMatrix(ColorMatrixPresets.getPresetColorMatrix(strName));
305 | }
306 | });
307 | builder.show();
308 | }
309 |
310 | @Override
311 | public boolean onCreateOptionsMenu(Menu menu) {
312 | MenuInflater inflater = getMenuInflater();
313 | inflater.inflate(R.menu.menu_main, menu);
314 | return true;
315 | }
316 |
317 | @Override
318 | public boolean onOptionsItemSelected(MenuItem item) {
319 | if (item.getItemId() == R.id.action_github) {
320 | Intent i = new Intent(Intent.ACTION_VIEW);
321 | i.setData(Uri.parse(getString(R.string.github_url)));
322 | startActivity(i);
323 | return true;
324 | } else {
325 | return super.onOptionsItemSelected(item);
326 | }
327 | }
328 |
329 | @Override
330 | public void onClick(View v) {
331 | switch (v.getId()) {
332 | case R.id.presetButton:
333 | showPresetDialog();
334 | break;
335 | case R.id.getCodeButton:
336 | showGetCodeDialog();
337 | break;
338 | }
339 | }
340 | }
341 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/default_image.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stealthcopter/InteractiveColorMatrixDemo/1303b59be21cfde43832b16c326727ed993a62ca/app/src/main/res/drawable/default_image.jpg
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
15 |
16 |
20 |
21 |
25 |
26 |
31 |
32 |
36 |
37 |
40 |
41 |
46 |
47 |
52 |
53 |
58 |
59 |
64 |
65 |
70 |
71 |
76 |
77 |
78 |
79 |
82 |
83 |
88 |
89 |
93 |
94 |
98 |
99 |
103 |
104 |
108 |
109 |
113 |
114 |
115 |
116 |
119 |
120 |
125 |
126 |
130 |
131 |
135 |
136 |
140 |
141 |
145 |
146 |
150 |
151 |
152 |
153 |
156 |
157 |
162 |
163 |
167 |
168 |
172 |
173 |
177 |
178 |
182 |
183 |
187 |
188 |
189 |
190 |
193 |
194 |
199 |
200 |
204 |
205 |
209 |
210 |
214 |
215 |
219 |
220 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
236 |
237 |
245 |
246 |
253 |
254 |
255 |
256 |
260 |
261 |
267 |
268 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_code.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stealthcopter/InteractiveColorMatrixDemo/1303b59be21cfde43832b16c326727ed993a62ca/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stealthcopter/InteractiveColorMatrixDemo/1303b59be21cfde43832b16c326727ed993a62ca/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_action_github.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stealthcopter/InteractiveColorMatrixDemo/1303b59be21cfde43832b16c326727ed993a62ca/app/src/main/res/mipmap-xhdpi/ic_action_github.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stealthcopter/InteractiveColorMatrixDemo/1303b59be21cfde43832b16c326727ed993a62ca/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stealthcopter/InteractiveColorMatrixDemo/1303b59be21cfde43832b16c326727ed993a62ca/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stealthcopter/InteractiveColorMatrixDemo/1303b59be21cfde43832b16c326727ed993a62ca/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 60dp
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ColourMatrixExample
3 | Github Page
4 | https://github.com/stealthcopter/InteractiveColorMatrixDemo
5 | Get Code
6 | Preset
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/test/java/com/stealthcopter/colourmatrixexample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.stealthcopter.colourmatrixexample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/art/screenshot_001.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stealthcopter/InteractiveColorMatrixDemo/1303b59be21cfde43832b16c326727ed993a62ca/art/screenshot_001.png
--------------------------------------------------------------------------------
/art/screenshot_002.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stealthcopter/InteractiveColorMatrixDemo/1303b59be21cfde43832b16c326727ed993a62ca/art/screenshot_002.png
--------------------------------------------------------------------------------
/art/screenshot_003.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stealthcopter/InteractiveColorMatrixDemo/1303b59be21cfde43832b16c326727ed993a62ca/art/screenshot_003.png
--------------------------------------------------------------------------------
/art/screenshot_004.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stealthcopter/InteractiveColorMatrixDemo/1303b59be21cfde43832b16c326727ed993a62ca/art/screenshot_004.png
--------------------------------------------------------------------------------
/art/web_hi_res_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stealthcopter/InteractiveColorMatrixDemo/1303b59be21cfde43832b16c326727ed993a62ca/art/web_hi_res_512.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stealthcopter/InteractiveColorMatrixDemo/1303b59be21cfde43832b16c326727ed993a62ca/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Mar 09 14:09:58 GMT 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Interactive ColorMatrix Demo 
2 |
3 | So if you, like me, don't have any clue how to understand or use a ColorMatrix this is a good way to start. Just have a play around with the values and see what funky effects that has on the image.
4 |
5 | ## General info
6 |
7 | ## Usage
8 |
9 | Just play around with the values to see what happens to the image. Use the presets for examples of what can be done. Use Identity(Reset) to reset to defaults.
10 |
11 | ## Screnshots
12 | 
13 | 
14 | 
15 | 
16 |
17 | ### More info
18 |
19 | [ColorMatrix - Android Developer Page](https://developer.android.com/reference/android/graphics/ColorMatrix.html)
20 |
21 | ### Permissions
22 | None
23 |
24 | ## Building
25 |
26 | It's a standard gradle project.
27 |
28 | # Contributing
29 |
30 | I welcome pull requests, issues and feedback.
31 |
32 | - Fork it
33 | - Create your feature branch (git checkout -b my-new-feature)
34 | - Commit your changes (git commit -am 'Added some feature')
35 | - Push to the branch (git push origin my-new-feature)
36 | - Create new Pull Request
37 |
38 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------