Android Open Source - MassRoute Mass Route






From Project

Back to project page MassRoute.

License

The source code is released under:

Copyright (c) 2010 Todd Anderson http://www.custardbelly.com/blog Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (th...

If you think the Android project MassRoute 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

package com.custardbelly.massdot;
// w  ww.java2 s . co m
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.AdapterContextMenuInfo;

import com.custardbelly.massdot.enumeration.ActivityViewType;
import com.custardbelly.massdot.enumeration.IntentExtraType;
import com.custardbelly.massdot.model.StoredStopRequest;
import com.custardbelly.massdot.service.IPreferenceService;
import com.custardbelly.massdot.service.PreferenceService;
import com.custardbelly.massdot.view.RouteListView;
import com.custardbelly.massdot.view.StopPredictionsView;
import com.custardbelly.massdot.view.adapter.StoredStopRequestsAdapter;

public class MassRoute extends Activity 
{
  private List<StoredStopRequest> _storedRequests;
  private ArrayAdapter<StoredStopRequest> _storedRequestsAdapter;
  
  private OnClickListener buttonOnClickListener = new View.OnClickListener() {
    public void onClick( View v )
    {
      Intent routeListIntent = new Intent( MassRoute.this, RouteListView.class );
          startActivityForResult( routeListIntent, ActivityViewType.ACTIVITY_ROUTE_LIST.getId() );
    }
  };
  
  private AdapterView.OnItemClickListener listOnClickListener = new AdapterView.OnItemClickListener() {
    public void onItemClick( AdapterView parentView, View childView, int position, long id )
    {
      StoredStopRequest request = (StoredStopRequest) _storedRequestsAdapter.getItem( position );
      activateStoredRequest( request );
    }
  };
  
  @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        final Button button = (Button) findViewById(R.id.startButton);
        button.setOnClickListener( buttonOnClickListener );
         
        final ListView list = (ListView) findViewById( R.id.storedRequestList );
        list.setOnItemClickListener( listOnClickListener );
        
        IPreferenceService requestsService = PreferenceService.instance();
        _storedRequests = requestsService.getStopRequests( getApplicationContext() );
        
        _storedRequestsAdapter = new StoredStopRequestsAdapter( MassRoute.this, R.layout.stored_request_row, _storedRequests );
      list.setAdapter( _storedRequestsAdapter );
      registerForContextMenu( list );
         
      handleStoredRequestsUpdate();
    }
  
  protected void handleStoredRequestsUpdate()
  {
    _storedRequestsAdapter.notifyDataSetChanged();
    showStoredRequests( ( _storedRequests != null && _storedRequests.size() > 0 ) ? View.VISIBLE : View.INVISIBLE );
  }
  
  protected void showStoredRequests( int isVisible )
  {
    final TextView header = (TextView) findViewById(R.id.mainOrField);
    final ListView list = (ListView) findViewById(R.id.storedRequestList);
    header.setVisibility( isVisible );
    list.setVisibility( isVisible );
  }
  
  protected void activateStoredRequest( StoredStopRequest request )
  {
    Intent intent = new Intent( MassRoute.this, StopPredictionsView.class );
    intent.putExtra( IntentExtraType.ROUTE_ID.toString(), request.routeId );
    intent.putExtra( IntentExtraType.ROUTE_TITLE.toString(), request.routeTitle );
    intent.putExtra( IntentExtraType.STOP_ID.toString(), request.stopId );
    intent.putExtra( IntentExtraType.STOP_TITLE.toString(), request.stopTitle );
    startActivityForResult( intent, ActivityViewType.ACTIVITY_ROUTE_PREDICTIONS.getId() );
  }
    
  @Override
  public void onCreateContextMenu( ContextMenu menu, View view, ContextMenuInfo menuInfo )
  {
    super.onCreateContextMenu( menu, view, menuInfo );
    
    ListView list = (ListView) findViewById( R.id.storedRequestList );
    if( view == list )
    {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate( R.menu.stored_requests_menu, menu );
    }
  }
  
  @Override
  public boolean onContextItemSelected( MenuItem item )
  {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    
    int index = info.position;
    StoredStopRequest request = (StoredStopRequest) _storedRequestsAdapter.getItem( index );
    if( request == null ) return false;
    
    switch( item.getItemId() )
    {
      case R.id.viewRequest:
        activateStoredRequest( request );
        break;
      case R.id.deleteRequest:
        boolean removeSuccess = PreferenceService.instance().removeStopRequest( request, getApplicationContext() );
        if( removeSuccess )
        {
          handleStoredRequestsUpdate();
        }
        break;
    }
    return true;
  }
  
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) 
    {
      super.onActivityResult( requestCode, resultCode, intent );
      
      final int routeActivity = ActivityViewType.ACTIVITY_ROUTE_LIST.getId();
      final int predictionActivity = ActivityViewType.ACTIVITY_ROUTE_PREDICTIONS.getId();
      
      if( requestCode == routeActivity || requestCode == predictionActivity )
      {    
        handleStoredRequestsUpdate();
      }
    }
}




