⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bluetoothinfocanvas.java

📁 提供蓝牙所有服务
💻 JAVA
字号:
package org.klings.wireless.BluetoothNumbers;
/*
 * BluetoothInfoCanvas.java
 *
 * Version 1.0
 *
 * 21. June 2004
 *
 * Copyright (c) 2004, Andre N. Klingsheim
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of the NoWires research group nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */


import javax.bluetooth.LocalDevice;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Ticker;

import org.klings.wireless.j2me.CanvasHelper;

/**
 * BluetoothInfoCanvas retrieves and prints Bluetooth system properties
 * from the Java/Bluetooth enabled host device. The output is correctly
 * formated according to the screen-size of the device. The user can scroll
 * up and down to see all the relevant properties. Like any other
 * <code>Canvas</code>, <code>Commands</code> etc. can be added to the
 * BluetoothInfoCanvas.
 * Note that no methods are available for the BluetoothInfoCanvas. Just create
 * a new BluetoothInfoCanvas and show it to the user.
 *
 * @author  Andr&eacute; N. Klingsheim
 * @version 1.0
 * @since 1.0
 * @see javax.microedition.lcdui.Canvas
 */
public class BluetoothInfoCanvas extends Canvas {



	/* Different fonts for different types of text */
	private Font plain,bold;

	/*Size of canvas */
	private int canvasHeight, canvasWidth;

	/* Height of fonts */
	private int plainHeight,boldHeight;

	/* Keep track of where we are in the canvas */
	private int y = 0;

	/* Constants used when drawing string */
	private final int X = 1;
	private int anchor = Graphics.LEFT|Graphics.TOP;

	/* Offset used to keep track of which lines to draw */
	int baseOffset = 0;
	/* Keycodes. The user can scroll up and down in the canvas */
	int upKey = getKeyCode(UP);
	int downKey = getKeyCode(DOWN);

	/**
	 * Constructs a new BluetoothInfoCanvas object.
	 *
	 */
	public BluetoothInfoCanvas() {
		super();

		canvasHeight = getHeight();
		canvasWidth = getWidth();

		/* Get height of fonts */
		plain=Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
		bold = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM);

