-1

From what i understand you cannot rotate an image in a widget using RemoteViews

Since they also depricated the analog clock widget, how do you do a simple analog clock Widgetusing your own images ?

I have everything set up in my widget, I also have a timer that runs every minute, I just need to rotate the minute dial and hour dial accordingly

been looking around and couldn't find an answer to this

how is that possible inside a Widget ?

i learn i can actually have 60 images for the minute dial + 60 images for the hour dial and then swap them progematicly.. but that's just an overkill... isn't there a way to just achieve this simple thing that allot of people are doing ?

Chief Madog
  • 1,738
  • 4
  • 28
  • 55

2 Answers2

1

You can rotate an image and assign it to a ImageView. I leave a snippet in Kotlin that should help you.

val bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.minute_hand)
remoteViews.setImageViewBitmap(R.id.imageView, bitmap.rotated(angle))

where rotated function is :

fun Bitmap.rotated(angle: Float): Bitmap {
    val source = this
    val matrix = Matrix()
    matrix.postRotate(angle)
    return Bitmap.createBitmap(source, 0, 0, source.width, source.height, matrix, true)
}
crgarridos
  • 8,758
  • 3
  • 49
  • 61
0

Not really an answer to your question, but there are many implementation of analog clocks.
You can try this whom looks very customisable

Edit :

I had never worked with widgets. It looks that you can't implement custom views inside anymore.

Check this answer : How to set time to Android AnalogClock in app widget?

crgarridos
  • 8,758
  • 3
  • 49
  • 61
  • That could have been awsome if only this clock is for activity. I need one for a widget – Chief Madog May 30 '17 at 22:28
  • that answer is using a depricated analog clock, i mentioned it in my post, my question is how to get around it since you cannot use it anymore – Chief Madog May 31 '17 at 14:31