2011-09-29 18:29:31 +00:00
|
|
|
package org.aprsdroid.app
|
|
|
|
|
|
|
|
import _root_.android.content.{BroadcastReceiver, Context, Intent, IntentFilter}
|
2016-02-23 11:03:08 +00:00
|
|
|
import _root_.android.graphics.drawable.Drawable
|
|
|
|
import _root_.android.graphics.{Bitmap, BitmapFactory, Canvas, Matrix, Paint, Path, Point, Rect, Typeface}
|
2011-09-29 18:29:31 +00:00
|
|
|
import _root_.android.util.AttributeSet
|
|
|
|
import _root_.android.widget.ImageView
|
|
|
|
|
2016-09-21 08:27:33 +00:00
|
|
|
object SymbolView {
|
|
|
|
var iconbitmap : Bitmap = null
|
|
|
|
|
|
|
|
def getSingleton(context : Context) = {
|
|
|
|
if (iconbitmap == null) {
|
|
|
|
iconbitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.allicons)
|
|
|
|
}
|
|
|
|
iconbitmap
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 18:29:31 +00:00
|
|
|
class SymbolView(context : Context, attrs : AttributeSet) extends ImageView(context, attrs) {
|
|
|
|
|
|
|
|
var symbol : String = "/$"
|
2016-09-21 08:27:33 +00:00
|
|
|
lazy val iconbitmap = SymbolView.getSingleton(context)
|
|
|
|
lazy val symbolSize = iconbitmap.getWidth()/16
|
2016-02-23 11:03:08 +00:00
|
|
|
|
2011-09-29 18:29:31 +00:00
|
|
|
|
|
|
|
def setSymbol(new_sym : String) {
|
|
|
|
symbol = new_sym
|
|
|
|
invalidate()
|
|
|
|
}
|
|
|
|
|
2016-09-21 09:26:30 +00:00
|
|
|
def symbol2rect(index : Int, page : Int) : Rect = {
|
|
|
|
val alt_offset = page*symbolSize*6
|
2016-02-23 11:03:08 +00:00
|
|
|
val y = (index / 16) * symbolSize + alt_offset
|
|
|
|
val x = (index % 16) * symbolSize
|
2011-09-29 18:29:31 +00:00
|
|
|
new Rect(x, y, x+symbolSize, y+symbolSize)
|
|
|
|
}
|
2016-09-21 09:26:30 +00:00
|
|
|
def symbol2rect(symbol : String) : Rect = {
|
|
|
|
symbol2rect(symbol(1) - 33, if (symbol(0) == '/') 0 else 1)
|
|
|
|
}
|
2011-09-29 18:29:31 +00:00
|
|
|
|
|
|
|
def symbolIsOverlayed(symbol : String) = {
|
|
|
|
(symbol(0) != '/' && symbol(0) != '\\')
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override def onDraw(canvas : Canvas) {
|
|
|
|
val srcRect = symbol2rect(symbol)
|
|
|
|
//android.util.Log.d("SymbolView", "x * y = " + getWidth() + "*" + getHeight())
|
|
|
|
val destRect = new Rect(0, 0, getWidth(), getHeight())
|
|
|
|
val drawPaint = new Paint()
|
|
|
|
drawPaint.setAntiAlias(true)
|
|
|
|
drawPaint.setFilterBitmap(true)
|
|
|
|
|
|
|
|
canvas.drawBitmap(iconbitmap, srcRect, destRect, drawPaint)
|
|
|
|
|
|
|
|
if (symbolIsOverlayed(symbol)) {
|
2016-09-21 09:26:30 +00:00
|
|
|
// use page 2, overlay letters
|
|
|
|
canvas.drawBitmap(iconbitmap, symbol2rect(symbol(0)-33, 2), destRect, drawPaint)
|
2011-09-29 18:29:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|