Updated osmo on dashboard

This commit is contained in:
Denis 2015-03-19 14:54:50 +02:00
parent 5fa08c2a36
commit 68ee87b498
9 changed files with 251 additions and 106 deletions

View file

@ -52,11 +52,6 @@
<include layout="@layout/check_item_rel"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<LinearLayout
android:visibility="gone"
android:layout_width="match_parent"

View file

@ -2,63 +2,84 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/dashListItemHeight"
android:orientation="horizontal">
android:layout_height="wrap_content"
android:minHeight="@dimen/dashListItemHeight"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/dashFavIconMargin"
android:layout_marginRight="@dimen/dashFavIconMargin"
tools:src="@drawable/ic_gpx_track"/>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<LinearLayout
android:layout_width="0dp"
android:layout_width="match_parent"
android:minHeight="@dimen/dashListItemHeight"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
android:orientation="horizontal">
<TextView
android:id="@+id/name"
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="@string/app_version"/>
android:layout_marginLeft="@dimen/dashFavIconMargin"
android:layout_marginRight="@dimen/dashFavIconMargin"
android:layout_marginTop="@dimen/favorites_icon_top_margin"
tools:src="@drawable/ic_gpx_track"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/people_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/people_count"
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
tools:text="@string/app_version"/>
<ImageView
android:id="@+id/direction_icon"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/people_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/people_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/direction_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="@+id/show_on_map"
android:layout_width="@dimen/dashListItemHeight"
android:layout_height="@dimen/dashListItemHeight"
android:layout_gravity="center_vertical"
android:background="?attr/options_button_background"
tools:src="@drawable/ic_action_marker_dark"/>
<include android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
layout="@layout/check_item_rel"/>
</LinearLayout>
<ImageButton
android:id="@+id/show_on_map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/dashFavIconMargin"
android:background="?attr/options_button_background"
tools:src="@drawable/ic_action_marker_dark"/>
</LinearLayout>

View file

@ -1,9 +1,10 @@
package net.osmand.plus;
import gnu.trove.map.hash.TLongObjectHashMap;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import gnu.trove.map.hash.TLongObjectHashMap;
public class IconsCache {
private TLongObjectHashMap<Drawable> drawable = new TLongObjectHashMap<Drawable>();
@ -27,7 +28,23 @@ public class IconsCache {
}
return d;
}
private Drawable getPaintedDrawable(int resId, int color){
long hash = ((long)resId << 31l) + color;
Drawable d = drawable.get(hash);
if(d == null) {
d = app.getResources().getDrawable(resId).mutate();
d.clearColorFilter();
d.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
drawable.put(hash, d);
}
return d;
}
public Drawable getPaintedContentIcon(int id, int color){
return getPaintedDrawable(id, color);
}
public Drawable getContentIcon(int id, int lightContentColor, int darkContentColor) {
return getDrawable(id, app.getSettings().isLightContent() ? lightContentColor : darkContentColor);
}

View file

