Friday 25 September 2015

Display Current Location on Map

Hello Guys,

Here I am going to explain about Display Current Location on Map.

NOTE: Please run sample code into your device only.

For that you must have to create a api key with your sha-1 key.

Very first you need to install keytool in your eclipse. For installing keytool follow Step 1.

Step 1: Go to Help --> Install New Software --> Add --> Enter keytool in Name and Enter http://keytool.sourceforge.net/update in Location --> Ok --> Select All --> Next --> Click on Accept radio button --> Finish.

Once Keytool is installed successfully then you will get one alert for restart your eclipse. You must Restart your eclipse.

Create SHA-1 key for your project. Follow Step 2.

Step 2:  C:\Program Files\Java\jdk1.8.0_45\bin>keytool.exe -v -list -alias androiddebugkey -keystore "c:\Users\admin\.android\debug.keystore" -storepass android -keypass android

You have to add your keytool's path instead of "c:\Users\admin\.android\debug.keystore". Rest of the things are same.

Once SHA-1 key is generated copy it from your notpad file for further use.

Now turn for create an api key.

Step 3: Create Google Map API Key using Google Developer Console.

Open following link into your browser.
Link: https://developers.google.com/maps/documentation/android/start

This link is provide whole documentation.

Open https://console.developers.google.com link into your browser and login with your gmail account.

After login with your gmail account you will get below window.




















In same window when you click on Select a project drop down, you will get Create a project option.
Click on Create a project option. You can change your project name.

I give a project name like DisplayCurrentLocation.



















Once your project is created successfully you will get following window.




















From above window you must have to select Google Maps Android API option. Then Click on Enable button. When your api is enabled then you will get following window.




















Then after click on Learn more option in same window and you will get new window.




















Now click on GET A KEY button you will get new window again.


















Click on Continue and you will get a window for create a api key.




















Click on Continue.



























When you click on create you will get your API Key.













This key is used into your app.

Output:


























I am sharing my Sample Code with you.

Download Full Source Code From Here: DisplayCurrentLocation

Happy Coding...!!!






Tab Activity With Swipe Gesture

Hello Guys,

Today I share an example of Tab implementation with Swipe Gesture.

All of you very well aware of Tabs. Because you see multiple tabs in many applications. Same way you can create different tabs into your application.

Using Swipe Gesture you can scroll your screen horizontally mean while your tabs are also changed.

Here I provide you sample code for it.

Sample Code:

File: MainActivity.java

package com.sneha.tabsswipe;

import com.sneha.tabsswipe.adapter.TabsPagerAdapter;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;

public class MainActivity extends FragmentActivity implements ActionBar.TabListener
{
private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;

        // Tab titles
private String[] tabs = { "Top Rated", "Games", "Movies" };

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

// Initilization
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getActionBar();
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

viewPager.setAdapter(mAdapter);
actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

// Adding Tabs
for (String tab_name : tabs)
{
actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this));
}

/**
* on swiping the viewpager make respective tab selected
* */
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener()
{
@Override
public void onPageSelected(int position)
{
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}

@Override
public void onPageScrolled(int arg0, float arg1, int arg2)
{
}

@Override
public void onPageScrollStateChanged(int arg0)
{
}
});
}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft)
{
}

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft)
{
// on tab selected
// show respected fragment view
viewPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft)
{
}
}

File: TabsPagerAdapter.java

package com.sneha.tabsswipe.adapter;

import com.sneha.tabsswipe.GamesFragment;
import com.sneha.tabsswipe.MoviesFragment;
import com.sneha.tabsswipe.TopRatedFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class TabsPagerAdapter extends FragmentPagerAdapter
{
public TabsPagerAdapter(FragmentManager fm)
{
super(fm);
}

@Override
public Fragment getItem(int index)
{
switch (index)
{
case 0:
// Top Rated fragment activity
return new TopRatedFragment();
case 1:
// Games fragment activity
return new GamesFragment();
case 2:
// Movies fragment activity
return new MoviesFragment();
}
return null;
}

@Override
public int getCount()
{
// get item count - equal to number of tabs
return 3;
}
}

File: TopRatedFragment.java

package com.sneha.tabsswipe;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class TopRatedFragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle                                 savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_top_rated, container, false);

return rootView;
}
}

