-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating hello-jnicallback to support large screen devices
Timer does not restart on configuration changes and utilizes a ViewModel to preserve state. Button added to start and stop. Small naming convention fix with stopTimer
- Loading branch information
Showing
5 changed files
with
118 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
hello-jniCallback/app/src/main/java/com/example/hellojnicallback/MainViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.example.hellojnicallback; | ||
|
||
import androidx.lifecycle.ViewModel; | ||
|
||
public class MainViewModel extends ViewModel { | ||
private int hour = 0; | ||
private int minute = 0; | ||
private int second = 0; | ||
public boolean started = false; | ||
public boolean running = false; | ||
|
||
public void updateTimer() { | ||
++second; | ||
if(second >= 60) { | ||
++minute; | ||
second -= 60; | ||
if(minute >= 60) { | ||
++hour; | ||
minute -= 60; | ||
} | ||
} | ||
} | ||
|
||
public void resetTimer() { | ||
hour = minute = second = 0; | ||
} | ||
|
||
public String time() { | ||
return hour + ":" + minute + ":" + second; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<resources> | ||
<string name="app_name">Hello-jniCallback</string> | ||
<string name="pause">PAUSE</string> | ||
<string name="resume">RESUME</string> | ||
</resources> |