Java Source Code List

com.custardbelly.massdot.MassRoute.java
com.custardbelly.massdot.enumeration.ActivityResultType.java
com.custardbelly.massdot.enumeration.ActivityViewType.java
com.custardbelly.massdot.enumeration.IntentExtraType.java
com.custardbelly.massdot.exception.MassRouteParserException.java
com.custardbelly.massdot.model.MassRouteModel.java
com.custardbelly.massdot.model.RouteConfig.java
com.custardbelly.massdot.model.RouteDirection.java
com.custardbelly.massdot.model.RouteSearchContentProvider.java
com.custardbelly.massdot.model.RouteStop.java
com.custardbelly.massdot.model.Route.java
com.custardbelly.massdot.model.StopPrediction.java
com.custardbelly.massdot.model.StoredStopRequest.java
com.custardbelly.massdot.model.StoredStopRequests.java
com.custardbelly.massdot.parser.IRouteConfigParser.java
com.custardbelly.massdot.parser.IRouteParser.java
com.custardbelly.massdot.parser.IStopPredictionsParser.java
com.custardbelly.massdot.parser.RouteConfigParser.java
com.custardbelly.massdot.parser.RouteParser.java
com.custardbelly.massdot.parser.StopPredictionsParser.java
com.custardbelly.massdot.parser.handler.MassRouteServiceParserHandler.java
com.custardbelly.massdot.service.IMassRouteService.java
com.custardbelly.massdot.service.IPreferenceService.java
com.custardbelly.massdot.service.IQueueableTaskResponder.java
com.custardbelly.massdot.service.IQueueableTask.java
com.custardbelly.massdot.service.IServiceTaskQueue.java
com.custardbelly.massdot.service.MassRouteService.java
com.custardbelly.massdot.service.PreferenceService.java
com.custardbelly.massdot.service.RouteConfigTask.java
com.custardbelly.massdot.service.RouteListTask.java
com.custardbelly.massdot.service.ServiceTaskQueue.java
com.custardbelly.massdot.service.StopPredictionTask.java
com.custardbelly.massdot.service.responder.IMassRouteServiceResponder.java
com.custardbelly.massdot.service.responder.IRoutesConfigServiceResponder.java
com.custardbelly.massdot.service.responder.IRoutesServiceResponder.java
com.custardbelly.massdot.service.responder.IStopPredictionsServiceResponder.java
com.custardbelly.massdot.view.MassRouteServiceView.java
com.custardbelly.massdot.view.RouteDirectionView.java
com.custardbelly.massdot.view.RouteListView.java
com.custardbelly.massdot.view.RouteStopsView.java
com.custardbelly.massdot.view.StopPredictionsView.java
com.custardbelly.massdot.view.adapter.RouteAdapter.java
com.custardbelly.massdot.view.adapter.RouteDirectionAdapter.java
com.custardbelly.massdot.view.adapter.RouteStopsAdapter.java
com.custardbelly.massdot.view.adapter.StopPredictionsAdapter.java
com.custardbelly.massdot.view.adapter.StoredStopRequestsAdapter.java