aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/compatibility/Compatibility.java
blob: 2f9491518569d9c82dcf83a929ff447149d9239e (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package cgeo.geocaching.compatibility;

import android.app.Activity;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.view.Display;
import android.view.Surface;

public final class Compatibility {

    private static AndroidLevel8 level8;
    private static boolean initialized = false;

    private static AndroidLevel8 getLevel8() {
        if (!initialized) {
            try {
                final int sdk = Integer.valueOf(Build.VERSION.SDK).intValue();
                if (sdk >= 8) {
                    level8 = new AndroidLevel8();
                }
            } catch (Exception e) {
                // nothing
            }
            initialized = true;
        }
        return level8;
    }

    public static Float getDirectionNow(final Float directionNowPre,
            final Activity activity) {
        AndroidLevel8 level8 = getLevel8();

        if (level8 != null) {
            final int rotation = level8.getRotation(activity);
            if (rotation == Surface.ROTATION_90) {
                return directionNowPre + 90;
            } else if (rotation == Surface.ROTATION_180) {
                return directionNowPre + 180;
            } else if (rotation == Surface.ROTATION_270) {
                return directionNowPre + 270;
            }
        } else {
            final Display display = activity.getWindowManager()
                    .getDefaultDisplay();
            final int rotation = display.getOrientation();
            if (rotation == Configuration.ORIENTATION_LANDSCAPE) {
                return directionNowPre + 90;
            }
        }
        return directionNowPre;
    }

    public static Uri getCalendarProviderURI() {
        final int sdk = Integer.valueOf(Build.VERSION.SDK).intValue();
        if (sdk >= 8) {
            return Uri.parse("content://com.android.calendar/calendars");
        } else {
            return Uri.parse("content://calendar/calendars");
        }
    }

    public static Uri getCalenderEventsProviderURI() {
        final int sdk = Integer.valueOf(Build.VERSION.SDK).intValue();
        if (sdk >= 8) {
            return Uri.parse("content://com.android.calendar/events");
        } else {
            return Uri.parse("content://calendar/events");
        }
    }

}