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

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du 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 : 61
    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
    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
    Futur Membre du 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 : 61
    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
    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
    Futur Membre du 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 : 61
    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
    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) ?

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, 08h10
  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, 15h57
  3. utilisation du meta type ANY
    Par Anonymous dans le forum CORBA
    Réponses: 1
    Dernier message: 15/04/2002, 12h36
  4. [BCB5] Utilisation des Ressources (.res)
    Par Vince78 dans le forum C++Builder
    Réponses: 2
    Dernier message: 04/04/2002, 16h01
  5. Réponses: 2
    Dernier message: 20/03/2002, 23h01

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