bVNC 用戶端源碼分析(android)

來源:互聯網
上載者:User

bVNC 用戶端源碼分析(android)

  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. 3)啟動vnc
  21. com.iiordanov.bVNC.RemoteCanvas.java

  22. /**
  23. * Create a view showing a remote desktop connection
  24. * @param context Containing context (activity)
  25. * @param bean Connection settings
  26. * @param setModes Callback to run on UI thread after connection is set up
  27. */
  28. void initializeCanvas(ConnectionBean bean, Database db, final Runnable setModes) {

  29. Thread t = new Thread () {
  30. public void run() {
  31. try {

  32. if (isSpice) {
  33. startSpiceConnection();
  34. } else if (isRdp) {
  35. startRdpConnection();
  36. } else if (connection.getConnectionType() < 4) {
  37. //啟動串連
  38. startVncConnection();
  39. }
  40. }
  41. }
  42. }
  43. }

  44. /**
  45. * Starts a VNC connection using the TightVNC backend.
  46. * @throws Exception
  47. */
  48. private void startVncConnection() throws Exception {
  49. Log.i(TAG, "Connecting to: " + connection.getAddress() + ", port: " + connection.getPort());

  50. String address = getAddress();
  51. int vncPort = getPort(connection.getPort());
  52. boolean anonTLS = (connection.getConnectionType() == Constants.CONN_TYPE_ANONTLS);
  53. try {
  54. rfb = new RfbProto(decoder, address, vncPort,
  55. connection.getPrefEncoding(), connection.getViewOnly());
  56. Log.v(TAG, "Connected to server: " + address + " at port: " + vncPort);
  57. rfb.initializeAndAuthenticate(connection.getUserName(), connection.getPassword(),
  58. connection.getUseRepeater(), connection.getRepeaterId(), anonTLS);
  59. } catch (Exception e) {
  60. throw new Exception (getContext().getString(R.string.error_vnc_unable_to_connect) + e.getLocalizedMessage());
  61. }

  62. rfbconn = rfb;
  63. pointer = new RemoteVncPointer (rfbconn, RemoteCanvas.this, handler);
  64. keyboard = new RemoteVncKeyboard (rfbconn, RemoteCanvas.this, handler);

  65. rfb.writeClientInit();
  66. rfb.readServerInit();
  67. initializeBitmap (displayWidth, displayHeight);
  68. decoder.setPixelFormat(rfb);

  69. handler.post(new Runnable() {
  70. public void run() {
  71. pd.setMessage(getContext().getString(R.string.info_progress_dialog_downloading));
  72. }
  73. });

  74. sendUnixAuth ();
  75. if (connection.getUseLocalCursor())
  76. initializeSoftCursor();

  77. handler.post(drawableSetter);
  78. handler.post(setModes);
  79. handler.post(desktopInfo);

  80. // Hide progress dialog
  81. if (pd.isShowing())
  82. pd.dismiss();

  83. rfb.processProtocol(this, connection.getUseLocalCursor());
  84. }

  85. 4)顯示案頭
  86. com.iiordanov.bVNC.RfbProto.java
  87. java實現的RFB映像顯示
  88. public void processProtocol () throws Exception {

  89. }


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.