Clean up TrackDetails

- use MyTracksProviderUtils to update a track
- define TRACK_ID and SHOW_CANCEL in TrackDetails
- log error if track doesn't exit
- add a scrollview
- add padding
This commit is contained in:
Jimmy Shih
2011-12-13 15:52:59 -08:00
parent bf03a4c54b
commit 762fc0d06e
8 changed files with 245 additions and 216 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ limitations under the License.
<!-- TODO: VIEW and PICK for waypoint cursor dir -->
<activity android:name="com.google.android.apps.mytracks.WaypointsList" />
<activity android:name="com.google.android.apps.mytracks.TrackDetails"
<activity android:name="com.google.android.apps.mytracks.TrackDetail"
android:label="@string/track_detail_title">
<intent-filter>
<action android:name="android.intent.action.EDIT" />
-83
View File
@@ -1,83 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2010 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="10dip"
android:background="#c000">
<TextView android:text="@string/track_detail_track_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:id="@+id/trackdetails_icon"
android:src="@drawable/track"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="4dip"
android:paddingRight="4dip"/>
<EditText android:id="@+id/trackdetails_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:autoText="true"
android:capitalize="words"
android:selectAllOnFocus="true"
android:hint="@string/track_detail_track_name"
android:imeOptions="actionNext"/>
</LinearLayout>
<TextView android:text="@string/track_detail_activity_type"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<AutoCompleteTextView android:id="@+id/trackdetails_category"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="@string/track_detail_activity_type_hint"
android:imeOptions="actionNext"/>
<TextView android:text="@string/track_detail_track_description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText android:id="@+id/trackdetails_description"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:singleLine="false"
android:autoText="true"
android:capitalize="sentences"
android:selectAllOnFocus="true"
android:maxLines="50"
android:gravity="top"
android:layout_weight="1"
android:hint="@string/track_detail_track_description"
android:imeOptions="actionDone"/>
<LinearLayout style="@style/ButtonLayout">
<LinearLayout style="@style/ButtonSpacer"/>
<Button android:id="@+id/trackdetails_save"
android:layout_gravity="left"
android:text="@string/generic_save"
style="@style/Button"/>
<Button android:id="@+id/trackdetails_cancel"
android:layout_gravity="right"
android:text="@string/generic_cancel"
style="@style/Button"/>
<LinearLayout style="@style/ButtonSpacer"/>
</LinearLayout>
</LinearLayout>
+118
View File
@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2010 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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
>
<ScrollView
android:background="@color/black"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="fill_parent"
>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:padding="4dp"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/track_detail_track_name"
/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
>
<ImageView
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:src="@drawable/track"
/>
<EditText
android:autoText="true"
android:capitalize="words"
android:hint="@string/track_detail_track_name"
android:id="@+id/track_detail_track_name"
android:imeOptions="actionNext"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:selectAllOnFocus="true"
android:singleLine="true"
/>
</LinearLayout>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/track_detail_activity_type"
/>
<AutoCompleteTextView
android:id="@+id/track_detail_activity_type"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="@string/track_detail_activity_type_hint"
android:imeOptions="actionNext"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/track_detail_track_description"
/>
<EditText
android:autoText="true"
android:capitalize="sentences"
android:hint="@string/track_detail_track_description"
android:id="@+id/track_detail_track_description"
android:imeOptions="actionDone"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:maxLines="50"
android:selectAllOnFocus="true"
android:singleLine="false"
/>
</LinearLayout>
</ScrollView>
<LinearLayout
style="@style/ButtonLayout"
>
<LinearLayout
style="@style/ButtonSpacer"
/>
<Button
android:id="@+id/track_detail_save"
android:layout_gravity="left"
android:text="@string/generic_save"
style="@style/Button"
/>
<Button
android:id="@+id/track_detail_cancel"
android:layout_gravity="right"
android:text="@string/generic_cancel"
style="@style/Button"
/>
<LinearLayout
style="@style/ButtonSpacer"
/>
</LinearLayout>
</LinearLayout>
@@ -420,9 +420,8 @@ public class MapActivity extends com.google.android.maps.MapActivity
Constants.getActionFromMenuId(item.getItemId()));
return true;
case Constants.MENU_EDIT: {
Intent intent = new Intent(this, TrackDetails.class);
// TODO: Pass in a content URI
intent.putExtra("trackid", dataHub.getSelectedTrackId());
Intent intent = new Intent(this, TrackDetail.class);
intent.putExtra(TrackDetail.TRACK_ID, dataHub.getSelectedTrackId());
startActivity(intent);
return true;
}
@@ -474,9 +474,9 @@ public class MyTracks extends TabActivity implements OnTouchListener {
serviceConnection.stop();
if (currentTrackId > 0) {
Intent intent = new Intent(MyTracks.this, TrackDetails.class);
intent.putExtra("trackid", currentTrackId);
intent.putExtra("hasCancelButton", false);
Intent intent = new Intent(MyTracks.this, TrackDetail.class);
intent.putExtra(TrackDetail.TRACK_ID, currentTrackId);
intent.putExtra(TrackDetail.SHOW_CANCEL, false);
startActivity(intent);
}
}
@@ -0,0 +1,119 @@
/*
* Copyright 2008 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;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
/**
* An activity that let's the user see and edit the user editable track meta
* data such as track name, activity type, and track description.
*
* @author Leif Hendrik Wilden
*/
public class TrackDetail extends Activity implements OnClickListener {
public static final String TRACK_ID = "trackId";
public static final String SHOW_CANCEL = "showCancel";
private static final String TAG = TrackDetail.class.getSimpleName();
private Long trackId;
private MyTracksProviderUtils myTracksProviderUtils;
private Track track;
private EditText trackName;
private AutoCompleteTextView activityType;
private EditText trackDescription;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.track_detail);
trackId = getIntent().getLongExtra(TRACK_ID, -1);
if (trackId < 0) {
Log.e(TAG, "invalid trackId.");
finish();
return;
}
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
track = myTracksProviderUtils.getTrack(trackId);
if (track == null) {
Log.e(TAG, "no track.");
finish();
return;
}
trackName = (EditText) findViewById(R.id.track_detail_track_name);
trackName.setText(track.getName());
activityType = (AutoCompleteTextView) findViewById(R.id.track_detail_activity_type);
activityType.setText(track.getCategory());
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.activity_types, android.R.layout.simple_dropdown_item_1line);
activityType.setAdapter(adapter);
trackDescription = (EditText) findViewById(R.id.track_detail_track_description);
trackDescription.setText(track.getDescription());
Button save = (Button) findViewById(R.id.track_detail_save);
save.setOnClickListener(this);
Button cancel = (Button) findViewById(R.id.track_detail_cancel);
if (getIntent().getBooleanExtra(SHOW_CANCEL, true)) {
cancel.setOnClickListener(this);
cancel.setVisibility(View.VISIBLE);
} else {
cancel.setVisibility(View.INVISIBLE);
}
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.track_detail_save:
save();
finish();
break;
case R.id.track_detail_cancel:
finish();
break;
default:
finish();
}
}
private void save() {
track.setName(trackName.getText().toString());
track.setCategory(activityType.getText().toString());
track.setDescription(trackDescription.getText().toString());
myTracksProviderUtils.updateTrack(track);
}
}
@@ -1,124 +0,0 @@
/*
* Copyright 2008 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;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.content.ContentValues;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
/**
* An activity that let's the user see and edit the user editable track meta
* data such as name, activity type and description.
*
* @author Leif Hendrik Wilden
*/
public class TrackDetails extends Activity implements OnClickListener {
/**
* The id of the track being edited (taken from bundle, "trackid")
*/
private Long trackId;
private EditText name;
private EditText description;
private AutoCompleteTextView category;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.mytracks_detail);
// Required extra when launching this intent:
trackId = getIntent().getLongExtra("trackid", -1);
if (trackId < 0) {
Log.d(Constants.TAG,
"MyTracksDetails intent was launched w/o track id.");
finish();
return;
}
// Optional extra that can be used to suppress the cancel button:
boolean hasCancelButton =
getIntent().getBooleanExtra("hasCancelButton", true);
name = (EditText) findViewById(R.id.trackdetails_name);
description = (EditText) findViewById(R.id.trackdetails_description);
category = (AutoCompleteTextView) findViewById(R.id.trackdetails_category);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this,
R.array.activity_types,
android.R.layout.simple_dropdown_item_1line);
category.setAdapter(adapter);
Button cancel = (Button) findViewById(R.id.trackdetails_cancel);
if (hasCancelButton) {
cancel.setOnClickListener(this);
cancel.setVisibility(View.VISIBLE);
} else {
cancel.setVisibility(View.INVISIBLE);
}
Button save = (Button) findViewById(R.id.trackdetails_save);
save.setOnClickListener(this);
fillDialog();
}
private void fillDialog() {
Track track = MyTracksProviderUtils.Factory.get(this).getTrack(trackId);
if (track != null) {
name.setText(track.getName());
description.setText(track.getDescription());
category.setText(track.getCategory());
}
}
private void saveDialog() {
ContentValues values = new ContentValues();
values.put(TracksColumns.NAME, name.getText().toString());
values.put(TracksColumns.DESCRIPTION, description.getText().toString());
values.put(TracksColumns.CATEGORY, category.getText().toString());
getContentResolver().update(
TracksColumns.CONTENT_URI,
values,
"_id = " + trackId,
null/*selectionArgs*/);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.trackdetails_cancel:
finish();
break;
case R.id.trackdetails_save:
saveDialog();
finish();
break;
}
}
}
@@ -167,8 +167,8 @@ public class TrackList extends ListActivity
return true;
}
case Constants.MENU_EDIT: {
Intent intent = new Intent(this, TrackDetails.class);
intent.putExtra("trackid", trackId);
Intent intent = new Intent(this, TrackDetail.class);
intent.putExtra(TrackDetail.TRACK_ID, trackId);
startActivity(intent);
return true;
}