Subscribe to web2feel.com
Subscribe to web2feel.com

Welcome to My Website

ShaTechs... Technology at your reach...
Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

How to create a cocos2d app in android SDK

Posted by shajir Friday, June 17, 2011 3 comments

We can create a simple cocos2d helloWorld app in android sdk simply by follow the steps below. Before that you need eclipse in your system with android sdk.

1. Open eclips and select File-->New-->Android Project,    then you got a window like this


 2. You just name the project and other fields like in the image and hit the finish button. Now your project is in workspace


3. Open your project --> src --> com.shatechs.firstcocos2d and double click on the java file. Now your java file appears on the code window as below.


4.  After that you right click on project folder -->new-->folder and named as libs. Then you download cocos2d-android.jar   and copy to the libs folder.

5.  Then right click on cocos2d-android.jar --> Build Path-->Add to Build Path. Now the jar file is added.

6. Now replace the Activity class with the following code

    CCGLSurfaceView mGLSurfaceView;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     // Hiding the app's title from the screen
        requestWindowFeature(Window.FEATURE_NO_TITLE);
       
        // set the screen flag to full screen
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
       
        // Keeps screen active
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        mGLSurfaceView = new CCGLSurfaceView(this);
       
        // set the view as mGLSurfaceView
        setContentView(mGLSurfaceView);
    }
    @Override
    public void onStart() {
       
        super.onStart();

        // attach the OpenGL view to a window
        CCDirector.sharedDirector().attachInView(mGLSurfaceView);
       
        //Change the device orientation to Portrait
        CCDirector.sharedDirector().setDeviceOrientation(CCDirector.kCCDeviceOrientationLandscapeLeft);
       
        // set false to disable FPS display, but don't forget to put fps_images.png in the assets folder
        CCDirector.sharedDirector().setDisplayFPS(true);
       
        // set frame rate
        CCDirector.sharedDirector().setAnimationInterval(1.0f / 60);
       
        // Create an instance of scene from HelloWorldLayer class
        CCScene scene = HelloWorldLayer.scene();
       
        // Make the Scene active
        CCDirector.sharedDirector().runWithScene(scene);
       
    }

    @Override
    public void onPause() {
        super.onPause();
        CCDirector.sharedDirector().pause();
    }

    @Override
    public void onResume() {
        super.onResume();
        CCDirector.sharedDirector().resume();
    }

    @Override
    public void onStop() {
        super.onStop();
        CCDirector.sharedDirector().end();
    }

 5. After closing the Activity class add the following class by just copy pasting

class HelloWorldLayer extends CCLayer  {
   
    //Gets screen size of the android device
    CGSize s = CCDirector.sharedDirector().winSize();
   
    public static CCScene scene() {
       
        //Creates scene
        CCScene scene = CCScene.node();
       
        //creates an instance of HelloWorldLayer
        CCLayer layer = new HelloWorldLayer();
       
        //adds layer to scene
        scene.addChild(layer);
       
        return scene;
       
    }

    protected HelloWorldLayer() {
       
        CCLabel lab = CCLabel.makeLabel("Hello World", "serif", 40);
        lab.setPosition(240, 160);
        addChild(lab);

    }
}


6. Download the following image and copy to the asset folder

7. You completed your first android cocos2d project just now. Now you can build and run the project


Note: For getting the emulator in landscape mode press Ctrl+F12/F11 .

Audio Jack Modem for iPhone and Android

Posted by shajir Thursday, June 16, 2011 0 comments

This serial modem brought to you by Switch Science allows you to interface an Arduino board with your iPhone or Android smart phone through the audio jack. Now you can integrate your smart phone into your next embedded project. Some software is required on the phone side, and of course there is an Arduino library.




Because the modem and supporting software exploits a connection originally intended for audio, some corruption of the serial data is to be expected from time to time. It's recommended that you keep this in mind when writing your code. See the links below for more information on the board, the Arduino library, and how to implement it.
A standard 3.5mm stereo headphone cable will not work correctly with this board. You must use the special 4-pole cable such as you would find on a wired headset. The audio jack shown does come with the board, but is not soldered to the board.
More Details..

