google

Newest Post

Custom Date Time Picker for Android

| Friday, November 6, 2015
Read more »
Android itself does not provide any date or time picker which can let user choose date and time together.

We can choose dates using DatePickerDialog and times using TimePickerDialog, which requires 2 different dialogs and 2 different actions. Instead of that we can use following code to provide selection of Date and Time in one dialog.

Following is the code of the layout file "date_time_picker.xml" which will be inflated to be displayed in the Date Time Picker Dialog.


 <?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout  
   xmlns:android="http://schemas.android.com/apk/res/android"  
   android:orientation="vertical"  
   android:layout_width="match_parent"  
   android:padding="10dp"  
   android:layout_height="match_parent">  
   <DatePicker  
     android:id="@+id/datepicker"  
     android:layout_width="match_parent"  
     android:calendarViewShown="true"  
     android:spinnersShown="false"  
     android:layout_weight="4"  
     android:layout_height="0dp" />  
   <TimePicker  
     android:id="@+id/timepicker"  
     android:layout_weight="4"  
     android:layout_width="match_parent"  
     android:layout_height="0dp" />  
   <Button  
     android:id="@+id/datetimeset"  
     android:layout_weight="1"  
     android:layout_width="match_parent"  
     android:text="Set"  
     android:layout_height="0dp" />  
 </LinearLayout>  

Following is the code of Button click in Java file which will open the dialog.


  public void SelectDateTime(View v) {  
     final View dialogView = View.inflate(this, R.layout.date_time_picker, null);  
     final AlertDialog alertDialog = new AlertDialog.Builder(this).create();  
     dialogView.findViewById(R.id.datetimeset).setOnClickListener(new View.OnClickListener() {  
       @Override  
       public void onClick(View view) {  
         DatePicker datePicker = (DatePicker) dialogView.findViewById(R.id.datepicker);  
         TimePicker timePicker = (TimePicker) dialogView.findViewById(R.id.timepicker);  
         Calendar calendar = new GregorianCalendar(datePicker.getYear(),  
             datePicker.getMonth(),  
             datePicker.getDayOfMonth(),  
             timePicker.getCurrentHour(),  
             timePicker.getCurrentMinute());  
         SimpleDateFormat mSDF = new SimpleDateFormat("HH:mm:ss");  
         String time = mSDF.format(calendar.getTime());  
         int day = datePicker.getDayOfMonth();  
         int month = datePicker.getMonth();  
         int year = datePicker.getYear();  
         SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");  
         String formatedDate = sdf.format(new Date(year-1900, month, day));  
         editText_datetime.setText(formatedDate + ' ' + time);  
         alertDialog.dismiss();  
       }  
     });  
     alertDialog.setView(dialogView);  
     alertDialog.show();  
   }  


"SelectDateTime" method is called on button click which will fetch the values from Date Time picker into the EditText.

"SimpleDateFormat" class has been used to set the values in desired date and time formats.

Important

String formatedDate = sdf.format(new Date(year-1900, month, day));  

Always +/- 1900 with year formatted using SimpleDateFormat. 

Custom Date Time Picker

Video - Converting a base64 string into the jpg or png Image and save in a folder in website

| Friday, August 28, 2015
Read more »

Video - Converting a base64 string into the jpg or png Image and save in a folder in website

Posted by : Stranger
Date :Friday, August 28, 2015
With 0comments

Converting a base64 string into the jpg or png Image and save in a folder in website

| Wednesday, March 4, 2015
Read more »
Converting a base64 string into the jpg or png Image and save in a folder in website.

This feature can be used for saving the images from the Mobile apps.



  if (!string.IsNullOrEmpty(base64Image))  
     {  
       using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(base64Image)))  
       {  
         using (Bitmap bm2 = new Bitmap(ms))  
         {  
           bm2.Save(HostingEnvironment.MapPath("~/upload/" + "Pic" + ".jpg"));  
         }  
       }  
     }  


The above code has been implemented in a .Net based WCF web service method for saving the image from the mobile app which is returning image as base64 string when uploaded from the mobile.

Converting a base64 string into the jpg or png Image and save in a folder in website

Posted by : Stranger
Date :Wednesday, March 4, 2015
With 0comments

Code to export the Grid View/Data Grid data into Excel File.

| Friday, February 13, 2015
Read more »
 protected void btnExportToExcel_Click(object sender, EventArgs e)  
   {  
     try  
     {  
       DataTable dt = student.GetDetails("B.Tech").Tables[0];  
       DataGrid GridView1 = new DataGrid();  
       GridView1.DataSource = dt;  
       GridView1.DataBind();  
       Response.Clear();  
       Response.Buffer = true;  
       Response.AddHeader("content-disposition", string.Format("attachment; filename=StudentsBTech.xls"));  
       Response.Charset = "";  
       Response.ContentType = "application/vnd.ms-excel";  
       StringWriter sw = new StringWriter();  
       HtmlTextWriter htw = new HtmlTextWriter(sw);  
       GridView1.GridLines = GridLines.Both;  
       GridView1.AllowPaging = false;  
       GridView1.RenderControl(htw);  
       Response.Output.Write(sw.ToString());  
       GridView1.DataBind();  
       Response.Flush();  
     }  
     catch (Exception ex)  
     {  
     }  
     finally { Response.End(); }  
   }  
   public override void VerifyRenderingInServerForm(Control control)  
   { }  

Code to export the Grid View/Data Grid data into Excel File.

Posted by : Stranger
Date :Friday, February 13, 2015
With 0comments
Next Prev
▲Top▲