Sunday, September 15, 2013


Xfce Desktop

Xfce is a lightweight desktop environment system for linux, and is a good alternative to the complex and clumsy gnome.

In this post I am going to show you how to install xfce on debian. It is available in the debian default repositories and can be installed right away.
# apt-get install xfce4
This will install the xfce desktop with all the necessary applications. The download size is around 20.4 MB and should finish in a few minutes on a fast broadband connection.
Along with the main xfce4 package you can also install additional useful applications by installing the package named xfce4-goodies.
# sudo apt-get install xfce4-goodies
If you want to install all the application of the xfce desktop suite then use the following command instead
# apt-get install xfce4-*
It will install a lot more applications. The download size is around 99MB and would take more time to complete.
So choose the right one for your needs.

Customise Xfce

After installing the XFCE desktop, you would want to customise the look and feel of it, to make it better. The default looks of any desktop are nothing great as such.

Get better themes

I personally find the greybird and bluebird themes to be great looking when it comes to xfce and lxde. On ubuntu they are present in the default repositories. However on debian we have to add the ubuntu ppa repository to get them.
Its easy, just run the following commands
# add-apt-repository 'deb http://ppa.launchpad.net/shimmerproject/ppa/ubuntu quantal main'
# apt-get update
# aptitude search shimmer
p   shimmer-themes-greybird         - Greybird Theme from the Shimmer Project
# apt-get install shimmer-themes-greybird
Now go to
Applications Menu > Settings > Appearance
And from the style tab, select greybird theme.
Also switch to a better font like Droid Sans. Enable anti aliasing with full hinting and RGB subpixel order. Now that should make your fonts look a great deal better.

Speed up the user interface

This is a simple trick that will speed up the menu display in xfce desktop. By default when you move the mouse over applications menu and and any sub menu under it, the sub menus appear after a short of few milliseconds. This delay can be removed to make the menus appear instantly making the user interface look very fast.


Xfce Desktop

Xfce is a lightweight desktop environment system for linux, and is a good alternative to the complex and clumsy gnome.

In this post I am going to show you how to install xfce on debian. It is available in the debian default repositories and can be installed right away.
# apt-get install xfce4
This will install the xfce desktop with all the necessary applications. The download size is around 20.4 MB and should finish in a few minutes on a fast broadband connection.
Along with the main xfce4 package you can also install additional useful applications by installing the package named xfce4-goodies.
# sudo apt-get install xfce4-goodies
If you want to install all the application of the xfce desktop suite then use the following command instead
# apt-get install xfce4-*
It will install a lot more applications. The download size is around 99MB and would take more time to complete.
So choose the right one for your needs.

Customise Xfce

After installing the XFCE desktop, you would want to customise the look and feel of it, to make it better. The default looks of any desktop are nothing great as such.

Get better themes

I personally find the greybird and bluebird themes to be great looking when it comes to xfce and lxde. On ubuntu they are present in the default repositories. However on debian we have to add the ubuntu ppa repository to get them.
Its easy, just run the following commands
# add-apt-repository 'deb http://ppa.launchpad.net/shimmerproject/ppa/ubuntu quantal main'
# apt-get update
# aptitude search shimmer
p   shimmer-themes-greybird         - Greybird Theme from the Shimmer Project
# apt-get install shimmer-themes-greybird
Now go to
Applications Menu > Settings > Appearance
And from the style tab, select greybird theme.
Also switch to a better font like Droid Sans. Enable anti aliasing with full hinting and RGB subpixel order. Now that should make your fonts look a great deal better.

Speed up the user interface

This is a simple trick that will speed up the menu display in xfce desktop. By default when you move the mouse over applications menu and and any sub menu under it, the sub menus appear after a short of few milliseconds. This delay can be removed to make the menus appear instantly making the user interface look very fast.









For this you need to install x-window-system-core,kde,gnome

Install KDE in debian

#apt-get install x-window-system-core kde

You'll probably also want to install KDM, for the KDE-style login screen.

