mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Revert menu icon color for froyo phones
This commit is contained in:
@@ -17,10 +17,12 @@
|
||||
package com.google.android.apps.mytracks;
|
||||
|
||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import com.google.android.apps.mytracks.util.TrackIconUtils;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
/**
|
||||
@@ -74,6 +76,12 @@ public abstract class AbstractMyTracksActivity extends FragmentActivity {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
TrackIconUtils.setMenuIconColor(menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
|
||||
@@ -248,7 +248,7 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
|
||||
insertMarkerMenuItem = menu.findItem(R.id.marker_list_insert_marker);
|
||||
searchMenuItem = menu.findItem(R.id.marker_list_search);
|
||||
ApiAdapterFactory.getApiAdapter().configureSearchWidget(this, searchMenuItem, null);
|
||||
return true;
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -289,7 +289,7 @@ public class SearchListActivity extends AbstractSendToGoogleActivity implements
|
||||
getMenuInflater().inflate(R.menu.search_list, menu);
|
||||
searchMenuItem = menu.findItem(R.id.search_list_search);
|
||||
ApiAdapterFactory.getApiAdapter().configureSearchWidget(this, searchMenuItem, null);
|
||||
return true;
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -380,7 +380,7 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
||||
voiceFrequencyMenuItem = menu.findItem(R.id.track_detail_voice_frequency);
|
||||
splitFrequencyMenuItem = menu.findItem(R.id.track_detail_split_frequency);
|
||||
sensorStateMenuItem = menu.findItem(R.id.track_detail_sensor_state);
|
||||
return true;
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -474,7 +474,8 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
exportAllMenuItem = menu.findItem(R.id.track_list_export_all);
|
||||
importAllMenuItem = menu.findItem(R.id.track_list_import_all);
|
||||
deleteAllMenuItem = menu.findItem(R.id.track_list_delete_all);
|
||||
return true;
|
||||
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -739,6 +740,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
startGpsMenuItem.setTitle(isGpsStarted ? R.string.menu_stop_gps : R.string.menu_start_gps);
|
||||
startGpsMenuItem.setIcon(
|
||||
isGpsStarted ? R.drawable.ic_menu_stop_gps : R.drawable.ic_menu_start_gps);
|
||||
TrackIconUtils.setMenuIconColor(startGpsMenuItem);
|
||||
}
|
||||
}
|
||||
if (refreshMenuItem != null) {
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.apps.mytracks.util.PhotoUtils;
|
||||
import com.google.android.apps.mytracks.util.StatsUtils;
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackIconUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Intent;
|
||||
@@ -113,12 +114,12 @@ public class MarkerDetailFragment extends Fragment {
|
||||
}
|
||||
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(getActivity());
|
||||
handler = new Handler();
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(
|
||||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
setHasOptionsMenu(true);
|
||||
View view = inflater.inflate(R.layout.marker_detail_fragment, container, false);
|
||||
|
||||
photo = (ImageView) view.findViewById(R.id.marker_detail_waypoint_photo);
|
||||
@@ -187,8 +188,10 @@ public class MarkerDetailFragment extends Fragment {
|
||||
String photoUrl = waypoint.getPhotoUrl();
|
||||
boolean hasPhoto = photoUrl != null && !photoUrl.equals("");
|
||||
menu.findItem(R.id.marker_detail_view_photo).setVisible(hasPhoto);
|
||||
|
||||
TrackIconUtils.setMenuIconColor(menu);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
long markerId = getArguments().getLong(KEY_MARKER_ID);
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.google.android.apps.mytracks.util.GoogleLocationUtils;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackIconUtils;
|
||||
import com.google.android.gms.location.LocationListener;
|
||||
import com.google.android.gms.maps.CameraUpdate;
|
||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||
@@ -330,6 +331,7 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflator) {
|
||||
menuInflator.inflate(R.menu.map, menu);
|
||||
TrackIconUtils.setMenuIconColor(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -78,6 +78,11 @@ public class Api8Adapter implements ApiAdapter {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revertMenuIconColor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BluetoothSocket getBluetoothSocket(BluetoothDevice bluetoothDevice) throws IOException {
|
||||
try {
|
||||
|
||||
@@ -69,4 +69,9 @@ public class Api9Adapter extends Api8Adapter {
|
||||
public boolean isGeoCoderPresent() {
|
||||
return Geocoder.isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revertMenuIconColor() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,13 @@ public interface ApiAdapter {
|
||||
*/
|
||||
public boolean isGeoCoderPresent();
|
||||
|
||||
/**
|
||||
* Returns true to revert menu icon color.
|
||||
* <p>
|
||||
* Due to changes in API level 9.
|
||||
*/
|
||||
public boolean revertMenuIconColor();
|
||||
|
||||
/**
|
||||
* Gets a {@link BluetoothSocket}.
|
||||
* <p>
|
||||
|
||||
@@ -21,7 +21,11 @@ import com.google.android.maps.mytracks.R;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Pair;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
@@ -33,92 +37,96 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Utilities for track icon.
|
||||
*
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class TrackIconUtils {
|
||||
|
||||
private static final String AIRPLANE = "AIRPLANE";
|
||||
public static final String AIRPLANE = "AIRPLANE";
|
||||
public static final String BIKE = "BIKE";
|
||||
private static final String BOAT = "BOAT";
|
||||
public static final String BOAT = "BOAT";
|
||||
public static final String DRIVE = "DRIVE";
|
||||
public static final String RUN = "RUN";
|
||||
private static final String SKI = "SKI";
|
||||
private static final String SNOW_BOARDING = "SNOW_BOARDING";
|
||||
public static final String SKI = "SKI";
|
||||
public static final String SNOW_BOARDING = "SNOW_BOARDING";
|
||||
public static final String WALK = "WALK";
|
||||
|
||||
private TrackIconUtils() {}
|
||||
private static final int[] AIRPLANE_LIST = new int[] { R.string.activity_type_airplane,
|
||||
R.string.activity_type_commercial_airplane, R.string.activity_type_rc_airplane };
|
||||
private static final int[] BIKE_LIST = new int[] { R.string.activity_type_biking,
|
||||
R.string.activity_type_cycling, R.string.activity_type_dirt_bike,
|
||||
R.string.activity_type_motor_bike, R.string.activity_type_mountain_biking,
|
||||
R.string.activity_type_road_biking, R.string.activity_type_track_cycling };
|
||||
private static final int[] BOAT_LIST = new int[] { R.string.activity_type_boat,
|
||||
R.string.activity_type_ferry, R.string.activity_type_motor_boating,
|
||||
R.string.activity_type_rc_boat };
|
||||
private static final int[] DRIVE_LIST = new int[] { R.string.activity_type_atv,
|
||||
R.string.activity_type_driving, R.string.activity_type_driving_bus,
|
||||
R.string.activity_type_driving_car };
|
||||
private static final int[] RUN_LIST = new int[] { R.string.activity_type_running,
|
||||
R.string.activity_type_street_running, R.string.activity_type_track_running,
|
||||
R.string.activity_type_trail_running };
|
||||
private static final int[] SKI_LIST = new int[] {
|
||||
R.string.activity_type_cross_country_skiing, R.string.activity_type_skiing };
|
||||
private static final int[] SNOW_BOARDING_LIST = new int[] {
|
||||
R.string.activity_type_snow_boarding };
|
||||
private static final int[] WALK_LIST = new int[] { R.string.activity_type_hiking,
|
||||
R.string.activity_type_off_trail_hiking, R.string.activity_type_speed_walking,
|
||||
R.string.activity_type_trail_hiking, R.string.activity_type_walking };
|
||||
|
||||
private static LinkedHashMap<String, Pair<Integer, Integer>> map =
|
||||
new LinkedHashMap<String, Pair<Integer, Integer>>();
|
||||
private static final LinkedHashMap<String, Pair<Integer, Integer>>
|
||||
MAP = new LinkedHashMap<String, Pair<Integer, Integer>>();
|
||||
|
||||
static {
|
||||
map.put(
|
||||
MAP.put(
|
||||
RUN, new Pair<Integer, Integer>(R.string.activity_type_running, R.drawable.ic_track_run));
|
||||
map.put(
|
||||
MAP.put(
|
||||
WALK, new Pair<Integer, Integer>(R.string.activity_type_walking, R.drawable.ic_track_walk));
|
||||
map.put(
|
||||
MAP.put(
|
||||
BIKE, new Pair<Integer, Integer>(R.string.activity_type_biking, R.drawable.ic_track_bike));
|
||||
map.put(DRIVE,
|
||||
MAP.put(DRIVE,
|
||||
new Pair<Integer, Integer>(R.string.activity_type_driving, R.drawable.ic_track_drive));
|
||||
map.put(
|
||||
MAP.put(
|
||||
SKI, new Pair<Integer, Integer>(R.string.activity_type_skiing, R.drawable.ic_track_ski));
|
||||
map.put(SNOW_BOARDING, new Pair<Integer, Integer>(
|
||||
MAP.put(SNOW_BOARDING, new Pair<Integer, Integer>(
|
||||
R.string.activity_type_snow_boarding, R.drawable.ic_track_snow_boarding));
|
||||
map.put(AIRPLANE,
|
||||
MAP.put(AIRPLANE,
|
||||
new Pair<Integer, Integer>(R.string.activity_type_airplane, R.drawable.ic_track_airplane));
|
||||
map.put(
|
||||
MAP.put(
|
||||
BOAT, new Pair<Integer, Integer>(R.string.activity_type_boat, R.drawable.ic_track_boat));
|
||||
}
|
||||
|
||||
private static int[] airplane = new int[] {
|
||||
R.string.activity_type_airplane, R.string.activity_type_commercial_airplane,
|
||||
R.string.activity_type_rc_airplane};
|
||||
private static int[] bike = new int[] {R.string.activity_type_biking,
|
||||
R.string.activity_type_cycling,
|
||||
R.string.activity_type_dirt_bike,
|
||||
R.string.activity_type_motor_bike,
|
||||
R.string.activity_type_mountain_biking,
|
||||
R.string.activity_type_road_biking,
|
||||
R.string.activity_type_track_cycling};
|
||||
private static int[] boat = new int[] {R.string.activity_type_boat, R.string.activity_type_ferry,
|
||||
R.string.activity_type_motor_boating, R.string.activity_type_rc_boat};
|
||||
private static int[] drive = new int[] {
|
||||
R.string.activity_type_atv, R.string.activity_type_driving,
|
||||
R.string.activity_type_driving_bus, R.string.activity_type_driving_car};
|
||||
private static int[] run = new int[] {
|
||||
R.string.activity_type_running, R.string.activity_type_street_running,
|
||||
R.string.activity_type_track_running, R.string.activity_type_trail_running};
|
||||
private static int[] ski =
|
||||
new int[] {R.string.activity_type_cross_country_skiing, R.string.activity_type_skiing};
|
||||
private static int[] snowBoarding = new int[] {R.string.activity_type_snow_boarding};
|
||||
private static int[] walk = new int[] {R.string.activity_type_hiking,
|
||||
R.string.activity_type_off_trail_hiking, R.string.activity_type_speed_walking,
|
||||
R.string.activity_type_trail_hiking, R.string.activity_type_walking};
|
||||
private static final float[] REVERT_COLOR_MATRIX = { -1.0f, 0, 0, 0, 255, // red
|
||||
0, -1.0f, 0, 0, 255, // green
|
||||
0, 0, -1.0f, 0, 255, // blue
|
||||
0, 0, 0, 1.0f, 0 // alpha
|
||||
};
|
||||
|
||||
private TrackIconUtils() {}
|
||||
|
||||
/**
|
||||
* Gets the icon drawable.
|
||||
*
|
||||
*
|
||||
* @param iconValue the icon value
|
||||
*/
|
||||
public static int getIconDrawable(String iconValue) {
|
||||
if (iconValue == null || iconValue.equals("")) {
|
||||
return R.drawable.ic_track_generic;
|
||||
}
|
||||
Pair<Integer, Integer> pair = map.get(iconValue);
|
||||
Pair<Integer, Integer> pair = MAP.get(iconValue);
|
||||
return pair == null ? R.drawable.ic_track_generic : pair.second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon activity type.
|
||||
*
|
||||
*
|
||||
* @param iconValue the icon value
|
||||
*/
|
||||
public static int getIconActivityType(String iconValue) {
|
||||
if (iconValue == null || iconValue.equals("")) {
|
||||
return R.string.activity_type_walking;
|
||||
}
|
||||
Pair<Integer, Integer> pair = map.get(iconValue);
|
||||
Pair<Integer, Integer> pair = MAP.get(iconValue);
|
||||
return pair == null ? R.string.activity_type_walking : pair.first;
|
||||
}
|
||||
|
||||
@@ -127,7 +135,7 @@ public class TrackIconUtils {
|
||||
*/
|
||||
public static List<String> getAllIconValues() {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (String value : map.keySet()) {
|
||||
for (String value : MAP.keySet()) {
|
||||
values.add(value);
|
||||
}
|
||||
return values;
|
||||
@@ -135,7 +143,7 @@ public class TrackIconUtils {
|
||||
|
||||
/**
|
||||
* Gets the icon value.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param activityType the activity type
|
||||
*/
|
||||
@@ -143,28 +151,28 @@ public class TrackIconUtils {
|
||||
if (activityType == null || activityType.equals("")) {
|
||||
return "";
|
||||
}
|
||||
if (inList(context, activityType, airplane)) {
|
||||
if (inList(context, activityType, AIRPLANE_LIST)) {
|
||||
return AIRPLANE;
|
||||
}
|
||||
if (inList(context, activityType, bike)) {
|
||||
if (inList(context, activityType, BIKE_LIST)) {
|
||||
return BIKE;
|
||||
}
|
||||
if (inList(context, activityType, boat)) {
|
||||
if (inList(context, activityType, BOAT_LIST)) {
|
||||
return BOAT;
|
||||
}
|
||||
if (inList(context, activityType, drive)) {
|
||||
if (inList(context, activityType, DRIVE_LIST)) {
|
||||
return DRIVE;
|
||||
}
|
||||
if (inList(context, activityType, run)) {
|
||||
if (inList(context, activityType, RUN_LIST)) {
|
||||
return RUN;
|
||||
}
|
||||
if (inList(context, activityType, ski)) {
|
||||
if (inList(context, activityType, SKI_LIST)) {
|
||||
return SKI;
|
||||
}
|
||||
if (inList(context, activityType, snowBoarding)) {
|
||||
if (inList(context, activityType, SNOW_BOARDING_LIST)) {
|
||||
return SNOW_BOARDING;
|
||||
}
|
||||
if (inList(context, activityType, walk)) {
|
||||
if (inList(context, activityType, WALK_LIST)) {
|
||||
return WALK;
|
||||
}
|
||||
return "";
|
||||
@@ -178,7 +186,7 @@ public class TrackIconUtils {
|
||||
stringBuilder.append(iconValue);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
public static ArrayAdapter<StringBuilder> getIconSpinnerAdapter(
|
||||
final Context context, String iconValue) {
|
||||
return new ArrayAdapter<StringBuilder>(context, android.R.layout.simple_spinner_item,
|
||||
@@ -198,7 +206,7 @@ public class TrackIconUtils {
|
||||
|
||||
/**
|
||||
* Returns true if the activity type is in the list.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param activityType the activity type
|
||||
* @param list the list
|
||||
@@ -211,4 +219,40 @@ public class TrackIconUtils {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the menu icon color.
|
||||
*
|
||||
* @param menu the menu
|
||||
*/
|
||||
public static void setMenuIconColor(Menu menu) {
|
||||
if (ApiAdapterFactory.getApiAdapter().revertMenuIconColor()) {
|
||||
int size = menu.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
MenuItem menuitem = menu.getItem(i);
|
||||
revertMenuIconColor(menuitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the menu icon color.
|
||||
*
|
||||
* @param menuitem the menu item
|
||||
*/
|
||||
public static void setMenuIconColor(MenuItem menuitem) {
|
||||
if (ApiAdapterFactory.getApiAdapter().revertMenuIconColor()) {
|
||||
revertMenuIconColor(menuitem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverts the menu icon color.
|
||||
*
|
||||
* @param menuitem the menu item
|
||||
*/
|
||||
private static void revertMenuIconColor(MenuItem menuitem) {
|
||||
Drawable drawable = menuitem.getIcon();
|
||||
drawable.setColorFilter(new ColorMatrixColorFilter(REVERT_COLOR_MATRIX));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user