move adjustAlpha to an Int extension, remove Utils class

This commit is contained in:
tibbi 2016-11-17 20:16:54 +01:00
parent eee184c51a
commit d44880bed2
15 changed files with 65 additions and 69 deletions

View File

@ -4,9 +4,9 @@ import android.os.Bundle
import android.support.v4.app.TaskStackBuilder
import android.view.View
import android.widget.AdapterView
import com.simplemobiletools.calendar.helpers.Constants
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.*
import com.simplemobiletools.calendar.helpers.*
import kotlinx.android.synthetic.main.activity_settings.*
class SettingsActivity : SimpleActivity() {
@ -49,8 +49,8 @@ class SettingsActivity : SimpleActivity() {
val reminderType = mConfig.defaultReminderType
val reminderMinutes = mConfig.defaultReminderMinutes
settings_default_reminder.setSelection(when (reminderType) {
Constants.REMINDER_OFF -> 0
Constants.REMINDER_AT_START -> 1
REMINDER_OFF -> 0
REMINDER_AT_START -> 1
else -> 2
})
custom_reminder_save.setTextColor(custom_reminder_other_val.currentTextColor)
@ -72,9 +72,9 @@ class SettingsActivity : SimpleActivity() {
}
mConfig.defaultReminderType = when (itemIndex) {
0 -> Constants.REMINDER_OFF
1 -> Constants.REMINDER_AT_START
else -> Constants.REMINDER_CUSTOM
0 -> REMINDER_OFF
1 -> REMINDER_AT_START
else -> REMINDER_CUSTOM
}
}
}
@ -83,13 +83,13 @@ class SettingsActivity : SimpleActivity() {
private fun saveReminder() {
val value = custom_reminder_value.value
val multiplier = when (custom_reminder_other_period.selectedItemPosition) {
1 -> Constants.HOUR_MINS
2 -> Constants.DAY_MINS
1 -> HOUR_MINS
2 -> DAY_MINS
else -> 1
}
mConfig.defaultReminderMinutes = Integer.valueOf(value) * multiplier
mConfig.defaultReminderType = Constants.REMINDER_CUSTOM
mConfig.defaultReminderType = REMINDER_CUSTOM
toast(R.string.reminder_saved)
hideKeyboard()
}
@ -98,11 +98,11 @@ class SettingsActivity : SimpleActivity() {
var value = mins
if (mins == 0) {
custom_reminder_other_period.setSelection(0)
} else if (mins % Constants.DAY_MINS == 0) {
value = mins / Constants.DAY_MINS
} else if (mins % DAY_MINS == 0) {
value = mins / DAY_MINS
custom_reminder_other_period.setSelection(2)
} else if (mins % Constants.HOUR_MINS == 0) {
value = mins / Constants.HOUR_MINS
} else if (mins % HOUR_MINS == 0) {
value = mins / HOUR_MINS
custom_reminder_other_period.setSelection(1)
} else {
custom_reminder_other_period.setSelection(0)

View File

@ -14,6 +14,7 @@ import android.widget.SeekBar
import android.widget.TextView
import com.simplemobiletools.calendar.MonthlyCalendarImpl
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.adjustAlpha
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
import com.simplemobiletools.calendar.models.Day
@ -141,8 +142,8 @@ class WidgetConfigureActivity : AppCompatActivity(), MonthlyCalendar {
}
private fun updateTextColors() {
mTextColor = Utils.adjustAlpha(mTextColorWithoutTransparency, HIGH_ALPHA)
mWeakTextColor = Utils.adjustAlpha(mTextColorWithoutTransparency, LOW_ALPHA)
mTextColor = mTextColorWithoutTransparency.adjustAlpha(HIGH_ALPHA)
mWeakTextColor = mTextColorWithoutTransparency.adjustAlpha(LOW_ALPHA)
top_left_arrow.drawable.mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP)
top_right_arrow.drawable.mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP)
@ -153,7 +154,7 @@ class WidgetConfigureActivity : AppCompatActivity(), MonthlyCalendar {
}
private fun updateBgColor() {
mBgColor = Utils.adjustAlpha(mBgColorWithoutTransparency, mBgAlpha)
mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha)
config_calendar.setBackgroundColor(mBgColor)
config_bg_color.setBackgroundColor(mBgColor)
config_save.setBackgroundColor(mBgColor)

View File

@ -5,8 +5,8 @@ import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import android.util.SparseArray
import com.simplemobiletools.calendar.helpers.Constants
import com.simplemobiletools.calendar.fragments.DayFragment
import com.simplemobiletools.calendar.helpers.DAY_CODE
class MyDayPagerAdapter(fm: FragmentManager, private val mCodes: List<String>, private val mListener: DayFragment.DeleteListener) :
FragmentStatePagerAdapter(fm) {
@ -21,7 +21,7 @@ class MyDayPagerAdapter(fm: FragmentManager, private val mCodes: List<String>, p
override fun getItem(position: Int): Fragment {
val bundle = Bundle()
val code = mCodes[position]
bundle.putString(Constants.DAY_CODE, code)
bundle.putString(DAY_CODE, code)
if (fragments.get(position) != null)
return fragments[position]

View File

@ -4,21 +4,18 @@ import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import com.simplemobiletools.calendar.helpers.Constants
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.fragments.MonthFragment
import com.simplemobiletools.calendar.helpers.DAY_CODE
import com.simplemobiletools.calendar.interfaces.NavigationListener
class MyMonthPagerAdapter(fm: FragmentManager, private val mCodes: List<String>, private val mListener: NavigationListener) : FragmentStatePagerAdapter(fm) {
override fun getCount(): Int {
return mCodes.size
}
override fun getCount() = mCodes.size
override fun getItem(position: Int): Fragment {
val bundle = Bundle()
val code = mCodes[position]
bundle.putString(Constants.DAY_CODE, code)
bundle.putString(DAY_CODE, code)
val fragment = MonthFragment()
fragment.arguments = bundle

View File

@ -4,8 +4,8 @@ import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import com.simplemobiletools.calendar.helpers.Constants
import com.simplemobiletools.calendar.fragments.YearFragment
import com.simplemobiletools.calendar.helpers.YEAR_LABEL
import com.simplemobiletools.calendar.interfaces.NavigationListener
class MyYearPagerAdapter(fm: FragmentManager, private val mYears: List<Int>, private val mListener: NavigationListener) : FragmentStatePagerAdapter(fm) {
@ -15,7 +15,7 @@ class MyYearPagerAdapter(fm: FragmentManager, private val mYears: List<Int>, pri
override fun getItem(position: Int): Fragment {
val bundle = Bundle()
val year = mYears[position]
bundle.putInt(Constants.YEAR_LABEL, year)
bundle.putInt(YEAR_LABEL, year)
val fragment = YearFragment()
fragment.arguments = bundle

View File

@ -0,0 +1,11 @@
package com.simplemobiletools.calendar.extensions
import android.graphics.Color
fun Int.adjustAlpha(factor: Float): Int {
val alpha = Math.round(Color.alpha(this) * factor)
val red = Color.red(this)
val green = Color.green(this)
val blue = Color.blue(this)
return Color.argb(alpha, red, green, blue)
}

View File

@ -16,6 +16,7 @@ import android.widget.RelativeLayout
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.EventActivity
import com.simplemobiletools.calendar.adapters.EventsAdapter
import com.simplemobiletools.calendar.extensions.adjustAlpha
import com.simplemobiletools.calendar.extensions.updateWidget
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
@ -68,7 +69,7 @@ class DayFragment : Fragment(), DBHelper.EventsListener, AdapterView.OnItemClick
private fun setupButtons() {
val baseColor = if (mConfig.isDarkTheme) Color.WHITE else Color.BLACK
mTextColor = Utils.adjustAlpha(baseColor, HIGH_ALPHA)
mTextColor = baseColor.adjustAlpha(HIGH_ALPHA)
mHolder.apply {
top_left_arrow.drawable.mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP)

View File

@ -14,6 +14,7 @@ import android.widget.*
import com.simplemobiletools.calendar.MonthlyCalendarImpl
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.DayActivity
import com.simplemobiletools.calendar.extensions.adjustAlpha
import com.simplemobiletools.calendar.extensions.beVisibleIf
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
@ -92,10 +93,10 @@ class MonthFragment : Fragment(), MonthlyCalendar {
private fun setupButtons() {
val baseColor = if (mConfig.isDarkTheme) Color.WHITE else Color.BLACK
mTextColor = Utils.adjustAlpha(baseColor, HIGH_ALPHA)
mTextColorWithEvent = Utils.adjustAlpha(mRes.getColor(R.color.colorPrimary), HIGH_ALPHA)
mWeakTextColor = Utils.adjustAlpha(baseColor, LOW_ALPHA)
mWeakTextColorWithEvent = Utils.adjustAlpha(mRes.getColor(R.color.colorPrimary), LOW_ALPHA)
mTextColor = baseColor.adjustAlpha(HIGH_ALPHA)
mTextColorWithEvent = mRes.getColor(R.color.colorPrimary).adjustAlpha(HIGH_ALPHA)
mWeakTextColor = baseColor.adjustAlpha(LOW_ALPHA)
mWeakTextColorWithEvent = mRes.getColor(R.color.colorPrimary).adjustAlpha(LOW_ALPHA)
mHolder.apply {
top_left_arrow.drawable.mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP)
@ -149,7 +150,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
}
private fun setupLabels() {
val letters = Utils.letterIDs
val letters = letterIDs
for (i in 0..6) {
val dayTV = mHolder.findViewById(mRes.getIdentifier("label_" + i, "id", mPackageName)) as TextView

View File

@ -10,9 +10,9 @@ import android.view.ViewGroup
import android.widget.TextView
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.YearlyCalendarImpl
import com.simplemobiletools.calendar.extensions.adjustAlpha
import com.simplemobiletools.calendar.helpers.Config
import com.simplemobiletools.calendar.helpers.HIGH_ALPHA
import com.simplemobiletools.calendar.helpers.Utils
import com.simplemobiletools.calendar.helpers.YEAR_LABEL
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.interfaces.YearlyCalendar
@ -75,7 +75,7 @@ class YearFragment : Fragment(), YearlyCalendar {
val now = DateTime()
if (now.year == mYear) {
val monthLabel = mView.findViewById(res.getIdentifier("month_${now.monthOfYear}_label", "id", activity.packageName)) as TextView
monthLabel.setTextColor(Utils.adjustAlpha(res.getColor(R.color.colorPrimary), HIGH_ALPHA))
monthLabel.setTextColor(res.getColor(R.color.colorPrimary).adjustAlpha(HIGH_ALPHA))
val monthView = mView.findViewById(res.getIdentifier("month_${now.monthOfYear}", "id", activity.packageName)) as SmallMonthView
monthView.setTodaysId(now.dayOfMonth)

View File

@ -1,5 +1,7 @@
package com.simplemobiletools.calendar.helpers
import com.simplemobiletools.calendar.R
val LOW_ALPHA = .2f
val MEDIUM_ALPHA = .6f
val HIGH_ALPHA = .8f
@ -36,3 +38,6 @@ val REMINDER_TYPE = "reminder_type"
val REMINDER_MINUTES = "reminder_minutes"
val WIDGET_BG_COLOR = "widget_bg_color"
val WIDGET_TEXT_COLOR = "widget_text_color"
val letterIDs = intArrayOf(R.string.sunday_letter, R.string.monday_letter, R.string.tuesday_letter, R.string.wednesday_letter,
R.string.thursday_letter, R.string.friday_letter, R.string.saturday_letter)

View File

@ -7,7 +7,6 @@ import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.database.sqlite.SQLiteQueryBuilder
import android.text.TextUtils
import com.simplemobiletools.calendar.helpers.Constants
import com.simplemobiletools.calendar.extensions.getIntValue
import com.simplemobiletools.calendar.extensions.getStringValue
import com.simplemobiletools.calendar.models.Event
@ -116,11 +115,11 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
put(COL_REPEAT_START, event.startTS)
put(COL_REPEAT_INTERVAL, repeatInterval)
if (repeatInterval == Constants.MONTH || repeatInterval == Constants.YEAR) {
if (repeatInterval == MONTH || repeatInterval == YEAR) {
put(COL_REPEAT_DAY, dateTime.dayOfMonth)
}
if (repeatInterval == Constants.YEAR) {
if (repeatInterval == YEAR) {
put(COL_REPEAT_MONTH, dateTime.monthOfYear)
}
}

View File

@ -6,7 +6,6 @@ import android.appwidget.AppWidgetProvider
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.res.Resources
import android.graphics.*
import android.text.SpannableString
@ -17,6 +16,7 @@ import com.simplemobiletools.calendar.MonthlyCalendarImpl
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.DayActivity
import com.simplemobiletools.calendar.activities.MainActivity
import com.simplemobiletools.calendar.extensions.adjustAlpha
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
import com.simplemobiletools.calendar.models.Day
import org.joda.time.DateTime
@ -51,8 +51,8 @@ class MyWidgetProvider : AppWidgetProvider(), MonthlyCalendar {
val prefs = initPrefs(context)
val storedTextColor = prefs.getInt(WIDGET_TEXT_COLOR, Color.WHITE)
mTextColor = Utils.adjustAlpha(storedTextColor, HIGH_ALPHA)
mWeakTextColor = Utils.adjustAlpha(storedTextColor, LOW_ALPHA)
mTextColor = storedTextColor.adjustAlpha(HIGH_ALPHA)
mWeakTextColor = storedTextColor.adjustAlpha(LOW_ALPHA)
mDayTextSize = mRes.getDimension(R.dimen.day_text_size) / mRes.displayMetrics.density
mTodayTextSize = mRes.getDimension(R.dimen.today_text_size) / mRes.displayMetrics.density
@ -181,7 +181,7 @@ class MyWidgetProvider : AppWidgetProvider(), MonthlyCalendar {
private fun updateLabelColor() {
val mSundayFirst = Config.newInstance(mContext).isSundayFirst
val packageName = mContext.packageName
val letters = Utils.letterIDs
val letters = letterIDs
for (i in 0..6) {
val id = mRes.getIdentifier("label_" + i, "id", packageName)
mRemoteViews.setInt(id, "setTextColor", mTextColor)

View File

@ -1,18 +0,0 @@
package com.simplemobiletools.calendar.helpers
import android.graphics.Color
import com.simplemobiletools.calendar.R
object Utils {
fun adjustAlpha(color: Int, factor: Float): Int {
val alpha = Math.round(Color.alpha(color) * factor)
val red = Color.red(color)
val green = Color.green(color)
val blue = Color.blue(color)
return Color.argb(alpha, red, green, blue)
}
val letterIDs: IntArray
get() = intArrayOf(R.string.sunday_letter, R.string.monday_letter, R.string.tuesday_letter, R.string.wednesday_letter,
R.string.thursday_letter, R.string.friday_letter, R.string.saturday_letter)
}

View File

@ -1,7 +1,6 @@
package com.simplemobiletools.calendar.models
import com.simplemobiletools.calendar.helpers.Constants
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.helpers.*
import org.joda.time.DateTime
import java.io.Serializable
@ -18,10 +17,10 @@ class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var title
val currStart = Formatter.getDateTimeFromTS(startTS)
val newStart: DateTime
newStart = when (repeatInterval) {
Constants.DAY -> currStart.plusDays(1)
Constants.WEEK -> currStart.plusWeeks(1)
Constants.BIWEEK -> currStart.plusWeeks(2)
Constants.MONTH -> currStart.plusMonths(1)
DAY -> currStart.plusDays(1)
WEEK -> currStart.plusWeeks(1)
BIWEEK -> currStart.plusWeeks(2)
MONTH -> currStart.plusMonths(1)
else -> currStart.plusYears(1)
}
val newStartTS = (newStart.millis / 1000).toInt()

View File

@ -7,9 +7,9 @@ import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.adjustAlpha
import com.simplemobiletools.calendar.helpers.Config
import com.simplemobiletools.calendar.helpers.MEDIUM_ALPHA
import com.simplemobiletools.calendar.helpers.Utils
import java.util.*
class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
@ -58,8 +58,8 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
}
val baseColor = if (Config.newInstance(context).isDarkTheme) Color.WHITE else Color.BLACK
mTextColor = Utils.adjustAlpha(baseColor, MEDIUM_ALPHA)
mColoredTextColor = Utils.adjustAlpha(resources.getColor(R.color.colorPrimary), MEDIUM_ALPHA)
mTextColor = baseColor.adjustAlpha(MEDIUM_ALPHA)
mColoredTextColor = resources.getColor(R.color.colorPrimary).adjustAlpha(MEDIUM_ALPHA)
mPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = mTextColor