#apt-get install kdm

 

Starting KDE

To start KDE, type

#startkde

you may need to start X-Server if it is not running, to start it run

#startx

To start KDE each time (you probably want this) you'll need to edit your startup files. If you use KDM or XDM to log in, edit .xsession, otherwise edit .xinitrc or .Xclients.

Install Gnome in Debian

#apt-get install gnome

This will install additional software (gnome-office, evolution) that you may or may not want.

Custom


For a smaller set of apps, you can also do

 # aptitude install gnome-desktop-environment

A set of additional productivity apps will be installed by

 # aptitude install gnome-fifth-toe

Developers

If you need development packages, e.g. for compiling GNOME dependent packages from source, you should try

 # aptitude install gnome-core-devel

For a full set of developer tools, please do

 # aptitude install gnome-devel

The install procedure will as you the details of your video card, keyboard and mouse. Some hints

- PS/2 mice are attached to /dev/psaux.

- USB mice are usually attached to /dev/input/mouse0

- Be sure to select the correct video driver. If you select an inappropriate one, X won't start. If you are not sure which driver to use, ask here.

- If you are completely helpless, use the 'vesa' driver. It should work on any card.

- Other than the things listed above, you can accept the default answers, but be sure to actually read what the installer ask; the default maybe isn't what you want.

After you done, you have two options.

The first one is to edit the ~/.xinitrc file, and write the 'exec startkde' or 'exec gnome-session' lines to it, depending on what you want to start. After this, if you issue the 'startx' command, a GUI will hopefully start.

The second option is to install a login manager, which is probably the more convenient choice, and is good for most people. Simply install the kdm or the gdm package (the former is KDE's login manager, the latter is of Gnome). No matter which one you choose, you can always choose your GUI upon login, if you installed both KDE and Gnome.










For this you need to install x-window-system-core,kde,gnome

Install KDE in debian

#apt-get install x-window-system-core kde

You'll probably also want to install KDM, for the KDE-style login screen.

#apt-get install kdm

 

Starting KDE

To start KDE, type

#startkde

you may need to start X-Server if it is not running, to start it run

#startx

To start KDE each time (you probably want this) you'll need to edit your startup files. If you use KDM or XDM to log in, edit .xsession, otherwise edit .xinitrc or .Xclients.

Install Gnome in Debian

#apt-get install gnome

This will install additional software (gnome-office, evolution) that you may or may not want.

Custom


For a smaller set of apps, you can also do

 # aptitude install gnome-desktop-environment

A set of additional productivity apps will be installed by

 # aptitude install gnome-fifth-toe

Developers

If you need development packages, e.g. for compiling GNOME dependent packages from source, you should try

 # aptitude install gnome-core-devel

For a full set of developer tools, please do

 # aptitude install gnome-devel

The install procedure will as you the details of your video card, keyboard and mouse. Some hints

- PS/2 mice are attached to /dev/psaux.

- USB mice are usually attached to /dev/input/mouse0

- Be sure to select the correct video driver. If you select an inappropriate one, X won't start. If you are not sure which driver to use, ask here.

- If you are completely helpless, use the 'vesa' driver. It should work on any card.

- Other than the things listed above, you can accept the default answers, but be sure to actually read what the installer ask; the default maybe isn't what you want.

After you done, you have two options.

The first one is to edit the ~/.xinitrc file, and write the 'exec startkde' or 'exec gnome-session' lines to it, depending on what you want to start. After this, if you issue the 'startx' command, a GUI will hopefully start.

The second option is to install a login manager, which is probably the more convenient choice, and is good for most people. Simply install the kdm or the gdm package (the former is KDE's login manager, the latter is of Gnome). No matter which one you choose, you can always choose your GUI upon login, if you installed both KDE and Gnome.


Thursday, April 18, 2013

bisa dibilang program ini adalah program kalkulator, karena fungsinya adalah untuk menghitung, sama seperti kalkulator yang sering kita temui, asalkan kita tau rumus n cara menghitungnya aja, kalo gak tau ya sama aja bhong…hehe, mendingan pkek program ni aja.
1. langkah pertama isi file strings.xml di res --> values --> strings.xml
strings.xml

<resources>;
    <string name="app_name">;BMICalculator</string>;
    <string name="menu_settings">;Settings</string>;
    <string name="title_activity_main">;BMI Calculator</string>;
    
    <string name="satu">   BMI < 18.5           --> Badan kurang Ideal</string>;
    <string name="dua">   BMI 18.5 - 22.9  --> Berat badan Ideal</string>;
    <string name="tiga">   BMI 23 - 24.9      --> Mendekati Obesitas</string>;
    <string name="empat">   BMI 25 - 29.9      --> Diambang batas Obesitas</string>;
    <string name="lime">   BMI >; 30              --> Melebihi Obesitas</string>;

    <color name="Kuning">#a2b314</color>;
    <color name="merah">#990000</color>;
    <color name="MerahOrange">#d25e09</color>

    <color name="hijau">#1fb314</color>
    <color name="birumuda">#14a6b3</color>
    <color name="hitam">#000000</color>
    <color name="putih">#ffffff</color>


    <string name="InputTinggibadan">Inputkan Tinggi Badan (cm)</string>
    <string name="InputBeratBadan">Inputkan Berat Badan (kg)</string>
   
    <string name="errorButton_hitung">OK</string>
    <string name="errorTitle_hitung">Error !</string>
    <string name="errorMessage_hitung">Data kurang lengkap !</string>
    <string name="errorButton_hasil">OK</string>
    <string name="errorTitle_hasil">Error !</string>
    <string name="errorMessage_hasil">hasil masik kosong</string>
</resources>

2. langkah kedua, buat 3 file xml yang akan jadi interface di program kita, dan letakkan di res --> layout :
   1. splashe.xml
   2. main.xml
   3. hasil.xml
1. splashe.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:background="@drawable/ww"
    android:orientation="vertical" >
</LinearLayout>

2. main.xml



    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/hitam" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tinggi Badan ( cm )"
            android:textColor="@color/putih" />

        <EditText
            android:id="@+id/tinggi_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/InputTinggibadan"
            android:inputType="numberDecimal" >

            <requestFocus />
        </EditText>

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Berat Badan ( kg )"
            android:textColor="@color/putih" />

        <EditText
            android:id="@+id/berat_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/InputBeratBadan"
            android:inputType="number|numberDecimal" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:id="@+id/btn_hitung"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hitung" />

        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/textView7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hasil "
            android:textColor="@color/putih" />

        <EditText
            android:id="@+id/hasil_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10" />

        <TextView
            android:id="@+id/textView8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:id="@+id/btn_lihathasil"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Lihat Hasil" />

    </TableLayout>
3. hasil.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:layout_gravity="center"
    android:background="@color/hitam"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/kosong1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Skala BMI"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/putih" />

    <FrameLayout
        android:id="@+id/abang"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="@color/merah" >

        <TextView
            android:id="@+id/textView05"
            android:layout_width="305dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="@string/lime"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

    <FrameLayout
        android:id="@+id/orange"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="@color/MerahOrange" >

        <TextView
            android:id="@+id/textView04"
            android:layout_width="306dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="@string/empat"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

    <FrameLayout
        android:id="@+id/semuijo"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="@color/Kuning" >

        <TextView
            android:id="@+id/textView03"
            android:layout_width="306dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="@string/tiga"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

    <FrameLayout
        android:id="@+id/ijo"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="@color/hijau" >

        <TextView
            android:id="@+id/textView02"
            android:layout_width="306dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="@string/dua"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

    <FrameLayout
        android:id="@+id/biru"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="@color/birumuda" >

        <TextView
            android:id="@+id/TextView01"
            android:layout_width="305dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="@string/satu"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

    <TextView
        android:id="@+id/TextView04"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall" />


    <TextView
        android:id="@+id/TextView03"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Berat badan anda termasuk"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/putih" />


    <FrameLayout
        android:id="@+id/abang1"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_gravity="center"
        android:background="@color/merah" >

        <TextView
            android:id="@+id/hasilakhir"
            android:layout_width="306dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

    <TextView
        android:id="@+id/TextView07"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <FrameLayout
        android:id="@+id/abang2"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_weight="0.88"
        android:background="@color/merah" >

        <TextView
            android:id="@+id/keterangan"
            android:layout_width="305dp"
            android:layout_height="125dp"
            android:layout_gravity="center_vertical|center_horizontal"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

</LinearLayout>

Langkah ketiga, buat 3 class.java di folder src --> package kamu :
    1. Splash.java
    2. Main.java
    3. Hasilnyaa.java
1. Class Splash.java

public class Splash extends Activity{
    protected int _splashTime = 5000;
    private Thread splashTread;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashe);
        final Splash sPlashScreen = this;
        // thread for displaying the SplashScreen
        splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    synchronized(this){
                            //wait 5 sec
                            wait(_splashTime);
                    }
                } catch(InterruptedException e) {}
                finally {
                    finish();
                    //start a new activity
                    Intent i = new Intent();
                    i.setClass(sPlashScreen, Main.class);
                            startActivity(i);
                    stop();
                }
            }
        };
        splashTread.start();
    }
    //Function that will handle the touch
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            synchronized(splashTread){
                    splashTread.notifyAll();
            }
        }
        return true;
    }

}
2. Class Main.java

public class Main extends Activity {
                public static final String statusnya="";
                private EditText tinggi_e;
                private EditText berat_e;
                private EditText hasil_e;
                private Button but_hit;
                private Button but_has;
                private double BMI;
                private double tinggi;
                private double berat;
                private int status;
               
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        tinggi_e=(EditText) findViewById(R.id.tinggi_id);
        berat_e=(EditText) findViewById(R.id.berat_id);
        hasil_e=(EditText) findViewById(R.id.hasil_id);
        but_hit=(Button) findViewById(R.id.btn_hitung);
        but_has=(Button) findViewById(R.id.btn_lihathasil);
       
        but_hit.setOnClickListener(hitung);
       
        but_has.setOnClickListener(hasile);
    }
    OnClickListener hitung=new OnClickListener() {
                               
                                public void onClick(View v) {
                                                if(tinggi_e.getText().length()==0 && berat_e.getText().length()==0){
                AlertDialog.Builder alert = new AlertDialog.Builder(Main.this);
                alert.setTitle(R.string.errorTitle_hitung);
                alert.setMessage(R.string.errorMessage_hitung);
                alert.setPositiveButton(R.string.errorButton_hitung, null);
                alert.show();
                     }else{
                        tinggi=Double.parseDouble(tinggi_e.getText().toString())/100;
                        berat=Double.parseDouble(berat_e.getText().toString());
                        BMI = (berat / (tinggi * tinggi));
                         hasil_e.setText(String.valueOf(BMI));
                                                               
                      if(BMI >= 30){
                           status=5;
                      }else if(BMI >= 25 &&BMI <=29.9){
                          status=4;
                      }else if(BMI >= 23 && BMI <=24.9){
                            status=3;
                      }else if(BMI >= 18.5 && BMI <=22.9){
                          status=2;
                      }else if(BMI < 18.5){
                           status=1;
                      }else{
                             status=0;
                      } }}};
               
    OnClickListener hasile=new OnClickListener() {
                               
                                public void onClick(View v) {
                                                if(hasil_e.getText().length()==0){
                AlertDialog.Builder alert = new AlertDialog.Builder(Main.this);
                alert.setTitle(R.string.errorTitle_hasil);
                alert.setMessage(R.string.errorMessage_hasil);
                alert.setPositiveButton(R.string.errorButton_hasil, null);
                alert.show();
                                                }else{
                                          Intent viewCon = new Intent(Main.this, Hasilnyaa.class);
                                          viewCon.putExtra(statusnya, status);
                                          startActivity(viewCon);
                      }                                             
              }
        };           
}
3. Class Hasilnyaa.java

public class Hasilnyaa extends Activity{
      
       private int id;
       private FrameLayout frame1;
       private FrameLayout frame2;
       private TextView hasile;
       private TextView kandani;
       public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.hasil);
              
         frame1=(FrameLayout) findViewById(R.id.abang1);
         frame2=(FrameLayout) findViewById(R.id.abang2);
              
         hasile=(TextView) findViewById(R.id.hasilakhir);
         kandani=(TextView) findViewById(R.id.keterangan);
         Bundle oleh=getIntent().getExtras();
         id=oleh.getInt(Main.statusnya);
              
    if(id==1){
         frame1.setBackgroundResource(R.color.birumuda);
         frame2.setBackgroundResource(R.color.birumuda);
         hasile.setText(R.string.satu);
         kandani.setText("Badan kamu kurus, Disarankan kamu untuk banyak makan dan olah raga ");
                    
    }else if(id==2){
         frame1.setBackgroundResource(R.color.hijau);
         frame2.setBackgroundResource(R.color.hijau);
         hasile.setText(R.string.dua);
         kandani.setText("Badan kamu ideal, tetapi tetap jaga pola makan dan olah raga secukupnya");
     }else if(id==3){
         frame1.setBackgroundResource(R.color.Kuning);
         frame2.setBackgroundResource(R.color.Kuning);
         hasile.setText(R.string.tiga);
         kandani.setText("Berat badan kamu masih tergolong normal-ideal mendekati obesitas, kamu perlu memperbaiki pola makan dan perbanyak olahraga");
      }else if(id==4){
         frame1.setBackgroundResource(R.color.MerahOrange);
         frame2.setBackgroundResource(R.color.MerahOrange);
         hasile.setText(R.string.empat);
         kandani.setText("Berat badan anda diambang batas obesitas, kondisi bahaya, segera ubah kebiasaan makan /kembali ke gaya hidup sehat");
       }else if(id==5){
         frame1.setBackgroundResource(R.color.merah);
         frame2.setBackgroundResource(R.color.merah);
         hasile.setText(R.string.lime);
         kandani.setText("Waduhh parah nie sob...!! berdoa aja moga2 gak cepet mati !");
       }else{
         frame1.setBackgroundResource(R.color.putih);
         frame2.setBackgroundResource(R.color.putih);
         hasile.setText("error");
               }
        }
}
4. langkah terakhir, kita rubah sedikit file AndroidManifest.xml
AndroidManifest.xml


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="okin.example.bmicalculator"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Splash"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="Main"></activity>
        <activity android:name="Hasilnyaa"></activity>
    </application>

</manifest>

Note : yang berwarna hijau adalah sourcode hasil penambahan atau perubahan

Siiippp program siap dijalankan jangan lupa di build and clean dulu mas Sob.. and coba jalankan.
Klik kanan project --> Run as --> 1. Android Application
Tampilan Splash Screennya.
Saya coba masukkan berat badan dan tinggi badan saya.. kamudian klik hitung akan keluar hasilnya di EditText "Hasil" kemudian klik tombol "Lihat hasil" maka akan keluar form baru yang akan memberi tahu Kondisi berat badan kamu.
 
Alhamdulillah, berat badan saya termasuk ideal sob hehe, jangan iri yaa hehe...
aku tambahin lagi nie buat seru seruan, jika hasil perhitungan berat badan kamu melebihi batas, lebih dari atau sama dengan 30.


Jika menemukan kesuliatan saat pengerjaan programnya donlot aja sourcecodenya di link ini

source : http://lubertopunya.blogspot.com/2012/12/setelah-memposting-program-android.html

