9 Jan 2015

Dynamic html and javascript from assets in a WebView | Add external css file on html page in Android

I am trying to display HTML content in a web view. The UI is simple jQuery Mobile. The HTML displays, but the CSS and JavaScript from the assets folder.
Css and js file will resides in assets folder.

Note : Put you .css and .js file in assets folder as well

here is the implementation code

OUTPUT :



WebView  wvSpecification= (WebView)rootview.findViewById(R.id.wvSpecification);

       StringBuilder sb = new StringBuilder();
                     sb.append("<HTML xmlns='http://www.w3.org/1999/xhtml'>" +           
                                  "<HEAD>"+
                                  "<meta name='viewport' content='width=device-width, initial-scale=1'>"+
                                  "<link rel='stylesheet' href=cssfilename.css'/>"+
                                  "<link rel='stylesheet' href= cssfilename.css'/>"+
                                  "<script src= jsfilename.js' type='text/javascript'></script>"+
                                  "</HEAD>"); 

                     sb.append("<body>"+
                                  "<h1>Mobile</h1>"+
                                  "<table class='responsive'>"+
                                  "<tr>"+
                                  "<th>Company Name</th>"+
                                  "<th>Model Name</th>"+
                                  "<th>Version</th>"+
                                  "</tr>"+
                                  "<tr>"+
                                  "<td>Google</td>"+
                                  "<td>Nexus 5</td>"+
                                  "<td>4.4</td>"+
                                  "</tr>"+
                                  "<tr>"+
                                  "<td>HTC</td>"+
                                  "<td>Desire X</td>"+
                                  "<td>4.1</td>"+
                                  "</tr>"+
                                   "<tr>"+
                                  "<td>Samsung</td>"+
                                  "<td>Galaxy s4</td>"+
                                  "<td>4.3</td>"+
                                  "</tr>"+
                                  "</table>"+
                                  "</body>");
                                  sb.append("</HTML>");


                                  wvSpecification.loadDataWithBaseURL("file:///android_asset/",sb.toString(),"text/html","UTF-8",null);


You may like Web View with Progress Dialog visit

I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.
Thank you :)

2 Jan 2015

Custom dialog with animation | Dialog effect Android

There are no any application available without alert massages,Generally we are using AlertDialog of android for Alert.

In this tutorial, you can achieve much more using dialog as per your desire like
-Set theme for dialog
-Set custom view in dialog
-Animations for dialog

Animation Effects :
Fadein, Slideleft, Slidetop, SlideBottom, Slideright, Fall, Newspager, Fliph, Flipv, RotateBottom, RotateLeft, Slit, Shake, Sidefill

For more visualization (See the Effect)

OUTPUT SCREEN :




Here is the implementation :

MainActivity :


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import com.hb.lib.CustomDialogBuilder;
import com.hb.lib.Effectstype;

public class MainActivity extends Activity
{
       private Effectstype effect;

       @Override
       protected void onCreate(Bundle savedInstanceState)
       {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
       }

       public void dialogShow(View v)
       {
              CustomDialogBuilder dialogBuilder=CustomDialogBuilder.getInstance(this);

              switch (v.getId())
              {
              case R.id.fadein:effect=Effectstype.Fadein;break;
              case R.id.slideright:effect=Effectstype.Slideright;break;
              case R.id.slideleft:effect=Effectstype.Slideleft;break;
              case R.id.slidetop:effect=Effectstype.Slidetop;break;
              case R.id.slideBottom:effect=Effectstype.SlideBottom;break;
              case R.id.newspager:effect=Effectstype.Newspager;break;
              case R.id.fall:effect=Effectstype.Fall;break;
              case R.id.sidefall:effect=Effectstype.Sidefill;break;
              case R.id.fliph:effect=Effectstype.Fliph;break;
              case R.id.flipv:effect=Effectstype.Flipv;break;
              case R.id.rotatebottom:effect=Effectstype.RotateBottom;break;
              case R.id.rotateleft:effect=Effectstype.RotateLeft;break;
              case R.id.slit:effect=Effectstype.Slit;break;
              case R.id.shake:effect=Effectstype.Shake;break;
              }

              dialogBuilder
              .withTitle("Alert Dialog")                           
              .withTitleColor("#FFFFFF")                           
              .withDividerColor("#cfdde7")                         
              .withMessage("This is a Dialog.")                    
              .withMessageColor("#FFFFFFFF")                           
              .withDialogColor("#264461")                              
              .withIcon(getResources().getDrawable(R.drawable.icon))
              .isCancelableOnTouchOutside(true)                         
              .withDuration(700)                                        
              .withEffect(effect)                                        
              .withButton1Text("OK")                                     
              .withButton2Text("Cancel")                                  
              .setCustomView(R.layout.custom_view,v.getContext()) 

              .setButton1Click(new View.OnClickListener()
              {
                     @Override
                     public void onClick(View v)
                     {
                           Toast.makeText(v.getContext(), "Press OK button", Toast.LENGTH_SHORT).show();
                     }
              })
              .setButton2Click(new View.OnClickListener()
              {
                     @Override
                     public void onClick(View v)
                     {
                           Toast.makeText(v.getContext(), "Press Cancel button", Toast.LENGTH_SHORT).show();
                     }
              })
              .show();

       }


}

Download Library & Sample :  DialogEffectSample

I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.
Thank you :)