add some list widget related things
This commit is contained in:
parent
a5a30582b9
commit
fcf47c8338
|
@ -57,6 +57,7 @@
|
|||
|
||||
<receiver
|
||||
android:name=".helpers.MyWidgetMonthlyProvider"
|
||||
android:label="@string/widget_monthly"
|
||||
android:icon="@mipmap/widget_preview">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
|
@ -67,6 +68,19 @@
|
|||
android:resource="@xml/widget_monthly_info"/>
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".helpers.MyWidgetListProvider"
|
||||
android:label="@string/widget_list"
|
||||
android:icon="@mipmap/widget_preview">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_list_info"/>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".receivers.NotificationReceiver"/>
|
||||
|
||||
<receiver android:name=".receivers.BootCompletedReceiver">
|
||||
|
|
|
@ -0,0 +1,160 @@
|
|||
package com.simplemobiletools.calendar.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Color
|
||||
import android.graphics.PorterDuff
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.View
|
||||
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
|
||||
import kotlinx.android.synthetic.main.first_row.*
|
||||
import kotlinx.android.synthetic.main.top_navigation.*
|
||||
import kotlinx.android.synthetic.main.widget_config.*
|
||||
import org.joda.time.DateTime
|
||||
import yuku.ambilwarna.AmbilWarnaDialog
|
||||
|
||||
class WidgetListConfigureActivity : AppCompatActivity() {
|
||||
lateinit var mRes: Resources
|
||||
private var mPackageName = ""
|
||||
|
||||
private var mBgAlpha = 0f
|
||||
private var mWidgetId = 0
|
||||
private var mBgColorWithoutTransparency = 0
|
||||
private var mBgColor = 0
|
||||
private var mTextColorWithoutTransparency = 0
|
||||
private var mTextColor = 0
|
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setResult(Activity.RESULT_CANCELED)
|
||||
setContentView(R.layout.widget_config)
|
||||
mPackageName = packageName
|
||||
initVariables()
|
||||
|
||||
val extras = intent.extras
|
||||
if (extras != null)
|
||||
mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
|
||||
|
||||
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
|
||||
finish()
|
||||
|
||||
config_save.setOnClickListener { saveConfig() }
|
||||
config_bg_color.setOnClickListener { pickBackgroundColor() }
|
||||
config_text_color.setOnClickListener { pickTextColor() }
|
||||
}
|
||||
|
||||
private fun initVariables() {
|
||||
mRes = resources
|
||||
|
||||
val prefs = initPrefs(this)
|
||||
mTextColorWithoutTransparency = prefs.getInt(WIDGET_TEXT_COLOR, resources.getColor(R.color.colorPrimary))
|
||||
updateTextColors()
|
||||
|
||||
mBgColor = prefs.getInt(WIDGET_BG_COLOR, 1)
|
||||
if (mBgColor == 1) {
|
||||
mBgColor = Color.BLACK
|
||||
mBgAlpha = .2f
|
||||
} else {
|
||||
mBgAlpha = Color.alpha(mBgColor) / 255.toFloat()
|
||||
}
|
||||
|
||||
mBgColorWithoutTransparency = Color.rgb(Color.red(mBgColor), Color.green(mBgColor), Color.blue(mBgColor))
|
||||
config_bg_seekbar.setOnSeekBarChangeListener(bgSeekbarChangeListener)
|
||||
config_bg_seekbar.progress = (mBgAlpha * 100).toInt()
|
||||
updateBgColor()
|
||||
}
|
||||
|
||||
private fun initPrefs(context: Context) = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
||||
|
||||
fun saveConfig() {
|
||||
storeWidgetColors()
|
||||
requestWidgetUpdate()
|
||||
|
||||
Intent().apply {
|
||||
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mWidgetId)
|
||||
setResult(Activity.RESULT_OK, this)
|
||||
}
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun storeWidgetColors() {
|
||||
getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE).apply {
|
||||
edit().putInt(WIDGET_BG_COLOR, mBgColor).putInt(WIDGET_TEXT_COLOR, mTextColorWithoutTransparency).apply()
|
||||
}
|
||||
}
|
||||
|
||||
fun pickBackgroundColor() {
|
||||
val dialog = AmbilWarnaDialog(this, mBgColorWithoutTransparency, object : AmbilWarnaDialog.OnAmbilWarnaListener {
|
||||
override fun onCancel(dialog: AmbilWarnaDialog) {
|
||||
}
|
||||
|
||||
override fun onOk(dialog: AmbilWarnaDialog, color: Int) {
|
||||
mBgColorWithoutTransparency = color
|
||||
updateBgColor()
|
||||
}
|
||||
})
|
||||
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
fun pickTextColor() {
|
||||
val dialog = AmbilWarnaDialog(this, mTextColor, object : AmbilWarnaDialog.OnAmbilWarnaListener {
|
||||
override fun onCancel(dialog: AmbilWarnaDialog) {
|
||||
}
|
||||
|
||||
override fun onOk(dialog: AmbilWarnaDialog, color: Int) {
|
||||
mTextColorWithoutTransparency = color
|
||||
updateTextColors()
|
||||
}
|
||||
})
|
||||
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun requestWidgetUpdate() {
|
||||
Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetMonthlyProvider::class.java).apply {
|
||||
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(mWidgetId))
|
||||
sendBroadcast(this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateTextColors() {
|
||||
mTextColor = mTextColorWithoutTransparency.adjustAlpha(HIGH_ALPHA)
|
||||
|
||||
config_text_color.setBackgroundColor(mTextColor)
|
||||
config_save.setTextColor(mTextColor)
|
||||
}
|
||||
|
||||
private fun updateBgColor() {
|
||||
mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha)
|
||||
config_calendar.setBackgroundColor(mBgColor)
|
||||
config_bg_color.setBackgroundColor(mBgColor)
|
||||
config_save.setBackgroundColor(mBgColor)
|
||||
}
|
||||
|
||||
private val bgSeekbarChangeListener = object : SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||
mBgAlpha = progress.toFloat() / 100.toFloat()
|
||||
updateBgColor()
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
||||
|
||||
}
|
||||
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package com.simplemobiletools.calendar.adapters
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.BaseAdapter
|
||||
import android.widget.TextView
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.models.ListEvent
|
||||
import com.simplemobiletools.calendar.models.ListItem
|
||||
import com.simplemobiletools.calendar.models.ListSection
|
||||
import kotlinx.android.synthetic.main.event_item.view.*
|
||||
|
||||
class EventListWidgetAdapter(val context: Context, val mEvents: List<ListItem>) : BaseAdapter() {
|
||||
val ITEM_EVENT = 0
|
||||
val ITEM_HEADER = 1
|
||||
|
||||
private val mInflater: LayoutInflater
|
||||
private var mTopDivider: Drawable? = null
|
||||
private var mNow = (System.currentTimeMillis() / 1000).toInt()
|
||||
private var mOrangeColor = 0
|
||||
private var mGreyColor = 0
|
||||
private var mTodayDate = ""
|
||||
|
||||
init {
|
||||
mInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
mTopDivider = context.resources.getDrawable(R.drawable.divider)
|
||||
mOrangeColor = context.resources.getColor(R.color.colorPrimary)
|
||||
val mTodayCode = Formatter.getDayCodeFromTS(mNow)
|
||||
mTodayDate = Formatter.getEventDate(context, mTodayCode)
|
||||
}
|
||||
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
var view = convertView
|
||||
val viewHolder: ViewHolder
|
||||
val type = getItemViewType(position)
|
||||
|
||||
if (view == null) {
|
||||
if (type == ITEM_EVENT) {
|
||||
view = mInflater.inflate(R.layout.event_list_item, parent, false)
|
||||
} else {
|
||||
view = mInflater.inflate(R.layout.event_list_section, parent, false)
|
||||
view.setOnClickListener(null)
|
||||
}
|
||||
viewHolder = ViewHolder(view)
|
||||
view!!.tag = viewHolder
|
||||
} else {
|
||||
viewHolder = view.tag as ViewHolder
|
||||
}
|
||||
|
||||
if (type == ITEM_EVENT) {
|
||||
val item = mEvents[position] as ListEvent
|
||||
viewHolder.apply {
|
||||
title.text = item.title
|
||||
description?.text = item.description
|
||||
start?.text = Formatter.getTime(item.startTS)
|
||||
|
||||
if (item.startTS == item.endTS) {
|
||||
end?.visibility = View.INVISIBLE
|
||||
} else {
|
||||
end?.text = Formatter.getTime(item.endTS)
|
||||
end?.visibility = View.VISIBLE
|
||||
|
||||
val startCode = Formatter.getDayCodeFromTS(item.startTS)
|
||||
val endCode = Formatter.getDayCodeFromTS(item.endTS)
|
||||
if (startCode != endCode) {
|
||||
end?.append(" (${Formatter.getEventDate(context, endCode)})")
|
||||
}
|
||||
}
|
||||
|
||||
val currTextColor = if (item.startTS <= mNow) mOrangeColor else mGreyColor
|
||||
start?.setTextColor(currTextColor)
|
||||
end?.setTextColor(currTextColor)
|
||||
title.setTextColor(currTextColor)
|
||||
description?.setTextColor(currTextColor)
|
||||
}
|
||||
} else {
|
||||
val item = mEvents[position] as ListSection
|
||||
viewHolder.title.text = item.title
|
||||
viewHolder.title.setCompoundDrawablesWithIntrinsicBounds(null, if (position == 0) null else mTopDivider, null, null)
|
||||
|
||||
if (mGreyColor == 0)
|
||||
mGreyColor = viewHolder.title.currentTextColor
|
||||
|
||||
viewHolder.title.setTextColor(if (item.title == mTodayDate) mOrangeColor else mGreyColor)
|
||||
}
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return if (mEvents[position] is ListEvent) ITEM_EVENT else ITEM_HEADER
|
||||
}
|
||||
|
||||
override fun getViewTypeCount(): Int {
|
||||
return 2
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
return mEvents.size
|
||||
}
|
||||
|
||||
override fun getItem(position: Int): Any {
|
||||
return mEvents[position]
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return 0
|
||||
}
|
||||
|
||||
internal class ViewHolder(view: View) {
|
||||
val title = view.event_item_title
|
||||
val description: TextView? = view.event_item_description
|
||||
val start: TextView? = view.event_item_start
|
||||
val end: TextView? = view.event_item_end
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.simplemobiletools.calendar.helpers
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProvider
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Color
|
||||
import android.widget.RemoteViews
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.activities.DayActivity
|
||||
import com.simplemobiletools.calendar.extensions.adjustAlpha
|
||||
import com.simplemobiletools.calendar.models.Day
|
||||
|
||||
class MyWidgetListProvider : AppWidgetProvider() {
|
||||
companion object {
|
||||
private var mTextColor = 0
|
||||
|
||||
lateinit var mRemoteViews: RemoteViews
|
||||
lateinit var mRes: Resources
|
||||
lateinit var mContext: Context
|
||||
lateinit var mWidgetManager: AppWidgetManager
|
||||
lateinit var mIntent: Intent
|
||||
}
|
||||
|
||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||
initVariables(context)
|
||||
updateWidget()
|
||||
super.onUpdate(context, appWidgetManager, appWidgetIds)
|
||||
}
|
||||
|
||||
private fun initVariables(context: Context) {
|
||||
mContext = context
|
||||
mRes = mContext.resources
|
||||
|
||||
val prefs = initPrefs(context)
|
||||
val storedTextColor = prefs.getInt(WIDGET_TEXT_COLOR, Color.WHITE)
|
||||
mTextColor = storedTextColor.adjustAlpha(HIGH_ALPHA)
|
||||
|
||||
mWidgetManager = AppWidgetManager.getInstance(mContext)
|
||||
|
||||
mRemoteViews = RemoteViews(mContext.packageName, R.layout.fragment_month)
|
||||
mIntent = Intent(mContext, MyWidgetMonthlyProvider::class.java)
|
||||
|
||||
val bgColor = prefs.getInt(WIDGET_BG_COLOR, Color.BLACK)
|
||||
mRemoteViews.setInt(R.id.calendar_holder, "setBackgroundColor", bgColor)
|
||||
}
|
||||
|
||||
private fun updateWidget() {
|
||||
val thisWidget = ComponentName(mContext, MyWidgetMonthlyProvider::class.java)
|
||||
AppWidgetManager.getInstance(mContext).updateAppWidget(thisWidget, mRemoteViews)
|
||||
}
|
||||
|
||||
private fun setupIntent(action: String, id: Int) {
|
||||
mIntent.action = action
|
||||
val pendingIntent = PendingIntent.getBroadcast(mContext, 0, mIntent, 0)
|
||||
mRemoteViews.setOnClickPendingIntent(id, pendingIntent)
|
||||
}
|
||||
|
||||
private fun setupDayOpenIntent(id: Int, dayCode: String) {
|
||||
Intent(mContext, DayActivity::class.java).apply {
|
||||
putExtra(DAY_CODE, dayCode)
|
||||
val pendingIntent = PendingIntent.getActivity(mContext, Integer.parseInt(dayCode), this, 0)
|
||||
mRemoteViews.setOnClickPendingIntent(id, pendingIntent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initPrefs(context: Context) = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
||||
|
||||
fun updateDays(days: List<Day>) {
|
||||
val displayWeekNumbers = Config.newInstance(mContext).displayWeekNumbers
|
||||
val len = days.size
|
||||
val packageName = mContext.packageName
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ListView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/widget_event_list_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
</ListView>
|
|
@ -10,6 +10,10 @@
|
|||
<string name="simple_event_list">Einfache Termin Liste</string>
|
||||
<string name="no_events_added">Sieht aus als wäre dein Kalender leer.\nDu kannst neue Termine mit dem Plus Button unten rechts erstellen.</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendar monthly</string>
|
||||
<string name="widget_list">Calendar event list</string>
|
||||
|
||||
<!-- Event -->
|
||||
<string name="event">Termin</string>
|
||||
<string name="edit_event">Termin bearbeiten</string>
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
<string name="simple_event_list">Lista de eventos simples</string>
|
||||
<string name="no_events_added">Parece que tu calendario está vacío.\nPuedes crear eventos con el botón Más de la parte inferior.</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendar monthly</string>
|
||||
<string name="widget_list">Calendar event list</string>
|
||||
|
||||
<!-- Event -->
|
||||
<string name="event">Evento</string>
|
||||
<string name="edit_event">Editar evento</string>
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
<string name="simple_event_list">सरल इवेंट सूची</string>
|
||||
<string name="no_events_added">लगता हैं की आपका कैलेंडर खाली हैं।\nआप इवेंट्स को नीचे प्लस बटन के साथ बना सकते हैं।</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendar monthly</string>
|
||||
<string name="widget_list">Calendar event list</string>
|
||||
|
||||
<!-- Event -->
|
||||
<string name="event">इवेंट</string>
|
||||
<string name="edit_event">इवेंट एडिट करें</string>
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
<string name="simple_event_list">Simple event list</string>
|
||||
<string name="no_events_added">Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom.</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendar monthly</string>
|
||||
<string name="widget_list">Calendar event list</string>
|
||||
|
||||
<!-- Event -->
|
||||
<string name="event">Evento</string>
|
||||
<string name="edit_event">Modifica evento</string>
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
<string name="simple_event_list">Simple event list</string>
|
||||
<string name="no_events_added">Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom.</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendar monthly</string>
|
||||
<string name="widget_list">Calendar event list</string>
|
||||
|
||||
<!-- Event -->
|
||||
<string name="event">イベント</string>
|
||||
<string name="edit_event">イベントを編集</string>
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
<string name="simple_event_list">Lista de eventos</string>
|
||||
<string name="no_events_added">Parece que o seu calendário está vazio.\nPode criar eventos com o botão +, existente na base.</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendar monthly</string>
|
||||
<string name="widget_list">Calendar event list</string>
|
||||
|
||||
<!-- Event -->
|
||||
<string name="event">Evento</string>
|
||||
<string name="edit_event">Editar evento</string>
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
<string name="simple_event_list">Simple event list</string>
|
||||
<string name="no_events_added">Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom.</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendar monthly</string>
|
||||
<string name="widget_list">Calendar event list</string>
|
||||
|
||||
<!-- Event -->
|
||||
<string name="event">Händelse</string>
|
||||
<string name="edit_event">Redigera händelse</string>
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
<string name="simple_event_list">Simple event list</string>
|
||||
<string name="no_events_added">Seems like your calendar is empty.\nYou can create events with the Plus button at the bottom.</string>
|
||||
|
||||
<!-- Widget titles -->
|
||||
<string name="widget_monthly">Calendar monthly</string>
|
||||
<string name="widget_list">Calendar event list</string>
|
||||
|
||||
<!-- Event -->
|
||||
<string name="event">Event</string>
|
||||
<string name="edit_event">Edit Event</string>
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:configure="com.simplemobiletools.calendar.activities.WidgetListConfigureActivity"
|
||||
android:initialLayout="@layout/widget_event_list"
|
||||
android:minHeight="@dimen/min_widget_height"
|
||||
android:minWidth="@dimen/min_widget_width"
|
||||
android:previewImage="@mipmap/widget_preview"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:updatePeriodMillis="150000"/>
|
Loading…
Reference in New Issue