Change track icon based on activity type.
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 55 KiB |
|
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
@@ -25,8 +25,7 @@ limitations under the License.
|
||||
android:contentDescription="@string/icon_track"
|
||||
android:id="@+id/list_item_icon"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:src="@drawable/track" />
|
||||
android:layout_width="wrap_content" />
|
||||
<LinearLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
|
||||
@@ -37,7 +37,7 @@ limitations under the License.
|
||||
android:hint="@string/generic_name"
|
||||
android:id="@+id/marker_edit_statistics_name"
|
||||
android:imeOptions="actionDone"
|
||||
style="@style/EditName" />
|
||||
style="@style/EditNameMarker" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/marker_edit_waypoint_section"
|
||||
@@ -49,7 +49,7 @@ limitations under the License.
|
||||
android:hint="@string/generic_name"
|
||||
android:id="@+id/marker_edit_waypoint_name"
|
||||
android:imeOptions="actionNext"
|
||||
style="@style/EditName" />
|
||||
style="@style/EditNameMarker" />
|
||||
<TextView
|
||||
android:text="@string/marker_edit_marker_type"
|
||||
style="@style/EditLabel.WithPaddingTop" />
|
||||
@@ -57,7 +57,7 @@ limitations under the License.
|
||||
android:hint="@string/marker_edit_marker_type_hint"
|
||||
android:id="@+id/marker_edit_waypoint_marker_type"
|
||||
android:imeOptions="actionNext"
|
||||
style="@style/EditCategory" />
|
||||
style="@style/EditCategoryMarker" />
|
||||
<TextView
|
||||
android:text="@string/generic_description"
|
||||
style="@style/EditLabel.WithPaddingTop" />
|
||||
|
||||
@@ -28,11 +28,10 @@ limitations under the License.
|
||||
android:text="@string/generic_name"
|
||||
style="@style/EditLabel" />
|
||||
<EditText
|
||||
android:drawableLeft="@drawable/track"
|
||||
android:hint="@string/generic_name"
|
||||
android:id="@+id/track_edit_name"
|
||||
android:imeOptions="actionNext"
|
||||
style="@style/EditName" />
|
||||
style="@style/EditNameTrack" />
|
||||
<TextView
|
||||
android:text="@string/track_edit_activity_type"
|
||||
style="@style/EditLabel.WithPaddingTop" />
|
||||
@@ -40,7 +39,7 @@ limitations under the License.
|
||||
android:hint="@string/track_edit_activity_type_hint"
|
||||
android:id="@+id/track_edit_activity_type"
|
||||
android:imeOptions="actionNext"
|
||||
style="@style/EditCategory" />
|
||||
style="@style/EditCategoryTrack" />
|
||||
<TextView
|
||||
android:text="@string/generic_description"
|
||||
style="@style/EditLabel.WithPaddingTop" />
|
||||
|
||||
@@ -27,6 +27,7 @@ limitations under the License.
|
||||
<item>@string/activity_type_cycling</item>
|
||||
<item>@string/activity_type_dirt_bike</item>
|
||||
<item>@string/activity_type_donkey_back_riding</item>
|
||||
<item>@string/activity_type_driving</item>
|
||||
<item>@string/activity_type_driving_bus</item>
|
||||
<item>@string/activity_type_driving_car</item>
|
||||
<item>@string/activity_type_ferry</item>
|
||||
|
||||
@@ -93,6 +93,11 @@ limitations under the License.
|
||||
completion suggestion for donkey back riding.">
|
||||
donkey back riding
|
||||
</string>
|
||||
<string name="activity_type_driving"
|
||||
translation_description="When entering an 'Activity type', in the auto-complete text box, the
|
||||
completion suggestion for driving.">
|
||||
driving
|
||||
</string>
|
||||
<string name="activity_type_driving_bus"
|
||||
translation_description="When entering an 'Activity type', in the auto-complete text box, the
|
||||
completion suggestion for driving bus.">
|
||||
|
||||
@@ -43,8 +43,14 @@ limitations under the License.
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
</style>
|
||||
<!-- The style for the edit category -->
|
||||
<style name="EditCategory" parent="@style/TextMedium">
|
||||
<!-- The style for the editing marker category -->
|
||||
<style name="EditCategoryMarker" parent="@style/TextMedium">
|
||||
<item name="android:layout_width">fill_parent</item>
|
||||
<item name="android:selectAllOnFocus">true</item>
|
||||
<item name="android:singleLine">true</item>
|
||||
</style>
|
||||
<!-- The style for the editing track category -->
|
||||
<style name="EditCategoryTrack" parent="@style/TextMedium.WithIcon">
|
||||
<item name="android:layout_width">fill_parent</item>
|
||||
<item name="android:selectAllOnFocus">true</item>
|
||||
<item name="android:singleLine">true</item>
|
||||
@@ -63,8 +69,15 @@ limitations under the License.
|
||||
<style name="EditLabel.WithPaddingTop">
|
||||
<item name="android:paddingTop">16dp</item>
|
||||
</style>
|
||||
<!-- The style for the edit name -->
|
||||
<style name="EditName" parent="@style/TextMedium.WithIcon">
|
||||
<!-- The style for editing marker name -->
|
||||
<style name="EditNameMarker" parent="@style/TextMedium.WithIcon">
|
||||
<item name="android:inputType">textAutoCorrect|textCapWords</item>
|
||||
<item name="android:layout_width">fill_parent</item>
|
||||
<item name="android:selectAllOnFocus">true</item>
|
||||
<item name="android:singleLine">true</item>
|
||||
</style>
|
||||
<!-- The style for editing track name -->
|
||||
<style name="EditNameTrack" parent="@style/TextMedium">
|
||||
<item name="android:inputType">textAutoCorrect|textCapWords</item>
|
||||
<item name="android:layout_width">fill_parent</item>
|
||||
<item name="android:selectAllOnFocus">true</item>
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.apps.mytracks.util.ListItemUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackIconUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
@@ -421,7 +422,8 @@ public class SearchListActivity extends AbstractMyTracksActivity implements Dele
|
||||
boolean isRecording = track.getId() == recordingTrackId;
|
||||
TripStatistics tripStatitics = track.getTripStatistics();
|
||||
resultMap.put(NAME_FIELD, track.getName());
|
||||
resultMap.put(ICON_FIELD, isRecording ? R.drawable.menu_record_track : R.drawable.track);
|
||||
resultMap.put(ICON_FIELD, isRecording
|
||||
? R.drawable.menu_record_track : TrackIconUtils.getIconDrawable(track.getIcon()));
|
||||
resultMap.put(ICON_CONTENT_DESCRIPTION_FIELD, getString(isRecording ? R.string.icon_recording
|
||||
: R.string.icon_track));
|
||||
resultMap.put(CATEGORY_FIELD, track.getCategory());
|
||||
|
||||
@@ -18,12 +18,14 @@ package com.google.android.apps.mytracks;
|
||||
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.util.TrackIconUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackNameUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
@@ -75,10 +77,30 @@ public class TrackEditActivity extends AbstractMyTracksActivity {
|
||||
|
||||
activityType = (AutoCompleteTextView) findViewById(R.id.track_edit_activity_type);
|
||||
activityType.setText(track.getCategory());
|
||||
|
||||
setActivityTypeIcon(track.getIcon());
|
||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
|
||||
this, R.array.activity_types, android.R.layout.simple_dropdown_item_1line);
|
||||
activityType.setAdapter(adapter);
|
||||
activityType.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
String iconValue = TrackIconUtils.getIconValue(
|
||||
TrackEditActivity.this, (String) activityType.getAdapter().getItem(position));
|
||||
setActivityTypeIcon(iconValue);
|
||||
}
|
||||
});
|
||||
activityType.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (!hasFocus) {
|
||||
String iconValue = TrackIconUtils.getIconValue(
|
||||
TrackEditActivity.this, activityType.getText().toString());
|
||||
setActivityTypeIcon(iconValue);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
description = (EditText) findViewById(R.id.track_edit_description);
|
||||
description.setText(track.getDescription());
|
||||
|
||||
@@ -87,7 +109,9 @@ public class TrackEditActivity extends AbstractMyTracksActivity {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
track.setName(name.getText().toString());
|
||||
track.setCategory(activityType.getText().toString());
|
||||
String category = activityType.getText().toString();
|
||||
track.setCategory(category);
|
||||
track.setIcon(TrackIconUtils.getIconValue(TrackEditActivity.this, category));
|
||||
track.setDescription(description.getText().toString());
|
||||
myTracksProviderUtils.updateTrack(track);
|
||||
finish();
|
||||
@@ -114,4 +138,14 @@ public class TrackEditActivity extends AbstractMyTracksActivity {
|
||||
cancel.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the activity type icon.
|
||||
*
|
||||
* @param iconValue the icon value
|
||||
*/
|
||||
private void setActivityTypeIcon(String iconValue) {
|
||||
activityType.setCompoundDrawablesWithIntrinsicBounds(
|
||||
TrackIconUtils.getIconDrawable(iconValue), 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.apps.mytracks.util.ListItemUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackIconUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
@@ -221,7 +222,8 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac
|
||||
|
||||
boolean isRecording = cursor.getLong(idIndex) == recordingTrackId;
|
||||
String name = cursor.getString(nameIndex);
|
||||
int iconId = isRecording ? R.drawable.menu_record_track : R.drawable.track;
|
||||
int iconId = isRecording ? R.drawable.menu_record_track
|
||||
: TrackIconUtils.getIconDrawable(cursor.getString(iconIndex));
|
||||
String iconContentDescription = getString(isRecording ? R.string.icon_recording
|
||||
: R.string.icon_track);
|
||||
String category = cursor.getString(categoryIndex);
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Utilities for track icon.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class TrackIconUtils {
|
||||
|
||||
private static final String BIKE = "BIKE";
|
||||
private static final String DRIVE = "DRIVE";
|
||||
private static final String RUN = "RUN";
|
||||
private static final String SKI = "SKI";
|
||||
private static final String WALK = "WALK";
|
||||
|
||||
private TrackIconUtils() {}
|
||||
|
||||
private static HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||
|
||||
static {
|
||||
map.put(BIKE, R.drawable.track_bike);
|
||||
map.put(DRIVE, R.drawable.track_drive);
|
||||
map.put(RUN, R.drawable.track_run);
|
||||
map.put(SKI, R.drawable.track_ski);
|
||||
map.put(WALK, R.drawable.track_walk);
|
||||
}
|
||||
|
||||
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[] 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[] 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 };
|
||||
|
||||
/**
|
||||
* Gets the icon drawable.
|
||||
*
|
||||
* @param iconValue the icon value
|
||||
*/
|
||||
public static int getIconDrawable(String iconValue) {
|
||||
if (iconValue == null || iconValue.equals("")) {
|
||||
return R.drawable.track_walk;
|
||||
}
|
||||
Integer drawable = map.get(iconValue);
|
||||
return drawable == null ? R.drawable.track_walk : drawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon value.
|
||||
*
|
||||
* @param context the context
|
||||
* @param activityType the activity type
|
||||
*/
|
||||
public static String getIconValue(Context context, String activityType) {
|
||||
if (inList(context, activityType, bike)) {
|
||||
return BIKE;
|
||||
}
|
||||
if (inList(context, activityType, drive)) {
|
||||
return DRIVE;
|
||||
}
|
||||
if (inList(context, activityType, run)) {
|
||||
return RUN;
|
||||
}
|
||||
if (inList(context, activityType, ski)) {
|
||||
return SKI;
|
||||
}
|
||||
if (inList(context, activityType, walk)) {
|
||||
return WALK;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the activity type is in the list.
|
||||
*
|
||||
* @param context the context
|
||||
* @param activityType the activity type
|
||||
* @param list the list
|
||||
*/
|
||||
private static boolean inList(Context context, String activityType, int[] list) {
|
||||
for (int i : list) {
|
||||
if (context.getString(i).equals(activityType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||