// Path: ServiceDemoIPC/app/src/main/java/edu/cs4730/servicedemoipc/RandNumService.java
// public class LocalBinder extends Binder {
//     RandNumService getService() {
//         // Return this instance of LocalService so clients can call public methods
//         return RandNumService.this;
//     }
// }


import edu.cs4730.servicedemoipc.RandNumService.LocalBinder;
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 androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Toast;
        // Inflate the layout for this fragment
        View myView = inflater.inflate(R.layout.fragment_main, container, false);

        //setup the button, so it will call into the service and get a random number.
        myView.findViewById(R.id.btn_gn).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mBound) {
                    // Call a method from the RandNumService.
                    // However, if this call were something that might hang, then this request should
                    // occur in a separate thread to avoid slowing down the activity performance.
                    //but getting a random number is really quick, so I'm doing it here instead.
                    int num = mService.getRandomNumber();
                    Toast.makeText(getActivity(), "number: " + num, Toast.LENGTH_SHORT).show();
                }

            }
        });
        return myView;
    }


    /**
     * Defines callbacks for service binding, passed to bindService()
     */
    private ServiceConnection mConnection = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName className, IBinder service) {
            // We've bound to LocalService, cast the IBinder and get LocalService instance
// Path: ServiceDemoIPC/app/src/main/java/edu/cs4730/servicedemoipc/RandNumService.java
// public class LocalBinder extends Binder {
//     RandNumService getService() {
//         // Return this instance of LocalService so clients can call public methods
//         return RandNumService.this;
//     }
// }


// Path: ServiceDemoIPC/app/src/main/java/edu/cs4730/servicedemoipc/MainFragment.java
import edu.cs4730.servicedemoipc.RandNumService.LocalBinder;
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 androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Toast;

        // Inflate the layout for this fragment
        View myView = inflater.inflate(R.layout.fragment_main, container, false);

        //setup the button, so it will call into the service and get a random number.
        myView.findViewById(R.id.btn_gn).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mBound) {
                    // Call a method from the RandNumService.
                    // However, if this call were something that might hang, then this request should
                    // occur in a separate thread to avoid slowing down the activity performance.
                    //but getting a random number is really quick, so I'm doing it here instead.
                    int num = mService.getRandomNumber();
                    Toast.makeText(getActivity(), "number: " + num, Toast.LENGTH_SHORT).show();
                }

            }
        });
        return myView;
    }


    /**
     * Defines callbacks for service binding, passed to bindService()
     */
    private ServiceConnection mConnection = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName className, IBinder service) {
            // We've bound to LocalService, cast the IBinder and get LocalService instance
            LocalBinder binder = (LocalBinder) service;