Pages

Thursday, January 29, 2015

SWITCH CASE 

switch (exp)
{
 case constant 1;
          statement;
         break;
  case constant 2;
           statement;
           break;
_____________
           ________
          ________
          default;
        statement;
}

RULES FOR SWITCH CASE :=

1.)  CASE CONSTANTS MUST BE OF TYPE INT OR CHAR.

2.) NO TWO CASE MAY BE SAME.

3.) BREAK IS OPTIMAL.

4.) DEFAULT IS OPTIMAL.


EXAMPLE


class color 
{
 public static void main (string args[])
 {
  char ch = args[0.].char At(0);

  switch(ch)
   {
     case "R":
     system.out.println("RED");
     break;
     case "G":
     system.out.println("GREEN");
     break;
     case "B":
     system.out.println("BLUE");
     break;
    default;
     system.out.println("UNDEFINED"); 
   } 
  }
 }


AS SAME WE CAN MAKE A CALCULATOR OR MORE OTHER PROGRAMS.














Saturday, January 17, 2015

A Example of "if else" loop

Here i'm going to give you an example of of "if else" loop to write a program on 

FIND THE TOTAL MARKS AND PERCENTAGE OF AA STUDENT IN 5 SUBJECTS 



class student 

{
  public static void main(string args[]);

  {
    int a,b,c,d,e,t;  
    float p;

a= Integer.parseInt(args[0]);
b= Integer.parseInt(args[1]);
c= Integer.parseInt(args[2]);
d= Integer.parseInt(args[3]);
e= Integer.parseInt(args[4]);

t=(a+b+c+d+e);

system.out.println("total marks are" +t);
p=(t/500)*100;
system.out.println("percentage is " +p);
if (p>=4)
{
system.out.println("student is passed");
}
else
 {
   system.out.println("student failed"); 
 }
}
}










Thursday, June 26, 2014

Capture image from camera in android


To capture image from android first fire an intent.
       
        private static final int REQUEST_CODE_IMAGE = 101;

        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, REQUEST_CODE_IMAGE);


//  get data on on Activity Result use the below code

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
 if (requestCode == REQUEST_CODE_IMAGE && resultCode == RESULT_OK) {

   if (data != null) {
    if (data.getExtras().get("data") != null) {
 
     Uri fileUri = data.getData();
     String filePath = getRealPathFromURI(fileUri,
       MediaStore.Images.Media.DATA);
     File file = new File(filePath);
     String fileName = file.getName();


     try {
      Bitmap photo = (Bitmap) data.getExtras().get("data");
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      photo.compress(Bitmap.CompressFormat.PNG, 100, stream);



     } catch (Exception ex) {

     }
    }
   }
  }

Show or Read PDF in Android


To Show PDF file in your android phone first save it in your assets folder than read PDF file by using below two methods.
These methods first store your pdf in local storage than show it from local storage.

private void CopyReadAssets(String fileName) {
AssetManager assetManager = getAssets();

InputStream in = null;
OutputStream out = null;
File file = new File(getFilesDir(), fileName);
try {
in = assetManager.open(fileName);
out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);

copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e) {
Log.e("tag", e.getMessage());
}

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.parse("file://" + getFilesDir() + "/" + fileName),
"application/pdf");

startActivity(intent);
}

private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
}

Saturday, February 15, 2014

How to get screen dimensions in android



There is Display class to get the display of screen in android.

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
//getSize()  method is introduced in API level 13.
int width = size.x;
int height = size.y;

Before API  level 13 below method are used.

Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth(); //this method is deprecated now
int height = display.getHeight();//this method is deprecated now