We provide complete mobile and web apps development solutions

Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Saturday, November 24, 2012

Graphics

Graphics in Android


Android API provides allow to draw custom graphics onto a canvas or to modify existing views to look good.

 We we draw graphics, we can do it in 2 ways.

1. draw the graphics into a view object from layout.
2. draw the graphics directly to the Canvas.

To draw something, we need 4 basic components.

1. A Bitmap to hold the pixels.
2. A canvas to host the draw  calls- writing into the Bitmap.
3. Draw primitive- like draw rectangle, text, path etc.
4. Paint- describes the colors and styles to draw.


Bitmap to hold the pixels:

It's a simple example to draw a bitmap on screen in View. The content view is set to a View, and the drawing is achieved in onDraw method.
To draw a bitmap on screen in View, Content view is set to view and dwaing is get in onDraw().

 A canvas to host the draw  calls- writing into the Bitmap:
Canvas works as interface to actual surface upon which graphics will drawn.
It holds all "draw" calls.With canvas, drawing is actually performed underlying Bitmap, which is placed into Window.

 Bitmap bm=BitmapFactory.decodeResource(getResources(),R.drawable.image);

canvas.drawBitmap(bm,0,0,null);


To draw color
 canvas.drawColor(Color.WHITE);

here is the simple example program

package com.srinivas.graphics;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new NewView(this));
    }
   
   
    private class NewView extends View
    {

        public NewView(Context context) {
            // TODO Auto-generated constructor stub
            super(context);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            // TODO Auto-generated method stub
            super.onDraw(canvas);
            Bitmap bm=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
            canvas.drawBitmap(bm, 0,0, null);
        }
    }
}


download source code here
http://www.4shared.com/zip/9wuEVziV/GRaphics.html?

SurfaceView

it is a subclass of View. By using this we can draw surface within the View hierarchy.



The SurfaceView is a special subclass of View that offers a dedicated drawing surface within the View hierarchy. The aim is to offer this drawing surface to an application's secondary thread, so that the application isn't required to wait until the system's View hierarchy is ready to draw. Instead, a secondary thread that has reference to a SurfaceView can draw to its own Canvas at its own pace.
To begin, you need to create a new class that extends SurfaceView. The class should also implement SurfaceHolder.Callback.


Friday, November 23, 2012

jobs@ Android


Urgent Requirement for Android Developers for Hyderabad Location 

Experience Range            :               0-5 Years



send resumes to

anupamareddy@celebron.com


About SIMFORM 

We are rapidly growing software solutions company based in Ahmedabad with primary client base in North America. We are developing couple of cloud software, providing web solutions to client round the globe and at the same time we provide top class small business web design services to clients in North America.
We are in our development stage but, promise our employees healthy and comfortable work conditions and a promising career at the same time.

Why to work @ Simform ? 

Employee-friendly company environment
Working days : Monday to Friday 
Flexible work hours
Attractive Salary Package, Incentives for top performer of month

JOB DESCRIPTION

Designation Offered: IPhone Applications Developer 
Department: Mobile Applications Development 
Qualification: B.E./B.Tech/M.E./M.Tech/ 
Experience: 1 yr + 
Reporting to: PM 

Roles & Responsibility: 
1) Understanding the project requirement 
2) Understanding the project requirement 
3) Able to code the projects with efficiency 
4) Testing the applications and ensuring the programs and applications do not have glitches, 
errors, or low functionality. Fixing bugs, if any. 

Knowledge/Skills/Ability : 
1) A systematic approach to application integration 
2) Defensive coding ability accompanied with strong analytical and creative problem solving skills 
3) Knowledge of Xcode, Objective C, Sqlite, Core Data, Webservice, APNS, Local notification, 
Calender, Facebook/Twitter integration, Graph, Barcode/QR code, Audio/Video streaming, Core 
Location, ePub/PDF programming, Basics of core graphics 
4) Knowledge of game development, iTunes connect and Keychain is desirable 
5) Strong OOPS concept, and knowledge of database and SDLC compulsory.



Urgent requirement for "Trainee Software Developer" -- Java & J2EE

Required Technical skills:
J2SE, J2EE, Servlets, JSP, Struts, SQL, XML, HTML, JavaScript

Eligibility : BE/BTech/MCA
Location: Hyderabad

Desired Candidate Profile:
* Candidate should have good verbal and written communication skills.
* Willing to relocate.

Interested candidates share your updated profile on hr.unijobz@gmail.com
Seo Directory List

Monday, October 29, 2012

Service in android

Activity is a foreground process. It contains user interaction. To run long running operations, we have to create a service.It will run in background. It does not contain user interaction.

Types of services:

1. Unbound Service: it runs in the background indefinitely even started activity with service ends also.
2. Bound Service : it will run till life time of activity.

 Activity can start service via startService()and it will stop via stopService().
If activity want to interact with service,it can use bindService().

first onCreate() is called, after onStartCommand is called with the intent data provided by the activity.


Android provides many predefined services exposed via Manager class.


Own services must be declared in the manifest file..


Some methods:

An activity can start a service via startService() method.

stop the service by using stopService() method.

bindService() - this is for activity to interact with service.

it needs "ServiceConnection" object.


Once service is started    onCreate()  is called.
onStart()



onBind()- the system calls when other component want to bind the service.

onStop() - for stopping the service.

OnDestroy()- called when service is no longer used. and it is destroyed.



Own services must be declared in manifest file.

how to declare own service:

<service android:name="your class"></service>
implementing class must extend the class   " service or one of its subclasses.


Ex: AsyncTask:
using services in android allows to have app running inthe background. if u want to do a simple task run in the background, use AsyncTask.

AsyncTask class:


private class someclassname extends AsyncTask<x,y,z>

protected void onPreExecute()
{
// starting new thread i.e    initilizing


protected void doInBackground()

// perform the action or do the task


protected void onPostExecute(){
// closing the process
}


 Example:

MainActivity.java
package com.example.servicetest;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        startService(new Intent(this,ServiceAct.class));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}


ServiceAct.java
package com.example.servicetest;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class ServiceAct extends Service{
    String tag="service tag";
    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        Log.d(tag, "service destroyed");   
    }
   
@Override
    public void onStart(Intent intent, int startId) {
        // TODO Auto-generated method stub
        super.onStart(intent, startId);
        Log.d(tag, "service started");
        stopSelf();
    }}

manifest permission

<service android:name="ServiceAct" />

Thursday, October 4, 2012

MediaPlayer/ MediaRecorder in Android


Package: android.media  

android.media   package provides various media interfaces in audi and video.
MediaPlayer class: it is used to control the playback of audio and video files.
MediaRecorder class: it is used to record audio and video.
MediaPlayer

MediaPlayer/MediaRecorder:
Steps to create MediaPlayer

Step1: Create an instance of the MediaPlayer
MediaPlayer mp1=new MediaPlayer();
Step2: specify the source path of media file
mp1=MediaPlayer.create(this,R.raw.my_music);
another method is to set a file from file system
mp1.setDataSource(path);
step3: prepare the mediaplayer for starting
mp1.prepare();

step4: start the playback of the audio

mp1.start();

mp1.resume();    // running state
mp1.pause();    // before stopping
mp1.stop();     // stopping stage
mp1.release();    //destroying state

example:
Context appCon=getApplicationContext();
If the media is from raw:
MediaPlayer mp1=MediaPlayer.create(appCon,Uri.parse("file://sdcard/newfile.mp3));
if the media file is from internet
MediaPlayer url=MediaPlayer.create(appCon,Uri.parse("http://websiteaddress/audio/filename.mp3"));

For Video Player playing
create videoView in xml

Initialize the VideoView in OnCreate()

VideoView vv=(VideoView)findviewById(R.id.videoid);

vv.setKeepScreenOn(true);
vv.setVideoPath("//sdcard/videofile.3gp");
if(vv.canSeekForward())
vv.seekTo(vv.getDuration()/2);
vv.start();
vv.stopPlayBack();









Thursday, September 27, 2012

Services And BroadcastReceivers in Android

Seo Directory List

Activity: it is single screen application. it is a foreground process.it contain user interaction.


Service:

a service is a component which runs in the background without interacting with user.

Android provides many predefined services exposed via Manager class.


Own services must be declared in the manifest file..


Some methods:

An activity can start a service via startService() method.

stop the service by using stopService() method.

bindService() - this is for activity to interact with service.

it needs "ServiceConnection" object.


Once service is started    onCreate()  is called.
onStart()



onBind()- the system calls when other component want to bind the service.

onStop() - for stopping the service.

OnDestroy()- called when service is no longer used. and it is destroyed.

ex:




 MainActivity.java
package com.example.serviceexample;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener {
            Button b1;
            Button b2;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
         b1=(Button)findViewById(R.id.button1);
         b2=(Button)findViewById(R.id.button2);
        b1.setOnClickListener(this);
        b2.setOnClickListener(this);   
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

     public void onClick(View v) {
                        // TODO Auto-generated method stub
                        switch(v.getId())
                        {
                        case R.id.button1:
                                    startService(new Intent(this,ServiceDemo.class));
                                    break;
                        case R.id.button2:
                                    startService(new Intent(this,ServiceDemo.class));
                                   
                        }
            }
}


 ServiceDemo.java
package com.example.serviceexample;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;

public class ServiceDemo extends Service{
     
      MediaPlayer mediaplayer;

      @Override
      public IBinder onBind(Intent arg0) {
            // TODO Auto-generated method stub
            return null;
      }

      @Override
      public void onCreate() {
            // TODO Auto-generated method stub
            super.onCreate();
           
            mediaplayer=MediaPlayer.create(this, R.raw.newsong);
      }

      @Override
      public void onDestroy() {
            // TODO Auto-generated method stub
            super.onDestroy();
            mediaplayer.stop();
      }
      @Override
      public void onStart(Intent intent, int startId) {
            // TODO Auto-generated method stub
            super.onStart(intent, startId);
            mediaplayer.start();
      }
}

Declare manifest permission for service

 <service android:name="ServiceDemo"></service>



you can download source code here

http://www.4shared.com/rar/O39SukJ_/ServiceExample.html?







Own services must be declared in manifest file.

how to declare own service:

<service android:name="your class"></service>
implementing class must extend the class   " service or one of its subclasses.


Ex: AsyncTask:
using services in android allows to have app running in the background. 

 

if u want to do a simple task run in the background, use AsyncTask.

AsyncTask class:


private class someclassname extends AsyncTask<x,y,z>

protected void onPreExecute()
{
// starting new thread i.e    initilizing


protected void doInBackground()

// perform the action or do the task


protected void onPostExecute(){
// closing the process
}



BroadCast Receiver:

It class which extends BroadCastReceiver.  
which is registered in the android app via manifest file.

This class can be able to recieve intents via sendBroadcast()

BroadCast Receiver defines the method  onReceive().  During this method , BroadCast Receiver object will be valid.


ex: 

public class PhoneReceiver extends BroadcastReciever
{

@override
public void onReceive()
{
}
}



Online Training

Your Name :
Your Email: (required)
Your Message: (required)

Powered by Blogger.

Recent Posts

Find Us On Facebook

Popular Posts