Monday, March 30, 2015

How to write style to error text of EditText in android?


int ecolor = R.color.black; String estring = "Please enter a valid email address";

ForegroundColorSpan fgcspan = new ForegroundColorSpan(ecolor);
SpannableStringBuilder ssbuilder = new SpannableStringBuilder(estring);
ssbuilder.setSpan(fgcspan, 0, estring.length(), 0);
edtEmail.requestFocus();
edtEmail.setError(ssbuilder); 

Friday, February 13, 2015

Current local time in UTC

   
        try {
            Calendar calendar = Calendar.getInstance();
            int month = calendar.getTime().getMonth() + 1;
            String timeStampToMatch = calendar.getTime().getDate() + "-"
                    + month + "-" + calendar.get(Calendar.YEAR) + " "
                    + "01:01 pm";

            Log.i("======>", timeStampToMatch);

            DateFormat dateFormat = new SimpleDateFormat("d-M-yyyy H:m");

            Date date = dateFormat.parse(timeStampToMatch);
            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
            Log.i("======>", dateFormat.format(date));

        } catch (ParseException e) {
            e.printStackTrace();
        }


Using common Layout and its event in all activities

ViewGroup vg = (ViewGroup) findViewById(R.id.lldata);
ViewGroup.inflate(getApplicationContext(), R.layout.listwitter, vg);

Tuesday, September 2, 2014

WebView Background Color (Transparent)

WebView webViewData = (WebView) findViewById(R.id.webView1);

webView1.setBackgroundColor(0x00000000);

WebView With HTML Script Demo

Ø  Create MainActivity.java class in src/package.


MainActivity.java


import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

       private WebView webView1;
       private ProgressDialog pd;

       @SuppressLint("SetJavaScriptEnabled")
       @Override
       protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.main);

             pd = ProgressDialog.show(this, "", "Loading...", true);

             webView1 = (WebView) findViewById(R.id.webView1);
             webView1.getSettings().setJavaScriptEnabled(true);
             webView1.getSettings().setSupportZoom(true);
             webView1.getSettings().setBuiltInZoomControls(true);
             webView1.setWebViewClient(new WebViewClient() {
                    @Override
                    public void onPageFinished(WebView view, String url) {
                           if (pd.isShowing() && pd != null) {
                                 pd.dismiss();
                           }
                    }
             });
             webView1.loadUrl("file:///android_asset/test.html");
       }
}


Ø  Create main.xml in res/layout.


main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>


Ø  Create test.html in assets.




test.html


<head>
<title>Internal Script</title>
</head>
<body>
       <script type="text/javascript">
   document.write("Hello Javascript!")
</script>

</body>

WebView With Loading Demo (WebViewClient)

Ø  Create MainActivity.java class in src/package.


MainActivity.java


import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

       private WebView webView1;
       private ProgressDialog pd;

       @SuppressLint("SetJavaScriptEnabled")
       @Override
       protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.main);

             pd = ProgressDialog.show(this, "", "Loading...", true);

             webView1 = (WebView) findViewById(R.id.webView1);
             webView1.getSettings().setJavaScriptEnabled(true);
             webView1.getSettings().setSupportZoom(true);
             webView1.getSettings().setBuiltInZoomControls(true);
             webView1.setWebViewClient(new WebViewClient() {
                    @Override
                    public void onPageFinished(WebView view, String url) {
                           if (pd.isShowing() && pd != null) {
                                 pd.dismiss();
                           }
                    }
             });
             webView1.loadUrl("https://www.google.co.in/");
       }
}


Ø  Create main.xml in res/layout.


main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>


Ø  Add Permission in AndroidManifest.xml.


<uses-permission android:name="android.permission.INTERNET" />




WebView Demo

Ø  Create MainActivity.java class in src/package.


MainActivity.java


import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class MainActivity extends Activity {

       private WebView webView1;

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

             webView1 = (WebView) findViewById(R.id.webView1);
             webView1.loadUrl("https://www.google.co.in/");
       }
}


Ø  Create main.xml in res/layout.


main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>


Ø  Add Permission in AndroidManifest.xml.


<uses-permission android:name="android.permission.INTERNET" />