• TekArt

    TekArt is an Organisation where people develop Android App through innovative ideas. App for the next Generation....

Sunday 20 April 2014

Posted by Unknown
7 comments | 04:25
Hello guys, today we are going to see how to change the screen with viewflipper and put animation in it. First of all we create the animation files. The animation files reside in the anim folder in the "res" directory.




in_from_left.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false">     <translate         android:fromXDelta="-100%" android:toXDelta="0%"            android:fromYDelta="0%" android:toYDelta="0%"            android:duration="1400" /> </set>

in_from_right.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
    <translate         android:fromXDelta="100%" android:toXDelta="0%"            android:fromYDelta="0%" android:toYDelta="0%"            android:duration="1400" /> </set>

out_to_left.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">       <translate android:fromXDelta="0%" android:toXDelta="-100%"         android:fromYDelta="0%" android:toYDelta="0%"         android:duration="1400"/> </set> 

out_to_right.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">       <translate android:fromXDelta="0%" android:toXDelta="100%"         android:fromYDelta="0%" android:toYDelta="0%"         android:duration="1400"/> </set>
activity_main.xml 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >


        <ViewFlipper
            android:id="@+id/view_flipper"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
             >
           
        <!--  The child Views/Layout to flip -->
       
        <!--  Layout 1 for 1st Screen -->
            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:orientation="vertical" >

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="45dp"
                        android:text="This Is Screen 1"
                        android:textColor="#191975"
                        android:textSize="25dp"
                        android:textStyle="bold" >
                    </TextView>

                    <ImageView
                        
                        android:id="@+id/imageView1"
                        android:layout_width="350dp"
                        android:layout_height="350dp"
                        android:scaleType="fitXY"
                        android:src="@drawable/image1" />
                   
            </LinearLayout>
           
             <!--  Layout 2 for 2nd Screen -->
           
            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:orientation="vertical" >

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="45dp"
                        android:text="This Is Screen 2"
                        android:textColor="#191975"
                        android:textSize="25dp"
                        android:textStyle="bold" >
                    </TextView>

                    <ImageView
                        
                        android:id="@+id/imageView3"
                        android:layout_width="350dp"
                        android:layout_height="350dp"
                        android:scaleType="fitXY"
                        android:src="@drawable/image2" />
                   
            </LinearLayout>
            <!--  Layout 3 for 1st Screen -->
            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:orientation="vertical" >

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="45dp"
                        android:text="This Is Screen 3"
                        android:textColor="#191975"
                        android:textSize="25dp"
                        android:textStyle="bold" >
                    </TextView>

                    <ImageView
                        
                        android:id="@+id/imageView3"
                        android:layout_width="350dp"
                        android:layout_height="350dp"
                        android:scaleType="fitXY"
                        android:src="@drawable/image3" />
                   
            </LinearLayout>
            <!--  Layout 4 for 1st Screen -->
            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:orientation="vertical" >

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="45dp"
                        android:text="This Is Screen 4"
                        android:textColor="#191975"
                        android:textSize="25dp"
                        android:textStyle="bold" >
                    </TextView>

                    <ImageView
                        
                        android:id="@+id/imageView3"
                        android:layout_width="350dp"
                        android:layout_height="350dp"
                        android:scaleType="fitXY"
                        android:src="@drawable/image4" />
                   
            </LinearLayout>


        </ViewFlipper>

</LinearLayout>

MainActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ViewFlipper;

public class MainActivity extends Activity {
    private ViewFlipper viewFlipper;
    private float lastX;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        viewFlipper = (ViewFlipper) findViewById(R.id.view_flipper);
    }

    public boolean onTouchEvent(MotionEvent touchevent) {
        switch (touchevent.getAction()) {

        case MotionEvent.ACTION_DOWN: {
            lastX = touchevent.getX();
            break;
        }
        case MotionEvent.ACTION_UP: {
            float currentX = touchevent.getX();

            if (lastX < currentX) {

                if (viewFlipper.getDisplayedChild() == 0)
                    break;

                viewFlipper.setInAnimation(this, R.anim.in_from_left);
                viewFlipper.setOutAnimation(this, R.anim.out_to_right);
                // Show The Previous Screen
                viewFlipper.showPrevious();
            }

            // if right to left swipe on screen
            if (lastX > currentX) {
                if (viewFlipper.getDisplayedChild() == 3)
                    break;

                viewFlipper.setInAnimation(this, R.anim.in_from_right);
                viewFlipper.setOutAnimation(this, R.anim.out_to_left);
                // Show the next Screen
                viewFlipper.showNext();
            }
            break;
        }
        }
        return false;
    }

}
   
 

Wednesday 16 April 2014

Posted by Unknown
No comments | 23:52
Hello guys, in this tutorial we are going to see how to create a timer and to do something when the timer reaches a particular time. So lets  do it.




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:background="#000000"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/timerValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/pauseButton"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="37dp"
        android:textSize="40sp"
        android:textColor="#ffffff"
        android:text="00:00:000" />

    <Button
        android:id="@+id/startButton"
        android:layout_width="90dp"
        android:layout_height="45dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="38dp"
        android:text="start" />

    <Button
        android:id="@+id/pauseButton"
        android:layout_width="90dp"
        android:layout_height="45dp"
        android:layout_alignBaseline="@+id/startButton"
        android:layout_alignBottom="@+id/startButton"
        android:layout_alignParentRight="true"
        android:layout_marginRight="38dp"
        android:text="pause" />

</RelativeLayout>

MainActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {
    Button start, pause;
    TextView time;
    private long startTime = 0L;

    private Handler customHandler = new Handler();

    long timeInMilliseconds = 0L;
    long timeSwapBuff = 0L;
    long updatedTime = 0L;
    boolean stopTimer = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        start = (Button) findViewById(R.id.startButton);
        pause = (Button) findViewById(R.id.pauseButton);
        time = (TextView) findViewById(R.id.timerValue);
        start.setOnClickListener(this);
        pause.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.startButton:
            startTime = SystemClock.uptimeMillis();
            customHandler.postDelayed(updateTimerThread, 0);
            break;

        case R.id.pauseButton:
            timeSwapBuff += timeInMilliseconds;
            customHandler.removeCallbacks(updateTimerThread);
            break;
        }
    }

    private Runnable updateTimerThread = new Runnable() {

        public void run() {
            timeInMilliseconds = SystemClock.uptimeMillis() - startTime;

            updatedTime = timeSwapBuff + timeInMilliseconds;

            int secs = (int) (updatedTime / 1000);
            int mins = secs / 60;
            secs = secs % 60;
            int milliseconds = (int) (updatedTime % 1000);
            String localtime = "" + mins + ":" + String.format("%02d", secs)
                    + ":" + String.format("%03d", milliseconds);
            time.setText(localtime);
            if (mins == 1) {
                stopTimer = true;
                Toast.makeText(MainActivity.this, "You guys are awesome",
                        Toast.LENGTH_SHORT).show();
            }
            if (!stopTimer)
                customHandler.postDelayed(this, 0);
        }

    };

}

Tuesday 15 April 2014

Posted by Unknown
1 comment | 00:25
Hey guys, in this blog we will see how to record sound in the android. The recorded sound will be saved in the "MediaRecorder" folder in your SD card. Run and test this project on the real device as it wont work on the emulator because emulators dont have mics to record.



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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

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

</RelativeLayout>

MainActivity.java

import java.io.File;
import java.io.IOException;

