This task describes how to add implementation to the
NodeDetailActivity.
In this task you will add implementation for the NodeDetailActivity
class.
- In the Package Explorer double-click on NodeDetailActivity.java to load it into the Eclipse editor.
-
Replace the existing stub code with the following:
package com.alfresco.tutorials.testapp1; import com.alfresco.tutorials.testapp1.MainActivity; import org.alfresco.mobile.android.api.model.Node; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; import android.support.v4.app.NavUtils; public class NodeDetailActivity extends Activity { private static final String TAG = "NodeDetailActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_node_detail); // Show the Up button in the action bar. getActionBar().setDisplayHomeAsUpEnabled(true); // Get message from intent Intent intent = getIntent(); Bundle bundle = intent.getExtras(); MessageObject message = bundle.getParcelable(MainActivity.EXTRA_MESSAGE); Node node = message.getNode(); if (node == null){ Log.d(TAG, "FATAL ERROR: Node is null!"); System.exit(0); } else{ // We now need to display node details in a UI TextView tv = (TextView) findViewById(R.id.node_name_value); tv.setText((CharSequence)node.getName()); tv = (TextView) findViewById(R.id.node_title_value); tv.setText((CharSequence)node.getTitle()); tv = (TextView) findViewById(R.id.node_description_value); tv.setText((CharSequence)node.getDescription()); tv = (TextView) findViewById(R.id.node_created_by_value); tv.setText((CharSequence)node.getCreatedBy()); tv = (TextView) findViewById(R.id.node_created_at_value); tv.setText((CharSequence)node.getCreatedAt().getTime().toString()); tv = (TextView) findViewById(R.id.node_identifier_value); tv.setText((CharSequence)node.getIdentifier()); tv = (TextView) findViewById(R.id.node_type_value); tv.setText((CharSequence)node.getType()); if(node.isFolder()){ tv = (TextView) findViewById(R.id.node_is_folder_value); tv.setText("True"); } else{ tv = (TextView) findViewById(R.id.node_is_folder_value); tv.setText("False"); } if(node.isDocument()){ tv = (TextView) findViewById(R.id.node_is_document_value); tv.setText("True"); } else{ tv = (TextView) findViewById(R.id.node_is_document_value); tv.setText("False"); } } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.node_detail, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // This ID represents the Home or Up button. In the case of this // activity, the Up button is shown. Use NavUtils to allow users // to navigate up one level in the application structure. For // more details, see the Navigation pattern on Android Design: // // http://developer.android.com/design/patterns/navigation.html#up-vs-back // NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } }
Attention: You will get an error regarding MainActivity.EXTRA_MESSAGE, but you will fix this in the next task.