package com.nbusy.app;

import android.app.ActionBar;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;

import android.os.IBinder;
import android.view.MenuItem;

/**
 * An activity representing a single Chat detail screen. This
 * activity is only used on handset devices. On tablet-size devices,
 * item details are presented side-by-side with a list of items
 * in a {@link ChatListActivity}.
 * <p/>
 * This activity is mostly just a 'shell' activity containing nothing
 * more than a {@link ChatDetailFragment}.
 */
public class ChatDetailActivity extends Activity {

    /* get an instance of WorkerService */
    private WorkerService workerService;

    private ServiceConnection workerServiceConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder binder) {
            WorkerService.WorkerServiceBinder workerServiceBinder = (WorkerService.WorkerServiceBinder) binder;
            workerService = workerServiceBinder.getService();
        }

        public void onServiceDisconnected(ComponentName className) {
            workerService = null;
        }
    };

    @Override
    public void onResume() {
        super.onResume();
        Intent intent = new Intent(this, WorkerService.class);
        bindService(intent, workerServiceConnection, Context.BIND_AUTO_CREATE);
    }

    @Override
    protected void onPause() {
        super.onPause();
        unbindService(workerServiceConnection);
    }
    /* get an instance of WorkerService */

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat_detail);

        // Show the Up button in the action bar.
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }

        // savedInstanceState is non-null when there is fragment state saved from previous configurations of this activity
        // (e.g. when rotating the screen from portrait to landscape)
        // in this case, the fragment will automatically be re-added to its container so we don't need to manually add it
        if (savedInstanceState != null) {
            return;
        }

        // Set activity title
        String chatId = getIntent().getStringExtra(ChatDetailFragment.ARG_ITEM_ID);
        setTitle(chatId);

        // create the detail fragment and add it to the activity using a fragment transaction.
        Bundle arguments = new Bundle();
        arguments.putString(ChatDetailFragment.ARG_ITEM_ID, chatId);
        ChatDetailFragment fragment = new ChatDetailFragment();
        fragment.setArguments(arguments);
        getFragmentManager().beginTransaction().add(R.id.chat_detail_container, fragment).commit();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            // this ID represents the Home or Up button
            // in the case of this activity, the Up button is shown
            navigateUpTo(new Intent(this, ChatListActivity.class));
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

@@ -103,180 +103,40 @@
 ent.
-ComponentName;%0Aimport android.content.Context;%0Aimport android.content.Intent;%0Aimport android.content.ServiceConnection;%0Aimport android.os.Bundle;%0A%0Aimport android.os.IBinder
+Intent;%0Aimport android.os.Bundle
 ;%0Aim
@@ -617,16 +617,18 @@
 vice */%0A
+//
     priv
@@ -660,17 +660,21 @@
 ervice;%0A
-%0A
+//%0A//
     priv
@@ -743,24 +743,26 @@
 nection() %7B%0A
+//
         publ
@@ -827,24 +827,26 @@
 r binder) %7B%0A
+//
             
@@ -945,16 +945,18 @@
 binder;%0A
+//
         
@@ -1005,24 +1005,26 @@
 tService();%0A
+//
         %7D%0A%0A 
@@ -1013,33 +1013,37 @@
 ();%0A//        %7D%0A
-%0A
+//%0A//
         public v
@@ -1091,24 +1091,26 @@
 lassName) %7B%0A
+//
             
@@ -1131,16 +1131,18 @@
 = null;%0A
+//
         
@@ -1147,16 +1147,22 @@
   %7D%0A
+//
     %7D;%0A
-%0A
+//%0A//
     
@@ -1163,32 +1163,34 @@
 //    @Override%0A
+//
     public void 
@@ -1198,24 +1198,26 @@
 nResume() %7B%0A
+//
         supe
@@ -1226,24 +1226,26 @@
 onResume();%0A
+//
         Inte
@@ -1291,24 +1291,26 @@
 ice.class);%0A
+//
         bind
@@ -1377,23 +1377,29 @@
 REATE);%0A
+//
     %7D%0A
-%0A
+//%0A//
     @Ove
@@ -1396,32 +1396,34 @@
 //    @Override%0A
+//
     protected vo
@@ -1433,24 +1433,26 @@
 onPause() %7B%0A
+//
         supe
@@ -1460,24 +1460,26 @@
 .onPause();%0A
+//
         unbi
@@ -1514,16 +1514,18 @@
 ction);%0A
+//
     %7D%0A  

comment out worker service binder for a possible event driven approach