2 * Copyright © 2020 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.AltosDroid;
21 import java.lang.ref.WeakReference;
24 import android.Manifest;
25 import android.app.Activity;
26 import android.app.PendingIntent;
27 import android.bluetooth.BluetoothAdapter;
28 import android.content.Intent;
29 import android.content.Context;
30 import android.content.ComponentName;
31 import android.content.ServiceConnection;
32 import android.content.DialogInterface;
33 import android.os.IBinder;
34 import android.os.Bundle;
35 import android.os.Handler;
36 import android.os.Message;
37 import android.os.Messenger;
38 import android.os.RemoteException;
39 import android.os.Parcelable;
40 import android.os.Parcel;
41 import androidx.fragment.app.FragmentActivity;
42 import androidx.fragment.app.FragmentManager;
43 import android.view.*;
44 import android.widget.*;
45 import android.app.AlertDialog;
46 import android.location.Location;
47 import android.location.LocationManager;
48 import android.location.LocationListener;
49 import android.hardware.usb.*;
50 import android.content.pm.PackageManager;
51 import androidx.core.app.ActivityCompat;
52 import org.altusmetrum.altoslib_14.*;
54 public class Tracker implements CharSequence, Comparable, Parcelable {
61 private void make_display() {
64 else if (frequency == AltosLib.MISSING) {
65 display = String.format("%-8.8s %6d", call, serial);
67 display = String.format("%-8.8s %7.3f %6d", call, frequency, serial);
71 public Tracker(int serial, String call, double frequency, long received_time) {
77 this.frequency = frequency;
78 this.received_time = received_time;
82 public Tracker(int serial, String call, double frequency) {
83 this(serial, call, frequency, 0);
86 public Tracker(AltosState s) {
87 this(s == null ? 0 : s.cal_data().serial,
88 s == null ? null : s.cal_data().callsign,
89 s == null ? 0.0 : s.frequency,
90 s == null ? 0 : s.received_time);
94 public char charAt(int index) {
95 return display.charAt(index);
99 return display.length();
102 public CharSequence subSequence(int start, int end) throws IndexOutOfBoundsException {
103 return display.subSequence(start, end);
106 public String toString() {
107 return display.toString();
111 public int compareTo (Object other) {
112 Tracker o = (Tracker) other;
113 if (frequency == 0.0) {
114 if (o.frequency == 0.0)
118 if (o.frequency == 0.0)
121 int a = serial - o.serial;
122 int b = call.compareTo(o.call);
123 int c = (int) Math.signum(frequency - o.frequency);
134 public int describeContents() {
135 AltosDebug.debug("describe contents %d", serial);
139 public void writeToParcel(Parcel out, int flags) {
140 AltosDebug.debug("write to parcel %s", display);
141 out.writeInt(serial);
142 out.writeString(call);
143 out.writeDouble(frequency);
144 out.writeLong(received_time);
147 public static final Parcelable.Creator<Tracker> CREATOR
148 = new Parcelable.Creator<Tracker>() {
149 public Tracker createFromParcel(Parcel in) {
150 AltosDebug.debug("createFromParcel");
151 return new Tracker(in);
154 public Tracker[] newArray(int size) {
155 AltosDebug.debug("newArray %d", size);
156 return new Tracker[size];
160 /* newer (-1), same (0), older(1) */
161 public int compareAge(Tracker o) {
162 if (received_time == o.received_time)
164 if (received_time == 0)
166 if (o.received_time == 0)
168 if (received_time > o.received_time)
173 public int compareCall(Tracker o) {
174 int v = call.compareTo(o.call);
177 if (call.equals("auto"))
179 if (o.call.equals("auto"))
184 public int compareSerial(Tracker o) {
185 return serial - o.serial;
188 public int compareFrequency(Tracker o) {
189 return (int) Math.signum(frequency - o.frequency);
192 private Tracker(Parcel in) {
193 serial = in.readInt();
194 call = in.readString();
195 frequency = in.readDouble();
196 received_time = in.readLong();
198 AltosDebug.debug("Create from parcel %s", display);