├── .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 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 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 |