Android Open Source - student_travel_app All Plan Activity






From Project

Back to project page student_travel_app.

License

The source code is released under:

Apache License

If you think the Android project student_travel_app 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.piasy.simpletravel;
//w ww. j  a  va2s.  co m
import java.util.Calendar;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ListView;

import com.baidu.location.BDLocation;
import com.piasy.simpletravel.controller.Controller;
import com.piasy.simpletravel.model.Constant;

public class AllPlanActivity extends Activity
{
  ListView allPlanListView;
  MyListViewAdapter adapter;
  Button travelInfoButton, planTableButton, settingButton;
  Button dateSelectButton, viewMapButton;
  
  int longClickPos = 0, clickPos = 0;
  int mYear, mMonth, mDay;
  boolean inited = false;
  
  Controller myController;
  
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    myController = Controller.getController();
    myController.setActivityHandler(handler);
//    myController.setPlanDays(2);
        
    travelInfoButton = (Button) findViewById(R.id.travelInfoInMain);
    planTableButton = (Button) findViewById(R.id.planTableInMain);
    settingButton = (Button) findViewById(R.id.SettingInMain);
    dateSelectButton = (Button) findViewById(R.id.dataSelectButton);
    viewMapButton = (Button) findViewById(R.id.viewMapInMain);
    allPlanListView = (ListView) findViewById(R.id.allPlanListview);
    adapter = new MyListViewAdapter(this, Constant.ACTIVITY_ALLPLAN);
    allPlanListView.setAdapter(adapter);

    settingButton.setOnClickListener(new View.OnClickListener()
    {
      
      @Override
      public void onClick(View v)
      {
        if (!inited)
        {
          initUI();
        }
        
        Intent settingIntent = new Intent(AllPlanActivity.this, SettingActivity.class);
        startActivity(settingIntent);
      }
    });
    
    if (myController.verified())
    {
      initUI();
      updateUI();
    }
    else
    {
      Controller.makeToast("??????????????");
    }
  }
  
  protected void initUI()
  {
    travelInfoButton.setOnClickListener(new View.OnClickListener()
    {
      
      @Override
      public void onClick(View v)
      {
        Intent travelInfoIntent = new Intent(AllPlanActivity.this, SearchActivity.class);
        startActivity(travelInfoIntent);
      }
    });
    
    planTableButton.setOnClickListener(new View.OnClickListener()
    {
      
      @Override
      public void onClick(View v)
      {
        
      }
    });
    
    
    dateSelectButton.setOnClickListener(new View.OnClickListener()
    {
      
      @Override
      public void onClick(View v)
      {
        Calendar cur = Calendar.getInstance();
        new DatePickerDialog(AllPlanActivity.this, new DatePickerDialog.OnDateSetListener()
        {
          
          @Override
          public void onDateSet(DatePicker view, int year, int monthOfYear,
              int dayOfMonth)
          {
            mYear = year;
            mMonth = monthOfYear;
            mDay = dayOfMonth;
          }
        }, cur.get(Calendar.YEAR), cur.get(Calendar.MONTH), cur.get(Calendar.DAY_OF_MONTH)).show();
      }
    });
    
    viewMapButton.setOnClickListener(new View.OnClickListener()
    {
      
      @Override
      public void onClick(View v)
      {
        BDLocation location = myController.getLocation();
        if (location == null || myController.getAroundSpots().size() == 0)
        {
          Controller.makeToast("?????????????????~");
          myController.searchAroundSpots();
        }
        else
        {
          myController.viewMap(Constant.VIEW_POS_MAP);
          Intent intent = new Intent(AllPlanActivity.this, MapViewActivity.class);
          startActivity(intent);
        }
      }
    });
    
    allPlanListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {

      @Override
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id)
      {
        if (position == adapter.getCount() - 1)
        {
          Calendar cur = Calendar.getInstance();
          DatePickerDialog dpDialog = new DatePickerDialog
          (AllPlanActivity.this, new DatePickerDialog.OnDateSetListener()
          {
            
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear,
                int dayOfMonth)
            {
              mYear = year;
              mMonth = monthOfYear;
              mDay = dayOfMonth;
              myController.setPlanStartDate(year, monthOfYear, dayOfMonth);
              
              Intent travelInfoIntent = new Intent(AllPlanActivity.this, SearchActivity.class);
              startActivity(travelInfoIntent);
            }
          }, cur.get(Calendar.YEAR), cur.get(Calendar.MONTH), cur.get(Calendar.DAY_OF_MONTH));
          dpDialog.setTitle("?????????");
          dpDialog.show();
        }
        else
        {
          myController.gotoDay(position);
          Intent singledayPlanIntent = new Intent(AllPlanActivity.this, SingledayPlanActivity.class);
          startActivity(singledayPlanIntent);
        }
      }
    });
    allPlanListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener()
    {

      @Override
      public boolean onItemLongClick(AdapterView<?> parent, View view,
          int position, long id)
      {
        longClickPos = position;
        return false;
      }
    });
    allPlanListView.setOnCreateContextMenuListener(new OnCreateContextMenuListener()
    {
      
      @Override
      public void onCreateContextMenu(ContextMenu menu, View v,
          ContextMenuInfo menuInfo)
      {
        menu.add(0, 0, 0, "????");
      }
    });
    
    inited = true;
  }
  
  protected void updateUI()
  {
//    ArrayList<ArrayList<JSONObject>> allPlans = myController.getPlan();
////    System.out.println("ok2");
////    System.out.println("" + (allPlans == null));
//    if (allPlans.size() != 0)
//    {
////      JSONObject date = Util.date2Json(myController.getPlanDate());
//      adapter.clear();
//      for (int i = 0; i < allPlans.size(); i ++)
//      {
//        JSONObject plan = new JSONObject();
//        try
//        {
//          plan.put("type", Constant.LISTVIEW_ITEM_PLAN);
//          plan.put("status", Constant.PLAN_STATUS_PLAN);
//          String spots = "";
//          for (int j = 0; j < allPlans.get(i).size(); j ++)
//          {
//            spots += allPlans.get(i).get(j).getString("name");
//            
//            if (j < allPlans.get(i).size() - 1)
//            {
//              spots += "?";
//            }
//          }
//          
//          Calendar date = myController.getPlanDate();
//          plan.put("spots", spots);
//          plan.put("year", date.get(Calendar.YEAR));
//          plan.put("month", date.get(Calendar.MONTH));
//          plan.put("day", date.get(Calendar.DAY_OF_MONTH) + i);
//          plan.put("weekday", (date.get(Calendar.DAY_OF_WEEK) + i) % 7);
//          
//          adapter.addItem(plan);
//        }
//        catch (JSONException e)
//        {
//          if (e.getMessage() == null)
//              {
//            Log.e(Constant.LOG_LEVEL_ERROR, "AllPlanActivity updateUI : JSONException");
//              }
//              else
//              {
//                Log.e(Constant.LOG_LEVEL_ERROR, "AllPlanActivity updateUI : " + e.getMessage());
//          }
//        }
//      }
//      
//      adapter.notifyDataSetChanged();
//    }
//    else
//    {
//      Controller.makeToast("?????????????????~");
//    }
  }
  
  @SuppressLint("HandlerLeak")
  Handler handler = new Handler()
  {
    public void handleMessage(Message msg)
    {
      Log.d(Constant.LOG_LEVEL_DEBUG, "get info at search activity : " + (String)msg.obj);
    }
  };
  
  @Override
  public boolean onContextItemSelected(MenuItem item)
  {
    switch (item.getItemId())
    {
    case 0:
      break;
    case 1:
      break;
    default:
      return super.onContextItemSelected(item);
    }
    return true;
  }
  
  @Override
  protected void onResume()
  {
    super.onResume();
    myController.setActivityHandler(handler);

    if (myController.exiting())
    {
      finish();
    }
    else
    {
      if (myController.verified())
      {
        if (!inited)
        {
          initUI();
        }
        updateUI();
      }
      else
      {
        Controller.makeToast("??????????????");
      }
    }
  }
}