import android.app.Activity;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener {
    
    MediaRecorder mRecorder;
    String filename="";
    Button record;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        record = (Button) findViewById(R.id.record);
        record.setOnClickListener(this);
    }

    private void record_and_save() {
        // TODO Auto-generated method stub
        
        
        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        
        mRecorder.setAudioEncodingBitRate(64);
        mRecorder.setAudioSamplingRate(48000);
        
        filename = Environment.getExternalStorageDirectory().getAbsolutePath();
        File file = new File(filename,"MediaRecorder");
        if(!file.exists()) file.mkdirs();
        filename = file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".wav";
        
        mRecorder.setOutputFile(filename);
        
        try {
            mRecorder.prepare();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        mRecorder.start();
        
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()) {
        case R.id.record : record_and_save();break;
        }
    }

}

Sunday 13 April 2014

Posted by Unknown
2 comments | 22:48

activity_main.xml

<LinearLayout 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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:orientation="vertical" >
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Low Pitch"
        android:id = "@+id/low"
         />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Normal"
        android:id = "@+id/normal"
         />
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="High"
        android:id = "@+id/high"
        />

</LinearLayout>

MainActivity.java

import android.app.Activity;
import android.media.AudioManager;
import android.media.SoundPool;
import android.media.SoundPool.OnLoadCompleteListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener{
    
    SoundPool sp;
    private Button low, normal, high;
    float pitch = 0.5f;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        low = (Button) findViewById(R.id.low);
        normal = (Button) findViewById(R.id.normal);
        high = (Button) findViewById(R.id.high);
        
        low.setOnClickListener(this);
        normal.setOnClickListener(this);
        high.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()) {
        case R.id.low : pitch = 0.5f;playit();break;
        
        case R.id.normal: pitch = 1.0f;playit();break;
        
        case R.id.high: pitch = 2.0f;playit();break;
        }
        
    }

    private void playit() {
        // TODO Auto-generated method stub
        sp = new SoundPool(1,AudioManager.STREAM_MUSIC,0);
        final int i = sp.load(this, R.raw.music, 0);
        sp.setOnLoadCompleteListener(new OnLoadCompleteListener() {

            @Override
            public void onLoadComplete(SoundPool arg0, int arg1, int arg2) {
                // TODO Auto-generated method stub
                sp.play(i, 1,1,0,0,pitch);    
            }
            
        });
    }
}

Saturday 12 April 2014

Posted by Unknown
No comments | 21:30
Hey Guys, Today we are going to see the usage of SoundPool in Android. So lets get started.




1) First of all create an Android Application Project.

2) Next go to "res/layout/activity_main.xml" and create a  button there.

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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="play"
        android:id = "@+id/play"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />

</RelativeLayout>

3) Now go to "src/your_package_name/MainActivity.java" and the code is here.

import android.app.Activity;
import android.media.SoundPool;
import android.media.SoundPool.OnLoadCompleteListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener{
    
    SoundPool sp;
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        btn = (Button) findViewById(R.id.play);
        btn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()) {
        case R.id.play : playit();break;
        }
        
    }

    private void playit() {
        // TODO Auto-generated method stub
        sp = new SoundPool(1,AudioManager.STREAM_MUSIC,0);
        final int i = sp.load(this, R.raw.music, 0);
        sp.setOnLoadCompleteListener(new OnLoadCompleteListener() {

            @Override
            public void onLoadComplete(SoundPool arg0, int arg1, int arg2) {
                // TODO Auto-generated method stub
                sp.play(i, 1,1,0,0,1.0f);    
            }
            
        });
    }
}












Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you



Friday 11 April 2014

Posted by Unknown
16 comments | 05:07
Hello guys, how are you today? Hope you will all in the best of your life.

Today we are going to see how to connect our android app with mysql databse using php. Just follow the video and post comments if you have any problem.




For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you

Wednesday 9 April 2014

Posted by Unknown
2 comments | 22:12
Hello guys, how are you today? Its super Thursday, and hope you will be in the best of your life.

Today we are going to see how to pass value from one activity to other in Android. So lets get started.



1) First of all create an Android Application Project.

2) Next, go to "res/layout/activity_main.xml" and create one editText and one "send" button there. The code looks like.

activity_main.xml 

