BVNC client source code analysis (android)

Source: Internet
Author: User

BVNC client source code analysis (android)

  1. 1) logon Interface
  2. 2) Desktop Activity
    3) Start vnc
    4) display Desktop

  1. 1) logon Interface
  2. Com. iiordanov. bVNC. bVNC. java

  3. Create logon interface (fill in IP address, PORT, and so on)
  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. // Read data from the login interface and write data to the bean
  30. UpdateSelectedFromView ();
  31. SaveAndWriteRecent ();

  32. // Start RemoteCanvasActivity. The parameter is selected. Gen_getValues ()
  33. Intent intent = new Intent (this, RemoteCanvasActivity. class );
  34. Intent. putExtra (Constants. CONNECTION, selected. Gen_getValues ());
  35. StartActivity (intent );
  36. }

2) Desktop Activity
  1. Com. iiordanov. bVNC. RemoteCanvasActivity. java

  2. @ Override
  3. Public void onCreate (Bundle icicle ){
  4. Super. onCreate (icicle );
  5. // Read the bean Parameters
  6. Initialize ();

  7. // Continue the connection, that is, initiate a connection to the VNC Server
  8. ContinueConnecting ();
  9. }


  10. Void continueConnecting (){

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

  13. // Actually initiate a connection
  14. Canvas. initializeCanvas (connection, database, new Runnable (){
  15. Public void run (){
  16. Try {setModes ();} catch (NullPointerException e ){}
  17. }
  18. });
  19. }
  20. 3) Start 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. // Start the connection
  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 (handle topinfo );

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

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

  85. 4) display Desktop
  86. Com. iiordanov. bVNC. RfbProto. java
  87. RFB Image Display implemented by java
  88. Public void processProtocol () throws Exception {

  89. }


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.