File: GamesFragment.java

package com.sneha.tabsswipe;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class GamesFragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle                                 savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_games, container, false);

return rootView;
}
}

File: MoviesFragment.java

package com.sneha.tabsswipe;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class MoviesFragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle                                 savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_movies, container, false);

return rootView;
}
}

Output:












































































Download Full Source Code From Here: TabActivity

Happy Coding...!!!

Thursday 24 September 2015

Sliding Menu In Android

Hello Friends,

Today I explain about Menu in android app.

Menu is basically used to display some features in app as options which are accessible fast from any screen. There are 2 types of  Menu.

i) Option Menu
ii) Sliding Menu

Option Menu: Option menu is simple display on top right corner or bottom of the screen same like our device.

Sliding Menu: Sliding menu is display the required options using left to right slide or right to left slide. You can create this menu same like Facebook, Google+ and rest od the applications which have similar kind of menu.

Both types are easy to implement in your android apps.

Here I provide you full source code of Sliding Menu implementation in Android Apps.

You can see the output here.

Output:












































































Download Full Source Code From Here: SlidingMenu

Happy Coding...!!!

  

Xml Parsing Using SAX Parser

Hello Friends,

Today I explain about Xml Parsing in android app.

Xml Parsing is used for parse the data from server and display into our applications. There are 3 types of  Parsers available in Xml.

i) DOM Parser
ii) Sax Parser
iii) XmlPull Parser

DOM Parser: DOM paser means Document Object Module. DOM parser is parsing the data faster if xml is small. If you have to parse large amount of data from xml then it needs more memory and due to need more memory sometimes you will get Out of Memory error. DOM Parser is parsing whole document using xml.

DOM parser have more chances that it will take a long time or even may not be able to load it completely simply because it requires lot of memory to create XML Dom Tree

Sax Parser: Sax Parser means Simple Api For Xml Parsing. This parser is an event based XML Parsing and it parse XML file step by step. SAX XML parser is used for parsing large xml files in Java because it doesn't require to load whole XML file in Java and it can read a big XML file in small parts.

XmlPull Parser: Android recommends to use XMLPullParser to parse the xml file compare to SAX and DOM because it is fast. XmlPull Parser is parsing data from xml using its Start Tag, Text and End Tag.

Here I provide a full code for Sax Parser.

Output:



























Download Full Source Code From Here: XmlParsing

Happy Coding...!!!

Monday 7 September 2015

Android Animations

Hello Guys,

Today I share how to implement Animations in Android Apps.

There are many kinds of animations used in Android Apps. In my example, I have
used following animations.

1) Blink
2) Bounce
3) Crossfade
4) FadeIn
5) FadeOut
6) Move
7) Rotate
8) Sequential
9) SlideDown
10) SlideUp
11) Together
12) ZoonIn
13) ZoomOut

For viewing these effects you need to see the code.

Here I provide you sample code for Animations.

Sample Code:

File: MainActivity.java

package com.sneha.androidanimations;

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

public class MainActivity extends Activity
{
Button btnFadeIn, btnFadeOut, btnCrossFade, btnBlink, btnZoomIn,
btnZoomOut, btnRotate, btnMove, btnSlideUp, btnSlideDown,
btnBounce, btnSequential, btnTogether;

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

btnFadeIn = (Button) findViewById(R.id.btnFadeIn);
btnFadeOut = (Button) findViewById(R.id.btnFadeOut);
btnCrossFade = (Button) findViewById(R.id.btnCrossFade);
btnBlink = (Button) findViewById(R.id.btnBlink);
btnZoomIn = (Button) findViewById(R.id.btnZoomIn);
btnZoomOut = (Button) findViewById(R.id.btnZoomOut);
btnRotate = (Button) findViewById(R.id.btnRotate);
btnMove = (Button) findViewById(R.id.btnMove);
btnSlideUp = (Button) findViewById(R.id.btnSlideUp);
btnSlideDown = (Button) findViewById(R.id.btnSlideDown);
btnBounce = (Button) findViewById(R.id.btnBounce);
btnSequential = (Button) findViewById(R.id.btnSequential);
btnTogether = (Button) findViewById(R.id.btnTogether);

/*
* Buttons click events
*/

// fade in
btnFadeIn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, FadeInActivity.class);
startActivity(i);
}
});