@ -1,30 +1,5 @@
package net.osmand.plus.dashboard;
import gnu.trove.map.hash.TIntObjectHashMap;
import java.lang.ref.WeakReference;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.audionotes.DashAudioVideoNotesFragment;
import net.osmand.plus.development.DashSimulateFragment;
import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.helpers.ScreenOrientationHelper;
import net.osmand.plus.monitoring.DashTrackFragment;
import net.osmand.plus.osmedit.DashOsmEditsFragment;
import net.osmand.plus.osmo.DashOsmoFragment;
import net.osmand.plus.parkingpoint.DashParkingFragment;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.DownloadedRegionsLayer;
import net.osmand.plus.views.OsmandMapTileView;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
@ -49,6 +24,32 @@ import android.widget.ScrollView;
import com.software.shell.fab.ActionButton;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.audionotes.DashAudioVideoNotesFragment;
import net.osmand.plus.development.DashSimulateFragment;
import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.helpers.ScreenOrientationHelper;
import net.osmand.plus.monitoring.DashTrackFragment;
import net.osmand.plus.osmedit.DashOsmEditsFragment;
import net.osmand.plus.osmo.DashOsMoFragment;
import net.osmand.plus.parkingpoint.DashParkingFragment;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.DownloadedRegionsLayer;
import net.osmand.plus.views.OsmandMapTileView;
import java.lang.ref.WeakReference;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import gnu.trove.map.hash.TIntObjectHashMap;
/**
* Created by Denis
* on 03.03.15.
@ -401,7 +402,7 @@ public class DashboardOnMap {
showFragment(manager, fragmentTransaction, DashFavoritesFragment.TAG, DashFavoritesFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashAudioVideoNotesFragment.TAG, DashAudioVideoNotesFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashTrackFragment.TAG, DashTrackFragment.class, showCards);
//showFragment(manager, fragmentTransaction, DashOsmoFragment.TAG, DashOsmoFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashOsMoFragment.TAG, DashOsMoFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashOsmEditsFragment.TAG, DashOsmEditsFragment.class, showCards);
// showFragment(manager, fragmentTransaction, DashUpdatesFragment.TAG, DashUpdatesFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashPluginsFragment.TAG, DashPluginsFragment.class, showCards);

View file

@ -3,7 +3,6 @@ package net.osmand.plus.osmedit;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -19,7 +18,6 @@ import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashBaseFragment;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.myplaces.FavoritesActivity;
import java.util.ArrayList;

View file

@ -4,13 +4,17 @@ import android.content.Intent;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.Location;
import net.osmand.data.PointDescription;
@ -30,12 +34,21 @@ import java.util.List;
* Created by Denis
* on 20.01.2015.
*/
public class DashOsmoFragment extends DashBaseFragment {
public class DashOsMoFragment extends DashBaseFragment implements OsMoGroups.OsMoGroupsUIListener {
public static final String TAG = "DASH_OSMO_FRAGMENT";
private Handler uiHandler = new Handler();
OsMoPlugin plugin;
@Override
public void onCloseDash() {
if (plugin != null && plugin.getGroups() !=null){
plugin.getGroups().removeUiListener(this);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
plugin = OsmandPlugin.getEnabledPlugin(OsMoPlugin.class);
@ -46,8 +59,7 @@ public class DashOsmoFragment extends DashBaseFragment {
view.findViewById(R.id.manage).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), OsMoGroupsActivity.class);
getActivity().startActivity(intent);
launchOsMoGroupsActivity();
}
});
@ -58,7 +70,9 @@ public class DashOsmoFragment extends DashBaseFragment {
@Override
public void onOpenDash() {
plugin = OsmandPlugin.getEnabledPlugin(OsMoPlugin.class);
if (plugin!=null){
plugin.getGroups().addUiListeners(this);
}
setupOsMoView();
}
@ -133,9 +147,11 @@ public class DashOsmoFragment extends DashBaseFragment {
private void updateConnectedDevices(View mainView) {
OsMoGroups grps = plugin.getGroups();
OsMoGroupsStorage.OsMoGroup mainGroup = null;
for (OsMoGroupsStorage.OsMoGroup grp : grps.getGroups()) {
ArrayList<OsMoGroupsStorage.OsMoGroup> groups = new ArrayList<>(grps.getGroups());
for (OsMoGroupsStorage.OsMoGroup grp : groups) {
if (grp.getGroupId() == null) {
mainGroup = grp;
groups.remove(grp);
break;
}
}
@ -153,17 +169,54 @@ public class DashOsmoFragment extends DashBaseFragment {
}
setupDeviceViews(contentList, devices);
if (devices.size() < 3 && groups.size() > 0) {
setupGroupsViews(3-devices.size(), groups, contentList);
}
}
private void setupGroupsViews(int toAddCount, ArrayList<OsMoGroupsStorage.OsMoGroup> groups, LinearLayout contentList) {
int counter = 1;
LayoutInflater inflater = getActivity().getLayoutInflater();
for (final OsMoGroupsStorage.OsMoGroup group : groups) {
View v = inflater.inflate(R.layout.dash_osmo_item, null, false);
v.findViewById(R.id.show_on_map).setVisibility(View.GONE);
v.findViewById(R.id.check_item).setVisibility(View.GONE);
final String name = group.getVisibleName(getActivity());
ImageView icon = (ImageView) v.findViewById(R.id.icon);
icon.setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_group));
((TextView) v.findViewById(R.id.name)).setText(name);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
launchOsMoGroupsActivity();
}
});
contentList.addView(v);
if (counter == toAddCount) {
return;
}
counter++;
}
}
private void setupDeviceViews(LinearLayout contentList, List<OsMoGroupsStorage.OsMoDevice> devices) {
Drawable markerIcon = getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_marker_dark);
LayoutInflater inflater = getActivity().getLayoutInflater();
for (final OsMoGroupsStorage.OsMoDevice device : devices) {
View v = inflater.inflate(R.layout.dash_osmo_item, null, false);
ImageButton showOnMap = (ImageButton)v.findViewById(R.id.show_on_map);
final ImageButton showOnMap = (ImageButton)v.findViewById(R.id.show_on_map);
showOnMap.setImageDrawable(markerIcon);
final String name = device.getVisibleName();
showOnMap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Location loc = device.getLastLocation();
if (loc == null){
Toast.makeText(getActivity(), R.string.osmo_device_not_found,Toast.LENGTH_SHORT).show();
return;
}
getMyApplication().getSettings().setMapLocationToShow(loc.getLatitude(),
loc.getLongitude(), 15,
new PointDescription(PointDescription.POINT_TYPE_MARKER, name),
@ -171,11 +224,65 @@ public class DashOsmoFragment extends DashBaseFragment {
MapActivity.launchMapActivityMoveToTop(getActivity());
}
});
final CompoundButton enableDevice = (CompoundButton) v.findViewById(R.id.check_item);
ImageView icon = (ImageView) v.findViewById(R.id.icon);
if (device.isEnabled()) {
enableDevice.setVisibility(View.GONE);
icon.setImageDrawable(getMyApplication().getIconsCache().
getPaintedContentIcon(R.drawable.ic_person, device.getColor()));
} else {
enableDevice.setVisibility(View.VISIBLE);
enableDevice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
plugin.getGroups().connectDevice(device);
refreshItems();
}
});
showOnMap.setVisibility(View.GONE);
icon.setImageDrawable(getMyApplication().getIconsCache().
getContentIcon(R.drawable.ic_person));
}
((TextView)v.findViewById(R.id.name)).setText(name);
if (device.isActive()){
}
((TextView) v.findViewById(R.id.name)).setText(name);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
launchOsMoGroupsActivity();
}
});
contentList.addView(v);
}
}
private void refreshItems() {
if (!uiHandler.hasMessages(OsMoGroupsActivity.LIST_REFRESH_MSG_ID)) {
Message msg = Message.obtain(uiHandler, new Runnable() {
@Override
public void run() {
updateConnectedDevices(getView());
}
});
msg.what = OsMoGroupsActivity.LIST_REFRESH_MSG_ID;
uiHandler.sendMessageDelayed(msg, 100);
}
}
private void launchOsMoGroupsActivity(){
Intent intent = new Intent(getActivity(), OsMoGroupsActivity.class);
getActivity().startActivity(intent);
}
@Override
public void groupsListChange(String operation, OsMoGroupsStorage.OsMoGroup group) {
updateConnectedDevices(getView());
}
@Override
public void deviceLocationChanged(OsMoGroupsStorage.OsMoDevice device) {
updateConnectedDevices(getView());
}
}

