aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java
blob: a388adbc5abc74996f5e383e1112b9a7e454d5ee (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
package cgeo.geocaching.compatibility;

import cgeo.geocaching.utils.Log;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.backup.BackupManager;
import android.view.Display;
import android.view.Surface;

@TargetApi(8)
public class AndroidLevel8 implements AndroidLevel8Interface {

    @Override
    public int getRotation(final Activity activity) {
        Display display = activity.getWindowManager().getDefaultDisplay();
        return display.getRotation();
    }

    @Override
    public void dataChanged(final String name) {
        Log.i("Requesting settings backup with settings manager");
        BackupManager.dataChanged(name);
    }

    @Override
    public int getRotationOffset(final Activity activity) {
        try {
            final int rotation = getRotation(activity);
            if (rotation == Surface.ROTATION_90) {
                return 90;
            } else if (rotation == Surface.ROTATION_180) {
                return 180;
            } else if (rotation == Surface.ROTATION_270) {
                return 270;
            }
        } catch (final Exception e) {
            // This should never happen: IllegalArgumentException, IllegalAccessException or InvocationTargetException
            Log.e("Cannot call getRotation()", e);
        }

        return 0;
    }
}