码迷,mamicode.com
首页 > 移动开发 > 详细

Android小项目之 where are you 监控

时间:2015-07-27 23:12:29      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:android

第一个小项目,实现监控短信,电话,以及响铃,震动,监控位置还没添加,会后续更新,先把代码贴上来

第一个是一个登录界面:

技术分享

xml:

技术分享

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:background="@drawable/green1"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="34dp"
        android:layout_marginTop="40dp"
        android:textColor="#ff008000"
        android:text="用户名:" />

    <EditText
        android:id="@+id/txtLogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_marginLeft="28dp"
        android:layout_marginTop="25dp"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#ff008000"
        android:layout_alignLeft="@+id/txtLogin"
        android:layout_below="@+id/txtLogin"
        android:layout_marginTop="30dp"
        android:text="密码:" />

    <EditText
        android:id="@+id/txtPass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView2"
        android:layout_centerVertical="true"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/btnLogin"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:layout_alignLeft="@+id/textView1"
        android:layout_alignRight="@+id/txtLogin"
        android:layout_below="@+id/txtPass"
        android:layout_marginTop="22dp"
        android:textColor="#ff008000"
        android:background="#5f888888"
        android:text="登陆" />

    <Button
        android:id="@+id/btnAbout"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:layout_alignLeft="@+id/btnExit"
        android:layout_alignParentBottom="true"
        android:textColor="#ff008000"
        android:background="#5f888888"
        android:layout_alignRight="@+id/btnExit"
        android:text="关于登陆" />

    <Button
        android:id="@+id/btnExit"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:layout_alignLeft="@+id/btnLogin"
        android:textColor="#ff008000"
        android:background="#5f888888"
        android:layout_alignRight="@+id/btnLogin"
        android:layout_below="@+id/btnLogin"
        android:layout_marginTop="15dp"
        android:text="退出" />

</RelativeLayout>

MainActivity.java

package com.example.whereareyou;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		final EditText txtLogin = (EditText) this.findViewById(R.id.txtLogin);
		final EditText txtPass = (EditText) this.findViewById(R.id.txtPass);
		
		Button btnLogin = (Button) this.findViewById(R.id.btnLogin);
		Button btnExit = (Button) this.findViewById(R.id.btnExit);
		Button btnAbout = (Button) this.findViewById(R.id.btnAbout);
		
		btnLogin.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
			    Intent intent = new Intent();
			    
			    String login = txtLogin.getText().toString();
			    String pass = txtPass.getText().toString();
			    
				if(login.equals("ahut") && pass.equals("123")){
					Toast.makeText(getApplicationContext(), "欢迎使用", 3000).show();
					intent.setClass(getApplicationContext(), LMainActivity.class);
					startActivity(intent);
				}
				else{
					Toast.makeText(getApplicationContext(), "用户名或密码错误", 3000).show();
				}
			}
		});
		
		btnAbout.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Toast.makeText(getApplicationContext(), "用户名为:ahut 密码为:123      " +
						"@安徽工业大学 计算机学院  辛闻", 8*1000).show();
			}
		});
		
		btnExit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.lmain, menu);
		return true;
	}

}

第二个是监控页面

技术分享

xml:

技术分享


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/RelativeLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/green1"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".LMainActivity" >

    <EditText
        android:id="@+id/txtNumber"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:ems="10"
        android:inputType="phone" >

        <requestFocus />
    </EditText>

    <CheckBox
        android:id="@+id/cbPhone "
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/txtNumber"
        android:text="监听电话"
        android:textColor="#ff008000" />

    <CheckBox
        android:id="@+id/cbSms"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/cbPhone "
        android:text="监听短信"
        android:textColor="#ff008000" />

    <CheckBox
        android:id="@+id/cbCall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/cbSms"
        android:text="回拨电话"
        android:textColor="#ff008000" />

    <CheckBox
        android:id="@+id/cbRing"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/cbCall"
        android:text="响铃"
        android:textColor="#ff008000" />

    <CheckBox
        android:id="@+id/cbVib"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/cbRing"
        android:text="震动"
        android:textColor="#ff008000" />

    <CheckBox
        android:id="@+id/cbLoc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/cbVib"
        android:text="位置监控"
        android:textColor="#ff008000" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="24dp"
        android:layout_toRightOf="@+id/cbPhone "
        android:text="请输入电话号码"
        android:textColor="#ff008000" />

    <Button
        android:id="@+id/btnListen"
        android:layout_width="270dp"
        android:layout_height="40dp"
        android:layout_alignLeft="@+id/cbLoc"
        android:layout_alignRight="@+id/btnSet"
        android:layout_below="@+id/cbLoc"
        android:layout_marginTop="10dp"
        android:background="#ff00ff00"
        android:text="开始监控"
        android:textColor="@drawable/white"
        android:textSize="30dp" />

    <Button
        android:id="@+id/btnSet"
        android:layout_width="206dp"
        android:layout_height="41dp"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/txtNumber"
        android:layout_toRightOf="@+id/textView1"
        android:background="#5f888888"
        android:text="设置"
        android:textColor="@drawable/white" />

    <Button
        android:id="@+id/btnExit2"
        android:layout_width="206dp"
        android:layout_height="42dp"
        android:layout_alignLeft="@+id/btnListen"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/cbLoc"
        android:background="#5f888888"
        android:text="返回"
        android:textColor="@drawable/white" />

