BartRunnerAndroid/src/com/dougkeen/bart/AddRouteActivity.java

52 lines
1.7 KiB
Java
Raw Normal View History

2011-05-23 18:59:34 +00:00
package com.dougkeen.bart;
import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
2011-05-23 18:59:34 +00:00
2012-07-16 15:06:31 +00:00
import com.dougkeen.bart.data.RoutesColumns;
import com.dougkeen.bart.model.Constants;
import com.dougkeen.bart.model.Station;
2011-05-23 18:59:34 +00:00
2012-07-16 15:06:31 +00:00
public class AddRouteActivity extends AbstractRouteSelectionActivity {
2011-05-23 18:59:34 +00:00
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final View checkboxText = findViewById(R.id.return_checkbox_text);
final View checkbox = findViewById(R.id.return_checkbox);
checkboxText.setVisibility(View.VISIBLE);
checkbox.setVisibility(View.VISIBLE);
checkboxText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
checkbox.performClick();
}
});
2011-05-23 18:59:34 +00:00
}
2012-07-16 15:06:31 +00:00
@Override
protected void onOkButtonClick(Station origin, Station destination) {
2011-05-23 18:59:34 +00:00
ContentValues values = new ContentValues();
values.put(RoutesColumns.FROM_STATION.string, origin.abbreviation);
values.put(RoutesColumns.TO_STATION.string, destination.abbreviation);
2011-05-23 18:59:34 +00:00
Uri newUri = getContentResolver().insert(
Constants.FAVORITE_CONTENT_URI, values);
if (((CheckBox) findViewById(R.id.return_checkbox)).isChecked()) {
values = new ContentValues();
values.put(RoutesColumns.FROM_STATION.string,
destination.abbreviation);
values.put(RoutesColumns.TO_STATION.string, origin.abbreviation);
getContentResolver().insert(Constants.FAVORITE_CONTENT_URI, values);
}
2011-05-23 18:59:34 +00:00
setResult(RESULT_OK, (new Intent()).setAction(newUri.toString()));
finish();
}
}