diff --git a/.travis.yml b/.travis.yml index 40b9a165..389dabd9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ android: - tools - tools - platfom-tools - - build-tools-25.0.2 + - build-tools-26.0.1 - android-25 - extra-android-m2repository licenses: diff --git a/app/build.gradle b/app/build.gradle index b9e4b5fc..4bbfd8d2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion '25.0.2' + compileSdkVersion 26 defaultConfig { applicationId "org.asdtm.goodweather" minSdkVersion 14 - targetSdkVersion 25 + targetSdkVersion 26 versionCode 13 versionName "4.4" vectorDrawables.useSupportLibrary = true @@ -15,22 +14,14 @@ android { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - applicationVariants.all { variant -> - variant.outputs.each { output -> - output.outputFile = new File( - output.outputFile.parent, - output.outputFile.name.replace("app-release.apk", "GoodWeather-release-${variant.versionName}.apk")) - } - } } debug { minifyEnabled false - applicationVariants.all { variant -> - variant.outputs.each { output -> - output.outputFile = new File( - output.outputFile.parent, - output.outputFile.name.replace("app-debug.apk", "GoodWeather-debug-${variant.versionName}.apk")) - } + } + + applicationVariants.all { variant -> + variant.outputs.all { output -> + outputFileName = "GoodWeather-${variant.buildType.name}-${variant.versionName}" + ".apk" } } } @@ -42,12 +33,12 @@ android { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:appcompat-v7:25.3.1' - compile 'com.android.support:design:25.3.1' - compile 'com.android.support:cardview-v7:25.3.1' - compile 'com.android.support:support-v4:25.3.1' + compile 'com.android.support:appcompat-v7:26.1.0' + compile 'com.android.support:design:26.1.0' + compile 'com.android.support:cardview-v7:26.1.0' + compile 'com.android.support:support-v4:26.1.0' testCompile 'junit:junit:4.12' - compile 'com.google.code.gson:gson:2.6.2' - compile 'com.github.PhilJay:MPAndroidChart:v3.0.0-beta1' + compile 'com.google.code.gson:gson:2.8.0' + compile 'com.github.PhilJay:MPAndroidChart:v3.0.2' compile 'com.android.support.constraint:constraint-layout:1.0.2' } diff --git a/app/src/main/java/org/asdtm/goodweather/GraphsActivity.java b/app/src/main/java/org/asdtm/goodweather/GraphsActivity.java index 9117044d..c6fca2cf 100644 --- a/app/src/main/java/org/asdtm/goodweather/GraphsActivity.java +++ b/app/src/main/java/org/asdtm/goodweather/GraphsActivity.java @@ -27,8 +27,8 @@ import org.asdtm.goodweather.utils.CustomValueFormatter; import org.asdtm.goodweather.utils.LanguageUtil; import org.asdtm.goodweather.utils.PreferenceUtil; -import org.asdtm.goodweather.utils.XAxisValueFormatter; import org.asdtm.goodweather.utils.Utils; +import org.asdtm.goodweather.utils.XAxisValueFormatter; import org.asdtm.goodweather.utils.YAxisValueFormatter; import org.json.JSONArray; import org.json.JSONException; @@ -50,8 +50,8 @@ public class GraphsActivity extends BaseActivity { - private ConnectionDetector mConnectionDetector; public List mForecastList; + private ConnectionDetector mConnectionDetector; private LineChart mTemperatureChart; private LineChart mWindChart; private LineChart mRainChart; @@ -116,7 +116,7 @@ public void handleMessage(android.os.Message msg) { } private void setTemperatureChart() { - mTemperatureChart.setDescription(""); + //mTemperatureChart.setDescription(""); mTemperatureChart.setDrawGridBackground(false); mTemperatureChart.setTouchEnabled(true); mTemperatureChart.setDragEnabled(true); @@ -185,7 +185,7 @@ private void setTemperatureChart() { } private void setWindChart() { - mWindChart.setDescription(""); + //mWindChart.setDescription(""); mWindChart.setDrawGridBackground(false); mWindChart.setTouchEnabled(true); mWindChart.setDragEnabled(true); @@ -254,7 +254,7 @@ private void setWindChart() { } private void setRainChart() { - mRainChart.setDescription(""); + //mRainChart.setDescription(""); mRainChart.setDrawGridBackground(false); mRainChart.setTouchEnabled(true); mRainChart.setDragEnabled(true); @@ -323,7 +323,7 @@ private void setRainChart() { } private void setSnowChart() { - mSnowChart.setDescription(""); + //mSnowChart.setDescription(""); mSnowChart.setDrawGridBackground(false); mSnowChart.setTouchEnabled(true); mSnowChart.setDragEnabled(true); diff --git a/app/src/main/java/org/asdtm/goodweather/MainActivity.java b/app/src/main/java/org/asdtm/goodweather/MainActivity.java index 3f2dfd54..ace21f8f 100644 --- a/app/src/main/java/org/asdtm/goodweather/MainActivity.java +++ b/app/src/main/java/org/asdtm/goodweather/MainActivity.java @@ -57,7 +57,12 @@ public class MainActivity extends BaseActivity implements AppBarLayout.OnOffsetC private static final String TAG = "MainActivity"; private static final long LOCATION_TIMEOUT_IN_MS = 30000L; - + private static final int REQUEST_LOCATION = 0; + public static Weather mWeather; + public static CitySearch mCitySearch; + private static String[] PERMISSIONS_LOCATION = {Manifest.permission.ACCESS_COARSE_LOCATION, + Manifest.permission.ACCESS_FINE_LOCATION}; + public Context storedContext; private TextView mIconWeatherView; private TextView mTemperatureView; private TextView mDescriptionView; @@ -75,7 +80,6 @@ public class MainActivity extends BaseActivity implements AppBarLayout.OnOffsetC private TextView mIconCloudinessView; private TextView mIconSunriseView; private TextView mIconSunsetView; - private ConnectionDetector connectionDetector; private Boolean isNetworkAvailable; private ProgressDialog mProgressDialog; @@ -83,7 +87,6 @@ public class MainActivity extends BaseActivity implements AppBarLayout.OnOffsetC private SwipeRefreshLayout mSwipeRefresh; private Menu mToolbarMenu; private BroadcastReceiver mWeatherUpdateReceiver; - private String mSpeedScale; private String mIconWind; private String mIconHumidity; @@ -93,18 +96,108 @@ public class MainActivity extends BaseActivity implements AppBarLayout.OnOffsetC private String mIconSunset; private String mPercentSign; private String mPressureMeasurement; - private SharedPreferences mPrefWeather; + FloatingActionButton.OnClickListener fabListener = new View.OnClickListener() { + @Override + public void onClick(View view) { + String temperatureScale = Utils.getTemperatureScale(MainActivity.this); + mSpeedScale = Utils.getSpeedScale(MainActivity.this); + String weather; + String temperature; + String description; + String wind; + String sunrise; + String sunset; + temperature = String.format(Locale.getDefault(), "%.0f", mPrefWeather.getFloat(Constants.WEATHER_DATA_TEMPERATURE, 0)); + description = mPrefWeather.getString(Constants.WEATHER_DATA_DESCRIPTION, + "clear sky"); + wind = String.format(Locale.getDefault(), "%.1f", + mPrefWeather.getFloat(Constants.WEATHER_DATA_WIND_SPEED, 0)); + sunrise = Utils.unixTimeToFormatTime(MainActivity.this, mPrefWeather + .getLong(Constants.WEATHER_DATA_SUNRISE, -1)); + sunset = Utils.unixTimeToFormatTime(MainActivity.this, mPrefWeather + .getLong(Constants.WEATHER_DATA_SUNSET, -1)); + weather = "City: " + Utils.getCityAndCountry(storedContext) + + "\nTemperature: " + temperature + temperatureScale + + "\nDescription: " + description + + "\nWind: " + wind + " " + mSpeedScale + + "\nSunrise: " + sunrise + + "\nSunset: " + sunset; + Intent shareIntent = new Intent(Intent.ACTION_SEND); + shareIntent.setType("text/plain"); + shareIntent.putExtra(Intent.EXTRA_TEXT, weather); + shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + try { + startActivity(Intent.createChooser(shareIntent, "Share Weather")); + } catch (ActivityNotFoundException e) { + Toast.makeText(MainActivity.this, + "Communication app not found", + Toast.LENGTH_LONG).show(); + } + } + }; private SharedPreferences mSharedPreferences; + private LocationListener mLocationListener = new LocationListener() { + @Override + public void onLocationChanged(Location location) { + mProgressDialog.cancel(); + String latitude = String.format("%1$.2f", location.getLatitude()); + String longitude = String.format("%1$.2f", location.getLongitude()); - public static Weather mWeather; - public static CitySearch mCitySearch; + if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + locationManager.removeUpdates(mLocationListener); + } - private static final int REQUEST_LOCATION = 0; - private static String[] PERMISSIONS_LOCATION = {Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.ACCESS_FINE_LOCATION}; + connectionDetector = new ConnectionDetector(MainActivity.this); + isNetworkAvailable = connectionDetector.isNetworkAvailableAndConnected(); - public Context storedContext; + mSharedPreferences = getSharedPreferences(Constants.APP_SETTINGS_NAME, + Context.MODE_PRIVATE); + SharedPreferences.Editor editor = mSharedPreferences.edit(); + editor.putString(Constants.APP_SETTINGS_LATITUDE, latitude); + editor.putString(Constants.APP_SETTINGS_LONGITUDE, longitude); + getAndWriteAddressFromGeocoder(latitude, longitude, editor); + editor.apply(); + + if (isNetworkAvailable) { + startService(new Intent(MainActivity.this, CurrentWeatherService.class)); + sendBroadcast(new Intent(Constants.ACTION_FORCED_APPWIDGET_UPDATE)); + } else { + Toast.makeText(MainActivity.this, R.string.connection_not_found, Toast.LENGTH_SHORT) + .show(); + } + } + + @Override + public void onStatusChanged(String provider, int status, Bundle extras) { + + } + + @Override + public void onProviderEnabled(String provider) { + + } + + @Override + public void onProviderDisabled(String provider) { + + } + }; + private SwipeRefreshLayout.OnRefreshListener swipeRefreshListener = + new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + isNetworkAvailable = connectionDetector.isNetworkAvailableAndConnected(); + if (isNetworkAvailable) { + startService(new Intent(MainActivity.this, CurrentWeatherService.class)); + } else { + Toast.makeText(MainActivity.this, + R.string.connection_not_found, + Toast.LENGTH_SHORT).show(); + mSwipeRefresh.setRefreshing(false); + } + } + }; @Override public void onCreate(Bundle savedInstanceState) { @@ -246,53 +339,6 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } - private LocationListener mLocationListener = new LocationListener() { - @Override - public void onLocationChanged(Location location) { - mProgressDialog.cancel(); - String latitude = String.format("%1$.2f", location.getLatitude()); - String longitude = String.format("%1$.2f", location.getLongitude()); - - if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { - locationManager.removeUpdates(mLocationListener); - } - - connectionDetector = new ConnectionDetector(MainActivity.this); - isNetworkAvailable = connectionDetector.isNetworkAvailableAndConnected(); - - mSharedPreferences = getSharedPreferences(Constants.APP_SETTINGS_NAME, - Context.MODE_PRIVATE); - SharedPreferences.Editor editor = mSharedPreferences.edit(); - editor.putString(Constants.APP_SETTINGS_LATITUDE, latitude); - editor.putString(Constants.APP_SETTINGS_LONGITUDE, longitude); - getAndWriteAddressFromGeocoder(latitude, longitude, editor); - editor.apply(); - - if (isNetworkAvailable) { - startService(new Intent(MainActivity.this, CurrentWeatherService.class)); - sendBroadcast(new Intent(Constants.ACTION_FORCED_APPWIDGET_UPDATE)); - } else { - Toast.makeText(MainActivity.this, R.string.connection_not_found, Toast.LENGTH_SHORT) - .show(); - } - } - - @Override - public void onStatusChanged(String provider, int status, Bundle extras) { - - } - - @Override - public void onProviderEnabled(String provider) { - - } - - @Override - public void onProviderDisabled(String provider) { - - } - }; - private void getAndWriteAddressFromGeocoder(String latitude, String longitude, SharedPreferences.Editor editor) { Geocoder geocoder = new Geocoder(this, Locale.getDefault()); try { @@ -308,22 +354,6 @@ private void getAndWriteAddressFromGeocoder(String latitude, String longitude, S } } - private SwipeRefreshLayout.OnRefreshListener swipeRefreshListener = - new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - isNetworkAvailable = connectionDetector.isNetworkAvailableAndConnected(); - if (isNetworkAvailable) { - startService(new Intent(MainActivity.this, CurrentWeatherService.class)); - } else { - Toast.makeText(MainActivity.this, - R.string.connection_not_found, - Toast.LENGTH_SHORT).show(); - mSwipeRefresh.setRefreshing(false); - } - } - }; - private void preLoadWeather() { mSpeedScale = Utils.getSpeedScale(this); String lastUpdate = Utils.setLastUpdateTime(this, @@ -468,48 +498,13 @@ public void onReceive(Context context, Intent intent) { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { - mSwipeRefresh.setEnabled(verticalOffset == 0); - } - - FloatingActionButton.OnClickListener fabListener = new View.OnClickListener() { - @Override - public void onClick(View view) { - String temperatureScale = Utils.getTemperatureScale(MainActivity.this); - mSpeedScale = Utils.getSpeedScale(MainActivity.this); - String weather; - String temperature; - String description; - String wind; - String sunrise; - String sunset; - temperature = String.format(Locale.getDefault(), "%.0f", mPrefWeather.getFloat(Constants.WEATHER_DATA_TEMPERATURE, 0)); - description = mPrefWeather.getString(Constants.WEATHER_DATA_DESCRIPTION, - "clear sky"); - wind = String.format(Locale.getDefault(), "%.1f", - mPrefWeather.getFloat(Constants.WEATHER_DATA_WIND_SPEED, 0)); - sunrise = Utils.unixTimeToFormatTime(MainActivity.this, mPrefWeather - .getLong(Constants.WEATHER_DATA_SUNRISE, -1)); - sunset = Utils.unixTimeToFormatTime(MainActivity.this, mPrefWeather - .getLong(Constants.WEATHER_DATA_SUNSET, -1)); - weather = "City: " + Utils.getCityAndCountry(storedContext) + - "\nTemperature: " + temperature + temperatureScale + - "\nDescription: " + description + - "\nWind: " + wind + " " + mSpeedScale + - "\nSunrise: " + sunrise + - "\nSunset: " + sunset; - Intent shareIntent = new Intent(Intent.ACTION_SEND); - shareIntent.setType("text/plain"); - shareIntent.putExtra(Intent.EXTRA_TEXT, weather); - shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - try { - startActivity(Intent.createChooser(shareIntent, "Share Weather")); - } catch (ActivityNotFoundException e) { - Toast.makeText(MainActivity.this, - "Communication app not found", - Toast.LENGTH_LONG).show(); - } + if (verticalOffset == 0) { + mSwipeRefresh.setEnabled(true); + } else { + mSwipeRefresh.setRefreshing(false); + mSwipeRefresh.setEnabled(false); } - }; + } private void detectLocation() { boolean isGPSEnabled = locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER) diff --git a/app/src/main/java/org/asdtm/goodweather/utils/CustomValueFormatter.java b/app/src/main/java/org/asdtm/goodweather/utils/CustomValueFormatter.java index ce5c98c9..de87051f 100644 --- a/app/src/main/java/org/asdtm/goodweather/utils/CustomValueFormatter.java +++ b/app/src/main/java/org/asdtm/goodweather/utils/CustomValueFormatter.java @@ -1,12 +1,12 @@ package org.asdtm.goodweather.utils; import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.formatter.ValueFormatter; +import com.github.mikephil.charting.formatter.IValueFormatter; import com.github.mikephil.charting.utils.ViewPortHandler; import java.text.DecimalFormat; -public class CustomValueFormatter implements ValueFormatter { +public class CustomValueFormatter implements IValueFormatter { private DecimalFormat mFormat; diff --git a/app/src/main/java/org/asdtm/goodweather/utils/LanguageUtil.java b/app/src/main/java/org/asdtm/goodweather/utils/LanguageUtil.java index 542bd94c..cf9fc457 100644 --- a/app/src/main/java/org/asdtm/goodweather/utils/LanguageUtil.java +++ b/app/src/main/java/org/asdtm/goodweather/utils/LanguageUtil.java @@ -22,7 +22,7 @@ public static void setLanguage(final ContextWrapper contextWrapper, String local if (TextUtils.isEmpty(locale)) { sLocale = Locale.getDefault(); } else { - String[] localeParts = locale.split("_"); + String[] localeParts = locale.split("-r"); if (localeParts.length > 1) { sLocale = new Locale(localeParts[0], localeParts[1]); } else { @@ -58,8 +58,8 @@ public static String getLanguageName(String locale) { if (TextUtils.isEmpty(locale)) { locale = Locale.getDefault().toString(); } - if (locale.contains("_")) { - return locale.split("_")[0]; + if (locale.contains("-")) { + return locale.split("-")[0]; } return locale; } diff --git a/app/src/main/java/org/asdtm/goodweather/utils/XAxisValueFormatter.java b/app/src/main/java/org/asdtm/goodweather/utils/XAxisValueFormatter.java index 8a70a13e..645adad9 100644 --- a/app/src/main/java/org/asdtm/goodweather/utils/XAxisValueFormatter.java +++ b/app/src/main/java/org/asdtm/goodweather/utils/XAxisValueFormatter.java @@ -1,9 +1,9 @@ package org.asdtm.goodweather.utils; import com.github.mikephil.charting.components.AxisBase; -import com.github.mikephil.charting.formatter.AxisValueFormatter; +import com.github.mikephil.charting.formatter.IAxisValueFormatter; -public class XAxisValueFormatter implements AxisValueFormatter { +public class XAxisValueFormatter implements IAxisValueFormatter { private String[] mValues; @@ -16,7 +16,6 @@ public String getFormattedValue(float value, AxisBase axis) { return mValues[(int) value]; } - @Override public int getDecimalDigits() { return 0; } diff --git a/app/src/main/java/org/asdtm/goodweather/utils/YAxisValueFormatter.java b/app/src/main/java/org/asdtm/goodweather/utils/YAxisValueFormatter.java index aec6772b..64440b84 100644 --- a/app/src/main/java/org/asdtm/goodweather/utils/YAxisValueFormatter.java +++ b/app/src/main/java/org/asdtm/goodweather/utils/YAxisValueFormatter.java @@ -1,11 +1,11 @@ package org.asdtm.goodweather.utils; import com.github.mikephil.charting.components.AxisBase; -import com.github.mikephil.charting.formatter.AxisValueFormatter; +import com.github.mikephil.charting.formatter.IAxisValueFormatter; import java.text.DecimalFormat; -public class YAxisValueFormatter implements AxisValueFormatter { +public class YAxisValueFormatter implements IAxisValueFormatter { private DecimalFormat mFormat; @@ -18,7 +18,6 @@ public String getFormattedValue(float value, AxisBase axis) { return mFormat.format(value); } - @Override public int getDecimalDigits() { return 1; } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 068d1db0..2a794571 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -87,6 +87,7 @@ Euskara (Basque) Беларуская (Belarusian) Català (Catalan) + 中文 (Chinese) Čeština (Czech) Français (French) Italiano (Italian) @@ -103,6 +104,7 @@ eu be ca + zh-rCN cs fr it diff --git a/build.gradle b/build.gradle index f1bed3ee..e5340eef 100644 --- a/build.gradle +++ b/build.gradle @@ -2,10 +2,11 @@ buildscript { repositories { + google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:3.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -14,6 +15,7 @@ buildscript { allprojects { repositories { + google() jcenter() maven { url "https://jitpack.io" } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0bb10c8b..93d1b921 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Mar 03 15:30:50 MSK 2017 +#Tue Nov 28 21:01:56 CST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip