Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1456316
  • 博文数量: 596
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 173
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-06 15:50
个人简介

在线笔记

文章分类

全部博文(596)

文章存档

2016年(1)

2015年(104)

2014年(228)

2013年(226)

2012年(26)

2011年(11)

分类: Android平台

2015-05-14 14:54:01

  1. 1)登录界面
  2. 2)桌面Activity
    3)启动vnc                                                      
    4)显示桌面

  1. 1)登录界面
  2. com.iiordanov.bVNC.bVNC.java

  3. 创建登录界面(填IP,PORT等等
  4. @Override
  5. public void onCreate(Bundle icicle) {

  6.     goButton = (Button) findViewById(R.id.buttonGO);
  7.     goButton.setOnClickListener(new View.OnClickListener() {
  8.     @Override
  9.     public void onClick(View view) {
  10.         if (ipText.getText().length() != 0 && portText.getText().length() != 0)
  11.             canvasStart();
  12.         else
  13.             Toast.makeText(view.getContext(), R.string.vnc_server_empty, Toast.LENGTH_LONG).show();
  14.         }
  15.     });
  16. }



  17. private void canvasStart() {
  18.     if (selected == null) return;
  19.     MemoryInfo info = Utils.getMemoryInfo(this);
  20.     if (info.lowMemory)
  21.         System.gc();
  22.     start();
  23. }

  24. /**
  25.  * Starts the activity which makes a VNC connection and displays the remote desktop.
  26.  */
  27. private void start () {
  28.     isConnecting = true;
  29.     //从登陆界面读取数据写入bean
  30.     updateSelectedFromView();
  31.     saveAndWriteRecent();

  32.     //启动RemoteCanvasActivity, 参数为selected.Gen_getValues()
  33.     Intent intent = new Intent(this, RemoteCanvasActivity.class);
  34.     intent.putExtra(Constants.CONNECTION,selected.Gen_getValues());
  35.     startActivity(intent);
  36. }

 2)桌面Activity
  1. com.iiordanov.bVNC.RemoteCanvasActivity.java

  2. @Override
  3. public void onCreate(Bundle icicle) {
  4.     super.onCreate(icicle);
  5.     //读取bean传过来的参数
  6.     initialize();

  7.     //继续连接,也就是向VNC服务端发起连接
  8.     continueConnecting();
  9. }


  10. void continueConnecting () {

  11.     // Initialize and define actions for on-screen keys.
  12.     initializeOnScreenKeys ();

  13.     //实际发起连接
  14.     canvas.initializeCanvas(connection, database, new Runnable() {
  15.         public void run() {
  16.             try { setModes(); } catch (NullPointerException e) { }
  17.         }
  18.     });
  19. }
  20.               
  21. 3)启动vnc                                                                       
  22. com.iiordanov.bVNC.RemoteCanvas.java

  23. /**
  24.  * Create a view showing a remote desktop connection
  25.  * @param context Containing context (activity)
  26.  * @param bean Connection settings
  27.  * @param setModes Callback to run on UI thread after connection is set up
  28.  */
  29. void initializeCanvas(ConnectionBean bean, Database db, final Runnable setModes) {
  30.     
  31.     Thread t = new Thread () {
  32.         public void run() {
  33.             try {

  34.                 if (isSpice) {
  35.                     startSpiceConnection();
  36.                 } else if (isRdp) {
  37.                     startRdpConnection();
  38.                 } else if (connection.getConnectionType() < 4) {
  39.                     //启动连接
  40.                     startVncConnection();
  41.                 }
  42.             }
  43.         }
  44.     }
  45. }

  46. /**
  47.  * Starts a VNC connection using the TightVNC backend.
  48.  * @throws Exception
  49.  */
  50. private void startVncConnection() throws Exception {
  51.     Log.i(TAG, "Connecting to: " + connection.getAddress() + ", port: " + connection.getPort());
  52.     
  53.     String address = getAddress();
  54.     int vncPort = getPort(connection.getPort());
  55.     boolean anonTLS = (connection.getConnectionType() == Constants.CONN_TYPE_ANONTLS);
  56.     try {
  57.         rfb = new RfbProto(decoder, address, vncPort,
  58.                             connection.getPrefEncoding(), connection.getViewOnly());
  59.         Log.v(TAG, "Connected to server: " + address + " at port: " + vncPort);
  60.         rfb.initializeAndAuthenticate(connection.getUserName(), connection.getPassword(),
  61.                                         connection.getUseRepeater(), connection.getRepeaterId(), anonTLS);
  62.     } catch (Exception e) {
  63.         throw new Exception (getContext().getString(R.string.error_vnc_unable_to_connect) + e.getLocalizedMessage());
  64.     }
  65.     
  66.     rfbconn = rfb;
  67.     pointer = new RemoteVncPointer (rfbconn, RemoteCanvas.this, handler);
  68.     keyboard = new RemoteVncKeyboard (rfbconn, RemoteCanvas.this, handler);
  69.     
  70.     rfb.writeClientInit();
  71.     rfb.readServerInit();
  72.     initializeBitmap (displayWidth, displayHeight);
  73.     decoder.setPixelFormat(rfb);
  74.     
  75.     handler.post(new Runnable() {
  76.         public void run() {
  77.             pd.setMessage(getContext().getString(R.string.info_progress_dialog_downloading));
  78.         }
  79.     });
  80.     
  81.     sendUnixAuth ();
  82.     if (connection.getUseLocalCursor())
  83.         initializeSoftCursor();
  84.     
  85.     handler.post(drawableSetter);
  86.     handler.post(setModes);
  87.     handler.post(desktopInfo);
  88.                                                                                                                                                           
  89.     // Hide progress dialog
  90.     if (pd.isShowing())
  91.         pd.dismiss();
  92.     
  93.     rfb.processProtocol(this, connection.getUseLocalCursor());
  94. }

  95. 4)显示桌面
  96. com.iiordanov.bVNC.RfbProto.java
  97. java实现的RFB图像显示
  98. public void processProtocol () throws Exception {

  99. }


阅读(2657) | 评论(0) | 转发(0) |
0

上一篇:android DPAD

下一篇:android项目增加v7.appcompat

给主人留下些什么吧!~~