Monday, June 25, 2018

Life Hacks for Daily Use

$*#@%$ ca-app-pub-1137779481600990/5267808203


# You can use Google as a timer by typing "Set timer (x) minutes" into the search bar. 

# Drinking two cups of water before meals can make you lose an average of 4.5 more pounds within 12 weeks than if you don't.


#If you type in any flight number into Google you can see exactly where the plane is.


#11 Stress Relieving Foods -Bananas -Pasta -Almonds -Grapes -Green Tea -Oatmeal -Chocolate -Water melon -Orange Juice -Cornflakes -Tuna

There are a lot of advices when it comes to stopping those annoying hiccups - holding your breath and eating sugar and what not. When you get hiccups, simply bend forwards and drink a glass of water from the other side as demonstrated in the picture. It will cure the hiccups immediately by restricting the spasmodic inhalation characteristics of hiccups.

While traveling abroad, you can use Google Maps as a free GPS without an international data plan. While offline, simply zooming to a map area you want in the maps app, and type “ok maps” into the search box. This data will be available even when you do not have data connectivity.


Replace "YouTube" with "listentoyoutube" in the URL to download the audio of the video.

. Replace "YouTube" with "ssyoutube" in the URL to download the video in any quality available.
. Replace "YouTube" with "nsfwyoutube" to bypass age restriction.
. Replace "YouTube" with "youtubeskip" in the URL and you won't see ads.
. Replace "YouTube" with "listenonrepeat" in the URL to repeat the video automatically.

Wednesday, May 16, 2018

Working with Images In Android


Working with Images



Images are used to make the user interface interactive and more user friendly. Images can be used with almost all the widgets like TextView, EditText, Buttons, ImageButtons etc.
To use the images we need to create a “drawable” folder in “res” folder and put all the images in this “drawable” folder.
Demo App : “Working with Images”


What we will do : We have five images named “one”, “two”, “three”, “four” and “five”.

                                                               


We have five buttons on main screen named  “One”, “Two”, “Three”, “Four” and “Five”.
When clicks on a particular button, we will show the respective image in Image View using  method setImageResource(resourceId);

main_activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
   

   <LinearLayout
    android:layout_marginTop="30dp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
   

    <Button
        android:id="@+id/buttonOne"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="One"
        android:onClick="showOne"/>
    
     <Button
        android:id="@+id/buttonTwo"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Two"
        android:onClick="showTwo" />
    
     <Button
        android:id="@+id/buttonThree"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Three"
        android:onClick="showThree"/>
    
     <Button
        android:id="@+id/buttonFour"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Four"
        android:onClick="showFour" />
    
     <Button
        android:id="@+id/buttonFive"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Five"
        android:onClick="showFive"/>
    
   
    </LinearLayout>
   
    <ImageView
        android:id="@+id/imageView1"
        android:layout_marginTop="50dp"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/one" />
   
</LinearLayout>

MainActivity.java
public class MainActivity extends Activity
{
    ImageView myImageView;
       @Override
       protected void onCreate(Bundle savedInstanceState)
       {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
             
              // get the reference of image view
              myImageView = (ImageView)findViewById(R.id.imageView1);
       }

      
       /* when user clicks on Button "One"
        * set the particular image in myImageView
        */
       public void showOne(View V)
       {
              myImageView.setImageResource(R.drawable.one);
       }
      
       /* when user clicks on Button "Two"
        * set the particular image in myImageView
        */
       public void showTwo(View V)
       {
              myImageView.setImageResource(R.drawable.two);
       }
      
       /* when user clicks on Button "Three"
        * set the particular image in myImageView
        */
       public void showThree(View V)
       {
              myImageView.setImageResource(R.drawable.three);
       }
      
       /* when user clicks on Button "Three"
        * set the particular image in myImageView
        */
       public void showFour(View V)
       {
              myImageView.setImageResource(R.drawable.four);
       }
      
       /* when user clicks on Button "Five"
        * set the particular image in myImageView
        */
       public void showFive(View V)
       {
              myImageView.setImageResource(R.drawable.five);
       }

}




Screenshots
             
     Main Screen(When nothing selected)                           When Button “One” Selected

        
          When Button “Three” Selected                               When Button “Five” Selected

Monday, April 30, 2018

Android Spinner Example


Spinner

Spinner is a widget which provides a quick way to select a value from a set. A spinner presents multiple options/items to the user from which user can select one option.
For ex.  In game application when we want user to select a particular level he/she wants to play, we can use spinner to multiples levels in which can select one level.






Using Spinner

Steps to use spinner in your application
1: Defining the spinner in your .xml/layout file by using “Spinner” tag
<!—Declaring Spinner in xml -->
    <Spinner
        android:id="@+id/spinner"
        android:layout_marginTop="20dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/spinner_title"
    />


2: Create an array/arraylist of strings that will be set as the items of spinner.
String spinnerItems[]={"Level 1","Level 2","Level 3","Level 4","Level 5",};


3: Create adapter and set it with spinner
// Create adapter for spinner
ArrayAdapter  dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, spinnerItems);

// attaching data adapter to spinner
mySpinnerObject.setAdapter(dataAdapter);


4: Set  clicklistener on Spinner
// set clicklistener on Spinner
 mySpinnerObject.setOnItemSelectedListener(this);



5: override  onItemSelected() method, this method gets called by the System when an item is selected. This method receives the position parameter which signifies the index of the array/arraylist which is selected by the user.



@Override
 public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
                         
// get the selected Spinner's Item
            String itemSelected = parent.getItemAtPosition(position).toString();

}

Let put all this together and develop an android application to learn how to use spinner.





Demo Application: “Working with Spinner”

What we will do: We will present a list of levels “Level 1,Level 2,Level 3,Level 4,Level 5" to the user and show the level selected by the user using Toast.


activity_main.xml

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


    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Select the Level"
        android:layout_marginTop="20dp"
        android:textColor="#0000FF"
        android:textSize="20dp"
        android:textStyle="bold"
    />

    <!-- Spinner Element -->
    <Spinner
        android:id="@+id/spinner"
        android:layout_marginTop="20dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />

  </LinearLayout>



SpinnerMainActivity.java

public class SpinnerMainActivity extends Activity implements OnItemSelectedListener
{
     Spinner mySpinner;
      /* create array of string of levels
     * to be set as Spinner Item
     */
    String spinnerItems[]={"Level 1","Level 2","Level 3","Level 4","Level 5",};
   
     @Override
     protected void onCreate(Bundle savedInstanceState)
     {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
         
          // get the Spinner reference
               mySpinner = (Spinner) findViewById(R.id.spinner);
       
               // set clicklistener on Spinner
               mySpinner.setOnItemSelectedListener(this);
       
              // Create adapter for spinner
          ArrayAdapter  dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, spinnerItems);

          // Drop down layout style - list view with radio button
                    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

          // attaching data adapter to spinner
          mySpinner.setAdapter(dataAdapter);
     }

     /* onItemSelected() method gets called by the System
      * when an item is selected
      * This method receives the position parameter
      * which signifies the index of the array
      * which is selected
      */
     @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
        {
           
              // get the selected Spinner's Item
              String itemSelected = parent.getItemAtPosition(position).toString();

              // Showing selected spinner item
              Toast.makeText(getApplicationContext(),  itemSelected+"  Selected", Toast.LENGTH_LONG).show();
          }
      
      
       @Override
          public void onNothingSelected(AdapterView view)
          {
              // TODO Auto-generated method stub
          }

}