Java Source Code List

com.piasy.simpletravel.AllPlanActivity.java
com.piasy.simpletravel.HotelDetailActivity.java
com.piasy.simpletravel.LaunchActivity.java
com.piasy.simpletravel.MapViewActivity.java
com.piasy.simpletravel.MyListViewAdapter.java
com.piasy.simpletravel.PopMenu.java
com.piasy.simpletravel.ScrollRefreshListView.java
com.piasy.simpletravel.SearchActivity.java
com.piasy.simpletravel.SettingActivity.java
com.piasy.simpletravel.SignupActivity.java
com.piasy.simpletravel.SimpleTravelApplication.java
com.piasy.simpletravel.SingledayPlanActivity.java
com.piasy.simpletravel.SpotDetailActivity.java
com.piasy.simpletravel.controller.Controller.java
com.piasy.simpletravel.dao.DBHelper.java
com.piasy.simpletravel.dao.DBManager.java
com.piasy.simpletravel.model.CommitModule.java
com.piasy.simpletravel.model.Constant.java
com.piasy.simpletravel.model.Flag.java
com.piasy.simpletravel.model.HotelSeacher.java
com.piasy.simpletravel.model.ListViewItems.java
com.piasy.simpletravel.model.LocationModule.java
com.piasy.simpletravel.model.PlanGenerator.java
com.piasy.simpletravel.model.RouteEntry.java
com.piasy.simpletravel.model.Setting.java
com.piasy.simpletravel.model.SignupModule.java
com.piasy.simpletravel.model.SpotsSeacher.java
com.piasy.simpletravel.model.VerifyModule.java
com.piasy.simpletravel.util.Util.java
dao.DBManager.java
driver.Driver.java
model.CommitHandler.java
model.Constant.java
model.QueryHandler.java
model.Setting.java
model.SignupHandler.java
model.VerifyHandler.java
parser.Driver.java
parser.HotelSeacher.java
util.Util.java