Skip to content

Commit

Permalink
2.245
Browse files Browse the repository at this point in the history
  • Loading branch information
WangDaYeeeeee committed Mar 19, 2019
1 parent 39f4bef commit 949c7f5
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 97 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "wangdaye.com.geometricweather"
minSdkVersion 19
targetSdkVersion 28
versionCode 2244
versionName "2.244"
versionCode 2245
versionName "2.245"
ndk {
abiFilters 'armeabi', 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
}
Expand Down
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2244,"versionName":"2.244","enabled":true,"outputFile":"GeometricWeather 2.244.apk","fullName":"release","baseName":"release"},"path":"GeometricWeather 2.244.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2245,"versionName":"2.245","enabled":true,"outputFile":"GeometricWeather 2.245.apk","fullName":"release","baseName":"release"},"path":"GeometricWeather 2.245.apk","properties":{}}]
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import wangdaye.com.geometricweather.ui.widget.weatherView.materialWeatherView.implementor.SunImplementor;
import wangdaye.com.geometricweather.ui.widget.weatherView.materialWeatherView.implementor.WindImplementor;
import wangdaye.com.geometricweather.db.DatabaseHelper;
import wangdaye.com.geometricweather.utils.LogUtils;
import wangdaye.com.geometricweather.utils.manager.TimeManager;

public class LiveWallpaperService extends WallpaperService {
Expand Down Expand Up @@ -80,13 +79,16 @@ protected void onRender(long interval) {

implementor.updateData(
sizes, interval,
(float) rotators[0].getRotate(), (float) rotators[1].getRotate());
(float) rotators[0].getRotate(), (float) rotators[1].getRotate()
);
if (step == STEP_DISPLAY) {
displayRate = (float) Math.min(
1, displayRate + 1.0 * interval / SWITCH_WEATHER_ANIMATION_DURATION);
1, displayRate + 1.0 * interval / SWITCH_WEATHER_ANIMATION_DURATION
);
} else {
displayRate = (float) Math.max(
0, displayRate - 1.0 * interval / SWITCH_WEATHER_ANIMATION_DURATION);
0, displayRate - 1.0 * interval / SWITCH_WEATHER_ANIMATION_DURATION
);
}
if (displayRate == 0) {
setWeatherImplementor();
Expand Down Expand Up @@ -115,7 +117,8 @@ protected void onRender(long interval) {
implementor.draw(
sizes, canvas,
displayRate, 0,
(float) rotators[0].getRotate(), (float) rotators[1].getRotate());
(float) rotators[0].getRotate(), (float) rotators[1].getRotate()
);
holder.unlockCanvasAndPost(canvas);
}
} catch (Exception ignored) {
Expand Down Expand Up @@ -388,16 +391,18 @@ public void onVisibilityChanged(boolean visible) {
location.weather = DatabaseHelper.getInstance(LiveWallpaperService.this)
.readWeather(location);
if (location.weather != null) {
LogUtils.log("read weather succeed");
setWeather(
WeatherViewController.getWeatherViewWeatherKind(
location.weather.realTime.weatherKind,
TimeManager.getInstance(LiveWallpaperService.this).isDayTime()));
TimeManager.getInstance(LiveWallpaperService.this).isDayTime()
)
);
}
setWeatherImplementor();
setOpenGravitySensor(
PreferenceManager.getDefaultSharedPreferences(LiveWallpaperService.this)
.getBoolean(getString(R.string.key_gravity_sensor_switch), true));
.getBoolean(getString(R.string.key_gravity_sensor_switch), true)
);

if (updateDataRunnable == null || !updateDataRunnable.isRunning()) {
updateDataRunnable = new UpdateDataRunnable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.widget.NestedScrollView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
Expand All @@ -25,6 +26,8 @@

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -224,8 +227,8 @@ private void readLocationList() {
locationList.get(i).weather = DatabaseHelper.getInstance(this)
.readWeather(locationList.get(i));
if (locationList.get(i).weather != null) {
locationList.get(i).history = DatabaseHelper.getInstance(this).readHistory(
locationList.get(i).weather);
locationList.get(i).history = DatabaseHelper.getInstance(this)
.readHistory(locationList.get(i).weather);
}
}
}
Expand Down Expand Up @@ -282,12 +285,14 @@ private void initWidget() {
} else {
kind = WeatherViewController.getWeatherViewWeatherKind(
locationNow.weather.realTime.weatherKind,
TimeManager.getInstance(this).isDayTime());
TimeManager.getInstance(this).isDayTime()
);
}
weatherView.setWeather(kind);
((MaterialWeatherView) weatherView).setOpenGravitySensor(
PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(getString(R.string.key_gravity_sensor_switch), true));
.getBoolean(getString(R.string.key_gravity_sensor_switch), true)
);
}

this.appBar = findViewById(R.id.activity_main_appBar);
Expand All @@ -313,10 +318,15 @@ private void initWidget() {
switchLayout.setOnTouchListener(indicatorStateListener);

this.refreshLayout = findViewById(R.id.activity_main_refreshView);
int startPosition = (int) (DisplayUtils.getStatusBarHeight(getResources())
+ DisplayUtils.dpToPx(this, 16));
int startPosition = (int) (
DisplayUtils.getStatusBarHeight(getResources())
+ DisplayUtils.dpToPx(this, 16)
);
refreshLayout.setProgressViewOffset(
false, startPosition, startPosition + refreshLayout.getProgressViewEndOffset());
false,
startPosition,
startPosition + refreshLayout.getProgressViewEndOffset()
);
refreshLayout.setOnRefreshListener(this);
if (weatherView instanceof MaterialWeatherView) {
refreshLayout.setColorSchemeColors(weatherView.getThemeColors()[0]);
Expand Down Expand Up @@ -375,11 +385,15 @@ private void buildUI() {
if (locationNow.weather == null) {
return;
} else {
TimeManager.getInstance(this).getDayTime(this, locationNow.weather, true);
TimeManager.getInstance(this)
.getDayTime(this, locationNow.weather, true);
}

WeatherViewController.setWeatherViewWeatherKind(
weatherView, locationNow.weather, TimeManager.getInstance(this).isDayTime());
weatherView,
locationNow.weather,
TimeManager.getInstance(this).isDayTime()
);
setDarkMode(TimeManager.getInstance(this).isDayTime());

DisplayUtils.setWindowTopColor(this, weatherView.getThemeColors()[0]);
Expand All @@ -397,8 +411,7 @@ private void buildUI() {
if (initAnimator != null) {
initAnimator.cancel();
}
initAnimator = (AnimatorSet) AnimatorInflater.loadAnimator(
MainActivity.this, R.animator.card_in);
initAnimator = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.card_in);
initAnimator.setTarget(scrollView);
initAnimator.setInterpolator(new DecelerateInterpolator());
initAnimator.start();
Expand Down Expand Up @@ -438,18 +451,22 @@ private void refreshBackgroundViews() {
Observable.just(1)
.compose(RxLifecycleCompact.bind(this).disposeObservableWhen(LifecycleEvent.DESTROY))
.delay(1, TimeUnit.SECONDS)
.doOnNext(integer -> ThreadManager.getInstance().execute(() ->
BackgroundManager.resetAllBackgroundTask(MainActivity.this, false)))
.subscribe();
.doOnNext(integer ->
ThreadManager.getInstance().execute(() ->
BackgroundManager.resetAllBackgroundTask(
MainActivity.this,
false
)
)
).subscribe();
if (locationNow.equals(locationList.get(0))) {
Observable.just(1)
.compose(RxLifecycleCompact.bind(this).disposeObservableWhen(LifecycleEvent.DESTROY))
.delay(1, TimeUnit.SECONDS)
.doOnNext(integer -> {
WidgetUtils.refreshWidgetInNewThread(this, locationList.get(0));
NotificationUtils.refreshNotificationInNewThread(this, locationList.get(0));
})
.subscribe();
}).subscribe();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutsManager.refreshShortcutsInNewThread(this, locationList);
Expand All @@ -460,10 +477,17 @@ private void refreshBackgroundViews() {

@RequiresApi(api = Build.VERSION_CODES.M)
private void requestLocationPermission() {
if (locationHelper.hasPermissions(this)) {
List<String> permissionList = new ArrayList<>(Arrays.asList(locationHelper.getPermissions()));
for (int i = permissionList.size() - 1; i >= 0; i --) {
if (ActivityCompat.checkSelfPermission(this, permissionList.get(i))
== PackageManager.PERMISSION_GRANTED) {
permissionList.remove(i);
}
}
if (permissionList.size() == 0) { // has permissions.
locationHelper.requestLocation(this, locationNow, this);
} else {
this.requestPermissions(locationHelper.getPermissions(), LOCATION_PERMISSIONS_REQUEST_CODE);
requestPermissions(permissionList.toArray(new String[0]), LOCATION_PERMISSIONS_REQUEST_CODE);
}
}

Expand All @@ -474,17 +498,19 @@ public void onRequestPermissionsResult(int requestCode,
switch (requestCode) {
case LOCATION_PERMISSIONS_REQUEST_CODE:
for (int i = 0; i < permission.length && i < grantResult.length; i ++) {
if ((permission[i].equals(Manifest.permission.ACCESS_COARSE_LOCATION)
|| permission[i].equals(Manifest.permission.ACCESS_FINE_LOCATION))
&& grantResult[i] != PackageManager.PERMISSION_GRANTED) {
if ((
permission[i].equals(Manifest.permission.ACCESS_COARSE_LOCATION)
|| permission[i].equals(Manifest.permission.ACCESS_FINE_LOCATION)
) && grantResult[i] != PackageManager.PERMISSION_GRANTED) {
SnackbarUtils.showSnackbar(
getString(R.string.feedback_request_location_permission_failed),
getString(R.string.help),
v -> {
if (isForeground()) {
new LocationHelpDialog().show(getSupportFragmentManager(), null);
}
});
}
);
setRefreshing(false);
return;
}
Expand Down Expand Up @@ -525,8 +551,7 @@ public void swipeTakeEffect(int direction) {
switchLayout.setEnabled(false);
for (int i = 0; i < locationList.size(); i ++) {
if (locationList.get(i).equals(locationNow)) {
int position = direction == SwipeSwitchLayout.DIRECTION_LEFT ?
i + 1 : i - 1;
int position = direction == SwipeSwitchLayout.DIRECTION_LEFT ? i + 1 : i - 1;
if (position < 0) {
position = locationList.size() - 1;
} else if (position > locationList.size() - 1) {
Expand Down Expand Up @@ -572,8 +597,7 @@ private class OnScrollListener implements NestedScrollView.OnScrollChangeListene
OnScrollListener(int firstCardMarginTop) {
super();
this.firstCardMarginTop = firstCardMarginTop;
this.overlapTriggerDistance = firstCardMarginTop
- DisplayUtils.getStatusBarHeight(getResources());
this.overlapTriggerDistance = firstCardMarginTop - DisplayUtils.getStatusBarHeight(getResources());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public static void refreshShortcutsInNewThread(final Context c, List<Location> l
try {
int size = Math.min((int) DisplayUtils.dpToPx(c, 108), 768);
Bitmap foreground = Glide.with(c)
.load(
WeatherHelper.getShortcutForeground(
weather.realTime.weatherKind,
TimeManager.getInstance(c).isDayTime()))
.load(WeatherHelper.getShortcutForeground(
weather.realTime.weatherKind,
TimeManager.isDaylight(weather)
))
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.centerCrop()
Expand All @@ -64,13 +64,19 @@ public static void refreshShortcutsInNewThread(final Context c, List<Location> l
icon = Icon.createWithResource(
c,
WeatherHelper.getShortcutIcon(
weather.realTime.weatherKind, TimeManager.getInstance(c).isDayTime()));
weather.realTime.weatherKind,
TimeManager.getInstance(c).isDayTime()
)
);
}
} else {
icon = Icon.createWithResource(
c,
WeatherHelper.getShortcutIcon(
weather.realTime.weatherKind, TimeManager.getInstance(c).isDayTime()));
weather.realTime.weatherKind,
TimeManager.getInstance(c).isDayTime()
)
);
}
} else {
icon = Icon.createWithResource(c, R.drawable.ic_shortcut_sun_day);
Expand Down
Loading

0 comments on commit 949c7f5

Please sign in to comment.