add_rotate_watchface_button_hybridhr #2408

Merged
ashimokawa merged 4 commits from HelloCodeberg/Gadgetbridge:add_rotate_watchface_button_hybridhr into master 2 months ago
  1. 15
      app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceDesignerActivity.java
  2. 13
      app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/BitmapUtil.java
  3. 26
      app/src/main/res/layout/activity_hybridhr_watchface_designer.xml

15
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceDesignerActivity.java

@ -155,6 +155,9 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
findViewById(R.id.button_set_background).setOnClickListener(this);
findViewById(R.id.button_add_widget).setOnClickListener(this);
findViewById(R.id.button_watchface_settings).setOnClickListener(this);
findViewById(R.id.watchface_rotate_left).setOnClickListener(this);
findViewById(R.id.watchface_rotate_right).setOnClickListener(this);
}
@Override
@ -236,6 +239,18 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
} else if (v.getId() == R.id.button_watchface_settings) {
showWatchfaceSettingsPopup();
}
else if (v.getId() == R.id.watchface_rotate_left) {
if (selectedBackgroundImage != null) {
selectedBackgroundImage = BitmapUtil.rotateImage(selectedBackgroundImage, -90);
renderWatchfacePreview();
}
}
else if (v.getId() == R.id.watchface_rotate_right) {
if (selectedBackgroundImage != null) {
selectedBackgroundImage = BitmapUtil.rotateImage(selectedBackgroundImage, 90);
renderWatchfacePreview();
}
}
}
@Override

13
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/BitmapUtil.java

@ -21,6 +21,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
@ -177,4 +178,16 @@ public class BitmapUtil {
// Return the circular bitmap
return dstBitmap;
}
/**
* Rotates a given Bitmap
* @param bitmap input bitmap
* @param degree int Degree of rotation
* @return new bitmap
*/
public static Bitmap rotateImage(Bitmap bitmap, int degree) {
Matrix matrix = new Matrix();
matrix.postRotate(degree);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
}

26
app/src/main/res/layout/activity_hybridhr_watchface_designer.xml

@ -42,17 +42,37 @@
android:text="@string/button_watchface_edit_name" />
</RelativeLayout>
<RelativeLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/watchface_invert_colors"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignStart="@+id/watchface_preview_layout"
app:srcCompat="@drawable/ic_invert_colors" />
<ImageView
android:id="@+id/watchface_rotate_left"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignStart="@+id/watchface_invert_colors"
app:srcCompat="@drawable/ic_rotate_left" />
<ImageView
android:id="@+id/watchface_rotate_right"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignStart="@+id/watchface_rotate_left"
android:rotationY="180"
app:srcCompat="@drawable/ic_rotate_left" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/watchface_preview_layout"
android:layout_width="match_parent"

Loading…
Cancel
Save