码迷,mamicode.com
首页 > 其他好文 > 详细

电话拨号盘(带触摸振动反馈)

时间:2014-12-22 18:07:06      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:拨号盘   安卓   android   振动反馈   

package com.example.theold;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Vibrator;
import android.provider.Contacts;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class phoneCall extends Activity {
       
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.phonecall_layout);
		final Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
		final int vibrateTime = 40 ;
		final EditText text = (EditText)findViewById(R.id.text) ;
		Button one  = (Button)findViewById(R.id.one) ;
		Button two  = (Button)findViewById(R.id.two) ;
		Button three  = (Button)findViewById(R.id.three) ;
		Button four  = (Button)findViewById(R.id.four) ;
		Button five  = (Button)findViewById(R.id.five) ;
		Button six  = (Button)findViewById(R.id.six) ;
		Button seven  = (Button)findViewById(R.id.seven) ;
		Button eight  = (Button)findViewById(R.id.eight) ;
		Button nine  = (Button)findViewById(R.id.nine) ;
		Button zero  = (Button)findViewById(R.id.zero) ;
		Button xing  = (Button)findViewById(R.id.xing) ;
		Button jing  = (Button)findViewById(R.id.jing) ;
		Button backspace  = (Button)findViewById(R.id.backspace) ;
		Button call  = (Button)findViewById(R.id.call) ;
		Button people =(Button)findViewById(R.id.people) ;
		zero.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				str+="0" ;
				text.setText(str);
				vibrator.vibrate(vibrateTime);
				
			}
		});
		
		
      one.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				str+="1" ;
				text.setText(str);
				vibrator.vibrate(vibrateTime);
				
			}
		});
      
      
      two.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				str+="2" ;
				text.setText(str);
				vibrator.vibrate(vibrateTime);
				
			}
		});
      
      
      three.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				str+="3" ;
				text.setText(str);
				vibrator.vibrate(vibrateTime);
				
			}
		});
      
      
      four.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				str+="4" ;
				text.setText(str);
				vibrator.vibrate(vibrateTime);
				
			}
		});
      
      
      five.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				str+="5" ;
				text.setText(str);
				vibrator.vibrate(vibrateTime);
				
			}
		});
      
      
      six.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				str+="6" ;
				text.setText(str);
				vibrator.vibrate(vibrateTime);
				
			}
		});
      
      
      seven.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				str+="7" ;
				text.setText(str);
				vibrator.vibrate(vibrateTime);
				
			}
		});
      
      eight.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				str+="8" ;
				text.setText(str);
				vibrator.vibrate(vibrateTime);
				
			}
		});
      
      
      nine.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				str+="9" ;
				text.setText(str);
				vibrator.vibrate(vibrateTime);
				
			}
		});
      
      
      xing.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				str+="*" ;
				text.setText(str);
				vibrator.vibrate(vibrateTime);
				
			}
		});
      
      
      jing.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				str+="#" ;
				text.setText(str);
				vibrator.vibrate(vibrateTime);
				
			}
		});
      
      
      
      backspace.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				int len = str.length() ;
				if(len==0)
				{
					vibrator.vibrate(vibrateTime);
					return ;
				}
				str = str.substring(0,len-1) ;
				text.setText(str);
				vibrator.vibrate(vibrateTime);
				
			}
		});
      
      call.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CharSequence temp = text.getText() ;
				String str = temp.toString();
				vibrator.vibrate(vibrateTime);
				Intent intent = new Intent() ;
				intent.setAction(Intent.ACTION_CALL) ;
				intent.setData(Uri.parse("tel:"+str)) ;
				startActivity(intent);
				
			}
		});
      people.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
            /* Intent intent= new Intent("com.android.contacts.action.LIST_STREQUENT");   
		    intent.setClassName("com.android.contacts","com.android.contacts.DialtactsActivity");
		    startActivity(intent);*/
			Intent intent = new Intent() ;
			intent.setClass(getApplicationContext(), Photos.class) ;
			startActivity(intent);
			
		}
	});
	}

}

 

技术分享



电话拨号盘(带触摸振动反馈)

标签:拨号盘   安卓   android   振动反馈   

原文地址:http://blog.csdn.net/u012566693/article/details/42081633

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!