Skip to main content

Posts

Showing posts from November, 2011

Email validation for android Edittext

public boolean eMailValidation(String emailstring) { emailPattern = Pattern.compile("[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + "\\@" + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + "(" + "\\." + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + ")+"); emailMatcher = emailPattern.matcher(emailstring); return emailMatcher.matches(); }

GET TEXT FROM ASSERT ANDROID

private String getAssertText(String path) { String javascrips= "" ; try { InputStream input = getAssets().open(path); int size; size = input.available(); byte [] buffer = new byte [size]; input.read(buffer); input.close(); // byte buffer into a string javascrips = new String(buffer); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return javascrips; }

Call webservice using restclient android

package com.util; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URLEncoder; import java.util.ArrayList; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; public class RestClient {     private static final int GET = 0; private static final int POST = 1; private ArrayList <NameValuePair> params;     private ArrayList <NameValuePair> header...

Parsing JSON using GSON in Android

Parsing JSON using GSON in Android Download GSON lib : http://code.google.com/p/google-gson/downloads/list As part of the college mini project,  I along with my group, developed a micro-blogging platform for Android. One of the biggest hurdles I had to face was of choosing the proper data format for receiving responses from the web service. I needed something that was fast as well as easy to understand and parse.  I first chose XML as it was easy to read and mostly because I knew no other alternatives. But parsing XML certainly wasn’t easy. With the variety of tags in the responses from the server and the heaviness of XML format, it just became impossible to use it. That’s when  JSON (JavaScript Object Notation) came up as an alternative to XML. I was circumspect about using JSON at first as I had doubts about its readability and ease of deserialization. But those doubts were not much more than just superstitions. JSON is smaller and easier to parse, than...

custom PopupWindow android

private void showAddTextPopup() { PopupWindow window1 = new PopupWindow(this);  window1.setWidth(500);  window1.setHeight(300);  window1.setTouchable(true);  window1.setFocusable(true);  LayoutInflater inflater = (LayoutInflater) NotesActivity.this .getLayoutInflater();// .getSystemService // (Context.LAYOUT_INFLATER_SERVICE);  View bottomView = inflater.inflate(R.layout.addtext, null);  window1.setContentView(bottomView);  window1.showAtLocation(bottomView, Gravity.CENTER_VERTICAL, 50, 50); }

Android AlertDialog Example :-

Android AlertDialog Example :- To ask user permission for "Exit ?" we can use Android AlertDialog with Yes or No Button. So, by clicking Yes we can Exit the  Application   and by clicking No we need not to do any action. [sourcecode language="java"] public class ExampleApp extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AlertDialog.Builder alt_bld = new AlertDialog.Builder(this); alt_bld.setMessage("Do you want to close this window ?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // Action for 'Yes' Button } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //  Action for 'NO' Button dialog.cancel(); } }); AlertDialog alert = alt_b...

Change system screen brightness, using android.provider.Settings.System.SCREEN_BRIGHTNESS

Change system screen brightness, using android.provider.Settings.System.SCREEN_BRIGHTNESS android. provider . Settings .System.putInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, SysBackLightValue); To access Settings.System.SCREEN_BRIGHTNESS, we have to modify AndroidManifest.xml to grant premission of "android.permission.WRITE_SETTINGS". <? xml version ="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.exercise.AndroidScreenBrightness" android:versionCode="1" android:versionName="1.0"> < application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".AndroidScreenBrightness" android:label="@string/app_name"> <intent-filter> <action android:name=...