Click here to Skip to main content
15,881,833 members
Articles / Mobile Apps / Android

Touch handling in Android

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
18 Oct 2012CPOL8 min read 75.1K   1.8K   20  
Touch handling in Android.
package com.hfk.yatv;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

public class TouchVisualizerSingleTouchDialogActivity extends Activity {
	static final int CUSTOM_DIALOG_ID = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.singletouch_dialog_view);              
        
        Button buttonStartDialog = (Button)findViewById(R.id.btnShowDialog);       
        buttonStartDialog.setOnClickListener(
        		new Button.OnClickListener(){   
        			@Override  public void onClick(View arg0) 
        			{   
        				removeDialog(CUSTOM_DIALOG_ID);
        				showDialog(CUSTOM_DIALOG_ID);  
        			}       
    			});
	}
	
	@Override
	protected Dialog onCreateDialog(int id) { 

		Dialog dialog = null;;    
		switch(id) {    
		case CUSTOM_DIALOG_ID:     
			dialog = new TouchVisualizerSingleTouchDialog(TouchVisualizerSingleTouchDialogActivity.this);          
	           
			break;    
			}    
		return dialog;
	}  
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.graphic_config, menu);
	    return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int menuItem = item.getItemId();
	    switch (menuItem) {
	        case R.id.mnu_single_graphic_config:
	    		Intent myIntent = new Intent(TouchVisualizerSingleTouchDialogActivity.this, TouchVisualizerTouchDialogConfigActivity.class);
	    	    
	    		Bundle b = new Bundle();
	    	    b.putBoolean(TouchVisualizerTouchDialogConfigActivity.REGISTER_OUTSIDETOUCH, this.getRegisterForOutsideTouch());
	    	    b.putBoolean(TouchVisualizerTouchDialogConfigActivity.HANDLE_ACTIONOUTSIDE, this.getHandleActionOutside());

	    	    myIntent.putExtras(b);

	    	    startActivityForResult(myIntent, 0);
	    		return true;
	        default:
	            return super.onOptionsItemSelected(item);
	    }
	}
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent){
    	Bundle config = intent.getExtras();
    	
    	this.setRegisterForOutsideTouch(config.getBoolean(TouchVisualizerTouchDialogConfigActivity.REGISTER_OUTSIDETOUCH));
    	this.setHandleActionOutside(config.getBoolean(TouchVisualizerTouchDialogConfigActivity.HANDLE_ACTIONOUTSIDE));
    }
	
	public void setRegisterForOutsideTouch(boolean value)
	{
		registerForOutsideTouch = value;
	}
	
	public boolean getRegisterForOutsideTouch()
	{
		return registerForOutsideTouch;
	}
	
	public void setHandleActionOutside(boolean value)
	{
		handleActionOutside = value;
	}
	
	public boolean getHandleActionOutside()
	{
		return handleActionOutside;
	}
    
    private boolean registerForOutsideTouch = true;
    private boolean handleActionOutside = true;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions