Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LocationState.java « location « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8c6b464f3e0a9c7309a4019119fe097a6b149c0f (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
73
74
75
76
77
78
79
80
81
82
83
package com.mapswithme.maps.location;

import android.support.annotation.IntDef;
import android.support.annotation.NonNull;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public final class LocationState
{
  interface ModeChangeListener
  {
    @SuppressWarnings("unused")
    void onMyPositionModeChanged(int newMode);
  }

  interface LocationPendingTimeoutListener
  {
    @SuppressWarnings("unused")
    void onLocationPendingTimeout();
  }

  @Retention(RetentionPolicy.SOURCE)
  @IntDef({ PENDING_POSITION, NOT_FOLLOW_NO_POSITION, NOT_FOLLOW, FOLLOW, FOLLOW_AND_ROTATE})
  @interface Value {}

  // These values should correspond to location::EMyPositionMode enum (from platform/location.hpp)
  public static final int PENDING_POSITION = 0;
  public static final int NOT_FOLLOW_NO_POSITION = 1;
  public static final int NOT_FOLLOW = 2;
  public static final int FOLLOW = 3;
  public static final int FOLLOW_AND_ROTATE = 4;

  static native void nativeSwitchToNextMode();
  @Value
  static native int nativeGetMode();

  static native void nativeSetListener(ModeChangeListener listener);
  static native void nativeRemoveListener();

  static native void nativeSetLocationPendingTimeoutListener(
      @NonNull LocationPendingTimeoutListener listener);
  static native void nativeRemoveLocationPendingTimeoutListener();

  private LocationState() {}

  /**
   * Checks if location state on the map is active (so its not turned off or pending).
   */
  static boolean isTurnedOn()
  {
    return hasLocation(nativeGetMode());
  }

  static boolean hasLocation(int mode)
  {
    return (mode > NOT_FOLLOW_NO_POSITION);
  }

  static String nameOf(@Value int mode)
  {
    switch (mode)
    {
      case PENDING_POSITION:
        return "PENDING_POSITION";

      case NOT_FOLLOW_NO_POSITION:
        return "NOT_FOLLOW_NO_POSITION";

      case NOT_FOLLOW:
        return "NOT_FOLLOW";

      case FOLLOW:
        return "FOLLOW";

      case FOLLOW_AND_ROTATE:
        return "FOLLOW_AND_ROTATE";

      default:
        return "Unknown: " + mode;
    }
  }
}