Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"FIX": Temporary Workaround for MessageService: Mocking some devices
ADD: Google API Key is now wrapped in resources. Read api_keys_template.xml for more info ADD: Devices can now be shown on a map
- Loading branch information
Showing
12 changed files
with
257 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
/captures | ||
**/*.iml | ||
**/build | ||
cormorant-framework/src/main/res/values/api_keys.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
cormorant-framework/src/main/java/at/usmile/cormorant/framework/common/CommonUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package at.usmile.cormorant.framework.common; | ||
|
||
import at.usmile.cormorant.framework.R; | ||
|
||
/** | ||
* Created by fhdwsse | ||
*/ | ||
|
||
public class CommonUtils { | ||
public static int getIconByScreenSize(double screenSize, boolean blue) { | ||
if (screenSize >= 7) { | ||
return blue ? R.drawable.ic_computer_blue_24dp : R.drawable.ic_computer_black_24dp; | ||
} | ||
if (screenSize < 3) { | ||
return blue ? R.drawable.ic_watch_blue_24dp : R.drawable.ic_watch_black_24dp; | ||
} else { | ||
return blue ? R.drawable.ic_phone_android_blue_24dp : R.drawable.ic_phone_android_black_24dp; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
cormorant-framework/src/main/java/at/usmile/cormorant/framework/group/GroupMapActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package at.usmile.cormorant.framework.group; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Canvas; | ||
import android.graphics.drawable.Drawable; | ||
import android.location.Location; | ||
import android.support.annotation.DrawableRes; | ||
import android.support.v4.content.res.ResourcesCompat; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
|
||
import com.google.android.gms.maps.CameraUpdate; | ||
import com.google.android.gms.maps.CameraUpdateFactory; | ||
import com.google.android.gms.maps.GoogleMap; | ||
import com.google.android.gms.maps.MapFragment; | ||
import com.google.android.gms.maps.OnMapReadyCallback; | ||
import com.google.android.gms.maps.model.BitmapDescriptor; | ||
import com.google.android.gms.maps.model.BitmapDescriptorFactory; | ||
import com.google.android.gms.maps.model.LatLng; | ||
import com.google.android.gms.maps.model.LatLngBounds; | ||
import com.google.android.gms.maps.model.Marker; | ||
import com.google.android.gms.maps.model.MarkerOptions; | ||
|
||
import java.security.acl.Group; | ||
import java.util.Arrays; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import at.usmile.cormorant.framework.R; | ||
import at.usmile.cormorant.framework.common.CommonUtils; | ||
import at.usmile.cormorant.framework.common.TypedServiceConnection; | ||
|
||
/** | ||
* Created by fhdwsse | ||
*/ | ||
public class GroupMapActivity extends AppCompatActivity implements OnMapReadyCallback, GroupChangeListener { | ||
public static final double MAP_PADDING_FACTOR = 0.15; | ||
private GoogleMap googleMap; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_group_map); | ||
|
||
bindService(new Intent(this, GroupService.class), groupService, Context.BIND_AUTO_CREATE); | ||
|
||
MapFragment mapFragment = (MapFragment) getFragmentManager() | ||
.findFragmentById(R.id.map); | ||
mapFragment.getMapAsync(this); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
if (groupService.isBound()) unbindService(groupService); | ||
super.onDestroy(); | ||
} | ||
|
||
@Override | ||
public void onMapReady(GoogleMap googleMap) { | ||
this.googleMap = googleMap; | ||
if(groupService.isBound()) setupMap(addMarkerForDevices(groupService.get().getGroup())); | ||
} | ||
|
||
private List<Marker> addMarkerForDevices(List<TrustedDevice> devices) { | ||
List<Marker> createdMarkers = new LinkedList<>(); | ||
devices.forEach(eachDevice -> { | ||
int iconByScreenSize = CommonUtils.getIconByScreenSize(eachDevice.getScreenSize(), | ||
groupService.get().getSelf().equals(eachDevice)); | ||
BitmapDescriptor markerIcon = convertVectorToBitmap(iconByScreenSize); | ||
Location deviceLoc = eachDevice.getLocation(); | ||
|
||
Marker mapMarker = googleMap.addMarker(new MarkerOptions() | ||
.position(new LatLng(deviceLoc.getLatitude(), deviceLoc.getLongitude())) | ||
.icon(markerIcon) | ||
.anchor(0.5f, 0.5f) | ||
.snippet(eachDevice.getDistanceToOtherDeviceGps() + "m") | ||
.title(eachDevice.getDevice())); | ||
createdMarkers.add(mapMarker); | ||
}); | ||
return createdMarkers; | ||
} | ||
|
||
private void setupMap(List<Marker> markers) { | ||
LatLngBounds.Builder builder = new LatLngBounds.Builder(); | ||
for (Marker marker : markers) { | ||
builder.include(marker.getPosition()); | ||
} | ||
LatLngBounds bounds = builder.build(); | ||
|
||
int padding = (int) (getResources().getDisplayMetrics().widthPixels * MAP_PADDING_FACTOR); | ||
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding); | ||
|
||
googleMap.setOnMapLoadedCallback(() -> googleMap.animateCamera(cu)); | ||
} | ||
|
||
private BitmapDescriptor convertVectorToBitmap(@DrawableRes int id) { | ||
Drawable vectorDrawable = ResourcesCompat.getDrawable(getResources(), id, null); | ||
Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(), | ||
vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); | ||
Canvas canvas = new Canvas(bitmap); | ||
vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); | ||
vectorDrawable.draw(canvas); | ||
return BitmapDescriptorFactory.fromBitmap(bitmap); | ||
} | ||
|
||
private TypedServiceConnection<GroupService> groupService = new TypedServiceConnection<GroupService>() { | ||
|
||
@Override | ||
public void onServiceConnected(GroupService service) { | ||
if(googleMap != null) setupMap(addMarkerForDevices(service.getGroup())); | ||
service.addGroupChangeListener(GroupMapActivity.this); | ||
} | ||
|
||
@Override | ||
public void onServiceDisconnected(GroupService service) { | ||
service.removeGroupChangeListener(GroupMapActivity.this); | ||
} | ||
}; | ||
|
||
@Override | ||
public void groupChanged() { | ||
//TODO refresh Map | ||
} | ||
} |
Oops, something went wrong.