Skip to content

Commit

Permalink
Merge pull request #15 from ChilliBits/beta
Browse files Browse the repository at this point in the history
Release to version 2.1.0
  • Loading branch information
marcauberer authored Jan 29, 2020
2 parents 5dd04ec + ebc5f7b commit 6033caf
Show file tree
Hide file tree
Showing 21 changed files with 192 additions and 32 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.chillibits.colorconverter"
applicationId "com.mrgames13.jimdo.colorconverter"
minSdkVersion 19
targetSdkVersion 29
versionCode 203
versionName "2.0.3"
versionCode 210
versionName "2.1.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -52,7 +52,7 @@ dependencies {
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61"
api 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61'
}

// Task for downloading all translation files
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
xmlns:tools="http://schemas.android.com/tools"
package="com.chillibits.colorconverter"
package="com.mrgames13.jimdo.colorconverter"
android:installLocation="auto">

<dist:module dist:instant="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
package com.chillibits.colorconverter.tools

import android.content.Context
import com.chillibits.colorconverter.R
import com.chillibits.colorconverter.model.Color
import com.mrgames13.jimdo.colorconverter.R

class ColorNameTools(private val context: Context) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.graphics.Bitmap
import android.graphics.Color
import androidx.core.content.ContextCompat
import androidx.palette.graphics.Palette
import com.chillibits.colorconverter.R
import com.mrgames13.jimdo.colorconverter.R

class ColorTools(private var context: Context) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import java.util.*
// Constants
const val TABLE_COLORS: String = "Colors"