bisa dibilang program ini adalah program kalkulator, karena fungsinya adalah untuk menghitung, sama seperti kalkulator yang sering kita temui, asalkan kita tau rumus n cara menghitungnya aja, kalo gak tau ya sama aja bhong…hehe, mendingan pkek program ni aja.
1. langkah pertama isi file strings.xml di res --> values --> strings.xml
strings.xml

<resources>;
    <string name="app_name">;BMICalculator</string>;
    <string name="menu_settings">;Settings</string>;
    <string name="title_activity_main">;BMI Calculator</string>;
    
    <string name="satu">   BMI < 18.5           --> Badan kurang Ideal</string>;
    <string name="dua">   BMI 18.5 - 22.9  --> Berat badan Ideal</string>;
    <string name="tiga">   BMI 23 - 24.9      --> Mendekati Obesitas</string>;
    <string name="empat">   BMI 25 - 29.9      --> Diambang batas Obesitas</string>;
    <string name="lime">   BMI >; 30              --> Melebihi Obesitas</string>;

    <color name="Kuning">#a2b314</color>;
    <color name="merah">#990000</color>;
    <color name="MerahOrange">#d25e09</color>

    <color name="hijau">#1fb314</color>
    <color name="birumuda">#14a6b3</color>
    <color name="hitam">#000000</color>
    <color name="putih">#ffffff</color>


    <string name="InputTinggibadan">Inputkan Tinggi Badan (cm)</string>
    <string name="InputBeratBadan">Inputkan Berat Badan (kg)</string>
   
    <string name="errorButton_hitung">OK</string>
    <string name="errorTitle_hitung">Error !</string>
    <string name="errorMessage_hitung">Data kurang lengkap !</string>
    <string name="errorButton_hasil">OK</string>
    <string name="errorTitle_hasil">Error !</string>
    <string name="errorMessage_hasil">hasil masik kosong</string>
</resources>

2. langkah kedua, buat 3 file xml yang akan jadi interface di program kita, dan letakkan di res --> layout :
   1. splashe.xml
   2. main.xml
   3. hasil.xml
1. splashe.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:background="@drawable/ww"
    android:orientation="vertical" >
</LinearLayout>

2. main.xml



    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/hitam" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tinggi Badan ( cm )"
            android:textColor="@color/putih" />

        <EditText
            android:id="@+id/tinggi_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/InputTinggibadan"
            android:inputType="numberDecimal" >

            <requestFocus />
        </EditText>

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Berat Badan ( kg )"
            android:textColor="@color/putih" />

        <EditText
            android:id="@+id/berat_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/InputBeratBadan"
            android:inputType="number|numberDecimal" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:id="@+id/btn_hitung"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hitung" />

        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/textView7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hasil "
            android:textColor="@color/putih" />

        <EditText
            android:id="@+id/hasil_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10" />

        <TextView
            android:id="@+id/textView8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:id="@+id/btn_lihathasil"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Lihat Hasil" />

    </TableLayout>
3. hasil.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:layout_gravity="center"
    android:background="@color/hitam"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/kosong1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Skala BMI"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@color/putih" />

    <FrameLayout
        android:id="@+id/abang"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="@color/merah" >

        <TextView
            android:id="@+id/textView05"
            android:layout_width="305dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="@string/lime"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

    <FrameLayout
        android:id="@+id/orange"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="@color/MerahOrange" >

        <TextView
            android:id="@+id/textView04"
            android:layout_width="306dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="@string/empat"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

    <FrameLayout
        android:id="@+id/semuijo"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="@color/Kuning" >

        <TextView
            android:id="@+id/textView03"
            android:layout_width="306dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="@string/tiga"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

    <FrameLayout
        android:id="@+id/ijo"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="@color/hijau" >

        <TextView
            android:id="@+id/textView02"
            android:layout_width="306dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="@string/dua"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

    <FrameLayout
        android:id="@+id/biru"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="@color/birumuda" >

        <TextView
            android:id="@+id/TextView01"
            android:layout_width="305dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="@string/satu"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

    <TextView
        android:id="@+id/TextView04"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall" />


    <TextView
        android:id="@+id/TextView03"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Berat badan anda termasuk"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/putih" />


    <FrameLayout
        android:id="@+id/abang1"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_gravity="center"
        android:background="@color/merah" >

        <TextView
            android:id="@+id/hasilakhir"
            android:layout_width="306dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

    <TextView
        android:id="@+id/TextView07"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <FrameLayout
        android:id="@+id/abang2"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_weight="0.88"
        android:background="@color/merah" >

        <TextView
            android:id="@+id/keterangan"
            android:layout_width="305dp"
            android:layout_height="125dp"
            android:layout_gravity="center_vertical|center_horizontal"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/putih" />

    </FrameLayout>

