diff --git a/OsmAnd/res/layout/fav_group_edit.xml b/OsmAnd/res/layout/fav_group_edit.xml new file mode 100644 index 0000000000..1374e002bc --- /dev/null +++ b/OsmAnd/res/layout/fav_group_edit.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/activities/FavouritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavouritesTreeFragment.java index 0d01d3d991..483d5d1bd3 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavouritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavouritesTreeFragment.java @@ -1,5 +1,7 @@ package net.osmand.plus.activities; +import gnu.trove.list.array.TIntArrayList; + import java.io.File; import java.text.MessageFormat; import java.util.ArrayList; @@ -24,6 +26,7 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.base.FavoriteImageDrawable; +import net.osmand.plus.helpers.ColorDialogs; import net.osmand.util.MapUtils; import android.app.Activity; import android.app.AlertDialog; @@ -39,6 +42,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.CheckBox; @@ -47,8 +51,10 @@ import android.widget.ExpandableListView; import android.widget.Filter; import android.widget.Filterable; import android.widget.ImageView; +import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; +import android.widget.AdapterView.OnItemSelectedListener; import com.actionbarsherlock.view.ActionMode; import com.actionbarsherlock.view.ActionMode.Callback; @@ -79,7 +85,6 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment { private ActionMode actionMode; private SearchView searchView; protected boolean hideActionBar; - private int defColor; @Override public void onAttach(Activity activity) { @@ -87,7 +92,6 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment { helper = getMyApplication().getFavorites(); favouritesAdapter = new FavouritesAdapter(); - defColor = getResources().getColor(R.color.color_favorite); favouritesAdapter.synchronizeGroups(); setAdapter(favouritesAdapter); } @@ -451,8 +455,26 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment { } - protected void openChangeGroupDialog() { - // TODO Auto-generated method stub + protected void openChangeGroupDialog(FavoriteGroup group) { + Builder bld = new AlertDialog.Builder(getActivity()); + View favEdit = getActivity().getLayoutInflater().inflate(R.layout.fav_group_edit, null); + final Spinner colorSpinner = (Spinner) favEdit.findViewById(R.id.ColorSpinner); + final TIntArrayList list = new TIntArrayList(); + ColorDialogs.setupColorSpinner(getActivity(), group.color, colorSpinner, list); + + CheckBox checkBox = (CheckBox) favEdit.findViewById(R.id.Visibility); + checkBox.setChecked(group.visible); + bld.setView(favEdit); + bld.setNegativeButton(R.string.default_buttons_cancel, null); + bld.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + list.get(colorSpinner.getSelectedItemPosition()); + + } + }); + bld.show(); } @@ -475,41 +497,6 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment { } } - private void importFile() { - final File tosave = getMyApplication().getAppPath(FavouritesDbHelper.FILE_TO_SAVE); - if (!tosave.exists()) { - AccessibleToast.makeText(getActivity(), - MessageFormat.format(getString(R.string.fav_file_to_load_not_found), tosave.getAbsolutePath()), - Toast.LENGTH_LONG).show(); - } else { - new AsyncTask() { - - @Override - protected String doInBackground(Void... params) { - // helper.loadGPXFile(getMyApplication(), tosave, this); - return null ; - } - - @Override - protected void onPreExecute() { - showProgressBar(); - }; - - @Override - protected void onPostExecute(String warning) { - hideProgressBar(); - if (warning == null) { - AccessibleToast.makeText(getActivity(), R.string.fav_imported_sucessfully, Toast.LENGTH_SHORT) - .show(); - } else { - AccessibleToast.makeText(getActivity(), warning, Toast.LENGTH_LONG).show(); - } - favouritesAdapter.synchronizeGroups(); - }; - - }.execute(); - } - } private void shareFavourites() { if (favouritesAdapter.isEmpty()) { @@ -542,7 +529,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment { } } - private void export() { + protected void export() { final File tosave = getMyApplication().getAppPath(FavouritesDbHelper.FILE_TO_SAVE); if (favouritesAdapter.isEmpty()) { AccessibleToast.makeText(getActivity(), R.string.no_fav_to_save, Toast.LENGTH_LONG).show(); @@ -726,7 +713,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment { ch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - openChangeGroupDialog(); + openChangeGroupDialog(model); } }); diff --git a/OsmAnd/src/net/osmand/plus/helpers/ColorDialogs.java b/OsmAnd/src/net/osmand/plus/helpers/ColorDialogs.java new file mode 100644 index 0000000000..55cf6e4f93 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/helpers/ColorDialogs.java @@ -0,0 +1,104 @@ +package net.osmand.plus.helpers; + +import gnu.trove.list.array.TIntArrayList; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.osmand.plus.R; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Spinner; +import android.widget.TextView; + +public class ColorDialogs { + public static int[] paletteColors = new int[] { + R.string.color_red, + R.string.color_pink, + R.string.color_orange, + R.string.color_brown, + R.string.color_yellow, + R.string.color_lightblue, + R.string.color_blue, + R.string.color_green + }; + + public static int[] pallette = new int[] { + 0xffd00d0d, + 0xffe044bb, + 0xffff5020, + 0xff8e2512, + 0xffeeee10, + 0xff10c0f0, + 0xff1010a0, + 0xff88e030 + }; + + + public static void setupColorSpinner(Context ctx, int selectedColor, final Spinner colorSpinner, + final TIntArrayList colors) { + OnItemSelectedListener listener = new OnItemSelectedListener() { + + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + View v = parent.getChildAt(0); + if(v instanceof TextView) { + ((TextView) v).setTextColor(colors.get(position)); + } + colorSpinner.invalidate(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + + }; + colors.add(pallette); + List colorNames= new ArrayList(); + int selection = -1; + for(int i = 0; i < pallette.length; i++) { + colorNames.add(ctx.getString(paletteColors[i])); + colors.add(pallette[i]); + if(selectedColor == pallette[i]) { + selection = i; + } + } + if(selection == -1) { + colors.insert(0, selectedColor); + colorNames.add(0, colorToString(selectedColor)); + selection = 0; + } + ArrayAdapter adapter = new ArrayAdapter(ctx, android.R.layout.simple_spinner_item, colorNames) { + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View v = super.getView(position, convertView, parent); + if(v instanceof TextView) { + ((TextView) v).setTextColor(colors.get(position)); + } + return v; + } + }; + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + colorSpinner.setAdapter(adapter); + colorSpinner.setOnItemSelectedListener(listener); + colorSpinner.setSelection(selection); + } + + public static int getRandomColor() { + return pallette[new Random().nextInt(pallette.length)]; + } + + public static String colorToString(int color) { + if ((0xFF000000 & color) == 0xFF000000) { + return "#" + Integer.toHexString(color & 0x00FFFFFF); //$NON-NLS-1$ + } else { + return "#" + Integer.toHexString(color); //$NON-NLS-1$ + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java index 2dac4badcb..ffb8a71b37 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java @@ -32,6 +32,7 @@ import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandExpandableListActivity; import net.osmand.plus.activities.actions.ShareDialog; import net.osmand.plus.base.MapViewTrackingUtilities; +import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.osmo.OsMoGroups.OsMoGroupsUIListener; import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice; import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoGroup; @@ -123,28 +124,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements private String operation; private Paint white; - private int[] paletteColors = new int[] { - R.string.color_red, - R.string.color_pink, - R.string.color_orange, - R.string.color_brown, - R.string.color_yellow, - R.string.color_lightblue, - R.string.color_blue, - R.string.color_green - }; - private int[] pallette = new int[] { - 0xffd00d0d, - 0xffe044bb, - 0xffff5020, - 0xff8e2512, - 0xffeeee10, - 0xff10c0f0, - 0xff1010a0, - 0xff88e030 - }; - @Override public void onCreate(Bundle icicle) { // This has to be called before setContentView and you must use the @@ -697,7 +677,8 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements final String id = tracker.getText().toString(); final String nick = nickname.getText().toString(); if(device.isChecked()) { - OsMoDevice dev = osMoPlugin.getGroups().addConnectedDevice(id, nameUser, getRandomColor()); + OsMoDevice dev = osMoPlugin.getGroups().addConnectedDevice(id, nameUser, + ColorDialogs.getRandomColor()); adapter.update(dev.group); adapter.notifyDataSetChanged(); } else { @@ -972,7 +953,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements int color = getResources().getColor(R.color.color_unknown); int activeColor = model.getColor(); if (activeColor == 0) { - activeColor = getRandomColor(); + activeColor = ColorDialogs.getRandomColor(); osMoPlugin.getGroups().setGenColor(model, activeColor); } //Location location = tracker.getLastLocation(model.trackerId); @@ -1053,9 +1034,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements } } - private int getRandomColor() { - return pallette[new Random().nextInt(pallette.length)]; - } + @Override public void updateCompassValue(float value) { @@ -1087,13 +1066,6 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements refreshList(); } - public static String colorToString(int color) { - if ((0xFF000000 & color) == 0xFF000000) { - return "#" + Integer.toHexString(color & 0x00FFFFFF); //$NON-NLS-1$ - } else { - return "#" + Integer.toHexString(color); //$NON-NLS-1$ - } - } private void showSettingsDialog(final OsMoDevice device) { Builder bld = new AlertDialog.Builder(OsMoGroupsActivity.this); @@ -1101,61 +1073,18 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements final LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.osmo_edit_device, null); final EditText name = (EditText) view.findViewById(R.id.Name); - final Spinner colorSpinner = (Spinner) view.findViewById(R.id.ColorSpinner); + if(device.getColor() == 0) { + osMoPlugin.getGroups().setDeviceProperties(device, device.getVisibleName(), + ColorDialogs.getRandomColor()); + } + int devColor = device.getColor(); bld.setView(view); name.setText(device.getVisibleName()); - final TIntArrayList list = new TIntArrayList(pallette); - List colorNames= new ArrayList(); - int selection = -1; - if(device.getColor() == 0) { - osMoPlugin.getGroups().setDeviceProperties(device, device.getVisibleName(), getRandomColor()); - } - int devColor = device.getColor(); - - for(int i = 0; i < pallette.length; i++) { - colorNames.add(getString(paletteColors[i])); - list.add(pallette[i]); - if(devColor == pallette[i]) { - selection = i; - } - } - if(selection == -1) { - list.insert(0, devColor); - colorNames.add(0, colorToString(devColor)); - selection = 0; - } - ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, colorNames) { - @Override - public View getView(int position, View convertView, ViewGroup parent) { - View v = super.getView(position, convertView, parent); - if(v instanceof TextView) { - ((TextView) v).setTextColor(list.get(position)); - } - return v; - } - }; - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + final Spinner colorSpinner = (Spinner) view.findViewById(R.id.ColorSpinner); + final TIntArrayList list = new TIntArrayList(); + ColorDialogs.setupColorSpinner(this, devColor, colorSpinner, list); - colorSpinner.setAdapter(adapter); - - colorSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { - - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - View v = parent.getChildAt(0); - if(v instanceof TextView) { - ((TextView) v).setTextColor(list.get(position)); - } - colorSpinner.invalidate(); - } - - @Override - public void onNothingSelected(AdapterView parent) { - } - - }); - colorSpinner.setSelection(selection); bld.setPositiveButton(R.string .default_buttons_yes, new DialogInterface.OnClickListener() { @Override @@ -1167,6 +1096,8 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements bld.setNegativeButton(R.string.default_buttons_no, null); bld.show(); } + + class NonDirectionDrawable extends Drawable { Paint paintRouteDirection;