Android Open Source - sthlmtraveling Change Route Time Activity






From Project

Back to project page sthlmtraveling.

License

The source code is released under:

Apache License

If you think the Android project sthlmtraveling listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2009 Johan Nilsson <http://markupartist.com>
 *// w  ww . j a  va  2s .c  om
 * 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.markupartist.sthlmtraveling;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.Time;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Spinner;
import android.widget.TimePicker;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.markupartist.sthlmtraveling.provider.planner.JourneyQuery;

public class ChangeRouteTimeActivity extends BaseActivity {
    static final String TAG = "ChangeRouteTimeActivity"; 
    static final int DIALOG_DATE = 0;
    static final int DIALOG_TIME = 1;

    private Time mTime;
    private Button mDateButton;
    private Button mTimeButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.change_route_time);
        
        registerScreen("Change route time");
        
        //setTitle(getText(R.string.change_date_and_time));
        //ActionBar actionBar = initActionBar();
        //actionBar.setDisplayHomeAsUpEnabled(true);

        Bundle extras = getIntent().getExtras();
        final JourneyQuery journeyQuery =
            extras.getParcelable(RoutesActivity.EXTRA_JOURNEY_QUERY);

        mTime = journeyQuery.time;

        mDateButton = (Button) findViewById(R.id.change_route_date);
        mDateButton.setOnClickListener(new OnClickListener() {
            @Override public void onClick(View v) {
                showDialog(DIALOG_DATE);
            }
        });

        mTimeButton = (Button) findViewById(R.id.change_route_time);
        mTimeButton.setOnClickListener(new OnClickListener() {
            @Override public void onClick(View v) {
                showDialog(DIALOG_TIME);
            }
        });

        int selectedPosition = journeyQuery.isTimeDeparture ? 0 : 1;
        final Spinner whenSpinner = (Spinner) findViewById(R.id.departure_arrival_choice);
        ArrayAdapter<CharSequence> whenChoiceAdapter = ArrayAdapter.createFromResource(
                this, R.array.when_choice, android.R.layout.simple_spinner_item);
        whenChoiceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        whenSpinner.setAdapter(whenChoiceAdapter);
        whenSpinner.setSelection(selectedPosition);

        // Inflate a "Done/Discard" custom action bar view.
        LayoutInflater inflater = (LayoutInflater) getSupportActionBar().getThemedContext()
                .getSystemService(LAYOUT_INFLATER_SERVICE);
        final View customActionBarView = inflater.inflate(
                R.layout.actionbar_custom_view_done_discard, null);
        customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        journeyQuery.isTimeDeparture =
                                whenSpinner.getSelectedItemId() == 0 ? true : false;
                            journeyQuery.time = mTime;

                            setResult(RESULT_OK, (new Intent())
                                    .putExtra(RoutesActivity.EXTRA_JOURNEY_QUERY,
                                            journeyQuery));

                            finish();
                    }
                });
        customActionBarView.findViewById(R.id.actionbar_discard).setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        setResult(RESULT_CANCELED);
                        finish();
                    }
                });

        // Show the custom action bar view and hide the normal Home icon and title.
        final ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayOptions(
                ActionBar.DISPLAY_SHOW_CUSTOM,
                ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME
                        | ActionBar.DISPLAY_SHOW_TITLE);
        actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

        updateDisplay();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.actionbar_change_route_time, menu);
        return true;
    }

    /**
     * Update time on the buttons.
     */
    private void updateDisplay() {
        String formattedDate = mTime.format("%x");
        String formattedTime = mTime.format("%R");
        mDateButton.setText(formattedDate);
        mTimeButton.setText(formattedTime);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
            case DIALOG_DATE:
                return new DatePickerDialog(this, mDateSetListener,
                        mTime.year, mTime.month, mTime.monthDay);
            case DIALOG_TIME:
                // TODO: Base 24 hour on locale, same with the format.
                return new TimePickerDialog(this, mTimeSetListener,
                        mTime.hour, mTime.minute, true);
        }
        return null;
    }

    @Override
    protected void onPrepareDialog(int id, Dialog dialog) {
        switch (id) {
            case DIALOG_DATE:
                ((DatePickerDialog) dialog).updateDate(mTime.year, mTime.month, mTime.monthDay);
                break;
            case DIALOG_TIME:
                ((TimePickerDialog) dialog).updateTime(mTime.hour, mTime.minute);
                break;
        }
    }

    @Override
    public boolean onSearchRequested() {
        Intent i = new Intent(this, StartActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);
        return true;
    }

    private DatePickerDialog.OnDateSetListener mDateSetListener =
        new DatePickerDialog.OnDateSetListener() {

            public void onDateSet(DatePicker view, int year, int monthOfYear,
                    int dayOfMonth) {
                mTime.year = year;
                mTime.month = monthOfYear;
                mTime.monthDay = dayOfMonth;
                updateDisplay();
            }
        };

    private TimePickerDialog.OnTimeSetListener mTimeSetListener =
        new TimePickerDialog.OnTimeSetListener() {

            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                mTime.hour = hourOfDay;
                mTime.minute = minute;
                updateDisplay();
            }
        };
}




Java Source Code List

