package com.qiyou.mb.android.ui.fragments;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.JsonSyntaxException;
import com.loopj.android.http.RequestParams;
import com.qiyou.mb.android.QiYouConstant;
import com.qiyou.mb.android.R;
import com.qiyou.mb.android.beans.basic.Activity_bean;
import com.qiyou.mb.android.beans.basic.GEO_bean;
import com.qiyou.mb.android.beans.basic.Media;
import com.qiyou.mb.android.beans.basic.Waypoint;
import com.qiyou.mb.android.utils.ImageLoader;
import com.qiyou.mb.android.utils.Utils;
import com.qiyou.mb.android.utils.enums.ActivityType;
import com.qiyou.mb.android.utils.enums.BBSCate;
import com.qiyou.mb.android.utils.enums.OperationType;
import com.qiyou.mb.android.utils.enums.mediaType;
import com.qiyou.mb.android.utils.exception.NoWebObjectException;
import com.qiyou.mb.android.utils.image.QimageView;
import com.qiyou.mb.android.utils.log.QLog;
import com.qiyou.mb.android.utils.server.RestMethods;
import com.umeng.analytics.MobclickAgent;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ActivityDetail extends WebList_fragment /*TrackingBasic_fragment*/ {
	
	@Override
	public String getCurrentTag() {
		// TODO Auto-generated method stub
		setFTag();
		return TAG;
	}

	@Override
	public void setFTag() {
		// TODO Auto-generated method stub
		TAG="com.qiyou.ActivityDetail";
//		FirstTabTextColor= getResources().getColorStateList(R.color.red);    
//		FirstTabBackGround=R.drawable.icon_star;
	}

	public static String getFTag() {
		return "com.qiyou.ActivityDetail";
	}
	protected  LinearLayout liveMap ;
	protected  LinearLayout bbsbar ;
	 
//	public class UserProfile extends TrackList_fragment {
	protected int currentLayout;
	protected Activity_bean currentAct;
	public static ActivityDetail newInstance(Activity_bean activity/*int inType,int actId*/){ 
		
		ActivityDetail f = new ActivityDetail();
		f.currentAct =activity;
		/*Bundle args = new Bundle();  
	    args.putInt(QiYouConstant.EXTRA_KEY_ID, actId); 
	    f.setArguments(args);*/
	    return f;
	}
    public static ActivityDetail newInstance(){ 
		
		ActivityDetail f = new ActivityDetail();
		 
	    return f;
	}
	public void setCurrentAct(Activity_bean activity){
		currentAct =activity;
//		initialWebQuery();
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
//		activity =(MainActivity)getActivity();
	
//		 if(activity.app!=null)activity.app.currentActiveFragment =TAG;
//		 currentLayout =R.layout.trackingbasic_fragment;
		//			 QLog.getLogger().d(dTAG,TAG+" "+ "onCreate");
//		drawTrack=true;
 		 
	}

	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {   
		 
		  if (currentAct == null) {	      
			  
			  currentAct = new Activity_bean();
		     
		      }
//		  svrNumber =currentAct.getSvrNumber();
		  
		  
		     title =currentAct.getSvrNumber()>0 ?   getResources().getString(R.string.frg_actdetail) +"｜"+currentAct.getName()
				  : getResources().getString(R.string.frg_actnew);
		    
	     
		currentLayout =R.layout.activity_detail;
		vContainer = inflater.inflate(currentLayout, container, false);
		
		webTab="活动";
		initialViews( ); 
//	 	initialLLViews();
//		 initialMapview();
	
		return vContainer;
		}		
	@Override
	Activity_bean getCurrentAct(){
		return currentAct;
	}
	 
	@Override
	void initialMapview(){
		super.initialMapview();
		/*  endOverlay=getItemizedOverlay(R.drawable.icon_send); 
		  startOverlay=getItemizedOverlay(R.drawable.icon_sstart);
		  actStartOverlay=getItemizedOverlay(R.drawable.icon_pass);
		  startOverlay=getItemizedOverlay(R.drawable.icon_sstart);
		  gpxOverlay =new GraphicsOverlay(mMapView);
		  mMapView.getOverlays().add(gpxOverlay);*/
	}
	
	
	
	
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState); 
		  IL = new ImageLoader(activity); 
//		  int actid=-1;
		 
//		  showActivityDetail(svrNumber);
		  showWebObject(); 
	}
	
	void showWebObject(){
		showDetail(currentAct.getSvrNumber()); 
	}
	@Override
	void mapViewOnActivityCreated(){
 		if(currentAct!=null && currentAct.getLat()>0){
			locateMapCenter(currentAct.getLat(),currentAct.getLon());
		 
			/*LatLng startGp =Utils.getLatLng(currentAct.getLat(),currentAct.getLon());
		    setStartIcon(startGp); */
		    
//			setGeoIcon(startGp,actStartOverlay);
	    
		}else{ 
			if(QiYouConstant.PV_LAST_LAT>0 ){
				locateMapCenter(QiYouConstant.PV_LAST_LAT,QiYouConstant.PV_LAST_LON);
			}
		}
	}
	 
	@Override
	 ArrayList<Integer> getGpxTracks(){
		   
		return currentAct ==null? new  ArrayList<Integer>()
					: currentAct.getRoadbooks();
//			 return currentAct.getRoadbooks();
	 }
	 

//	boolean isShareQuery=false;
    protected String lastActShareQueryPara="";
    List<Map<String, String>> shareTrackData;	
	boolean isRemoveRoadbook;
	boolean isRepeatAct;
//	int svrNumber;
	String title;
//	protected ItemizedOverlay<OverlayItem> actStartOverlay =null;
	Button btn_saveAct;
	Button btn_submitAct;
	Button btn_loadRoadbook;
//	Button btn_removeRoadbook;
	Button btn_refresh; 
	Button btn_actJoin;
	Button btn_share;
	
//	TextView td_track_sumary;
	EditText act_roadbook;
	EditText act_edit_title;