<LinearLayout 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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:orientation="vertical" >

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id = "@+id/et" />
    
    <Button 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id = "@+id/send"
        android:text="send"/>

</LinearLayout>

3) Next go to "src/your_package_name/MainActivity.java" and here we are goin to retrieve the value written in the EditText and send the value to the "Second_Activity.java" on clicking the send button. The code looks like the following.

MainActivity.java

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

public class MainActivity extends Activity implements OnClickListener {
    EditText et;
    Button send;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        et = (EditText) findViewById(R.id.et);
        send = (Button) findViewById(R.id.send);

        send.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.send:
            Intent i = new Intent(this, Second_Activity.class);
            i.putExtra("value", et.getText().toString());
            startActivity(i);
            break;
        }
    }

}

4) Now go to "res/layout" and create an Android Xml file there, for our case lets name it "show.xml" .

show.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id = "@+id/tv"
        android:text="Demo text"
        android:textColor="#000000" />
    

</LinearLayout>

5) Next go to "src/your_package_name/Second_Activity.java" and here we are going to retrieve the value send in by MainActivity.java and set the same value  in the TextView.

Second_Activity.java

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class Second_Activity extends Activity {
    TextView tv;
    String word;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.show);
        try{
        word = getIntent().getExtras().getString("value");
        Toast.makeText(this, word, Toast.LENGTH_SHORT).show();
        }catch(Exception e) {
            Toast.makeText(this, "Exception raised", Toast.LENGTH_SHORT).show();
            
        }
        tv = (TextView) findViewById(R.id.tv);
        tv.setText(word);
    
    }

}

Note - Dont forget to declare the activity in AndroidManifest.xml

<activity android:name="com.example.passing_value.Second_Activity" /> 

Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you





Tuesday 8 April 2014

Posted by Unknown
No comments | 23:06
Hello guys, whats up?? Today in this blog we are going to see how to draw graphs in Android. For this purpose we are going to use a library called as "achartengine" . So , lets get started.




1) First of all  create an Android Application Project.

2) Next go to "res/alyout/activity_main.xml" and create a LinearLayout there.

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/label"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

</LinearLayout>

3) Now go to http://www.achartengine.org/content/download.html and download "achartengine" library from there.

4) Right click on the project file in eclipse and go to properties->Java Bild Path-> Libraries-> Export External Jar files and select the downloaded "achartengine" library from there.

5) Now go to "src/your_package_name/MainActivity.java" and paste the following code there.

MainActivity.java

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.*;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.os.Bundle;
import android.app.Activity;
import android.app.Fragment;
import android.graphics.Paint.Align;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

public class MainActivity extends Activity {

    private GraphicalView mChart;
    private XYSeriesRenderer mCurrentRenderer;
    private XYSeriesRenderer mCurrentRenderer1;
    private XYSeriesRenderer mCurrentRenderer2;
    private XYSeries mCurrentSeries;
    private XYSeries mCurrentSeries1;
    private XYSeries mCurrentSeries2;
    private XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset();
    private XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
    private View rootView = null;

    private void addSampleData1() {
        double[] arrayOfDouble = { 20.0D, 30.0D, 67.0D, 80.0D, 85.0D, 94.0D,
                99.0D, 100.0D, 102.0D, 104.0D, 106.0D, 108.0D };
        for (int i = 0;; i++) {
            if (i >= 12) {
                return;
            }
            this.mCurrentSeries.add(i, arrayOfDouble[i]);
        }
    }

    private void addSampleData2() {
        double[] arrayOfDouble = { 30.0D, 55.0D, 80.0D, 90.0D, 91.0D, 100.0D,
                102.0D, 105.0D, 110.0D, 115.0D, 120.0D, 125.0D };
        for (int i = 0;; i++) {
            if (i >= 12) {
                return;
            }
            this.mCurrentSeries1.add(i, arrayOfDouble[i]);
        }
    }

