Payday Loan Payday Loan

Archive for July, 2012

Hi.
Once again, this is Bogdan with another article for androidgenuine.com.

Today I will show you a simple but very usefull thing. I will show you how to start anactivityforresult to the camera and how the taken photo will be transformed into a bitmap a seen on an imageview.

The tutorial is simple and pretty short. I have only one class : ImageCapture.class and an xml file : mylayout.xml (like usual, I am too lazy to change the name of the layout).

Here is the Java code for ImageCapture class:

public class ImageCapture extends Activity implements View.OnClickListener{	
	//The declaration part...
	Button b;
	ImageView iv;
	final static int cameraData = 0;
	Bitmap  bmp;
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mylayout);
		//We call for initialize method
		initialize();
		//We use the inputstream to get the drawable resource
		InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
		bmp = BitmapFactory.decodeStream(is);
	}
	private void initialize() {
		// TODO Auto-generated method stub
		//Stuff with imageview and button, I suppose you know these.
		iv = (ImageView) findViewById(R.id.ivReturnedPic);
		b = (Button) findViewById (R.id.bTakePic);
 
		b.setOnClickListener(this);
	}
	 public void onClick(View v) {
		// TODO Auto-generated method stub
 
		 //Here is the intent that we use to start the Camera
			Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
			//Here we start the activity for result with the unique code "cameraData" and intent i.
			startActivityForResult(i, cameraData);
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		//Check the unique code if it matches with the RESULT_OK
		if (resultCode == RESULT_OK){
			//The bundle where we collect the extras
			Bundle extras = data.getExtras();
			// Here is our bitmap - the photo we'd just taken
			bmp = (Bitmap) extras.get("data");
			//Here we set the bitmap to our imageview
			iv.setImageBitmap(bmp);
		}
	}
 
}

And here is the code for the xml file:

<?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" >
 
    <ImageView
        android:id="@+id/ivReturnedPic"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_gravity="center"
        android:layout_marginTop="20dip"
        android:src="@drawable/ic_launcher" />
 
 
 
    <Button
        android:layout_gravity="center"
        android:id="@+id/bTakePic"
        android:layout_width="150dp"
        android:layout_marginTop="10dip"
        android:layout_height="wrap_content"
        android:text="Take picture" />
 
</LinearLayout>

Here is a picture where you can see how the application looks like :

Like always, you can download the entire project from here.

This was all for this tutorial . I hope you enjoyed it and you’ll read my future articles , too. Until next tutorial, bye !

||||| 0 I Like It! |||||

How to change the volume using a seekbar

Hi.
This is Bogdan with another interesting , I hope, tutorial for http://androidgenuine.com .

Today I will show you how to adjust the sound of the mediaplayer using a seekbar. I guess you have at least one song on your phone to check if the change of volume works but in any case I also put in this project 3 buttons : Start , Pause and Stop ; to control the song I added.
I hope you do not dislike the song so much. Anyway, I like this song so that’s why it is Maroon 5 – Moves Like Jagger.

Ok. The structure is simple :
-I have a class called: ControlVolume.class
-An xml file : mylayout.xml (like usual)
-This is important .Be focused. I created a new folder in type resources (res) called raw where I added the song.

Here is ControlVolume.class:

public class ControlVolume extends Activity implements OnSeekBarChangeListener{   //We neww onseekbarchangelistener so I implemented it
 
	//Here I declare some stuff
 