//	LinearLayout ll_start_place;
//	LinearLayout ll_end_place;
	TextView txtStartGeoPicker;// act_txt_startGeo_picker 
	TextView txtEndGeoPicker;		// act_txt_startGeo_picker 
	EditText edit_act_endGeo;	
	EditText edit_act_startGeo;
	EditText act_edit_description;
	RatingBar act_levlRatingBar;
	TextView act_creator;
	
	TextView  act_svrNo;
	
	EditText edit_act_startDate;
	EditText edit_act_endDate;
	
	EditText edit_act_startTime;
	EditText edit_act_endTime;
	EditText edit_act_distance;
	EditText edit_act_speed;
    RadioGroup repeatRdGroup;
    RadioGroup roadbookRdGroup;
    RadioGroup actTypeRdGroup;
    
    TextView  act_startplace_share;
    TextView  act_endplace_share;
    QimageView imgTopBanner ; 
   

	
	@Override
	protected void initialViews(){
//		initialTabhost();
//		initialRoadBookViews();
//		liveList =(LinearLayout)vContainer.findViewById(R.id.ll_liveList) ;
//		liveList.setVisibility(View.VISIBLE);
 	
//		btn_refresh =(Button)vContainer.findViewById(R.id.act_btn_refresh);
//		btn_refresh.setOnClickListener(ButtonOnClickListener);		
		imgTopBanner= (QimageView) vContainer.findViewById(R.id.imgTopBanner);
		imgTopBanner.setOnClickListener(ButtonOnClickListener);
		
		btn_saveAct =(Button)vContainer.findViewById(R.id.btn_SaveAct);
		btn_saveAct.setOnClickListener(ButtonOnClickListener);
		btnShare =(Button)vContainer.findViewById(R.id.act_btn_share);
		btnShare.setOnClickListener(ButtonOnClickListener);
		
		btn_submitAct =(Button)vContainer.findViewById(R.id.btn_submitAct);
		btn_submitAct.setOnClickListener(ButtonOnClickListener);
	  
		act_edit_description =(EditText)vContainer.findViewById(R.id.act_edit_desc);
		act_levlRatingBar =(RatingBar)vContainer.findViewById(R.id.act_levlRatingBar);
		
//		td_track_sumary = (TextView) vContainer.findViewById(R.id.td_track_sumary);
		
		act_creator = (TextView) vContainer.findViewById(R.id.act_textview_creator);
		act_svrNo = (TextView) vContainer.findViewById(R.id.act_textview_svrNo);

		
//		act_roadbook = (EditText) vContainer.findViewById(R.id.act_edit_roadbook); 
		act_edit_title = (EditText) vContainer.findViewById(R.id.act_edit_title); ;
		
//		  noRec = (TextView) vContainer.findViewById(R.id.trakList_tv_norec); 
		  txtNote =(TextView)vContainer.findViewById(R.id.txt_web_note);  
	
//		  lvWeb.setOnItemClickListener(itemListener);
//		  lvWeb.setOnTouchListener(new OnTouchListener() {
//			    @Override
//			    public boolean onTouch(View v, MotionEvent event) {
//	 		        Utils.hideSoftKeyboard(activity);
//			        return false;
//			    }
//			});
		  
		  edit_act_startGeo =(EditText)vContainer.findViewById(R.id.act_edit_startGeo);
		  edit_act_distance= (EditText) vContainer.findViewById(R.id.act_edit_distance);  
		  edit_act_speed= (EditText) vContainer.findViewById(R.id.act_edit_speed);  
		  btn_actJoin =(Button)vContainer.findViewById(R.id.act_btn_join);
		  btn_actJoin.setOnClickListener(ButtonOnClickListener); 
		  txtStartGeoPicker = (TextView) vContainer.findViewById(R.id.act_txt_startGeo_picker);
		  txtStartGeoPicker.setOnClickListener(ButtonOnClickListener);
		     act_startplace_share  = (TextView) vContainer.findViewById(R.id.act_txt_startGeo_share);
		     act_startplace_share.setOnClickListener(ButtonOnClickListener);
			 edit_act_startTime = (EditText) vContainer.findViewById(R.id.act_edit_starttime); 

		     popupText=(TextView) vContainer.findViewById(R.id.textcache);
		     
		     
		  /*   btn_live_refresh =(Button)vContainer.findViewById(R.id.share_btn_refresh);
		     btn_live_list =(Button)vContainer.findViewById(R.id.share_btn_list);
		     btn_live_query =(Button)vContainer.findViewById(R.id.share_btn_query);
		     
		     btn_live_refresh.setOnClickListener(ButtonOnClickListener);
			 btn_live_list.setOnClickListener(ButtonOnClickListener); 
			 btn_live_query.setOnClickListener(ButtonOnClickListener);*/
	
//			  btn_pageup=(ImageButton)vContainer.findViewById(R.id.btn_webpageup);  
//			  btn_pageup.setOnClickListener(ButtonOnClickListener); 
//			  btn_pagedown=(ImageButton)vContainer.findViewById(R.id.btn_webpagedown); 
//			  btn_pagedown.setOnClickListener(ButtonOnClickListener);
			  
		  initialExtraViews();
//		  initialMapview();
//		  initialLoadingMore(); 
		  
//		  textContainer =(android.widget.ScrollView)vContainer.findViewById(R.id.td_scrollView); 		  
// 		  if(textContainer!=null)
//		     textContainer.setOnTouchListener(new OnTouchListener() {
//			    @Override
//			    public boolean onTouch(View v, MotionEvent event) {
//	 		        Utils.hideSoftKeyboard(activity);
//			        return false;
//			    }
//			});
		  
		  
		}
	
	
	void initialExtraViews(){
		  edit_act_endGeo =(EditText)vContainer.findViewById(R.id.act_edit_endGeo);   
		 
		  
//		  timePickerListener tpl= new timePickerListener();
		  dateTimePickerListener dtpl = new dateTimePickerListener();
		  tl = new datePickerListener();
		  edit_act_endTime = (EditText) vContainer.findViewById(R.id.act_edit_endtime);
		  
		  edit_act_startTime.setOnTouchListener(dtpl);
		  edit_act_endTime.setOnTouchListener(dtpl); 
		  
		 	 repeatRdGroup = (RadioGroup)vContainer.findViewById(R.id.act_rdGroup_repeat); 
			 if(repeatRdGroup!=null)
				 repeatRdGroup.setOnCheckedChangeListener(rdgChanged);
			 
			 
			 
			 
			 actTypeRdGroup = (RadioGroup)vContainer.findViewById(R.id.act_rdGroup_type); 
			 if(actTypeRdGroup!=null)
				 actTypeRdGroup.setOnCheckedChangeListener(rdgChanged);
			 
	       
			   txtEndGeoPicker = (TextView) vContainer.findViewById(R.id.act_txt_endGeo_picker);
			 txtEndGeoPicker.setOnClickListener(ButtonOnClickListener);
			 
			 
		     act_endplace_share  = (TextView) vContainer.findViewById(R.id.act_txt_endGeo_share);
		     act_endplace_share.setOnClickListener(ButtonOnClickListener);
			    
		     super.BBScate = BBSCate.ACT.toInt();
//			 
	}
	
	

	
	   OnCheckedChangeListener rdgChanged = new OnCheckedChangeListener() { 
		   
        @Override
        public void onCheckedChanged(RadioGroup arg0, int arg1) {
            // TODO Auto-generated method stub
            //获取变更后的选中项的ID
            int radioButtonId = arg0.getCheckedRadioButtonId();
            //根据ID获取RadioButton的实例
//            RadioButton rb = (RadioButton)activity.findViewById(radioButtonId);
            
            if(radioButtonId ==R.id.act_rd_addroadbook){ 
            	isRemoveRoadbook =false;
            }else if(radioButtonId ==R.id.act_rd_removeroadbook){ 
            	isRemoveRoadbook=true;             
            } else if(radioButtonId ==R.id.act_rd_single){
            	edit_act_startTime.setBackgroundColor(getResources().getColor(R.color.linen));
            	edit_act_endTime.setBackgroundColor(getResources().getColor(R.color.linen));
//            	edit_act_startTime.setTextAppearance(activity, R.style.activtity_edit_required);
//            	edit_act_endTime.setTextAppearance(activity, R.style.activtity_edit_required);
            	showRepeatDays(false);
            	
            } else if(radioButtonId ==R.id.act_rd_multi){
            	edit_act_startTime.setBackgroundColor(getResources().getColor(R.color.ivory));
            	edit_act_endTime.setBackgroundColor(getResources().getColor(R.color.ivory));
//            	edit_act_startTime.setTextAppearance(activity, R.style.activtity_edit);
//            	edit_act_endTime.setTextAppearance(activity, R.style.activtity_edit);
            	showRepeatDays(true);
            } else if(radioButtonId ==R.id.act_rd_public){
            	setActType(ActivityType.PUBLIC);
            } else if(radioButtonId ==R.id.act_rd_cycle){
            	setActType(ActivityType.CYCLE);
            }else if(radioButtonId ==R.id.act_rd_private){
            	setActType(ActivityType.PRIVATE);
            }
            	
             
        }
    }; 
    
  
    @Override
    void pickGeoPlace(int textViewId){
//    	activity.addressTextId=textViewId;
//    	activity.showLocationFinder();
    	saveSvrObj();
    	activity.addressTextId=textViewId;
    	setbackGeoInfo(textViewId);
    	activity.showLocationFinder();
     	 
    	 
    	
    	
    }
    
    void setbackGeoInfo(int textViewId){
    	if(textViewId == R.id.act_txt_startGeo_picker){
    		activity.latToshow =currentAct.getLat();
    		activity.lngToshow =currentAct.getLon();
    		
    	}else if(textViewId == R.id.act_txt_endGeo_picker){
    		activity.latToshow =currentAct.getEndGeo().getLat();
    		activity.lngToshow =currentAct.getEndGeo().getLon();
    	}
    	 
    }
    
	void setActType(ActivityType type){
//		ActivityType actype = ActivityType.valueOf(type);
		currentAct.setType( type/*ActivityType.valueOf(type)*//*actype*/);
 		
		
	}
		  
	void showRepeatDays(boolean isShow){
		isRepeatAct =isShow;
		vContainer.findViewById(R.id.act_ll_days).setVisibility(isShow?View.VISIBLE:View.GONE);
		
		
	}
	@Override	
	void onTimePicked(int viewId,long timePicked){
		if (viewId == R.id.act_edit_starttime) { 
			currentAct.setStartDate(timePicked);
		}else if (viewId == R.id.act_edit_endtime){
			currentAct.setEndDate(timePicked);
		}
			
	}
	 
	 
//		final String shareTab ="分享";
//		 String memberTab ="成员";
//		  String webTab="活动";
		 String roadbookTab ="路书";
		final String actLiveTab ="直播";
		 final int tabResourceId = R.id.tab_webquery;
		@Override
		void creatTabs(){
			 
		    memberTab ="成员";
		    
		    tabBbs = tabhost.newTabSpec(bbsTab);  
			tabBbs.setIndicator(bbsTab/*, getResources().getDrawable(R.drawable.icon_user,null)*/);
//			tabBbs.setContent(R.id.tab_bbs); 
			
			tabBbs.setContent(tabResourceId); 
			
        	tabRoadbook = tabhost.newTabSpec(roadbookTab);  
        	tabRoadbook.setIndicator(roadbookTab);
//        	tabRoadbook.setContent(R.id.tab_webquery); 
        	tabRoadbook.setContent(tabResourceId); 
		      
        	tabUser = tabhost.newTabSpec(memberTab);  
        	tabUser.setIndicator(memberTab);
//        	tabUser.setContent(R.id.act_tab_members);
        	tabUser.setContent(tabResourceId); 
			
			 tabTrack = tabhost.newTabSpec(shareTab);  
			 tabTrack.setIndicator(shareTab);
//			 tabTrack.setContent(R.id.act_tab_share);
			 tabTrack.setContent(tabResourceId); 
			 
			 tabLive = tabhost.newTabSpec(actLiveTab);  
			 tabLive.setIndicator(actLiveTab);
//			 tabLive.setContent(R.id.tab_map);
			 tabLive.setContent(tabResourceId); 
			
			 tabAct = tabhost.newTabSpec(actTab);  
			 tabAct.setIndicator(actTab);
//			 tabLive.setContent(R.id.tab_map);
			 tabAct.setContent(tabResourceId); 
			 
			 tabGrp = tabhost.newTabSpec(grpTab);  
			 tabGrp.setIndicator(grpTab);
//			 tabLive.setContent(R.id.tab_map);
			 tabGrp.setContent(tabResourceId); 
			  
			 
		}
		/*
		@Override
		void addTabs(){ 
			
			tabhost.addTab(t1);
			 
			if(currentAct.getSvrNumber()>0)	{  
				((LinearLayout)vContainer.findViewById(R.id.act_tab_members)).setVisibility( View.VISIBLE ); 
				 ((LinearLayout)vContainer.findViewById(R.id.act_tab_share)).setVisibility( View.VISIBLE ); 
				((LinearLayout)vContainer.findViewById(R.id.tab_map)).setVisibility( View.VISIBLE ); 
				
				
				 tabhost.addTab(t2); 
				 
				
				 tabhost.addTab(t3);
				 
				
				 tabhost.addTab(t4); 
				 
			}else{
				((LinearLayout)vContainer.findViewById(R.id.act_tab_members)).setVisibility( View.GONE ); 
					 ((LinearLayout)vContainer.findViewById(R.id.act_tab_share)).setVisibility( View.GONE ); 
					((LinearLayout)vContainer.findViewById(R.id.tab_map)).setVisibility( View.GONE ); 
//					  
			}
		}
		*/
		/*
		int newTabId=-1;		
		@Override
		void addPic(LinearLayout ll,int currentTab,int tabsCnt){
			 if(currentTab>newTabId){
				 super.addPic(ll, currentTab ,tabsCnt);
			 }
		        
			 ll.setPadding(10, 0, 0, 0);
		}
		*/
		
 
		@Override
		void loadRoadBook(){
//			 activity.showLocationFinder();
			
			
			
			
			
			
			
			if(isRemoveRoadbook){
				delActBook();
				return;
			}
			this.firstLoad=false;
			lastWebQueryPara="";
			if(!TextUtils.isEmpty(act_roadbook.getText())){
//				this.requestTrackFromWeb( Integer.valueOf(act_roadbook.getText().toString()));
				if(!currentAct.getRoadbooks().contains(Integer.valueOf(act_roadbook.getText().toString()))){
					currentAct.getRoadbooks().add(Integer.valueOf(act_roadbook.getText().toString()));
					doWebTrackQuery();//query out the added roadbooks
					updateRoadbooks();
				}else{
					 //show msg that the roadbook was already added
					Toast.makeText(activity, "已经添加了该路书", Toast.LENGTH_SHORT).show();
				}
			}
		 }
		
		@Override
	    void delActBook(){
			firstLoad=false;
			if(!TextUtils.isEmpty(act_roadbook.getText())){
				if(currentAct.getRoadbooks().contains(Integer.valueOf(act_roadbook.getText().toString()))){
					
					
					AlertDialog.Builder builder = new Builder(activity);
					   builder.setMessage("是否删除该路书？");
					   builder.setTitle("提示");
					   builder.setCancelable(false);
					   builder.setPositiveButton("确认", new android.content.DialogInterface.OnClickListener() {
						   @Override
						   public void onClick(DialogInterface dialog, int which) {
						   dialog.dismiss();	
						 
								currentAct.getRoadbooks().remove(Integer.valueOf(act_roadbook.getText().toString()));
								Toast.makeText(activity, "移除路书成功", Toast.LENGTH_SHORT).show();
								if(currentAct.getRoadbooks().size()>0){
									doWebTrackQuery();//query out the added roadbooks
								}else{
									 trackData = new ArrayList<Map<String, String>>();
									 showWebTrackListData(trackData);
									  
								} 
								updateRoadbooks();
								 
						   
							}
						});
					  builder.setNegativeButton("取消", new android.content.DialogInterface.OnClickListener() {
						 @Override
						 public void onClick(DialogInterface dialog, int which) {
							 dialog.dismiss();
							 
							 }
						 });
					  	builder.create().show();
					 
					  
				}else{
					 //show msg that the roadbook was already added
					Toast.makeText(activity, "活动没有添加该路书", Toast.LENGTH_SHORT).show();
				}
			}
	    	
	    }

		//update web activity roadbook
		void updateRoadbooks(){
			if(currentAct.getSvrNumber()>0){
				Activity_bean tmp = new Activity_bean();
				tmp.setSvrNumber(currentAct.getSvrNumber());
				tmp.setRoadbooks(currentAct.getRoadbooks());
				this.postJsonWS(Utils.getGsonString(tmp), RestMethods.ACT_P_UPDATE_ROODBOOK);
				
			}
		}
	    
		/*@Override
		 void  showWebTrack(Track track){ 
			if(track==null)return;
			staticMapImg= (QimageView) vContainer.findViewById(R.id.td_staticMap);
			td_track_sumary.setText(track.getSummary());
			 if(staticMapImg==null)return;
			 IL.DisplayImage(track.getStaticMap(),staticMapImg);  
			 act_roadbook.setText(track.getTrackBean().getName());
		  }*/
		
		
		
	 
		private void showDetail(int actid){
 			if(actid>0 && currentAct!=null && actid==currentAct.getSvrNumber()){
			 
			
//				initialWebQuery(); 
				
				
			/*	if(currentAct.getRoadbooks().size()>0){
					for(int i =0;i<currentAct.getRoadbooks().size();i++){
						if(currentAct.getRoadbooks().get(i)>0){
							requestTrackFromWeb(currentAct.getRoadbooks().get(i));//only toget general data
							break;
						}
					}
				}*/
				 
 				btn_submitAct.setText("更新");
 				
			}else{ //start new action
				newActivity();
				
			}
			
			getDetails(); 
		
			
		}
		
		
		void newActivity(){		
			loadLocalActivity();
			if(currentAct==null||currentAct.getSvrNumber()>0){
				currentAct = new Activity_bean();
				currentAct.setUserId(activity.app.user.getUserbean().getId());
				currentAct.setUserName(activity.app.user.getUserbean().getUserName());
			}
//			setActivityDetails();
			 
			
			
		}
		void getDetails(){
			
		 
			
			if(currentAct.getSvrNumber()>0  ){
//				act_creator.setText(currentAct.getUserName());
				setUserLinkSpanTxt(act_creator,currentAct.getUserId(),currentAct.getUserName());

				this.BBScate = BBSCate.ACT.toInt(); // act
				this.BBSSubcate = currentAct.getSvrNumber();
				this.BBSsubCateName = currentAct.getName();
			}else{
				act_creator.setText(activity.app.user.getUserbean().getUserName());
			}
			if ( !TextUtils.isEmpty(currentAct.getAlbum()) ){
				if (currentAct.getSvrNumber() > 0){
					IL.DisplayImage(QiYouConstant.BASE_MD_URL +	currentAct.getAlbum(), this.imgTopBanner);
				}else{
					IL.DisplayImage(currentAct.getAlbum(), this.imgTopBanner);
				}
			}else {
				 this.imgTopBanner.setBackgroundResource(R.drawable.icon_actbanner);
			}
			act_edit_title.setText(currentAct.getName());// + (currentAct.getSvrNumber() > 0 ? "" : "<草稿>"));
//			this.edit_act_endGeo.setText(currentAct.getEndAddress());
//			this.edit_act_startGeo.setText(currentAct.getStartAddress()); 
			this.edit_act_startGeo.setText(currentAct.getStartPlace());
			urlFormat(R.id.act_txt_startGeo_map,R.id.act_txt_startGeo_share,currentAct.getStartAddressUrl());
			

			this.edit_act_endGeo.setText(currentAct.getEndPlace());
			urlFormat(R.id.act_txt_endGeo_map,R.id.act_txt_endGeo_share,currentAct.getEndAddressUrl());
			act_edit_description.setText(currentAct.getDescription());
//			if(currentAct.getSvrNumber()>0)
			act_levlRatingBar.setRating(currentAct.getRateLevel());
			
			edit_act_startTime.setText(Utils.getFormatedTime(currentAct.getStartDate()));
			edit_act_endTime.setText(Utils.getFormatedTime(currentAct.getEndDate()));
			
			edit_act_distance.setText(String.format("%.0f",currentAct.getDistance()));
			edit_act_speed.setText(String.format("%.0f",currentAct.getAvSpeed()));
			if(currentAct.getSvrNumber()>0){
				act_svrNo.setText(currentAct.getSvrNumber()+"");
			}
			
			isRepeatAct = currentAct.isRepeatable();			
			showRepeatDays(isRepeatAct);			
			((RadioButton)repeatRdGroup.getChildAt(1)).setChecked(isRepeatAct);
			for(int i:currentAct.getDays()){
				switch (i){
				case 1: ((CheckBox) vContainer.findViewById(R.id.act_chk_day_1)).setChecked(true); break;
				case 2: ((CheckBox) vContainer.findViewById(R.id.act_chk_day_2)).setChecked(true); break;
				case 3: ((CheckBox) vContainer.findViewById(R.id.act_chk_day_3)).setChecked(true); break;
				case 4: ((CheckBox) vContainer.findViewById(R.id.act_chk_day_4)).setChecked(true); break;
				case 5: ((CheckBox) vContainer.findViewById(R.id.act_chk_day_5)).setChecked(true); break;
				case 6: ((CheckBox) vContainer.findViewById(R.id.act_chk_day_6)).setChecked(true); break;
				case 7: ((CheckBox) vContainer.findViewById(R.id.act_chk_day_7)).setChecked(true); break;
				}
			}
			
			((RadioButton)actTypeRdGroup.getChildAt( currentAct.getType().toInt())).setChecked(true);

		}
		void setDetails(){
 
		 
			if(currentAct.getSvrNumber()==0 || currentAct.getUserId()<=0){
				currentAct.setUserId(activity.app.user.getUserbean().getId());				
				currentAct.setUserName(activity.app.user.getUserbean().getUserName());
				act_creator.setText(currentAct.getUserName());
			}
//			
			currentAct.setName(act_edit_title.getText().toString());
			currentAct.setDescription(act_edit_description.getText().toString());
//			currentAct.setRateLevel(act_levlRatingBar.getNumStars());
			currentAct.setRateLevel(act_levlRatingBar.getRating()); 
			currentAct.setStartPlace(((EditText) vContainer.findViewById(R.id.act_edit_startGeo)).getText().toString());
			currentAct.setEndPlace(((EditText) vContainer.findViewById(R.id.act_edit_endGeo)).getText().toString());
			
				if(!TextUtils.isEmpty(edit_act_distance.getText())){				 
						try{
							currentAct.setDistance(Float.valueOf(edit_act_distance.getText().toString().trim()));		
						}catch(NumberFormatException e){
							
						} 
				}
				 
			
				if(!TextUtils.isEmpty(edit_act_distance.getText())){
					try{
						currentAct.setAvSpeed(Float.valueOf(edit_act_speed.getText().toString().trim()));
					}catch(NumberFormatException e){
						
					}
					
				}
				 
				
				currentAct.setRepeatable(isRepeatAct);
				currentAct.getDays().clear();
				for(int i=1;i<8;i++){
					switch (i){
					case 1: if(((CheckBox) vContainer.findViewById(R.id.act_chk_day_1)).isChecked()) currentAct.getDays().add(i); break;
					case 2: if(((CheckBox) vContainer.findViewById(R.id.act_chk_day_2)).isChecked()) currentAct.getDays().add(i); break;
					case 3: if(((CheckBox) vContainer.findViewById(R.id.act_chk_day_3)).isChecked()) currentAct.getDays().add(i); break;
					case 4: if(((CheckBox) vContainer.findViewById(R.id.act_chk_day_4)).isChecked()) currentAct.getDays().add(i); break;
					case 5: if(((CheckBox) vContainer.findViewById(R.id.act_chk_day_5)).isChecked()) currentAct.getDays().add(i); break;
					case 6: if(((CheckBox) vContainer.findViewById(R.id.act_chk_day_6)).isChecked()) currentAct.getDays().add(i); break;
					case 7: if(((CheckBox) vContainer.findViewById(R.id.act_chk_day_7)).isChecked()) currentAct.getDays().add(i); break;
					}
				}
				
		}
		
		
		
		
	
		
		void setFindResult(){
			
			if(canEdit() && activity.geoAddress!=null &&activity.geoAddress.getLat()>0 && activity.addressTextId!=0){
				
//				int txtid=activity.addressTextId == R.id.ll_start_place?R.id.act_edit_startGeo
//						:activity.addressTextId == R.id.ll_end_place?R.id.act_edit_endGeo:-1;
				

				int txtid=activity.addressTextId == R.id.act_txt_startGeo_picker?R.id.act_edit_startGeo
						:activity.addressTextId == R.id.act_txt_endGeo_picker?R.id.act_edit_endGeo:-1;
				
				 
				if(txtid==-1)return;
				
				if(activity.geoAddress==null || TextUtils.isEmpty(activity.geoAddress.getCity()) ||TextUtils.isEmpty(activity.geoAddress.getCity().replace("null", "")))return;
				
				EditText text =((EditText)vContainer.findViewById(txtid));
				
				if(text!=null){
					text.setText(activity.geoAddress.getName()); 
					
					if(txtid ==R.id.act_edit_startGeo){
						currentAct.setStartGeo(new GEO_bean(activity.geoAddress ));
						currentAct.getStartGeo().setSharedAddressUrl(activity.sharedAddressUrl );
						currentAct.setStartAddressUrl(activity.sharedAddressUrl);
						currentAct.setStartAddress(activity.geoAddress.getAddress());
						currentAct.setStartPlace(activity.geoAddress.getName());
						currentAct.setLat(activity.geoAddress.getLat());
						currentAct.setLon(activity.geoAddress.getLon());
						urlFormat(R.id.act_txt_startGeo_map,R.id.act_txt_startGeo_share,activity.sharedAddressUrl );
					}else					
					if(txtid ==R.id.act_edit_endGeo){
						currentAct.setEndGeo(new GEO_bean(activity.geoAddress ));
						currentAct.getEndGeo().setSharedAddressUrl(activity.sharedAddressUrl );
						currentAct.setEndAddressUrl(activity.sharedAddressUrl);
						currentAct.setEndAddress(activity.geoAddress.getAddress());
						currentAct.setEndPlace(activity.geoAddress.getName());
						urlFormat(R.id.act_txt_endGeo_map,R.id.act_txt_endGeo_share,currentAct.getEndAddressUrl());

					}
					
 					activity.geoAddress=null;
 					activity.addressTextId=0;
				}
			}
		}
		
		boolean canEdit(){
			return currentAct.getSvrNumber()==0
					|| currentAct==null 
					|| currentAct.getSvrNumber()==0
					|| currentAct.getUserId() ==activity.app.user.getUserbean().getId() 
			        ||this.isAdmin();
		}
		
		//show input as editable or not
		void validInputs(){
			
			boolean canEdit = canEdit();
			
			this.imgTopBanner.setEnabled(canEdit);
			
//			canEdit=false;
			int visible=canEdit?View.VISIBLE:View.GONE; 
			checkSvrObjUser(currentAct.getSvrNumber(),activity.app.user.getUserbean().getId()); 
			 
			 txtStartGeoPicker.setVisibility(visible);  
             txtEndGeoPicker.setVisibility(visible); 
			
       
//			btn_removeRoadbook.setEnabled(canEdit); 
//			btn_saveAct.setVisibility(visible);		
 			btn_submitAct.setVisibility(visible);		
			btn_submitAct.setEnabled(canEdit);
			btn_saveAct.setEnabled(currentAct.getSvrNumber()==0);
			btn_saveAct.setVisibility(currentAct.getSvrNumber()==0?View.VISIBLE:View.GONE);	
			btn_submitAct.setText(currentAct.getSvrNumber()>0?R.string.act_update:R.string.act_submit);
		
			
			act_edit_title.setEnabled(canEdit);
  
			
//			txtStartGeoPicker.setClickable(canEdit);  
//			txtEndGeoPicker.setClickable(canEdit); 
			
			edit_act_endGeo.setEnabled(canEdit);   
			edit_act_startGeo.setEnabled(canEdit); 
			
			
			
			
			act_edit_description.setEnabled(canEdit); 
			act_levlRatingBar.setEnabled(canEdit);  
			
			 
			  edit_act_startTime.setEnabled(canEdit); 
			  edit_act_endTime.setEnabled(canEdit);  
			  
			  edit_act_distance.setEnabled(canEdit); 
			  edit_act_speed.setEnabled(canEdit); 
  
			  this.repeatRdGroup.setEnabled(canEdit);

				for (int i = 0; i < repeatRdGroup.getChildCount(); i++) {
					repeatRdGroup.getChildAt(i).setEnabled(canEdit);
				}

				for (int i = 0; i < actTypeRdGroup.getChildCount(); i++) {
					actTypeRdGroup.getChildAt(i).setEnabled(canEdit);
				}
//			  btn_actJoin.setEnabled(currentAct.getSvrNumber()>0);
//			  btn_actJoin.setText(currentAct.getSvrNumber()>0?R.string.act_join:R.string.act_left);
			  
			  boolean canJoin = currentAct.getSvrNumber()>0 ;// && currentAct.getUserId() !=activity.app.user.getUserbean().getId();
			  visible=canJoin ?View.VISIBLE:View.GONE;
		 
 			  btn_actJoin.setVisibility(visible);
 			  btnShare.setVisibility(visible);
 			  
//		      btn_refresh.setEnabled(currentAct.getSvrNumber()>0);
//		      btn_refresh.setVisibility(currentAct.getSvrNumber()>0?View.VISIBLE:View.GONE);
			  
		}
		
		
		void urlFormat(int viewId ,int shareId,String url){
//			act_txt_endGeo_map
			TextView txtmap =(TextView) vContainer.findViewById(viewId); 
			 
			TextView txtshare =(TextView) vContainer.findViewById(shareId);  
		 
		     txtshare.setVisibility(View.GONE);
			
			if(TextUtils.isEmpty(url) || url.equalsIgnoreCase("null")) return;
//			String html =  editText.getText().toString() ; 
			String aformat= "\n<a href='%s'>地图</a>";
			String html =String.format(aformat, url);//这里即使不加协议好HTTP；也能自动被系统识别出来。 
			CharSequence charSequence = Html.fromHtml(html); 
			txtmap.setText(charSequence); 
//			txtview.setAutoLinkMask(Linkify.MAP_ADDRESSES); 
			txtmap.setMovementMethod(LinkMovementMethod.getInstance()); 
			txtshare.setVisibility(View.VISIBLE);
			
		}
		
		boolean validDate(){
			long startDate=currentAct.getStartDate();
			long endDate =currentAct.getEndDate();		
			
			
			if(currentAct.isRepeatable() ){
				if(startDate==0){
					currentAct.setStartDate(System.currentTimeMillis());
				}
			}
			
			boolean isPass =currentAct.isRepeatable() && currentAct.getDays().size()>0  ||
							(currentAct.getSvrNumber()>0 ||startDate>System.currentTimeMillis())	&& startDate<endDate;
 			if(!isPass){
				if(currentAct.isRepeatable()){ 
				
					showNotes("请设置活动周期数据");
					
					
				}else{
					if(currentAct.getSvrNumber() ==0 && startDate<System.currentTimeMillis()){
						
						
						if(startDate>0){
							((EditText) vContainer.findViewById(R.id.act_edit_starttime)).setText("");
							((EditText) vContainer.findViewById(R.id.act_edit_starttime)).setHint(Utils.getFormatedTime(startDate));
							((EditText) vContainer.findViewById(R.id.act_edit_starttime)).setHintTextColor(Color.RED);
						}
					
//						((EditText) vContainer.findViewById(R.id.act_edit_starttime)).setTextColor(Color.RED);
						showNotes("请输入正确的活动开始时间");
					 
					}else if( startDate >= endDate){
						((EditText) vContainer.findViewById(R.id.act_edit_endtime)).setText("");
						((EditText) vContainer.findViewById(R.id.act_edit_endtime)).setHint(Utils.getFormatedTime(endDate));
						((EditText) vContainer.findViewById(R.id.act_edit_endtime)).setHintTextColor(Color.RED);
//						((EditText) vContainer.findViewById(R.id.act_edit_endtime)).setTextColor(Color.RED);
						
						showNotes("请输入正确的活动结束时间");
					}
				}
			}
			return isPass;
		}
		
		@Override
		 void submitSvrObj(){
			
			setDetails();
 
		 
			
			if(validSubmit()){
				
				saveSvrObj();
				
				//			 QLog.getLogger().d(dTAG, "uploading activity is:" +Utils.getGsonString(currentAct));
				 
				 postSvr();
				
			}
			 
		}
		
		  void postSvr() {
			  this.postJsonWS(Utils.getGsonString(currentAct),RestMethods.ACT_P_IMPORT/* "mb/activity/"*/);    
		  }
		
		
		boolean validSubmit(){
			if(currentAct.getUserId() <=0){
				activity.showLogin();
				return false;
			}
			
			
			if(TextUtils.isEmpty(currentAct.getName() .trim())){
				
//				act_edit_title.setBackgroundColor(Color.YELLOW);
				act_edit_title.setHintTextColor(Color.RED);
				act_edit_title.setSelected(true);
				this.showNotes("请输入活动标题");
			return false;
			}
			if(TextUtils.isEmpty(currentAct.getStartPlace()  )){
				
//				act_edit_title.setBackgroundColor(Color.YELLOW);
				((EditText) vContainer.findViewById(R.id.act_edit_startGeo)).setHintTextColor(Color.RED);
				this.showNotes("请设置活动起始地点");
			return false;
			}
			
			if(TextUtils.isEmpty(currentAct.getDescription() .trim())){
				
//				act_edit_title.setBackgroundColor(Color.YELLOW);
				act_edit_description.setHintTextColor(Color.RED);
				this.showNotes("请输入活动须知信息");
			return false;
			}
			 
			
			
			
		 return !TextUtils.isEmpty(currentAct.getName().toString().trim())
								&& !TextUtils.isEmpty(currentAct.getStartPlace().toString().trim())
								&& !TextUtils.isEmpty(currentAct.getDescription().toString().trim())
								&& validDate();
			
			
			
		}
		
		@Override
		 void saveSvrObj(){
			setDetails();
			writeLocalObjCache();
			 
		}
		
		void writeLocalObjCache(){
			writeActivitiesCache(currentAct);
			showNotes("已保存草稿",false);  
		}
		
		void loadLocalActivity(){
			try {
				currentAct = getActFromWebCache(0,0);
			} catch (JsonSyntaxException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		
		
		
		@Override
		 void joinSvrObj(){
			int userId=activity.app.user.getUserbean().getId();
			int actId =currentAct.getSvrNumber(); 
			String userName=activity.app.user.getUserbean().getUserName();
			String rest =RestMethods.ACT_P_DEL_MEMBER;
		     if(btn_actJoin.getText().toString().equalsIgnoreCase(getResources().getString(R.string.act_join))){
		    	 rest=RestMethods.ACT_P_ADD_MEMBER;
		     }
		    
		     doMemberOperation(actId,currentAct.getName(),currentAct.getUserId(),userId, userName,rest);
		
		
		
		}
		
		@Override
		void removeUser(int userId){ 
			doMemberOperation(currentAct.getSvrNumber(),currentAct.getName(),currentAct.getUserId(),userId, activity.app.user.getUserbean().getUserName(),RestMethods.ACT_P_DEL_MEMBER);
		}
		
		void doMemberOperation(int svrId, String svrName,int ownerId,int userId,String userName,final String restMethod){
			 
			 if(userId<=0||svrId<=0){
				 return;
			 }
			 
				final JSONObject json = new JSONObject();
	            try {
					json.put("svrId", String.valueOf(svrId)); 
					json.put("userId", String.valueOf( userId));
					json.put("ownerId", String.valueOf( ownerId));
					json.put("userName", userName);
					json.put("svrName", svrName);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	            
			 if(restMethod.equalsIgnoreCase(RestMethods.ACT_P_DEL_MEMBER) 
					 || restMethod.equalsIgnoreCase(RestMethods.GRP_P_DEL_MEMBER))	{
			    	AlertDialog.Builder builder = new Builder(activity);
					   builder.setMessage("确认继续此退出操作？");
					   builder.setTitle("提示");
					   builder.setCancelable(false);
					   builder.setPositiveButton("确认", new android.content.DialogInterface.OnClickListener() {
						   @Override
						   public void onClick(DialogInterface dialog, int which) {
						   dialog.dismiss();	
						 
							  
					            postJsonWS(json.toString(), restMethod);
								 
						   
							}
						});
					  builder.setNegativeButton("取消", new android.content.DialogInterface.OnClickListener() {
						 @Override
						 public void onClick(DialogInterface dialog, int which) {
							 dialog.dismiss();
							 
							 }
						 });
					  	builder.create().show();
			    }else 
			    	postJsonWS(json.toString(), restMethod);
			 
			 
			 
			 
			
	            
				 /*if(btn_actJoin.getText().toString().equalsIgnoreCase(getResources().getString(R.string.act_join)))
					 postJsonWS(json.toString(), RestMethods.ACT_P_ADD_MEMBER"mb/activity/addmember");
				 else
					 postJsonWS(json.toString(),RestMethods.ACT_P_DEL_MEMBER "mb/activity/delmember");*/
			  
			
		}
		
		@Override
		 void processJsonObject(String method,JSONObject jsonObject,String msg)throws JSONException{
			 pirntCookies();
			 if(jsonObject==null)return;
			   
			 if(method.equalsIgnoreCase(RestMethods.ACT_P_ADD_MEMBER) 
					 || method.equalsIgnoreCase(RestMethods.GRP_P_ADD_MEMBER)){ //joinAct() 
//				if(Boolean.valueOf(jsonObject.getString(QiYouConstant.SIMPLE_KEY))){
				if(jsonObject!=null && jsonObject.has(QiYouConstant.SIMPLE_KEY) ){
					//success
//					this.showNotes(msg/*"您已加入"*/);
					  OperationType optype = OperationType.NORMAL;
					  optype= OperationType.valueOf(Integer.valueOf(jsonObject.getString(QiYouConstant.SIMPLE_KEY)));  

					    
					if(optype == OperationType.DONE) {
						btn_actJoin.setText(R.string.act_left);	
//						lastMemberQueryPara=""; 
//						doUserQuery(); 
					}else if(optype == OperationType.INPROGRESS){
						btn_actJoin.setText(R.string.act_joinInprogress);
						btn_actJoin.setEnabled(false);
					}else if(optype == OperationType.NORMAL){
						
					}
					
					shareObj();
				 
				}else{
					//failed
//					this.showNotes(msg/*"加入失败"*/);
				}
			
				this.showNotes(msg/*"您已加入"*/);
				
				 return;
			 }
			 
			 else if(method.equalsIgnoreCase(RestMethods.ACT_P_DEL_MEMBER)
					 ||method.equalsIgnoreCase(RestMethods.GRP_P_DEL_MEMBER)
					 ){ //LEAVE activity,group
				 if(Boolean.valueOf(jsonObject.getString(QiYouConstant.SIMPLE_KEY))){
						//success
						this.showNotes(msg/*"退出成功"*/);
						btn_actJoin.setText(R.string.act_join);
//					    lastMemberQueryPara="";
//						 doUserQuery(); 
						  
					}else{
						//failed
						this.showNotes(msg/*"退出失败"*/);
					}
					
					 return;
			 }
			 
			 else if(method.equalsIgnoreCase(RestMethods.ACT_P_IMPORT)){ //sumbmit act
			 
				 
				 int svrNo= jsonObject.getInt("svrNumber"); 
				 if(svrNo<=0)return;
				 
				  //check and upload image
				   
	//			 activity.app.user.getUserbean().setScore(jsonObject.getInt("userScore"));
	//			 activity.app.updateUserPref();
				 currentAct.setLastupdated(jsonObject.getInt("lastupdated"));
//			     svrNumber =currentAct.getSvrNumber();
				 
				 if(currentAct.getSvrNumber()!=svrNo){
					
					 currentAct.setSvrNumber(svrNo); 
					 
					 doMemberOperation(svrNo,currentAct.getName(),currentAct.getUserId(),activity.app.user.getUserbean().getId(),activity.app.user.getUserbean().getUserName(), RestMethods.ACT_P_ADD_MEMBER);

					 writeActivitiesCache(currentAct); 
					 if(!TextUtils.isEmpty(currentAct.getAlbum())){
						 setMD(currentAct.getAlbum(),0,null,null);
					 }
 					 showSubmitedObj(svrNo); 
					
				 }else{
					 showNotes(msg/*"更新成功！"*/);
				 }
				 
				
				 
				 
				 return;
				 
				 
				 
			 }else if(method.equalsIgnoreCase(RestMethods.ACT_P_UPDATE_ROODBOOK)){
				 
				 if(Boolean.valueOf(jsonObject.getString(QiYouConstant.SIMPLE_KEY))){
						//success
						this.showNotes(msg/*"路书更新成功"*/);
					 
						 
					}else{
						//failed
						this.showNotes(msg/*"路书更新失败"*/);
					}
				 return;
			 } 
 
		 }
		
		@Override
		void shareObj(){
			    String shareTitle =  super.BBSsubCateName  ;
			    String shareType = this.currentAct!=null?"队伍":"活动";
				String shareContent =  "欢迎加入"+shareType+"，约吗？";
//				Bitmap b = this.imgTopBanner.getDrawingCache();
//				Bitmap b = ((BitmapDrawable)imgTopBanner.getDrawable()).getBitmap();  
				Bitmap b  = Utils.getBitmapFromView(imgTopBanner);
//				String imgurl = currentAct !=null ? currentAct.getAlbum() :
				String type = BBSCate.values()[super.BBScate].toString();
				String url = String.format("%slist?%s=%s",  QiYouConstant.BASE_URL,type.toLowerCase(),super.BBSSubcate);
				 MobclickAgent.onEvent(activity,"shareObj-" + type);
				QLog.getLogger().d(dTAG, "url is:" + url +", sharecontent is "+shareContent +",title is "+ title);
				activity.doShare(shareTitle, shareContent, "", b ,   url);
				
			
		  }
		
	 
		 void checkSvrObjUserResult( JSONObject response) throws JSONException {
			 
			  if(response!=null && response.has(QiYouConstant.SIMPLE_KEY) ){
				  OperationType optype = OperationType.NORMAL;
				    optype= OperationType.valueOf(Integer.valueOf(response.getString(QiYouConstant.SIMPLE_KEY)));  

				 /* try{
				    optype= OperationType.valueOf(Integer.valueOf(response.getString(QiYouConstant.SIMPLE_KEY)));  
				  }catch(IllegalArgumentException e){
					  
				  }*/
			
//				  boolean isInTheAct=Boolean.valueOf(response.getString(QiYouConstant.SIMPLE_KEY)); 
//				  btn_actJoin.setText(isInTheAct?R.string.act_left:R.string.act_join);
				  int res=optype==OperationType.DONE?R.string.act_left           //has been in
						  							:optype==OperationType.INPROGRESS?R.string.act_joinInprogress    //waiting for approve
						  									:   R.string.act_join; 
			      btn_actJoin.setEnabled(optype!=OperationType.INPROGRESS);		  
				  btn_actJoin.setText(res);
			  }
		  }
		
		
		  void checkSvrObjUser(int actId,int userId){
			  if(actId<=0 || userId<=0){
				  return;
			  }
				RequestParams params = new RequestParams();  
				params.add("actId", String.valueOf( actId)); 
				params.add("userId", String.valueOf( userId)); 
				//			 QLog.getLogger().d(dTAG, TAG+" web query params: "+params);
				
				getJsonWs(params,RestMethods.ACT_G_IS_MEMBER_HAS_ACT /*"mb/activity/isMemberHasAct"*/,true);
		  }
		  
		
		
		  @Override
			void processGetJsonObject(String method,JSONObject jsonObject,String msg) throws JSONException,NullPointerException, NoWebObjectException {
			 super.processGetJsonObject(method, jsonObject, msg); 
				  
			    if(method.equalsIgnoreCase(RestMethods.ACT_G_IS_MEMBER_HAS_ACT)){
			    	checkSvrObjUserResult(jsonObject);
					 
				 }else if(method.equalsIgnoreCase(RestMethods.GRP_G_IS_MEMBER_HAS_GRP)){
					 checkSvrObjUserResult(jsonObject);
				 }
			  
		  }
		 
		  
		  void showSubmitedObj(int svrNo) {
			  act_svrNo.setText(svrNo+"");
			  showNotes("上传成功！云编号："+svrNo);
			
 			 
 			  activity.updateActionBarTitle(title);	
			  validInputs();
			  getDetails(); 
			  mapViewOnActivityCreated();
			  shareObj();
			  
		  }
     
		  
//	  @Override
//	  void showActivity(Activity_bean act) { 
//		  this.currentAct=act;
//		  getDetails();  
//		 }
		  
		  

		@Override
		public void onActivityResult(int requestCode, int resultCode, Intent data) {
			
				super.onActivityResult(requestCode, resultCode, data);  
				/*if(requestCode ==SELECT_PIC_KITKAT ||requestCode ==SELECT_PIC) 				 
				if (resultCode == Activity.RESULT_OK) {
//					picPath = data.getStringExtra(SelectPicActivity.KEY_PHOTO_PATH);
//					Log.i(TAG, "最终选择的图片="+picPath);
//					Bitmap bm = BitmapFactory.decodeFile(picPath);
//					imageView.setImageBitmap(bm);
					 
					Uri photoUri = data.getData();
					String path= Utils.getPath(activity,photoUri);
 				setMD(path,System.currentTimeMillis(),mdWp,mediaType.PIC);
					
				}*/
			}
		
		
		@Override
		 protected void setMD(String picName,long time,Waypoint wp,mediaType mdType){
			 
			 
			
			if (currentAct.getSvrNumber() > 0){
				Media md = new Media();
				md.setTrackSvrNumber(currentAct.getSvrNumber());
				md.setUri(picName);
				md.setType(mediaType.PIC);
				md.setSvrUri(currentAct.getAlbum());
				try {
					super.postBinaryWS(md, RestMethods.ACT_P_UPLOAD_ALBUM);
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			 
				
			}else {
				IL.DisplayImage(picName,imgTopBanner);
				currentAct.setAlbum(picName);
			}
			
			 
		 }
		
		@Override
		 void uploadMediasOnReturn(JSONObject jo)  {
			this.showNotes("图片上传成功！");
			if (jo!=null){
				try {
					if (currentAct!=null){
						currentAct.setAlbum(jo.getString("svrUri"));
					} 
					 
					IL.DisplayImage(QiYouConstant.BASE_MD_URL +	jo.getString("svrUri"),imgTopBanner);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			
		 }
		 
	  
//	@Override	
//	 void processTabQuery(){
//	 }
	
	@Override
	public void onResume() { 
//        activity.app.currentActiveFragment =TAG;
		super.onResume();
        activity.updateActionBarTitle(title);	
        setFindResult();
        validInputs();
	   
	}
	
	@Override	
	   void shareEndUrl(int viewId){
			
			Intent sendIntent = new Intent();
			sendIntent.setAction(Intent.ACTION_SEND);
			String url =viewId==R.id.act_txt_startGeo_share? currentAct.getStartAddressUrl()
															: currentAct.getEndAddressUrl();
			String title =viewId==R.id.act_txt_startGeo_share? currentAct.getStartPlace()
					: currentAct.getEndPlace();
			 title =this.currentAct.getName() +"【活动地址】"+title;
			if(viewId==R.id.act_txt_startGeo_share)
			sendIntent.putExtra(Intent.EXTRA_TEXT,title+ url);
			sendIntent.setType("text/plain");
			startActivity(Intent.createChooser(sendIntent,title ));
			
		}
	
	@Override
	public boolean isShowBottomTabs() {
		// TODO Auto-generated method stub
		return false;
	}
	
	   
}