</RelativeLayout>

LMainActivity.java:

package com.example.whereareyou;

import android.R.drawable;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class LMainActivity extends Activity{
	
	EditText txtNumber;
	
	CheckBox cbPhone;	
	CheckBox cbSms;
	CheckBox cbCall;
	CheckBox cbRing;
	CheckBox cbVib;
	CheckBox cbLoc;
	
	Button btnListen;
	Button btnSet;
	Button btnExit2;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lmain);
		
		txtNumber = (EditText) this.findViewById(R.id.txtNumber);
		
		cbPhone = (CheckBox) this.findViewById(R.id.cbPhone);
		cbSms = (CheckBox) this.findViewById(R.id.cbSms);
		cbCall = (CheckBox) this.findViewById(R.id.cbCall);
		cbRing = (CheckBox) this.findViewById(R.id.cbRing);
		cbVib = (CheckBox) this.findViewById(R.id.cbVib);
		cbLoc = (CheckBox) this.findViewById(R.id.cbLoc);
		
		btnListen = (Button) this.findViewById(R.id.btnListen);
		btnSet = (Button) this.findViewById(R.id.btnSet);
		btnExit2 = (Button) this.findViewById(R.id.btnExit2);
		
		btnListen.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String number = txtNumber.getText().toString();
				
				if(number.trim().equals("")){//去掉前后的空格
					Toast.makeText(LMainActivity.this,"请输入电话号码",3000).show();
					return ;
				}
						
				boolean isPhone = cbPhone.isChecked();
				boolean isSms   = cbSms.isChecked();
				boolean isCall  = cbCall.isChecked();
				boolean isRing  = cbRing.isChecked();
				boolean isVib   = cbVib.isChecked();
				boolean isLoc   = cbLoc.isChecked();
				
			    if(isPhone||isSms||isCall||isRing||isVib||isLoc){
					AppContext.setNumber(number);
			    	AppContext.setCall(isCall);
			    	AppContext.setPhone(isPhone);
			    	AppContext.setSms(isSms);
			    	AppContext.setLoc(isLoc);
			    	AppContext.setRing(isRing);
			    	AppContext.setVib(isVib);
			    	
		    		Intent intent = new Intent();
		    		intent.setClass(getApplicationContext(), ListenPhone.class);
		    		
			    	if(btnListen.getText().toString().equals("开始监控")){
			    		btnListen.setText("停止监控");
			    		btnListen.setBackgroundColor(Color.RED);
			    		//启动service	    			
			    		startService(intent);
			    	}else{
			    		btnListen.setText("开始监控");
			    		btnListen.setBackgroundColor(Color.GREEN);
			    		//停止service
			    		stopService(intent);
			    	}
			    	
			    }else{
			    	Toast.makeText(getApplicationContext(), "请选择监控项目", 3000).show();
			    	return ;
			    }
			}
		});
		
		btnSet.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(LMainActivity.this, SMainActivity.class);
				startActivity(intent);
			}
		});
		
		btnExit2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

后面的就没啥技术含量就不贴出来了


版权声明:本文为博主原创文章,未经博主允许不得转载。

Android小项目之 where are you 监控

标签:android

原文地址:http://blog.csdn.net/xinwen1995/article/details/47090805

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