IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants FMX Delphi Discussion :

[XE5] Utilisation de addGpsStatusListener


Sujet :

Composants FMX Delphi

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Août 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 59
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Août 2014
    Messages : 4
    Points : 1
    Points
    1
    Par défaut [XE5] Utilisation de addGpsStatusListener
    Bonjour,
    ça fait 3 jours que je sèche sur l'utilisation de addGpsStatusListener.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    unit Unit1;
    
    interface
    
    uses
      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
      FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts,
      FMX.Memo, FMX.TabControl, FMX.StdCtrls, FMX.ListBox, FMX.WebBrowser, FMX.Edit,
      Posix.Unistd {pour deletefile},
    
    {pour le GPS : }
      FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText,Androidapi.JNI.Os,
      Androidapi.JNI.Location, Androidapi.JNIBridge, Androidapi.JNI.JavaTypes,
      Androidapi.JNI.Provider {pour appel Parametres/Localisation};
    
    type
      TForm1 = class(TForm)
        TabControl1: TTabControl;
        TabItemGPS: TTabItem;
        TabItemCarte: TTabItem;
        TabItemHisto: TTabItem;
        MemoHisto: TMemo;
        ListBox1: TListBox;
        ListBoxHeader1: TListBoxHeader;
        ListBoxGroupHeader1: TListBoxGroupHeader;
        ListBoxLat: TListBoxItem;
        ListBoxLon: TListBoxItem;
        ListBoxAlt: TListBoxItem;
        ListBoxPrc: TListBoxItem;
        ListBoxGroupHeader2: TListBoxGroupHeader;
        ListBoxNum: TListBoxItem;
        ListBoxRue: TListBoxItem;
        ListBoxPtl: TListBoxItem;
        ListBoxVil: TListBoxItem;
        ListBoxPay: TListBoxItem;
        ListBoxCdP: TListBoxItem;
        Label1: TLabel;
        WebBrowser1: TWebBrowser;
        Zoom: TTrackBar;
        ToolBar1: TToolBar;
        LabelZoom: TLabel;
        ButtonClb: TButton;
        TypeCarte: TComboBox;
        GoogleMap: TListBoxItem;
        roadmap: TListBoxItem;
        satellite: TListBoxItem;
        hybrid: TListBoxItem;
        terrain: TListBoxItem;
        openstreetmap: TListBoxItem;
    
        procedure FormCreate(Sender: TObject);
        procedure onLocationChanged(location: JLocation);
        procedure FaitCarte;
        procedure FaitCarte1;
        procedure FaitCarte2;
        procedure FaitCarte3;
        procedure onChangeZoom(Sender: TObject);
        procedure TypeCarteChange(Sender: TObject);
        procedure ButtonClbClick(Sender: TObject);
        procedure ParametresLocalisation(Sender: TObject);
        procedure TabControl1Resize(Sender: TObject);
        procedure TabItemCarteClick(Sender: TObject);
        procedure ListBoxLatClick(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
    
      private
        FLocationManager : JLocationManager;
        FGeocoder: JGeocoder;
        Address : Jaddress;
        AddressList : JList;
      public
        { Déclarations publiques }
      end;
    
      TLocationListener = class(TJavaLocal, JLocationListener)
      private
        Fparent : TForm1;
      public
        constructor Create(AParent: TForm1);
        procedure onLocationChanged(location: JLocation); cdecl;
        procedure onProviderDisabled(provider: JString); cdecl;
        procedure onProviderEnabled(provider: JString); cdecl;
        procedure onStatusChanged(provider: JString; status: Integer; extras: JBundle); cdecl;
      end;
    
      TGpsListener = class (TJavaLocal, JGpsStatus_Listener)
      private
        Fparent : TForm1;
      public
        constructor Create(AParent: TForm1);
        procedure onGpsStatusChanged(event: integer); cdecl;
      end;
    
    var
      Form1: TForm1;
      locationListener : TLocationListener;
      GPSListener : TGpsListener;
      TestB : boolean = False;
    
    implementation
    
    {$R *.fmx}
    
    // GPS --------------------------------------------------------------------------------------
    constructor TGpsListener.Create(AParent: TForm1);
    begin
      inherited Create;
      FParent := AParent;
    end;
    
    procedure TGpsListener.onGPSStatusChanged(event: integer);
    begin
      if TestB then FParent.MemoHisto.Lines.Add('onGPSStatusChanged event = ' + IntToStr(event));    //     <----  ne passe jamais ici
    end;
    
    constructor TLocationListener.Create(AParent: TForm1);
    begin
      inherited Create;
      FParent := AParent;
    end;
    
    procedure TLocationListener.onLocationChanged(location: JLocation);
    begin
      FParent.onLocationChanged(location);
    end;
    
    procedure TLocationListener.onProviderDisabled(provider: JString);
    begin
      if TestB then
        FParent.MemoHisto.Lines.Add('Fournisseur ' +
                                    JStringToString(provider) +
                                    ' désactivé par l''utilisateur');
    end;
    
    procedure TLocationListener.onProviderEnabled(provider: JString);
    begin
      if TestB then
        FParent.MemoHisto.Lines.Add('Fournisseur ' +
                                    JStringToString(provider) +
                                    ' activé par l''utilisateur');
    end;
    
    procedure TLocationListener.onStatusChanged(provider: JString;
                                                status: Integer;
                                                extras: JBundle);
    begin
      if TestB then case status of
        0 : FParent.MemoHisto.Lines.Add('Fournisseur ' +
                                        JStringToString(provider) +
                                        ' hors service et ne devrait pas changer dans un avenir proche');
        1 : FParent.MemoHisto.Lines.Add('Fournisseur ' +
                                        JStringToString(provider) +
                                        ' temporairement indisponible mais disponible sous peu');
        2 : FParent.MemoHisto.Lines.Add('Fournisseur ' +
                                        JStringToString(provider) +
                                        ' actuellement disponible');
      end;
    end;
    
    procedure TForm1.onLocationChanged(location: JLocation);
    var
      LSettings: TFormatSettings;
      LDecSeparator : Char;
    begin
      if Assigned(location) then
      begin
        LDecSeparator := FormatSettings.DecimalSeparator;
        LSettings := FormatSettings;
    
        try
          FormatSettings.DecimalSeparator := '.';
          ListBoxLat.ItemData.Detail := FormatFloat('##0.0#####',location.getLatitude);
          ListBoxLon.ItemData.Detail := FormatFloat('##0.0#####',location.getLongitude);
          ListBoxAlt.ItemData.Detail := FormatFloat('####0.0## m',location.getAltitude);
          ListBoxPrc.ItemData.Detail := location.getAccuracy.ToString + ' m';
          //FaitCarte;  deplacé dans TabItemCarteClick
        finally
          FormatSettings.DecimalSeparator := LDecSeparator;
        end;
    
        if not Assigned(FGeocoder) then FGeocoder := TJGeocoder.JavaClass.init(SharedActivityContext);
        if Assigned(FGeocoder) then
        begin
          AddressList := Fgeocoder.getFromLocation(location.getLatitude, location.getLongitude, 1);
          if AddressList.size>0 then
          begin
            Address := TJAddress.Wrap((AddressList.get(0) as ILocalObject).GetObjectID);
            if Assigned(Address) then
            begin
                ListBoxNum.ItemData.Detail := JStringToString(Address.getSubThoroughfare);
                ListBoxRue.ItemData.Detail := JStringToString(Address.getThoroughfare);
                ListBoxPtl.ItemData.Detail := JStringToString(Address.getPostalCode);
                ListBoxVil.ItemData.Detail := JStringToString(Address.getLocality);
                ListBoxPay.ItemData.Detail := JStringToString(Address.getCountryName);
                ListBoxCdP.ItemData.Detail := JStringToString(Address.getCountryCode);
            end;
          end;
        end;
      end;
    end;
    
    //------------------------------------------------------------------------------------------------------------
    
    procedure TForm1.ButtonClbClick(Sender: TObject);
    begin
      if ListBoxLat.ItemData.Detail<>'' then
      with TMemo.Create(Self) do
      begin
        Visible:=False;
        Lines.Clear;
        Lines.Add(ListBoxNum.ItemData.Detail + ' ' + ListBoxRue.ItemData.Detail);
        Lines.Add(ListBoxPtl.ItemData.Detail + ' ' + ListBoxVil.ItemData.Detail);
        Lines.Add(ListBoxPay.ItemData.Detail);
        SelectAll;
        CopyToClipboard;
        Free;
      end;
    end;
    
    procedure TForm1.ListBoxLatClick(Sender: TObject);
    begin
      if ListBoxLat.ItemData.Detail<>'' then
      with TMemo.Create(Self) do
      begin
        Visible:=False;
        Lines.Clear;
        Lines.Add(ListBoxLat.ItemData.Detail + ',' + ListBoxLon.ItemData.Detail);
        SelectAll;
        CopyToClipboard;
        Free;
      end;
    end;
    
    procedure TForm1.onChangeZoom(Sender: TObject);
    begin
      LabelZoom.Text:=Format('%2.0f', [Zoom.Value]);
      FaitCarte;
    end;
    
    procedure TForm1.TabControl1Resize(Sender: TObject);
    begin
      Zoom.Width := Trunc(TabControl1.Width / 2);
    end;
    
    procedure TForm1.TabItemCarteClick(Sender: TObject);
    begin
      FaitCarte;
    end;
    
    procedure TForm1.TypeCarteChange(Sender: TObject);
    begin
      FaitCarte;
    end;
    
    procedure TForm1.FaitCarte;
    begin
      case TypeCarte.ItemIndex  of
        0..3: begin
                Zoom.Visible := true;
                LabelZoom.Visible := true;
                FaitCarte1;
              end;
        4:    begin
                Zoom.Visible := false;
                LabelZoom.Visible := false;
                FaitCarte2;
              end;
        5:    begin
                Zoom.Visible := false;
                LabelZoom.Visible := false;
                FaitCarte3;
              end;
      end;
    end;
    
    procedure TForm1.FaitCarte1;
    var
      URLString: String;
    begin
      if ListBoxLat.ItemData.Detail<>'' then
    ...
    end;
    
    procedure TForm1.FaitCarte2;
    begin
      WebBrowser1.Navigate('about:blank');  //au cas où le fichier soit tenu par WebBrowser1
      deletefile('file:///sdcard/Download/test.htm');
      if ListBoxLat.ItemData.Detail<>'' then
      begin
        with TMemo.Create(Self) do
        begin
          Visible:=False;
          Lines.Clear;
          Lines.Add('<!DOCTYPE html>');
          Lines.Add('<html>');
    ...
          Lines.Add('</html>');
    
          Lines.SaveToFile('/sdcard/Download/test.htm');
          Free;
        end;
        WebBrowser1.Navigate('file:///sdcard/Download/test.htm');
      end;
    end;
    
    procedure TForm1.FaitCarte3;
    begin
      WebBrowser1.Navigate('about:blank');  //au cas où le fichier soit tenu par WebBrowser1
      deletefile('file:///sdcard/Download/test.htm');
      if ListBoxLat.ItemData.Detail<>'' then
      begin
        with TMemo.Create(Self) do
        begin
          Visible:=False;
          Lines.Clear;
          Lines.Add('<!DOCTYPE html>');
          Lines.Add('<html>');
    ...
          Lines.Add('</html>');
    
          Lines.SaveToFile('/sdcard/Download/test.htm');
          Free;
        end;
        WebBrowser1.Navigate('file:///sdcard/Download/test.htm');
      end;
    end;
    
    procedure TForm1.ParametresLocalisation(Sender: TObject);
    var
       poke : JIntent;
    begin
      poke := TJIntent.JavaClass.init(TJSettings.JavaClass.ACTION_LOCATION_SOURCE_SETTINGS);
      poke.addCategory(TJIntent.JavaClass.CATEGORY_DEFAULT);
      poke.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK or
                    TJIntent.JavaClass.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    
      poke.setComponent(TJComponentName.JavaClass.init(StringToJString('com.android.settings'),
                        StringToJString('com.android.settings.Settings$LocationSettingsActivity')));
      SharedActivityContext.startActivity(poke);
    end;
    
    
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      WebBrowser1.Navigate('about:blank');  //au cas où le fichier soit tenu par WebBrowser1
      deletefile('file:///sdcard/Download/test.htm');
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    var
      LocationManagerService : JObject;
      iter : JIterator;
      location : JLocation;
    
    begin
      Zoom.Width := Trunc(ToolBar1.Width / 2);
      LabelZoom.Text:=Format('%2.0f', [Zoom.Value]);
      if not Assigned(FLocationManager) then
      begin
          LocationManagerService := SharedActivityContext.getSystemService(TJcontext.JavaClass.LOCATION_SERVICE);
          FLocationManager := TJLocationManager.Wrap((LocationManagerService as ILocalObject).GetObjectID);
          if not Assigned(LocationListener) then LocationListener := TLocationListener.Create(self);
          FLocationManager.requestLocationUpdates(TJLocationManager.JavaClass.GPS_PROVIDER,
                                                  10000,    {delais ms}
                                                  10,       {distance m}
                                                  LocationListener,
                                                  TJLooper.JavaClass.getMainLooper);
      end;
    
      iter := FLocationManager.GetAllProviders.Iterator;
    
      MemoHisto.Lines.Clear;
      MemoHisto.Lines.Add('GetAllProviders :');
      while iter.hasNext do MemoHisto.Lines.Add(JStringToString(iter.next.ToString));
      MemoHisto.Lines.Add('');
    
      if NOT FLocationManager.IsProviderEnabled(TJLocationManager.JavaClass.GPS_PROVIDER) then
      case MessageDlg('Veuillez activer le GPS',
                      System.UITypes.TMsgDlgType.mtInformation,
                     [System.UITypes.TMsgDlgBtn.mbYes,
                      System.UITypes.TMsgDlgBtn.mbCancel],
                      0) of
        mrYES:    ParametresLocalisation(Sender){appel menu Parametres/Localisation};
        mrCancel: Halt;
      end;
    
      MemoHisto.Lines.Add('IsProviderEnabled :');
    
      if FLocationManager.IsProviderEnabled(TJLocationManager.JavaClass.GPS_PROVIDER) then
          MemoHisto.Lines.Add('GPS_PROVIDER');
      if FLocationManager.IsProviderEnabled(TJLocationManager.JavaClass.PASSIVE_PROVIDER) then
          MemoHisto.Lines.Add('PASSIVE_PROVIDER');
      if FLocationManager.IsProviderEnabled(TJLocationManager.JavaClass.NETWORK_PROVIDER) then
          MemoHisto.Lines.Add('NETWORK_PROVIDER');
    
      MemoHisto.Lines.Add('');
    
      location := FLocationManager.getLastKnownLocation(TJLocationManager.JavaClass.GPS_PROVIDER);
    
      if not Assigned(GPSListener) then GPSListener := TGpsListener.Create(self);
    
      try
        if FLocationManager.addGpsStatusListener(GPSListener) then MemoHisto.Lines.Add('addGpsStatusListener OK');
      except
        on E: Exception do
        begin
          MemoHisto.Lines.Add('addGpsStatusListener NOK :' + #13#10 + E.Message);  //message : "java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()"
          MemoHisto.Lines.Add('');
        end;
      end;
      TestB := True;
    end;
    
    end.
    Il y a quelque chose que je fais mal ? Rien trouvé sur internet pour Delphi XE5.

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    Ce n'est peut-être pas à proprement parler un problème FMX

    Cordialement. Gilles

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Août 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 59
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Août 2014
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    Merci Gilles mais c'est mon 1er programme android et je n'arrive pas a traduire le source java du lien que vous m'avez proposé en Delphi.

    Cdlt Pascal

  4. #4
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    Un élément de réponse pourrait être "It seems that I needed to call LocationManager.addGpsStatusListener(...) from the main thread. ".
    Je ne peux pas aller plus loin. Je n'ai pas de FMX d'installé. Il faudrait que je télécharge la Delphi XE6 Trial... Je crois que mon dernier essai était la 5. Mais il faut que je libère mon PC à "formatage usine" pour le remettre en quelques minutes dans son état d'origine et il est actuellement occupé par des tests de compilations de Qt sous Mingw-w64.... L'installation de Delphi XE crée un tel foutoir sur mes postes que j'utilise un poste à part. L'installation encore n'est rien mais c'est la désinstallation qui est en cause ! J'aimerais que le disque dur retrouve son état d'origine (hormis la clef qui indique que la version a été installée) et ce n'est pas le cas...
    Reste évidemment l'achat de Delphi... Mais de mon côté, cette option ne sera pas, tant que ces braves gens ne proposeront pas un développement Linux-Desktop.

    Cordialement. Gilles

  5. #5
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Août 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 59
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Août 2014
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    Bonjour,
    après 4 mois, je n'ai toujours pas réussi.
    Si quelqu'un avait la solution...

    Merci

  6. #6
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    je dispose désormais d'un Delphi XE7..., d'un petit peu de temps et de curiosité. Mais le développement sur cette plate-forme avec Delphi XE7 n'est pas une "spécialité"... Il y a moyen d'avoir le fmx de unit1 (éventuellement son vlb si vous utilisez le LiveBinding) ?

  7. #7
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Août 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 59
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Août 2014
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    bonjour Gilles,
    le code a légèrement changé.

    Unit1.pas :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    unit Unit1;
     
    interface
     
    uses
      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
      FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts,
      FMX.Memo, FMX.TabControl, FMX.StdCtrls, FMX.ListBox, FMX.WebBrowser, FMX.Edit,
     
      Androidapi.JNI.Toast {pour Toast},
      NetworkState {pour TNetworkState (activer acceder etat reseau et etat wifi)},
      System.IOUtils {pour TPath},
      Androidapi.JNI.Provider {pour appel Parametres/Localisation},
     
    {pour FormKeyUp (3): }
      FMX.VirtualKeyboard, FMX.Platform, FMX.Platform.Android,
     
    {pour le GPS (6): }
      FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.Os,
      Androidapi.JNI.Location, Androidapi.JNIBridge, Androidapi.JNI.JavaTypes;
     
    type
      TForm1 = class(TForm)
        TabControl1: TTabControl;
        TabItemLoca: TTabItem;
        TabItemCarte: TTabItem;
        TabItemHisto: TTabItem;
        MemoHisto: TMemo;
        ListBox1: TListBox;
        ListBoxHeader1: TListBoxHeader;
        ListBoxGroupHeader1: TListBoxGroupHeader;
        ListBoxLat: TListBoxItem;
        ListBoxLon: TListBoxItem;
        ListBoxAlt: TListBoxItem;
        ListBoxPrc: TListBoxItem;
        ListBoxGroupHeader2: TListBoxGroupHeader;
        ListBoxNum: TListBoxItem;
        ListBoxRue: TListBoxItem;
        ListBoxPtl: TListBoxItem;
        ListBoxVil: TListBoxItem;
        ListBoxPay: TListBoxItem;
        ListBoxCdP: TListBoxItem;
        Label1: TLabel;
        WebBrowser1: TWebBrowser;
        Zoom: TTrackBar;
        ToolBar1: TToolBar;
        LabelZoom: TLabel;
        ButtonClb: TButton;
        TypeCarte: TComboBox;
        GoogleMap: TListBoxItem;
        roadmap: TListBoxItem;
        satellite: TListBoxItem;
        hybrid: TListBoxItem;
        terrain: TListBoxItem;
        openstreetmap: TListBoxItem;
     
        procedure FormCreate(Sender: TObject);
        procedure onLocationChanged(location: JLocation);
        procedure FaitCarte;
        procedure FaitCarte1;
        procedure FaitCarte2;
        procedure FaitCarte3;
        procedure NoReseau;
        procedure onChangeZoom(Sender: TObject);
        procedure TypeCarteChange(Sender: TObject);
        procedure ButtonClbClick(Sender: TObject);
        procedure ParametresLocalisation(Sender: TObject);
        procedure TabControl1Resize(Sender: TObject);
        procedure TabItemCarteClick(Sender: TObject);
        procedure ListBoxLatClick(Sender: TObject);
        procedure FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
        Function Reseau : boolean;
     
      private
        FLocationManager: JLocationManager;
        FGeocoder: JGeocoder;
        Address: Jaddress;
        AddressList: JList;
      public
        { Déclarations publiques }
         destructor Destroy; override;
      end;
     
      TLocationListener = class(TJavaLocal, JLocationListener)
      private
        Fparent : TForm1;
      public
    //    LogS: string;     {pour histo dans create}
        constructor Create(AParent: TForm1);
        procedure onLocationChanged(location: JLocation); cdecl;
        procedure onProviderDisabled(provider: JString); cdecl;
        procedure onProviderEnabled(provider: JString); cdecl;
        procedure onStatusChanged(provider: JString; status: Integer; extras: JBundle); cdecl;
      end;
     
      TGpsListener = class (TJavaLocal, JGpsStatus_Listener)
      private
        Fparent : TForm1;
      public
        constructor Create(AParent: TForm1);
        procedure onGpsStatusChanged(event: integer); cdecl;
      end;
     
    var
      Form1: TForm1;
      locationListener: TLocationListener;
    //  FLocationManager: JLocationManager;
      GPSListener: TGpsListener;
      TmpMapS: String;
      TestB: boolean = False;  //eviter que les évenements ne s'executent avant la fin de la def ou qu'un évenement ne soit pas terminé
     
    implementation
     
    {$R *.fmx}
     
    // GPS constructor destructor --------------------------------------------------
    constructor TGpsListener.Create(AParent: TForm1);
    begin
      inherited Create;
      FParent := AParent;
    end;
     
    constructor TLocationListener.Create(AParent: TForm1);
    begin
      inherited Create;
      FParent := AParent;
    end;
     
    destructor TForm1.Destroy;
    begin
      if Assigned(locationListener) then FLocationManager.removeUpdates(locationListener);
      if Assigned(GPSListener) then FLocationManager.removeGpsStatusListener(GPSListener);
      inherited;
    end;
     
    // GPS Evénements --------------------------------------------------------------
    procedure TGpsListener.onGPSStatusChanged(event: integer);
    begin
      {if TestB then
      begin
        TestB := False;}
        FParent.MemoHisto.Lines.Add('onGPSStatusChanged event = ' + IntToStr(event));
        {TestB := True;
      end;}
    end;
     
    procedure TLocationListener.onLocationChanged(location: JLocation);
    begin
      if TestB then FParent.onLocationChanged(location);
    end;
     
    procedure TLocationListener.onProviderDisabled(provider: JString);
    begin
      if TestB then
      begin
        TestB := False;
        FParent.MemoHisto.Lines.Add('Fournisseur ' +
                                    JStringToString(provider) +
                                    ' désactivé par l''utilisateur');
        TestB := True;
      end;
    end;
     
    procedure TLocationListener.onProviderEnabled(provider: JString);
    begin
      if TestB then
      begin
        TestB := False;
        FParent.MemoHisto.Lines.Add('Fournisseur ' +
                                    JStringToString(provider) +
                                    ' activé par l''utilisateur');
        TestB := True;
      end;
    end;
     
    procedure TLocationListener.onStatusChanged(provider: JString;
                                                status: Integer;
                                                extras: JBundle);
    begin
      if TestB then
      begin
        TestB := False;
        case status of
          0 : FParent.MemoHisto.Lines.Add('Fournisseur ' +
                                          JStringToString(provider) +
                                          ' hors service et ne devrait pas changer dans un avenir proche');
          1 : FParent.MemoHisto.Lines.Add('Fournisseur ' +
                                          JStringToString(provider) +
                                          ' temporairement indisponible mais disponible sous peu');
          2 : FParent.MemoHisto.Lines.Add('Fournisseur ' +
                                          JStringToString(provider) +
                                          ' actuellement disponible');
        end;
        TestB := True;
      end;
    end;
     
    procedure TForm1.onLocationChanged(location: JLocation);
    var LSettings: TFormatSettings;
        LDecSeparator : Char;
    begin
      if TestB and Assigned(location) then
      begin
        TestB := False;
        LDecSeparator := FormatSettings.DecimalSeparator;
        LSettings := FormatSettings;
        try
          FormatSettings.DecimalSeparator := '.';
          ListBoxLat.ItemData.Detail := FormatFloat('##0.0#####',location.getLatitude);
          ListBoxLon.ItemData.Detail := FormatFloat('##0.0#####',location.getLongitude);
          ListBoxAlt.ItemData.Detail := FormatFloat('####0.0## m',location.getAltitude);
          ListBoxPrc.ItemData.Detail := location.getAccuracy.ToString + ' m';
          //FaitCarte;  deplacé dans TabItemCarteClick
        finally
          FormatSettings.DecimalSeparator := LDecSeparator;
        end;
     
        if not Assigned(FGeocoder) then FGeocoder := TJGeocoder.JavaClass.init(SharedActivityContext);
        if Assigned(FGeocoder) and Reseau then
        begin
          AddressList := Fgeocoder.getFromLocation(location.getLatitude, location.getLongitude, 1); 
          if AddressList.size>0 then
          begin
            Address := TJAddress.Wrap((AddressList.get(0) as ILocalObject).GetObjectID);
            if Assigned(Address) then
            begin
                ListBoxNum.ItemData.Detail := JStringToString(Address.getSubThoroughfare);
                ListBoxRue.ItemData.Detail := JStringToString(Address.getThoroughfare);
                ListBoxPtl.ItemData.Detail := JStringToString(Address.getPostalCode);
                ListBoxVil.ItemData.Detail := JStringToString(Address.getLocality);
                ListBoxPay.ItemData.Detail := JStringToString(Address.getCountryName);
                ListBoxCdP.ItemData.Detail := JStringToString(Address.getCountryCode);
            end;
          end;
        end
        else begin
          ListBoxNum.ItemData.Detail := '';
          ListBoxRue.ItemData.Detail := '';
          ListBoxPtl.ItemData.Detail := '';
          ListBoxVil.ItemData.Detail := '';
          ListBoxPay.ItemData.Detail := '';
          ListBoxCdP.ItemData.Detail := '';
        end;
        TestB := True;
      end;
    end;
     
    //Evénements resultant action --------------------------------------------------
    procedure TForm1.ButtonClbClick(Sender: TObject);
    begin
      if ListBoxLat.ItemData.Detail<>'' then
      with TMemo.Create(Self) do
      begin
        Visible:=False;
        Lines.Clear;
        Lines.Add(ListBoxNum.ItemData.Detail + ' ' + ListBoxRue.ItemData.Detail);
        Lines.Add(ListBoxPtl.ItemData.Detail + ' ' + ListBoxVil.ItemData.Detail);
        Lines.Add(ListBoxPay.ItemData.Detail);
        SelectAll;
        CopyToClipboard;
        Free;
        Toast('Adresse copiée dans clipboard');
      end;
    end;
     
    procedure TForm1.ListBoxLatClick(Sender: TObject);
    begin
      if ListBoxLat.ItemData.Detail<>'' then
      with TMemo.Create(Self) do
      begin
        Visible:=False;
        Lines.Clear;
        Lines.Add(ListBoxLat.ItemData.Detail + ',' + ListBoxLon.ItemData.Detail);
        SelectAll;
        CopyToClipboard;
        Free;
        Toast('Coordonnées copiées dans clipboard');
      end;
    end;
     
    procedure TForm1.onChangeZoom(Sender: TObject);
    begin
      LabelZoom.Text:=Format('%2.0f', [Zoom.Value]);
      FaitCarte;
    end;
     
    procedure TForm1.TabControl1Resize(Sender: TObject);
    begin
      Zoom.Width := Trunc(TabControl1.Width / 2);
    end;
     
    procedure TForm1.TabItemCarteClick(Sender: TObject);
    begin
      FaitCarte;
    end;
     
    procedure TForm1.TypeCarteChange(Sender: TObject);
    begin
      FaitCarte;
    end;
     
    procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
    var Keyboard: IFMXVirtualKeyboardService;
    begin
      if (Key = vkHardwareBack) then
      begin
        TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, IInterface(Keyboard));
        if (Keyboard <> nil) and (vksVisible in Keyboard.VirtualKeyBoardState) then
        begin
          (* retour arrière, clavier visible, rien faire dans ce prog *)
        end else
        begin
          (* retour arrière, clavier non visible ou non supporté par cette platforme *)
          if MessageDlg('Voulez-vous quitter ?',
                        System.UITypes.TMsgDlgType.mtConfirmation,
                       [System.UITypes.TMsgDlgBtn.mbYes,
                        System.UITypes.TMsgDlgBtn.mbNo],
                        0) = mrYes then
          begin
            (* sortie du prog *)
            WebBrowser1.Navigate('about:blank');  //au cas où le fichier TmpMap soit tenu par WebBrowser1
            deletefile(TmpMapS);
            if Assigned(locationListener) then FLocationManager.removeUpdates(locationListener);
            if Assigned(GPSListener) then FLocationManager.removeGpsStatusListener(GPSListener);
            // NotificationCenter1.CancelNotification('MyNotification'); //si notification !!!
            MainActivity.finish;
          end else
          begin
            (* ignore le retour arrière... *)
            Key := 0;
          end;
        end;
      end;
    end;
     
    //Mes procédures et fonctions --------------------------------------------------
    procedure TForm1.FaitCarte;
    begin
      TypeCarte.Visible := true;
      if Reseau then 
      case TypeCarte.ItemIndex  of
        0..3: begin
                Zoom.Visible := true;
                LabelZoom.Visible := true;
                FaitCarte1;
              end;
        4:    begin
                Zoom.Visible := false;
                LabelZoom.Visible := false;
                FaitCarte2;
              end;
        5:    begin
                Zoom.Visible := false;
                LabelZoom.Visible := false;
                FaitCarte3;
              end;
      end
      else NoReseau;
    end;
     
    procedure TForm1.FaitCarte1;
    var URLString: String;
     
    begin
      if ListBoxLat.ItemData.Detail<>'' then
      begin
        URLString :=(Format('http://maps.googleapis.com/maps/api/staticmap?zoom=%2.0f&size=512x512&maptype=%s&markers=%s,%s',
                            [Zoom.Value,
                             TypeCarte.Selected.Text,
                             ListBoxLat.ItemData.Detail,
                             ListBoxLon.ItemData.Detail]));
        WebBrowser1.Navigate(URLString);
      end;
    end;
     
    procedure TForm1.FaitCarte2;
    begin
      WebBrowser1.Navigate('about:blank');  //au cas où le fichier TmpMap soit tenu par WebBrowser1
      if ListBoxLat.ItemData.Detail<>'' then
      begin
        with TMemo.Create(Self) do
        begin
          Visible:=False;
          Lines.Clear;
          Lines.Add('<!DOCTYPE html>');
          Lines.Add('<html>');
          Lines.Add('<head>');
          Lines.Add('<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=FR"');
          Lines.Add('type="text/javascript"></script>');
          Lines.Add('<style type="text/css">');
          Lines.Add('html, body, #map-canvas { height: 100%; width: 100%; margin: 0; }');
          Lines.Add('</style>');
          Lines.Add('<script type="text/javascript">');
          Lines.Add('function initialize() {');
          Lines.Add('var map = new google.maps.Map(');
          Lines.Add('document.getElementById(''map-canvas''), {');
          Lines.Add('center: new google.maps.LatLng('+
                     ListBoxLat.ItemData.Detail+','+
                     ListBoxLon.ItemData.Detail+'),');
          Lines.Add('zoom: 15,');
          Lines.Add('mapTypeId: google.maps.MapTypeId.ROADMAP });');
          Lines.Add('var marker = new google.maps.Marker({');
          Lines.Add('position: new google.maps.LatLng('+
                     ListBoxLat.ItemData.Detail+','+
                     ListBoxLon.ItemData.Detail+'),');
          Lines.Add('map: map });    }');
          Lines.Add('google.maps.event.addDomListener(window, ''load'', initialize);');
          Lines.Add('</script>');
          Lines.Add('</head>');
          Lines.Add('<body>');
          Lines.Add('<div id="map-canvas"></div>');
          Lines.Add('</body>');
          Lines.Add('</html>');
     
          Lines.SaveToFile(TmpMapS);
          Free;
        end;
        WebBrowser1.Navigate('file://' + TmpMapS);
      end;
    end;
     
    procedure TForm1.FaitCarte3;
    begin
      WebBrowser1.Navigate('about:blank');  //au cas où le fichier TmpMap soit tenu par WebBrowser1
      if ListBoxLat.ItemData.Detail<>'' then
      begin
        with TMemo.Create(Self) do
        begin
          Visible:=False;
          Lines.Clear;
          Lines.Add('<!DOCTYPE html>');
          Lines.Add('<html>');
          Lines.Add('<head>');
          Lines.Add('<meta charset="utf-8" />');
          Lines.Add('<title>Google Maps v3 API Example</title>');
          Lines.Add('<style>');
          Lines.Add('html, body, #map {');
          Lines.Add('height: 100%;');
          Lines.Add('width: 100%;');
          Lines.Add('margin: 0;');
          Lines.Add('padding: 0;}');
          Lines.Add('div#footer {');
          Lines.Add('position: fixed;');
          Lines.Add('left: 0;');
          Lines.Add('right: 0;');
          Lines.Add('bottom: 0;');
          Lines.Add('width: 100%;');
          Lines.Add('height: 18px;');
          Lines.Add('margin: 0;');
          Lines.Add('padding: 6px;');
          Lines.Add('z-index: 2;');
          Lines.Add('background: WHITE;}');
          Lines.Add('</style>');
          Lines.Add('</head>');
          Lines.Add('<body>');
          Lines.Add('<div id="map" style="float: left;"></div>');
          Lines.Add('<div id="footer">Pascal99 </div>');
          Lines.Add('<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>');
          Lines.Add('<script type="text/javascript">');
          Lines.Add('var element = document.getElementById("map");');
          Lines.Add('var map = new google.maps.Map(element, {');
          Lines.Add('center: new google.maps.LatLng('+
                     ListBoxLat.ItemData.Detail+','+
                     ListBoxLon.ItemData.Detail+'),');
          Lines.Add('zoom: 15,');
          Lines.Add('mapTypeId: "OSM",');
          Lines.Add('mapTypeControl: false,');
          Lines.Add('streetViewControl: false});');
          Lines.Add('var marker = new google.maps.Marker({');
          Lines.Add('position: new google.maps.LatLng('+
                     ListBoxLat.ItemData.Detail+','+
                     ListBoxLon.ItemData.Detail+'),');
          Lines.Add('map: map});');
          Lines.Add('map.mapTypes.set("OSM", new google.maps.ImageMapType({');
          Lines.Add('getTileUrl: function(coord, zoom) {');
          Lines.Add('return "http://tile.openstreetmap.org/" + zoom + "/" + coord.x + "/" + coord.y + ".png";},');
          Lines.Add('tileSize: new google.maps.Size(256, 256),');
          Lines.Add('name: "OpenStreetMap",');
          Lines.Add('maxZoom: 20}));');
          Lines.Add('</script>');
          Lines.Add('</body>');
          Lines.Add('</html>');
     
          Lines.SaveToFile(TmpMapS);
          Free;
        end;
        WebBrowser1.Navigate('file://' + TmpMapS);
      end;
    end;
     
    procedure TForm1.NoReseau;
    begin
      Zoom.Visible := false;
      LabelZoom.Visible := false;
      TypeCarte.Visible := false;
      WebBrowser1.Navigate('about:blank');  //au cas où le fichier TmpMap soit tenu par WebBrowser1
      with TMemo.Create(Self) do
      begin
        Visible:=False;
        Lines.Clear;
        Lines.Add('<!DOCTYPE html>');
        Lines.Add('<html>');
        Lines.Add('<head>');
        Lines.Add('<meta charset="utf-8" />');
        Lines.Add('<title>NoReseau</title>');
        Lines.Add('<STYLE type="text/css">');
        //Lines.Add('BODY {height:300px;line-height:300px;text-align: center}');
        Lines.Add('BODY {width:300px;height:300px;text-align:center;display:table-cell;vertical-align:middle}');
        Lines.Add('</STYLE>');
        Lines.Add('</head>');
        Lines.Add('<body>');
        Lines.Add('pas de réseau');
        Lines.Add('</body>');
        Lines.Add('</html>');
     
        Lines.SaveToFile(TmpMapS);
        Free;
      end;
      WebBrowser1.Navigate('file://' + TmpMapS);
    end;
     
     
    procedure TForm1.ParametresLocalisation(Sender: TObject);
    var poke : JIntent;
    begin
      poke := TJIntent.JavaClass.init(TJSettings.JavaClass.ACTION_LOCATION_SOURCE_SETTINGS);
      poke.addCategory(TJIntent.JavaClass.CATEGORY_DEFAULT);
      poke.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK or
                    TJIntent.JavaClass.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
     
      poke.setComponent(TJComponentName.JavaClass.init(StringToJString('com.android.settings'),
                        StringToJString('com.android.settings.Settings$LocationSettingsActivity')));
      SharedActivityContext.startActivity(poke);
    end;
     
    function TForm1.Reseau ;
    var NS: TNetworkState;
    begin
      NS := TNetworkState.Create;
      try
        Reseau := NS.IsConnected;
      finally
        NS.Free;
      end;
    end;
     
    //------------------------------------------------------------------------------
    procedure TForm1.FormCreate(Sender: TObject);
    var LocationManagerService : JObject;
        iter : JIterator;
        location : JLocation;
        GpsStatus : JGpsStatus;
     
    begin
      //TJLooper.JavaClass.prepare;       //plus l'erreur mais plantage fréquent
      Zoom.Width := Trunc(ToolBar1.Width / 2);
      LabelZoom.Text:=Format('%2.0f', [Zoom.Value]);
      TmpMapS := TPath.Combine(TPath.GetDocumentsPath, 'TmpMap.htm');
      MemoHisto.Lines.Clear;
     
      LocationManagerService := SharedActivityContext.getSystemService(TJcontext.JavaClass.LOCATION_SERVICE);
      FLocationManager := TJLocationManager.Wrap((LocationManagerService as ILocalObject).GetObjectID);
     
      //création des listeners
      LocationListener := TLocationListener.Create(self);
      GPSListener := TGpsListener.Create(self);
     
      FLocationManager.requestLocationUpdates(TJLocationManager.JavaClass.GPS_PROVIDER,
                                              1000,    {delais ms}
                                              1,       {distance m}
                                              LocationListener,
                                              TJLooper.JavaClass.getMainLooper);
     
      try
        FLocationManager.addGpsStatusListener(GPSListener);
      except
        on E: Exception do MemoHisto.Lines.Add(E.Message); //message : "java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()"
      end;
     
      if NOT FLocationManager.IsProviderEnabled(TJLocationManager.JavaClass.GPS_PROVIDER) then
      case MessageDlg('Veuillez activer le GPS',
                      System.UITypes.TMsgDlgType.mtInformation,
                     [System.UITypes.TMsgDlgBtn.mbYes,
                      System.UITypes.TMsgDlgBtn.mbCancel],
                      0) of
        mrYES:    ParametresLocalisation(Sender);{appel menu Parametres/Localisation}
        mrCancel: Halt;
      end;
     
      //pour histo
      MemoHisto.Lines.Add('GetAllProviders :');
      iter := FLocationManager.GetAllProviders.Iterator;
      while iter.hasNext do MemoHisto.Lines.Add(JStringToString(iter.next.ToString));
      MemoHisto.Lines.Add('');
     
      MemoHisto.Lines.Add('IsProviderEnabled :');
      if FLocationManager.IsProviderEnabled(TJLocationManager.JavaClass.GPS_PROVIDER) then
          MemoHisto.Lines.Add('GPS_PROVIDER');
      if FLocationManager.IsProviderEnabled(TJLocationManager.JavaClass.PASSIVE_PROVIDER) then
          MemoHisto.Lines.Add('PASSIVE_PROVIDER');
      if FLocationManager.IsProviderEnabled(TJLocationManager.JavaClass.NETWORK_PROVIDER) then
          MemoHisto.Lines.Add('NETWORK_PROVIDER');
      MemoHisto.Lines.Add('');
     
      location := FLocationManager.getLastKnownLocation(TJLocationManager.JavaClass.GPS_PROVIDER);
      GpsStatus := FlocationManager.getGpsStatus(NIL);
      MemoHisto.Lines.Add(JStringToString(GpsStatus.toString));
      TestB := True;
    end;
     
    end.
    Unit1.fmx :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    object Form1: TForm1
      Left = 0
      Top = 0
      Caption = 'Form1'
      ClientHeight = 615
      ClientWidth = 360
      FormFactor.Width = 320
      FormFactor.Height = 480
      FormFactor.Devices = [dkDesktop]
      OnCreate = FormCreate
      OnKeyUp = FormKeyUp
      DesignerMobile = True
      DesignerWidth = 360
      DesignerHeight = 640
      DesignerDeviceName = 'Samsung Galaxy S4'
      DesignerOrientation = 0
      DesignerOSVersion = ''
      object TabControl1: TTabControl
        Align = alClient
        FullSize = True
        Height = 615.000000000000000000
        TabHeight = 49.000000000000000000
        TabIndex = 0
        TabOrder = 0
        TabPosition = tpBottom
        Width = 360.000000000000000000
        OnResize = TabControl1Resize
        object TabItemLoca: TTabItem
          WordWrap = False
          Height = 49.000000000000000000
          IsSelected = True
          TabOrder = 0
          Text = 'LOCALISATION'
          Trimming = ttCharacter
          Width = 120.000000000000000000
          object ListBox1: TListBox
            Align = alClient
            Height = 566.000000000000000000
            TabOrder = 0
            Width = 360.000000000000000000
            DefaultItemStyles.ItemStyle = 'listboxitemnodetail'
            DefaultItemStyles.GroupHeaderStyle = ''
            DefaultItemStyles.GroupFooterStyle = ''
            object ListBoxGroupHeader1: TListBoxGroupHeader
              Font.Style = [fsBold]
              StyledSettings = [ssFamily, ssSize, ssFontColor]
              Height = 30.000000000000000000
              Text = 'GPS'
              TextAlign = taCenter
              Width = 360.000000000000000000
            end
            object ListBoxLat: TListBoxItem
              StyledSettings = [ssFamily, ssSize, ssStyle, ssFontColor]
              Height = 44.000000000000000000
              Position.Y = 30.000000000000000000
              StyleLookup = 'listboxitemleftdetail'
              Text = 'Latitude'
              Width = 360.000000000000000000
              OnClick = ListBoxLatClick
            end
            object ListBoxLon: TListBoxItem
              Selectable = False
              StyledSettings = [ssFamily, ssSize, ssStyle, ssFontColor]
              Height = 44.000000000000000000
              Position.Y = 74.000000000000000000
              StyleLookup = 'listboxitemleftdetail'
              Text = 'Longitude'
              Width = 360.000000000000000000
            end
            object ListBoxAlt: TListBoxItem
              Selectable = False
              StyledSettings = [ssFamily, ssSize, ssStyle, ssFontColor]
              Height = 44.000000000000000000
              Position.Y = 118.000000000000000000
              StyleLookup = 'listboxitemleftdetail'
              Text = 'Altitude'
              Width = 360.000000000000000000
            end
            object ListBoxPrc: TListBoxItem
              Selectable = False
              StyledSettings = [ssFamily, ssSize, ssStyle, ssFontColor]
              Height = 44.000000000000000000
              Position.Y = 162.000000000000000000
              StyleLookup = 'listboxitemleftdetail'
              Text = 'Pr'#233'cision'
              Width = 360.000000000000000000
            end
            object ListBoxGroupHeader2: TListBoxGroupHeader
              Font.Style = [fsBold]
              StyledSettings = [ssFamily, ssSize, ssFontColor]
              Height = 30.000000000000000000
              Position.Y = 206.000000000000000000
              Text = 'Adresse'
              TextAlign = taCenter
              Width = 360.000000000000000000
            end
            object ListBoxNum: TListBoxItem
              Selectable = False
              StyledSettings = [ssFamily, ssSize, ssStyle, ssFontColor]
              Height = 44.000000000000000000
              Position.Y = 236.000000000000000000
              StyleLookup = 'listboxitemleftdetail'
              Text = 'n'#176
              Width = 360.000000000000000000
            end
            object ListBoxRue: TListBoxItem
              Selectable = False
              StyledSettings = [ssFamily, ssSize, ssStyle, ssFontColor]
              Height = 44.000000000000000000
              Position.Y = 280.000000000000000000
              StyleLookup = 'listboxitemleftdetail'
              Text = 'voie'
              Width = 360.000000000000000000
            end
            object ListBoxPtl: TListBoxItem
              Selectable = False
              StyledSettings = [ssFamily, ssSize, ssStyle, ssFontColor]
              Height = 44.000000000000000000
              Position.Y = 324.000000000000000000
              StyleLookup = 'listboxitemleftdetail'
              Text = 'code postal'
              Width = 360.000000000000000000
            end
            object ListBoxVil: TListBoxItem
              Selectable = False
              StyledSettings = [ssFamily, ssSize, ssStyle, ssFontColor]
              Height = 44.000000000000000000
              Position.Y = 368.000000000000000000
              StyleLookup = 'listboxitemleftdetail'
              Text = 'ville'
              Width = 360.000000000000000000
            end
            object ListBoxPay: TListBoxItem
              Selectable = False
              StyledSettings = [ssFamily, ssSize, ssStyle, ssFontColor]
              Height = 44.000000000000000000
              Position.Y = 412.000000000000000000
              StyleLookup = 'listboxitemleftdetail'
              Text = 'pays'
              Width = 360.000000000000000000
            end
            object ListBoxCdP: TListBoxItem
              Selectable = False
              StyledSettings = [ssFamily, ssSize, ssStyle, ssFontColor]
              Height = 44.000000000000000000
              Position.Y = 456.000000000000000000
              StyleLookup = 'listboxitemleftdetail'
              Text = 'code pays'
              Width = 360.000000000000000000
            end
            object ListBoxHeader1: TListBoxHeader
              Height = 48.000000000000000000
              TabOrder = 0
              Width = 360.000000000000000000
              object Label1: TLabel
                Align = alClient
                Height = 48.000000000000000000
                StyleLookup = 'toollabel'
                Text = 'Localisation'
                TextAlign = taCenter
                Width = 360.000000000000000000
                Trimming = ttCharacter
              end
              object ButtonClb: TButton
                Anchors = [akTop, akRight]
                Height = 48.000000000000000000
                Position.X = 309.000000000000000000
                Position.Y = -1.000000000000000000
                StyleLookup = 'pagecurltoolbutton'
                TabOrder = 1
                Text = 'ButtonClb'
                Trimming = ttCharacter
                Width = 48.000000000000000000
                OnClick = ButtonClbClick
              end
            end
          end
        end
        object TabItemCarte: TTabItem
          WordWrap = False
          Height = 49.000000000000000000
          IsSelected = False
          Position.X = 120.000000000000000000
          TabOrder = 1
          Text = 'Carte'
          Trimming = ttCharacter
          Width = 120.000000000000000000
          OnClick = TabItemCarteClick
          object WebBrowser1: TWebBrowser
            Align = alClient
            Height = 518.000000000000000000
            Width = 360.000000000000000000
          end
          object ToolBar1: TToolBar
            Height = 48.000000000000000000
            TabOrder = 1
            Width = 360.000000000000000000
            object Zoom: TTrackBar
              Height = 32.000000000000000000
              Max = 20.000000000000000000
              Min = 7.000000000000000000
              Orientation = orHorizontal
              Position.X = 3.000000000000000000
              Position.Y = 8.000000000000000000
              TabOrder = 0
              Value = 15.000000000000000000
              Width = 177.000000000000000000
              OnChange = onChangeZoom
            end
            object TypeCarte: TComboBox
              Anchors = [akTop, akRight]
              DisableFocusEffect = False
              Height = 32.000000000000000000
              ItemIndex = 0
              Position.X = 224.000000000000000000
              Position.Y = 8.000000000000000000
              TabOrder = 1
              Width = 132.000000000000000000
              OnChange = TypeCarteChange
              object roadmap: TListBoxItem
                Height = 19.000000000000000000
                Text = 'roadmap'
                Width = 19.000000000000000000
              end
              object satellite: TListBoxItem
                Height = 19.000000000000000000
                Text = 'satellite'
                Width = 19.000000000000000000
              end
              object hybrid: TListBoxItem
                Height = 19.000000000000000000
                Text = 'hybrid'
                Width = 19.000000000000000000
              end
              object terrain: TListBoxItem
                Height = 19.000000000000000000
                Text = 'terrain'
                Width = 19.000000000000000000
              end
              object GoogleMap: TListBoxItem
                Height = 44.000000000000000000
                Text = 'GoogleMap'
                Width = 44.000000000000000000
              end
              object openstreetmap: TListBoxItem
                Height = 19.000000000000000000
                Text = 'openstreetmap'
                Width = 19.000000000000000000
              end
            end
            object LabelZoom: TLabel
              Align = alCenter
              Font.Size = 10.000000000000000000
              StyledSettings = [ssFamily, ssStyle, ssFontColor]
              Height = 32.000000000000000000
              Text = '15'
              TextAlign = taCenter
              Width = 33.000000000000000000
              Trimming = ttCharacter
            end
          end
        end
        object TabItemHisto: TTabItem
          WordWrap = False
          Height = 49.000000000000000000
          IsSelected = False
          Position.X = 240.000000000000000000
          TabOrder = 2
          Text = 'Histo'
          Trimming = ttCharacter
          Width = 120.000000000000000000
          object MemoHisto: TMemo
            Touch.InteractiveGestures = [igPan, igLongTap, igDoubleTap]
            Align = alClient
            Height = 566.000000000000000000
            TabOrder = 0
            Width = 360.000000000000000000
          end
        end
      end
    end
    S'il y a besoin d'autre chose, n'hésitez pas a le demander.

    merci de l'intérêt que vous portez a ce code.
    Pascal

Discussions similaires

  1. [Système/Fichiers/API] Utilisation d'une DLL visualstudio avec CBuilder Xe5
    Par Gouyon dans le forum C++Builder
    Réponses: 9
    Dernier message: 02/04/2019, 09h10
  2. utiliser les tag [MFC] [Win32] [.NET] [C++/CLI]
    Par hiko-seijuro dans le forum Visual C++
    Réponses: 8
    Dernier message: 08/06/2005, 16h57
  3. utilisation du meta type ANY
    Par Anonymous dans le forum CORBA
    Réponses: 1
    Dernier message: 15/04/2002, 13h36
  4. [BCB5] Utilisation des Ressources (.res)
    Par Vince78 dans le forum C++Builder
    Réponses: 2
    Dernier message: 04/04/2002, 17h01
  5. Réponses: 2
    Dernier message: 21/03/2002, 00h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo