/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.BluetoothChat;
import java.io.UnsupportedEncodingException;
import java.util.UUID;
import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
/**
* This is the main Activity that displays the current chat session.
*/
public class BluetoothChat extends Activity {
// 调试
private static final String TAG = "BluetoothChat";
private static boolean D = true;
private static final String info = "junge";
// 类型的消息发送从bluetoothchatservice处理程序
public static final int MESSAGE_STATE_CHANGE = 1;
public static final int MESSAGE_READ = 2;
public static final int MESSAGE_WRITE = 3;
public static final int MESSAGE_DEVICE_NAME = 4;
public static final int MESSAGE_TOAST = 5;
public static final String BluetoothData = "fullscreen";
public String filename = ""; // 用来保存存储的文件名
private String newCode = "";
private String newCode2 = "";
private String fmsg = ""; // 保存用数据缓存
// 键名字从收到的bluetoothchatservice处理程序
public static final String DEVICE_NAME = "device_name";
public static final String TOAST = "toast";
// 独特的是这个应用程序
private static final UUID MY_UUID = UUID
.fromString("00001101-0000-1000-8000-00805F9B34FB");
// Intent需要 编码
public static final int REQUEST_CONNECT_DEVICE = 1;
private static final int REQUEST_ENABLE_BT = 2;
// 布局控件
private TextView mTitle;
private EditText mInputEditText;
private EditText mIlluminationText;
private EditText mHumidity;
private EditText mOutEditText;
private EditText mOutEditText2;
private Button mSendButton;
private CheckBox HEXCheckBox;
private Button breakButton;
private CheckBox checkBox_sixteen;
private ImageView ImageLogoView;
// 名字的连接装置
private String mConnectedDeviceName = null;
// 传出消息的字符串缓冲区
private StringBuffer mOutStringBuffer;
// 当地的蓝牙适配器
private BluetoothAdapter mBluetoothAdapter = null;
// 成员对象的聊天服务
private BluetoothChatService mChatService = null;
// 设置标识符,选择用户接受的数据格式
private boolean dialogs;
//第一次输入加入-->变量
private int sum =1;
private int UTF =1;
private int a=0;
private int b=0;
private int c=0;
// 名社民党记录当创建服务器套接字
String mmsg = "";
String mmsg2 = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
D = false;
if (D)
Log.e(TAG, "+++ ON CREATE +++");
Log.i(info, "" + dialogs);
// 设置窗口布局
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title);
mInputEditText = (EditText) findViewById(R.id.editText1);
mIlluminationText=(EditText) findViewById(R.id.illumination);
mHumidity=(EditText) findViewById(R.id.humidity);
//mInputEditText.setGravity(Gravity.TOP);
mInputEditText.setSelection(mInputEditText.getText().length(),
mInputEditText.getText().length());
mInputEditText.clearFocus();
mInputEditText.setFocusable(false);
// mIlluminationText.setSelection(mIlluminationText.getText().length(),
// mIlluminationText.getText().length());
// mIlluminationText.clearFocus();
// mIlluminationText.setFocusable(false);
//
// mHumidity.setSelection(mHumidity.getText().length(),
// mHumidity.getText().length());
// mHumidity.clearFocus();
// mHumidity.setFocusable(false);
//设置ImageView
ImageLogoView = (ImageView)findViewById(R.id.imagelogo);
ImageLogoView.setImageResource(R.drawable.logo);
// 设置文本的标题
mTitle = (TextView) findViewById(R.id.title_left_text);
mTitle.setText(R.string.app_name);
mTitle = (TextView) findViewById(R.id.title_right_text);
// 初始化Radiobutton]
HEXCheckBox = (CheckBox) findViewById(R.id.radioMale);
breakButton = (Button) findViewById(R.id.button_break);
// 得到当地的蓝牙适配器
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// 初始化CheckBox
checkBox_sixteen = (CheckBox) findViewById(R.id.checkBox_sixteen);//点击图片跳转到公司页面
ImageLogoView.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("http://www.dlmu.edu.cn"));
startActivity(intent);
}
});
if(getWindow().getAttributes().softInputMode==WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED)
{
//隐藏软键盘
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
// 初始化Socket
if (mBluetoothAdapter == null) {
Toast.makeText(this, R.string.not_connected, Toast.LENGTH_LONG)
.show();
finish();
return;
}
checkBox_sixteen
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// String getValue = mInputEditText.getText().toString();
// if (isChecked) {
// mInputEditText.setText(CodeFormat.stringToHex(getValue));
//
// } else {
// mInputEditText.setText(fmsg);
//
// }
}
});
HEXCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
mOutEditText.setText("");
mOutEditText.setVisibility(View.GONE);
mOutEditText2.setVisibility(View.VISIBLE);
} else {
mOutEditText.setVisibility(View.VISIBLE);
mOutEditText2.setVisibility(View.GONE);
}
}
});
}
@Override
public void onStart() {
super.onStart();
if (D)
Log.e(TAG, "++ ON START ++");
// 如果是没有,要求它启用。
// setupchat()将被称为在onactivityresult
if (!mBluetoothAdapter.isEnabled()) {
//以为这样会无提示,结果无效,fu'c'k
// mBluetoothAdapter.enable();
Intent enableIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
// 否则,设置聊天会话
} else {
if (mChatService == null)
setupChat();
}
}
// 连接按键响应函数
public void onConnectButtonClicked(View v) {
if (breakButton.getText().equals("连接")||breakButton.getText().equals("connect")) {
Intent serverIntent = new Intent(this, D
没有合适的资源?快使用搜索试试~ 我知道了~
蓝牙智能温室控制系统APP
共78个文件
class:34个
xml:13个
log:11个
1星 需积分: 24 11 下载量 73 浏览量
2017-05-11
23:41:12
上传
评论 1
收藏 276KB RAR 举报
温馨提示
HC-05蓝牙从机将温度、光照强度与湿度按照“\n**C**#**%”的格式发送到手机上,APP上会显示出这些信息; 并且,可以通过按键控制水泵、通风设备、卷帘机工作与否。
资源推荐
资源详情
资源评论
收起资源包目录
BluetoothChat.rar (78个子文件)
BluetoothChat
bin
classes.dex 38KB
res
crunch
drawable
app_icon.png 4KB
drawable-mdpi
app_icon.png 4KB
BluetoothChat.apk 101KB
dexedLibs
classes
com
example
android
BluetoothChat
CodeFormat.class 4KB
BluetoothChatService$ConnectThread.class 3KB
BluetoothChatService.class 6KB
BluetoothChat$15.class 988B
BuildConfig.class 375B
FullScreen.class 1KB
BluetoothChat.class 16KB
DeviceListActivity$3.class 955B
R$layout.class 639B
BluetoothChat$10.class 948B
R$id.class 2KB
R$drawable.class 477B
DeviceListActivity.class 5KB
BluetoothChat$12.class 948B
BluetoothChat$4.class 959B
BluetoothChat$5.class 1KB
BluetoothChatService$AcceptThread.class 3KB
BluetoothChat$3.class 1KB
R$attr.class 385B
BluetoothChat$1.class 2KB
R$menu.class 440B
BluetoothChat$14.class 989B
R.class 697B
BluetoothChat$9.class 946B
DeviceListActivity$2.class 2KB
BluetoothChat$13.class 1KB
BluetoothChatService$ConnectedThread.class 3KB
R$string.class 2KB
BluetoothChat$2.class 5KB
DeviceListActivity$1.class 2KB
BluetoothChat$11.class 948B
BluetoothChat$8.class 1KB
BluetoothChat$7.class 1KB
BluetoothChat$6.class 2KB
resources.ap_ 80KB
AndroidManifest.xml 2KB
hs_err_pid6136.log 4KB
hs_err_pid5644.log 4KB
res
drawable-ldpi
menu
option_menu.xml 1KB
values-en
strings.xml 3KB
drawable-hdpi
drawable
app_icon.png 4KB
logo.jpg 27KB
values
strings.xml 3KB
drawable-mdpi
app_icon.png 4KB
logo.jpg 27KB
layout
fullscreen.xml 1KB
sname.xml 607B
device_list.xml 2KB
custom_title.xml 1KB
main.xml 7KB
device_name.xml 876B
message.xml 876B
assets
hs_err_pid1856.log 4KB
gen
com
example
android
BluetoothChat
BuildConfig.java 175B
R.java 5KB
hs_err_pid4612.log 4KB
hs_err_pid3804.log 4KB
.settings
org.eclipse.jdt.core.prefs 177B
src
com
example
android
BluetoothChat
FullScreen.java 1KB
BluetoothChatService.java 15KB
DeviceListActivity.java 6KB
BluetoothChat.java 22KB
CodeFormat.java 4KB
.project 849B
hs_err_pid2936.log 4KB
.classpath 569B
hs_err_pid7848.log 4KB
hs_err_pid3692.log 4KB
project.properties 361B
AndroidManifest.xml 2KB
hs_err_pid7724.log 4KB
hs_err_pid452.log 4KB
hs_err_pid4264.log 4KB
lint.xml 53B
共 78 条
- 1
资源评论
- selphones2017-05-17没啥用,这源码根本用不了,不用下了
acewangzhongjie
- 粉丝: 19
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功