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

TrafficButtonController.java « widget « traffic « maplayer « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e032ab5b74d8be38e52fe5492f71cabc55bb8ee0 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.mapswithme.maps.maplayer.traffic.widget;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.Toast;

import com.mapswithme.maps.R;
import com.mapswithme.maps.maplayer.MapLayerController;
import com.mapswithme.maps.maplayer.traffic.TrafficManager;

public class TrafficButtonController implements TrafficManager.TrafficCallback, MapLayerController
{
  @NonNull
  private final TrafficButton mButton;
  @NonNull
  private final Activity mActivity;
  @Nullable
  private Dialog mDialog;

  public TrafficButtonController(@NonNull TrafficButton button,
                                 @NonNull Activity activity)
  {
    mButton = button;
    mActivity = activity;
  }

  @Override
  public void onEnabled()
  {
    turnOn();
  }

  @Override
  public void turnOn()
  {
    mButton.turnOn();
  }

  @Override
  public void hideImmediately()
  {
    mButton.hideImmediately();
  }

  @Override
  public void adjust(int offsetX, int offsetY)
  {
    mButton.setOffset(offsetX, offsetY);
  }

  @Override
  public void attachCore()
  {
    TrafficManager.INSTANCE.attach(this);
  }

  @Override
  public void detachCore()
  {
    destroy();
  }

  @Override
  public void onDisabled()
  {
    turnOff();
  }

  @Override
  public void turnOff()
  {
    mButton.turnOff();
  }

  @Override
  public void show()
  {
    mButton.show();
  }

  @Override
  public void showImmediately()
  {
    mButton.showImmediately();
  }

  @Override
  public void hide()
  {
    mButton.hide();
  }

  @Override
  public void onWaitingData()
  {
    mButton.startWaitingAnimation();
  }

  @Override
  public void onOutdated()
  {
    mButton.markAsOutdated();
  }

  @Override
  public void onNoData()
  {
    turnOn();
    Toast.makeText(mActivity, R.string.traffic_data_unavailable, Toast.LENGTH_SHORT).show();
  }

  @Override
  public void onNetworkError()
  {
    if (mDialog != null && mDialog.isShowing())
      return;

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity)
        .setMessage(R.string.common_check_internet_connection_dialog)
        .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener()
        {
          @Override
          public void onClick(DialogInterface dialog, int which)
          {
            TrafficManager.INSTANCE.setEnabled(false);
          }
        })
        .setCancelable(true)
        .setOnCancelListener(new DialogInterface.OnCancelListener()
        {
          @Override
          public void onCancel(DialogInterface dialog)
          {
            TrafficManager.INSTANCE.setEnabled(false);
          }
        });
    mDialog = builder.show();
  }

  public void destroy()
  {
    if (mDialog != null && mDialog.isShowing())
      mDialog.cancel();
  }

  @Override
  public void onExpiredData()
  {
    turnOn();
    Toast.makeText(mActivity, R.string.traffic_update_maps_text, Toast.LENGTH_SHORT).show();
  }

  @Override
  public void onExpiredApp()
  {
    turnOn();
    Toast.makeText(mActivity, R.string.traffic_update_app, Toast.LENGTH_SHORT).show();
  }
}