    private void addSampleDatamid() {
        double[] arrayOfDouble = { 25.0D, 50.0D, 75.0D, 85.0D, 87.0D, 99.0D,
                100.0D, 105.0D, 106.0D, 107.0D, 108.0D, 109.0D };
        for (int i = 0;; i++) {
            if (i >= 12) {
                return;
            }
            this.mCurrentSeries2.add(i, arrayOfDouble[i]);
        }
    }

    private void initChart() {
        this.mCurrentSeries = new XYSeries("Min Price");
        this.mCurrentSeries1 = new XYSeries("Max Price");
        this.mCurrentSeries2 = new XYSeries("Predicted Price");
        this.mDataset.addSeries(this.mCurrentSeries);
        this.mDataset.addSeries(this.mCurrentSeries1);
        this.mDataset.addSeries(this.mCurrentSeries2);
        this.mCurrentRenderer = new XYSeriesRenderer();
        this.mCurrentRenderer1 = new XYSeriesRenderer();
        this.mCurrentRenderer2 = new XYSeriesRenderer();
        this.mCurrentRenderer.setColor(-16776961);
        this.mCurrentRenderer1.setColor(-16711936);
        this.mCurrentRenderer2.setColor(-65536);
        this.mCurrentRenderer.setPointStyle(PointStyle.SQUARE);
        this.mCurrentRenderer1.setPointStyle(PointStyle.CIRCLE);
        this.mCurrentRenderer2.setPointStyle(PointStyle.DIAMOND);
        this.mCurrentRenderer.setFillPoints(true);
        this.mCurrentRenderer1.setFillPoints(true);
        this.mCurrentRenderer2.setFillPoints(true);
        this.mRenderer.addSeriesRenderer(this.mCurrentRenderer);
        this.mRenderer.addSeriesRenderer(this.mCurrentRenderer1);
        this.mRenderer.addSeriesRenderer(this.mCurrentRenderer2);
        this.mRenderer.setXTitle("month");
        this.mRenderer.setYTitle("price");
        this.mRenderer.setZoomButtonsVisible(true);
        this.mRenderer.setPointSize(2.0F);
        this.mRenderer.setShowGridX(true);
        String[] arrayOfString = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
        for (int i = 0;; i++) {
            if (i >= arrayOfString.length) {
                this.mRenderer.setXLabels(0);
                this.mRenderer.setXLabelsAlign(Align.CENTER);
                return;
            }
            this.mRenderer.addTextLabel(i, arrayOfString[i]);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    public void onResume() {
        super.onResume();
        LinearLayout localLinearLayout = (LinearLayout) findViewById(R.id.label);
        if (this.mChart == null) {
            initChart();
            addSampleData1();
            addSampleData2();
            addSampleDatamid();
            this.mChart = ChartFactory.getLineChartView(this, this.mDataset,
                    this.mRenderer);
            localLinearLayout.addView(this.mChart);
            return;
        }
        this.mChart.repaint();
    }

} 

Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you
Posted by Unknown
No comments | 05:17
Hello Guys , how are you today? Hope you will be fine.

Have you ever wondered how to write in Hindi or any other language in Android. In this tutorial we are going to see how to develop multilingual android application.



1) First of all, create an Android Application Project.

2) Next go to "res/layout/activity_main.xml" and create a TextView there. The code looks like

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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

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

</RelativeLayout>


3) Now you need to download the font file of the language you wish to use. For our case its hindi, so i downloaded the "Mangal.ttf" file. You can google for your respective font file.

4) After downloading the font file save it in "assets/font/font_file.ttf" .

5) Next go to "src/your_package_name/MainActivity.java" and paste the below code.

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {
    TextView text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        text = (TextView) findViewById(R.id.text);
        Typeface tf = Typeface.createFromAsset(getAssets(), "font/Mangal.ttf");              
        //TextView tv = (TextView) findViewById(R.id.yourtextview);
        text.setTypeface(tf);
        text.setText("यह एक अच्छा एप्लीकेशन है | इ  लव इट |");
    }

}


