Skip to content

Commit

Permalink
Merge pull request #55 from Doubi88/version-1.2.0
Browse files Browse the repository at this point in the history
Version 1.2.0
  • Loading branch information
Doubi88 authored Mar 12, 2024
2 parents 9f84bf5 + dfc4b01 commit 2e119c8
Show file tree
Hide file tree
Showing 28 changed files with 414 additions and 187 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ android {
applicationId "io.github.doubi88.slideshowwallpaper"
minSdkVersion 18
targetSdk 34
versionCode 6
versionName "1.1.0"
versionCode 9
versionName "1.2.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
Expand Down Expand Up @@ -57,6 +57,6 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.10.0'
implementation 'androidx.exifinterface:exifinterface:1.3.6'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.exifinterface:exifinterface:1.3.7'
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,26 @@ public class SlideshowWallpaperEngine extends Engine {
private float deltaX;
private float lastXOffset;
private float lastXOffsetStep;
private boolean isScrolling = false;

private SharedPreferencesManager manager;

public SlideshowWallpaperEngine() {
SharedPreferences prefs = getSharedPreferences();
manager = new SharedPreferencesManager(prefs);

deltaX = 0;
handler = new Handler(Looper.getMainLooper());
drawRunner = new DrawRunner();

clearPaint = new Paint();
clearPaint.setAntiAlias(true);
clearPaint.setColor(Color.BLACK);
clearPaint.setStyle(Paint.Style.FILL);

imagePaint = new Paint();
imagePaint.setAntiAlias(true);
if (manager.getAntiAlias()) {
imagePaint.setAntiAlias(true);
}

textPaint = new Paint();
textPaint.setAntiAlias(true);
Expand All @@ -103,8 +107,6 @@ public SlideshowWallpaperEngine() {
textSize = (int) (10f * scale + 0.5f);
textPaint.setTextSize(textSize);
handler.post(drawRunner);

manager = new SharedPreferencesManager(getSharedPreferences());
}

@Override
Expand All @@ -123,6 +125,9 @@ public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep, fl
e.printStackTrace();
deltaX = 0;
}

// When the xOffset is not a whole number, the wallpaper is scrolling
isScrolling = (Math.floor(xOffset) != xOffset);
handler.removeCallbacks(drawRunner);
handler.post(drawRunner);
}
Expand Down Expand Up @@ -194,7 +199,7 @@ private SharedPreferences getSharedPreferences() {
private Bitmap getNextImage() throws IOException {
Uri uri = getNextUri();
if (uri != null) {
if (lastRenderedImage == null || !uri.equals(lastRenderedImage.getUri())) {
if (lastRenderedImage == null || lastRenderedImage.getImage() == null || !uri.equals(lastRenderedImage.getUri())) {
lastRenderedImage = ImageLoader.loadImage(uri, SlideshowWallpaperService.this, width, height, false);
Bitmap image = lastRenderedImage.getImage();
if (image != null) {
Expand All @@ -212,21 +217,21 @@ private Bitmap getNextImage() throws IOException {
private Uri getNextUri() {
Uri result = null;
SharedPreferencesManager.Ordering ordering = manager.getCurrentOrdering(getResources());
List<Uri> uris = manager.getImageUris(ordering);
int countUris = manager.getImageUrisCount();

if (uris.size() > 0) {
if (countUris > 0) {
int currentImageIndex = manager.getCurrentIndex();
if (currentImageIndex >= uris.size()) {
if (currentImageIndex >= countUris) {
// If an image was deleted and therefore we are over the end of the list
currentImageIndex -= uris.size();
currentImageIndex -= countUris;
}
int nextUpdate = calculateNextUpdateInSeconds();
if (nextUpdate <= 0) {
int delay = getDelaySeconds();
while (nextUpdate <= 0) {
currentImageIndex++;

if (currentImageIndex >= uris.size()) {
if (currentImageIndex >= countUris) {
currentImageIndex = 0;
}

Expand All @@ -235,9 +240,9 @@ private Uri getNextUri() {
manager.setCurrentIndex(currentImageIndex);
manager.setLastUpdate(System.currentTimeMillis());
}
result = uris.get(currentImageIndex);
result = manager.getImageUri(currentImageIndex, ordering);
currentIndex = currentImageIndex;
listLength = uris.size();
listLength = countUris;
}

return result;
Expand Down Expand Up @@ -285,6 +290,9 @@ public void run() {
currentImageWidth = bitmap.getWidth();

SharedPreferencesManager.TooWideImagesRule rule = manager.getTooWideImagesRule(getResources());
boolean antiAlias = manager.getAntiAlias();
boolean antiAliasScrolling = manager.getAntiAliasWhileScrolling();
imagePaint.setAntiAlias(antiAlias && (!isScrolling || antiAliasScrolling));
if (rule == SharedPreferencesManager.TooWideImagesRule.SCALE_DOWN) {
canvas.drawBitmap(bitmap, ImageLoader.calculateMatrixScaleToFit(bitmap, width, height, true), imagePaint);
} else if (rule == SharedPreferencesManager.TooWideImagesRule.SCALE_UP || rule == SharedPreferencesManager.TooWideImagesRule.SCROLL_FORWARD || rule == SharedPreferencesManager.TooWideImagesRule.SCROLL_BACKWARD) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
*/
package io.github.doubi88.slideshowwallpaper.listeners;

import java.util.HashSet;

import io.github.doubi88.slideshowwallpaper.utilities.ImageInfo;

public interface OnDeleteClickListener {
public interface OnSelectListener {

public void onImageSelected(ImageInfo info);

public void onImagedDeselected(ImageInfo info);

public void onDeleteButtonClicked(ImageInfo info);
public void onSelectionChanged(HashSet<ImageInfo> setInfo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class SharedPreferencesManager {
private static final String PREFERENCE_KEY_URI_LIST_RANDOM = "uri_list_random";
private static final String PREFERENCE_KEY_SECONDS_BETWEEN = "seconds";
private static final String PREFERENCE_KEY_TOO_WIDE_IMAGES_RULE = "too_wide_images_rule";
private static final String PREFERENCE_KEY_ANTI_ALIAS = "anti_alias";
private static final String PREFERENCE_KEY_ANTI_ALIAS_WHILE_SCROLLING = "anti_alias_scrolling";

public enum Ordering {
SELECTION(0, PREFERENCE_KEY_URI_LIST) {
Expand Down Expand Up @@ -140,6 +142,16 @@ public List<Uri> getImageUris(@NonNull Ordering ordering) {
return result;
}

public int getImageUrisCount() {
String[] uris = getUriList(Ordering.SELECTION);
return uris.length;
}

public Uri getImageUri(@NonNull int index, @NonNull Ordering ordering) {
String[] uris = getUriList(ordering);
return Uri.parse(uris[index]);
}

public boolean hasImageUri(@NonNull Uri uri) {
List<Uri> uris = getImageUris(Ordering.SELECTION);
return uris.contains(uri);
Expand Down Expand Up @@ -231,4 +243,24 @@ public TooWideImagesRule getTooWideImagesRule(Resources r) {
String value = preferences.getString(PREFERENCE_KEY_TOO_WIDE_IMAGES_RULE, TooWideImagesRule.SCALE_DOWN.getValue(r));
return TooWideImagesRule.forValue(value, r);
}

public boolean getAntiAlias() {
return preferences.getBoolean(PREFERENCE_KEY_ANTI_ALIAS, true);
}

public void setAntiAlias(boolean value) {
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(PREFERENCE_KEY_ANTI_ALIAS, value);
editor.apply();
}

public boolean getAntiAliasWhileScrolling() {
return preferences.getBoolean(PREFERENCE_KEY_ANTI_ALIAS_WHILE_SCROLLING, true);
}

public void setAntiAliasWhileScrolling(boolean value) {
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(PREFERENCE_KEY_ANTI_ALIAS_WHILE_SCROLLING, value);
editor.apply();
}
}
Loading

0 comments on commit 2e119c8

Please sign in to comment.