Release Beta Version

This commit is contained in:
Tommaso Berlose 2017-10-27 19:41:07 +02:00
parent 9318a99d1f
commit 4cbb5d702f
19 changed files with 634 additions and 285 deletions

View File

@ -15,7 +15,7 @@ android {
applicationId "com.tommasoberlose.anotherwidget" applicationId "com.tommasoberlose.anotherwidget"
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 26 targetSdkVersion 26
versionCode 20 versionCode 22
versionName "1.2" versionName "1.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
@ -36,19 +36,21 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'
}) })
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.survivingwithandroid:weatherlib:1.6.0' implementation 'com.survivingwithandroid:weatherlib:1.6.0'
compile 'com.survivingwithandroid:weatherlib_volleyclient:1.6.0' implementation 'com.survivingwithandroid:weatherlib_volleyclient:1.6.0'
compile 'com.mcxiaoke.volley:library:1.0.6@aar' implementation 'com.mcxiaoke.volley:library:1.0.6@aar'
compile 'com.android.support:customtabs:26.1.0' implementation 'com.android.support:customtabs:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0' implementation 'com.android.support:cardview-v7:26.1.0'
kapt 'com.android.databinding:compiler:2.3.3' kapt 'com.android.databinding:compiler:2.3.3'
compile('com.crashlytics.sdk.android:crashlytics:2.7.0@aar') { implementation('com.crashlytics.sdk.android:crashlytics:2.7.0@aar') {
transitive = true; transitive = true;
} }
compile 'com.android.support:design:26.1.0' implementation 'com.android.support:design:26.1.0'
compile 'org.greenrobot:eventbus:3.0.0' implementation 'org.greenrobot:eventbus:3.0.0'
compile 'com.android.support:recyclerview-v7:26.1.0' implementation 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.google.android.gms:play-services-awareness:11.4.2' implementation 'com.google.android.gms:play-services-awareness:11.4.2'
compile 'joda-time:joda-time:2.9.9' implementation 'joda-time:joda-time:2.9.9'
compile 'com.pes.materialcolorpicker:library:1.0.4' implementation 'com.pes.materialcolorpicker:library:1.0.4'
implementation 'com.andkulikov:transitionseverywhere:1.7.6'
implementation 'me.everything:providers-android:1.0.1'
} }

View File

@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":20},"path":"app-release.apk","properties":{"packageId":"com.tommasoberlose.anotherwidget","split":"","minSdkVersion":"19"}}] [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":22},"path":"app-release.apk","properties":{"packageId":"com.tommasoberlose.anotherwidget","split":"","minSdkVersion":"19"}}]

View File

@ -14,7 +14,6 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<meta-data <meta-data
android:name="com.google.android.awareness.API_KEY" android:name="com.google.android.awareness.API_KEY"
android:value="AIzaSyAMkqiQHTdZGOUxRd0ZEvvrIE1qN_3pJb4" /> android:value="AIzaSyAMkqiQHTdZGOUxRd0ZEvvrIE1qN_3pJb4" />
@ -60,11 +59,14 @@
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="com.tommasoberlose.anotherwidget.action.ACTION_TIME_UPDATE" /> <action android:name="com.tommasoberlose.anotherwidget.action.ACTION_TIME_UPDATE" />
<action android:name="com.tommasoberlose.anotherwidget.action.ACTION_CALENDAR_UPDATE" /> <action android:name="com.tommasoberlose.anotherwidget.action.ACTION_CALENDAR_UPDATE" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.sec.android.widgetapp.APPWIDGET_RESIZE" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" /> <action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" /> <action android:name="android.intent.action.PACKAGE_REPLACED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
<data android:scheme="package" /> <data android:scheme="package" />
</intent-filter> </intent-filter>
</receiver> </receiver>
@ -81,6 +83,7 @@
<action android:name="android.intent.action.PACKAGE_REPLACED" /> <action android:name="android.intent.action.PACKAGE_REPLACED" />
<action android:name="android.intent.action.PACKAGE_ADDED" /> <action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
<data android:scheme="package" /> <data android:scheme="package" />
</intent-filter> </intent-filter>
</receiver> </receiver>
@ -94,12 +97,23 @@
android:configChanges="keyboardHidden|orientation|screenSize" android:configChanges="keyboardHidden|orientation|screenSize"
android:launchMode="singleInstance" android:launchMode="singleInstance"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity android:name=".ui.activity.ChooseApplicationActivity" <activity
android:name=".ui.activity.ChooseApplicationActivity"
android:configChanges="keyboardHidden|orientation|screenSize" android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity android:name=".ui.activity.WeatherProviderActivity" <activity
android:name=".ui.activity.WeatherProviderActivity"
android:configChanges="keyboardHidden|orientation|screenSize" android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<receiver
android:name=".receiver.OpenWeatherIntentReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.tommasoberlose.anotherwidget.action.ACTION_OPEN_WEATHER_INTENT" />
</intent-filter>
</receiver>
</application> </application>
</manifest> </manifest>

View File

@ -57,10 +57,14 @@ object Constants {
val PREF_TEXT_COLOR = "PREF_TEXT_COLOR" val PREF_TEXT_COLOR = "PREF_TEXT_COLOR"
val PREF_TEXT_MAIN_SIZE = "PREF_TEXT_MAIN_SIZE" val PREF_TEXT_MAIN_SIZE = "PREF_TEXT_MAIN_SIZE"
val PREF_TEXT_SECOND_SIZE = "PREF_TEXT_SECOND_SIZE" val PREF_TEXT_SECOND_SIZE = "PREF_TEXT_SECOND_SIZE"
val PREF_TEXT_CLOCK_SIZE = "PREF_TEXT_CLOCK_SIZE"
val PREF_WEATHER_PROVIDER = "PREF_WEATHER_PROVIDER" val PREF_WEATHER_PROVIDER = "PREF_WEATHER_PROVIDER"
val PREF_SHOW_CLOCK = "PREF_SHOW_CLOCK" val PREF_SHOW_CLOCK = "PREF_SHOW_CLOCK"
val PREF_CLOCK_APP_NAME = "PREF_CLOCK_APP_NAME" val PREF_CLOCK_APP_NAME = "PREF_CLOCK_APP_NAME"
val PREF_CLOCK_APP_PACKAGE = "PREF_CLOCK_APP_PACKAGE" val PREF_CLOCK_APP_PACKAGE = "PREF_CLOCK_APP_PACKAGE"
val PREF_TEXT_SHADOW = "PREF_TEXT_SHADOW"
val PREF_SHOW_DIFF_TIME = "PREF_SHOW_DIFF_TIME"
val PREF_SHOW_DECLINED_EVENTS = "PREF_SHOW_DECLINED_EVENTS"
val ACTION_EXTRA_OPEN_WEATHER_PROVIDER = "ACTION_EXTRA_OPEN_WEATHER_PROVIDER" val ACTION_EXTRA_OPEN_WEATHER_PROVIDER = "ACTION_EXTRA_OPEN_WEATHER_PROVIDER"
@ -72,7 +76,8 @@ object Constants {
val ACTION_TIME_UPDATE = "com.tommasoberlose.anotherwidget.action.ACTION_TIME_UPDATE" val ACTION_TIME_UPDATE = "com.tommasoberlose.anotherwidget.action.ACTION_TIME_UPDATE"
val ACTION_CALENDAR_UPDATE = "com.tommasoberlose.anotherwidget.action.ACTION_CALENDAR_UPDATE" val ACTION_CALENDAR_UPDATE = "com.tommasoberlose.anotherwidget.action.ACTION_CALENDAR_UPDATE"
val ACTION_WEATHER_UPDATE = "com.tommasoberlose.anotherwidget.action.ACTION_WEATHER_UPDATE" val ACTION_WEATHER_UPDATE = "com.tommasoberlose.anotherwidget.action.ACTION_WEATHER_UPDATE"
val ACTION_SOMETHING_APPENED = "com.tommasoberlose.anotherwidget.action.ACTION_SOMETHING_APPENED" val ACTION_SOMETHING_HAPPENED = "com.tommasoberlose.anotherwidget.action.ACTION_SOMETHING_HAPPENED"
val ACTION_OPEN_WEATHER_INTENT = "com.tommasoberlose.anotherwidget.action.ACTION_OPEN_WEATHER_INTENT"
val WEATHER_PROVIDER_GOOGLE_AWARENESS = 1 val WEATHER_PROVIDER_GOOGLE_AWARENESS = 1
val WEATHER_PROVIDER_OPEN_WEATHER = 2 val WEATHER_PROVIDER_OPEN_WEATHER = 2

View File

@ -0,0 +1,17 @@
package com.tommasoberlose.anotherwidget.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.tommasoberlose.anotherwidget.`object`.Constants
import com.tommasoberlose.anotherwidget.util.Util
class OpenWeatherIntentReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Constants.ACTION_OPEN_WEATHER_INTENT) {
context.sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
context.startActivity(Util.getWeatherIntent(context))
}
}
}

View File

