summaryrefslogtreecommitdiff
path: root/app/src/androidTest/legacy/Screenshot.java
blob: ade28b73a86178c93bf5eb25922e053e97b306d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package se.leap.bitmaskclient.test;

import com.robotium.solo.*;

import java.text.*;
import java.util.*;

public class Screenshot {
    private static String default_name = Screenshot.class.getPackage().getName();
    private static DateFormat date_format = DateFormat.getDateTimeInstance();
    private static int DEFAULT_MILLISECONDS_TO_SLEEP = 500;
    private static int milliseconds_to_sleep = 0;
    private static Solo solo;

    public static void initialize(Solo solo) {
        Screenshot.solo = solo;
    }

    public static void take(String name) {
        solo.takeScreenshot(name.replace(" ", "_") + " " + getTimeStamp());
    }

    public static void takeWithSleep(String name) {
        sleepBefore();
        take(name);
    }

    public static void take() {
        take(default_name + "_" + getTimeStamp());
    }

    public static void takeWithSleep() {
        sleepBefore();
        take();
    }

    private static String getTimeStamp() {
        return date_format.format(Calendar.getInstance().getTime()).replace(" ", "_").replace("/", "_").replace(":", "_");
    }

    public static void setTimeToSleep(double seconds) {
        long milliseconds_to_sleep = Math.round(seconds * 1000);
        Screenshot.milliseconds_to_sleep = Math.round(milliseconds_to_sleep);
    }

    private static void sleepBefore() {
        if(milliseconds_to_sleep == 0)
            solo.sleep(DEFAULT_MILLISECONDS_TO_SLEEP);
        else
            solo.sleep(milliseconds_to_sleep);
        milliseconds_to_sleep = 0;
    }
}