Skip to content

feat: added emoji rendering #1200 #1213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: flutter_app
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
351 changes: 282 additions & 69 deletions lib/bademagic_module/utils/converters.dart

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions lib/badge_animation/ani_fixed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ import 'package:badgemagic/badge_animation/animation_abstract.dart';

class FixedAnimation extends BadgeAnimation {
@override
void processAnimation(int badgeHeight, int badgeWidth, int animationIndex,
List<List<bool>> processGrid, List<List<bool>> canvas) {
void processAnimation(
int badgeHeight,
int badgeWidth,
int animationIndex,
List<List<bool>> processGrid,
List<List<bool>> canvas,
) {
int newWidth = processGrid[0].length;
int horizontalOffset = (badgeWidth - newWidth) ~/ 2;
int rowLimit =
badgeHeight < processGrid.length ? badgeHeight : processGrid.length;

for (int i = 0; i < badgeHeight; i++) {
for (int i = 0; i < rowLimit; i++) {
for (int j = 0; j < badgeWidth; j++) {
int sourceCol = j - horizontalOffset;
bool isWithinNewGrid = sourceCol >= 0 && sourceCol < newWidth;
Expand Down
46 changes: 19 additions & 27 deletions lib/providers/animation_badge_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,13 @@ class AnimationBadgeProvider extends ChangeNotifier {
int _animationIndex = 0;
int _animationSpeed = aniSpeedStrategy(0);
Timer? _timer;

//List that contains the state of each cell of the badge for home view
List<List<bool>> _paintGrid =
List.generate(11, (i) => List.generate(44, (j) => false));
List.generate(16, (i) => List.generate(45, (j) => false));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing the badge size?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardware badge is 11x44


BadgeAnimation _currentAnimation = LeftAnimation();

final Set<BadgeEffect?> _currentEffect = {};

//function to get the state of the cell
List<List<bool>> getPaintGrid() => _paintGrid;

//function to calculate duration for the animation
void calculateDuration(int speed) {
int newSpeed = aniSpeedStrategy(speed - 1);
if (newSpeed != _animationSpeed) {
Expand All @@ -65,12 +59,9 @@ class AnimationBadgeProvider extends ChangeNotifier {
}

List<List<bool>> _newGrid =
List.generate(11, (i) => List.generate(44, (j) => false));

//getter for newGrid
List.generate(16, (i) => List.generate(45, (j) => false));
List<List<bool>> getNewGrid() => _newGrid;

//setter for newGrid
void setNewGrid(List<List<bool>> grid) {
_newGrid = grid;
_animationIndex = 0;
Expand Down Expand Up @@ -100,7 +91,6 @@ class AnimationBadgeProvider extends ChangeNotifier {
}
}

//function to stop timer and reset the animationIndex
void stopAnimation() {
logger.d("Timer stopped ${_timer?.tick.toString()}");
_timer?.cancel();
Expand All @@ -109,20 +99,16 @@ class AnimationBadgeProvider extends ChangeNotifier {
}

void stopAllAnimations() {
// Stop any ongoing timer and reset the animation index
stopAnimation();
_currentAnimation = LeftAnimation();
// Reset the grids to all false values
_paintGrid = List.generate(11, (i) => List.generate(44, (j) => false));
_newGrid = List.generate(11, (i) => List.generate(44, (j) => false));
_paintGrid = List.generate(16, (i) => List.generate(45, (j) => false));
_newGrid = List.generate(16, (i) => List.generate(45, (j) => false));
logger.d("All animations stopped");
}

void startTimer() {
_timer =
Timer.periodic(Duration(microseconds: _animationSpeed), (Timer timer) {
// logger.i(
// "New Grid set to: ${getNewGrid().map((e) => e.map((e) => e ? 1 : 0).toList()).toList()}");
renderGrid(getNewGrid());
_animationIndex++;
});
Expand Down Expand Up @@ -150,18 +136,24 @@ class AnimationBadgeProvider extends ChangeNotifier {
return isActive;
}

void badgeAnimation(
String message, Converters converters, bool isInverted) async {
if (message == "") {
//geerate a 2d list with all values as 0
void badgeAnimation(String message, Converters converters, bool isInverted,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Review the default TextStyle fallback in badgeAnimation.

The current fallback uses 'TextStyle(fontSize: 11, color: Colors.black)'. Ensure that this default aligns with overall design expectations or consider defining it as a class-level constant.

Suggested implementation:

class AnimationBadgeProvider extends ChangeNotifier {
  static const TextStyle defaultTextStyle = TextStyle(fontSize: 11, color: Colors.black);

  void badgeAnimation(String message, Converters converters, bool isInverted,
      {TextStyle? textStyle}
      ) async {
    if (message.isEmpty) {
      List<List<bool>> image =
          List.generate(16, (i) => List.generate(45, (j) => false));
      setNewGrid(image);
    } else {
      final effectiveTextStyle = textStyle ?? defaultTextStyle;

Please ensure that the rest of the badgeAnimation function uses effectiveTextStyle where a TextStyle is needed.

{TextStyle? textStyle}) async {
if (message.isEmpty) {
List<List<bool>> image =
List.generate(11, (i) => List.generate(44, (j) => false));
List.generate(16, (i) => List.generate(45, (j) => false));
setNewGrid(image);
} else {
List<String> hexString =
await converters.messageTohex(message, isInverted);
List<List<bool>> binaryArray = hexStringToBool(hexString.join());
setNewGrid(binaryArray);
try {
List<List<bool>> matrix = await converters.renderTextToMatrix(
message,
textStyle ?? TextStyle(fontSize: 11, color: Colors.black),
);

List<List<bool>> binaryArray = matrix;
setNewGrid(binaryArray);
} catch (e) {
logger.e("Error rendering text to matrix: $e");
}
}
}

Expand Down
Loading
Loading