Popular Posts

There was an error in this gadget

Jun 25, 2012

Exceptions of Android

Exceptions that are supported by Android:

1. InflateException : This exception is thrown When an error conditions are occurred.

2. Surface.OutOfResourceException: This exception is thrown When a surface is not created or resized.

3. SurfaceHolder.BadSurfaceTypeException: This exception is thrown from the lockCanvas() method, when invoked on a Surface whose is SURFACE_TYPE_PUSH_BUFFERS

4. WindowManager.BadTokenException: This exception is thrown at the time of trying to add view an invalid WindowManager.LayoutParamstoken.



Hide Title in android application

You can hide your android application title....

Create MyFirstAndroidApp.Java Class  :   -----
-----------------------------------------------


package my.MyFirstAndroidApp;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;

import android.view.View;
import android.view.View.OnClickListener;

import android.widget.Button;
import android.widget.Toast;

public class MyFirstAndroidAppActivity extends Activity { 
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        // -- hides the title bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);
       
        setContentView(R.layout.main);
    }
}

Features of Android

Android features:

1. Components can be reused and replaced by the application framework.

2. Optimized DVM for mobile devices

3. SQLite enables to store the data in a structured manner.

4. Supports GSM telephone and Bluetooth, WiFi, 3G and EDGE technologies

5. The development is a combination of a device emulator, debugging tools, memory profiling and plug-in for Eclipse IDE.

Jun 20, 2012

Generate 3D Pie Chart using Google Chart Tools

Using Google Chart Tools, we can easily generate 3D pie chart.

Class File:

package com.pie.chart;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class PieChartActivity extends Activity {
    /** Called when the activity is first created. */
   
    final static String urlGoogleChart = "http://chart.apis.google.com/chart";
    final static String urlp3Api = "?cht=p3&chs=400x150&chl=A|B|C|D|E&chd=t:";
     
     EditText inputA, inputB, inputC;
     Button generate;
     ImageView pieChart;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        inputA = (EditText)findViewById(R.id.adata);
        inputB = (EditText)findViewById(R.id.bdata);
        inputC = (EditText)findViewById(R.id.cdata);
        generate = (Button)findViewById(R.id.generate);
        pieChart = (ImageView)findViewById(R.id.pie);
        generate.setOnClickListener(generateOnClickListener);
    }

  Button.OnClickListener generateOnClickListener = new Button.OnClickListener(){

  @Override
  public void onClick(View arg0) {
   // TODO Auto-generated method stub
   String A = inputA.getText().toString();
   String B = inputB.getText().toString();
   String C = inputC.getText().toString();
   String D = "14";
   String E = "24";
   String urlRqs3DPie = urlGoogleChart + urlp3Api + A + "," + B + "," + C+ "," + D+ "," + E;
   
   Bitmap bm3DPie = loadChart(urlRqs3DPie);
   if(bm3DPie == null){
    Toast.makeText(PieChartActivity.this, "Problem in loading 3D Pie Chart", Toast.LENGTH_LONG).show();
   }else{
    pieChart.setImageBitmap(bm3DPie);
   }
  }};

 
  private Bitmap loadChart(String urlRqs){
      Bitmap bm = null;
      InputStream inputStream = null;
      
      try {
       inputStream = OpenHttpConnection(urlRqs);
       bm = BitmapFactory.decodeStream(inputStream);
       inputStream.close();
      } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
      
      return bm;
     }
         
     private InputStream OpenHttpConnection(String strURL) throws IOException{
      InputStream is = null;
      URL url = new URL(strURL);
      URLConnection urlConnection = url.openConnection();
           
      try{
       HttpURLConnection httpConn = (HttpURLConnection)urlConnection;
       httpConn.setRequestMethod("GET");
       httpConn.connect();
       
       if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
        is = httpConn.getInputStream();
       }
      }catch (Exception ex){
      }
      
      return is;
     }
   
   
}


Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<LinearLayout
 android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="A "
    />
<EditText
    android:id="@+id/adata"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="number" />
</LinearLayout>
<LinearLayout
 android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="B "
    />
<EditText
    android:id="@+id/bdata"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="number" />
</LinearLayout>
<LinearLayout
 android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="C "
    />
<EditText
    android:id="@+id/cdata"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="number" />
</LinearLayout>
<Button
    android:id="@+id/generate"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Generate 3D Pie Chart"
    />

<ImageView
    android:id="@+id/pie"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

</LinearLayout>


Add   <uses-permission android:name="android.permission.INTERNET" /> to manifest file.


Jun 13, 2012

Write in text file(C#)


 Create file at C:\Text\myText.txt

         try
            {
                string fileName = @"C:\Text\myText.txt";

                using (System.IO.StreamWriter writer = new System.IO.StreamWriter(fileName, true))
                {

                    writer.Write("Write some text here");

                }

            }

            catch (Exception exp)
            {

                Console.WriteLine(exp.Message);

            }

            Console.ReadKey();

Read Text File In C#

      using (StreamReader sr = new StreamReader(@"C:\TextFile\text.txt"))
            {
                String line;
                // Read line by line
                while ((line = sr.ReadLine()) != null)
                {
                    Console.WriteLine(line);
                }
            }
            Console.ReadKey();