adding some core widget related things
This commit is contained in:
parent
3fed41e03b
commit
1949e433c7
10 changed files with 284 additions and 0 deletions
|
@ -63,6 +63,15 @@
|
|||
android:name=".activities.SnoozeReminderActivity"
|
||||
android:theme="@style/Theme.Transparent"/>
|
||||
|
||||
<activity
|
||||
android:name=".activities.WidgetDateTimeConfigureActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/MyWidgetConfigTheme">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service android:name=".services.SnoozeService"/>
|
||||
|
||||
<receiver android:name=".receivers.AlarmReceiver"/>
|
||||
|
@ -76,5 +85,17 @@
|
|||
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".helpers.MyWidgetDateTimeProvider"
|
||||
android:label="@string/digital_clock_and_date">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_date_time_info"/>
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
package com.simplemobiletools.clock.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.widget.SeekBar
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.clock.helpers.MyWidgetDateTimeProvider
|
||||
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
||||
import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||
import kotlinx.android.synthetic.main.widget_config_date_time.*
|
||||
|
||||
class WidgetDateTimeConfigureActivity : SimpleActivity() {
|
||||
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?) {
|
||||
useDynamicTheme = false
|
||||
super.onCreate(savedInstanceState)
|
||||
setResult(Activity.RESULT_CANCELED)
|
||||
setContentView(R.layout.widget_config_date_time)
|
||||
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() }
|
||||
|
||||
val primaryColor = config.primaryColor
|
||||
config_bg_seekbar.setColors(mTextColor, primaryColor, primaryColor)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
window.decorView.setBackgroundColor(0)
|
||||
}
|
||||
|
||||
private fun initVariables() {
|
||||
mTextColorWithoutTransparency = config.widgetTextColor
|
||||
updateColors()
|
||||
|
||||
mBgColor = config.widgetBgColor
|
||||
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 saveConfig() {
|
||||
storeWidgetColors()
|
||||
requestWidgetUpdate()
|
||||
|
||||
Intent().apply {
|
||||
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mWidgetId)
|
||||
setResult(Activity.RESULT_OK, this)
|
||||
}
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun storeWidgetColors() {
|
||||
config.apply {
|
||||
widgetBgColor = mBgColor
|
||||
widgetTextColor = mTextColorWithoutTransparency
|
||||
}
|
||||
}
|
||||
|
||||
private fun pickBackgroundColor() {
|
||||
ColorPickerDialog(this, mBgColorWithoutTransparency) {
|
||||
mBgColorWithoutTransparency = it
|
||||
updateBgColor()
|
||||
}
|
||||
}
|
||||
|
||||
private fun pickTextColor() {
|
||||
ColorPickerDialog(this, mTextColor) {
|
||||
mTextColorWithoutTransparency = it
|
||||
updateColors()
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestWidgetUpdate() {
|
||||
Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetDateTimeProvider::class.java).apply {
|
||||
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(mWidgetId))
|
||||
sendBroadcast(this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateColors() {
|
||||
mTextColor = mTextColorWithoutTransparency
|
||||
config_text_color.setBackgroundColor(mTextColor)
|
||||
config_save.setTextColor(mTextColor)
|
||||
}
|
||||
|
||||
private fun updateBgColor() {
|
||||
mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha)
|
||||
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,16 @@
|
|||
package com.simplemobiletools.clock.helpers
|
||||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProvider
|
||||
import android.content.Context
|
||||
|
||||
class MyWidgetDateTimeProvider : AppWidgetProvider() {
|
||||
|
||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||
performUpdate(context)
|
||||
}
|
||||
|
||||
private fun performUpdate(context: Context) {
|
||||
|
||||
}
|
||||
}
|
72
app/src/main/res/layout/widget_config_date_time.xml
Normal file
72
app/src/main/res/layout/widget_config_date_time.xml
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/config_date_time_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_margin="@dimen/activity_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/config_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/big_margin"
|
||||
android:gravity="center_horizontal"
|
||||
android:textSize="@dimen/clock_text_size"
|
||||
tools:text="00:00"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/config_date"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/config_time"
|
||||
android:gravity="center_horizontal"
|
||||
android:textSize="@dimen/big_text_size"
|
||||
tools:text="Mon, 1 January"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/config_bg_color"
|
||||
android:layout_width="@dimen/widget_colorpicker_size"
|
||||
android:layout_height="@dimen/widget_colorpicker_size"
|
||||
android:layout_above="@+id/config_text_color"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/config_bg_seekbar_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignBottom="@+id/config_bg_color"
|
||||
android:layout_alignTop="@+id/config_bg_color"
|
||||
android:layout_toRightOf="@+id/config_bg_color"
|
||||
android:background="@android:color/white">
|
||||
|
||||
<com.simplemobiletools.commons.views.MySeekBar
|
||||
android:id="@+id/config_bg_seekbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/config_text_color"
|
||||
android:layout_width="@dimen/widget_colorpicker_size"
|
||||
android:layout_height="@dimen/widget_colorpicker_size"
|
||||
android:layout_alignParentBottom="true"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/config_save"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:fontFamily="sans-serif-light"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:text="@string/ok"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="@dimen/big_text_size"/>
|
||||
|
||||
</RelativeLayout>
|
27
app/src/main/res/layout/widget_date_time.xml
Normal file
27
app/src/main/res/layout/widget_date_time.xml
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/widget_date_time_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/big_margin"
|
||||
android:gravity="center_horizontal"
|
||||
android:textSize="@dimen/clock_text_size"
|
||||
tools:text="00:00"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_date"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/widget_time"
|
||||
android:gravity="center_horizontal"
|
||||
android:textSize="@dimen/big_text_size"
|
||||
tools:text="Mon, 1 January"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -12,6 +12,7 @@
|
|||
<string name="timer_stopped">Timer has been stopped</string>
|
||||
<string name="max_reminder_length">Max reminder length</string>
|
||||
<string name="time_expired">Time expired</string>
|
||||
<string name="digital_clock_and_date">Digital clock and date</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="clock_tab">Relógio</string>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<string name="timer_stopped">Časovač bol zastavený</string>
|
||||
<string name="max_reminder_length">Maximálna dĺžka upozorňovania</string>
|
||||
<string name="time_expired">Čas vypršal</string>
|
||||
<string name="digital_clock_and_date">Digitálne hodiny a dátum</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="clock_tab">Okno s časom</string>
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
<dimen name="stopwatch_button_small_size">60dp</dimen>
|
||||
<dimen name="stopwatch_button_size">64dp</dimen>
|
||||
<dimen name="lap_time_size">80dp</dimen>
|
||||
<dimen name="min_widget_height">30dp</dimen>
|
||||
<dimen name="min_widget_width">110dp</dimen>
|
||||
|
||||
<dimen name="clock_text_size">70sp</dimen>
|
||||
<dimen name="alarm_text_size">46sp</dimen>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<string name="timer_stopped">Timer has been stopped</string>
|
||||
<string name="max_reminder_length">Max reminder length</string>
|
||||
<string name="time_expired">Time expired</string>
|
||||
<string name="digital_clock_and_date">Digital clock and date</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="clock_tab">Clock tab</string>
|
||||
|
|
9
app/src/main/res/xml/widget_date_time_info.xml
Normal file
9
app/src/main/res/xml/widget_date_time_info.xml
Normal file
|
@ -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.clock.activities.WidgetDateTimeConfigureActivity"
|
||||
android:initialLayout="@layout/widget_date_time"
|
||||
android:minHeight="@dimen/min_widget_height"
|
||||
android:minWidth="@dimen/min_widget_width"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:updatePeriodMillis="60000"/>
|
Loading…
Reference in a new issue