Multiple changes and fixes
This commit is contained in:
@ -0,0 +1,80 @@
|
||||
package com.tommasoberlose.anotherwidget.ui.activity
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.location.Address
|
||||
import android.location.Geocoder
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import android.transition.Slide
|
||||
import android.view.Gravity
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import android.support.v4.view.ViewCompat.setAlpha
|
||||
import android.support.v4.view.ViewCompat.animate
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Toast
|
||||
import com.tommasoberlose.anotherwidget.`object`.Constants
|
||||
import com.tommasoberlose.anotherwidget.util.WeatherUtil
|
||||
import kotlinx.android.synthetic.main.activity_custom_location.*
|
||||
|
||||
|
||||
class CustomLocationActivity : AppCompatActivity() {
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_custom_location)
|
||||
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
val list = ArrayList<String>()
|
||||
val addressesList = ArrayList<Address>()
|
||||
val thread: Thread = Thread()
|
||||
|
||||
var adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, list)
|
||||
list_view.adapter = adapter
|
||||
|
||||
list_view.onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, id ->
|
||||
SP.edit()
|
||||
.putString(Constants.PREF_CUSTOM_LOCATION_LAT, addressesList[position].latitude.toString())
|
||||
.putString(Constants.PREF_CUSTOM_LOCATION_LON, addressesList[position].longitude.toString())
|
||||
.putString(Constants.PREF_CUSTOM_LOCATION_ADD, addressesList[position].getAddressLine(0))
|
||||
.commit()
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
|
||||
location.addTextChangedListener(object: TextWatcher {
|
||||
override fun afterTextChanged(text: Editable?) {
|
||||
val coder = Geocoder(this@CustomLocationActivity)
|
||||
try {
|
||||
val addresses = coder.getFromLocationName(text.toString(), 10) as ArrayList<Address>
|
||||
list.clear()
|
||||
addressesList.clear()
|
||||
|
||||
addresses.mapTo(list) { it.getAddressLine(0) }
|
||||
addresses.mapTo(addressesList) { it }
|
||||
|
||||
adapter = ArrayAdapter(this@CustomLocationActivity, R.layout.custom_location_item, list)
|
||||
list_view.adapter = adapter
|
||||
} catch (ignored: Exception) {
|
||||
Toast.makeText(this@CustomLocationActivity, "Erroreeeee", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
}
|
||||
|
||||
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.tommasoberlose.anotherwidget.ui.activity
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.app.AlertDialog
|
||||
import android.content.pm.PackageManager
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
@ -16,8 +17,6 @@ import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.util.Util
|
||||
import com.tommasoberlose.anotherwidget.receiver.UpdatesReceiver
|
||||
import com.tommasoberlose.anotherwidget.receiver.WeatherReceiver
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.the_widget.*
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import android.content.Intent
|
||||
@ -25,8 +24,18 @@ import android.content.BroadcastReceiver
|
||||
import com.tommasoberlose.anotherwidget.util.CalendarUtil
|
||||
import com.tommasoberlose.anotherwidget.util.WeatherUtil
|
||||
import android.content.DialogInterface
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import com.github.rubensousa.bottomsheetbuilder.BottomSheetBuilder
|
||||
import com.github.rubensousa.bottomsheetbuilder.BottomSheetMenuDialog
|
||||
import com.tommasoberlose.anotherwidget.`object`.CalendarSelector
|
||||
import io.fabric.sdk.android.Fabric
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.the_widget.*
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
@ -41,9 +50,7 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
receiver
|
||||
|
||||
// TODO Util.showIntro(this)
|
||||
Fabric.with(this, Crashlytics())
|
||||
|
||||
action_support.setOnClickListener(object: View.OnClickListener {
|
||||
override fun onClick(p0: View?) {
|
||||
@ -80,15 +87,11 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>,
|
||||
grantResults: IntArray) {
|
||||
when (requestCode) {
|
||||
Constants.CALENDAR_REQUEST_CODE -> if (permissions.size != 1 || grantResults.size != 1 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
|
||||
UpdatesReceiver().removeUpdates(this)
|
||||
} else {
|
||||
UpdatesReceiver().setUpdates(this)
|
||||
Constants.CALENDAR_REQUEST_CODE -> if (!(permissions.size != 1 || grantResults.size != 1 || grantResults[0] != PackageManager.PERMISSION_GRANTED)) {
|
||||
CalendarUtil.updateEventList(this)
|
||||
}
|
||||
Constants.LOCATION_REQUEST_CODE -> if (permissions.size != 1 || grantResults.size != 1 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
|
||||
WeatherReceiver().removeUpdates(this)
|
||||
} else {
|
||||
WeatherReceiver().setUpdates(this)
|
||||
Constants.LOCATION_REQUEST_CODE -> if (!(permissions.size != 1 || grantResults.size != 1 || grantResults[0] != PackageManager.PERMISSION_GRANTED)) {
|
||||
WeatherUtil.updateWeather(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -107,11 +110,11 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (!Util.checkGrantedPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)) {
|
||||
if (!Util.checkGrantedPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
no_location_permission_container.visibility = View.VISIBLE
|
||||
request_location.setOnClickListener(object: View.OnClickListener {
|
||||
override fun onClick(view: View?) {
|
||||
ActivityCompat.requestPermissions(this@MainActivity, arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION), Constants.LOCATION_REQUEST_CODE)
|
||||
ActivityCompat.requestPermissions(this@MainActivity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), Constants.LOCATION_REQUEST_CODE)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@ -123,18 +126,36 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
|
||||
internal fun updateAppWidget() {
|
||||
widget_bg.setImageDrawable(Util.getCurrentWallpaper(this))
|
||||
updateCalendarView()
|
||||
updateLocationView()
|
||||
val wallpaper: Drawable? = Util.getCurrentWallpaper(this)
|
||||
if (wallpaper != null) {
|
||||
widget_bg.setImageDrawable(wallpaper)
|
||||
updateCalendarView()
|
||||
updateLocationView()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == Constants.RESULT_CODE_CUSTOM_LOCATION) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
updateSettings()
|
||||
WeatherUtil.updateWeather(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCalendarView() {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val now = Calendar.getInstance()
|
||||
val calendarLayout = Util.checkGrantedPermission(this, Manifest.permission.READ_CALENDAR)
|
||||
|
||||
empty_layout.visibility = View.VISIBLE
|
||||
calendar_layout.visibility = View.GONE
|
||||
empty_date.text = String.format("%s%s", Constants.dateFormat.format(now.time)[0].toUpperCase(), Constants.dateFormat.format(now.time).substring(1))
|
||||
var dateStringValue: String = String.format("%s%s", Constants.engDateFormat.format(now.time)[0].toUpperCase(), Constants.engDateFormat.format(now.time).substring(1))
|
||||
if (SP.getBoolean(Constants.PREF_ITA_FORMAT_DATE, false)) {
|
||||
dateStringValue = String.format("%s%s", Constants.itDateFormat.format(now.time)[0].toUpperCase(), Constants.itDateFormat.format(now.time).substring(1))
|
||||
}
|
||||
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) {
|
||||
val e = CalendarUtil.getNextEvent(this)
|
||||
@ -148,18 +169,25 @@ class MainActivity : AppCompatActivity() {
|
||||
var time = ""
|
||||
val hour = TimeUnit.MILLISECONDS.toHours(difference)
|
||||
if (hour > 0) {
|
||||
time = hour.toString() + getString(R.string.h_code)
|
||||
time = hour.toString() + getString(R.string.h_code) + " "
|
||||
}
|
||||
val minutes = TimeUnit.MILLISECONDS.toMinutes(difference - hour * 3600 * 1000)
|
||||
if (minutes > 0) {
|
||||
time += " " + minutes + getString(R.string.min_code)
|
||||
time += "" + minutes + getString(R.string.min_code)
|
||||
}
|
||||
|
||||
next_event.text = String.format("%s %s %s", e.title, getString(R.string.in_code), time)
|
||||
} else {
|
||||
next_event.text = String.format("%s", e.title)
|
||||
}
|
||||
next_event_date.text = String.format("%s - %s", Constants.hourFormat.format(e.startDate), Constants.hourFormat.format(e.endDate))
|
||||
|
||||
if (!e.allDay) {
|
||||
val startHour: String = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(e.startDate) else Constants.goodHourFormat.format(e.startDate)
|
||||
val endHour: String = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(e.endDate) else Constants.goodHourFormat.format(e.endDate)
|
||||
next_event_date.text = String.format("%s - %s", startHour, endHour)
|
||||
} else {
|
||||
next_event_date.text = dateStringValue
|
||||
}
|
||||
|
||||
empty_layout.visibility = View.GONE
|
||||
calendar_layout.visibility = View.VISIBLE
|
||||
@ -168,7 +196,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
fun updateLocationView() {
|
||||
val locationLayout = Util.checkGrantedPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||
val locationLayout = Util.checkGrantedPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
if (locationLayout && SP.contains(Constants.PREF_WEATHER_TEMP) && SP.contains(Constants.PREF_WEATHER_ICON)) {
|
||||
@ -202,40 +230,92 @@ class MainActivity : AppCompatActivity() {
|
||||
temp_unit.text = if (SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F").equals("F")) getString(R.string.fahrenheit) else getString(R.string.celsius)
|
||||
action_change_unit.setOnClickListener {
|
||||
SP.edit().putString(Constants.PREF_WEATHER_TEMP_UNIT, if (SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F").equals("F")) "C" else "F").commit()
|
||||
WeatherUtil.getWeather(this)
|
||||
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
|
||||
updateSettings()
|
||||
}
|
||||
|
||||
all_day_label.text = if (SP.getBoolean(Constants.PREF_CALENDAR_ALL_DAY, false)) getString(R.string.settings_all_day_subtitle_visible) else getString(R.string.settings_all_day_subtitle_gone)
|
||||
action_show_all_day.setOnClickListener {
|
||||
SP.edit().putBoolean(Constants.PREF_CALENDAR_ALL_DAY, !SP.getBoolean(Constants.PREF_CALENDAR_ALL_DAY, false)).commit()
|
||||
updateUI()
|
||||
CalendarUtil.updateEventList(this)
|
||||
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)
|
||||
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()
|
||||
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
|
||||
updateSettings()
|
||||
}
|
||||
|
||||
val now = Calendar.getInstance()
|
||||
var dateStringValue: String = String.format("%s%s", Constants.engDateFormat.format(now.time)[0].toUpperCase(), Constants.engDateFormat.format(now.time).substring(1))
|
||||
if (SP.getBoolean(Constants.PREF_ITA_FORMAT_DATE, false)) {
|
||||
dateStringValue = String.format("%s%s", Constants.itDateFormat.format(now.time)[0].toUpperCase(), Constants.itDateFormat.format(now.time).substring(1))
|
||||
}
|
||||
date_format_label.text = dateStringValue
|
||||
action_date_format.setOnClickListener {
|
||||
SP.edit().putBoolean(Constants.PREF_ITA_FORMAT_DATE, !SP.getBoolean(Constants.PREF_ITA_FORMAT_DATE, false)).commit()
|
||||
updateSettings()
|
||||
Util.updateWidget(this)
|
||||
}
|
||||
|
||||
label_weather_refresh_period.text = getString(Util.getRefreshPeriodString(SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1)))
|
||||
action_weather_refresh_period.setOnClickListener {
|
||||
val dialog: BottomSheetMenuDialog = BottomSheetBuilder(this, R.style.Theme_Design_Light_BottomSheetDialog)
|
||||
.setMode(BottomSheetBuilder.MODE_LIST)
|
||||
.setMenu(R.menu.weather_refresh_period_menu)
|
||||
.setIconTintColor(ContextCompat.getColor(this, R.color.black_50))
|
||||
.delayDismissOnItemClick(false)
|
||||
.setItemClickListener({ item: MenuItem ->
|
||||
SP.edit().putInt(Constants.PREF_WEATHER_REFRESH_PERIOD, when (item.itemId) {
|
||||
R.id.refresh_1 -> 1
|
||||
R.id.refresh_2 -> 2
|
||||
R.id.refresh_3 -> 3
|
||||
R.id.refresh_4 -> 4
|
||||
R.id.refresh_5 -> 5
|
||||
else -> 1
|
||||
}).commit()
|
||||
updateSettings()
|
||||
WeatherReceiver().setUpdates(this@MainActivity)
|
||||
})
|
||||
.createDialog()
|
||||
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
label_custom_location.text = SP.getString(Constants.PREF_CUSTOM_LOCATION_ADD, getString(R.string.custom_location_gps))
|
||||
action_custom_location.setOnClickListener {
|
||||
startActivityForResult(Intent(this, CustomLocationActivity::class.java), Constants.RESULT_CODE_CUSTOM_LOCATION)
|
||||
}
|
||||
|
||||
action_filter_calendar.setOnClickListener {
|
||||
val calendarSelectorList: List<CalendarSelector> = CalendarUtil.getCalendarList(this)
|
||||
var calFiltered = SP.getString(Constants.PREF_CALENDAR_FILTER, "")
|
||||
|
||||
if (!calendarSelectorList.isEmpty()) {
|
||||
val calNames = calendarSelectorList.map { if (it.name.equals(it.account_name)) String.format("%s: %s", getString(R.string.main_calendar), it.name) else it.name }.toTypedArray()
|
||||
val calSelected = calendarSelectorList.map { !calFiltered.contains(" " + Integer.toString(it.id) + ",") }.toBooleanArray()
|
||||
|
||||
val calNames = calendarSelectorList.map { if (it.name.equals(it.account_name)) String.format("%s: %s", getString(R.string.main_calendar), it.name) else it.name }.toTypedArray()
|
||||
val calSelected = calendarSelectorList.map { !calFiltered.contains(" " + Integer.toString(it.id)+",") }.toBooleanArray()
|
||||
|
||||
AlertDialog.Builder(this).setTitle(getString(R.string.settings_filter_calendar_subtitle))
|
||||
.setMultiChoiceItems(calNames, calSelected,
|
||||
DialogInterface.OnMultiChoiceClickListener { dialog, item, isChecked ->
|
||||
val dialogItem: String = String.format(" %s%s", calendarSelectorList.get(item).id, ",")
|
||||
calFiltered = calFiltered.replace(dialogItem, "");
|
||||
if (!isChecked) {
|
||||
calFiltered += dialogItem
|
||||
}
|
||||
})
|
||||
.setPositiveButton(android.R.string.ok, { dialog: DialogInterface, _: Int ->
|
||||
SP.edit().putString(Constants.PREF_CALENDAR_FILTER, calFiltered).commit()
|
||||
CalendarUtil.updateEventList(this)
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show()
|
||||
AlertDialog.Builder(this).setTitle(getString(R.string.settings_filter_calendar_subtitle))
|
||||
.setMultiChoiceItems(calNames, calSelected,
|
||||
DialogInterface.OnMultiChoiceClickListener { dialog, item, isChecked ->
|
||||
val dialogItem: String = String.format(" %s%s", calendarSelectorList.get(item).id, ",")
|
||||
calFiltered = calFiltered.replace(dialogItem, "");
|
||||
if (!isChecked) {
|
||||
calFiltered += dialogItem
|
||||
}
|
||||
})
|
||||
.setPositiveButton(android.R.string.ok, { dialog: DialogInterface, _: Int ->
|
||||
SP.edit().putString(Constants.PREF_CALENDAR_FILTER, calFiltered).commit()
|
||||
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
|
||||
updateSettings()
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show()
|
||||
} else {
|
||||
Toast.makeText(this, R.string.calendar_settings_list_error, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,41 +0,0 @@
|
||||
package com.tommasoberlose.anotherwidget.ui.activity
|
||||
|
||||
import android.Manifest
|
||||
import android.os.Bundle
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.heinrichreimersoftware.materialintro.app.IntroActivity
|
||||
import com.heinrichreimersoftware.materialintro.slide.SimpleSlide
|
||||
|
||||
|
||||
class SplashActivity : IntroActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
isButtonNextVisible = true
|
||||
isButtonBackVisible = false
|
||||
isButtonCtaVisible = false
|
||||
buttonCtaTintMode = BUTTON_CTA_TINT_MODE_TEXT
|
||||
|
||||
addSlide(SimpleSlide.Builder()
|
||||
.title(R.string.app_name)
|
||||
.background(R.color.colorPrimary)
|
||||
.backgroundDark(R.color.colorPrimaryDark)
|
||||
.build())
|
||||
|
||||
addSlide(SimpleSlide.Builder()
|
||||
.title(R.string.title_permission_calendar)
|
||||
.description(R.string.description_permission_calendar)
|
||||
.background(R.color.colorPrimary)
|
||||
.backgroundDark(R.color.colorPrimaryDark)
|
||||
.permission(Manifest.permission.READ_CALENDAR)
|
||||
.build())
|
||||
|
||||
addSlide(SimpleSlide.Builder()
|
||||
.title(R.string.title_permission_location)
|
||||
.description(R.string.description_permission_location)
|
||||
.background(R.color.colorPrimary)
|
||||
.backgroundDark(R.color.colorPrimaryDark)
|
||||
.permission(Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||
.build())
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.tommasoberlose.anotherwidget.ui.view
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.content.res.TypedArray
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.widget.TextView
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
|
||||
|
||||
/**
|
||||
* Created by tommaso on 12/10/17.
|
||||
*/
|
||||
class TitleTextView : TextView {
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) {
|
||||
init(context, attrs)
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
|
||||
init(context, attrs)
|
||||
}
|
||||
|
||||
constructor(context: Context) : super(context) {}
|
||||
|
||||
fun init(context: Context, attrs: AttributeSet) {
|
||||
try {
|
||||
val ta = context.obtainStyledAttributes(attrs, R.styleable.FontText)
|
||||
|
||||
if (ta != null) {
|
||||
val fontAsset = ta.getString(R.styleable.FontText_typefaceAsset)
|
||||
|
||||
if (fontAsset != null && !fontAsset.isEmpty()) {
|
||||
val tf = Typeface.createFromAsset(getContext().assets, fontAsset)
|
||||
|
||||
if (tf != null)
|
||||
typeface = tf
|
||||
else
|
||||
Log.i("FontText", String.format("Could not create a font from asset: %s", fontAsset))
|
||||
}
|
||||
ta.recycle()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.i("FontText", "Could not create a font from asset")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -24,6 +24,13 @@ import android.content.ContentUris
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.util.CalendarUtil
|
||||
import com.tommasoberlose.anotherwidget.util.WeatherUtil
|
||||
import android.graphics.Typeface
|
||||
import android.net.Uri
|
||||
import android.widget.TextClock
|
||||
import android.widget.TextView
|
||||
import android.content.ComponentName
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -63,95 +70,109 @@ class TheWidget : AppWidgetProvider() {
|
||||
}
|
||||
|
||||
fun updateCalendarView(context: Context, views: RemoteViews, widgetID: Int): RemoteViews {
|
||||
val now = Calendar.getInstance()
|
||||
val calendarLayout = Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val now = Calendar.getInstance()
|
||||
val calendarLayout = Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)
|
||||
|
||||
views.setViewVisibility(R.id.empty_layout, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.calendar_layout, View.GONE)
|
||||
views.setTextViewText(R.id.empty_date, Constants.dateFormat.format(now.time)[0].toUpperCase() + Constants.dateFormat.format(now.time).substring(1))
|
||||
views.setViewVisibility(R.id.empty_layout, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.calendar_layout, View.GONE)
|
||||
var dateStringValue: String = String.format("%s%s", Constants.engDateFormat.format(now.time)[0].toUpperCase(), Constants.engDateFormat.format(now.time).substring(1))
|
||||
if (SP.getBoolean(Constants.PREF_ITA_FORMAT_DATE, false)) {
|
||||
dateStringValue = String.format("%s%s", Constants.itDateFormat.format(now.time)[0].toUpperCase(), Constants.itDateFormat.format(now.time).substring(1))
|
||||
}
|
||||
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 calIntent = Intent(Intent.ACTION_MAIN)
|
||||
calIntent.addCategory(Intent.CATEGORY_APP_CALENDAR)
|
||||
val calPIntent = PendingIntent.getActivity(context, widgetID, calIntent, 0)
|
||||
views.setOnClickPendingIntent(R.id.main_layout, calPIntent)
|
||||
val calIntent = Intent(Intent.ACTION_MAIN)
|
||||
calIntent.addCategory(Intent.CATEGORY_APP_CALENDAR)
|
||||
val calPIntent = PendingIntent.getActivity(context, widgetID, calIntent, 0)
|
||||
views.setOnClickPendingIntent(R.id.main_layout, calPIntent)
|
||||
|
||||
|
||||
if (calendarLayout) {
|
||||
val e = CalendarUtil.getNextEvent(context)
|
||||
if (calendarLayout) {
|
||||
val e = CalendarUtil.getNextEvent(context)
|
||||
|
||||
if (e.id != 0) {
|
||||
val difference = e.startDate - now.timeInMillis
|
||||
if (e.id != 0) {
|
||||
val difference = e.startDate - now.timeInMillis
|
||||
|
||||
if (difference > 1000 * 60) {
|
||||
var time = ""
|
||||
val hour = TimeUnit.MILLISECONDS.toHours(difference)
|
||||
if (hour > 0) {
|
||||
time = hour.toString() + context.getString(R.string.h_code)
|
||||
}
|
||||
val minutes = TimeUnit.MILLISECONDS.toMinutes(difference - hour * 3600 * 1000)
|
||||
if (minutes > 0) {
|
||||
time += " " + minutes + context.getString(R.string.min_code)
|
||||
}
|
||||
|
||||
views.setTextViewText(R.id.next_event, String.format("%s %s %s", e.title, context.getString(R.string.in_code), time))
|
||||
} else {
|
||||
views.setTextViewText(R.id.next_event, String.format("%s", e.title))
|
||||
if (difference > 1000 * 60) {
|
||||
var time = ""
|
||||
val hour = TimeUnit.MILLISECONDS.toHours(difference)
|
||||
if (hour > 0) {
|
||||
time = hour.toString() + context.getString(R.string.h_code) + " "
|
||||
}
|
||||
val minutes = TimeUnit.MILLISECONDS.toMinutes(difference - hour * 3600 * 1000)
|
||||
if (minutes > 0) {
|
||||
time += "" + minutes + context.getString(R.string.min_code)
|
||||
}
|
||||
views.setTextViewText(R.id.next_event_date, String.format("%s - %s", Constants.hourFormat.format(e.startDate), Constants.hourFormat.format(e.endDate)))
|
||||
|
||||
views.setViewVisibility(R.id.empty_layout, View.GONE)
|
||||
views.setViewVisibility(R.id.calendar_layout, View.VISIBLE)
|
||||
|
||||
val builder = CalendarContract.CONTENT_URI.buildUpon()
|
||||
builder.appendPath("time")
|
||||
ContentUris.appendId(builder, e.startDate)
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
.setData(builder.build())
|
||||
val pIntent = PendingIntent.getActivity(context, widgetID, intent, 0)
|
||||
views.setOnClickPendingIntent(R.id.main_layout, pIntent)
|
||||
views.setTextViewText(R.id.next_event, String.format("%s %s %s", e.title, context.getString(R.string.in_code), time))
|
||||
} else {
|
||||
views.setTextViewText(R.id.next_event, String.format("%s", e.title))
|
||||
}
|
||||
}
|
||||
|
||||
return views
|
||||
if (!e.allDay) {
|
||||
val startHour: String = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(e.startDate) else Constants.goodHourFormat.format(e.startDate)
|
||||
val endHour: String = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(e.endDate) else Constants.goodHourFormat.format(e.endDate)
|
||||
views.setTextViewText(R.id.next_event_date, String.format("%s - %s", startHour, endHour))
|
||||
} else {
|
||||
views.setTextViewText(R.id.next_event_date, dateStringValue)
|
||||
}
|
||||
|
||||
views.setViewVisibility(R.id.empty_layout, View.GONE)
|
||||
views.setViewVisibility(R.id.calendar_layout, View.VISIBLE)
|
||||
|
||||
val builder = CalendarContract.CONTENT_URI.buildUpon()
|
||||
builder.appendPath("time")
|
||||
ContentUris.appendId(builder, e.startDate)
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
.setData(builder.build())
|
||||
val pIntent = PendingIntent.getActivity(context, widgetID, intent, 0)
|
||||
views.setOnClickPendingIntent(R.id.main_layout, pIntent)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateLocationView(context: Context, views: RemoteViews, widgetID: Int): RemoteViews {
|
||||
val locationLayout = Util.checkGrantedPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||
return views
|
||||
}
|
||||
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
if (locationLayout && SP.contains(Constants.PREF_WEATHER_TEMP) && SP.contains(Constants.PREF_WEATHER_ICON)) {
|
||||
views.setViewVisibility(R.id.weather, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.calendar_weather, View.VISIBLE)
|
||||
val temp = String.format(Locale.getDefault(), "%.0f °%s", SP.getFloat(Constants.PREF_WEATHER_TEMP, 0f), SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F"))
|
||||
fun updateLocationView(context: Context, views: RemoteViews, widgetID: Int): RemoteViews {
|
||||
val locationLayout = Util.checkGrantedPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
if (locationLayout && SP.contains(Constants.PREF_WEATHER_TEMP) && SP.contains(Constants.PREF_WEATHER_ICON)) {
|
||||
views.setViewVisibility(R.id.weather, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.calendar_weather, View.VISIBLE)
|
||||
val temp = String.format(Locale.getDefault(), "%.0f °%s", SP.getFloat(Constants.PREF_WEATHER_TEMP, 0f), SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F"))
|
||||
|
||||
|
||||
views.setViewVisibility(R.id.weather_icon, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.empty_weather_icon, View.VISIBLE)
|
||||
val icon: String = SP.getString(Constants.PREF_WEATHER_ICON, "")
|
||||
if (icon.equals("")) {
|
||||
views.setViewVisibility(R.id.weather_icon, View.GONE)
|
||||
views.setViewVisibility(R.id.empty_weather_icon, View.GONE)
|
||||
} else {
|
||||
views.setImageViewResource(R.id.weather_icon, WeatherUtil.getWeatherIconResource(icon))
|
||||
views.setImageViewResource(R.id.empty_weather_icon, WeatherUtil.getWeatherIconResource(icon))
|
||||
}
|
||||
|
||||
views.setTextViewText(R.id.temp, temp)
|
||||
views.setTextViewText(R.id.calendar_temp, temp)
|
||||
|
||||
val weatherIntent = Intent("com.google.android.googlequicksearchbox.GOOGLE_SEARCH")
|
||||
weatherIntent.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
weatherIntent.putExtra("type", "string")
|
||||
weatherIntent.putExtra("query", "weather")
|
||||
val weatherPIntent = PendingIntent.getActivity(context, widgetID, weatherIntent, 0)
|
||||
|
||||
views.setOnClickPendingIntent(R.id.weather, weatherPIntent)
|
||||
views.setOnClickPendingIntent(R.id.calendar_weather, weatherPIntent)
|
||||
views.setViewVisibility(R.id.weather_icon, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.empty_weather_icon, View.VISIBLE)
|
||||
val icon: String = SP.getString(Constants.PREF_WEATHER_ICON, "")
|
||||
if (icon.equals("")) {
|
||||
views.setViewVisibility(R.id.weather_icon, View.GONE)
|
||||
views.setViewVisibility(R.id.empty_weather_icon, View.GONE)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.weather, View.GONE)
|
||||
views.setViewVisibility(R.id.calendar_weather, View.GONE)
|
||||
views.setImageViewResource(R.id.weather_icon, WeatherUtil.getWeatherIconResource(icon))
|
||||
views.setImageViewResource(R.id.empty_weather_icon, WeatherUtil.getWeatherIconResource(icon))
|
||||
}
|
||||
return views
|
||||
|
||||
views.setTextViewText(R.id.temp, temp)
|
||||
views.setTextViewText(R.id.calendar_temp, temp)
|
||||
|
||||
val weatherIntent: Intent = Intent(Intent.ACTION_VIEW)
|
||||
weatherIntent.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
weatherIntent.data = Uri.parse("dynact://velour/weather/ProxyActivity")
|
||||
weatherIntent.component = ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.velour.DynamicActivityTrampoline")
|
||||
|
||||
val weatherPIntent = PendingIntent.getActivity(context, widgetID, weatherIntent, 0)
|
||||
|
||||
views.setOnClickPendingIntent(R.id.weather, weatherPIntent)
|
||||
views.setOnClickPendingIntent(R.id.calendar_weather, weatherPIntent)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.weather, View.GONE)
|
||||
views.setViewVisibility(R.id.calendar_weather, View.GONE)
|
||||
}
|
||||
return views
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user