Note - You can download and use google input tools for converting english to your respective languages. In our case it was Hindi so i used hindi.

Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you

Monday 7 April 2014

Posted by Unknown
No comments | 22:04
Hello Guys, How are you today? Hope you all be fine..

Today we are going to see how to create sidebar or Navigation Drawer in Android.


1)  Go to "res/layout/activity_main.xml" and create Navigation drawer there. The code looks like

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">



<FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />



<ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>
</android.support.v4.widget.DrawerLayout>

2) Create two more Android xml files in the "res/layout" folder . For our case lets name it "drawer_list_item.xml"  and "fragment_planet.xml"  .

drawer_list_item.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:gravity="center_vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:textColor="#fff"
    android:background="?android:attr/activatedBackgroundIndicator"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"/>


fragment_planet.xml

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:gravity="center"
    android:padding="32dp" />

3) In the "res/values/strings.xml" write the following code.

<resources>
    <string name="app_name">Navigation Drawer Example</string>
    <string-array name="planets_array">
        <item>Mercury</item>
        <item>Venus</item>
        <item>Earth</item>
        <item>Mars</item>
        <item>Jupiter</item>
        <item>Saturn</item>
        <item>Uranus</item>
        <item>Neptune</item>
    </string-array>
    <string name="drawer_open">Open navigation drawer</string>
    <string name="drawer_close">Close navigation drawer</string>
    <string name="action_websearch">Web search</string>
    <string name="app_not_available">Sorry, there\'s no web browser available</string>
</resources>

4) Next go to "res/menu/main.xml" .

main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/action_websearch"
          android:icon="@drawable/action_search"
          android:title="@string/action_websearch"
          android:showAsAction="ifRoom|withText" />
</menu>

5) Next go to "src/your_package_name/MainActivity.java" and paste the following code.

import java.util.Locale;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.SearchManager;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;


public class MainActivity extends Activity {
    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;

    private CharSequence mDrawerTitle;
    private CharSequence mTitle;
    private String[] mPlanetTitles;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTitle = mDrawerTitle = getTitle();
        mPlanetTitles = getResources().getStringArray(R.array.planets_array);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);

        // set a custom shadow that overlays the main content when the drawer opens
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
        // set up the drawer's list view with items and click listener
        mDrawerList.setAdapter(new ArrayAdapter<String>(this,
                R.layout.drawer_list_item, mPlanetTitles));
        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

        // enable ActionBar app icon to behave as action to toggle nav drawer
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);

        // ActionBarDrawerToggle ties together the the proper interactions
        // between the sliding drawer and the action bar app icon
        mDrawerToggle = new ActionBarDrawerToggle(
                this,                  /* host Activity */
                mDrawerLayout,         /* DrawerLayout object */
                R.drawable.ic_drawer,  /* nav drawer image to replace 'Up' caret */
                R.string.drawer_open,  /* "open drawer" description for accessibility */
                R.string.drawer_close  /* "close drawer" description for accessibility */
                ) {
            public void onDrawerClosed(View view) {
                getActionBar().setTitle(mTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }

            public void onDrawerOpened(View drawerView) {
                getActionBar().setTitle(mDrawerTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);

        if (savedInstanceState == null) {
            selectItem(0);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
    }

    /* Called whenever we call invalidateOptionsMenu() */
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // If the nav drawer is open, hide action items related to the content view
        boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
        menu.findItem(R.id.action_websearch).setVisible(!drawerOpen);
        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
         // The action bar home/up action should open or close the drawer.
         // ActionBarDrawerToggle will take care of this.
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        // Handle action buttons
        switch(item.getItemId()) {
        case R.id.action_websearch:
            // create intent to perform web search for this planet
            Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
            intent.putExtra(SearchManager.QUERY, getActionBar().getTitle());
            // catch event that there's no activity to handle intent
            if (intent.resolveActivity(getPackageManager()) != null) {
                startActivity(intent);
            } else {
                Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
            }
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

    /* The click listner for ListView in the navigation drawer */
    private class DrawerItemClickListener implements ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    }

    private void selectItem(int position) {
        // update the main content by replacing fragments
        Fragment fragment = new PlanetFragment();
        Bundle args = new Bundle();
        args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
        fragment.setArguments(args);

        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        setTitle(mPlanetTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
    }

    @Override
    public void setTitle(CharSequence title) {
        mTitle = title;
        getActionBar().setTitle(mTitle);
    }

    /**
     * When using the ActionBarDrawerToggle, you must call it during
     * onPostCreate() and onConfigurationChanged()...
     */

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // Pass any configuration change to the drawer toggls
        mDrawerToggle.onConfigurationChanged(newConfig);
    }

    /**
     * Fragment that appears in the "content_frame", shows a planet
     */
    public static class PlanetFragment extends Fragment {
        public static final String ARG_PLANET_NUMBER = "planet_number";

        public PlanetFragment() {
            // Empty constructor required for fragment subclasses
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_planet, container, false);
            int i = getArguments().getInt(ARG_PLANET_NUMBER);
            String planet = getResources().getStringArray(R.array.planets_array)[i];

            int imageId = getResources().getIdentifier(planet.toLowerCase(Locale.getDefault()),
                            "drawable", getActivity().getPackageName());
            ((ImageView) rootView.findViewById(R.id.image)).setImageResource(imageId);
            getActivity().setTitle(planet);
            return rootView;
        }
    }
}

All the image files you can download it from the download link at top of the page which also contains the project file.

Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you

Sunday 6 April 2014

Posted by Unknown
No comments | 22:13
Hello guys, How are you today? I hope you all be in the best of your life.

Today, we are going to see how to show the information in dialog in Android. So , lets get started.



1) First of all, create an Android Application Project.