	private static TextView reading = null;
	AudioManager audioManager;
	  MediaPlayer oSong;
	  int stopped =1 ;
	    @Override
 
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.mylayout); //The layout that we are using
 
	        //Here is a song that I have in a folder that I create in resources.
	        //The name of the folder is raw and there is my song called "melodie"
	        //Actually the song is Maroon 5 - Moves Like Jaggar
			oSong = MediaPlayer.create(ControlVolume.this, R.raw.melodie);
			//Here is the textview that we are using to show to progress : ?%
			reading = (TextView) findViewById(R.id.reading);
	        SeekBar seekBar = (SeekBar) findViewById(R.id.sbSound);
	        //Here we declare the audioManager . We change the volume with it.
	        audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
	        //We need the stream max volume to set the seekbar's maximum with this value
	        int maxV = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
	        //We want that the default progress of the seekbar to be the value that the sound is in that moment.
	        //For example if the sound is 50%  we want the progress of the seekbar to be at the half of it
			int curV = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
			//Here we set the max and progress like I said above.
			seekBar.setMax(maxV);
			seekBar.setProgress(curV);
			//Here we do some maths to find out the percentage of the volume and the seekbar's progress is.
			int x = (int)(curV*(((float)100/15)));
			//We set the default text for our textview
			reading.setText(""+x+"% ");
			//Here we have the 3 buttons : Start,Pause,Stop; for our song.
			Button bStart = (Button) findViewById(R.id.bStart);
			bStart.setOnClickListener(new View.OnClickListener() {
 
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					//I am using the int stopped to know if the song is stopped or paused
 
					if(stopped==1){
						//If it is stopped we need to assign it the song we want again.
					oSong = MediaPlayer.create(ControlVolume.this, R.raw.melodie);
					}
					oSong.start();
 
				}
			});	
			Button bPause = (Button) findViewById(R.id.bPause);
			bPause.setOnClickListener(new View.OnClickListener() {
 
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					oSong.pause();
					//Playing with stopped variable
					stopped=0;
				}
			});	
			Button bStop = (Button) findViewById(R.id.bStop);
			bStop.setOnClickListener(new View.OnClickListener() {
 
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					oSong.stop();
					stopped=1;
				}
			});	
 
 
	   //We set the onseekbarchangelistener
	        seekBar.setOnSeekBarChangeListener(this);
	        }
		public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {
			// TODO Auto-generated method stub
			//We update the textview with actual progress
			int x = (int)(progress*(((float)100/15)));
			reading.setText(""+x+"% ");
			//We update the sound with actual progress of the seekbar
			audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
		}
		public void onStartTrackingTouch(SeekBar arg0) {
			// TODO Auto-generated method stub
 
		}
		public void onStopTrackingTouch(SeekBar arg0) {
			// TODO Auto-generated method stub
 
		}
 
	}

Here is the XML file :

<?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"
    android:padding="20dp">
 
 
    <LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_gravity="center"
    >
 
        <Button
            android:id="@+id/bStart"
            android:layout_width="80dip"
            android:layout_height="wrap_content"
            android:text="Start" />
 
         <Button
            android:id="@+id/bPause"
            android:layout_width="80dip"
            android:layout_height="wrap_content"
            android:text="Pause" />
         <Button
            android:id="@+id/bStop"
            android:layout_width="80dip"
            android:layout_height="wrap_content"
            android:text="Stop" />
 
        </LinearLayout>
    <SeekBar
        android:id="@+id/sbSound"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
 
         />
 
	<TextView 
	    android:id="@+id/reading"
	    android:text="0%"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:textSize="40dp"
	    android:layout_gravity="center"
 
	    />
 
</LinearLayout>

Here is a picture where you can see how the application looks like:

You can download the entire project, like always, from here.

This was all for this tutorial. I hope you understood and liked it. See you with more new and interesting stuff . Bye!

||||| 0 I Like It! |||||

Get contacts’ details in Android.

Hello ! This is Bogdan with another awesome tutorial at www.androidgenuine.com.

Today I will show you how you can get contacts’ name and birthdays . Please notice that we’ll collect these information only from the contacts that are in phone memory, not in the SIM one.

Ok, let’s start. We’ll have only a class : ContactDetails.class and a XML file : mylayout.xml (I was not inspired here, sorry ).
Like always I will explain things using messages in the java code.

Here is the java class :

public class ContactDetails extends Activity{
 
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout); //Set the contentview layout
TextView tvContactDetails = (TextView) findViewById(R.id.tvContactDetails); //Here is our textview
 
Uri uri = ContactsContract.Data.CONTENT_URI; //We need this uri to get Contact Details
 
String[] projection = new String[] { //Here we define the projection, a string where we write what we need to
//take from the contacts
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Event.CONTACT_ID,
ContactsContract.CommonDataKinds.Event.START_DATE
};
 
String where = //here is another string which we will use . Here we put some conditions about the details
//They can't be null and so on. It's a little bit harder this part
ContactsContract.Data.MIMETYPE + "= ? AND " +
ContactsContract.CommonDataKinds.Event.TYPE + "=" + ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY;
String[] selectionArgs = new String[] {ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE};
String sortOrder = null; //sortOrder we want to be null.
//To read all the contact details we need a cursor
//Our cursor is a managedQuery with these properties.
Cursor cursor = managedQuery(uri, projection, where, selectionArgs, sortOrder);
 
//Here is the "while" where the interesting part will happen.
//The clause is cursor.moveToNext, so what is in while will happen until there is no "next" element.
while (cursor.moveToNext()) {
 
//Here we get the two strings we are interested in
 
String displayBirthday = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE));
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
 
//We take only the contacts that have inserted a birthday .
 
if(!displayBirthday.equals("")){
 
// We set the text to the textview.
//We just add the new name and birthday.
String was = tvContactDetails.getText().toString();
tvContactDetails.setText(was + name + " - " +displayBirthday+"\n");
 
}
 
}
}

Here is the xml file(we just have a textview) :

<?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:id="@+id/tvContactDetails"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />
 
</LinearLayout>

Here is a screen capture at this project :

Like always, I give the entire project . You can download it from here .

This is all for this tutorial. I hope you understood it and thank you for reading. See you !

||||| 0 I Like It! |||||

Play a .pls file in Android.

Ok , I suppose most of you know that to listen to a radio station from Shoutcast you need to play a .pls file.
If you download the .pls file on your Android phone and you’ll try to play it you’ll notice that you can’t do that.
So, in this tutorial I’ll teach you how to play a .pls file in an Android application.

Like always, I made a short sample which you’ll be able to download .I’ll explain you step by step by adding comments in the Java code. In this project I created only a class and an XML file.

Ok. Here is the ListenToTheRadio.class :

public class ListenToTheRadio extends Activity{
 
MediaPlayer mp; //We declare the mediaplayer
Button bStart,bPause,bStop; //We declare the buttons we will use
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
 
mp = new MediaPlayer();
 
bStart = (Button) findViewById(R.id.bStart); //findviewbyid for this 3 buttons
bPause = (Button) findViewById(R.id.bPause);
bStop = (Button) findViewById(R.id.bStop);
 
bStart.setOnClickListener(new View.OnClickListener() { //Ok this is the most importat part, be focused !
 
public void onClick(View v) { //This happens when we click the Start button.
// TODO Auto-generated method stub
 
/* Ok, let me explain what this "if" does. The mediaplayer can be stopped or paused. If it is paused with
mp.start(); we can resume it but if it is stopped we need to setDataSource and prepare it again(to get data from the link).
So, I made as when we click the start button , it will unclickable but when you click pause or stop it will be clickable.
If this is foggy for you I think you will understand more as you read the code.
*/
if(bStop.isClickable()){
 
mp.start(); //Here we resume after we pressed the Pause button.
 
}else{
 
try {
mp.setDataSource("http://92.114.63.16:8100/"); //Here we set the source
//As you see, you need to enter the link to the shoutcast radio.
//DO NOT write /listen.pls also, write ONLY the link
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) { //This try and catch we need to put them because if we don't
//will have errors.
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mp.prepare(); //We prepare the mediaplayer to run.
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace(); //Another some boring try and catch clauses.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
mp.start(); //Here we DO NOT resume, we START the MediaPlayer.
 
//Here we set the clickable value for the 3 buttons
bStart.setClickable(false);
bPause.setClickable(true);
bStop.setClickable(true);
}
}
});
 
bPause.setOnClickListener(new View.OnClickListener() {
 
public void onClick(View v) {
// TODO Auto-generated method stub
mp.pause(); //We pause the MediaPlayer
 
//Start button will be clickable, as well as the Stop button but the Pause button will be unclickable
bStart.setClickable(true);
bPause.setClickable(false);
bStop.setClickable(true);
}
});
 
bStop.setOnClickListener(new View.OnClickListener() {
 
public void onClick(View v) {
// TODO Auto-generated method stub
mp.stop(); //Here we stop the MediaPlayer
 
//Another change for the buttons clickable's values.
bStop.setClickable(false);
bPause.setClickable(false);
bStart.setClickable(true);
}
});
 
bPause.setClickable(false);
bStop.setClickable(false); //At first we will be able to click only on the start Button
 
}
}

Here is the mylayout.xml file where we have the three buttons :

<?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="horizontal" >
 
    <Button
        android:id="@+id/bStart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start" />
 
    <Button
        android:id="@+id/bPause"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pause" />
 
    <Button
        android:id="@+id/bStop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Stop" />
 
</LinearLayout>

VERY IMPORTANT !
In your Manifest file please enter the Internet Permission :

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

You can download the entire project from here .

This is all for this tutorial. Thank you for reading and I hope you enjoyed it.

||||| 0 I Like It! |||||

How to create an Adapter for a Listview

Hi, this is my first tutorial here. I hope you’ll enjoy it. Ok, let’s start.

