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

CountryTree.cpp « country « mapswithme « com « jni « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e78cad39b14b14c1cd34ed4bea2965c8c14dbf3f (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <jni.h>

#include "../maps/Framework.hpp"
#include "../core/jni_helper.hpp"
#include "country_helper.hpp"

using namespace storage_utils;
using namespace storage;

extern "C"
{
  JNIEXPORT void JNICALL
  Java_com_mapswithme_country_CountryTree_setDefaultRoot(JNIEnv * env, jclass clazz)
  {
    GetTree().SetDefaultRoot();
  }

  JNIEXPORT void JNICALL
  Java_com_mapswithme_country_CountryTree_setParentAsRoot(JNIEnv * env, jclass clazz)
  {
    GetTree().SetParentAsRoot();
  }

  JNIEXPORT void JNICALL
  Java_com_mapswithme_country_CountryTree_setChildAsRoot(JNIEnv * env, jclass clazz, jint position)
  {
    GetTree().SetChildAsRoot(position);
  }

  JNIEXPORT void JNICALL
  Java_com_mapswithme_country_CountryTree_resetRoot(JNIEnv * env, jclass clazz)
  {
    GetTree().ResetRoot();
  }

  JNIEXPORT jboolean JNICALL
  Java_com_mapswithme_country_CountryTree_hasParent(JNIEnv * env, jclass clazz)
  {
    return GetTree().HasParent();
  }

  JNIEXPORT jint JNICALL
  Java_com_mapswithme_country_CountryTree_getChildCount(JNIEnv * env, jclass clazz)
  {
    return GetTree().GetChildCount();
  }

  JNIEXPORT jobject JNICALL
  Java_com_mapswithme_country_CountryTree_getChildItem(JNIEnv * env, jclass clazz, jint position)
  {
    CountryTree & tree = GetTree();
    int corePosition = static_cast<int>(position);
    bool const isLeaf = tree.IsLeaf(corePosition);
    jstring name = jni::ToJavaString(env, tree.GetChildName(corePosition));
    jint status = isLeaf ? static_cast<jint>(tree.GetLeafStatus(corePosition)) : 0;
    jint options = isLeaf ? static_cast<jint>(tree.GetLeafOptions(corePosition)) : 0;

    jclass createClass = env->FindClass("com/mapswithme/country/CountryItem");
    ASSERT(createClass, ());

    jmethodID createMethodId = env->GetMethodID(createClass, "<init>", "(Ljava/lang/String;IIZ)V");
    ASSERT(createMethodId, ());

    return env->NewObject(createClass, createMethodId,
                          name, status, options, (!isLeaf) == true ? JNI_TRUE : JNI_FALSE);
  }

  JNIEXPORT void JNICALL
  Java_com_mapswithme_country_CountryTree_downloadCountry(JNIEnv * env, jclass clazz, jint position, jint options)
  {
    GetTree().DownloadCountry(position, ToOptions(options));
  }

  JNIEXPORT void JNICALL
  Java_com_mapswithme_country_CountryTree_deleteCountry(JNIEnv * env, jclass clazz, jint position, jint options)
  {
    GetTree().DeleteCountry(position, ToOptions(options));
  }

  JNIEXPORT void JNICALL
  Java_com_mapswithme_country_CountryTree_cancelDownloading(JNIEnv * env, jclass clazz, jint position)
  {
    GetTree().CancelDownloading(position);
  }

  JNIEXPORT void JNICALL
  Java_com_mapswithme_country_CountryTree_retryDownloading(JNIEnv * env, jclass clazz, jint position)
  {
    GetTree().RetryDownloading(position);
  }

  JNIEXPORT void JNICALL
  Java_com_mapswithme_country_CountryTree_showLeafOnMap(JNIEnv * env, jclass clazz, jint position)
  {
    GetTree().ShowLeafOnMap(position);
    g_framework->DontLoadState();
  }

  JNIEXPORT jlong JNICALL
  Java_com_mapswithme_country_CountryTree_getLeafSize(JNIEnv * env, jclass clazz, jint position, jint options, jboolean isLocal)
  {
    CountryTree & tree = GetTree();
    int pos = static_cast<int>(position);
    bool const local = (isLocal == JNI_TRUE) ? true : false;
    MapOptions opt = ToOptions(options);

    if (options == -1 || local)
    {
      LocalAndRemoteSizeT sizes = options == -1 ? tree.GetDownloadableLeafSize(pos) : tree.GetLeafSize(pos, opt);
      return local ? sizes.first : sizes.second;
    }

    LocalAndRemoteSizeT sizes = tree.GetRemoteLeafSizes(pos);
    switch (opt)
    {
      case MapOptions::Map:
        return sizes.first;
      case MapOptions::CarRouting:
        return sizes.second;
      default:
        return sizes.first + sizes.second;
    }
  }

  JNIEXPORT void JNICALL
  Java_com_mapswithme_country_CountryTree_setListener(JNIEnv * env, jclass clazz, jobject listener)
  {
    g_framework->SetCountryTreeListener(jni::make_global_ref(listener));
  }

  JNIEXPORT void JNICALL
  Java_com_mapswithme_country_CountryTree_resetListener(JNIEnv * env, jclass clazz, jobject listener)
  {
    g_framework->ResetCountryTreeListener();
  }
}