@ -13,7 +13,9 @@ import com.tommasoberlose.anotherwidget.`object`.Constants
import com.tommasoberlose.anotherwidget.`object`.Event import com.tommasoberlose.anotherwidget.`object`.Event
import com.tommasoberlose.anotherwidget.util.CalendarUtil import com.tommasoberlose.anotherwidget.util.CalendarUtil
import com.tommasoberlose.anotherwidget.util.Util import com.tommasoberlose.anotherwidget.util.Util
import java.sql.Time
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit
class UpdatesReceiver : BroadcastReceiver() { class UpdatesReceiver : BroadcastReceiver() {
@ -21,7 +23,7 @@ class UpdatesReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
if (intent.action.equals(Intent.ACTION_BOOT_COMPLETED) || intent.action.equals(Intent.ACTION_MY_PACKAGE_REPLACED) || intent.action.equals("android.intent.action.PACKAGE_REPLACED") || intent.action.equals("android.intent.action.PACKAGE_ADDED")) { if (intent.action.equals(Intent.ACTION_BOOT_COMPLETED) || intent.action.equals(Intent.ACTION_MY_PACKAGE_REPLACED) || intent.action.equals("android.intent.action.PACKAGE_REPLACED") || intent.action.equals("android.intent.action.PACKAGE_ADDED")) {
setUpdates(context) setUpdates(context)
} else if (intent.action.equals(Constants.ACTION_TIME_UPDATE)) { } else if (intent.action.equals(Constants.ACTION_TIME_UPDATE) || intent.action.equals("com.sec.android.widgetapp.APPWIDGET_RESIZE") || intent.action == "android.intent.action.USER_PRESENT") {
val e: Event = CalendarUtil.getNextEvent(context) val e: Event = CalendarUtil.getNextEvent(context)
if (e.id == 0 || e.endDate <= Calendar.getInstance().timeInMillis) { if (e.id == 0 || e.endDate <= Calendar.getInstance().timeInMillis) {
CalendarUtil.updateEventList(context) CalendarUtil.updateEventList(context)

View File

@ -27,27 +27,25 @@ import android.graphics.Color
import android.graphics.Typeface import android.graphics.Typeface
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import android.support.annotation.ColorInt
import android.support.design.widget.BottomSheetDialog import android.support.design.widget.BottomSheetDialog
import android.support.v4.content.ContextCompat import android.support.v4.content.ContextCompat
import android.text.Html import android.text.Html
import android.util.Log
import android.util.TypedValue import android.util.TypedValue
import android.widget.Toast import android.widget.Toast
import com.crashlytics.android.Crashlytics import com.crashlytics.android.Crashlytics
import com.pes.androidmaterialcolorpickerdialog.ColorPicker import com.pes.androidmaterialcolorpickerdialog.ColorPicker
import com.tommasoberlose.anotherwidget.`object`.CalendarSelector import com.tommasoberlose.anotherwidget.`object`.CalendarSelector
import com.tommasoberlose.anotherwidget.receiver.UpdatesReceiver
import io.fabric.sdk.android.Fabric import io.fabric.sdk.android.Fabric
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.key_time_wait_layout.view.* import kotlinx.android.synthetic.main.key_time_wait_layout.view.*
import kotlinx.android.synthetic.main.main_menu_layout.view.* import kotlinx.android.synthetic.main.main_menu_layout.view.*
import kotlinx.android.synthetic.main.the_widget.* import kotlinx.android.synthetic.main.the_widget.*
import kotlinx.android.synthetic.main.the_widget.view.*
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
var mAppWidgetId: Int = -1 private var mAppWidgetId: Int = -1
private val receiver = object : BroadcastReceiver() { private val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
@ -59,6 +57,8 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
Fabric.with(this, Crashlytics()) Fabric.with(this, Crashlytics())
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
if (intent.extras?.containsKey(Constants.ACTION_EXTRA_OPEN_WEATHER_PROVIDER) == true) { if (intent.extras?.containsKey(Constants.ACTION_EXTRA_OPEN_WEATHER_PROVIDER) == true) {
startActivityForResult(Intent(this, WeatherProviderActivity::class.java), Constants.WEATHER_PROVIDER_REQUEST_CODE) startActivityForResult(Intent(this, WeatherProviderActivity::class.java), Constants.WEATHER_PROVIDER_REQUEST_CODE)
@ -84,12 +84,6 @@ class MainActivity : AppCompatActivity() {
action_menu.setOnClickListener { action_menu.setOnClickListener {
val mBottomSheetDialog: BottomSheetDialog = BottomSheetDialog(this) val mBottomSheetDialog: BottomSheetDialog = BottomSheetDialog(this)
val menuView: View = getLayoutInflater().inflate(R.layout.main_menu_layout, null) val menuView: View = getLayoutInflater().inflate(R.layout.main_menu_layout, null)
menuView.action_support.setOnClickListener(object: View.OnClickListener {
override fun onClick(p0: View?) {
Util.openURI(this@MainActivity, "https://paypal.me/tommasoberlose")
mBottomSheetDialog.dismiss()
}
})
menuView.action_share.setOnClickListener(object: View.OnClickListener { menuView.action_share.setOnClickListener(object: View.OnClickListener {
override fun onClick(p0: View?) { override fun onClick(p0: View?) {
@ -143,7 +137,7 @@ class MainActivity : AppCompatActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
val filter = IntentFilter() val filter = IntentFilter()
filter.addAction(Constants.ACTION_SOMETHING_APPENED); filter.addAction(Constants.ACTION_SOMETHING_HAPPENED);
registerReceiver(receiver, filter); registerReceiver(receiver, filter);
updateUI() updateUI()
} }
@ -182,11 +176,12 @@ class MainActivity : AppCompatActivity() {
val wallpaper: Drawable? = Util.getCurrentWallpaper(this) val wallpaper: Drawable? = Util.getCurrentWallpaper(this)
if (wallpaper != null) { if (wallpaper != null) {
widget_bg.setImageDrawable(wallpaper) widget_bg.setImageDrawable(wallpaper)
}
widget_bg.setBackgroundColor(Color.WHITE)
updateCalendarView() updateCalendarView()
updateLocationView() updateLocationView()
updateClockView() updateClockView()
} }
}
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@ -226,20 +221,6 @@ class MainActivity : AppCompatActivity() {
WeatherReceiver().setOneTimeUpdate(this) WeatherReceiver().setOneTimeUpdate(this)
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE)) sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
updateSettings() updateSettings()
val mBottomSheetDialog: BottomSheetDialog = BottomSheetDialog(this)
val provView: View = layoutInflater.inflate(R.layout.key_time_wait_layout, null)
provView.title.text = String.format("%s %s", Util.getEmojiByUnicode(0x1F389), getString(R.string.well_done))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
provView.text.text = Html.fromHtml(getString(R.string.api_key_info_all_set), Html.FROM_HTML_MODE_LEGACY)
} else {
provView.text.text = Html.fromHtml(getString(R.string.api_key_info_all_set))
}
provView.action_close.setOnClickListener {
mBottomSheetDialog.dismiss()
}
mBottomSheetDialog.setContentView(provView)
mBottomSheetDialog.show();
} }
} }
@ -266,14 +247,18 @@ class MainActivity : AppCompatActivity() {
dateStringValue = Util.getCapWordString(Constants.itDateFormat.format(now.time)) dateStringValue = Util.getCapWordString(Constants.itDateFormat.format(now.time))
} }
empty_date.text = dateStringValue empty_date.text = dateStringValue
//empty_date.setImageBitmap(Util.buildUpdate(this, String.format("%s%s", Constants.dateFormat.format(now.time)[0].toUpperCase(), Constants.dateFormat.format(now.time).substring(1)), "fonts/product_sans_regular.ttf"))
if (calendarLayout) { if (calendarLayout) {
val e = CalendarUtil.getNextEvent(this) val e = CalendarUtil.getNextEvent(this)
if (e.id != 0) { if (e.id != 0) {
next_event.text = e.title next_event.text = e.title
if (SP.getBoolean(Constants.PREF_SHOW_DIFF_TIME, true)) {
next_event_difference_time.text = Util.getDifferenceText(this, now.timeInMillis, e.startDate) next_event_difference_time.text = Util.getDifferenceText(this, now.timeInMillis, e.startDate)
next_event_difference_time.visibility = View.VISIBLE
} else {
next_event_difference_time.visibility = View.GONE
}
if (!e.address.equals("") && SP.getBoolean(Constants.PREF_SHOW_EVENT_LOCATION, false)) { if (!e.address.equals("") && SP.getBoolean(Constants.PREF_SHOW_EVENT_LOCATION, false)) {
second_row_icon.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_action_location)) second_row_icon.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_action_location))
@ -320,6 +305,7 @@ class MainActivity : AppCompatActivity() {
divider2.setTextColor(Util.getFontColor(SP)) divider2.setTextColor(Util.getFontColor(SP))
calendar_temp.setTextColor(Util.getFontColor(SP)) calendar_temp.setTextColor(Util.getFontColor(SP))
second_row_icon.setColorFilter(Util.getFontColor(SP)) second_row_icon.setColorFilter(Util.getFontColor(SP))
time.setTextColor(Util.getFontColor(SP))
empty_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f)) empty_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f))
@ -330,6 +316,35 @@ class MainActivity : AppCompatActivity() {
next_event_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f)) next_event_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
divider2.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f)) divider2.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
calendar_temp.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f)) calendar_temp.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
time.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f))
val shadowRadius = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
0 -> 0f
1 -> 5f
2 -> 4f
else -> 5f
}
val shadowColor = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
0 -> Color.TRANSPARENT
1 -> R.color.black_50
2 -> Color.BLACK
else -> R.color.black_50
}
val shadowDy = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
0 -> 0f
1 -> 0f
2 -> 1f
else -> 0f
}
empty_date.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
divider1.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
temp.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
next_event.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
next_event_difference_time.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
next_event_date.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
divider2.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
calendar_temp.setShadowLayer(shadowRadius, 0f, 0f, shadowColor)
time.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
val product_sans: Typeface = Typeface.createFromAsset(assets, "fonts/product_sans_regular.ttf") val product_sans: Typeface = Typeface.createFromAsset(assets, "fonts/product_sans_regular.ttf")
@ -341,6 +356,7 @@ class MainActivity : AppCompatActivity() {
next_event_date.typeface = product_sans next_event_date.typeface = product_sans
divider2.typeface = product_sans divider2.typeface = product_sans
calendar_temp.typeface = product_sans calendar_temp.typeface = product_sans
time.typeface = product_sans
} }
fun updateLocationView() { fun updateLocationView() {
@ -383,8 +399,6 @@ class MainActivity : AppCompatActivity() {
.putBoolean(Constants.PREF_SHOW_CLOCK, false) .putBoolean(Constants.PREF_SHOW_CLOCK, false)
.commit() .commit()
sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE)) sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE))
updateSettings()
updateAppWidget()
} }
show_clock_label.text = getString(R.string.show_clock_visible) show_clock_label.text = getString(R.string.show_clock_visible)
} else { } else {
@ -394,8 +408,6 @@ class MainActivity : AppCompatActivity() {
.putBoolean(Constants.PREF_SHOW_CLOCK, true) .putBoolean(Constants.PREF_SHOW_CLOCK, true)
.commit() .commit()
sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE)) sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE))
updateSettings()
updateAppWidget()
} }
show_clock_label.text = getString(R.string.show_clock_not_visible) show_clock_label.text = getString(R.string.show_clock_not_visible)
} }
@ -411,7 +423,7 @@ class MainActivity : AppCompatActivity() {
updateSettings() updateSettings()
updateAppWidget() updateAppWidget()
} }
show_clock_label.text = getString(R.string.show_events_visible) show_events_label.text = getString(R.string.show_events_visible)
} else { } else {
calendar_settings.visibility= View.GONE calendar_settings.visibility= View.GONE
action_show_events.setOnClickListener { action_show_events.setOnClickListener {
@ -471,6 +483,20 @@ class MainActivity : AppCompatActivity() {
updateSettings() updateSettings()
} }
show_diff_time_label.text = if (SP.getBoolean(Constants.PREF_SHOW_DIFF_TIME, true)) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
action_show_diff_time.setOnClickListener {
SP.edit().putBoolean(Constants.PREF_SHOW_DIFF_TIME, !SP.getBoolean(Constants.PREF_SHOW_DIFF_TIME, true)).commit()
sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE))
updateSettings()
}
show_declined_events_label.text = if (SP.getBoolean(Constants.PREF_SHOW_DECLINED_EVENTS, true)) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
action_show_declined_events.setOnClickListener {
SP.edit().putBoolean(Constants.PREF_SHOW_DECLINED_EVENTS, !SP.getBoolean(Constants.PREF_SHOW_DECLINED_EVENTS, true)).commit()
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
updateSettings()
}
hour_format_label.text = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) getString(R.string.settings_hour_format_subtitle_12) else getString(R.string.settings_hour_format_subtitle_24) hour_format_label.text = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) getString(R.string.settings_hour_format_subtitle_12) else getString(R.string.settings_hour_format_subtitle_24)
action_hour_format.setOnClickListener { action_hour_format.setOnClickListener {
SP.edit().putString(Constants.PREF_HOUR_FORMAT, if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) "24" else "12").commit() SP.edit().putString(Constants.PREF_HOUR_FORMAT, if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) "24" else "12").commit()
@ -511,6 +537,17 @@ class MainActivity : AppCompatActivity() {
updateAppWidget() updateAppWidget()
} }
clock_text_size_label.text = String.format("%.0f%s", SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f), "sp")
action_clock_text_size.setOnClickListener {
var fontSize = SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f) + 5
if (fontSize > 110) {
fontSize = 70f
}
SP.edit().putFloat(Constants.PREF_TEXT_CLOCK_SIZE, fontSize).commit()
Util.updateWidget(this)
updateSettings()
updateAppWidget()
}
val textColor = try { val textColor = try {
Color.parseColor(SP.getString(Constants.PREF_TEXT_COLOR, "#FFFFFF")) Color.parseColor(SP.getString(Constants.PREF_TEXT_COLOR, "#FFFFFF"))
@ -544,6 +581,10 @@ class MainActivity : AppCompatActivity() {
updateSettings() updateSettings()
} }
if (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) {
action_weather_refresh_period.visibility = View.GONE
} else {
label_weather_refresh_period.text = getString(Util.getRefreshPeriodString(SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1))) label_weather_refresh_period.text = getString(Util.getRefreshPeriodString(SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1)))
action_weather_refresh_period.setOnClickListener { action_weather_refresh_period.setOnClickListener {
SP.edit().putInt(Constants.PREF_WEATHER_REFRESH_PERIOD, when (SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1)) { SP.edit().putInt(Constants.PREF_WEATHER_REFRESH_PERIOD, when (SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1)) {
@ -558,6 +599,8 @@ class MainActivity : AppCompatActivity() {
updateSettings() updateSettings()
WeatherReceiver().setUpdates(this@MainActivity) WeatherReceiver().setUpdates(this@MainActivity)
} }
action_weather_refresh_period.visibility = View.VISIBLE
}
show_until_label.text = getString(Util.getShowUntilString(SP.getInt(Constants.PREF_SHOW_UNTIL, 1))) show_until_label.text = getString(Util.getShowUntilString(SP.getInt(Constants.PREF_SHOW_UNTIL, 1)))
action_show_until.setOnClickListener { action_show_until.setOnClickListener {
@ -567,51 +610,78 @@ class MainActivity : AppCompatActivity() {
2 -> 3 2 -> 3
3 -> 4 3 -> 4
4 -> 5 4 -> 5
5 -> 0 5 -> 6
6 -> 0
else -> 1 else -> 1
}).commit() }).commit()
updateSettings() updateSettings()
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE)) sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
} }
text_shadow_label.text = getString(Util.getTextshadowString(SP.getInt(Constants.PREF_TEXT_SHADOW, 1)))
action_text_shadow.setOnClickListener {
SP.edit().putInt(Constants.PREF_TEXT_SHADOW, when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
0 -> 1
1 -> 2
2 -> 0
else -> 1
}).commit()
sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE))
updateSettings()
updateAppWidget()
}
if (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) {
action_custom_location.visibility = View.GONE
} else {
label_custom_location.text = SP.getString(Constants.PREF_CUSTOM_LOCATION_ADD, getString(R.string.custom_location_gps)) label_custom_location.text = SP.getString(Constants.PREF_CUSTOM_LOCATION_ADD, getString(R.string.custom_location_gps))
action_custom_location.setOnClickListener { action_custom_location.setOnClickListener {
startActivityForResult(Intent(this, CustomLocationActivity::class.java), Constants.RESULT_CODE_CUSTOM_LOCATION) startActivityForResult(Intent(this, CustomLocationActivity::class.java), Constants.RESULT_CODE_CUSTOM_LOCATION)
} }
action_custom_location.visibility = View.VISIBLE
}
if (!SP.getString(Constants.PREF_WEATHER_PROVIDER_API_KEY, "").equals("")) { if (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) {
label_weather_provider_api_key.text = getString(R.string.settings_weather_provider_api_key_subtitle_all_set) label_weather_provider_api_key.text = getString(R.string.provider_google_awareness)
alert_icon.visibility = View.GONE alert_icon.visibility = View.GONE
} else { } else {
if (SP.getString(Constants.PREF_WEATHER_PROVIDER_API_KEY, "") == ("")) {
label_weather_provider_api_key.text = getString(R.string.settings_weather_provider_api_key_subtitle_not_set) label_weather_provider_api_key.text = getString(R.string.settings_weather_provider_api_key_subtitle_not_set)
alert_icon.visibility = View.VISIBLE alert_icon.visibility = View.VISIBLE
} else {
label_weather_provider_api_key.text = getString(when (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS)) {
Constants.WEATHER_PROVIDER_OPEN_WEATHER -> R.string.provider_open_weather
else -> R.string.settings_weather_provider_api_key_subtitle_all_set
})
alert_icon.visibility = View.GONE
}
} }
action_weather_provider_api_key.setOnClickListener { action_weather_provider_api_key.setOnClickListener {
startActivityForResult(Intent(this, WeatherProviderActivity::class.java), Constants.WEATHER_PROVIDER_REQUEST_CODE) startActivityForResult(Intent(this, WeatherProviderActivity::class.java), Constants.WEATHER_PROVIDER_REQUEST_CODE)
} }
calendar_app_label.text = SP.getString(Constants.PREF_CALENDAR_APP_NAME, getString(R.string.default_name)) calendar_app_label.text = SP.getString(Constants.PREF_CALENDAR_APP_NAME, getString(R.string.default_calendar_app))
action_calendar_app.setOnClickListener { action_calendar_app.setOnClickListener {
startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.CALENDAR_APP_REQUEST_CODE) startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.CALENDAR_APP_REQUEST_CODE)
} }
weather_app_label.text = SP.getString(Constants.PREF_WEATHER_APP_NAME, getString(R.string.default_name)) weather_app_label.text = SP.getString(Constants.PREF_WEATHER_APP_NAME, getString(R.string.default_weather_app))
action_weather_app.setOnClickListener { action_weather_app.setOnClickListener {
startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.WEATHER_APP_REQUEST_CODE) startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.WEATHER_APP_REQUEST_CODE)
} }
clock_app_label.text = SP.getString(Constants.PREF_CLOCK_APP_NAME, getString(R.string.default_name)) clock_app_label.text = SP.getString(Constants.PREF_CLOCK_APP_NAME, getString(R.string.default_clock_app))
action_clock_app.setOnClickListener { action_clock_app.setOnClickListener {
startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.CLOCK_APP_REQUEST_CODE) startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.CLOCK_APP_REQUEST_CODE)
} }
event_app_label.text = SP.getString(Constants.PREF_EVENT_APP_NAME, getString(R.string.default_name)) event_app_label.text = SP.getString(Constants.PREF_EVENT_APP_NAME, getString(R.string.default_event_app))
action_event_app.setOnClickListener { action_event_app.setOnClickListener {
startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.EVENT_APP_REQUEST_CODE) startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.EVENT_APP_REQUEST_CODE)
} }
action_filter_calendar.setOnClickListener { action_filter_calendar.setOnClickListener {
val calendarSelectorList: List<CalendarSelector> = CalendarUtil.getCalendarList(this) val calendarSelectorList: List<CalendarSelector> = CalendarUtil.getCalendarList(this).map { CalendarSelector(it.id.toInt(), it.displayName, it.accountName) }
var calFiltered = SP.getString(Constants.PREF_CALENDAR_FILTER, "") var calFiltered = SP.getString(Constants.PREF_CALENDAR_FILTER, "")
if (!calendarSelectorList.isEmpty()) { if (!calendarSelectorList.isEmpty()) {

View File

@ -22,6 +22,7 @@ import com.tommasoberlose.anotherwidget.util.CalendarUtil
import com.tommasoberlose.anotherwidget.util.Util import com.tommasoberlose.anotherwidget.util.Util
import com.tommasoberlose.anotherwidget.util.WeatherUtil import com.tommasoberlose.anotherwidget.util.WeatherUtil
import kotlinx.android.synthetic.main.activity_weather_provider.* import kotlinx.android.synthetic.main.activity_weather_provider.*
import kotlinx.android.synthetic.main.key_time_wait_layout.view.*
import kotlinx.android.synthetic.main.main_menu_layout.view.* import kotlinx.android.synthetic.main.main_menu_layout.view.*
import kotlinx.android.synthetic.main.provider_info_layout.view.* import kotlinx.android.synthetic.main.provider_info_layout.view.*
@ -35,12 +36,6 @@ class WeatherProviderActivity : AppCompatActivity() {
setContentView(R.layout.activity_weather_provider) setContentView(R.layout.activity_weather_provider)
SP = PreferenceManager.getDefaultSharedPreferences(this) SP = PreferenceManager.getDefaultSharedPreferences(this)
action_paste.setOnClickListener {
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
if (clipboard.primaryClip != null && clipboard.primaryClip.itemCount > 0) {
api_key.setText(clipboard.primaryClip.getItemAt(0).text)
}
}
updateUI() updateUI()
@ -71,27 +66,23 @@ class WeatherProviderActivity : AppCompatActivity() {
action_open_provider.setOnClickListener { action_open_provider.setOnClickListener {
Util.openURI(this, "https://home.openweathermap.org/users/sign_up") Util.openURI(this, "https://home.openweathermap.org/users/sign_up")
} }
action_open_info_text.setOnClickListener {
val mBottomSheetDialog: BottomSheetDialog = BottomSheetDialog(this)
val provView: View = layoutInflater.inflate(R.layout.provider_info_layout, null)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
provView.text.text = Html.fromHtml(getString(R.string.api_key_info_text), Html.FROM_HTML_MODE_LEGACY)
} else {
provView.text.text = Html.fromHtml(getString(R.string.api_key_info_text))
}
mBottomSheetDialog.setContentView(provView)
mBottomSheetDialog.show();
}
} }
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
fun updateUI() { private fun updateUI() {
val currentProvider = SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) val currentProvider = SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS)
if (currentProvider == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) { if (currentProvider == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) {
api_key.visibility = View.GONE api_key_container.visibility = View.GONE
content_info.visibility = View.GONE
} else { } else {
api_key.visibility = View.VISIBLE api_key_container.visibility = View.VISIBLE
content_info.visibility = View.VISIBLE
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
last_info.text = Html.fromHtml(getString(R.string.api_key_info_all_set), Html.FROM_HTML_MODE_LEGACY)
} else {
last_info.text = Html.fromHtml(getString(R.string.api_key_info_all_set))
}
} }
label_weather_provider.text = when (currentProvider) { label_weather_provider.text = when (currentProvider) {
Constants.WEATHER_PROVIDER_OPEN_WEATHER -> getString(R.string.provider_open_weather) Constants.WEATHER_PROVIDER_OPEN_WEATHER -> getString(R.string.provider_open_weather)

View File

@ -31,7 +31,9 @@ import android.widget.TextView
import android.content.ComponentName import android.content.ComponentName
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.BitmapDrawable
import android.os.Bundle
import android.support.v4.content.ContextCompat.startActivity import android.support.v4.content.ContextCompat.startActivity
import android.provider.CalendarContract.Events import android.provider.CalendarContract.Events
import android.support.v4.content.ContextCompat import android.support.v4.content.ContextCompat
@ -51,6 +53,11 @@ class TheWidget : AppWidgetProvider() {
} }
} }
override fun onAppWidgetOptionsChanged(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int, newOptions: Bundle?) {
super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions)
updateAppWidget(context, appWidgetManager, appWidgetId)
}
override fun onEnabled(context: Context) { override fun onEnabled(context: Context) {
UpdatesReceiver().setUpdates(context) UpdatesReceiver().setUpdates(context)
WeatherReceiver().setUpdates(context) WeatherReceiver().setUpdates(context)
@ -67,16 +74,16 @@ class TheWidget : AppWidgetProvider() {
internal fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager, internal fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager,
appWidgetId: Int) { appWidgetId: Int) {
val views = RemoteViews(context.packageName, R.layout.the_widget_sans) var views = RemoteViews(context.packageName, R.layout.the_widget_sans)
var v = View.inflate(context, R.layout.the_widget, null) var v = View.inflate(context, R.layout.the_widget, null)
v = updateCalendarViewByLayout(context, v) v = updateCalendarViewByLayout(context, v)
v = updateLocationViewByLayout(context, v) v = updateLocationViewByLayout(context, v)
v = updateClockViewByLayout(context, v) v = updateClockViewByLayout(context, v)
views.setImageViewBitmap(R.id.bitmap_container, Util.getBitmapFromView(v)) views.setImageViewBitmap(R.id.bitmap_container, Util.getBitmapFromView(v))
/*
views = updateCalendarView(context, views, appWidgetId)
views = updateCalendarView(context, views, appWidgetId)
views = updateLocationView(context, views, appWidgetId) views = updateLocationView(context, views, appWidgetId)
views = updateClockView(context, views, appWidgetId)
val SP = PreferenceManager.getDefaultSharedPreferences(context) val SP = PreferenceManager.getDefaultSharedPreferences(context)
views.setTextColor(R.id.empty_date, Util.getFontColor(SP)) views.setTextColor(R.id.empty_date, Util.getFontColor(SP))
@ -96,7 +103,8 @@ class TheWidget : AppWidgetProvider() {
views.setTextViewTextSize(R.id.next_event_date, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f)) views.setTextViewTextSize(R.id.next_event_date, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
views.setTextViewTextSize(R.id.divider2, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f)) views.setTextViewTextSize(R.id.divider2, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
views.setTextViewTextSize(R.id.calendar_temp, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f)) views.setTextViewTextSize(R.id.calendar_temp, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
*/
appWidgetManager.updateAppWidget(appWidgetId, views) appWidgetManager.updateAppWidget(appWidgetId, views)
} }
@ -112,11 +120,10 @@ class TheWidget : AppWidgetProvider() {
dateStringValue = Util.getCapWordString(Constants.itDateFormat.format(now.time)) dateStringValue = Util.getCapWordString(Constants.itDateFormat.format(now.time))
} }
views.setTextViewText(R.id.empty_date, dateStringValue) views.setTextViewText(R.id.empty_date, dateStringValue)
//views.setImageViewBitmap(R.id.empty_date, Util.buildUpdate(context, Constants.dateFormat.format(now.time)[0].toUpperCase() + Constants.dateFormat.format(now.time).substring(1), "fonts/product_sans_regular.ttf"))
val calPIntent = PendingIntent.getActivity(context, widgetID, Util.getCalendarIntent(context), 0) val calPIntent = PendingIntent.getActivity(context, widgetID, Util.getCalendarIntent(context), 0)
views.setOnClickPendingIntent(R.id.main_layout, calPIntent) views.setOnClickPendingIntent(R.id.empty_date, calPIntent)
if (calendarLayout) { if (calendarLayout) {
@ -124,7 +131,12 @@ class TheWidget : AppWidgetProvider() {
if (e.id != 0) { if (e.id != 0) {
views.setTextViewText(R.id.next_event, e.title) views.setTextViewText(R.id.next_event, e.title)
if (SP.getBoolean(Constants.PREF_SHOW_DIFF_TIME, true)) {
views.setTextViewText(R.id.next_event_difference_time, Util.getDifferenceText(context, now.timeInMillis, e.startDate)) views.setTextViewText(R.id.next_event_difference_time, Util.getDifferenceText(context, now.timeInMillis, e.startDate))
views.setViewVisibility(R.id.next_event_difference_time, View.VISIBLE)
} else {
views.setViewVisibility(R.id.next_event_difference_time, View.GONE)
}
if (!e.address.equals("") && SP.getBoolean(Constants.PREF_SHOW_EVENT_LOCATION, false)) { if (!e.address.equals("") && SP.getBoolean(Constants.PREF_SHOW_EVENT_LOCATION, false)) {
@ -173,7 +185,9 @@ class TheWidget : AppWidgetProvider() {
views.setViewVisibility(R.id.calendar_layout, View.VISIBLE) views.setViewVisibility(R.id.calendar_layout, View.VISIBLE)
val pIntent = PendingIntent.getActivity(context, widgetID, Util.getEventIntent(context, e), 0) val pIntent = PendingIntent.getActivity(context, widgetID, Util.getEventIntent(context, e), 0)
views.setOnClickPendingIntent(R.id.main_layout, pIntent) views.setOnClickPendingIntent(R.id.next_event, pIntent)
views.setOnClickPendingIntent(R.id.next_event_difference_time, pIntent)
views.setOnClickPendingIntent(R.id.next_event_date, pIntent)
} }
} }
@ -205,7 +219,7 @@ class TheWidget : AppWidgetProvider() {
views.setTextViewText(R.id.calendar_temp, temp) views.setTextViewText(R.id.calendar_temp, temp)
val weatherPIntent = PendingIntent.getActivity(context, widgetID, Util.getWeatherIntent(context), 0) val weatherPIntent = PendingIntent.getBroadcast(context, widgetID, Intent(Constants.ACTION_OPEN_WEATHER_INTENT), 0)
views.setOnClickPendingIntent(R.id.weather, weatherPIntent) views.setOnClickPendingIntent(R.id.weather, weatherPIntent)
views.setOnClickPendingIntent(R.id.calendar_weather, weatherPIntent) views.setOnClickPendingIntent(R.id.calendar_weather, weatherPIntent)
@ -216,7 +230,7 @@ class TheWidget : AppWidgetProvider() {
return views return views
} }
fun updateClockView(context: Context, views: RemoteViews, widgetID: Int) { fun updateClockView(context: Context, views: RemoteViews, widgetID: Int): RemoteViews {
val SP = PreferenceManager.getDefaultSharedPreferences(context) val SP = PreferenceManager.getDefaultSharedPreferences(context)
if (!SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) { if (!SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
views.setViewVisibility(R.id.time, View.GONE) views.setViewVisibility(R.id.time, View.GONE)
@ -225,6 +239,11 @@ class TheWidget : AppWidgetProvider() {
} }
val now = Calendar.getInstance() val now = Calendar.getInstance()
views.setTextViewText(R.id.time, if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(now.timeInMillis) else Constants.goodHourFormat.format(now.timeInMillis)) views.setTextViewText(R.id.time, if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(now.timeInMillis) else Constants.goodHourFormat.format(now.timeInMillis))
val clockPIntent = PendingIntent.getActivity(context, widgetID, Util.getClockIntent(context), 0)
views.setOnClickPendingIntent(R.id.time, clockPIntent)
return views
} }
fun updateCalendarViewByLayout(context: Context, v: View): View { fun updateCalendarViewByLayout(context: Context, v: View): View {
@ -239,14 +258,18 @@ class TheWidget : AppWidgetProvider() {
dateStringValue = Util.getCapWordString(Constants.itDateFormat.format(now.time)) dateStringValue = Util.getCapWordString(Constants.itDateFormat.format(now.time))
} }
v.empty_date.text = dateStringValue v.empty_date.text = dateStringValue
//empty_date.setImageBitmap(Util.buildUpdate(this, String.format("%s%s", Constants.dateFormat.format(now.time)[0].toUpperCase(), Constants.dateFormat.format(now.time).substring(1)), "fonts/product_sans_regular.ttf"))
if (calendarLayout) { if (calendarLayout) {
val e = CalendarUtil.getNextEvent(context) val e = CalendarUtil.getNextEvent(context)
if (e.id != 0) { if (e.id != 0) {
v.next_event.text = e.title v.next_event.text = e.title
if (SP.getBoolean(Constants.PREF_SHOW_DIFF_TIME, true)) {
v.next_event_difference_time.text = Util.getDifferenceText(context, now.timeInMillis, e.startDate) v.next_event_difference_time.text = Util.getDifferenceText(context, now.timeInMillis, e.startDate)
v.next_event_difference_time.visibility = View.VISIBLE
} else {
v.next_event_difference_time.visibility = View.GONE
}
if (!e.address.equals("") && SP.getBoolean(Constants.PREF_SHOW_EVENT_LOCATION, false)) { if (!e.address.equals("") && SP.getBoolean(Constants.PREF_SHOW_EVENT_LOCATION, false)) {
v.second_row_icon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_action_location)) v.second_row_icon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_action_location))
@ -293,6 +316,7 @@ class TheWidget : AppWidgetProvider() {
v.divider2.setTextColor(Util.getFontColor(SP)) v.divider2.setTextColor(Util.getFontColor(SP))
v.calendar_temp.setTextColor(Util.getFontColor(SP)) v.calendar_temp.setTextColor(Util.getFontColor(SP))
v.second_row_icon.setColorFilter(Util.getFontColor(SP)) v.second_row_icon.setColorFilter(Util.getFontColor(SP))
v.time.setTextColor(Util.getFontColor(SP))
v.empty_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f)) v.empty_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f))
@ -303,6 +327,35 @@ class TheWidget : AppWidgetProvider() {
v.next_event_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f)) v.next_event_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
v.divider2.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f)) v.divider2.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
v.calendar_temp.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f)) v.calendar_temp.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
v.time.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f))
val shadowRadius = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
0 -> 0f
1 -> 5f
2 -> 5f
else -> 5f
}
val shadowColor = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
0 -> Color.TRANSPARENT
1 -> R.color.black_50
2 -> Color.BLACK
else -> R.color.black_50
}
val shadowDy = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
0 -> 0f
1 -> 0f
2 -> 1f
else -> 0f
}
v.empty_date.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
v.divider1.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
v.temp.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
v.next_event.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
v.next_event_difference_time.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
v.next_event_date.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
v.divider2.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
v.calendar_temp.setShadowLayer(shadowRadius, 0f, 0f, shadowColor)
v.time.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
val product_sans: Typeface = Typeface.createFromAsset(context.assets, "fonts/product_sans_regular.ttf") val product_sans: Typeface = Typeface.createFromAsset(context.assets, "fonts/product_sans_regular.ttf")
@ -314,6 +367,7 @@ class TheWidget : AppWidgetProvider() {
v.next_event_date.typeface = product_sans v.next_event_date.typeface = product_sans
v.divider2.typeface = product_sans v.divider2.typeface = product_sans
v.calendar_temp.typeface = product_sans v.calendar_temp.typeface = product_sans
v.time.typeface = product_sans
return v return v
} }

