Android Open Source - student_travel_app Pop Menu






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;
//ww  w.j a v a 2 s  .  c  o m
import java.util.ArrayList;

import com.piasy.simpletravel.model.Constant;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

public class PopMenu
{
  private ArrayList<String> itemList;
  private Context context;
  private PopupWindow popupWindow;
  private ListView listView;
  PopAdapter adapter = new PopAdapter();
  int viewType;

  public PopMenu(Context context, int viewType) 
  {
    this.context = context;
    this.viewType = viewType;
    
    itemList = new ArrayList<String>();

    View view = LayoutInflater.from(context)
        .inflate(R.layout.popmenu, null);

    listView = (ListView) view.findViewById(R.id.viewTypeListView);
    listView.setAdapter(adapter);
    listView.setFocusableInTouchMode(true);
    listView.setFocusable(true);

    switch (viewType)
    {
    case Constant.POPUP_VIEW_INMAP:
      popupWindow = new PopupWindow(view, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
      break;
    case Constant.POPUP_VIEW_INACTIVITY:
      popupWindow = new PopupWindow(view, 120, LayoutParams.WRAP_CONTENT);
    default:
      break;
    }

    // ?????????Back????????????????????????????
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
  }

  // ????????????????
  public void setOnItemClickListener(OnItemClickListener listener) 
  {
    listView.setOnItemClickListener(listener);
  }

  public void clearItems()
  {
    itemList.clear();
    adapter.notifyDataSetChanged();
  }
  
  // ????????????
  public void addItems(String[] items) 
  {
    for (String s : items)
    {
      itemList.add(s);
    }
    adapter.notifyDataSetChanged();
  }

  // ?????????????
  public void addItem(String item) 
  {
    itemList.add(item);
    adapter.notifyDataSetChanged();
  }

  // ???? ?? pop?????? parent ?????
  public void showAsDropDown(View parent)
  {
    switch (viewType)
    {
    case Constant.POPUP_VIEW_INMAP:
      popupWindow.showAsDropDown(parent, 0, 0);
      break;
    case Constant.POPUP_VIEW_INACTIVITY:
      popupWindow.showAsDropDown(parent, 0, 5);
    default:
      break;
    }

    // ??????
    popupWindow.setFocusable(true);
    // ???????????
    popupWindow.setOutsideTouchable(true);
    // ?????
    popupWindow.update();
  }

  // ??????????
  public void dismiss() 
  {
    popupWindow.dismiss();
  }

  // ????
  private final class PopAdapter extends BaseAdapter 
  {

    @Override
    public int getCount() 
    {
      return itemList.size();
    }

    @Override
    public Object getItem(int position)
    {
      return itemList.get(position);
    }

    @Override
    public long getItemId(int position) 
    {
      return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
      ViewHolder holder;
      if (convertView == null) 
      {
        convertView = LayoutInflater.from(context).inflate(
            R.layout.pomenu_item, null);
        holder = new ViewHolder();

        convertView.setTag(holder);

        holder.groupItem = (TextView) convertView
            .findViewById(R.id.popupMenuItem);

      } 
      else 
      {
        holder = (ViewHolder) convertView.getTag();
      }

      holder.groupItem.setText(itemList.get(position));

      return convertView;
    }

    private final class ViewHolder 
    {
      TextView groupItem;
    }
  }
}




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