Skip to content

Commit

Permalink
Stop drawing when paused
Browse files Browse the repository at this point in the history
Because the (drawing) surface isn't destroyed when the activity
is paused.
  • Loading branch information
markusfisch committed Jul 18, 2020
1 parent 433adfe commit 7183184
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ public void onClick(View v) {
public void onResume() {
super.onResume();
queryThemesAsync();
themesView.startDrawing();
}

@Override
public void onPause() {
super.onPause();
themesView.closeCursor();
themesView.stopDrawing();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void run() {
private int currentIndex;
private int idColumn;
private int pointerId;
private boolean initialized = false;
private boolean swiping = false;
private boolean drawing = false;
private float swipeThreshold;
Expand Down Expand Up @@ -97,6 +98,20 @@ public ThemesView(
initView(context);
}

public void startDrawing() {
if (initialized && !drawing) {
drawing = true;
postDelayed(drawRunnable, 16L);
}
}

public void stopDrawing() {
if (drawing) {
drawing = false;
removeCallbacks(drawRunnable);
}
}

public void closeCursor() {
if (cursor != null) {
cursor.close();
Expand Down Expand Up @@ -237,8 +252,8 @@ public void surfaceChanged(
int width,
int height) {
renderer.setSize(width, height);
drawing = true;
postDelayed(drawRunnable, 16L);
initialized = true;
startDrawing();
}

@Override
Expand All @@ -247,8 +262,7 @@ public void surfaceCreated(SurfaceHolder holder) {

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
drawing = false;
removeCallbacks(drawRunnable);
stopDrawing();
}
});
}
Expand Down

0 comments on commit 7183184

Please sign in to comment.