</LinearLayout>

Langkah ketiga, buat 3 class.java di folder src --> package kamu :
    1. Splash.java
    2. Main.java
    3. Hasilnyaa.java
1. Class Splash.java

public class Splash extends Activity{
    protected int _splashTime = 5000;
    private Thread splashTread;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashe);
        final Splash sPlashScreen = this;
        // thread for displaying the SplashScreen
        splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    synchronized(this){
                            //wait 5 sec
                            wait(_splashTime);
                    }
                } catch(InterruptedException e) {}
                finally {
                    finish();
                    //start a new activity
                    Intent i = new Intent();
                    i.setClass(sPlashScreen, Main.class);
                            startActivity(i);
                    stop();
                }
            }
        };
        splashTread.start();
    }
    //Function that will handle the touch
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            synchronized(splashTread){
                    splashTread.notifyAll();
            }
        }
        return true;
    }

}
2. Class Main.java

public class Main extends Activity {
                public static final String statusnya="";
                private EditText tinggi_e;
                private EditText berat_e;
                private EditText hasil_e;
                private Button but_hit;
                private Button but_has;
                private double BMI;
                private double tinggi;
                private double berat;
                private int status;
               
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        tinggi_e=(EditText) findViewById(R.id.tinggi_id);
        berat_e=(EditText) findViewById(R.id.berat_id);
        hasil_e=(EditText) findViewById(R.id.hasil_id);
        but_hit=(Button) findViewById(R.id.btn_hitung);
        but_has=(Button) findViewById(R.id.btn_lihathasil);
       
        but_hit.setOnClickListener(hitung);
       
        but_has.setOnClickListener(hasile);
    }
    OnClickListener hitung=new OnClickListener() {
                               
                                public void onClick(View v) {
                                                if(tinggi_e.getText().length()==0 && berat_e.getText().length()==0){
                AlertDialog.Builder alert = new AlertDialog.Builder(Main.this);
                alert.setTitle(R.string.errorTitle_hitung);
                alert.setMessage(R.string.errorMessage_hitung);
                alert.setPositiveButton(R.string.errorButton_hitung, null);
                alert.show();
                     }else{
                        tinggi=Double.parseDouble(tinggi_e.getText().toString())/100;
                        berat=Double.parseDouble(berat_e.getText().toString());
                        BMI = (berat / (tinggi * tinggi));
                         hasil_e.setText(String.valueOf(BMI));
                                                               
                      if(BMI >= 30){
                           status=5;
                      }else if(BMI >= 25 &&BMI <=29.9){
                          status=4;
                      }else if(BMI >= 23 && BMI <=24.9){
                            status=3;
                      }else if(BMI >= 18.5 && BMI <=22.9){
                          status=2;
                      }else if(BMI < 18.5){
                           status=1;
                      }else{
                             status=0;
                      } }}};
               
    OnClickListener hasile=new OnClickListener() {
                               
                                public void onClick(View v) {
                                                if(hasil_e.getText().length()==0){
                AlertDialog.Builder alert = new AlertDialog.Builder(Main.this);
                alert.setTitle(R.string.errorTitle_hasil);
                alert.setMessage(R.string.errorMessage_hasil);
                alert.setPositiveButton(R.string.errorButton_hasil, null);
                alert.show();
                                                }else{
                                          Intent viewCon = new Intent(Main.this, Hasilnyaa.class);
                                          viewCon.putExtra(statusnya, status);
                                          startActivity(viewCon);
                      }                                             
              }
        };           
}
3. Class Hasilnyaa.java

