Wednesday, April 18, 2012

Custom Toast

custom_toast_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:drawable/picture_frame"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginLeft="5dp"
        android:src="@drawable/inbox" />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:text="Toast text here"
        android:textColor="#000000"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</LinearLayout>


main.xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#454545"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Click here to see custom Toast" />

</RelativeLayout>

In java File


Button mButton1 = (Button) findViewById(R.id.button1);
  mButton1.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.custom_toast_layout,
      (ViewGroup) findViewById(R.id.root));

    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText("Message Sent Succesfully !!");

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.BOTTOM, 10, 80);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();
   }
  });

Multiple Toast 



Toast m_currentToast;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  Button mButton = (Button) findViewById(R.id.button);
  mButton.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    showToast("5");
    showToast("4");
    showToast("3");
    showToast("2");
    showToast("1");
    showToast("Go go go...");

   }
  });

 }

 void showToast(String text) {
  if (m_currentToast != null) {
   m_currentToast.cancel();
  }
  LayoutInflater inflater = getLayoutInflater();
  View layout = inflater.inflate(R.layout.custom_toast_layout,
    (ViewGroup) findViewById(R.id.root));
  TextView text1 = (TextView) layout.findViewById(R.id.text);
  text1.setText(text);

  m_currentToast = new Toast(getApplicationContext());
  m_currentToast.setDuration(Toast.LENGTH_SHORT);
  m_currentToast.setView(layout);
  m_currentToast.setGravity(Gravity.TOP, 10, 180);
  m_currentToast.show();

 }

Saturday, April 7, 2012

Secret Codes For Android Mobile Phones







1. Complete Information About your Phone

*#*#4636#*#*
                                        
This code can be used to get some interesting information about your phone and battery.
Usage statistics


                                              

2. Factory data reset

*#*#7780#*#*
                                            
This code can be used for a factory data reset. It'll remove following things:
Google account settings stored in your phone
System and application data and settings
Downloaded applications

It'll NOT remove:
Current system software and bundled application
SD card files e.g. photos, music files, etc.
Note: Once you give this code, you get a prompt screen asking you to click on "Reset phone" button. So you get a chance to cancel your operation.




3. Format Android Phone
*2767*3855#

Think before you give this code. This code is used for factory format. It'll remove all files and settings including the internal memory storage. It'll also reinstall the phone firmware.

Note: Once you give this code, there is no way to cancel the operation unless you remove the battery from the phone. So think twice before giving this code.




4. Phone Camera Update
*#*#34971539#*#*

This code is used to get information about phone camera. It shows following 4 menus:
Update camera firmware in image (Don't try this option)
Update camera firmware in SD card
Get camera firmware version
Get firmware update count

WARNING: Never use the first option otherwise your phone camera will stop working and you'll need to take your phone to service center to reinstall camera firmware.




5. End Call/Power
*#*#7594#*#*

This one is my favorite one. This code can be used to change the "End Call / Power" button action in your phone. Be default, if you long press the button, it shows a screen asking you to select any option from Silent mode, AirPlane mode and Power off.

You can change this action using this code. You can enable direct power off on this button so you don't need to waste your time in selecting the option.




6. File Copy for Creating Backup

*#*#273283*255*663282*#*#*

This code opens a File copy screen where you can backup your media files e.g. Images, Sound, Video and Voice memo.




7. Service Mode

*#*#197328640#*#*
This code can be used to enter into Service mode. You can run various tests and change settings in the service mode.




8. WLAN, GPS and Bluetooth Test Codes:

*#*#232339#*#* OR *#*#526#*#* OR *#*#528#*#* - WLAN test (Use "Menu" button to start various tests)

*#*#232338#*#* - Shows WiFi MAC address

*#*#1472365#*#* - GPS test

*#*#1575#*#* - Another GPS test

*#*#232331#*#* - Bluetooth test

*#*#232337#*#* - Shows Bluetooth device address




9. Codes to get Firmware version information:

*#*#4986*2650468#*#* - PDA, Phone, H/W, RFCallDate

*#*#1234#*#* - PDA and Phone

*#*#1111#*#* - FTA SW Version

*#*#2222#*#* - FTA HW Version

*#*#44336#*#* - PDA, Phone, CSC, Build Time, Changelist number




10. Codes to launch various Factory Tests:

*#*#0283#*#*
- Packet Loopback

*#*#0*#*#* - LCD test

*#*#0673#*#* OR *#*#0289#*#* - Melody test

*#*#0842#*#* - Device test (Vibration test and BackLight test)

*#*#2663#*#* - Touch screen version

*#*#2664#*#* - Touch screen test

*#*#0588#*#* - Proximity sensor test

*#*#3264#*#* - RAM version

Standard Android Button with a different color




Add this file into drawable folder in res folder 

red_button.xml

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true" >
        <shape>
            <gradient
                android:startColor="#FFFFFF"
                android:endColor="#FFEEEE"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="#454545" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>

    <item android:state_focused="true" >
        <shape>
            <gradient
                android:endColor="#FF0000"
                android:startColor="#AA0000"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="#FFFFFF" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>

    <item>        
        <shape>
            <gradient
                android:endColor="#FF0000"
                android:startColor="#AA0000"
                android:angle="270" />
            <stroke
                android:width="2dp"
                android:color="#454545" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
</selector>

And set background to button like

<Button android:text="Click Me !" android:id="@+id/button1"
  android:background="@drawable/red_button" android:layout_margin="10dp"
  android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>


That's it !!