Timer stopwatch based on Java Calendar class Android example
Start Stop Stopwatch Timer Android example source code.
private static long mStartTime = 0L;
Calendar cal;
TextView hTextViewVypis = (TextView)findViewById(R.id.idTextVypis);
void start(){
cal = Calendar.getInstance();
mStartTime = cal.getTimeInMillis();
}
void stop(){
prinOutStopWatchTime();
}
private void prinOutStopWatchTime() {
final long start = mStartTime;
cal = Calendar.getInstance();
long stopTime = cal.getTimeInMillis();
long millis = stopTime - start;
long milisekundy = millis % 1000;
int seconds = (int) (millis / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;
int hour = minutes / 60;
hour = hour % 60;
if (seconds < 10) {
hTextViewVypis.setText(hour + ":" + minutes + ":0" + seconds + ":" + milisekundy);
} else {
hTextViewVypis.setText(hour + ":" + minutes + ":" + seconds + ":" + milisekundy);
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
I You use offline work for better building speed of project or for other purpose
https://gradle.org/releases
Offline work:
File - Settings - Gradle
- select Use local gradle distribution
- select path Gradle home:
- check Offline work
https://gradle.org/releases
Offline work:
File - Settings - Gradle
- select Use local gradle distribution
- select path Gradle home:
- check Offline work
Table of usability phones with Android: (Our software)
Graph of usability Smartphone with Android - October 2011:
Samsung Galaxy S2 vs iPhone4 - browsing, gaming, apps, performance, browser, fast, against, navigation, Sygic, apk, Android, iOS
October 2011 | September 2011 | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
Graph of usability Smartphone with Android - October 2011:
Samsung Galaxy S2 vs iPhone4 - video
Samsung Galaxy S2 vs iPhone4 - browsing, gaming, apps, performance, browser, fast, against, navigation, Sygic, apk, Android, iOS
Dialog Yes No sample code
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit application?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MyActivity.this.finish(); //Close this Activity for example: MyActivity.java
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// some code if you want
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
Switch statement with numbers and array of strings Java example.
Possible:
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = { "One", "Two", "Three", "Four" };
int i = 2;
switch (i) {
case 1: {
System.out.println(arrayOfString[i]);
break;
}
case 2: {
System.out.println(arrayOfString[i]);
break;
}
case 3: {
System.out.println(arrayOfString[i]);
break;
}
default: {
System.out.println("Enter a valid value.");
}
} // END of switch
}
}
/*
* Three
*/
Possible:
case 1:
System.out.println(arrayOfString[i]);
break;
// i love this notation
case 1:{
System.out.println(arrayOfString[i]);
}break;
case 1:{
System.out.println(arrayOfString[i]);
break;
}
Draw the trajectory of shot.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
}
private static void makePath(Path p) {
p.moveTo(10, 0);
p.cubicTo(100, -50, 200, 150, 300, 0);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.CYAN);
Paint p = new Paint();
// smooths
p.setAntiAlias(true);
p.setColor(Color.RED);
p.setStyle(Paint.Style.STROKE);
p.setStrokeWidth(5);
// opacity
//p.setAlpha(0x80);
p.setColor(Color.BLACK);
Path mPath = new Path();
makePath(mPath);
canvas.drawPath(mPath, p); //(rectF, 90, 45, true, p);
}
}
}
Editace: 2011-09-26 14:48:31
Počet článků v kategorii: 396
Url:timer-stopwatch-java-calendar-android-example