class StorageTools(context: Context): SQLiteOpenHelper(context, "database.db", null, 1) {
class StorageTools(val context: Context): SQLiteOpenHelper(context, "database.db", null, 1) {

override fun onCreate(db: SQLiteDatabase?) {
try {
// Create tables
Expand All @@ -39,6 +40,18 @@ class StorageTools(context: Context): SQLiteOpenHelper(context, "database.db", n
writableDatabase.execSQL(command)
}

// ------------------------------------ Shared Preference --------------------------------------

fun putBoolean(name: String, value: Boolean) {
val prefs = context.getSharedPreferences("com.mrgames13.jimdo.colorconverter_preferences", Context.MODE_PRIVATE)
prefs.edit().putBoolean(name, value).apply()
}

fun getBoolean(name: String, default: Boolean = false): Boolean {
val prefs = context.getSharedPreferences("com.mrgames13.jimdo.colorconverter_preferences", Context.MODE_PRIVATE)
return prefs.getBoolean(name, default)
}

// ------------------------------------ Color Management ---------------------------------------

fun addColor(color: Color) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.chillibits.colorconverter.R
import com.chillibits.colorconverter.model.Color
import com.chillibits.colorconverter.tools.SimpleTextWatcher
import com.chillibits.colorconverter.tools.StorageTools
import com.chillibits.colorconverter.ui.adapter.ColorsAdapter
import com.mrgames13.jimdo.colorconverter.R
import kotlinx.android.synthetic.main.activity_color_selection.*
import kotlinx.android.synthetic.main.dialog_color_rename.view.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,38 @@
package com.chillibits.colorconverter.ui.activity

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.graphics.Matrix
import android.graphics.drawable.BitmapDrawable
import android.media.AudioManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.MediaStore
import android.speech.tts.TextToSpeech
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat
import androidx.exifinterface.media.ExifInterface
import com.chillibits.colorconverter.R
import com.chillibits.colorconverter.tools.ColorNameTools
import com.chillibits.colorconverter.tools.ColorTools
import com.chillibits.colorconverter.tools.StorageTools
import com.chillibits.colorconverter.viewmodel.DetailedFlagView
import com.fxn.pix.Options
import com.fxn.pix.Pix
import com.fxn.utility.PermUtil
import com.mrgames13.jimdo.colorconverter.R
import com.skydoves.colorpickerview.listeners.ColorListener
import kotlinx.android.synthetic.main.activity_image.*
import java.util.*

// Constants
private const val REQ_IMAGE_PICKER = 10001
Expand All @@ -37,8 +45,12 @@ class ImageActivity : AppCompatActivity() {

// Tools packages
private val ct = ColorTools(this)
private val cnt = ColorNameTools(this)
private val st = StorageTools(this)

// Variables as objects
private lateinit var tts: TextToSpeech
private var speakItem: MenuItem? = null
private var selectedColor: Int = Color.BLACK
private var vibrantColor: Int = Color.BLACK
private var vibrantColorLight: Int = Color.BLACK
Expand All @@ -48,6 +60,9 @@ class ImageActivity : AppCompatActivity() {
private var mutedColorDark: Int = Color.BLACK
private var imageUri: String? = null

// Variables
private var initialized = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_image)
Expand All @@ -58,12 +73,9 @@ class ImageActivity : AppCompatActivity() {
image.colorListener = ColorListener { color, _ ->
selectedColor = color
selected_color.background.colorFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(color, BlendModeCompat.SRC_IN)
if(speakItem != null && speakItem!!.isChecked) speakColor()
}
image.flagView =
DetailedFlagView(
this,
R.layout.flag_layout
)
image.flagView = DetailedFlagView(this, R.layout.flag_layout)

selected_color.setOnClickListener { finishWithResult(selectedColor) }
vibrant_color.setOnClickListener { finishWithResult(vibrantColor) }
Expand All @@ -73,6 +85,19 @@ class ImageActivity : AppCompatActivity() {
light_muted_color.setOnClickListener { finishWithResult(mutedColorLight) }
dark_muted_color.setOnClickListener { finishWithResult(mutedColorDark) }

tts = TextToSpeech(this) { status ->
if(status == TextToSpeech.SUCCESS) {
val result = tts.setLanguage(Locale.getDefault())
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Toast.makeText(this, R.string.language_not_available, Toast.LENGTH_SHORT).show()
} else {
initialized = true
}
} else {
Toast.makeText(this, R.string.initialization_failed, Toast.LENGTH_SHORT).show()
}
}

if(intent.hasExtra("ImageUri")) {
// Load default image
val defaultImageUri = intent.getParcelableExtra("ImageUri") as Uri
Expand All @@ -86,12 +111,19 @@ class ImageActivity : AppCompatActivity() {

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_activity_image, menu)
speakItem = menu?.getItem(0)
speakItem?.isChecked = st.getBoolean("speak_color")
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when(item.itemId) {
android.R.id.home -> finish()
R.id.action_speak -> {
val newState = !item.isChecked
st.putBoolean("speak_color", newState)
item.isChecked = newState
}
R.id.action_new_image -> chooseImage()
}
return super.onOptionsItemSelected(item)
Expand All @@ -115,10 +147,8 @@ class ImageActivity : AppCompatActivity() {
try{
imageUri = data?.getStringArrayListExtra(Pix.IMAGE_RESULTS)?.get(0).toString()
applyImage(applyRotation(BitmapFactory.decodeFile(imageUri), imageUri!!)!!)
} catch (e: Exception) {}
} else {
finish()
}
} catch (ignored: Exception) {}
} else finish()
}
}

Expand Down Expand Up @@ -167,10 +197,32 @@ class ImageActivity : AppCompatActivity() {
Pix.start(this, Options.init().setRequestCode(REQ_IMAGE_PICKER))
}

private fun speakColor() {
if(isAudioMuted()) {
Toast.makeText(this, R.string.audio_muted, Toast.LENGTH_SHORT).show()
} else {
if(initialized) {
val colorName = cnt.getColorNameFromColor(com.chillibits.colorconverter.model.Color(0, "", selectedColor, 0))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
tts.speak(colorName, TextToSpeech.QUEUE_FLUSH, null, null)
} else {
tts.speak(colorName, TextToSpeech.QUEUE_FLUSH, null)
}
} else {
Toast.makeText(this, R.string.initialization_failed, Toast.LENGTH_SHORT).show()
}
}
}

private fun finishWithResult(color: Int) {
val data = Intent()
data.putExtra("Color", color)
setResult(Activity.RESULT_OK, data)
finish()
}

private fun isAudioMuted(): Boolean {
val manager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
return manager.ringerMode != AudioManager.RINGER_MODE_NORMAL
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import android.animation.ValueAnimator
import android.app.Activity
import android.content.*
import android.content.pm.PackageManager
import android.media.AudioManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.speech.tts.TextToSpeech
import android.text.Editable
import android.text.InputType
import android.text.Selection
Expand All @@ -24,13 +26,13 @@ import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.graphics.*
import com.chillibits.colorconverter.R
import com.chillibits.colorconverter.model.Color
import com.chillibits.colorconverter.tools.ColorNameTools
import com.chillibits.colorconverter.tools.ColorTools
import com.chillibits.colorconverter.tools.SimpleTextWatcher
import com.chillibits.colorconverter.tools.StorageTools
import com.google.android.instantapps.InstantApps
import com.mrgames13.jimdo.colorconverter.R
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.dialog_edit_hex.view.*
import kotlinx.android.synthetic.main.dialog_edit_hsv.view.*
Expand All @@ -52,8 +54,12 @@ class MainActivity : AppCompatActivity() {
private val cnt = ColorNameTools(this)

// Variables as objects
private lateinit var tts: TextToSpeech
private var selectedColor = Color(0, "Selection", android.graphics.Color.BLACK, -1)

// Variables
private var initialized = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand Down Expand Up @@ -149,6 +155,11 @@ class MainActivity : AppCompatActivity() {
editHSVCode()
}

// Speak color
speak_color.setOnClickListener {
speakColor()
}

pick.setOnClickListener { chooseColor() }
pick_random_color.setOnClickListener { randomizeColor() }
pick_from_image.setOnClickListener { pickColorFromImage() }
Expand All @@ -161,6 +172,20 @@ class MainActivity : AppCompatActivity() {
android.graphics.Color.RGBToHSV(selectedColor.red, selectedColor.green, selectedColor.blue, hsv)
display_hsv.text = String.format(getString(R.string.hsv_), String.format("%.02f", hsv[0]), String.format("%.02f", hsv[1]), String.format("%.02f", hsv[2]))

// Initialize tts
tts = TextToSpeech(this) { status ->
if(status == TextToSpeech.SUCCESS) {
val result = tts.setLanguage(Locale.getDefault())
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Toast.makeText(this, R.string.language_not_available, Toast.LENGTH_SHORT).show()
} else {
initialized = true
}
} else {
Toast.makeText(this, R.string.initialization_failed, Toast.LENGTH_SHORT).show()
}
}

// Redirect to ImageActivity, if needed
if (intent.hasExtra("action") && intent.getStringExtra("action") == "image") pickColorFromImage()

Expand Down Expand Up @@ -496,4 +521,26 @@ class MainActivity : AppCompatActivity() {
.setNegativeButton(R.string.cancel, null)
.show()
}

private fun speakColor() {
if(isAudioMuted()) {
Toast.makeText(this, R.string.audio_muted, Toast.LENGTH_SHORT).show()
} else {
if(initialized) {
val colorName = cnt.getColorNameFromColor(selectedColor)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
tts.speak(colorName, TextToSpeech.QUEUE_FLUSH, null, null)
} else {
tts.speak(colorName, TextToSpeech.QUEUE_FLUSH, null)
}
} else {
Toast.makeText(this, R.string.initialization_failed, Toast.LENGTH_SHORT).show()
}
}
}

private fun isAudioMuted(): Boolean {
val manager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
return manager.ringerMode != AudioManager.RINGER_MODE_NORMAL
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chillibits.colorconverter.R
import com.chillibits.colorconverter.model.Color
import com.chillibits.colorconverter.tools.setTint
import com.chillibits.colorconverter.ui.activity.ColorSelectionActivity
import com.mrgames13.jimdo.colorconverter.R
import kotlinx.android.synthetic.main.item_color.view.*

class ColorsAdapter(private val activity: ColorSelectionActivity, private val colors: ArrayList<Color>) : RecyclerView.Adapter<ColorsAdapter.ViewHolder>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package com.chillibits.colorconverter.viewmodel
import android.annotation.SuppressLint
import android.content.Context
import androidx.core.graphics.*
import com.chillibits.colorconverter.R
import com.mrgames13.jimdo.colorconverter.R
import com.skydoves.colorpickerview.ColorEnvelope
import com.skydoves.colorpickerview.flag.FlagView
import kotlinx.android.synthetic.main.flag_layout.view.*
Expand All @@ -20,6 +20,6 @@ class DetailedFlagView(context: Context, layout: Int) : FlagView(context, layout
flag_color_hex.text = String.format(context.getString(R.string.hex_), String.format("#%06X", 0xFFFFFF and colorEnvelope.color))
val hsv = FloatArray(3)
android.graphics.Color.RGBToHSV(colorEnvelope.color.red, colorEnvelope.color.green, colorEnvelope.color.blue, hsv)
flag_color_hsv.text = String.format(context.getString(com.chillibits.colorconverter.R.string.hsv_), String.format("%.02f", hsv[0]), String.format("%.02f", hsv[1]), String.format("%.02f", hsv[2]))
flag_color_hsv.text = String.format(context.getString(R.string.hsv_), String.format("%.02f", hsv[0]), String.format("%.02f", hsv[1]), String.format("%.02f", hsv[2]))
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/volume_up.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--
~ Copyright © Marc Auberer 2020. All rights reserved
-->

<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M3,9v6h4l5,5L12,4L7,9L3,9zM16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v8.05c1.48,-0.73 2.5,-2.25 2.5,-4.02zM14,3.23v2.06c2.89,0.86 5,3.54 5,6.71s-2.11,5.85 -5,6.71v2.06c4.01,-0.91 7,-4.49 7,-8.77s-2.99,-7.86 -7,-8.77z"/>
</vector>
Loading

0 comments on commit 6033caf

Please sign in to comment.