From c6a3884c782e8499ce2fbcad29ddf7861c8117af Mon Sep 17 00:00:00 2001 From: gohv Date: Tue, 4 Apr 2017 13:40:07 +0300 Subject: [PATCH 1/2] added a SeekBar for the Saturation --- .idea/vcs.xml | 6 +++ app/build.gradle | 5 ++- .../teamtreehouse/colorizer/MainActivity.java | 42 +++++++++++++++---- app/src/main/res/layout/activity_main.xml | 14 +++++++ 4 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index eb3b4b0..a63f4d7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,8 +24,9 @@ dependencies { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:25.3.0' - compile 'com.android.support.constraint:constraint-layout:1.0.2' + compile 'com.android.support:appcompat-v7:25.3.1' testCompile 'junit:junit:4.12' compile 'com.github.bumptech.glide:glide:3.7.0' + compile 'com.android.support.constraint:constraint-layout:1.0.1' + } diff --git a/app/src/main/java/com/teamtreehouse/colorizer/MainActivity.java b/app/src/main/java/com/teamtreehouse/colorizer/MainActivity.java index 3f5197b..bb314ee 100644 --- a/app/src/main/java/com/teamtreehouse/colorizer/MainActivity.java +++ b/app/src/main/java/com/teamtreehouse/colorizer/MainActivity.java @@ -5,23 +5,29 @@ import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ImageView; +import android.widget.SeekBar; import com.bumptech.glide.Glide; public class MainActivity extends AppCompatActivity { - ImageView imageView; - int[] imageResIds = {R.drawable.cuba1, R.drawable.cuba2, R.drawable.cuba3}; - int imageIndex = 0; - boolean color = true; - boolean red = true; - boolean green = true; - boolean blue = true; + private ImageView imageView; + private SeekBar saturationSeekBar; + private int[] imageResIds = {R.drawable.cuba1, R.drawable.cuba2, R.drawable.cuba3}; + private int imageIndex = 0; + private boolean color = true; + private boolean red = true; + private boolean green = true; + private boolean blue = true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = (ImageView)findViewById(R.id.imageView); + saturationSeekBar = (SeekBar)findViewById(R.id.saturationSeekBar); + + saturationSeekBar.setOnSeekBarChangeListener(saturationSeekBarListener); + loadImage(); } @@ -29,11 +35,11 @@ private void loadImage() { Glide.with(this).load(imageResIds[imageIndex]).into(imageView); } - private void updateSaturation() { + private void updateSaturation(int saturation) { ColorMatrix colorMatrix = new ColorMatrix(); if (color) { red = green = blue = true; - colorMatrix.setSaturation(1); + colorMatrix.setSaturation(saturation); } else { colorMatrix.setSaturation(0); } @@ -56,4 +62,22 @@ private void updateColors() { ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix); imageView.setColorFilter(colorFilter); } + + /*Add a SeekBar for saturation*/ + private final SeekBar.OnSeekBarChangeListener saturationSeekBarListener = new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + updateSaturation(progress); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + }; } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 05be2bb..a300442 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -16,4 +16,18 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"/> + + \ No newline at end of file From 4430525f046eb131f4fbb39027e910b14536e966 Mon Sep 17 00:00:00 2001 From: gohv Date: Tue, 4 Apr 2017 13:50:54 +0300 Subject: [PATCH 2/2] added a SeekBar for the Saturation --- .idea/misc.xml | 2 +- app/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 5d19981..fbb6828 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index a63f4d7..dc9bd34 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,6 +27,6 @@ dependencies { compile 'com.android.support:appcompat-v7:25.3.1' testCompile 'junit:junit:4.12' compile 'com.github.bumptech.glide:glide:3.7.0' - compile 'com.android.support.constraint:constraint-layout:1.0.1' + compile 'com.android.support.constraint:constraint-layout:1.0.2' }