This commit is contained in:
Tommaso Berlose
2018-08-03 10:52:18 +02:00
parent 6d297911ee
commit 05a0308f8f
29 changed files with 211 additions and 119 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -17,6 +17,7 @@ object Constants {
val EVENT_APP_REQUEST_CODE = 6
val WEATHER_PROVIDER_REQUEST_CODE = 5
val CLOCK_APP_REQUEST_CODE = 7
val CUSTOM_FONT_CHOOSER_REQUEST_CODE = 8
val RESULT_CODE_CUSTOM_LOCATION = 45
@ -67,14 +68,19 @@ object Constants {
val PREF_SHOW_DIFF_TIME = "PREF_SHOW_DIFF_TIME"
val PREF_SHOW_DECLINED_EVENTS = "PREF_SHOW_DECLINED_EVENTS"
val PREF_OPEN_WEATHER_API_KEY = "PREF_OPEN_WEATHER_API_KEY"
val PREF_DARK_SKY_API_KEY = "PREF_DARK_SKY_API_KEY"
val PREF_WU_API_KEY = "PREF_WU_API_KEY"
val PREF_SECOND_ROW_INFORMATION = "PREF_SECOND_ROW_INFORMATION"
val PREF_CUSTOM_FONT = "PREF_CUSTOM_FONT"
val PREF_CUSTOM_FONT_FILE = "PREF_CUSTOM_FONT_FILE"
val PREF_SHOW_NEXT_EVENT = "PREF_SHOW_NEXT_EVENT"
val PREF_SHOW_WIDGET_PREVIEW = "PREF_SHOW_WIDGET_PREVIEW"
val PREF_SHOW_GPS_NOTIFICATION = "PREF_SHOW_GPS_NOTIFICATION"
val CUSTOM_FONT_PRODUCT_SANS = 1
val ACTION_EXTRA_OPEN_WEATHER_PROVIDER = "ACTION_EXTRA_OPEN_WEATHER_PROVIDER"
val ACTION_EXTRA_DISABLE_GPS_NOTIFICATION = "ACTION_EXTRA_DISABLE_GPS_NOTIFICATION"
val itDateFormat = SimpleDateFormat("EEEE, d MMM")
val engDateFormat = SimpleDateFormat("EEEE, MMM d")
@ -90,4 +96,6 @@ object Constants {
val WEATHER_PROVIDER_GOOGLE_AWARENESS = 1
val WEATHER_PROVIDER_OPEN_WEATHER = 2
val WEATHER_PROVIDER_DARK_SKY = 3
val WEATHER_PROVIDER_WU = 4
}

View File

@ -23,10 +23,12 @@ class OpenWeatherIntentReceiver : BroadcastReceiver() {
context.applicationContext.startActivity(Util.getWeatherIntent(context.applicationContext))
} catch (e: Exception) {
val uri = Uri.parse("http://www.google.com/#q=weather")
val i = Intent(Intent.ACTION_VIEW, uri)
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK
try {
context.startActivity(Intent(Intent.ACTION_VIEW, uri))
context.startActivity(i)
} catch (e: Exception) {
context.applicationContext.startActivity(Intent(Intent.ACTION_VIEW, uri))
context.applicationContext.startActivity(i)
}
}
}

View File

@ -27,6 +27,7 @@ import android.content.res.Resources
import android.graphics.Color
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Build
import android.support.design.widget.BottomSheetDialog
import android.support.v4.content.ContextCompat
@ -47,11 +48,13 @@ import kotlinx.android.synthetic.main.key_time_wait_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.view.*
import java.io.File
class MainActivity : AppCompatActivity() {
private var mAppWidgetId: Int = -1
private lateinit var SP: SharedPreferences
private val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
@ -67,31 +70,12 @@ class MainActivity : AppCompatActivity() {
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
val SP = PreferenceManager.getDefaultSharedPreferences(this)
if (intent.extras?.containsKey(Constants.ACTION_EXTRA_OPEN_WEATHER_PROVIDER) == true) {
startActivityForResult(Intent(this, WeatherProviderActivity::class.java), Constants.WEATHER_PROVIDER_REQUEST_CODE)
}
val extras = intent.extras
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID)
if (mAppWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
action_add_widget.visibility = View.VISIBLE
action_add_widget.setOnClickListener {
addNewWidget()
}
}
}
SP = PreferenceManager.getDefaultSharedPreferences(this)
controlExtras(intent)
action_menu.setOnClickListener {
val mBottomSheetDialog: BottomSheetDialog = BottomSheetDialog(this)
val mBottomSheetDialog = BottomSheetDialog(this)
val menuView: View = getLayoutInflater().inflate(R.layout.main_menu_layout, null)
menuView.action_share.setOnClickListener(object: View.OnClickListener {
@ -150,7 +134,7 @@ class MainActivity : AppCompatActivity() {
}
mBottomSheetDialog.setContentView(menuView)
mBottomSheetDialog.show();
mBottomSheetDialog.show()
}
}
@ -163,6 +147,43 @@ class MainActivity : AppCompatActivity() {
}
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
if (intent != null) {
controlExtras(intent)
}
}
fun controlExtras(intent: Intent) {
val extras = intent.extras
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID)
if (mAppWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
action_add_widget.visibility = View.VISIBLE
action_add_widget.setOnClickListener {
addNewWidget()
}
}
if (extras.containsKey(Constants.ACTION_EXTRA_OPEN_WEATHER_PROVIDER)) {
startActivityForResult(Intent(this, WeatherProviderActivity::class.java), Constants.WEATHER_PROVIDER_REQUEST_CODE)
}
if (extras.containsKey(Constants.ACTION_EXTRA_DISABLE_GPS_NOTIFICATION)) {
SP.edit()
.putBoolean(Constants.PREF_SHOW_GPS_NOTIFICATION, false)
.apply()
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
finish()
}
}
}
fun addNewWidget() {
val resultValue = Intent()
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId)
@ -207,8 +228,6 @@ class MainActivity : AppCompatActivity() {
updateAppWidget()
updateClockView()
val SP = PreferenceManager.getDefaultSharedPreferences(this)
if (SP.getBoolean(Constants.PREF_SHOW_WIDGET_PREVIEW, true)) {
val displayMetrics = Resources.getSystem().displayMetrics
var width = displayMetrics.widthPixels
@ -245,7 +264,6 @@ class MainActivity : AppCompatActivity() {
@SuppressLint("ApplySharedPref")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val SP = PreferenceManager.getDefaultSharedPreferences(this)
if (requestCode == Constants.RESULT_CODE_CUSTOM_LOCATION && resultCode == Activity.RESULT_OK) {
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
updateSettings()
@ -281,11 +299,20 @@ class MainActivity : AppCompatActivity() {
WeatherReceiver().setOneTimeUpdate(this)
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
updateSettings()
} else if (requestCode == Constants.CUSTOM_FONT_CHOOSER_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
/*val uri = data.data
Log.d("AW", "File Uri: " + uri.toString())
val path = Util.getPath(this, uri)
Log.d("AW", "File Path: " + path)
SP.edit()
.putString(Constants.PREF_CUSTOM_FONT_FILE, path)
.commit()
sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE))
updateSettings()*/
}
}
fun updateClockView() {
val SP = PreferenceManager.getDefaultSharedPreferences(this)
if (!SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
time.visibility = View.GONE
} else {
@ -293,18 +320,19 @@ class MainActivity : AppCompatActivity() {
}
val now = Calendar.getInstance()
if (SP.getString(Constants.PREF_HOUR_FORMAT, "12") == "12") {
val textBadHour = SpannableString(Constants.badHourFormat.format(now.timeInMillis))
textBadHour.setSpan(RelativeSizeSpan(0.4f), textBadHour.length - 2,
textBadHour.length, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
time.text = textBadHour
// time.format12Hour = "hh:mm a"
// val textBadHour = SpannableString(Constants.badHourFormat.format(time.))
// textBadHour.setSpan(RelativeSizeSpan(0.4f), textBadHour.length - 2,
// textBadHour.length, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
//
// time.text = textBadHour
} else {
time.text = Constants.goodHourFormat.format(now.timeInMillis)
// time.format24Hour = "HH:mm"
// time.text = Constants.goodHourFormat.format(now.timeInMillis)
}
}
fun updateCalendarView() {
val SP = PreferenceManager.getDefaultSharedPreferences(this)
val now = Calendar.getInstance()
val calendarLayout = SP.getBoolean(Constants.PREF_SHOW_EVENTS, true) && Util.checkGrantedPermission(this, Manifest.permission.READ_CALENDAR)
@ -384,7 +412,7 @@ class MainActivity : AppCompatActivity() {
divider2.setTextColor(Util.getFontColor(SP))
calendar_temp.setTextColor(Util.getFontColor(SP))
second_row_icon.setColorFilter(Util.getFontColor(SP))
time.setTextColor(Util.getFontColor(SP))
// time.setTextColor(Util.getFontColor(SP))
empty_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f))
@ -395,7 +423,7 @@ class MainActivity : AppCompatActivity() {
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))
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))
// time.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f))
second_row_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 18f
second_row_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 18f
@ -435,10 +463,20 @@ class MainActivity : AppCompatActivity() {
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)
// time.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
if (SP.getInt(Constants.PREF_CUSTOM_FONT, Constants.CUSTOM_FONT_PRODUCT_SANS) == Constants.CUSTOM_FONT_PRODUCT_SANS) {
val product_sans: Typeface = Typeface.createFromAsset(assets, "fonts/product_sans_regular.ttf")
val product_sans_light: Typeface = Typeface.createFromAsset(assets, "fonts/product_sans_light.ttf")
/*if (SP.getString(Constants.PREF_CUSTOM_FONT_FILE, "") != "") {
val file = File(SP.getString(Constants.PREF_CUSTOM_FONT_FILE, ""))
if (file.exists()) {
Log.d("AW", "OK")
}
// product_sans = Typeface.createFromFile("")
}*/
empty_date.typeface = product_sans
divider1.typeface = product_sans
temp.typeface = product_sans
@ -447,7 +485,7 @@ class MainActivity : AppCompatActivity() {
next_event_date.typeface = product_sans
divider2.typeface = product_sans
calendar_temp.typeface = product_sans
time.typeface = product_sans
//time.typeface = product_sans_light
} else {
empty_date.typeface = Typeface.DEFAULT
divider1.typeface = Typeface.DEFAULT
@ -457,12 +495,11 @@ class MainActivity : AppCompatActivity() {
next_event_date.typeface = Typeface.DEFAULT
divider2.typeface = Typeface.DEFAULT
calendar_temp.typeface = Typeface.DEFAULT
time.typeface = Typeface.DEFAULT
//time.typeface = Typeface.DEFAULT
}
}
fun updateLocationView() {
val SP = PreferenceManager.getDefaultSharedPreferences(this)
val locationLayout = SP.getBoolean(Constants.PREF_SHOW_WEATHER, true)
if (locationLayout && SP.contains(Constants.PREF_WEATHER_TEMP) && SP.contains(Constants.PREF_WEATHER_ICON)) {
@ -492,7 +529,6 @@ class MainActivity : AppCompatActivity() {
@SuppressLint("ApplySharedPref")
fun updateSettings() {
val SP = PreferenceManager.getDefaultSharedPreferences(this)
if (SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
clock_settings.visibility = View.VISIBLE
@ -739,11 +775,24 @@ class MainActivity : AppCompatActivity() {
custom_font_label.text = getString(Util.getCustomFontLabel(SP.getInt(Constants.PREF_CUSTOM_FONT, Constants.CUSTOM_FONT_PRODUCT_SANS)))
action_custom_font.setOnClickListener {
SP.edit().putInt(Constants.PREF_CUSTOM_FONT, when (SP.getInt(Constants.PREF_CUSTOM_FONT, Constants.CUSTOM_FONT_PRODUCT_SANS)) {
0 -> Constants.CUSTOM_FONT_PRODUCT_SANS
Constants.CUSTOM_FONT_PRODUCT_SANS -> 0
else -> Constants.CUSTOM_FONT_PRODUCT_SANS
}).commit()
/*
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "* / *" TO FIX WITHOUT SPACE
intent.addCategory(Intent.CATEGORY_OPENABLE)
try {
startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), Constants.CUSTOM_FONT_CHOOSER_REQUEST_CODE)
} catch (ex: android.content.ActivityNotFoundException) {
Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show()
}
*/
sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE))
updateSettings()
updateAppWidget()
@ -763,10 +812,7 @@ class MainActivity : AppCompatActivity() {
label_weather_provider_api_key.text = getString(R.string.provider_google_awareness)
alert_icon.visibility = View.GONE
} else {
if (SP.getString(when (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS)) {
Constants.WEATHER_PROVIDER_OPEN_WEATHER -> Constants.PREF_OPEN_WEATHER_API_KEY
else -> Constants.PREF_OPEN_WEATHER_API_KEY
}, "") == ("")) {
if (WeatherUtil.getWeatherProviderKey(this, SP) == ("")) {
label_weather_provider_api_key.text = getString(R.string.settings_weather_provider_api_key_subtitle_not_set)
alert_icon.visibility = View.VISIBLE
} else {

View File

@ -108,7 +108,7 @@ class SupportDevActivity : AppCompatActivity(), BillingProcessor.IBillingHandler
Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (!bp.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data)
}

View File

@ -41,10 +41,7 @@ class WeatherProviderActivity : AppCompatActivity() {
action_save.setOnClickListener {
SP.edit()
.putString(when (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS)) {
Constants.WEATHER_PROVIDER_OPEN_WEATHER -> Constants.PREF_OPEN_WEATHER_API_KEY
else -> Constants.PREF_OPEN_WEATHER_API_KEY
}, api_key.text.toString())
.putString(WeatherUtil.getWeatherProviderKeyConstant(this, SP), api_key.text.toString())
.commit()
setResult(Activity.RESULT_OK)
finish()
@ -53,10 +50,7 @@ class WeatherProviderActivity : AppCompatActivity() {
api_key.addTextChangedListener(object: TextWatcher {
override fun afterTextChanged(text: Editable?) {
if (text.toString().equals("") || text.toString().equals(
SP.getString(when (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS)) {
Constants.WEATHER_PROVIDER_OPEN_WEATHER -> Constants.PREF_OPEN_WEATHER_API_KEY
else -> Constants.PREF_OPEN_WEATHER_API_KEY
}, ""))) {
WeatherUtil.getWeatherProviderKey(this@WeatherProviderActivity, SP))) {
Util.collapse(button_container)
} else {
Util.expand(button_container)
@ -105,18 +99,12 @@ class WeatherProviderActivity : AppCompatActivity() {
}
Util.collapse(button_container)
api_key.setText(SP.getString(when (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS)) {
Constants.WEATHER_PROVIDER_OPEN_WEATHER -> Constants.PREF_OPEN_WEATHER_API_KEY
else -> Constants.PREF_OPEN_WEATHER_API_KEY
}, ""))
api_key.setText(WeatherUtil.getWeatherProviderKey(this, SP))
}
override fun onBackPressed() {
val SP = PreferenceManager.getDefaultSharedPreferences(this)
if (!SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS).equals(Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) && (api_key.text.toString().equals("") || !api_key.text.toString().equals(SP.getString(when (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS)) {
Constants.WEATHER_PROVIDER_OPEN_WEATHER -> Constants.PREF_OPEN_WEATHER_API_KEY
else -> Constants.PREF_OPEN_WEATHER_API_KEY
}, "")))) {
if (!SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS).equals(Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) && (api_key.text.toString().equals("") || !api_key.text.toString().equals(WeatherUtil.getWeatherProviderKey(this, SP)))) {
AlertDialog.Builder(this)
.setMessage(getString(R.string.error_weather_api_key))
.setNegativeButton(android.R.string.cancel, null)

View File

@ -86,12 +86,8 @@ class TheWidget : AppWidgetProvider() {
appWidgetId: Int) {
val SP = PreferenceManager.getDefaultSharedPreferences(context)
val displayMetrics = Resources.getSystem().displayMetrics
val widgetInfo = appWidgetManager.getAppWidgetInfo(appWidgetId)
var height = Util.convertDpToPixel(80f, context).toInt()
var height = Util.convertDpToPixel(110f, context).toInt()
val width = displayMetrics.widthPixels
if (widgetInfo != null) {
height = widgetInfo.minHeight
}
if (SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
height += Util.convertSpToPixels(SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f), context).toInt() + Util.convertDpToPixel(16f, context).toInt()
}
@ -115,7 +111,7 @@ class TheWidget : AppWidgetProvider() {
views.setTextColor(R.id.next_event_date, Util.getFontColor(PreferenceManager.getDefaultSharedPreferences(context)))
views.setTextColor(R.id.divider2, Util.getFontColor(PreferenceManager.getDefaultSharedPreferences(context)))
views.setTextColor(R.id.calendar_temp, Util.getFontColor(PreferenceManager.getDefaultSharedPreferences(context)))
views.setTextColor(R.id.time, Util.getFontColor(PreferenceManager.getDefaultSharedPreferences(context)))
//views.setTextColor(R.id.time, Util.getFontColor(PreferenceManager.getDefaultSharedPreferences(context)))
views.setTextViewTextSize(R.id.empty_date, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f))
views.setTextViewTextSize(R.id.divider1, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
@ -125,7 +121,7 @@ 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.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.time, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f))
//views.setTextViewTextSize(R.id.time, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f))
v = updateCalendarViewByLayout(context, v)
v = updateLocationViewByLayout(context, v)
@ -297,16 +293,16 @@ class TheWidget : AppWidgetProvider() {
if (!SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
views.setViewVisibility(R.id.time, View.GONE)
} else {
val now = Calendar.getInstance()
if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) {
val textBadHour = SpannableString(Constants.badHourFormat.format(now.timeInMillis).replace(" ", ""))
textBadHour.setSpan(RelativeSizeSpan(0.4f), textBadHour.length - 2,
textBadHour.length, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
views.setTextViewText(R.id.time, textBadHour)
} else {
views.setTextViewText(R.id.time, Constants.goodHourFormat.format(now.timeInMillis))
}
// val now = Calendar.getInstance()
// if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) {
// val textBadHour = SpannableString(Constants.badHourFormat.format(now.timeInMillis).replace(" ", ""))
// textBadHour.setSpan(RelativeSizeSpan(0.4f), textBadHour.length - 2,
// textBadHour.length, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
//
// views.setTextViewText(R.id.time, textBadHour)
// } else {
// views.setTextViewText(R.id.time, Constants.goodHourFormat.format(now.timeInMillis))
// }
val clockPIntent = PendingIntent.getActivity(context, widgetID, Util.getClockIntent(context), 0)
views.setOnClickPendingIntent(R.id.time, clockPIntent)
@ -439,8 +435,8 @@ class TheWidget : AppWidgetProvider() {
v.second_row_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 18f
v.second_row_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 18f
v.weather_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 16f
v.weather_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 16f
v.weather_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 18f
v.weather_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 18f
v.empty_weather_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f) / 24f
v.empty_weather_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f) / 24f
@ -478,6 +474,7 @@ class TheWidget : AppWidgetProvider() {
if (SP.getInt(Constants.PREF_CUSTOM_FONT, Constants.CUSTOM_FONT_PRODUCT_SANS) == Constants.CUSTOM_FONT_PRODUCT_SANS) {
val product_sans: Typeface = Typeface.createFromAsset(context.assets, "fonts/product_sans_regular.ttf")
val product_sans_light: Typeface = Typeface.createFromAsset(context.assets, "fonts/product_sans_light.ttf")
v.empty_date.typeface = product_sans
v.divider1.typeface = product_sans
v.temp.typeface = product_sans
@ -486,7 +483,7 @@ class TheWidget : AppWidgetProvider() {
v.next_event_date.typeface = product_sans
v.divider2.typeface = product_sans
v.calendar_temp.typeface = product_sans
v.time.typeface = product_sans
v.time.typeface = product_sans_light
}
return v
@ -527,16 +524,16 @@ class TheWidget : AppWidgetProvider() {
if (!SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
v.time.visibility = View.GONE
} else {
val now = Calendar.getInstance()
if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) {
val textBadHour = SpannableString(Constants.badHourFormat.format(now.timeInMillis).replace(" ", ""))
textBadHour.setSpan(RelativeSizeSpan(0.4f), textBadHour.length - 2,
textBadHour.length, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
v.time.text = textBadHour
} else {
v.time.text = Constants.goodHourFormat.format(now.timeInMillis)
}
// val now = Calendar.getInstance()
// if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) {
// val textBadHour = SpannableString(Constants.badHourFormat.format(now.timeInMillis).replace(" ", ""))
// textBadHour.setSpan(RelativeSizeSpan(0.4f), textBadHour.length - 2,
// textBadHour.length, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
//
// v.time.text = textBadHour
// } else {
// v.time.text = Constants.goodHourFormat.format(now.timeInMillis)
// }
v.time.visibility = View.VISIBLE
}
return v

View File

@ -24,6 +24,7 @@ import android.support.annotation.StringRes
import android.util.TypedValue
import android.content.Intent
import android.content.ComponentName
import android.database.Cursor
import android.location.LocationManager
import android.os.Build
import android.preference.PreferenceManager
@ -43,6 +44,7 @@ import com.tommasoberlose.anotherwidget.`object`.Event
import io.realm.Realm
import io.realm.RealmConfiguration
import org.joda.time.DateTime
import java.net.URISyntaxException
import java.util.concurrent.TimeUnit
@ -94,17 +96,29 @@ object Util {
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
val SP = PreferenceManager.getDefaultSharedPreferences(context)
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) {
if (SP.getBoolean(Constants.PREF_SHOW_GPS_NOTIFICATION, true) && !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) {
val settingsIntent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
val pi: PendingIntent = PendingIntent.getActivity(context, 50, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT)
val providerIntent2 = Intent(context, MainActivity::class.java)
providerIntent2.flags = Intent.FLAG_ACTIVITY_NEW_TASK
providerIntent2.putExtra(Constants.ACTION_EXTRA_OPEN_WEATHER_PROVIDER, true)
val pi2: PendingIntent = PendingIntent.getActivity(context, 51, providerIntent2, PendingIntent.FLAG_UPDATE_CURRENT)
val providerIntentDisable = Intent(context, MainActivity::class.java)
providerIntentDisable.flags = Intent.FLAG_ACTIVITY_NEW_TASK
providerIntentDisable.putExtra(Constants.ACTION_EXTRA_DISABLE_GPS_NOTIFICATION, true)
val piDisable: PendingIntent = PendingIntent.getActivity(context, 52, providerIntentDisable, PendingIntent.FLAG_UPDATE_CURRENT)
val mBuilder: NotificationCompat.Builder = NotificationCompat.Builder(context, "Error")
.setSmallIcon(R.drawable.ic_stat_name)
.setColor(ContextCompat.getColor(context, R.color.colorPrimary))
.setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher_round))
.setContentTitle(context.getString(R.string.notification_gps_title))
.setContentText(context.getString(R.string.notification_gps_subtitle))
.addAction(R.drawable.ic_action_sync, context.getString(R.string.change_provider), pi2)
.addAction(R.drawable.ic_action_settings, context.getString(R.string.disable_notification), piDisable)
.setContentIntent(pi)
val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
val pi: PendingIntent = PendingIntent.getActivity(context, 50, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pi);
mNotificationManager.notify(10, mBuilder.build());
} else {
mNotificationManager.cancel(10)
@ -639,4 +653,28 @@ object Util {
return null
}
}
@Throws(Exception::class)
fun getPath(context: Context, uri: Uri): String? {
if ("content".equals(uri.scheme, ignoreCase = true)) {
val projection = arrayOf(android.provider.MediaStore.Files.FileColumns.DATA)
var cursor: Cursor? = null
try {
cursor = context.contentResolver.query(uri, projection, null, null, null)
val column_index = cursor.getColumnIndexOrThrow(android.provider.MediaStore.Files.FileColumns.DATA)
if (cursor.moveToFirst()) {
Log.d("AW", "4: " + cursor.getString(0))
return cursor.getString(0)
}
} catch (e: Exception) {
e.printStackTrace()
}
} else if ("file".equals(uri.scheme, ignoreCase = true)) {
return uri.path
}
return null
}
}

View File

@ -137,20 +137,14 @@ object WeatherUtil {
.putString(Constants.PREF_CUSTOM_LOCATION_LON, longitude.toString())
.apply()
if (!SP.getString(when (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS)) {
Constants.WEATHER_PROVIDER_OPEN_WEATHER -> Constants.PREF_OPEN_WEATHER_API_KEY
else -> Constants.PREF_OPEN_WEATHER_API_KEY
}, "").equals("")) {
if (!getWeatherProviderKey(context, SP).equals("")) {
try {
val config = WeatherConfig()
config.unitSystem = if (SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F").equals("C")) WeatherConfig.UNIT_SYSTEM.M else WeatherConfig.UNIT_SYSTEM.I
config.lang = "en"
config.maxResult = 1
config.numDays = 1
config.ApiKey = SP.getString(when (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS)) {
Constants.WEATHER_PROVIDER_OPEN_WEATHER -> Constants.PREF_OPEN_WEATHER_API_KEY
else -> Constants.PREF_OPEN_WEATHER_API_KEY
}, "")
config.ApiKey = WeatherUtil.getWeatherProviderKey(context, SP)
val client = WeatherClient.ClientBuilder().attach(context)
.httpClient(com.survivingwithandroid.weather.lib.client.volley.WeatherClientDefault::class.java)
@ -187,6 +181,19 @@ object WeatherUtil {
}
}
fun getWeatherProviderKeyConstant(context: Context, SP: SharedPreferences): String {
return when (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS)) {
Constants.WEATHER_PROVIDER_OPEN_WEATHER -> Constants.PREF_OPEN_WEATHER_API_KEY
Constants.WEATHER_PROVIDER_DARK_SKY -> Constants.PREF_DARK_SKY_API_KEY
Constants.WEATHER_PROVIDER_WU -> Constants.PREF_WU_API_KEY
else -> Constants.PREF_OPEN_WEATHER_API_KEY
}
}
fun getWeatherProviderKey(context: Context, SP: SharedPreferences): String {
return SP.getString(getWeatherProviderKeyConstant(context, SP), "")
}
@SuppressLint("ApplySharedPref")
fun removeWeather(context: Context, SP: SharedPreferences) {
SP.edit().

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 418 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 939 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 826 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -162,7 +162,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Date"
android:layout_marginStart="4dp"
android:layout_marginStart="8dp"
android:ellipsize="marquee"
android:layout_marginEnd="4dp"
android:includeFontPadding="false"

View File

@ -155,4 +155,7 @@
<string name="action_hide_widget_preview">Nascondi Anteprima Widget</string>
<string name="error_widget_notification_title">GPS Disattivato</string>
<string name="error_widget_notification_subtitle">Riattiva il GPS così che Another Widget possa aggiornare il meteo con le API di Google Awareness.</string>
<string name="open_location_settings">Impostazioni GPS</string>
<string name="change_provider">Cambia Provider</string>
<string name="disable_notification">Disabilita Notifica</string>
</resources>

View File

@ -160,4 +160,7 @@
<string name="action_hide_widget_preview">Hide Widget Preview</string>
<string name="error_widget_notification_title">Location is turned off</string>
<string name="error_widget_notification_subtitle">Turn Location back on so Another Widget can update weather informations with Google Awareness API.</string>
<string name="open_location_settings">Location Settings</string>
<string name="change_provider">Change Provider</string>
<string name="disable_notification">Disable Notification</string>
</resources>

View File

@ -2,10 +2,10 @@
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialKeyguardLayout="@layout/the_widget"
android:initialLayout="@layout/the_widget"
android:minHeight="80dp"
android:minHeight="50dp"
android:minWidth="300dp"
android:configure="com.tommasoberlose.anotherwidget.ui.activity.MainActivity"
android:minResizeHeight="60dp"
android:minResizeHeight="50dp"
android:minResizeWidth="300dp"
android:previewImage="@drawable/widget_preview"
android:resizeMode="vertical|horizontal"

View File

@ -2,9 +2,9 @@
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialKeyguardLayout="@layout/the_widget"
android:initialLayout="@layout/the_widget"
android:minHeight="80dp"
android:minHeight="50dp"
android:minWidth="300dp"
android:minResizeHeight="60dp"
android:minResizeHeight="50dp"
android:minResizeWidth="300dp"
android:previewImage="@drawable/widget_preview"
android:resizeMode="vertical|horizontal"