Remove unused files

This commit is contained in:
nielsandriesse 2020-09-10 09:02:25 +10:00
parent 4192e5f7e8
commit 36d69cc380
8 changed files with 6 additions and 244 deletions

View File

@ -1,49 +0,0 @@
package org.thoughtcrime.securesms.loki.todo
import android.graphics.*
import android.graphics.drawable.Drawable
/**
* Basically a [Bitmap] wrapper, the [Bitmap] size must be known when instantiating it
* but when drawing it will draw the [Bitmap] to fit the canvas.
*/
abstract class IdenticonDrawable(width: Int, height: Int, hash: Long) : Drawable() {
private val bitmapRect: Rect = Rect(0, 0, width, height)
private val destinationRect: Rect = Rect(0, 0, width, height)
private val bitmap: Bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
private val canvas: Canvas = Canvas(bitmap)
private val bitmapPaint = Paint(Paint.ANTI_ALIAS_FLAG)
var hash: Long = hash
set(value) {
field = value
onSetHash(value)
invalidateBitmap()
}
protected fun invalidateBitmap() {
drawBitmap(canvas)
invalidateSelf()
}
protected abstract fun drawBitmap(canvas: Canvas)
protected open fun onSetHash(newHash: Long) = Unit
override fun draw(canvas: Canvas) {
destinationRect.set(0, 0, canvas.width, canvas.height)
canvas.drawBitmap(bitmap, bitmapRect, destinationRect, bitmapPaint)
}
override fun setAlpha(i: Int) {
bitmapPaint.alpha = i
}
override fun setColorFilter(colorFilter: ColorFilter?) {
bitmapPaint.colorFilter = colorFilter
}
override fun getOpacity(): Int {
return bitmapPaint.alpha
}
}

View File

@ -1,22 +0,0 @@
package org.thoughtcrime.securesms.loki.todo
import android.content.Context
import android.graphics.drawable.Drawable
import androidx.appcompat.content.res.AppCompatResources
import network.loki.messenger.R
import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto
class JazzIdenticonContactPhoto(val hexEncodedPublicKey: String) : FallbackContactPhoto {
override fun asDrawable(context: Context, color: Int): Drawable {
return asDrawable(context, color, false)
}
override fun asDrawable(context: Context, color: Int, inverted: Boolean): Drawable {
val targetSize = context.resources.getDimensionPixelSize(R.dimen.contact_photo_target_size)
return JazzIdenticonDrawable(targetSize, targetSize, hexEncodedPublicKey)
}
override fun asCallCard(context: Context): Drawable? {
return AppCompatResources.getDrawable(context, R.drawable.ic_person_large)
}
}

View File

@ -1,132 +0,0 @@
package org.thoughtcrime.securesms.loki.todo
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import kotlin.math.*
class JazzIdenticonDrawable(width: Int, height: Int, hash: Long) : IdenticonDrawable(width, height, hash) {
constructor(width: Int, height: Int, hashString: String): this(width, height, 0) {
val hexRegex = Regex("^[0-9A-Fa-f]+\$")
if (hashString.length >= 12 && hashString.matches(hexRegex)) {
hash = hashString.substring(0 until 12).toLong(16)
}
}
companion object {
var colors = listOf(
"#01888c", // teal
"#fc7500", // bright orange
"#034f5d", // dark teal
"#E784BA", // light pink
"#81C8B6", // bright green
"#c7144c", // raspberry
"#f3c100", // goldenrod
"#1598f2", // lightning blue
"#2465e1", // sail blue
"#f19e02" // gold
).map{ Color.parseColor(it) }
}
private var generator: RNG = RNG(hash)
private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
// Settings
private val wobble: Float = 30f
private val shapeCount = 4
init {
invalidateBitmap()
}
override fun onSetHash(newHash: Long) {
super.onSetHash(newHash)
generator = RNG(newHash)
invalidateBitmap()
}
override fun drawBitmap(canvas: Canvas) {
generator.reset()
val newColors = hueShift(colors)
val shuffled = shuffleList(newColors)
canvas.drawColor(shuffled[0])
for (i in 0 until shapeCount) {
drawSquare(canvas, shuffled[i + 1], i, shapeCount - 1)
}
}
private fun drawSquare(canvas: Canvas, color: Int, index: Int, total: Int) {
val size = min(canvas.width, canvas.height)
val center = (size / 2).toFloat()
val firstRotation = generator.nextFloat()
val angle = PI * 2 * firstRotation
val a = size / total.toFloat()
val b = generator.nextFloat()
val c = index.toFloat() * a
val velocity = a * b + c
val tx = cos(angle) * velocity
val ty = sin(angle) * velocity
// Third random is a shape rotation on top of all that
val secondRotation = generator.nextFloat()
val rotation = (firstRotation * 360f) + (secondRotation * 180f)
// Paint it!
canvas.save()
paint.color = color
canvas.translate(tx.toFloat(), ty.toFloat())
canvas.rotate(rotation.round(1), center, center)
canvas.drawRect(0f, 0f, canvas.width.toFloat(), canvas.height.toFloat(), paint)
canvas.restore()
}
private fun hueShift(colors: List<Int>): List<Int> {
val amount = generator.nextFloat() * 30 - wobble / 2
return colors.map { color ->
val red = Color.red(color)
val green = Color.green(color)
val blue = Color.blue(color)
val hsv = FloatArray(3)
Color.RGBToHSV(red, green, blue, hsv)
// Normalise between 0 and 360
var newHue = hsv[0] + round(amount)
if (newHue < 0) { newHue += 360 }
if (newHue > 360) { newHue -= 360 }
hsv[0] = newHue
Color.HSVToColor(hsv)
}
}
private fun <T> shuffleList(list: List<T>): List<T> {
var currentIndex = list.count()
val newList = list.toMutableList()
while (currentIndex > 0) {
val randomIndex = generator.next().toInt() % currentIndex
currentIndex -= 1
// Swap
val temp = newList[currentIndex]
newList[currentIndex] = newList[randomIndex]
newList[randomIndex] = temp
}
return newList
}
}
private fun Float.round(decimals: Int): Float {
var multiplier = 1f
repeat(decimals) { multiplier *= 10 }
return round(this * multiplier) / multiplier
}