public class Hasilnyaa extends Activity{
      
       private int id;
       private FrameLayout frame1;
       private FrameLayout frame2;
       private TextView hasile;
       private TextView kandani;
       public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.hasil);
              
         frame1=(FrameLayout) findViewById(R.id.abang1);
         frame2=(FrameLayout) findViewById(R.id.abang2);
              
         hasile=(TextView) findViewById(R.id.hasilakhir);
         kandani=(TextView) findViewById(R.id.keterangan);
         Bundle oleh=getIntent().getExtras();
         id=oleh.getInt(Main.statusnya);
              
    if(id==1){
         frame1.setBackgroundResource(R.color.birumuda);
         frame2.setBackgroundResource(R.color.birumuda);
         hasile.setText(R.string.satu);
         kandani.setText("Badan kamu kurus, Disarankan kamu untuk banyak makan dan olah raga ");
                    
    }else if(id==2){
         frame1.setBackgroundResource(R.color.hijau);
         frame2.setBackgroundResource(R.color.hijau);
         hasile.setText(R.string.dua);
         kandani.setText("Badan kamu ideal, tetapi tetap jaga pola makan dan olah raga secukupnya");
     }else if(id==3){
         frame1.setBackgroundResource(R.color.Kuning);
         frame2.setBackgroundResource(R.color.Kuning);
         hasile.setText(R.string.tiga);
         kandani.setText("Berat badan kamu masih tergolong normal-ideal mendekati obesitas, kamu perlu memperbaiki pola makan dan perbanyak olahraga");
      }else if(id==4){
         frame1.setBackgroundResource(R.color.MerahOrange);
         frame2.setBackgroundResource(R.color.MerahOrange);
         hasile.setText(R.string.empat);
         kandani.setText("Berat badan anda diambang batas obesitas, kondisi bahaya, segera ubah kebiasaan makan /kembali ke gaya hidup sehat");
       }else if(id==5){
         frame1.setBackgroundResource(R.color.merah);
         frame2.setBackgroundResource(R.color.merah);
         hasile.setText(R.string.lime);
         kandani.setText("Waduhh parah nie sob...!! berdoa aja moga2 gak cepet mati !");
       }else{
         frame1.setBackgroundResource(R.color.putih);
         frame2.setBackgroundResource(R.color.putih);
         hasile.setText("error");
               }
        }
}
4. langkah terakhir, kita rubah sedikit file AndroidManifest.xml
AndroidManifest.xml


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="okin.example.bmicalculator"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Splash"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="Main"></activity>
        <activity android:name="Hasilnyaa"></activity>
    </application>

</manifest>

Note : yang berwarna hijau adalah sourcode hasil penambahan atau perubahan

Siiippp program siap dijalankan jangan lupa di build and clean dulu mas Sob.. and coba jalankan.
Klik kanan project --> Run as --> 1. Android Application
Tampilan Splash Screennya.
Saya coba masukkan berat badan dan tinggi badan saya.. kamudian klik hitung akan keluar hasilnya di EditText "Hasil" kemudian klik tombol "Lihat hasil" maka akan keluar form baru yang akan memberi tahu Kondisi berat badan kamu.
 
Alhamdulillah, berat badan saya termasuk ideal sob hehe, jangan iri yaa hehe...
aku tambahin lagi nie buat seru seruan, jika hasil perhitungan berat badan kamu melebihi batas, lebih dari atau sama dengan 30.


Jika menemukan kesuliatan saat pengerjaan programnya donlot aja sourcecodenya di link ini

source : http://lubertopunya.blogspot.com/2012/12/setelah-memposting-program-android.html