Let’s say that we want to create a Listview more different. We do not want to have only a small text, we want a button , a checkbox etc. in every Listview item. Here is a small tutorial where you can learn how to create an Adapter, the ” thing ” that will help us to personalize the ListView.

Ok, here is a small project where we’ll have:

-two classes : Listview.class (the class where we have  the Listview ) and the ListviewAdapter.class ( the class which cantains the adapter for the Listview, with its help will populate the Listview as we want )

-two XML files : one where is the Listview and one where is the “design ” for each item. I’ve named them listview.xml and listview_row.xml .

I’ve decided to create an Adapter for a Listview whose each item will contain two Textviews , one for Firstname other for Lastname.Here is the content that we’re interested in. I will explain it by adding comments in the Java code.

Listview.class :

public class Listview extends Activity {
 
	//Here are variables which contains the unique "keys", one for  every text in a single Listview row. 
	static final String KEY_FIRSTNAME = "firstname",KEY_LASTNAME="lastname";
 
	//Here are two arrays which contains some "interesting" words. Sorry, I had no inspiration.
	String[] firstname = {"Gates","Cheese","Apple","Computer","Noidea","Something","Bestintheworld"}; 
	String[] lastname = {"Tom","Dan","Andrew","Tyler","Austin","Jane","Bill"};
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview);
 
        //We declare the Listview. I had so much inspiration that I called it - listview .Yes, amazing.
        ListView listview = (ListView) findViewById(R.id.lvGenuine);
 
        //This arraylist stores all the the information that will be in the ListView
        ArrayList<HashMap<String, String>> myArrayList = new ArrayList<HashMap<String, String>>();
 
        //I need this " lenth" for the "for " part.
        int length = firstname.length;
 
 
        //I guess you know what this is.
        for(int i=0;i<length;i++){
 
        	// This hashmap stores the information that exists only in the item. 
        HashMap<String, String> blablabla  = new HashMap<String, String>();
		blablabla.put(KEY_FIRSTNAME, firstname[i]);
		blablabla.put(KEY_LASTNAME, lastname[i]);
 
		//we save the hashmap in the ArrayList . Big thing retains the small one.
		myArrayList.add(blablabla);
 
        }
 
        //We declare the adapter using the other class
        ListviewAdapter adapter = new ListviewAdapter(this,myArrayList);
        //We set the adapter, here is the "place" where we populate the List.
        listview.setAdapter(adapter);
 
    }
}

ListviewAdapter.class:

public class ListviewAdapter extends BaseAdapter {//To create an adapter we have to extend BaseAdapter instead of Activity, or whatever.
 
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
 
 
    public ListviewAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
    }
 
    public int getCount() {   //get the number of elements in the listview
        return data.size();
    }
 
    public Object getItem(int position) {   //this method returns on Object by position
        return position;
    }
 
    public long getItemId(int position) {   //get item id by position
        return position;
    }
 
    public View getView(int position, View convertView, ViewGroup parent) {   //getView method is the method which populates the listview with our personalized rows
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.listview_row, null);       //every item in listview uses xml "listview_row"'s design 
 
        TextView firstname = (TextView)vi.findViewById(R.id.tvFirstname);  //Here are two textviews in the listview_row xml file
        TextView lastname = (TextView)vi.findViewById(R.id.tvLastname);   // You can enter anything you want, buttons, radiobuttons, images, etc.
 
 
 
        HashMap<String, String> hash = new HashMap<String, String>();  //We need a HashMap to store our data for any item
        hash = data.get(position);
 
 
        firstname.setText(hash.get(Listview.KEY_FIRSTNAME));  //We personalize our row's items.
        lastname.setText(hash.get(Listview.KEY_LASTNAME));
 
 
        return vi;
    }
}

listview.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" >
 
    <ListView
        android:id="@+id/lvGenuine"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>
 
</LinearLayout>

and finally listview_row.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:id="@+id/tvFirstname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Firstname"
        android:layout_marginLeft="20dip"
        android:textSize="25dip" />
 
    <TextView
        android:id="@+id/tvLastname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Lastname"
        android:layout_marginLeft="40dip"
        android:textSize="15dip" />
 
</LinearLayout>

Here is a screenshot where you can see how it looks like :

You can download the entire project from here .

I hope you enjoyed the tutorial. I wait any kind of reviews and critics which I promise I will read and will think about them. If you’d like to see any tutorial for Android Development on www.androidgeniune.com you can leave a comment with your wish and I’ll try to help you.

This is all for now. Thank you for reading. See you !

 

||||| 0 I Like It! |||||

Search

Popular

Sponsors