View file

@ -1,17 +1,11 @@
package net.osmand.plus.osmo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import android.text.TextUtils;
import net.osmand.Location;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoGroup;
import net.osmand.plus.osmo.OsMoTracker.OsmoTrackerListener;
@ -21,7 +15,13 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
@ -45,7 +45,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
private OsMoTracker tracker;
private OsMoService service;
private OsMoGroupsStorage storage;
private OsMoGroupsUIListener uiListener;
private ArrayList<OsMoGroupsUIListener> uiListeners = new ArrayList<>();
private OsMoPlugin plugin;
private OsmandApplication app;
@ -71,12 +71,14 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
}
}
public void setUiListener(OsMoGroupsUIListener uiListener) {
this.uiListener = uiListener;
public void addUiListeners(OsMoGroupsUIListener uiListener) {
if (!uiListeners.contains(uiListener)){
uiListeners.add(uiListener);
}
}
public OsMoGroupsUIListener getUiListener() {
return uiListener;
public void removeUiListener(OsMoGroupsUIListener uiListener) {
uiListeners.remove(uiListener);
}
private void connectDeviceImpl(OsMoDevice d) {
@ -161,8 +163,9 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
public void locationChange(String trackerId, Location location) {
for (OsMoGroup g : getGroups()) {
OsMoDevice d = g.updateLastLocation(trackerId, location);
if (d != null && uiListener != null) {
uiListener.deviceLocationChanged(d);
if (d != null && uiListeners != null) {
for(OsMoGroupsUIListener listener : uiListeners)
listener.deviceLocationChanged(d);
}
}
}
@ -353,8 +356,11 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
}
processed = true;
}
if(processed && uiListener != null) {
uiListener.groupsListChange(operation, group);
if(processed && uiListeners != null) {
for(OsMoGroupsUIListener listener : uiListeners){
listener.groupsListChange(operation, group);
}
}
return processed;
}

View file

@ -113,7 +113,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
protected static final int SETTINGS_ID = 9;
protected static final int SETTINGS_DEV_ID = 10;
protected static final int TRACK_DEV_ID = 11;
private static final int LIST_REFRESH_MSG_ID = OsmAndConstants.UI_HANDLER_SEARCH + 30;
public static final int LIST_REFRESH_MSG_ID = OsmAndConstants.UI_HANDLER_SEARCH + 30;
public static final long RECENT_THRESHOLD = 60000;
private boolean joinGroup;
@ -405,7 +405,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
}
app.getLocationProvider().addLocationListener(this);
app.getLocationProvider().resumeAllUpdates();
osMoPlugin.getGroups().setUiListener(this);
osMoPlugin.getGroups().addUiListeners(this);
if(osMoPlugin.getService().isConnected()) {
adapter.synchronizeGroups();
}
@ -420,7 +420,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
app.getLocationProvider().removeCompassListener(this);
}
app.getLocationProvider().removeLocationListener(this);
osMoPlugin.getGroups().setUiListener(null);
osMoPlugin.getGroups().addUiListeners(null);
osMoPlugin.setGroupsActivity(null);
}

View file

@ -187,14 +187,14 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor {
@Override
public void mapActivityPause(MapActivity activity) {
groups.setUiListener(null);
groups.addUiListeners(null);
mapActivity = activity;
}
@Override
public void mapActivityResume(MapActivity activity) {
if (olayer != null) {
groups.setUiListener(olayer);
groups.addUiListeners(olayer);
}
mapActivity = null;
}