Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
Added VibratorCompat and const where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
DreierF committed Jan 2, 2018
1 parent bef32ff commit 6241330
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .idea/dictionaries/florian.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import android.support.v4.content.ContextCompat

object PermissionGranter {

private val PERMISSIONS_DIALOG_DELAY = 1000
private val GRANT_BUTTON_INDEX = 1
private const val PERMISSIONS_DIALOG_DELAY = 1000
private const val GRANT_BUTTON_INDEX = 1

fun allowPermissionsIfNeeded(activity: Activity, permissionNeeded: String) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ class EditArrowFragment : EditWithImageFragmentBase<ArrowImage>(R.drawable.arrow
}

companion object {
val ARROW_ID = "arrow_id"
const val ARROW_ID = "arrow_id"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import java.util.*

object ScoreboardUtils {

private val PAGE_WIDTH = 600
private val MARGIN = 50
private const val PAGE_WIDTH = 600
private const val MARGIN = 50

fun getScoreboardView(context: Context, locale: Locale, training: Training, roundId: Long, configuration: ScoreboardConfiguration): LinearLayout {
val rounds: List<Round>? = if (roundId == -1L) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ class ViewToPdfWriter(private val content: LinearLayout) {
/**
* Left and Right page margin in inches
*/
private val MARGIN_HORIZONTAL = 0.78f
private const val MARGIN_HORIZONTAL = 0.78f

/**
* Top and Bottom page margin in inches
*/
private val MARGIN_VERTICAL = 0.78f
private const val MARGIN_VERTICAL = 0.78f
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import java.io.IOException
import java.util.*

object ExternalStorageBackup {
private val FOLDER_NAME = "MyTargets"
private const val FOLDER_NAME = "MyTargets"

//If may get a full path that is not the right one, even if we don't have the SD Card there.
//We just need the "/mnt/extSdCard/" i.e and check if it's writable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import java.io.IOException
import java.util.*

object InternalStorageBackup {
private val FOLDER_NAME = "MyTargets"
private const val FOLDER_NAME = "MyTargets"

@Throws(IOException::class)
private fun createDirectory(directory: File) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import de.dreier.mytargets.features.settings.SettingsManager
* Static helper methods for working with the sync framework.
*/
object SyncUtils {
private val ONE_DAY: Long = 86400 // 1 day (in seconds)
private const val ONE_DAY: Long = 86400 // 1 day (in seconds)

val CONTENT_AUTHORITY = BuildConfig.APPLICATION_ID + ".provider"
const val CONTENT_AUTHORITY = BuildConfig.APPLICATION_ID + ".provider"

var isSyncAutomaticallyEnabled: Boolean
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,9 @@ class ChipGroup @JvmOverloads constructor(context: Context, attrs: AttributeSet?
var tags: List<Tag>
get() = ArrayList(tagList)
set(tags) {
removeAllViews()
tagList.clear()
tagList.addAll(tags)
for (tag in tagList) {
appendTag(tag)
}
visibility = if (tags.size < 2) View.GONE else View.VISIBLE
notifyTagsListChanged()
}

/**
Expand Down Expand Up @@ -148,6 +144,13 @@ class ChipGroup @JvmOverloads constructor(context: Context, attrs: AttributeSet?
}
}

fun notifyTagsListChanged() {
removeAllViews()
for (tag in tagList) {
appendTag(tag)
}
}

/**
* Append tag to this group.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ class StatisticsActivity : ChildActivityBase(), LoaderManager.LoaderCallbacks<Li
rounds = data
binding.progressBar.hide()
binding.distanceTags.tags = getDistanceTags()
binding.distanceTags.setOnTagClickListener({ applyFilter() })
binding.distanceTags.setOnTagClickListener { applyFilter() }
binding.diameterTags.tags = getDiameterTags()
binding.diameterTags.setOnTagClickListener({ applyFilter() })
binding.diameterTags.setOnTagClickListener { applyFilter() }
binding.arrowTags.tags = getArrowTags()
binding.arrowTags.setOnTagClickListener({ applyFilter() })
binding.arrowTags.setOnTagClickListener { applyFilter() }
binding.bowTags.tags = getBowTags()
binding.bowTags.setOnTagClickListener({ applyFilter() })
binding.bowTags.setOnTagClickListener { applyFilter() }

if (distanceTags != null && diameterTags != null && arrowTags != null && bowTags != null) {
restoreCheckedStates()
Expand All @@ -123,10 +123,10 @@ class StatisticsActivity : ChildActivityBase(), LoaderManager.LoaderCallbacks<Li
binding.diameterTags.tags.forEach { it.isChecked = diameterTags!!.contains(it.text) }
binding.arrowTags.tags.forEach { it.isChecked = arrowTags!!.contains(it.id) }
binding.bowTags.tags.forEach { it.isChecked = bowTags!!.contains(it.id) }
binding.distanceTags.tags = binding.distanceTags.tags
binding.diameterTags.tags = binding.diameterTags.tags
binding.arrowTags.tags = binding.arrowTags.tags
binding.bowTags.tags = binding.bowTags.tags
binding.distanceTags.notifyTagsListChanged()
binding.diameterTags.notifyTagsListChanged()
binding.arrowTags.notifyTagsListChanged()
binding.bowTags.notifyTagsListChanged()
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand Down Expand Up @@ -179,18 +179,18 @@ class StatisticsActivity : ChildActivityBase(), LoaderManager.LoaderCallbacks<Li
}

private fun applyFilter() {
distanceTags = binding.distanceTags.checkedTags.map { t -> t.text }.toHashSet()
diameterTags = binding.diameterTags.checkedTags.map { t -> t.text }.toHashSet()
arrowTags = binding.arrowTags.checkedTags.map { t -> t.id }.toHashSet()
bowTags = binding.bowTags.checkedTags.map { t -> t.id }.toHashSet()
distanceTags = binding.distanceTags.checkedTags.map { it.text }.toHashSet()
diameterTags = binding.diameterTags.checkedTags.map { it.text }.toHashSet()
arrowTags = binding.arrowTags.checkedTags.map { it.id }.toHashSet()
bowTags = binding.bowTags.checkedTags.map { it.id }.toHashSet()
filteredRounds = rounds!!
.filter { (training, round) ->
distanceTags!!.contains(round.distance.toString())
&& diameterTags!!.contains(round.target.diameter.toString())
&& arrowTags!!.contains(training.arrowId)
&& bowTags!!.contains(training.bowId)
}
.map { p -> p.second }
.map { it.second }
.groupBy { value -> Pair(value.target.id, value.target.getScoringStyle()) }
.map { value1 -> Pair(value1.value[0].target, value1.value) }
.sortedByDescending { it.second.size }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class RoundFragment : EditableListFragment<End>() {
override fun bindItem(item: End) {
val shots = item.loadShots()
if (SettingsManager.shouldSortTarget(round!!.target)) {
Collections.sort(shots)
shots.sort()
}
binding.shoots.setShots(round!!.target, shots)
binding.imageIndicator.visibility = if (item.loadImages().isEmpty()) View.INVISIBLE else View.VISIBLE
Expand All @@ -187,6 +187,6 @@ class RoundFragment : EditableListFragment<End>() {
}

companion object {
val ROUND_ID = "round_id"
const val ROUND_ID = "round_id"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class MyBackupAgent : BackupAgentHelper() {

companion object {
// The name of the SharedPreferences file
val PREFS = "user_preferences"
const val PREFS = "user_preferences"

// A key to uniquely identify the set of backup data
private val PREFS_BACKUP_KEY = "prefs"
private val SQLITE_BACKUP_KEY = "sqlite"
private val IMAGES_BACKUP_KEY = "images"
private const val PREFS_BACKUP_KEY = "prefs"
private const val SQLITE_BACKUP_KEY = "sqlite"
private const val IMAGES_BACKUP_KEY = "images"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.view.WindowManager
import de.dreier.mytargets.shared.R
import de.dreier.mytargets.shared.base.fragment.ETimerState.*
import de.dreier.mytargets.shared.models.TimerSettings
import de.dreier.mytargets.shared.utils.VibratorCompat

abstract class TimerFragmentBase : Fragment(), View.OnClickListener {

Expand Down Expand Up @@ -142,7 +143,7 @@ abstract class TimerFragmentBase : Fragment(), View.OnClickListener {
pattern[i * 2 + 1] = 400
pattern[i * 2 + 2] = 750
}
v.vibrate(pattern, -1)
VibratorCompat.vibrate(v, pattern, -1)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Thumbnail(internal var data: ByteArray) : Parcelable {
/**
* Constant used to indicate the dimension of micro thumbnail.
*/
private val TARGET_SIZE_MICRO_THUMBNAIL = 96
private const val TARGET_SIZE_MICRO_THUMBNAIL = 96

fun from(bitmap: Bitmap): Thumbnail {
val thumbnail = ThumbnailUtils.extractThumbnail(bitmap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import kotlinx.android.parcel.Parcelize
data class ArrowImage(
@Column(name = "_id")
@PrimaryKey(autoincrement = true)
var id: Long? = 0,
var id: Long = 0,

@Column
override var fileName: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import kotlinx.android.parcel.Parcelize
data class BowImage(
@Column(name = "_id")
@PrimaryKey(autoincrement = true)
var id: Long? = 0,
var id: Long = 0,

@Column
override var fileName: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import de.dreier.mytargets.shared.targets.models.*
import java.util.*

object StandardRoundFactory {
val IFAA = 8
val CUSTOM = 256
private val ASA = 1
private val AUSTRALIAN = 2
private val ARCHERY_GB = 4
private val NASP = 16
private val NFAA = 32
private val NFAS = 64
private val WA = 128
const val IFAA = 8
const val CUSTOM = 256
private const val ASA = 1
private const val AUSTRALIAN = 2
private const val ARCHERY_GB = 4
private const val NASP = 16
private const val NFAA = 32
private const val NFAS = 64
private const val WA = 128
private var idCounter: Long = 0
private var roundCounter: Long = 0

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2018 Florian Dreier
*
* This file is part of MyTargets.
*
* MyTargets is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* MyTargets is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

package de.dreier.mytargets.shared.utils

import android.os.Build
import android.os.VibrationEffect
import android.os.Vibrator

object VibratorCompat {
@Suppress("DEPRECATION")
fun vibrate(v: Vibrator, durationInMs: Long) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(VibrationEffect.createOneShot(durationInMs, VibrationEffect.DEFAULT_AMPLITUDE))
} else {
v.vibrate(durationInMs)
}
}

@Suppress("DEPRECATION")
fun vibrate(v: Vibrator, timings: LongArray, repeat: Int) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(VibrationEffect.createWaveform(timings, repeat))
} else {
v.vibrate(timings, repeat)
}
}

}
3 changes: 2 additions & 1 deletion wearable/src/main/java/de/dreier/mytargets/InputActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import de.dreier.mytargets.shared.models.augmented.AugmentedEnd
import de.dreier.mytargets.shared.models.augmented.AugmentedRound
import de.dreier.mytargets.shared.models.db.End
import de.dreier.mytargets.shared.models.db.Shot
import de.dreier.mytargets.shared.utils.VibratorCompat
import de.dreier.mytargets.shared.views.TargetViewBase
import java.text.DateFormat
import java.util.*
Expand Down Expand Up @@ -97,7 +98,7 @@ class InputActivity : WearableActivity(), TargetViewBase.OnEndFinishedListener {
this@InputActivity.startActivity(intent)
val v = this@InputActivity
.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
v.vibrate(200)
VibratorCompat.vibrate(v, 200)
this@InputActivity.finish()
val end = End(round.round.shotsPerEnd, 0)
end.roundId = round.round.id
Expand Down

0 comments on commit 6241330

Please sign in to comment.