//
// Copyright (C) 2010 Michael A. MacDonald
// Copyright (C) 2004 Horizon Wimba. All Rights Reserved.
// Copyright (C) 2001-2003 HorizonLive.com, Inc. All Rights Reserved.
// Copyright (C) 2001,2002 Constantin Kaplinsky. All Rights Reserved.
// Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this software; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
//
//
// VncCanvas is a subclass of android.view.SurfaceView which draws a VNC
// desktop on it.
//
package android.androidVNC;
import java.io.IOException;
import java.util.zip.Inflater;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Paint.Style;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.Toast;
import com.antlersoft.android.bc.BCFactory;
public class VncCanvas extends ImageView {
private final static String TAG = "VncCanvas";
private final static boolean LOCAL_LOGV = true;
AbstractScaling scaling;
// Available to activity
int mouseX, mouseY;
// Connection parameters
ConnectionBean connection;
// Runtime control flags
private boolean maintainConnection = true;
private boolean showDesktopInfo = true;
private boolean repaintsEnabled = true;
/**
* Use camera button as meta key for right mouse button
*/
boolean cameraButtonDown = false;
// Keep track when a seeming key press was the result of a menu shortcut
int lastKeyDown;
boolean afterMenu;
// Color Model settings
private COLORMODEL pendingColorModel = COLORMODEL.C24bit;
private COLORMODEL colorModel = null;
private int bytesPerPixel = 0;
private int[] colorPalette = null;
// VNC protocol connection
public RfbProto rfb;
// Internal bitmap data
AbstractBitmapData bitmapData;
public Handler handler = new Handler();
// VNC Encoding parameters
private boolean useCopyRect = false; // TODO CopyRect is not working
private int preferredEncoding = -1;
// Unimplemented VNC encoding parameters
private boolean requestCursorUpdates = false;
private boolean ignoreCursorUpdates = true;
// Unimplemented TIGHT encoding parameters
private int compressLevel = -1;
private int jpegQuality = -1;
// Used to determine if encoding update is necessary
private int[] encodingsSaved = new int[20];
private int nEncodingsSaved = 0;
// ZRLE encoder's data.
private byte[] zrleBuf;
private int[] zrleTilePixels;
private ZlibInStream zrleInStream;
// Zlib encoder's data.
private byte[] zlibBuf;
private Inflater zlibInflater;
private MouseScrollRunnable scrollRunnable;
private Paint handleRREPaint;
/**
* Position of the top left portion of the <i>visible</i> part of the screen, in
* full-frame coordinates
*/
int absoluteXPosition = 0, absoluteYPosition = 0;
/**
* Constructor used by the inflation apparatus
* @param context
*/
public VncCanvas(final Context context, AttributeSet attrs)
{
super(context, attrs);
scrollRunnable = new MouseScrollRunnable();
handleRREPaint = new Paint();
handleRREPaint.setStyle(Style.FILL);
}
/**
* Create a view showing a VNC connection
* @param context Containing context (activity)
* @param bean Connection settings
* @param setModes Callback to run on UI thread after connection is set up
*/
void initializeVncCanvas(ConnectionBean bean, final Runnable setModes) {
connection = bean;
this.pendingColorModel = COLORMODEL.valueOf(bean.getColorModel());
// Startup the RFB thread with a nifty progess dialog
final ProgressDialog pd = ProgressDialog.show(getContext(), "Connecting...", "Establishing handshake.\nPlease wait...", true, true, new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
closeConnection();
handler.post(new Runnable() {
public void run() {
Utils.showErrorMessage(getContext(), "VNC connection aborted!");
}
});
}
});
final Display display = pd.getWindow().getWindowManager().getDefaultDisplay();
Thread t = new Thread() {
public void run() {
try {
connectAndAuthenticate(connection.getUserName(),connection.getPassword());
doProtocolInitialisation(display.getWidth(), display.getHeight());
handler.post(new Runnable() {
public void run() {
pd.setMessage("Downloading first frame.\nPlease wait...");
}
});
processNormalProtocol(getContext(), pd, setModes);
} catch (Throwable e) {
if (maintainConnection) {
Log.e(TAG, e.toString());
e.printStackTrace();
// Ensure we dismiss the progress dialog
// before we fatal error finish
if (pd.isShowing())
pd.dismiss();
if (e instanceof OutOfMemoryError) {
// TODO Not sure if this will happen but...
// figure out how to gracefully notify the user
// Instantiating an alert dialog here doesn't work
// because we are out of memory. :(
} else {
String error = "VNC connection failed!";
if (e.getMessage() != null && (e.getMessage().indexOf("authentication") > -1)) {
error = "VNC authentication failed!";
}
final String error_ = error + "<br>" + e.getLocalizedMessage();
handler.post(new Runnable() {
public void run() {
Utils.showFatalErrorMessage(getContext(), error_);
}
});
}
}
}
}
};
t.start();
}
void connectAndAuthenticate(String us,String pw) throws Exception {
Log.i(TAG, "Connecting to " + connection.getAddress() + ", port " + connection.getPort() + "...");
rfb = new RfbProto(connection.getAddress(), connection.getPort());
if (LOCAL_LOGV) Log.v(TAG, "Connected to server");
// <RepeaterMagic>
if (connection.getUseRepeater() && connection.getRepeaterId() != null && connection.getRepeaterId().length()>0) {
Log.i(TAG, "Negotiating repeater/proxy connection");
byte[] protocolMsg = new byte[12];
rfb.is.read(protocolMsg);
byte[] buffer = new byte[250];
System.arraycopy(connection.getRepeaterId().getBytes(), 0, buffer, 0, connection.getRepeaterId().length());
rfb.os.write(buffer);
}
// </RepeaterMagic>
rfb.readVersionMsg();
Log.i(TAG, "RFB server supports protocol version " + rfb.serverMajor + "." + rfb.serverMinor);
rfb.writeVersionMsg();
Log.i(TAG, "Using RFB protocol version " + rfb.clientMajor + "." + rfb.clientMinor);
int bitPref=0;
if(connection.getUserName().length()>0)
bitPref|=1;
Log.d("debug","bitPref="+bitPref);
int secType = rfb.negotiateSecurity(bitPref);
int authType;
if (secType == RfbProto.SecTypeTight) {
rfb.initCapabilities();
rfb.setupTunneling();
authType = rfb.negotiateAuthenticationTight();
} else if (secType == RfbProto.SecTypeUltra34) {
rfb.prepareDH();
authType = RfbProto.AuthUltra;
} else {
authType = secType;
}
switch (authType) {
case RfbProto.AuthNone:
Log.i(TAG, "No authentication needed");
rfb.authenticateNone();
break;
case RfbProto.AuthVNC:
Log.i(
没有合适的资源?快使用搜索试试~ 我知道了~
android-vnc
共625个文件
svn-base:303个
c:83个
java:78个
5星 · 超过95%的资源 需积分: 15 44 下载量 136 浏览量
2012-12-06
22:37:25
上传
评论 1
收藏 2.62MB RAR 举报
温馨提示
在Android上实现远程控制的源码,包括android-vnc-server和android-vnc-viewver两部分。
资源推荐
资源详情
资源评论
收起资源包目录
android-vnc (625个子文件)
configure.ac 25KB
Makefile.am 2KB
Makefile.am 759B
Makefile.am 654B
Makefile.am 516B
Makefile.am 428B
Makefile.am 399B
Makefile.am 389B
Makefile.am 182B
Makefile.am 127B
Makefile.am 102B
AUTHORS 2KB
rfbserver.c 98KB
tight.c 67KB
minilzo.c 67KB
minilzo.c 67KB
rfbproto.c 51KB
main.c 29KB
handlefiletransferrequest.c 24KB
zywrletemplate.c 23KB
hextile.c 23KB
cursor.c 22KB
rfbregion.c 20KB
tight.c 19KB
stats.c 17KB
sockets.c 17KB
filetransfermsg.c 17KB
mac.c 16KB
d3des.c 15KB
httpd.c 15KB
corre.c 14KB
fbvncserver.c 14KB
scale.c 14KB
rfbtightserver.c 14KB
rre.c 13KB
translate.c 13KB
VNConsole.c 12KB
vnc2mpg.c 12KB
sockets.c 11KB
zrle.c 10KB
auth.c 10KB
example.c 9KB
zlib.c 9KB
tabletrans24template.c 9KB
selbox.c 9KB
vncviewer.c 9KB
encodingstest.c 8KB
SDLvncviewer.c 8KB
cursortest.c 8KB
zrleencodetemplate.c 8KB
cargs.c 8KB
ultra.c 7KB
ultra.c 7KB
zrle.c 7KB
zrleoutstream.c 7KB
zippy.c 6KB
cursor.c 5KB
tableinit24.c 5KB
LinuxVNC.c 5KB
tableinittctemplate.c 5KB
font.c 5KB
zlib.c 5KB
camera.c 5KB
vncauth.c 4KB
tabletranstemplate.c 4KB
filelistinfo.c 3KB
hextile.c 3KB
vncev.c 3KB
backchannel.c 3KB
pnmshow.c 3KB
VNCommand.c 3KB
tableinitcmtemplate.c 3KB
listen.c 3KB
ppmtest.c 3KB
backchannel.c 2KB
pnmshow24.c 2KB
rre.c 2KB
corre.c 2KB
rotate.c 2KB
zrlepalettehelper.c 2KB
fontsel.c 2KB
draw.c 2KB
storepasswd.c 1KB
cutpaste.c 1KB
copyrecttest.c 1KB
rotatetemplate.c 1KB
cargstest.c 749B
colourmaptest.c 673B
simple15.c 636B
example.c 633B
filetransfer.c 366B
simple.c 320B
blooptest.c 62B
regiontest.c 57B
blooptest.c 50B
proguard.cfg 1KB
ChangeLog 29KB
ChangeLog 558B
.classpath 572B
.classpath 273B
共 625 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
老骥伏枥2018
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页