
package com.lianxin.pubqq.chat;

import java.util.Date;

import android.content.Intent;
import android.os.Bundle;
import android.os.Looper;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.lianxin.panqq.chat.BaseActivity;
import com.lianxin.panqq.chat.entity.EMMessage;
import com.lianxin.pubqq.R;
import com.lianxin.pubqq.main.MyApp;

public class ContextMenu extends BaseActivity {

	private int position;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		int txtValue = EMMessage.MsgType.MSG_TEXT;
		int type = getIntent().getIntExtra("type", 0);
		int mode = getIntent().getIntExtra("mode", 0);
		int sendtime = getIntent().getIntExtra("sendtime", 0);		
		if (type == EMMessage.MsgType.MSG_TEXT) {
		    setContentView(R.layout.context_menu_for_text);
		    if(mode < 1)
		    {
		    	LinearLayout lay_cancel = (LinearLayout) findViewById(R.id.rl_msg_cancel);	
		    	lay_cancel.setVisibility(View.GONE);		    	
		    }else{
		    	int nowtime = (int) (new Date().getTime()/1000);
			    if((nowtime-sendtime) > 600)
			    {
			    	LinearLayout lay_cancel = (LinearLayout) findViewById(R.id.rl_msg_cancel);	
			    	lay_cancel.setVisibility(View.GONE);		    	
			    }
	    
		    }
		    if(mode > 1)
		    {
		    	LinearLayout lay_mark = (LinearLayout) findViewById(R.id.rl_msg_mark);	
		    	lay_mark.setVisibility(View.GONE);		    	
		    }
		    
		} else if (type == EMMessage.MsgType.MSG_LOCATION) {
		    setContentView(R.layout.context_menu_for_location);
		} else if (type == EMMessage.MsgType.MSG_IMAGE) {
		    setContentView(R.layout.context_menu_for_image);
		} else if (type == EMMessage.MsgType.MSG_VOICE) {
		    setContentView(R.layout.context_menu_for_voice);
		} else if (type == EMMessage.MsgType.MSG_VIDEO) {
			setContentView(R.layout.context_menu_for_video);
		}		    

		position = getIntent().getIntExtra("position", -1);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		finish();
		return true;
	}

	public void copy(View view){
		setResult(EMChatActivity.RESULT_CODE_COPY, new Intent().putExtra("position", position));
		finish();
	}
	public void delete(View view){
		setResult(EMChatActivity.RESULT_CODE_DELETE, new Intent().putExtra("position", position));
		finish();
	}
	public void cancel(View view){
		setResult(EMChatActivity.RESULT_CODE_CANCEL, new Intent().putExtra("position", position));
		finish();
	}	
	public void mark(View view){
		setResult(EMChatActivity.RESULT_CODE_MARK, new Intent().putExtra("position", position));
		finish();
	}	
	public void forward(View view){
		setResult(EMChatActivity.RESULT_CODE_FORWARD, new Intent().putExtra("position", position));
		finish();
	}
	
	public void open(View v){
	    setResult(EMChatActivity.RESULT_CODE_OPEN, new Intent().putExtra("position", position));
        finish();
	}
	public void download(View v){
	    setResult(EMChatActivity.RESULT_CODE_DWONLOAD, new Intent().putExtra("position", position));
        finish();
	}
	public void toCloud(View v){
	    setResult(EMChatActivity.RESULT_CODE_TO_CLOUD, new Intent().putExtra("position", position));
        finish();
	}
	
}