View File

@ -9,12 +9,17 @@ import android.net.Uri
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.provider.CalendarContract import android.provider.CalendarContract
import android.util.Log import android.util.Log
import android.util.TimeUtils
import android.widget.Toast import android.widget.Toast
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.`object`.CalendarSelector import com.tommasoberlose.anotherwidget.`object`.CalendarSelector
import com.tommasoberlose.anotherwidget.`object`.Constants import com.tommasoberlose.anotherwidget.`object`.Constants
import com.tommasoberlose.anotherwidget.`object`.Event import com.tommasoberlose.anotherwidget.`object`.Event
import me.everything.providers.android.calendar.CalendarProvider
import me.everything.providers.android.contacts.ContactsProvider
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.Comparator
/** /**
* Created by tommaso on 08/10/17. * Created by tommaso on 08/10/17.
@ -36,6 +41,7 @@ object CalendarUtil {
3 -> limit.add(Calendar.DAY_OF_MONTH, 1) 3 -> limit.add(Calendar.DAY_OF_MONTH, 1)
4 -> limit.add(Calendar.DAY_OF_MONTH, 3) 4 -> limit.add(Calendar.DAY_OF_MONTH, 3)
5 -> limit.add(Calendar.DAY_OF_MONTH, 7) 5 -> limit.add(Calendar.DAY_OF_MONTH, 7)
6 -> limit.add(Calendar.HOUR, 1)
else -> limit.add(Calendar.HOUR, 6) else -> limit.add(Calendar.HOUR, 6)
} }
@ -47,49 +53,45 @@ object CalendarUtil {
if (!Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)) { if (!Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)) {
resetNextEventData(context) resetNextEventData(context)
} else { } else {
val provider = CalendarProvider(context)
val instanceCursor = context.contentResolver.query(builder.build(), arrayOf(CalendarContract.Instances.EVENT_ID, CalendarContract.Instances.BEGIN, CalendarContract.Instances.END), null, null, null) val instances = provider.getInstances(now.timeInMillis, limit.timeInMillis).list
if (instanceCursor != null && instanceCursor.count > 0) { for (instance in instances) {
instanceCursor.moveToFirst() val e = provider.getEvent(instance.eventId)
if (e != null && (SP.getBoolean(Constants.PREF_CALENDAR_ALL_DAY, false) || !e.allDay) && !(SP.getString(Constants.PREF_CALENDAR_FILTER, "").contains(" " + e.calendarId + ",")) && (SP.getBoolean(Constants.PREF_SHOW_DECLINED_EVENTS, true) || !e.selfAttendeeStatus.equals(CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED))) {
for (i in 0 until instanceCursor.count) { eventList.add(Event(e.id.toInt(), e.title, e.dTStart, e.dTend, e.calendarId.toInt(), e.allDay, e.eventLocation))
val ID = instanceCursor.getInt(0)
val eventCursor = context.contentResolver.query(CalendarContract.Events.CONTENT_URI, arrayOf(CalendarContract.Events.TITLE, CalendarContract.Events.ALL_DAY, CalendarContract.Events.CALENDAR_ID, CalendarContract.Events.EVENT_LOCATION),
CalendarContract.Events._ID + " = ?",
arrayOf(Integer.toString(ID)), null)
if (eventCursor != null && eventCursor.count > 0) {
eventCursor.moveToFirst()
for (j in 0 until eventCursor.count) {
val e = Event(eventCursor, instanceCursor)
val allDay: Boolean = !eventCursor.getString(1).equals("0")
if ((SP.getBoolean(Constants.PREF_CALENDAR_ALL_DAY, false) || !allDay) && !(SP.getString(Constants.PREF_CALENDAR_FILTER, "").contains(" " + e.calendarID + ","))) {
eventList.add(e)
} }
eventCursor.moveToNext()
}
eventCursor.close()
}
instanceCursor.moveToNext()
}
instanceCursor.close()
} }
if (eventList.isEmpty()) { if (eventList.isEmpty()) {
resetNextEventData(context) resetNextEventData(context)
} else { } else {
Collections.sort(eventList, { event: Event, event1: Event -> eventList.sortWith(Comparator { event: Event, event1: Event ->
if (event.startDate > event1.startDate) { if (event.allDay && event1.allDay) {
return@sort 1 0
} else if (event.startDate < event1.startDate) { } else {
return@sort -1 if (event.allDay) {
Log.d("AW1", event.title + " " + event.startDate + " - " + event1.title + " " + event1.startDate)
if (TimeUnit.MILLISECONDS.toMinutes(event1.startDate - now.timeInMillis) > 31 || now.timeInMillis > event1.endDate) {
1
} else {
-1
}
} else if (event1.allDay) {
Log.d("AW2", event.title + " " + event.startDate + " - " + event1.title + " " + event1.startDate)
if (TimeUnit.MILLISECONDS.toMinutes(event.startDate - now.timeInMillis) > 31 || now.timeInMillis > event.endDate) {
-1
} else {
1
}
} else {
if (event.startDate > event1.startDate) {
1
} else if (event.startDate < event1.startDate) {
-1
}
0
}
} }
return@sort 0
}) })
saveNextEventData(context, eventList.get(0)) saveNextEventData(context, eventList.get(0))
} }
@ -100,13 +102,16 @@ object CalendarUtil {
} }
fun getCalendarList(context: Context): List<CalendarSelector> { fun getCalendarList(context: Context): List<me.everything.providers.android.calendar.Calendar> {
val calendarList = ArrayList<CalendarSelector>() val calendarList = ArrayList<me.everything.providers.android.calendar.Calendar>()
if (!Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)) { if (!Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)) {
return calendarList return calendarList
} }
val provider = CalendarProvider(context)
return provider.calendars.list
/*
try { try {
val calendarCursor = context.contentResolver.query(Uri.parse("content://com.android.calendar/calendars"), val calendarCursor = context.contentResolver.query(Uri.parse("content://com.android.calendar/calendars"),
arrayOf(CalendarContract.Calendars._ID, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, CalendarContract.Calendars.ACCOUNT_NAME), arrayOf(CalendarContract.Calendars._ID, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, CalendarContract.Calendars.ACCOUNT_NAME),
@ -157,7 +162,7 @@ object CalendarUtil {
} }
} finally { } finally {
return calendarList return calendarList
} }*/
} }
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")

