Wednesday, February 29, 2012

Sunday, February 26, 2012

important eclipse shortcut

I have made a list of the most productive and important shortcuts an Android developer could benefit from. Those keywords are the default bindings in Eclipse for Java developer. There are definitely people who would disagree at some point, and I understand, because the list is composed by me and is subjective, depending on developer and hes/her code style.
Shortcuts which I, as an Android developer, find the most effective are:
  • CTRL + 7 = Toggle comment (You can easily comment and uncomment blocks of codes (or singel row) with this shortcut)
  • CTRL + F11 = Run (With this shortcut you can easily run your application without needing to click on the green run icon on menu bar)
  • F11 = Debug (Starts the debugging without the need for a click on the bug icon)
  • CTRL + SHIF + M = Add import (Moving your cursor on the selected item and hiting CTRL + SHIFT + M Eclipse imports the needed libary for you, so you don't have to it manually by typing import libaryName)
  • CTRL+SHIFT+NUMBAD_DEVIDE = Collapse all (Collapses all methods and code blocks which are collapsable. Collapsing has to be enabled in settings. Allows you easily to maintain many rows of code)
  • ALT+SHIFT+R = Refactor (Renames method/variable and all references)
  • ALT+SHIFT+M = Exctract method (Generates method out of the selected/active code block) <-- MY FAVORITE!
  • CTRL+E = Switch tab inside editor window
  • CTRL+F6 = Switch tab inside Eclipse
  • ALT + SHIFT + A, S = Extract Android string to strings.xml file
+ well known shortcuts for any developer like (CTRL +S, CTRL+F, CTRL + C etc.)

Wednesday, February 22, 2012

how changed pressed button color in android

Well, that’s quit simple,just drop these images in a drawable folder of your project and set it as a background of a button. I’ve put all these images in the drawable-hdpi folder. Created a button style in strings.xml like:

<style name="ButtonText">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">#ffffff</item>
        <item name="android:gravity">center</item>
        <item name="android:layout_margin">3dp</item>
        <item name="android:textSize">30dp</item>
        <item name="android:shadowColor">#000000</item>
        <item name="android:shadowDx">1</item>
        <item name="android:shadowDy">1</item>
        <item name="android:shadowRadius">2</item>
        <item name="android:paddingLeft">15dp</item>
        <item name="android:paddingRight">15dp</item>

Thenn, just create a layout with some buttons:

<LinearLayout xmlns:android=""
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    <Button android:text="Button" android:id="@+id/button1" style="@style/ButtonText" android:background="@drawable/btn_army_glossy"></Button>
    <Button android:text="Button" android:id="@+id/button2" style="@style/ButtonText" android:background="@drawable/btn_blue_glossy"></Button>
    <Button android:text="Button" android:id="@+id/button3" style="@style/ButtonText" android:background="@drawable/btn_blue_pink_glossy"></Button>
    <Button android:text="Button" android:id="@+id/button4" style="@style/ButtonText" android:background="@drawable/btn_green_glossy"></Button>
    <Button android:text="Button" android:id="@+id/button5" style="@style/ButtonText" android:background="@drawable/btn_lightblue_glossy"></Button>
    <Button android:text="Button" android:id="@+id/button6" style="@style/ButtonText" android:background="@drawable/btn_pink_glossy"></Button>

Ofcourse it is possible to setup a more rubust environment where a button will have multiple states. Therefore we need a selector file which is just a simple xml file stored in the drawablefolder. Just call it btn_blue_states.xml or something like that. This file will contain state definitions of the buttons:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="">
    <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/button_selected" />
    <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/btn_blue_glossy" />
    <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/btn_blue_pink_glossy" />
    <item android:drawable="@drawable/btn_blue_glossy" />

Tuesday, February 21, 2012

how can get unicode from String in java/android

public class Test
   public static void main(String[] args)
        String str = "Bangladesh";
        System.out.println("String : " + str);
        int uniCodePoint = str.codePointAt(2);
        System.out.println("Character (unicode point) at" + " "
                + "index 3 in given string :" + uniCodePoint);

Monday, February 20, 2012

delete character from String in java or android

public class Test{

    public static void main(String[] args) {

        StringBuilder sb = new StringBuilder();

        sb.append("Java Stringbuilder deleteCharAt");


        System.out.println("StringBuilder :"+sb);

Sunday, February 19, 2012

how can get sin value in java or android

public class Test{ 
   public static void main(String args[]){
     double degrees = 45.0;
     double radians = Math.toRadians(degrees);

     System.out.format("The value of pi is %.4f%n", Math.PI);
     System.out.format("The sine of %.1f degrees is %.4f%n",
                        degrees, Math.sin(radians));