Android SDK architecture

Posted by shajir Friday, June 10, 2011 0 comments

The following diagram shows the major components of the Android operating system. Each section is described in more detail below.


What is android SDK

Posted by shajir 0 comments

Android is a software stack for mobile devices that includes an operating system, middleware and key applications. The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
 
It is a software development kit that enables developers to create applications for the Android platform. The Android SDK includes sample projects with source code, development tools, an emulator, and required libraries to build Android applications. Applications are written using the Java programming language and run on Dalvik, a custom virtual machine designed for embedded use which runs on top of a Linux kernel.

Features

  • Application framework enabling reuse and replacement of components
  • Dalvik virtual machine optimized for mobile devices
  • Integrated browser based on the open source WebKit engine
  • Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional)
  • SQLite for structured data storage
  • Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)
  • GSM Telephony (hardware dependent)
  • Bluetooth, EDGE, 3G, and WiFi (hardware dependent)
  • Camera, GPS, compass, and accelerometer (hardware dependent)
  • Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE

Putting ad from admob on your Android App

Posted by shajir Wednesday, June 8, 2011 0 comments

You can put admob on your android app successfully by following the steps

step1: Register your app in admob and get the publisher id.
step2: Change the AndroidManifest.xml by adding the following lines of code after closing activity
<meta-data android:value="a14d4b7f95df21d" android:name="ADMOB_PUBLISHER_ID" />
                 
         <receiver android:name="com.admob.android.ads.analytics.InstallReceiver" android:exported="true">
                 <intent-filter>
                         <action android:name="com.android.vending.INSTALL_REFERRER" />
                 </intent-filter>
         </receiver>
       
    <meta-data android:value="true" android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" />

step3: Change the publisher id with yours
step4: Add the following lines of code in main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.test"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/layout"
    >
  <com.admob.android.ads.AdView
       android:id="@+id/ad"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"     
       app:backgroundColor="#000000"
       app:primaryTextColor="#FFFFFF"
       app:secondaryTextColor="#CCCCCC"
       app:keywords="Android Game"
    />
</LinearLayout>
step5: create a new xml file and named as attr.xml and place in values folder and change it to
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="com.admob.android.ads.AdView">
        <attr name="backgroundColor" format="color" />
        <attr name="primaryTextColor" format="color" />
        <attr name="secondaryTextColor" format="color" />
        <attr name="keywords" format="string" />
        <attr name="refreshInterval" format="integer" />
    </declare-styleable>
</resources>

step6: Download admob-sdk-android.jar and pasted in libs folder and add to build path
step7: Done!!!
step8: For testing add the following lines code into your java file and run...
AdManager.setTestDevices( new String[] {
AdManager.TEST_EMULATOR, // Android emulator
"E83D20734F72FB3108F104ABC0FFC738", // My T-Mobile G1 Test Phone
} );

We can determine screen resolution of different android devices (phone and tablets) programmatically  in andengine and set camera width and height easily by adding the following code snippet 

public Engine onLoadEngine() {
        WindowManager w = getWindowManager();
        Display d = w.getDefaultDisplay();
        //d.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
        DisplayMetrics metrics = new DisplayMetrics();
        d.getMetrics(metrics);
       
        CAMERA_WIDTH = d.getWidth();
        CAMERA_HEIGHT = d.getHeight();

        final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new                                             RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera));
    }

IOIO for Android

Posted by shajir Saturday, June 4, 2011 0 comments

The IOIO (pronounced "yo-yo") is a board specially designed to work with your Android device (OS versions 1.5 and greater). The board provides extensive and robust connectivity to an Android device via a USB connection. The IOIO is fully controllable from within an Android application, using a simple and intuitive Java API - no embedded programming or external programmer will ever be needed, even for firmware upgrades!


The IOIO (pronounced "yo-yo") is a board specially designed to work with your Android device (OS versions 1.5 and greater). The board provides extensive and robust connectivity to an Android device via a USB connection. The IOIO is fully controllable from within an Android application, using a simple and intuitive Java API - no embedded programming or external programmer will ever be needed, even for firmware upgrades!

Search This Blog