View File

@ -28,6 +28,7 @@ import android.util.TypedValue
import android.content.Intent import android.content.Intent
import android.content.ComponentName import android.content.ComponentName
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.provider.AlarmClock
import android.provider.CalendarContract import android.provider.CalendarContract
import android.provider.Settings import android.provider.Settings
import android.support.v4.graphics.drawable.DrawableCompat import android.support.v4.graphics.drawable.DrawableCompat
@ -62,7 +63,7 @@ object Util {
update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds) update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds)
update.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE update.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
context.sendBroadcast(update) context.sendBroadcast(update)
context.sendBroadcast(Intent(Constants.ACTION_SOMETHING_APPENED)) context.sendBroadcast(Intent(Constants.ACTION_SOMETHING_HAPPENED))
} }
fun showNotification(context: Context) { fun showNotification(context: Context) {
@ -144,23 +145,6 @@ object Util {
} }
} }
fun buildUpdate(context: Context, time: String, fontPath: String): Bitmap {
val myBitmap:Bitmap = Bitmap.createBitmap(convertDpToPixel(300f, context).toInt(), convertDpToPixel(40f, context).toInt(), Bitmap.Config.ARGB_8888)
val myCanvas: Canvas = Canvas(myBitmap)
val paint: Paint = Paint()
val clock: Typeface = Typeface.createFromAsset(context.assets, fontPath)
paint.isAntiAlias = true
paint.isSubpixelText = true
paint.typeface = clock
paint.style = Paint.Style.FILL
paint.color = Color.WHITE
paint.textSize = convertSpToPixels(14f, context)
paint.textAlign = Paint.Align.CENTER
paint.setShadowLayer(5f,0f, 0f, R.color.black_50)
myCanvas.drawText("Ultra Pixel Meeting Ciao Ciao", convertDpToPixel(150f, context), convertDpToPixel(20f, context), paint)
return myBitmap;
}
fun getBitmapFromView(view: View): Bitmap { fun getBitmapFromView(view: View): Bitmap {
//Define a bitmap with the same size as the view //Define a bitmap with the same size as the view
val measuredWidth = View.MeasureSpec.makeMeasureSpec(view.width, View.MeasureSpec.UNSPECIFIED) val measuredWidth = View.MeasureSpec.makeMeasureSpec(view.width, View.MeasureSpec.UNSPECIFIED)
@ -223,10 +207,20 @@ object Util {
3 -> R.string.settings_show_until_subtitle_3 3 -> R.string.settings_show_until_subtitle_3
4 -> R.string.settings_show_until_subtitle_4 4 -> R.string.settings_show_until_subtitle_4
5 -> R.string.settings_show_until_subtitle_5 5 -> R.string.settings_show_until_subtitle_5
6 -> R.string.settings_show_until_subtitle_6
else -> R.string.settings_show_until_subtitle_1 else -> R.string.settings_show_until_subtitle_1
} }
} }
fun getTextshadowString(shadow: Int): Int {
return when (shadow) {
0 -> R.string.settings_text_shadow_subtitle_none
1 -> R.string.settings_text_shadow_subtitle_low
2 -> R.string.settings_text_shadow_subtitle_high
else -> R.string.settings_text_shadow_subtitle_low
}
}
fun getCalendarIntent(context: Context): Intent { fun getCalendarIntent(context: Context): Intent {
val SP = PreferenceManager.getDefaultSharedPreferences(context) val SP = PreferenceManager.getDefaultSharedPreferences(context)
if (SP.getString(Constants.PREF_CALENDAR_APP_PACKAGE, "").equals("")) { if (SP.getString(Constants.PREF_CALENDAR_APP_PACKAGE, "").equals("")) {
@ -298,6 +292,26 @@ object Util {
} }
} }
fun getClockIntent(context: Context): Intent {
val SP = PreferenceManager.getDefaultSharedPreferences(context)
if (SP.getString(Constants.PREF_CLOCK_APP_PACKAGE, "").equals("")) {
val clockIntent = Intent(AlarmClock.ACTION_SHOW_ALARMS)
clockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
return clockIntent
} else {
val pm: PackageManager = context.packageManager
return try {
val intent: Intent = pm.getLaunchIntentForPackage(SP.getString(Constants.PREF_CLOCK_APP_PACKAGE, ""))
intent.addCategory(Intent.CATEGORY_LAUNCHER)
intent
} catch (e: Exception) {
val clockIntent = Intent(AlarmClock.ACTION_SHOW_ALARMS)
clockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
return clockIntent
}
}
}
fun getCapWordString(text: String): String { fun getCapWordString(text: String): String {
return try { return try {
val ar = text.split(" ") val ar = text.split(" ")
@ -427,9 +441,10 @@ object Util {
val nowDate = DateTime(now) val nowDate = DateTime(now)
val eventDate = DateTime(start) val eventDate = DateTime(start)
val difference = start - now var difference = start - now
difference += 60 * 1000 - (difference % (60 * 1000))
if (difference < 0) { if (difference <= 0) {
return "" return ""
} else if (TimeUnit.MILLISECONDS.toHours(difference) < 1) { } else if (TimeUnit.MILLISECONDS.toHours(difference) < 1) {
val minutes = TimeUnit.MILLISECONDS.toMinutes(difference) val minutes = TimeUnit.MILLISECONDS.toMinutes(difference)

View File

@ -20,10 +20,14 @@ import android.support.v4.content.ContextCompat.startActivity
import android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS import android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS
import android.content.Intent import android.content.Intent
import android.location.LocationManager import android.location.LocationManager
import android.support.annotation.NonNull
import android.util.Log import android.util.Log
import com.google.android.gms.awareness.Awareness import com.google.android.gms.awareness.Awareness
import com.google.android.gms.awareness.snapshot.WeatherResponse import com.google.android.gms.awareness.snapshot.WeatherResponse
import com.google.android.gms.awareness.snapshot.WeatherResult
import com.google.android.gms.awareness.state.Weather import com.google.android.gms.awareness.state.Weather
import com.google.android.gms.common.api.GoogleApiClient
import com.google.android.gms.common.api.ResultCallback
import com.google.android.gms.tasks.OnFailureListener import com.google.android.gms.tasks.OnFailureListener
import com.google.android.gms.tasks.OnSuccessListener import com.google.android.gms.tasks.OnSuccessListener
import java.util.* import java.util.*
@ -40,13 +44,24 @@ object WeatherUtil {
val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
if (SP.getString(Constants.PREF_CUSTOM_LOCATION_ADD, "").equals("") || SP.getString(Constants.PREF_CUSTOM_LOCATION_LAT, "").equals("") || SP.getString(Constants.PREF_CUSTOM_LOCATION_LON, "").equals("")) { if (SP.getString(Constants.PREF_CUSTOM_LOCATION_ADD, "").equals("") || SP.getString(Constants.PREF_CUSTOM_LOCATION_LAT, "").equals("") || SP.getString(Constants.PREF_CUSTOM_LOCATION_LON, "").equals("")) {
if (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) {
newWeatherProvider(context) newWeatherProvider(context)
return } else {
/*
if (!Util.checkGrantedPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)) { if (!Util.checkGrantedPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)) {
return return
} }
val mGoogleApiClient = GoogleApiClient.Builder(context)
.addApi(Awareness.API)
.build()
mGoogleApiClient.connect()
Awareness.SnapshotApi.getLocation(mGoogleApiClient)
.setResultCallback({ locationResult ->
if (locationResult.status.isSuccess) {
getCurrentWeather(context, locationResult.location)
}
})
/*
var gpsEnabled = false var gpsEnabled = false
var networkEnabled = false var networkEnabled = false
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
@ -73,7 +88,9 @@ object WeatherUtil {
if (networkEnabled) { if (networkEnabled) {
getCurrentWeather(context, locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)) getCurrentWeather(context, locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER))
} }
}*/ }
*/
}
} else { } else {
weatherNetworkRequest(context, SP.getString(Constants.PREF_CUSTOM_LOCATION_LAT, "").toDouble(), SP.getString(Constants.PREF_CUSTOM_LOCATION_LON, "").toDouble()) weatherNetworkRequest(context, SP.getString(Constants.PREF_CUSTOM_LOCATION_LAT, "").toDouble(), SP.getString(Constants.PREF_CUSTOM_LOCATION_LON, "").toDouble())
} }
@ -84,9 +101,15 @@ object WeatherUtil {
if (!Util.checkGrantedPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)) { if (!Util.checkGrantedPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)) {
return return
} }
Awareness.getSnapshotClient(context).weather val mGoogleApiClient = GoogleApiClient.Builder(context)
.addOnSuccessListener { weatherResponse -> .addApi(Awareness.API)
val weather: Weather = weatherResponse.weather .build();
mGoogleApiClient.connect()
Awareness.SnapshotApi.getWeather(mGoogleApiClient)
.setResultCallback({ weatherResult ->
if (weatherResult.status.isSuccess) {
val weather: Weather = weatherResult.weather
val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
SP.edit() SP.edit()
.putFloat(Constants.PREF_WEATHER_TEMP, weather.getTemperature(if (SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F").equals("F")) Weather.FAHRENHEIT else Weather.CELSIUS)) .putFloat(Constants.PREF_WEATHER_TEMP, weather.getTemperature(if (SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F").equals("F")) Weather.FAHRENHEIT else Weather.CELSIUS))
@ -95,6 +118,8 @@ object WeatherUtil {
.commit() .commit()
Util.updateWidget(context) Util.updateWidget(context)
} }
mGoogleApiClient.disconnect()
})
} }

View File

@ -81,31 +81,6 @@
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:text="@string/settings_general_title" android:text="@string/settings_general_title"
style="@style/AnotherWidget.Settings.Header"/> style="@style/AnotherWidget.Settings.Header"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:id="@+id/action_font_color"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title"
android:text="@string/settings_font_color_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/font_color_label"
style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -154,6 +129,54 @@
android:id="@+id/second_text_size_label" android:id="@+id/second_text_size_label"
style="@style/AnotherWidget.Settings.Subtitle"/> style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:id="@+id/action_font_color"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title"
android:text="@string/settings_font_color_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/font_color_label"
style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:id="@+id/action_text_shadow"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title"
android:text="@string/title_text_shadow"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_shadow_label"
style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
@ -179,6 +202,11 @@
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical" android:gravity="center_vertical"
android:id="@+id/action_show_clock" android:id="@+id/action_show_clock"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -192,11 +220,43 @@
android:text="@string/description_show_clock" android:text="@string/description_show_clock"
style="@style/AnotherWidget.Settings.Subtitle"/> style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout> </LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/beta"
android:layout_marginLeft="8dp"
android:layout_gravity="center_vertical|right"
style="@style/AnotherWidget.Settings.Header"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/clock_settings" android:id="@+id/clock_settings"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:id="@+id/action_clock_text_size"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title"
android:text="@string/settings_clock_text_size_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/clock_text_size_label"
style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -361,6 +421,30 @@
android:id="@+id/all_day_label" android:id="@+id/all_day_label"
style="@style/AnotherWidget.Settings.Subtitle"/> style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:id="@+id/action_show_declined_events"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title"
android:text="@string/settings_show_declined_events_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/show_declined_events_label"
style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -385,6 +469,30 @@
android:id="@+id/show_until_label" android:id="@+id/show_until_label"
style="@style/AnotherWidget.Settings.Subtitle"/> style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:id="@+id/action_show_diff_time"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title"
android:text="@string/settings_show_diff_time_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/show_diff_time_label"
style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -72,18 +72,22 @@
style="@style/AnotherWidget.Settings.Subtitle" style="@style/AnotherWidget.Settings.Subtitle"
android:textColor="@android:color/black"/> android:textColor="@android:color/black"/>
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/black_10"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize" android:layout_height="?android:attr/actionBarSize"
android:orientation="horizontal" android:orientation="horizontal"
android:descendantFocusability="beforeDescendants" android:descendantFocusability="beforeDescendants"
android:focusable="true" android:focusable="true"
android:id="@+id/api_key_container"
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:gravity="center_vertical"> android:gravity="center_vertical">
<EditText <EditText
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/white" android:background="@android:color/white"
android:padding="16dp" android:padding="16dp"
android:inputType="textCapWords" android:inputType="textCapWords"
@ -93,13 +97,6 @@
android:nextFocusLeft="@id/api_key" android:nextFocusLeft="@id/api_key"
android:gravity="center_vertical" android:gravity="center_vertical"
android:hint="@string/api_key_hint"/> android:hint="@string/api_key_hint"/>
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:padding="12dp"
android:id="@+id/action_paste"
android:src="@drawable/ic_action_paste"
android:tint="@android:color/black"/>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -122,6 +119,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:focusable="true" android:focusable="true"
android:id="@+id/content_info"
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
@ -134,27 +132,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:padding="16dp"> android:padding="16dp">
<LinearLayout <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="@string/api_key_info_title" android:text="@string/api_key_info_title"
android:gravity="start" android:gravity="start"
style="@style/AnotherWidget.Main.Title" style="@style/AnotherWidget.Main.Title"
android:textSize="20sp" android:textSize="20sp"
android:textColor="@android:color/black"/> android:textColor="@android:color/black"/>
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/action_open_info_text"
android:tint="@android:color/black"
android:src="@drawable/ic_action_info"/>
</LinearLayout>
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -211,6 +196,14 @@
android:textSize="16sp" android:textSize="16sp"
android:gravity="start" android:gravity="start"
android:text="@string/api_key_subtitle_3"/> android:text="@string/api_key_subtitle_3"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
style="@style/AnotherWidget.Main.Subtitle"
android:textSize="16sp"
android:gravity="start"
android:id="@+id/last_info"/>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>

View File

@ -123,6 +123,7 @@
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:padding="16dp" android:padding="16dp"
android:visibility="gone"
android:id="@+id/action_support" android:id="@+id/action_support"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView

View File

@ -7,20 +7,21 @@
android:id="@+id/time" android:id="@+id/time"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="20:16" android:layout_marginTop="-16dp"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:gravity="center" android:gravity="center"
android:lineSpacingMultiplier="1" android:lineSpacingMultiplier="1"
android:lineSpacingExtra="0dp" android:lineSpacingExtra="0dp"
android:visibility="gone"
android:includeFontPadding="false" android:includeFontPadding="false"
android:padding="0dp" android:padding="0dp"
android:visibility="gone"
style="@style/AnotherWidget.Title" style="@style/AnotherWidget.Title"
android:textSize="90sp"/> android:textSize="90sp"/>
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:layout_marginTop="-8dp"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_below="@+id/time" android:layout_below="@+id/time"
android:orientation="horizontal" android:orientation="horizontal"
@ -71,6 +72,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:visibility="gone" android:visibility="gone"
android:layout_marginTop="-8dp"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_below="@+id/time" android:layout_below="@+id/time"
android:id="@+id/calendar_layout" android:id="@+id/calendar_layout"

View File

@ -1,11 +1,20 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_layout"> android:id="@+id/main_layout">
<ImageView <ImageView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:id="@+id/bitmap_container"/> android:id="@+id/bitmap_container"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:alpha="0">
<include layout="@layout/the_widget"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/intent_container" />
</LinearLayout>
</RelativeLayout> </RelativeLayout>

View File

@ -93,7 +93,7 @@
<string name="api_key_info_start">Ciao a tutti.</string> <string name="api_key_info_start">Ciao a tutti.</string>
<string name="api_key_info_text"><![CDATA[Another widget è e rimarrà gratuita e senza banner pubblicitari.<BR /><BR />Però a causa del successo dell\'applicazione, sicuramente oltre ogni mia aspettativa, il provider del meteo non riesce a supportare il numero di richieste che arrivano (a causa dell\'utilizzo di un account gratuito).<BR /><BR />Sono costretto a chiedervi di registrarvi su OpenWeather.com; l\'operazione richiederà solo alcuni minuti e dopo non avrete più problemi con la fruizione delle informazioni sul meteo!<BR /><BR />Mi dispiace per l\'inconveniente ma continuate a supportarmi!!]]></string> <string name="api_key_info_text"><![CDATA[Another widget è e rimarrà gratuita e senza banner pubblicitari.<BR /><BR />Però a causa del successo dell\'applicazione, sicuramente oltre ogni mia aspettativa, il provider del meteo non riesce a supportare il numero di richieste che arrivano (a causa dell\'utilizzo di un account gratuito).<BR /><BR />Sono costretto a chiedervi di registrarvi su OpenWeather.com; l\'operazione richiederà solo alcuni minuti e dopo non avrete più problemi con la fruizione delle informazioni sul meteo!<BR /><BR />Mi dispiace per l\'inconveniente ma continuate a supportarmi!!]]></string>
<string name="well_done">Ben Fatto!</string> <string name="well_done">Ben Fatto!</string>
<string name="api_key_info_all_set"><![CDATA[Posso essere necessari fino a <b>dieci minuti</b> prima che la tua chiave sia attivata.<BR /><BR />Quindi <i>rilassati</i>! Il meteo verrà aggiornato non appena sarà disponibile!]]></string> <string name="api_key_info_all_set"><![CDATA[Posso essere necessari fino a <b>dieci minuti</b> prima che la tua chiave sia attivata.<BR />Quindi <i>rilassati</i>! Il meteo verrà aggiornato non appena sarà disponibile!]]></string>
<string name="hs_code">" ore"</string> <string name="hs_code">" ore"</string>
<string name="tomorrow">Domani</string> <string name="tomorrow">Domani</string>
<string name="today">Oggi</string> <string name="today">Oggi</string>
@ -110,4 +110,22 @@
<string name="description_show_clock">Mostra l\'ora sopra eventi e meteo</string> <string name="description_show_clock">Mostra l\'ora sopra eventi e meteo</string>
<string name="show_clock_visible">Orologio visibile</string> <string name="show_clock_visible">Orologio visibile</string>
<string name="show_clock_not_visible">Orologio non visibile</string> <string name="show_clock_not_visible">Orologio non visibile</string>
<string name="settings_clock_text_size_title">Dimensione Testo Orologio</string>
<string name="title_text_shadow">Ombra Testo</string>
<string name="settings_text_shadow_subtitle_none">Nessuna</string>
<string name="settings_text_shadow_subtitle_low">Bassa</string>
<string name="settings_text_shadow_subtitle_high">Alta</string>
<string name="advanced_settings_title">Impostazioni Avanzate</string>
<string name="beta">Beta</string>
<string name="settings_product_sans_font_title">Font Product Sans</string>
<string name="settings_product_sans_font_subtitle">L\'utilizzo del Product Sans disabilita i tap sugli elementi del widget. Ci sto attualmente lavorando.</string>
<string name="settings_show_until_subtitle_6">1 Ora dopo</string>
<string name="settings_show_diff_time_title">Tempo rimanente all\'evento</string>
<string name="settings_show_declined_events_title">Event Rifiutati</string>
<string name="settings_visible">Visibile</string>
<string name="settings_not_visible">Non Visibile</string>
<string name="default_event_app">Dettagli Evento Google Calendar</string>
<string name="default_calendar_app">App Calendario di Default</string>
<string name="default_weather_app">Meteo Google</string>
<string name="default_clock_app">App Orologio di Default</string>
</resources> </resources>

View File

@ -94,7 +94,7 @@
<string name="api_key_subtitle_3">Enter the key in this section and save it. Once the key is activated the weather will be visible.</string> <string name="api_key_subtitle_3">Enter the key in this section and save it. Once the key is activated the weather will be visible.</string>
<string name="api_key_info_start">Hi Everyone!</string> <string name="api_key_info_start">Hi Everyone!</string>
<string name="action_open_provider">Go to OpenWeather.com</string> <string name="action_open_provider">Go to OpenWeather.com</string>
<string name="api_key_info_all_set"><![CDATA[It may take up to <b>ten minutes</b> before your API key is activated.<BR /><BR />So <i>relax</i>! The weather will be updated as soon as it is available!!]]></string> <string name="api_key_info_all_set"><![CDATA[It may take up to <b>ten minutes</b> before your API key is activated.<BR />So <i>relax</i>! The weather will be updated as soon as it is available!!]]></string>
<string name="well_done">Well Done!</string> <string name="well_done">Well Done!</string>
<string name="hs_code">h</string> <string name="hs_code">h</string>
<string name="tomorrow">Tomorrow</string> <string name="tomorrow">Tomorrow</string>
@ -114,4 +114,22 @@
<string name="description_show_clock">View the time over events and weather</string> <string name="description_show_clock">View the time over events and weather</string>
<string name="show_clock_visible">Clock is visible</string> <string name="show_clock_visible">Clock is visible</string>
<string name="show_clock_not_visible">Clock is not visible</string> <string name="show_clock_not_visible">Clock is not visible</string>
<string name="settings_clock_text_size_title">Clock Text Size</string>
<string name="title_text_shadow">Text Shadow</string>
<string name="settings_text_shadow_subtitle_none">None</string>
<string name="settings_text_shadow_subtitle_low">Low</string>
<string name="settings_text_shadow_subtitle_high">High</string>
<string name="advanced_settings_title">Advanced Settings</string>
<string name="beta">Beta</string>
<string name="settings_product_sans_font_title">Product Sans Font</string>
<string name="settings_product_sans_font_subtitle">Using Product Sans disabled the possibilty to tap widget elements. I\'m working on it.</string>
<string name="settings_show_until_subtitle_6">1 hour later</string>
<string name="settings_show_diff_time_title">Time left for the event</string>
<string name="settings_visible">Visible</string>
<string name="settings_not_visible">Not Visible</string>
<string name="settings_show_declined_events_title">Declined Events</string>
<string name="default_weather_app">Google Weather</string>
<string name="default_event_app">Google Calendar Event Details</string>
<string name="default_calendar_app">Default Calendar App</string>
<string name="default_clock_app">Default Clock App</string>
</resources> </resources>