package com.gani.lib.screen;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.telephony.TelephonyManager;
import android.widget.Toast;

public class LauncherHelper {
  private Context context;

  public LauncherHelper(Context context) {
    this.context = context;
  }

  public void map(String address) {
    String uri = "http://maps.google.com/maps?q=" + address;
    // String uri = "geo:0,0?q=" + object.getNullableString("location");
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    // intent.setPackage("com.google.android.apps.maps");
    context.startActivity(intent);
  }

  public void call(String number) {
//    Intent i = new Intent(Intent.ACTION_CALL);
//    i.setData(Uri.parse("tel:" + number));
//    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
//      Toast.makeText(context, "Please grant the  permission to call", Toast.LENGTH_SHORT).show();
//      ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.CALL_PHONE}, 1);
//    } else {
//      context.startActivity(i);
//    }

    if (((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
      Intent i = new Intent(Intent.ACTION_DIAL);
      i.setData(Uri.parse("tel:" + number));
      context.startActivity(i);
    }
  }

  public void mail(String to, String subject, String message) {
    Intent i = new Intent(Intent.ACTION_SEND);
    String[] s = {to};
    i.putExtra(Intent.EXTRA_EMAIL, s);
    i.putExtra(Intent.EXTRA_SUBJECT, subject);
    i.putExtra(Intent.EXTRA_TEXT, message);
    i.setType("message/rfc822");
    Intent chooser = Intent.createChooser(i, "Launch Email");
    context.startActivity(chooser);
  }
}

@@ -27,62 +27,8 @@
 n;%0A%0A
-import android.Manifest;%0Aimport android.app.Activity;%0A
 impo
@@ -105,103 +105,15 @@
 oid.
-content.pm.PackageManager;%0Aimport android.net.Uri;%0Aimport android.support.v4.app.ActivityCompat
+net.Uri
 ;%0Aim
@@ -157,34 +157,46 @@
 er;%0A
+%0A
 import 
-android.widget.Toas
+com.gani.lib.notification.Aler
 t;%0A%0A
@@ -1458,16 +1458,106 @@
 ;%0A    %7D%0A
+    else %7B%0A      Alert.display(context, %22This device doesn't support phone calls%22);%0A    %7D%0A
   %7D%0A%0A  p

add alert