com.markupartist.sthlmtraveling.AboutActivity.java
com.markupartist.sthlmtraveling.AllTests.java
com.markupartist.sthlmtraveling.AppConfig.java
com.markupartist.sthlmtraveling.AutoCompleteStopAdapter.java
com.markupartist.sthlmtraveling.BaseActivity.java
com.markupartist.sthlmtraveling.BaseFragmentActivity.java
com.markupartist.sthlmtraveling.BaseFragment.java
com.markupartist.sthlmtraveling.BaseListActivity.java
com.markupartist.sthlmtraveling.BaseListFragmentActivity.java
com.markupartist.sthlmtraveling.BaseListFragment.java
com.markupartist.sthlmtraveling.BasePreferenceActivity.java
com.markupartist.sthlmtraveling.ChangeRouteTimeActivity.java
com.markupartist.sthlmtraveling.DepartureAdapter.java
com.markupartist.sthlmtraveling.DeparturesActivity.java
com.markupartist.sthlmtraveling.DeviationDetailActivity.java
com.markupartist.sthlmtraveling.DeviationsActivity.java
com.markupartist.sthlmtraveling.DialogHelper.java
com.markupartist.sthlmtraveling.FavoritesFragment.java
com.markupartist.sthlmtraveling.MultipleListAdapter.java
com.markupartist.sthlmtraveling.MyApplication.java
com.markupartist.sthlmtraveling.MyLocationManager.java
com.markupartist.sthlmtraveling.NearbyActivity.java
com.markupartist.sthlmtraveling.PlannerFragmentActivity.java
com.markupartist.sthlmtraveling.PlannerFragment.java
com.markupartist.sthlmtraveling.PointOnMapActivity.java
com.markupartist.sthlmtraveling.RouteDetailActivity.java
com.markupartist.sthlmtraveling.RouteParserTest.java
com.markupartist.sthlmtraveling.RoutesActivity.java
com.markupartist.sthlmtraveling.SearchDeparturesFragmentActivity.java
com.markupartist.sthlmtraveling.SearchDeparturesFragment.java
com.markupartist.sthlmtraveling.SectionedAdapter.java
com.markupartist.sthlmtraveling.SettingsActivity.java
com.markupartist.sthlmtraveling.StartActivity.java
com.markupartist.sthlmtraveling.TrafficStatusFragment.java
com.markupartist.sthlmtraveling.ViewOnMapActivity.java
com.markupartist.sthlmtraveling.provider.FavoritesDbAdapter.java
com.markupartist.sthlmtraveling.provider.HistoryDbAdapter.java
com.markupartist.sthlmtraveling.provider.JourneysProvider.java
com.markupartist.sthlmtraveling.provider.PlacesProvider.java
com.markupartist.sthlmtraveling.provider.TransportMode.java
com.markupartist.sthlmtraveling.provider.departure.DeparturesStore.java
com.markupartist.sthlmtraveling.provider.deviation.DeviationNotificationDbAdapter.java
com.markupartist.sthlmtraveling.provider.deviation.DeviationStore.java
com.markupartist.sthlmtraveling.provider.deviation.Deviation.java
com.markupartist.sthlmtraveling.provider.planner.JourneyQuery.java
com.markupartist.sthlmtraveling.provider.planner.Planner.java
com.markupartist.sthlmtraveling.provider.site.Site.java
com.markupartist.sthlmtraveling.provider.site.SitesStore.java
com.markupartist.sthlmtraveling.receivers.OnAlarmReceiver.java
com.markupartist.sthlmtraveling.receivers.OnBootReceiver.java
com.markupartist.sthlmtraveling.service.DataMigrationService.java
com.markupartist.sthlmtraveling.service.DeviationService.java
com.markupartist.sthlmtraveling.service.WakefulIntentService.java
com.markupartist.sthlmtraveling.ui.view.DelayAutoCompleteTextView.java
com.markupartist.sthlmtraveling.ui.view.LineSegment.java
com.markupartist.sthlmtraveling.ui.view.SmsTicketDialog.java
com.markupartist.sthlmtraveling.ui.view.TripView.java
com.markupartist.sthlmtraveling.utils.Analytics.java
com.markupartist.sthlmtraveling.utils.BarcodeScannerIntegrator.java
com.markupartist.sthlmtraveling.utils.DateTimeUtil.java
com.markupartist.sthlmtraveling.utils.DisplayMetricsHelper.java
com.markupartist.sthlmtraveling.utils.ErrorReporter.java
com.markupartist.sthlmtraveling.utils.HttpHelper.java
com.markupartist.sthlmtraveling.utils.IntentUtil.java
com.markupartist.sthlmtraveling.utils.LocationUtils.java
com.markupartist.sthlmtraveling.utils.StreamUtils.java
com.markupartist.sthlmtraveling.utils.StringUtils.java
com.markupartist.sthlmtraveling.utils.ViewHelper.java
com.viewpagerindicator.CirclePageIndicator.java
com.viewpagerindicator.IconPageIndicator.java
com.viewpagerindicator.IconPagerAdapter.java
com.viewpagerindicator.IcsLinearLayout.java
com.viewpagerindicator.LinePageIndicator.java
com.viewpagerindicator.PageIndicator.java
com.viewpagerindicator.TabPageIndicator.java
com.viewpagerindicator.TitlePageIndicator.java
com.viewpagerindicator.UnderlinePageIndicator.java