Show Settings Alert

    public void showSettingsAlert(){
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

        // Setting Dialog Title
        alertDialog.setTitle("GPS is settings");

        // Setting Dialog Message
        alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");

        // On pressing Settings button
        alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int which) {
                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                mContext.startActivity(intent);
            }
        });

        // on pressing cancel button
        alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });

        // Showing Alert Message
        alertDialog.show();
    }

Detect Tap Count in Android

private int count = 0;
    private long startMillis=0;

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        int eventaction = event.getAction();
        if (eventaction == MotionEvent.ACTION_UP) {

            //get system current milliseconds
            long time= System.currentTimeMillis();


            //if it is the first time, or if it has been more than 3 seconds since the first tap ( so it is like a new try), we reset everything
            if (startMillis==0 || (time-startMillis> 3000) ) {
                startMillis=time;
                count=1;
            }
            //it is not the first, and it has been  less than 3 seconds since the first
            else{ //  time-startMillis< 3000
                count++;
            }

            if (count==5) {
                 BrId = myPrefs.getInt("BrId", 0); // return 0 if someValue doesn't exist
                if(BrId != 0){
                    txtBrId.setText(String.valueOf(BrId));
                }
                txtBrId.setVisibility(View.VISIBLE);
                btnSaveBrId.setVisibility(View.VISIBLE);
                btnStartTracker.setVisibility(View.INVISIBLE);
            }
            return true;
        }
        return false;
    }

Show notification in android status bar

    private void ShowStatusBarNotification(String contentTitle,String contentText)
    {
        Notification notification = new Notification.Builder(getApplicationContext())
                .setContentTitle(contentTitle)
                .setContentText(contentText)
                .setSmallIcon(R.drawable.ic_statusbar_msg)
                .build();

        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // notificationID allows you to update the notification later on.
        mNotificationManager.notify("BR Tracker",(int)(Math.random() * 101) ,notification);
    }

Google Map Polyline

<script type="text/javascript">
var map;
var markers = [];
var path = [];

