Commit a852b8df authored by Lukas Fülling's avatar Lukas Fülling

make animations toggleable

parent 60cf38dd
......@@ -22,6 +22,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
......@@ -62,7 +63,6 @@ public class VaporFace extends CanvasWatchFaceService {
private static final int BOTTOM_COMPLICATION_ID = 0;
public static final int[] COMPLICATION_IDS = {BOTTOM_COMPLICATION_ID};
// Left and right dial supported types.
......@@ -87,6 +87,7 @@ public class VaporFace extends CanvasWatchFaceService {
private static final int MSG_UPDATE_TIME = 0;
public static boolean updateBackground = false;
private Typeface VAPOR_FONT;
private boolean animationsEnabled;
@Override
public Engine onCreateEngine() {
......@@ -468,11 +469,15 @@ public class VaporFace extends CanvasWatchFaceService {
canvas.drawColor(Color.BLACK);
drawAesthetic(canvas);
} else {
if (backgroundDrawable.length > 1) {
if (bgaCount >= backgroundDrawable.length) {
bgaCount = 0;
if (animationsEnabled) {
if (backgroundDrawable.length > 1) {
if (bgaCount >= backgroundDrawable.length) {
bgaCount = 0;
}
bgaCount++;
}
bgaCount++;
} else {
bgaCount = 0;
}
canvas.drawBitmap(backgroundDrawable[bgaCount], 0F, 0F, null);
......@@ -590,7 +595,9 @@ public class VaporFace extends CanvasWatchFaceService {
}
private Bitmap[] getBackgroundDrawable() {
String currentBackground = getSharedPreferences("vaporface", MODE_PRIVATE).getString("background", String.valueOf(0));
SharedPreferences preferences = getSharedPreferences("vaporface", MODE_PRIVATE);
String currentBackground = preferences.getString("background", String.valueOf(0));
animationsEnabled = preferences.getBoolean("animations_enabled", false);
Bitmap[] drawable;
int dstWidth = ((surfaceWidth != null)) ? surfaceWidth : 320;
......@@ -613,8 +620,7 @@ public class VaporFace extends CanvasWatchFaceService {
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_04_13)), dstWidth, dstHeight, false),
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_04_14)), dstWidth, dstHeight, false)
};
}
else if ("2".equals(currentBackground)) {
} else if ("2".equals(currentBackground)) {
drawable = new Bitmap[]{
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_08_01)), dstWidth, dstHeight, false),
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_08_02)), dstWidth, dstHeight, false),
......@@ -641,8 +647,7 @@ public class VaporFace extends CanvasWatchFaceService {
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_08_23)), dstWidth, dstHeight, false),
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_08_24)), dstWidth, dstHeight, false)
};
}
else if ("3".equals(currentBackground)) {
} else if ("3".equals(currentBackground)) {
drawable = new Bitmap[]{
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_10_01)), dstWidth, dstHeight, false),
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_10_02)), dstWidth, dstHeight, false),
......@@ -653,8 +658,7 @@ public class VaporFace extends CanvasWatchFaceService {
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_10_07)), dstWidth, dstHeight, false),
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_10_08)), dstWidth, dstHeight, false)
};
}
else if ("4".equals(currentBackground)) {
} else if ("4".equals(currentBackground)) {
drawable = new Bitmap[]{
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_12_01)), dstWidth, dstHeight, false),
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_12_02)), dstWidth, dstHeight, false),
......@@ -679,8 +683,7 @@ public class VaporFace extends CanvasWatchFaceService {
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_12_21)), dstWidth, dstHeight, false),
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_12_22)), dstWidth, dstHeight, false)
};
}
else if ("5".equals(currentBackground)) {
} else if ("5".equals(currentBackground)) {
drawable = new Bitmap[]{
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_15_01)), dstWidth, dstHeight, false),
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_15_02)), dstWidth, dstHeight, false),
......@@ -704,8 +707,7 @@ public class VaporFace extends CanvasWatchFaceService {
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_15_20)), dstWidth, dstHeight, false),
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_15_21)), dstWidth, dstHeight, false)
};
}
else if ("6".equals(currentBackground)) {
} else if ("6".equals(currentBackground)) {
drawable = new Bitmap[]{
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_16_01)), dstWidth, dstHeight, false),
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_16_02)), dstWidth, dstHeight, false),
......@@ -732,8 +734,7 @@ public class VaporFace extends CanvasWatchFaceService {
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_16_23)), dstWidth, dstHeight, false),
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_16_24)), dstWidth, dstHeight, false)
};
}
else if ("7".equals(currentBackground)) {
} else if ("7".equals(currentBackground)) {
drawable = new Bitmap[]{
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_20_01)), dstWidth, dstHeight, false),
Bitmap.createScaledBitmap(drawableToBitmap(getDrawable(R.drawable.bg_20_02)), dstWidth, dstHeight, false),
......
......@@ -31,6 +31,7 @@ public class VaporFaceConfigActivity extends Activity implements View.OnClickLis
private SharedPreferences preferences;
private ImageButton bgChangeRight;
private ImageButton bgChangeLeft;
private ImageButton animationToggle;
public enum ComplicationLocation {
BOTTOM
......@@ -78,6 +79,15 @@ public class VaporFaceConfigActivity extends Activity implements View.OnClickLis
setBackgroundPreview();
animationToggle = findViewById(R.id.animation_toggle);
boolean animationsEnabled = preferences.getBoolean("animations_enabled", false);
if(animationsEnabled) {
animationToggle.setImageDrawable(getDrawable(R.drawable.ic_check_box_white_24dp));
} else {
animationToggle.setImageDrawable(getDrawable(R.drawable.ic_check_box_outline_blank_white_24dp));
}
animationToggle.setOnClickListener(v -> toggleAnimationToggle());
bgChangeRight = findViewById(R.id.bgc_right);
bgChangeRight.setOnClickListener(v -> toggleNextBg());
......@@ -87,6 +97,17 @@ public class VaporFaceConfigActivity extends Activity implements View.OnClickLis
retrieveInitialComplicationsData();
}
private void toggleAnimationToggle() {
boolean previousState = preferences.getBoolean("animations_enabled", false);
preferences.edit().putBoolean("animations_enabled", !previousState).apply();
boolean animationsEnabled = preferences.getBoolean("animations_enabled", false);
if(animationsEnabled) {
animationToggle.setImageDrawable(getDrawable(R.drawable.ic_check_box_white_24dp));
} else {
animationToggle.setImageDrawable(getDrawable(R.drawable.ic_check_box_outline_blank_white_24dp));
}
}
private void togglePrevBg() {
currentBG--;
if (currentBG < 0) {
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp">
<path android:fillColor="#FFFFFF" android:pathData="M19,5v14H5V5h14m0,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2z"/>
</vector>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp">
<path android:fillColor="#FFFFFF" android:pathData="M19,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.11,0 2,-0.9 2,-2L21,5c0,-1.1 -0.89,-2 -2,-2zM10,17l-5,-5 1.41,-1.41L10,14.17l7.59,-7.59L19,8l-9,9z"/>
</vector>
......@@ -25,6 +25,25 @@
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<TextView
android:id="@+id/animation_toggle_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:textColor="#ffffff"
android:layout_centerHorizontal="true"
android:text="@string/animation_toggle"/>
<ImageButton
android:id="@+id/animation_toggle"
android:layout_below="@id/animation_toggle_text"
android:layout_marginTop="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#00000000"
android:src="@drawable/ic_check_box_outline_blank_white_24dp"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
......
......@@ -2,5 +2,6 @@
<string name="app_name">vaporface</string>
<string name="message">Watch face tapped</string>
<string name="my_digital_name">Vapor</string>
<string name="vapor_settings" translatable="false">🌴⚙️</string>
<string name="vapor_settings" translatable="false">🌴⚙</string>
<string name="animation_toggle">Animations</string>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment