Learn Android for Free,issues for developers, mobengineers website provide complete solutions for developers issues posts.It also provides online training for android development

Monday, February 25, 2013

SurfaceView

android.view.SurfaceView

 SurfaceView class provides dedicated drawing surface.Surface is Zordered. It punches a hole in the window to allow the surface to be displayed. SurfaceView takes care of placing the view at correct place.
getHolder() - Access to the surface is provided through SurfaceHolder interface which can be retrieved by calling getHolder().

Implement SurfaceCreated, SurfaceDestroyed , SurfaceChanged to discover when the surface is created, changed, destroyed.


Here is the example for SurfaceView class

public class Surface


public class SurfaceExample extends SurfaceView
{
public SurfaceExample(Context context, AttributeSet attrSet)
{
super(context, attrSet);
}
}

Download Source code 

 

package com.srinivas.hellomr;

import java.io.IOException;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import android.hardware.Camera;
import android.view.WindowManager;

public class MainActivity extends Activity implements SurfaceHolder.Callback {
    SurfaceHolder mSurfaceHolder;
    SurfaceView mSurfaceView;
    public Camera mCamera;
    boolean mPreviewRunning;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        mSurfaceView = (SurfaceView) findViewById(R.id.surfaceview);
        mSurfaceHolder = mSurfaceView.getHolder();
        mSurfaceHolder.addCallback(this);
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    @Override
    public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
        if (mPreviewRunning) {

            mCamera.stopPreview();
        }
        Camera.Parameters p = mCamera.getParameters();
        mCamera.setParameters(p);
        try {
            mCamera.setPreviewDisplay(arg0);
        } catch (IOException e) {
            e.printStackTrace();
        }
        mCamera.startPreview();
        mPreviewRunning = true;
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        mCamera = Camera.open();
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        mCamera.stopPreview();
        mPreviewRunning = false;
        mCamera.release();
    }

    Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
        public void onPictureTaken(byte[] imageData, Camera c) {

        }
    };
}

 

 activity_main.xml

 <?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" android:id="@+id/layout">

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <SurfaceView
        android:id="@+id/surfaceview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

 



Sunday, February 24, 2013

Forum

Post your query here and get fastest solution

HttpClient post in Android

To post the data to the server, to get the data from the server which is stored in remote database, we can use HttpClient for webservice requests.
 call HttpClient ,
HttpClient  client = new DefaultHttpClient();
Here is the example for HttpClient for posting the data, getting response from the server.

public class MainActivity extends Activity {
    TextView tv;
    String text;
    Button b;
    DefaultHttpClient client; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tv     = (TextView)findViewById(R.id.textView1);
     text     = "";
    }
     public void callWebService(View webService)
    {
      try {
            postData();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
           }
  public void postData() throws JSONException{ 
        // Create a new HttpClient and Post Header
        client = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://192.168.0.1:8080/webservice/latest");        
        JSONObject json= new JSONObject();
           try {
            // JSON data:
                json.put("datapost",subJSON);
         StringEntity entity = new StringEntity(mainJSON.toString(), HTTP.UTF_8);
            httppost.setHeader("Content-Type","application/json");
            httppost.setEntity(entity);
            // Execute HTTP Post Request
            System.out.print(json);
            Log.e("tag", text);
            HttpResponse response = client.execute(httppost,localContext);
                      // for JSON:
            if(response != null)
            {
                InputStream is = response.getEntity().getContent();

                BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                StringBuilder sb = new StringBuilder();

                String line = null;
                try {
                    while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        is.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                text = sb.toString();
            }
            tv.setText(text);
 }catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }
    }

Wednesday, February 20, 2013

Android Developers -Freshers and Experienced




Picon Infotech Pvt Ltd            0-2 yrs            Android developer                   Click here to apply

OKIT Pvt Ltd                               0-2 yrs               Android Developer                    Click here to apply

 Smart Utility Systems           0-1 yr                Android Developer                 Click here to apply

Pennywise software               0-2 yrs               Android Developer                  Click here to apply 

Multiplex Systems Private Limited               Iphone Developer                      Click here to apply

 

 









HP hiring Software developers (freshers)

Qualifications:


Bachelors or Masters degree in Cse, It



Experience:



0-2 yrs


Skills:


Good analytical and problem solving skills.

Good knowledge of design of software applications.

Good communication skills.


Primary Location: 


Bangalore

MAQ hiring software engineers

Job location: Mumbai, Hyderabad

Position: Software Engineer

Experience:  Freshers (0 to 1 yr)

Event date: 09 march 2013

Eligibility:

2012 batch Btech

Graduates with PH score

Job Description:

Web app development using C#, SharePoint, Microsoft SQL Server,

XML Webservices

Business Intelligent app testing


Click here to apply


Dell India hiring freshers

Position:  Software Developer Analysts

Location:  Bangalore

Experience: Freshers

Job Code: 130004QE

Job Description:

To resolve Netcool Change requests
Obtain requirements from clients
delivering commited change requests with all quality.

Click here to apply

Wednesday, February 13, 2013

WebView in Android

WebView is a class which is an extention of View class. Using Webview, we can display webpages in the mobile browser.

To add webview to your application, declare internet permission in manifest file and add WebView to xml.
To load webpage in WebView, use loadUrl

WebView wb=(WebView)findViewById(R.id.webView1);
        wb.loadUrl("http://www.mobengineers.com");
      
You must enable javascript in your webview to load javascript in the page.

To bind interface between Javascript code and android code, then use
        webview.addJavascriptInterface(new WebAppInterface(this), "Android");

To store user data in the browser, we have to use cookies, so that the browser data it does not share.

android.webkit.CookieSyncManager  class to manage all cookies.
To use this, 1st create one instance,
cookieSyncManager.createInstance(context);
setup sync call
to start
cookieSyncManager.getInstance().startSync();
to stop
cookieSyncManager.getInstance().stopSync();
to get sync instantly,

cookieSyncManager.getInstance().Sync();

sample webview example here

package com.example.demo1;

public class MainActivity extends Activity {

    public class WebAppInterface { Context mContext;

    WebAppInterface(Context c) {
        mContext = c;
    }


    public void showToast(String toast) {
        Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
    }

}

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        WebView wb=(WebView)findViewById(R.id.webView1);
        wb.loadUrl("http://www.mobengineers.com");
        WebSettings ws=wb.getSettings();
        ws.setJavaScriptEnabled(true);
       // wb.addJavascriptInterface(new WebAppInterface(this), "Android");
        wb.setWebViewClient(new WebViewClient());
       
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (Uri.parse(url).getHost().equals("www.getnicejobs.com")) {
                return false;
            }
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }


}
}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

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

</RelativeLayout>







Monday, February 11, 2013

Java Developers Jobs

Java Developers in MNC

experience: 2 yrs
 email your resumes to
karuna@sancrosoftusa.com



for more jobs apply here
http://www.sancrosoftusa.com/jobopenings.html

SancroSoft USA inc
4944 Sunrise Blvd, Suite B-4, Fair Oaks,
CA 95628,
Phone: 718-360-4561













InteractCRM  hiring Java Professionals

Job Dec:


Work in product devel team to build  Contact Center Solutions for our clients.
Deliver work  using OOAD methodologies , provide technical insights to the team.
Design, coding & testing of Modules and components assigned.


Desired Profile:




3 - 4 years hands on Java / J2EE & web services develop exp.
 exposure to all software development life cycle.
 analytical, logical & communication skills. email ur resumes to:
careers@interactcrm.com

Friday, February 8, 2013

Loaders in Android

Loaders providing Asynchronous loading data into an activity or fragment.When the data changes, it automatically update the new results.It automatically reconnect last loader when its recreated. So, no need to re query.

Starting the Loader:

we can initilize loader in onCreate() method.

getLoaderManager().initLoader(0,null, this);


initLoader takes the following parameters

unique id. In the above unique id is 0.
argument to supply to loader at construct (optional).
LoaderManager.LoaderCallbacks

LoaderManager calls to report loader events.

Thursday, February 7, 2013

Internal Flow of Threads or Thread Model

    whenever we write multi threading application, it contains multiple flow of controls.
All the flow controls follow the sequence steps at execution time.


Java programs starts execution by loading .class file

JVM creates a background thread and will reside in main.

Background thread creates various foreground threads and dispatches to their run to execute and result back to background and will handover to garbage.
Background thread gives back to program.
JVM collects background thread and will handover to Garbage collector.
Java program stops its execution.

Monday, February 4, 2013

Difference between StartActivityForResult, startActivity

Many of them  have confution about startActivity and startActivityForResult() methods.
startActivity() is to start another activity
StartActivityForResult() is to receive a result. The activity has to return a result.
When it returns a result, it sends as another intent object and activity recives result in onActivityResult() and here we can handle.
We need to pass an integer arg to startActivityForResult() method. So that request code will identifies the request.
When you get the result intent, callback provides the same request code to identify the result.

see this example:
  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, 1);
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1){           
        }       


Sunday, February 3, 2013

Tabs like with ActionBar


 TabActivity is depreciated  in Api 13. Tabs are presented in latest versions with ActionBar.
ActionBar.newTab().

So, prefer to not to use depreciated classes and methods. So use latest classes and methods.

Here is the simple example of creating Tab like activity using fragments.



 MobEngineersActivity.java

package com.srinivas.mobengineers;

import android.app.ActionBar;
import android.app.Activity;
import android.app.ActionBar.Tab;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Context;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.os.Bundle;
import android.widget.Toast;


public class MobEngineersActivity extends Activity {
    public static Context appContext;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        appContext = getApplicationContext();

 
        ActionBar actionbar = getActionBar();       // initilize actionBar
        actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);     // set navigation mode
       
        ActionBar.Tab Category1Tab = actionbar.newTab().setText("FOOD");
        ActionBar.Tab Category2Tab = actionbar.newTab().setText("BEVERAGES");
       
        Fragment FoodFragment = new FoodFragment();
        Fragment BeveragesFragment = new BeveragesFragment();
       CategoryTab.setTabListener(new MyTabsListener(FoodFragment));
      BeveragesTab.setTabListener(new MyTabsListener(BeveragesFragment));

        actionbar.addTab(FoodTab);
        actionbar.addTab(BeveragesTab);
    }
Food.java

public class FoodFragment extends Fragment {
   
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.afragment, container, false);
    }
  }

Beverages.java
public class FoodFragment extends Fragment {
   
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.afragment, container, false);
    }
  }

 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
    <LinearLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

 </LinearLayout>
</LinearLayout>



20% off

Online Training

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

NDTV Gadgets360

Powered by Blogger.

Recent Posts

Find Us On Facebook

Popular Posts