2) Next go to "res/layout/activity_main.xml" and create a button for which we are going to implement OnClickListener. The code looks like

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click Me"
        android:id="@+id/click" />

</RelativeLayout>

3) Next make an Android xml file in the "res/layout/" folder and create a TextView in there. For our case the name is "show.xml" .

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="You are awesome"
        android:textColor="#ffffff"/>
    

</LinearLayout>

4) Next go to "src/your_package_name/MainActivity.java" and implement OnClickListener for the click button. The code looks like

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

public class MainActivity extends Activity implements OnClickListener {
    Button click;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        click = (Button) findViewById(R.id.click);
        click.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()) {
        case R.id.click : Intent i = new Intent(this, Show.class);
        startActivity(i);
        break;
        }
    }

}

5) Now, we have to create a class "Show.java" in the "src/your_package_name" . In Show.java we are going to display the show.xml.

import android.app.Activity;
import android.os.Bundle;

public class Show extends Activity{
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.show);
        
    
    }

}

6) Now open AndroidManifest,xml and create an Show Activity with the dialog theme.

For our case its like
<activity android:theme="@android:style/Theme.Dialog" android:name="com.example.dialog_blog.Show" />

Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you
Posted by Unknown
2 comments | 00:07
Hello Guys , How are you?? Its Super Sunday, hope you guys enjoying your weekend.

Today we will see how to Play Videos in Android. So lets get started.



1) First of all create an Android Application Project.

2) Go to "res/layout/activity_main.xml" and create a VideoView. The code looks like

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <VideoView  
        android:id="@+id/videoView1"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_alignParentLeft="true"  
        android:layout_centerVertical="true" />  

</RelativeLayout>



3) Next go to "src/your_package_name/MainActivity.java" and create set the MediaController for VideoView.

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        VideoView videoView = (VideoView) findViewById(R.id.videoView1);

        // Creating MediaController
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);

        // specify the location of media file
        Uri uri = Uri.parse("android.resource://com.example.videoplayer_blog/"
                + R.raw.video1);

        // Setting MediaController and URI, then starting the videoView
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(uri);
        videoView.requestFocus();
        videoView.start();
    }

}

Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you