content: package com.example.sparsh.phone_book;
  
  import android.Manifest;
  import android.app.Activity;
  import android.content.Intent;
  import android.content.pm.PackageManager;
  import android.net.Uri;
  import android.os.Bundle;
  import android.support.annotation.NonNull;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.design.widget.TabLayout;
  import android.support.v4.app.ActivityCompat;
  import android.support.v4.content.ContextCompat;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.DragEvent;
  import android.view.View;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.widget.Toast;
  
  public class MainActivity extends AppCompatActivity implements Calls.OnFragmentInteractionListener ,Contact.OnFragmentInteractionListener ,Searching.OnFragmentInteractionListener{
      int REQUEST_CALL = 1;
      String num="";
  
      FloatingActionButton fab, fab1, fab2;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          fab = (FloatingActionButton) findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  finish();
                  Intent i = new Intent("AddNewRecord");
                  startActivity(i);
  
  
              }
          });
  
  
          TabLayout tabLayout = (TabLayout) findViewById(R.id.tablayout);
  
          tabLayout.setTabGravity(tabLayout.GRAVITY_FILL);
  
          final ViewPager viewPager = findViewById(R.id.viewpager);
          final PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
          viewPager.setAdapter(adapter);
          viewPager.setCurrentItem(1);
  
          viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
  
          tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
              @Override
              public void onTabSelected(TabLayout.Tab tab) {
                  viewPager.setCurrentItem(tab.getPosition());
              }
  
              @Override
              public void onTabUnselected(TabLayout.Tab tab) {
  
              }
  
              @Override
              public void onTabReselected(TabLayout.Tab tab) {
  
              }
  
          });
  
      }
  
      @Override
      public void onFragmentInteraction(Uri uri) {
  
      }
      public void dial(String num)
      {
          Calls.alist.add(0,num);
          this.num = num;
          makePhoneCall();
      }
  
      public void makePhoneCall() {
          String number =num;
          if (number.trim().length() > 0) {
  
              if (ContextCompat.checkSelfPermission(MainActivity.this,
                      Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                  ActivityCompat.requestPermissions(MainActivity.this,
                          new String[]{Manifest.permission.CALL_PHONE}, REQUEST_CALL);
              } else {
                  String dial = "tel:" + number;
                  startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
              }
  
          } else {
              Toast.makeText(MainActivity.this, "Enter Phone Number", Toast.LENGTH_SHORT).show();
          }
      }
  
      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
          if (requestCode == REQUEST_CALL) {
              if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                  makePhoneCall();
              } else {
                  Toast.makeText(this, "Permission DENIED", Toast.LENGTH_SHORT).show();
              }
          }
      }
      public void textMessage(String num)
      {
          Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
          smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
          smsIntent.setType("vnd.android-dir/mms-sms");
          smsIntent.setData(Uri.parse("sms:"+num));
          startActivity(smsIntent);
      }
  }
  