$(function () {

    var opts = {
        zoom: 10,
        center: { lat: 23.564587, lng: 90.569874 },
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById('map_canvas'), opts);



    $('#AttendanceSearch').click(function (e) {
        e.preventDefault();
               

        var newMarker = {};
        newMarker.Latitude = 24.8594959;
        newMarker.Longitude = 89.3631192;
        newMarker.Accuracy = 20.0;
        newMarker.MarkerName = 'hi';
        markers.push(newMarker);
        path.push(new google.maps.LatLng(24.8594959, 89.3631192));

        var markerTwo = {};
        markerTwo.Latitude = 23.9246227;
        markerTwo.Longitude = 90.7130343;
        markerTwo.Accuracy = 20.0;
        markerTwo.MarkerName = 'hello';

        markers.push(markerTwo);
        path.push(new google.maps.LatLng(23.9246227, 90.7130343));

        setArrows = new ArrowHandler();

        //Looping markers array--->
        markers.forEach(function (markerInfo, index) {
            //marker object --->
            var marker = new google.maps.Marker({
                name: markerInfo.MarkerName,
                position: { lat: markerInfo.Latitude, lng: markerInfo.Longitude },
                map: map,
                title: markerInfo.MarkerName
            });
            //marker object ---<

            marker.addListener('click', function () {
                var contentString = "Hello Bro";


                var infowindow = new google.maps.InfoWindow({
                    content: contentString
                });

                infowindow.open(map, marker);
            });

        });
        //Looping markers array ----<

        createPoly(path, "midline");
    });
</script>


<script type="text/javascript">
    //<![CDATA[

    /**
     * Based on code provided by Mike Williams
     * http://econym.org.uk/gmap/arrows.htm
     * Improved and transformed to v3
    */

    var setArrows;


    function ArrowHandler() {
        this.setMap(map);
        // Markers with 'head' arrows must be stored
        this.arrowheads = [];
    }
    // Extends OverlayView from the Maps API
    ArrowHandler.prototype = new google.maps.OverlayView();

    // Draw is inter alia called on zoom change events.
    // So we can use the draw method as zoom change listener
    ArrowHandler.prototype.draw = function () {

        if (this.arrowheads.length > 0) {
            for (var i = 0, m; m = this.arrowheads[i]; i++) {
                m.setOptions({ position: this.usePixelOffset(m.p1, m.p2) });
            }
        }
    };


    // Computes the length of a polyline in pixels
    // to adjust the position of the 'head' arrow
    ArrowHandler.prototype.usePixelOffset = function (p1, p2) {

        var proj = this.getProjection();
        var g = google.maps;
        var dist = 12; // Half size of triangle icon

        var pix1 = proj.fromLatLngToContainerPixel(p1);
        var pix2 = proj.fromLatLngToContainerPixel(p2);
        var vector = new g.Point(pix2.x - pix1.x, pix2.y - pix1.y);
        var length = Math.sqrt(vector.x * vector.x + vector.y * vector.y);
        var normal = new g.Point(vector.x / length, vector.y / length);
        var offset = new g.Point(pix2.x - dist * normal.x, pix2.y - dist * normal.y);

        return proj.fromContainerPixelToLatLng(offset);
    };


    // Returns the triangle icon object
    ArrowHandler.prototype.addIcon = function (file) {
        var g = google.maps;
        var icon = {
            url: "http://www.google.com/mapfiles/" + file,
            size: new g.Size(24, 24), anchor: new g.Point(12, 12)
        };
        return icon;
    };

    // Creates markers with corresponding triangle icons
    ArrowHandler.prototype.create = function (p1, p2, mode) {
        var markerpos;
        var g = google.maps;
        if (mode == "onset") markerpos = p1;
        else if (mode == "head") markerpos = this.usePixelOffset(p1, p2);
        else if (mode == "midline") markerpos = g.geometry.spherical.interpolate(p1, p2, .5);

        // Compute the bearing of the line in degrees
        var dir = g.geometry.spherical.computeHeading(p1, p2).toFixed(1);
        // round it to a multiple of 3 and correct unusable numbers
        dir = Math.round(dir / 3) * 3;
        if (dir < 0) dir += 240;
        if (dir > 117) dir -= 120;
        // use the corresponding icon
        var icon = this.addIcon("dir_" + dir + ".png");
        var marker = new g.Marker({
            position: markerpos,
            map: map, icon: icon, clickable: false
        });
        if (mode == "head") {
            // Store markers with 'head' arrows to adjust their offset position on zoom change
            marker.p1 = p1;
            marker.p2 = p2;
            // marker.setValues({ p1: p1, p2: p2 });
            this.arrowheads.push(marker);
        }
    };

    ArrowHandler.prototype.load = function (points, mode) {
        for (var i = 0; i < points.length - 1; i++) {
            var p1 = points[i],
            p2 = points[i + 1];
            this.create(p1, p2, mode);
        }
    };


    // Draws a polyline with accordant arrow heads
    function createPoly(path, mode) {
        var poly = new google.maps.Polyline({
            strokeColor: "#0000ff",
            strokeOpacity: 0.8,
            strokeWeight: 3,
            map: map,
            path: path
        });

        setArrows.load(path, mode);
        return poly;
    }
</script>

Google map polyline

//API v2
var polyline = new GPolyline([
  new GLatLng(37.4419, -122.1419),
  new GLatLng(37.4519, -122.1519)],
  "#ff0000", 10);
map.addOverlay(polyline);

//API v3
var line = new google.maps.Polyline({
    path: [new google.maps.LatLng(37.4419, -122.1419), new google.maps.LatLng(37.4519, -122.1519)],
    strokeColor: "#FF0000",
    strokeOpacity: 1.0,
    strokeWeight: 10,
    geodesic: true, //This line is optional
    map: map
});

C# dynamic ExpandoObject()

using System;
using System.Dynamic;
public class HomeController : Controller
{
       public ActionResult SingleObject()
       {
           dynamic contact = new ExpandoObject(); //Declaring new dynamic object

           contact.Name = "ABC"; // manually adding property & value
           string propertyName = "Age";  int propertyValue = 5; 
           AddProperty(contact, propertyName, propertyValue); //dynamically adding   
                                                                prop & value

           return View(contact);
       }

       //SingleObject.cshtml
       @model dynamic
       <h1>@Model.Name</h1>
       <h1>@Model.Age</h1>

       public ActionResult ObjectList()
       {
          // declaring a list of dynamic object
          dynamic contacts = new List<dynamic>(); 

          // Adding 1st object to the list
          contacts.Add(new ExpandoObject());
          contacts[0].Name = "ABC";
          contacts[0].Phone = "123";

          // Adding 2nd object to the list
          contacts.Add(new ExpandoObject());
          contacts[1].Name = "XYZ";
          contacts[1].Phone = "456";

          return View(contacts);
        }

        //ObjectList.cshtml
        @model dynamic
        @foreach (var item in Model)
        {
           <h2>@item.Name;</h2>
        }

        //Helper method to add property in run-time.
        public void AddProperty(ExpandoObject expando, string propertyName, object propertyValue)
        {
            // ExpandoObject supports IDictionary so we can extend it like this
            var expandoDict = expando as IDictionary<string, object>;
            if (expandoDict.ContainsKey(propertyName))
                expandoDict[propertyName] = propertyValue;
            else
                expandoDict.Add(propertyName, propertyValue);
        }
}

Quickly submit HTML Form in AJAX as JSON

//
//JQuery part-
//
function form_to_json(selector) {
    var ary = $(selector).serializeArray();
    var obj = {};
    for (var a = 0; a < ary.length; a++) obj[ary[a].name] = ary[a].value;
    return obj;
}

$('#SubmitTheForm').click(function (e) {
    e.preventDefault();
    var $button = $(this);
    var url = $('#form').attr("action");
    var formdata = form_to_json('#form');
    $.ajax({
        type: 'POST',
        url: url,
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(formdata), 
        dataType: 'json',
        beforeSend: function () {
            $button.attr('disabled', 'disabled');
            $button.html('Working…');
        },
        success: function (result) {
            console.log(result);
        },
        error: function (request, status, error) {
            alert('Failed to save. Error Details – Request: ' + request + ', Status: ' + status + ', Error: ' + error);
        },
        complete: function () {
            $button.removeAttr('disabled');
            $button.html('Submit');
        }
    });
});
//
//JQuery part-
//
public ActionResult AddBr(int Id, string Name)
{
    return Json(BrName);
}

Quickly submit HTML Form in AJAX

It is best for quickly submit a simple html form via AJAX.

//
//JQuery Part
//
$('#SubmitTheForm').click(function (e) {
    e.preventDefault();
    var $button = $(this);
    var SubmitURL = $('#form').attr("action");
    var FormData = $('#form').serialize();
    $.ajax({
        type: 'POST',
        url: url,
        data: FormData,
        beforeSend: function () {
            $button.attr('disabled', 'disabled');
            $button.html('Working…');
        },
        success: function (result) {         
        },
        error: function (request, status, error) {
        },
        complete: function () {
            $button.removeAttr('disabled');
            $button.html('Submit');
        }
    });
});
//
//C# Part
//
[HttpPost]
public ActionResult AddBr(int id, string name)
{
    return Json("success");
}

Convert HTML Form to JSON


Option -1:
function form_to_json(selector) {
    var ary = $(selector).serializeArray();
    var obj = {};
    for (var a = 0; a < ary.length; a++) obj[ary[a].name] = ary[a].value;
    return obj;
}

//Example
var mydata = form_to_json('#form');
JSON.stringify(mydata);
---------------------------------------------------------

Option-2:
Using Third party JQuery plugin- http://maxatwork.github.io/form2js/

<script src="form2js.js"></script>
<script src="jquery.toObject.js"></script>

var data = $('#form').toObject({skipEmpty:false});
JSON.stringify(data)