// fade out
btnFadeOut.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, FadeOutActivity.class);
startActivity(i);
}
});

// cross fade
btnCrossFade.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, CrossfadeActivity.class);
startActivity(i);
}
});

// blink
btnBlink.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, BlinkActivity.class);
startActivity(i);
}
});

// Zoom In
btnZoomIn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, ZoomInActivity.class);
startActivity(i);
}
});

// Zoom Out
btnZoomOut.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, ZoomOutActivity.class);
startActivity(i);
}
});

// Rotate
btnRotate.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, RotateActivity.class);
startActivity(i);
}
});

// Move
btnMove.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) 
{
Intent i = new Intent(MainActivity.this, MoveActivity.class);
startActivity(i);
}
});

// Slide Up
btnSlideUp.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, SlideUpActivity.class);
startActivity(i);
}
});

// Slide Down
btnSlideDown.setOnClickListener(new View.OnClickListener() 
{
@Override
public void onClick(View v) 
{
Intent i = new Intent(MainActivity.this, SlideDownActivity.class);
startActivity(i);
}
});

// Slide Down
btnBounce.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, BounceActivity.class);
startActivity(i);
}
});

// Sequential
btnSequential.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) 
{
Intent i = new Intent(MainActivity.this, SequentialActivity.class);
startActivity(i);
}
});

// Together
btnTogether.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, TogetherActivity.class);
startActivity(i);
}
});
}
}

Output:

MainActivity Screen:


























Blink Animation:


























Bounce Animation:


























Fade-In Animation:


























Fade-Out Animation:


























For rest of the code you need to download full example using below link.

Download Full Source Code From Here: Animations

Happy Coding...!!!

Video Streaming

Hello Guys,

Today I share Video Streaming implementation in android apps with you.

I already explained the meaning of streaming in my previous post Audio Streaming.
If anybody need to know again then refer my previous post.

All of you know that when you play any video in youtube player then its done buffering some part for few minutes then play, again buffering some part and play.

This process is going till the end of video.

Here I provide you sample code for Video Streaming which is fully done buffering first
then play continuously.

Permission:  <uses-permission android:name="android.permission.INTERNET"/>

NOTE: YOU MUST NEED TO TEST THIS DEMO APP INTO YOUR DEVICE ONLY.

Sample Code:

File: MainActivity.java

package com.sneha.videostreamtutorial;

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

public class MainActivity extends Activity 
{
Button button;

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

button = (Button) findViewById(R.id.MyButton);

button.setOnClickListener(new OnClickListener() 
{
public void onClick(View arg0) 
{
Intent myIntent = new Intent(MainActivity.this, VideoViewActivity.class);
startActivity(myIntent);
}
});
}
}
   
File: VideoViewActivity.java

package com.sneha.videostreamtutorial;

import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.util.Log;
import android.view.Window;
import android.widget.MediaController;
import android.widget.VideoView;

public class VideoViewActivity extends Activity 
{
ProgressDialog pDialog;
VideoView videoview;

// Insert your Video URL

String VideoURL = "https://ia700401.us.archive.org/19/items /                                                               ksnn_compilation_master_the_internet/ ksnn_compilation_master_the_internet_512kb.mp4";

@Override
protected void onCreate(Bundle savedInstanceState) 
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.videoview_main);

videoview = (VideoView) findViewById(R.id.VideoView);

pDialog = new ProgressDialog(VideoViewActivity.this);
pDialog.setTitle("Android Video Streaming Tutorial");
pDialog.setMessage("Buffering...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();

try 
{
// Start the MediaController
MediaController mediacontroller = new MediaController(VideoViewActivity.this);
mediacontroller.setAnchorView(videoview);

// Get the URL from String VideoURL
Uri video = Uri.parse(VideoURL);
videoview.setMediaController(mediacontroller);
videoview.setVideoURI(video);

}
catch (Exception e) 
{
Log.e("Error", e.getMessage());
e.printStackTrace();
}

videoview.requestFocus();
videoview.setOnPreparedListener(new OnPreparedListener() 
{
public void onPrepared(MediaPlayer mp) 
{
pDialog.dismiss();
videoview.start();
}
});
}
}


Output:











































































Download Full Source Code From Here: VideoStreaming

Happy Coding...!!!