View File

@ -1,30 +0,0 @@
package org.thoughtcrime.securesms.loki.todo
class RNG(hash: Long) {
private var seed: Long
private val initial: Long
private val maxInt32 = Int.MAX_VALUE.toLong()
init {
seed = hash % maxInt32
if (seed <= 0) {
seed = maxInt32 - 1
}
initial = seed
}
fun next(): Long {
val newSeed = (seed * 16807) % maxInt32
seed = newSeed
return seed
}
fun nextFloat(): Float {
return (next() - 1).toFloat() / (maxInt32 - 1)
}
fun reset() {
seed = initial
}
}

View File

@ -1,4 +1,4 @@
package org.thoughtcrime.securesms.loki.todo
package org.thoughtcrime.securesms.loki.utilities
import android.content.Context
import android.graphics.*

View File

@ -13,7 +13,7 @@ import network.loki.messenger.R
import org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto
import org.thoughtcrime.securesms.database.Address
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.loki.todo.AvatarPlaceholderGenerator
import org.thoughtcrime.securesms.loki.utilities.AvatarPlaceholderGenerator
import org.thoughtcrime.securesms.mms.GlideRequests
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.util.TextSecurePreferences

View File

@ -29,7 +29,7 @@ import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.loki.todo.AvatarPlaceholderGenerator;
import org.thoughtcrime.securesms.loki.utilities.AvatarPlaceholderGenerator;
import org.thoughtcrime.securesms.loki.utilities.NotificationUtilities;
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader;
import org.thoughtcrime.securesms.mms.GlideApp;

View File

@ -20,6 +20,7 @@ package org.thoughtcrime.securesms.recipients;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -43,7 +44,6 @@ import org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState;
import org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode;
import org.thoughtcrime.securesms.database.RecipientDatabase.VibrateState;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.loki.todo.JazzIdenticonContactPhoto;
import org.thoughtcrime.securesms.loki.utilities.ProfilePictureModifiedEvent;
import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.recipients.RecipientProvider.RecipientDetails;
@ -465,15 +465,10 @@ public class Recipient implements RecipientModifiedListener {
}
public synchronized @NonNull FallbackContactPhoto getFallbackContactPhoto() {
// TODO: I believe this is now completely unused
if (isResolving()) return new TransparentContactPhoto();
else if (isGroupRecipient()) return new GeneratedContactPhoto(name, R.drawable.ic_profile_default);
else {
String userPublicKey = TextSecurePreferences.getLocalNumber(context);
String publicKey = address.serialize();
String userMasterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
String publicKeyToUse = (publicKey.equalsIgnoreCase(userPublicKey) && userMasterPublicKey != null) ? userMasterPublicKey : publicKey;
return new JazzIdenticonContactPhoto(publicKeyToUse);
}
else { return new TransparentContactPhoto(); }
}
public synchronized @Nullable ContactPhoto getContactPhoto() {