title: How to implement dialog like truecaller
body: <p>I am trying to implement the app similar to true caller,I am able to get the phone number when the phone rings using broadcast receiver and opening the MyCustomDialog Activity</p>
  
  <p>This is my receiver class by which I am getting the Call State that the call is starts or ends. In this, I make some methods which I am using in  <strong>CallReceiver.java</strong></p>
  
  <p><strong>PhonecallReceiver.java</strong></p>
  
  <pre><code>import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.telephony.TelephonyManager;
  import java.util.Date;
  
  public abstract class PhonecallReceiver extends BroadcastReceiver
  {
      private static int lastState = TelephonyManager.CALL_STATE_IDLE;
      private static Date callStartTime;
      private static boolean isIncoming;
      private static String savedNumber;
  
      @Override
      public void onReceive(Context context, Intent intent)
      {
      try
      {
          if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL"))
          {
              savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
          }
          else
          {
              String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
              String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
              int state = 0;
              if(stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE))
              {
                  state = TelephonyManager.CALL_STATE_IDLE;
              }
              else if(stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
              {
                  state = TelephonyManager.CALL_STATE_OFFHOOK;
              }
              else if(stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING))
              {
                  state = TelephonyManager.CALL_STATE_RINGING;
              }
  
              onCallStateChanged(context, state, number);
          }
      }
      catch (Exception e)
      {
          e.printStackTrace();
      }
  }
  
      //Derived classes should override these to respond to specific events of interest
      protected void onIncomingCallStarted(Context ctx, String number, Date start){}
      protected void onIncomingCallEnded(Context ctx, String number, Date start, Date end){}
  
      public void onCallStateChanged(Context context, int state, String number)
      {
          if(lastState == state)
          {
              //No change, debounce extras
              return;
          }
          switch (state)
          {
              case TelephonyManager.CALL_STATE_RINGING:
                  isIncoming = true;
                  callStartTime = new Date();
                  savedNumber = number;
                  onIncomingCallStarted(context, number, callStartTime);
                  break;
  
              case TelephonyManager.CALL_STATE_OFFHOOK:
                  if (isIncoming)
                  {
                      onIncomingCallEnded(context,savedNumber,callStartTime,new Date());
                  }
  
              case TelephonyManager.CALL_STATE_IDLE:
                  if(isIncoming)
                  {
                      onIncomingCallEnded(context, savedNumber, callStartTime, new Date());
                  }
          }
          lastState = state;
      }
  }
  </code></pre>
  
  <p><strong>CallReceiver.java</strong></p>
  
  <pre><code>import android.app.Activity;
  import android.app.Dialog;
  import android.app.Notification;
  import android.content.ComponentName;
  import android.content.Context;
  import android.content.Intent;
  import android.graphics.drawable.ColorDrawable;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.Window;
  import android.widget.Button;
  import android.widget.Toast;
  import android.os.Handler;
  import java.util.Date;
  
  import dootam.dspl.com.lawyercasecall.R;
  
  public class CallReceiver extends PhonecallReceiver
  {
      Context context;
  
      @Override
      protected void onIncomingCallStarted(final Context ctx, String number, Date start)
      {
          Toast.makeText(ctx,"Kushal Incoming Call"+ number,Toast.LENGTH_LONG).show();
  
          context =   ctx;
  
          final Intent intent = new Intent(context, MyCustomDialog.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
          intent.putExtra("phone_no",number);
  
          new Handler().postDelayed(new Runnable()
          {
              @Override
              public void run()
              {
                  context.startActivity(intent);
              }
          },2000);
  
  //        MyCus/*tomDialog dialog   =   new MyCustomDialog(context);
  //        dialog.*/show();
      }
  
      @Override
      protected void onIncomingCallEnded(Context ctx, String number, Date start, Date end)
      {
          Toast.makeText(ctx,"Bye Bye"+ number,Toast.LENGTH_LONG).show();
      }
  }
  </code></pre>
  
  <p><strong>MyCustomDialog.java</strong></p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.view.Window;
  import android.widget.Button;
  import android.widget.TextView;
  import dootam.dspl.com.lawyercasecall.R;
  
  public class MyCustomDialog extends Activity
  {
      TextView tv_client;
      String phone_no;
      Button dialog_ok;
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          try
          {
              requestWindowFeature(Window.FEATURE_NO_TITLE);
              this.setFinishOnTouchOutside(false);
              super.onCreate(savedInstanceState);
              setContentView(R.layout.dialog);
              initializeContent();
  
              /*WindowManager.LayoutParams params = getWindow().getAttributes();
              params.x = -100;
              params.height = 70;
              params.width = 1000;
              params.y = -50;
  
              this.getWindow().setAttributes(params);*/
  
              phone_no    =   getIntent().getExtras().getString("phone_no");
              tv_client.setText(""+phone_no +" is calling you");
  
              dialog_ok.setOnClickListener(new View.OnClickListener()
              {
                  @Override
                 public void onClick(View v)
                  {
                      MyCustomDialog.this.finish();
  //                    this.setFinishOnTouchOutside(false);
                      System.exit(0);
                  }
              });
          }
          catch (Exception e)
          {
              Log.d("Exception", e.toString());
              e.printStackTrace();
          }
      }
  
      private void initializeContent()
      {
          tv_client   = (TextView) findViewById(R.id.tv_client);
          dialog_ok   = (Button) findViewById(R.id.dialog_ok);
      }
  }
  </code></pre>
  
  <p><strong>My AndroidManifest.xml</strong></p>
  
  <pre><code> &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".AddCasesActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:name=".receiver.MyCustomDialog"
                    android:theme="@android:style/Theme.Dialog"
                    android:noHistory="true"
              /&gt;
  
  
          &lt;receiver android:name=".receiver.CallReceiver" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.PHONE_STATE" /&gt;
              &lt;/intent-filter&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.NEW_OUTGOING_CALL" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  
      &lt;/application&gt;
  
      &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/&gt;
      &lt;uses-permission android:name="android.permission.MODIFY_PHONE_STATE" tools:ignore="ProtectedPermissions"/&gt;
      &lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /&gt;
  </code></pre>
  
  <p>By implementing all this stuff I am getting the desired output</p>
  
  <p><a href="https://i.stack.imgur.com/vjdU8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vjdU8.png" alt="my receiver output on incoming call"></a></p>
  
  <p>Please guide me how to make this activity dialog dragable like the popup of the truecaller app.</p>
  
  <p>I am searching for the dialog similar to this image ,</p>
  
  <p><a href="https://i.stack.imgur.com/gTvfn.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gTvfn.png" alt="truecaller incoming screen"></a></p>