@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Get view references (from activity_main.xml) mConnectDevice = (TextView) findViewById(R.id.connected_device); mHUDConnected = (TextView) findViewById(R.id.hud_connected); mLocalWeb = (TextView) findViewById(R.id.local_web_connected); mRemoteWeb = (TextView) findViewById(R.id.remote_web_connected); mDownloadFile = (Button) findViewById(R.id.download_file_button); mUploadFile = (Button) findViewById(R.id.upload_file_button); mDownloadImage = (Button) findViewById(R.id.load_image_button); mDownloadFile.setOnClickListener(this); mUploadFile.setOnClickListener(this); mDownloadImage.setOnClickListener(this); mDownloadFile.setEnabled(false); mUploadFile.setEnabled(false); mDownloadImage.setEnabled(false); // Get an instance of HUDConnectivityManager mHUDConnectivityManager = (HUDConnectivityManager) HUDOS.getHUDService(HUDOS.HUD_CONNECTIVITY_SERVICE); if (mHUDConnectivityManager == null) { Log.e(TAG, "Failed to get HUDConnectivityManager"); finish(); } setViewColor(mHUDConnected, COL_RED); setViewColor(mLocalWeb, COL_RED); setViewColor(mRemoteWeb, COL_RED); if (mHUDConnectivityManager.isHUDConnected()) { Log.d(TAG, "HUD is connected."); mHUDConnected.setText("HUD Connected"); } else { Log.d(TAG, "HUD is disconnected."); mHUDConnected.setText("HUD Disconnected"); } // !!!! -------- IMPORTANT NOTICE -------- !!!! // // Note: This following line is necessary for HUDConnectivityManager to run properly System.load("/system/lib/libreconinstruments_jni.so"); // !!!! -------- IMPORTANT NOTICE -------- !!!! // }
@Override public void onNetworkEvent(NetworkEvent networkEvent, boolean hasNetworkAccess) { switch (networkEvent) { case LOCAL_WEB_GAINED: mLocalWeb.setText("Local Web: ON"); setViewColor(mLocalWeb, COL_GREEN); break; case LOCAL_WEB_LOST: mLocalWeb.setText("Local Web: OFF"); setViewColor(mLocalWeb, COL_RED); break; case REMOTE_WEB_GAINED: mRemoteWeb.setText("Remote Web: ON"); setViewColor(mRemoteWeb, COL_GREEN); break; case REMOTE_WEB_LOST: mRemoteWeb.setText("Remote Web: OFF"); setViewColor(mRemoteWeb, COL_RED); break; default: Log.e(TAG, "onNetworkEvent() with unknown networkEvent:" + networkEvent); break; } Log.d( TAG, "onNetworkEvent() - networkEvent: " + networkEvent + ", hasNetworkAccess: " + hasNetworkAccess); Log.d( TAG, "onNetworkEvent() - getDeviceName(): " + mHUDConnectivityManager.getDeviceName() + ", isHUDConnected(): " + mHUDConnectivityManager.isHUDConnected() + ", hasLocalWeb(): " + mHUDConnectivityManager.hasLocalWeb() + ", hasRemoteWeb(): " + mHUDConnectivityManager.hasRemoteWeb() + ", hasWebConnection(): " + mHUDConnectivityManager.hasWebConnection() + ", getConnectionState(): " + mHUDConnectivityManager.getConnectionState()); mDownloadFile.setEnabled(hasNetworkAccess); mUploadFile.setEnabled(hasNetworkAccess); mDownloadImage.setEnabled(hasNetworkAccess); }
@Override public void onPause() { // Unregister the IHUDConnectivity from HUDConnectivityManager mHUDConnectivityManager.unregister(this); super.onPause(); }
@Override public void onResume() { super.onResume(); // Register the IHUDConnectivity to HUDConnectivityManager mHUDConnectivityManager.register(this); }