diff --git a/app/build.gradle b/app/build.gradle index 4905f6d..465c070 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,7 +17,7 @@ android { applicationId "com.tommasoberlose.anotherwidget" minSdkVersion 19 targetSdkVersion 26 - versionCode 31 + versionCode 32 versionName "1.3" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } @@ -45,12 +45,12 @@ dependencies { implementation 'com.android.support:cardview-v7:26.1.0' kapt 'com.android.databinding:compiler:3.0.0' implementation('com.crashlytics.sdk.android:crashlytics:2.7.0@aar') { - transitive = true; + transitive = true } implementation 'com.android.support:design:26.1.0' implementation 'org.greenrobot:eventbus:3.0.0' implementation 'com.android.support:recyclerview-v7:26.1.0' - implementation 'com.google.android.gms:play-services-awareness:11.4.2' + implementation 'com.google.android.gms:play-services-awareness:11.6.0' implementation 'joda-time:joda-time:2.9.9' implementation 'com.pes.materialcolorpicker:library:1.0.4' implementation 'com.andkulikov:transitionseverywhere:1.7.6' diff --git a/app/release/app-release.apk b/app/release/app-release.apk index 7b48e37..7c4f93e 100644 Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ diff --git a/app/release/output.json b/app/release/output.json index cd0675e..c5b59e5 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":31},"path":"app-release.apk","properties":{"packageId":"com.tommasoberlose.anotherwidget","split":"","minSdkVersion":"19"}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":32},"path":"app-release.apk","properties":{"packageId":"com.tommasoberlose.anotherwidget","split":"","minSdkVersion":"19"}}] \ No newline at end of file diff --git a/app/src/main/assets/fonts/product_sans_black.ttf b/app/src/main/assets/fonts/product_sans_black.ttf new file mode 100644 index 0000000..060739f Binary files /dev/null and b/app/src/main/assets/fonts/product_sans_black.ttf differ diff --git a/app/src/main/assets/fonts/product_sans_light.ttf b/app/src/main/assets/fonts/product_sans_light.ttf new file mode 100644 index 0000000..1221e07 Binary files /dev/null and b/app/src/main/assets/fonts/product_sans_light.ttf differ diff --git a/app/src/main/assets/fonts/product_sans_medium.ttf b/app/src/main/assets/fonts/product_sans_medium.ttf new file mode 100644 index 0000000..85860e6 Binary files /dev/null and b/app/src/main/assets/fonts/product_sans_medium.ttf differ diff --git a/app/src/main/assets/fonts/product_sans_thin.ttf b/app/src/main/assets/fonts/product_sans_thin.ttf new file mode 100644 index 0000000..9d08714 Binary files /dev/null and b/app/src/main/assets/fonts/product_sans_thin.ttf differ diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/object/Constants.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/object/Constants.kt index 60a8a23..7e9cfc6 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/object/Constants.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/object/Constants.kt @@ -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 } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/OpenWeatherIntentReceiver.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/OpenWeatherIntentReceiver.kt index d49de0d..e63da2c 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/OpenWeatherIntentReceiver.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/OpenWeatherIntentReceiver.kt @@ -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) } } } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/MainActivity.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/MainActivity.kt index 08af345..578d35c 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/MainActivity.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/MainActivity.kt @@ -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 { diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/SupportDevActivity.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/SupportDevActivity.kt index 5863a12..8b92a0c 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/SupportDevActivity.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/SupportDevActivity.kt @@ -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) } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/WeatherProviderActivity.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/WeatherProviderActivity.kt index 2a2ce54..48985f6 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/WeatherProviderActivity.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/WeatherProviderActivity.kt @@ -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) diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widget/TheWidget.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widget/TheWidget.kt index 4a24ecc..b8c2fae 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widget/TheWidget.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widget/TheWidget.kt @@ -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 diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/util/Util.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/util/Util.kt index b647c6a..372a408 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/util/Util.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/util/Util.kt @@ -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 + } } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/util/WeatherUtil.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/util/WeatherUtil.kt index 012eccb..41dbd3d 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/util/WeatherUtil.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/util/WeatherUtil.kt @@ -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(). diff --git a/app/src/main/res/drawable-hdpi/ic_action_settings.png b/app/src/main/res/drawable-hdpi/ic_action_settings.png new file mode 100644 index 0000000..30b356d Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_settings.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_sync.png b/app/src/main/res/drawable-hdpi/ic_action_sync.png new file mode 100644 index 0000000..7f80184 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_sync.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_settings.png b/app/src/main/res/drawable-mdpi/ic_action_settings.png new file mode 100644 index 0000000..ce72de5 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_settings.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_sync.png b/app/src/main/res/drawable-mdpi/ic_action_sync.png new file mode 100644 index 0000000..c7fd1be Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_sync.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_settings.png b/app/src/main/res/drawable-xhdpi/ic_action_settings.png new file mode 100644 index 0000000..7afaebc Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_settings.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_sync.png b/app/src/main/res/drawable-xhdpi/ic_action_sync.png new file mode 100644 index 0000000..4a0a2e9 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_sync.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_settings.png b/app/src/main/res/drawable-xxhdpi/ic_action_settings.png new file mode 100644 index 0000000..4b473b7 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_settings.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_sync.png b/app/src/main/res/drawable-xxhdpi/ic_action_sync.png new file mode 100644 index 0000000..c395f5f Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_sync.png differ diff --git a/app/src/main/res/layout/the_widget.xml b/app/src/main/res/layout/the_widget.xml index c681254..56f3862 100644 --- a/app/src/main/res/layout/the_widget.xml +++ b/app/src/main/res/layout/the_widget.xml @@ -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" diff --git a/app/src/main/res/values-it-rIT/strings.xml b/app/src/main/res/values-it-rIT/strings.xml index 16cac80..e3587dd 100644 --- a/app/src/main/res/values-it-rIT/strings.xml +++ b/app/src/main/res/values-it-rIT/strings.xml @@ -155,4 +155,7 @@ Nascondi Anteprima Widget GPS Disattivato Riattiva il GPS così che Another Widget possa aggiornare il meteo con le API di Google Awareness. + Impostazioni GPS + Cambia Provider + Disabilita Notifica \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f80809b..129edb5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -160,4 +160,7 @@ Hide Widget Preview Location is turned off Turn Location back on so Another Widget can update weather informations with Google Awareness API. + Location Settings + Change Provider + Disable Notification diff --git a/app/src/main/res/xml-v21/the_widget_info.xml b/app/src/main/res/xml-v21/the_widget_info.xml index b7bb16b..802913f 100644 --- a/app/src/main/res/xml-v21/the_widget_info.xml +++ b/app/src/main/res/xml-v21/the_widget_info.xml @@ -2,10 +2,10 @@