package com.samples.clipboardmanager;

import android.app.Activity;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class ClipboardManagerActivity extends Activity 
		implements View.OnClickListener {
	
	private ClipboardManager manager;
    private EditText textCopy;
    private TextView textPaste;
    
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.main);
	 
	    textCopy = (EditText)findViewById(R.id.textCopy);
	    textPaste = (TextView)findViewById(R.id.textPaste);
	    
	    final Button bCopy = (Button)findViewById(R.id.bCopy);
	    final Button bViewAllClips = (Button)findViewById(R.id.bPaste);
	    
	    bCopy.setOnClickListener(this);    
	    bViewAllClips.setOnClickListener(this);
	    
	    manager = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.bCopy:
			manager.setText(textCopy.getText());
			break;
		case R.id.bPaste:
			textPaste.append(manager.getText() + "\n");
			break;
		}	
	}	
}