- 1)登录界面
- 2)桌面Activity
3)启动vnc
4)显示桌面
- 1)登录界面
- com.iiordanov.bVNC.bVNC.java
- 创建登录界面(填IP,PORT等等
- @Override
-
public void onCreate(Bundle icicle) {
- goButton = (Button) findViewById(R.id.buttonGO);
- goButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (ipText.getText().length() != 0 && portText.getText().length() != 0)
- canvasStart();
- else
- Toast.makeText(view.getContext(), R.string.vnc_server_empty, Toast.LENGTH_LONG).show();
- }
- });
-
}
-
private void canvasStart() {
- if (selected == null) return;
- MemoryInfo info = Utils.getMemoryInfo(this);
- if (info.lowMemory)
- System.gc();
- start();
-
}
- /**
- * Starts the activity which makes a VNC connection and displays the remote desktop.
- */
-
private void start () {
- isConnecting = true;
- //从登陆界面读取数据写入bean
- updateSelectedFromView();
- saveAndWriteRecent();
- //启动RemoteCanvasActivity, 参数为selected.Gen_getValues()
- Intent intent = new Intent(this, RemoteCanvasActivity.class);
- intent.putExtra(Constants.CONNECTION,selected.Gen_getValues());
- startActivity(intent);
-
}
- com.iiordanov.bVNC.RemoteCanvasActivity.java
- @Override
-
public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- //读取bean传过来的参数
- initialize();
- //继续连接,也就是向VNC服务端发起连接
- continueConnecting();
-
}
-
void continueConnecting () {
- // Initialize and define actions for on-screen keys.
- initializeOnScreenKeys ();
- //实际发起连接
- canvas.initializeCanvas(connection, database, new Runnable() {
- public void run() {
- try { setModes(); } catch (NullPointerException e) { }
- }
- });
-
}
- 3)启动vnc
- com.iiordanov.bVNC.RemoteCanvas.java
- /**
- * Create a view showing a remote desktop connection
- * @param context Containing context (activity)
- * @param bean Connection settings
- * @param setModes Callback to run on UI thread after connection is set up
- */
-
void initializeCanvas(ConnectionBean bean, Database db, final Runnable setModes) {
-
- Thread t = new Thread () {
- public void run() {
- try {
- if (isSpice) {
- startSpiceConnection();
- } else if (isRdp) {
- startRdpConnection();
- } else if (connection.getConnectionType() < 4) {
- //启动连接
- startVncConnection();
- }
- }
- }
- }
-
}
- /**
- * Starts a VNC connection using the TightVNC backend.
- * @throws Exception
- */
-
private void startVncConnection() throws Exception {
- Log.i(TAG, "Connecting to: " + connection.getAddress() + ", port: " + connection.getPort());
-
- String address = getAddress();
- int vncPort = getPort(connection.getPort());
- boolean anonTLS = (connection.getConnectionType() == Constants.CONN_TYPE_ANONTLS);
- try {
- rfb = new RfbProto(decoder, address, vncPort,
- connection.getPrefEncoding(), connection.getViewOnly());
- Log.v(TAG, "Connected to server: " + address + " at port: " + vncPort);
- rfb.initializeAndAuthenticate(connection.getUserName(), connection.getPassword(),
- connection.getUseRepeater(), connection.getRepeaterId(), anonTLS);
- } catch (Exception e) {
- throw new Exception (getContext().getString(R.string.error_vnc_unable_to_connect) + e.getLocalizedMessage());
- }
-
- rfbconn = rfb;
- pointer = new RemoteVncPointer (rfbconn, RemoteCanvas.this, handler);
- keyboard = new RemoteVncKeyboard (rfbconn, RemoteCanvas.this, handler);
-
- rfb.writeClientInit();
- rfb.readServerInit();
- initializeBitmap (displayWidth, displayHeight);
- decoder.setPixelFormat(rfb);
-
- handler.post(new Runnable() {
- public void run() {
- pd.setMessage(getContext().getString(R.string.info_progress_dialog_downloading));
- }
- });
-
- sendUnixAuth ();
- if (connection.getUseLocalCursor())
- initializeSoftCursor();
-
- handler.post(drawableSetter);
- handler.post(setModes);
- handler.post(desktopInfo);
-
- // Hide progress dialog
- if (pd.isShowing())
- pd.dismiss();
-
- rfb.processProtocol(this, connection.getUseLocalCursor());
-
}
- 4)显示桌面
- com.iiordanov.bVNC.RfbProto.java
- java实现的RFB图像显示
-
public void processProtocol () throws Exception {
- }
阅读(1072) | 评论(0) | 转发(0) | <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script> 0
上一篇:android DPAD
相关热门文章 给主人留下些什么吧!~~ 评论热议