Skip to content

Commit

Permalink
Merge pull request #20 from ChilliBits/beta
Browse files Browse the repository at this point in the history
Release to version 2.2.0
  • Loading branch information
marcauberer authored May 17, 2020
2 parents 5e02a25 + cb4cfc4 commit 870f8df
Show file tree
Hide file tree
Showing 36 changed files with 299 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 15 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
sudo: false
language: android
dist: trusty
jdk: oraclejdk8

android:
components:
- build-tools-29.0.3
- extra-google-google_play_services
- android-29
- extra-android-support
- extra-google-m2repository
- extra-android-m2repository
- android-$ANDROID_EMULATOR_LEVEL
- sys-img-armeabi-v7a-google_apis-$ANDROID_EMULATOR_LEVEL
env:
global:
- ANDROID_API_LEVEL=26
- ANDROID_EMULATOR_LEVEL=24
- ANDROID_BUILD_TOOLS_VERSION=26.0.1
- ANDROID_ABI=armeabi-v7a
- ANDROID_TAG=google_apis
- ADB_INSTALL_TIMEOUT=20
- extra-google-google_play_services
licenses:
- '.+'

before_install:
- chmod +x gradlew
licenses:
- '.+'

before_script:
- android list targets | grep -E '^id:' | awk -F '"' '{$1=""; print $2}'
- echo no | android create avd --force -n test -t "android-"$ANDROID_EMULATOR_LEVEL --abi $ANDROID_ABI --tag $ANDROID_TAG
- QEMU_AUDIO_DRV=none emulator -avd test -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
- echo yes | android update sdk --no-ui --all --filter platform-tools,tools
- echo yes | android update sdk --no-ui --all --filter build-tools-29.0.3
- echo yes | android update sdk --no-ui --all --filter android-29

script:
- ./gradlew clean test
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Color Converter
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/cb98dbe7ca6d46af8b385dadd618c446)](https://app.codacy.com/gh/ChilliBits/color-converter?utm_source=github.com&utm_medium=referral&utm_content=ChilliBits/color-converter&utm_campaign=Badge_Grade_Dashboard)
[![Build Status](https://travis-ci.com/ChilliBits/color-converter.svg?branch=master)](https://travis-ci.com/ChilliBits/color-converter)
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/chillibits/color-converter?include_prereleases)

Color Converter is an Android app to pick, display and convert colors.

Expand All @@ -12,7 +13,7 @@ More info on our homepage: [https://chillibits.com/color-converter](https://chil

- Pick colors
- Get name of picked colors
- Display picked colors in different formats (RGB, HEX, HSV)
- Display picked colors in different formats (ARGB, HEX, HSV)
- Generate random colors
- Pick color from a photo / image
- Save / load colors
Expand Down
30 changes: 16 additions & 14 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ android {
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.mrgames13.jimdo.colorconverter"
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 29
versionCode 212
versionName "2.1.2"
versionCode 2200
versionName "2.2.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -36,26 +36,28 @@ android {
dependencies {
// base dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
implementation 'androidx.appcompat:appcompat:1.2.0-beta01'
implementation 'androidx.core:core-ktx:1.3.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta5'
implementation 'com.google.android.instantapps:instantapps:1.1.0'
implementation 'com.google.android.play:core:1.7.2'
implementation 'androidx.palette:palette:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.palette:palette-ktx:1.0.0'
implementation 'com.google.android.material:material:1.2.0-alpha06'

// External dependencies
implementation 'net.margaritov.preference.colorpicker.ColorPickerPreference:ColorPickerPreference:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'com.fxn769:pix:1.4.4'
implementation 'com.fxn769:pix:1.5.3'
implementation 'com.github.skydoves:colorpickerview:2.1.6'
implementation 'com.mikepenz:iconics-core:5.0.1'
implementation 'com.mikepenz:iconics-core:5.0.3'
implementation 'com.mikepenz:material-design-iconic-typeface:2.2.0.6-kotlin@aar'
implementation 'com.mikepenz:fastadapter:5.0.0'
implementation 'com.github.javiersantos:MaterialStyledDialogs:2.1'
implementation 'com.mikepenz:fastadapter:5.0.2'
implementation 'com.github.javiersantos:MaterialStyledDialogs:3.0.1'

// dependencies for testing
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2-beta01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-beta01'
}

// Task for downloading all translation files
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/chillibits/colorconverter/model/Color.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Color: Comparable<Color> {
var id: Int
var name: String
var color: Int
var alpha: Int
var red: Int
var green: Int
var blue: Int
Expand All @@ -21,16 +22,15 @@ class Color: Comparable<Color> {
this.id = id
this.name = name
this.color = color
this.alpha = android.graphics.Color.alpha(color)
this.red = android.graphics.Color.red(color)
this.green = android.graphics.Color.green(color)
this.blue = android.graphics.Color.blue(color)
if(creationTimestamp != -1L) this.creationTimestamp = creationTimestamp
}

constructor(id: Int, name: String, red: Int, green: Int, blue: Int, creationTimestamp: Long):
this(id, name, android.graphics.Color.argb(255, red, green, blue), creationTimestamp)
constructor(id: Int, name: String, alpha: Int, red: Int, green: Int, blue: Int, creationTimestamp: Long):
this(id, name, android.graphics.Color.argb(alpha, red, green, blue), creationTimestamp)

override fun compareTo(@NotNull other: Color): Int {
return other.creationTimestamp.compareTo(creationTimestamp)
}
override fun compareTo(@NotNull other: Color) = other.creationTimestamp.compareTo(creationTimestamp)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

package com.chillibits.colorconverter.tools

import android.app.Activity
import android.content.Context
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.Color
import androidx.core.content.ContextCompat
import androidx.palette.graphics.Palette
import com.mrgames13.jimdo.colorconverter.R


class ColorTools(private var context: Context) {
fun getVibrantColor(image: Bitmap): Int {
val palette = Palette.from(image).generate()
Expand Down Expand Up @@ -42,8 +45,16 @@ class ColorTools(private var context: Context) {
return palette.getDarkMutedColor(ContextCompat.getColor(context, R.color.gray))
}

fun getTextColor(color: Int): Int {
val sum = Color.red(color) + Color.green(color) + Color.blue(color)
return if (sum > 384) Color.BLACK else Color.WHITE
fun getTextColor(activity: Activity, color: Int): Int {
return if(Color.alpha(color) > 127) {
val sum = Color.red(color) + Color.green(color) + Color.blue(color)
if (sum > 384) Color.BLACK else Color.WHITE
} else {
return when (activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_NO -> Color.BLACK
Configuration.UI_MODE_NIGHT_YES -> Color.WHITE
else -> Color.BLACK
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ object Constants {

// Other constants
const val COLOR_ANIMATION_DURATION = 500L
const val HEX_FORMAT_STRING = "#%06X"
const val NAME_SELECTED_COLOR = "Selection"
const val HSV_FORMAT_STRING = "%.02f"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import android.content.res.Resources
import android.widget.ImageView
import androidx.core.widget.ImageViewCompat

fun ImageView.setTint(color: Int) {
fun ImageView.setTint(color: Int) =
ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(color))
}

fun dpToPx(dp: Int) = (dp * Resources.getSystem().displayMetrics.density).toInt()
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ import java.util.*
// Constants
const val TABLE_COLORS: String = "Colors"

class StorageTools(val context: Context): SQLiteOpenHelper(context, "database.db", null, 1) {
class StorageTools(val context: Context): SQLiteOpenHelper(context, "database.db", null, 2) {
override fun onCreate(db: SQLiteDatabase?) {
// Create tables
db?.execSQL("CREATE TABLE IF NOT EXISTS $TABLE_COLORS (id integer PRIMARY KEY, name text, red integer, green integer, blue integer, creation_timestamp integer);")
db?.execSQL("CREATE TABLE IF NOT EXISTS $TABLE_COLORS (id integer PRIMARY KEY, name text, red integer, green integer, blue integer, creation_timestamp integer, alpha integer);")
}

override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
// Nothing to upgrade
if(oldVersion == 1 && newVersion == 2) {
db?.execSQL("ALTER TABLE $TABLE_COLORS ADD COLUMN alpha integer DEFAULT 255")
}
}

// ------------------------------------ Shared Preference --------------------------------------
Expand All @@ -44,6 +46,7 @@ class StorageTools(val context: Context): SQLiteOpenHelper(context, "database.db
val values = ContentValues()
values.put("id", loadColors().size)
values.put("name", color.name)
values.put("alpha", color.alpha)
values.put("red", color.red)
values.put("green", color.green)
values.put("blue", color.blue)
Expand All @@ -54,13 +57,11 @@ class StorageTools(val context: Context): SQLiteOpenHelper(context, "database.db
}
}

fun updateColor(id: Int, newName: String) {
fun updateColor(id: Int, newName: String) =
writableDatabase.execSQL("UPDATE $TABLE_COLORS SET name='$newName' WHERE id=$id")
}

fun removeColor(id: Int) {
fun removeColor(id: Int) =
writableDatabase.delete(TABLE_COLORS, "id=?", arrayOf(id.toString()))
}

fun loadColors(): ArrayList<Color> {
try {
Expand All @@ -75,6 +76,7 @@ class StorageTools(val context: Context): SQLiteOpenHelper(context, "database.db
Color(
cursor.getInt(0),
cursor.getString(1),
cursor.getInt(6),
cursor.getInt(2),
cursor.getInt(3),
cursor.getInt(4),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ class ColorSelectionActivity : AppCompatActivity() {
}

private fun done() {
Intent().run {
setResult(Activity.RESULT_OK, Intent().apply {
putExtra(Constants.EXTRA_COLOR, selectedColor!!.color)
setResult(Activity.RESULT_OK, this)
}
})
finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ class ImageActivity : AppCompatActivity() {
}

private fun applyRotation(source: Bitmap, path: String): Bitmap? {
val ei = ExifInterface(path)
return when (ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) {
return when (ExifInterface(path).getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) {
ExifInterface.ORIENTATION_ROTATE_90 -> rotateImage(source, 90F)
ExifInterface.ORIENTATION_ROTATE_180 -> rotateImage(source, 180F)
ExifInterface.ORIENTATION_ROTATE_270 -> rotateImage(source, 270F)
Expand All @@ -176,9 +175,10 @@ class ImageActivity : AppCompatActivity() {
}

private fun rotateImage(source: Bitmap, angle: Float): Bitmap? {
val matrix = Matrix()
matrix.postRotate(angle)
return Bitmap.createBitmap(source, 0, 0, source.width, source.height, matrix, true)
return Matrix().run {
postRotate(angle)
Bitmap.createBitmap(source, 0, 0, source.width, source.height, this, true)
}
}

private fun applyImage(bitmap: Bitmap) {
Expand All @@ -200,15 +200,15 @@ class ImageActivity : AppCompatActivity() {

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if(requestCode == PermUtil.REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Pix.start(this, Options.init().setRequestCode(Constants.REQ_IMAGE_PICKER))
}
}
if(requestCode == PermUtil.REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS && grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)
chooseImage()
}

private fun chooseImage() {
Pix.start(this, Options.init().setRequestCode(Constants.REQ_IMAGE_PICKER))
val options = Options.init()
.setExcludeVideos(true)
.setRequestCode(Constants.REQ_IMAGE_PICKER)
Pix.start(this, options)
}

private fun speakColor() {
Expand Down
Loading

0 comments on commit 870f8df

Please sign in to comment.