		/* heights to compute where to draw. */
		plainHeight = plain.getHeight();
		boldHeight = bold.getHeight();
		setTitle("JABWT Information");
		setTicker(new Ticker("JABWT Info Canvas, by Klings @ "+
		"http://www.klings.org/nowires --- "));
	}


	protected void paint(Graphics g) {

		/* Initialize the canvas */
		g.setColor(0xffffff);
		g.fillRect(0,0, canvasWidth,canvasHeight);

		/* We want black text */
		g.setColor(0x000000);
		g.setFont(plain);
		y=2;
		int i=0;
		/* * Set the offset to baseOffset. If base Offset is 0, all lines
		 * will be drawn. If baseOffset is e.g. -1, the first two lines
		 * will be skipped.
		 */
		int offset = baseOffset;
		String temp = LocalDevice.getProperty("bluetooth.api.version");
		String temp2 = null;
		String[] content;

		if (temp == null){

			y += CanvasHelper.printString("Bluetoth system not available.",X,y,
					anchor,plain,canvasWidth,g);

			y += CanvasHelper.printString(
					"Some JABWT devices require that you turn on Bluetooth"+
					"before starting Java Bluetooth applications. If Bluetooth"
					+"is already turned on, your device may not support JABWT.",
					X,y,anchor,plain,canvasWidth,g);
			return;
		}
		if (offset++ >=0){


			y += CanvasHelper.printString("JABWT version:",X,y,anchor,
					bold,canvasWidth,g);

			y += CanvasHelper.printString(temp,X,y,anchor,plain,canvasWidth,g);

		}

		/* If the canvasHeight is exceeded, there is no need to draw more
		 * information.
		 */
		if (y > canvasHeight) return;

		if (offset++ >=0){
			temp = LocalDevice.getProperty("bluetooth.l2cap.receiveMTU.max");

			if (temp != null){

				y += CanvasHelper.printString("L2CAP Max Receive MTU :",X,y,
						anchor,bold,canvasWidth,g);
				y += CanvasHelper.printString(temp + " bytes",X,y,anchor,
						plain,canvasWidth,g);
			}}
		if (offset++ >=0){
			temp = LocalDevice.getProperty("bluetooth.master.switch");
			if (temp != null){

				y += CanvasHelper.printString("Master/slave switch allowed:",
						X,y,anchor,bold,canvasWidth,g);
				y += CanvasHelper.printString(temp,X,y,anchor,plain,
						canvasWidth,g);

			}
		}

		if (y > canvasHeight) return;

		if (offset++ >=0){
			temp = LocalDevice.getProperty(
			"bluetooth.sd.attr.retrievable.max");

			if (temp != null){

				y += CanvasHelper.printString(
						"Max service record attributes received:",X,y,anchor,
						bold,canvasWidth,g);
				y += CanvasHelper.printString(temp,X,y,anchor,plain,
						canvasWidth,g);


			}
		}

		if (y > canvasHeight) return;

		if (offset++ >=0){
			temp = LocalDevice.getProperty("bluetooth.connected.devices.max");

			if (temp != null){

				y += CanvasHelper.printString("Max connected devices:",X,y,
						anchor,bold,canvasWidth,g);
				y += CanvasHelper.printString(temp,X,y,anchor,plain,
						canvasWidth,g);
			}
		}

		if (y > canvasHeight) return;
		if (offset++ >=0){
			temp = LocalDevice.getProperty("bluetooth.sd.trans.max");

			if (temp != null){

				y += CanvasHelper.printString(
						"Concurrent service discoveries:",X,y,anchor,bold,
						canvasWidth,g);







				y += CanvasHelper.printString(temp,X,y,anchor,plain,
						canvasWidth,g);
			}
		}
		if (y > canvasHeight) return;

		if (offset++ >=0){
			temp = LocalDevice.getProperty("bluetooth.connected.inquiry.scan");

			if (temp != null){


				y += CanvasHelper.printString(
						"Inquiry scan during connection:",X,y,anchor,
						bold,canvasWidth,g);
				y += CanvasHelper.printString(temp,X,y,anchor,
						plain,canvasWidth,g);

			}
		}

		if (y > canvasHeight) return;
		if (offset++ >=0){
			temp = LocalDevice.getProperty("bluetooth.connected.page.scan");
			if (temp != null){


				y += CanvasHelper.printString(
						"Page scan during connection:",X,y,anchor,
						bold,canvasWidth,g);
				y += CanvasHelper.printString(temp,X,y,anchor,
						plain,canvasWidth,g);


			}
		}
		if (y > canvasHeight) return;

		if (offset++ >=0){
			temp = LocalDevice.getProperty("bluetooth.connected.inquiry");

			if (temp != null){
				y += CanvasHelper.printString("Inquiry during connection:",
						X,y,anchor,bold,canvasWidth,g);
				y += CanvasHelper.printString(temp,X,y,anchor,
						plain,canvasWidth,g);

			}
		}


		if (y > canvasHeight) return;

		if (offset++ >=0){
			temp = LocalDevice.getProperty("bluetooth.connected.page");

			if (temp != null){

				y += CanvasHelper.printString("Paging during connection:",
						X,y,anchor,bold,canvasWidth,g);
				y += CanvasHelper.printString(temp,X,y,anchor,
						plain,canvasWidth,g);
			}
		}
	}


	protected void keyPressed(int keyCode) {

		if(keyCode == downKey && y > canvasHeight) {

			/*
			 * Show one property less in the top of the canvas, which
			 * gives one property more in the bottom of the canvas.
			 */
			baseOffset--;
		}else if (keyCode == upKey && baseOffset < 0){

			/*
			 * Show one property more in the top of the canvas, which
			 * gives one property less in the bottom of the canvas.
			 */
			baseOffset++;
		}
		repaint();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -