Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #96

Open
wants to merge 5 commits into
base: native
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "23.0.3"
compileSdkVersion 33

defaultConfig {
applicationId "org.traccar.manager"
minSdkVersion 14
targetSdkVersion 24
minSdkVersion 19
targetSdkVersion 33
versionCode 9
versionName "1.7"
multiDexEnabled = true
vectorDrawables.useSupportLibrary = true
}

dexOptions {
incremental true
javaMaxHeapSize "4g"
}

packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt')
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}

}

dependencies {
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.google.android.gms:play-services:9.6.1'
compile 'com.squareup.okhttp3:okhttp-ws:3.4.1'
compile "com.squareup.okhttp3:okhttp-urlconnection:3.4.1"
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-jackson:2.1.0'
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'com.squareup.okhttp3:okhttp-ws:3.4.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "com.squareup.okhttp3:okhttp-urlconnection:3.4.1"
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-jackson:2.1.0'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.robolectric:robolectric:4.2.1'
}
Binary file added app/release/app-release.apk
Binary file not shown.
20 changes: 20 additions & 0 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also remove the output and probably add it to the gitignore.

"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "org.traccar.manager",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 9,
"versionName": "1.7",
"outputFile": "app-release.apk"
}
],
"elementType": "File"
}
8 changes: 2 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Expand All @@ -22,7 +21,8 @@
android:value="AIzaSyAMQYClXhA2tZdfCzu9EK9wUDWtCRQ6Bj0" />

<activity
android:name=".LoginActivity" >
android:name=".LoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -36,10 +36,6 @@
android:name=".DevicesActivity"
android:label="@string/devices_title" />

<activity
android:name=".SendCommandActivity"
android:label="@string/send_command_title" />

</application>

</manifest>
4 changes: 2 additions & 2 deletions app/src/main/java/org/traccar/manager/DevicesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package org.traccar.manager;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

public class DevicesActivity extends AppCompatActivity {

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/org/traccar/manager/DevicesFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.fragment.app.ListFragment;
import org.traccar.manager.model.Device;

import java.util.List;

import okhttp3.OkHttpClient;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/traccar/manager/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.traccar.manager;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;

public class LoginActivity extends AppCompatActivity {

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/traccar/manager/LoginFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
Expand All @@ -33,6 +31,8 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/org/traccar/manager/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
package org.traccar.manager;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

public class MainActivity extends AppCompatActivity {

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/org/traccar/manager/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.multidex.MultiDexApplication;
import android.widget.Toast;

import androidx.multidex.MultiDexApplication;
import org.traccar.manager.model.User;

import java.net.CookieManager;
Expand Down
24 changes: 19 additions & 5 deletions app/src/main/java/org/traccar/manager/MainFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import android.view.View;
import android.widget.TextView;

import androidx.fragment.app.FragmentTransaction;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
Expand Down Expand Up @@ -60,12 +62,12 @@ public class MainFragment extends SupportMapFragment implements OnMapReadyCallba

public static final int REQUEST_DEVICE = 1;
public static final int RESULT_SUCCESS = 1;

private FragmentTransaction fragmentTransaction;
private GoogleMap map;

private Handler handler = new Handler();
private ObjectMapper objectMapper = new ObjectMapper();

private long deviceId;
private Map<Long, Device> devices = new HashMap<>();
private Map<Long, Position> positions = new HashMap<>();
private Map<Long, Marker> markers = new HashMap<>();
Expand Down Expand Up @@ -104,7 +106,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_DEVICE && resultCode == RESULT_SUCCESS) {
long deviceId = data.getLongExtra(DevicesFragment.EXTRA_DEVICE_ID, 0);
deviceId = data.getLongExtra(DevicesFragment.EXTRA_DEVICE_ID, 0);
Position position = positions.get(deviceId);
if (position != null) {
map.moveCamera(CameraUpdateFactory.newLatLng(
Expand All @@ -126,13 +128,25 @@ public View getInfoWindow(Marker marker) {

@Override
public View getInfoContents(Marker marker) {
View view = getLayoutInflater(null).inflate(R.layout.view_info, null);
View view = getLayoutInflater().inflate(R.layout.view_info, null);
((TextView) view.findViewById(R.id.title)).setText(marker.getTitle());
((TextView) view.findViewById(R.id.details)).setText(marker.getSnippet());
return view;
}
});


map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Bundle args = new Bundle();
args.putLong("deviceId", deviceId);
fragmentTransaction =getFragmentManager().beginTransaction();
SendCommandFragment sendCommandFragment = new SendCommandFragment();
sendCommandFragment.setArguments(args);
sendCommandFragment.show(fragmentTransaction, "sendCommand_tag");
}
});
createWebSocket();
}

Expand Down Expand Up @@ -188,7 +202,7 @@ private void handleMessage(String message) throws IOException {
Update update = objectMapper.readValue(message, Update.class);
if (update != null && update.positions != null) {
for (Position position : update.positions) {
long deviceId = position.getDeviceId();
deviceId = position.getDeviceId();
if (devices.containsKey(deviceId)) {
LatLng location = new LatLng(position.getLatitude(), position.getLongitude());
Marker marker = markers.get(deviceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.traccar.manager;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;

public class SendCommandActivity extends AppCompatActivity {

Expand Down
19 changes: 12 additions & 7 deletions app/src/main/java/org/traccar/manager/SendCommandFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -28,22 +26,24 @@
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import org.traccar.manager.model.Command;
import org.traccar.manager.model.CommandType;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Response;

public class SendCommandFragment extends Fragment {
public class SendCommandFragment extends DialogFragment {

class CommandTypeDataHolder {
private String type;
Expand Down Expand Up @@ -132,7 +132,7 @@ public void onNothingSelected(AdapterView<?> parent) {
}
});

final long deviceId = getActivity().getIntent().getExtras().getLong(EXTRA_DEVICE_ID);
final long deviceId = getArguments().getLong(EXTRA_DEVICE_ID);
final MainApplication application = (MainApplication) getActivity().getApplication();
final WebService service = application.getService();
service.getCommandTypes(deviceId).enqueue(new WebServiceCallback<List<CommandType>>(getContext()) {
Expand Down Expand Up @@ -175,9 +175,14 @@ public void onClick(View v) {
public void onSuccess(Response<Command> response) {
Toast.makeText(getContext(), R.string.command_sent, Toast.LENGTH_LONG).show();
}

@Override
public void onFailure(Call<Command> call, Throwable t) {
super.onFailure(call, t);
Toast.makeText(getActivity(), R.string.command_not_sent, Toast.LENGTH_LONG).show();
}
});

getActivity().finish();
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.traccar.manager;

public class ServiceException extends Exception {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please revert the files that only have formatting changes like this.

public ServiceException(String message) {
super(message);
}
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/org/traccar/manager/WebService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
import java.util.List;

import retrofit2.Call;
import retrofit2.Response;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;

public interface WebService {
Expand All @@ -41,9 +39,10 @@ public interface WebService {
@GET("/api/devices")
Call<List<Device>> getDevices();

@GET("/api/commandtypes")
@GET("/api/commands/types")
Call<List<CommandType>> getCommandTypes(@Query("deviceId") long deviceId);

@POST("/api/commands")
@POST("/api/commands/send")
Call<Command> sendCommand(@Body Command command);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import android.content.Context;
import android.widget.Toast;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/traccar/manager/model/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;


@JsonIgnoreProperties(ignoreUnknown = true)
public class Command extends Extensible {

Expand Down
Loading