info@thistimebd.com

Wednesday 15th of May 02:05:52am

Country Profile Android app source Code

main_activity.java

------------------

package com.sam.web.countryprofile;


import android.content.DialogInterface;

import android.content.Intent;

import android.support.v7.app.AlertDialog;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;


public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Button bangladesButton, indiaButton, pakistanButton;

    private Intent intent;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);


        bangladesButton=(Button) findViewById(R.id.bangladeshButtonId);

        indiaButton=(Button) findViewById(R.id.indiaButtonId);

        pakistanButton=(Button) findViewById(R.id.pakistanButtonId);


        bangladesButton.setOnClickListener(this);

        indiaButton.setOnClickListener(this);

        pakistanButton.setOnClickListener(this);



    }


    @Override

    public void onClick(View v) {

        if(v.getId()==R.id.bangladeshButtonId){

            intent=new Intent(MainActivity.this,ProfileActivity.class);

            intent.putExtra("name","bangladesh");

            startActivity(intent);



        } if(v.getId()==R.id.indiaButtonId){

            intent=new Intent(MainActivity.this,ProfileActivity.class);

            intent.putExtra("name","india");

            startActivity(intent);



        } if(v.getId()==R.id.pakistanButtonId){

            intent=new Intent(MainActivity.this,ProfileActivity.class);

            intent.putExtra("name","pakistan");

            startActivity(intent);



        }


    }


    @Override

    public void onBackPressed() {

        AlertDialog.Builder alertDialogBuilder;

        alertDialogBuilder=new AlertDialog.Builder(MainActivity.this);

        alertDialogBuilder.setIcon(R.drawable.question);

        alertDialogBuilder.setTitle(R.string.title_text);

        alertDialogBuilder.setMessage(R.string.message_text);

        alertDialogBuilder.setCancelable(false);


        alertDialogBuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

            @Override

            public void onClick(DialogInterface dialog, int which) {

                finish();


            }

        });


        alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {

            @Override

            public void onClick(DialogInterface dialog, int which) {

                dialog.cancel();


            }

        });


        AlertDialog alertDialog=alertDialogBuilder.create();

        alertDialog.show();

    }

}

==================================

activity_main.xml

----------------



<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    android:background="#148e73"

    android:gravity="center"


    tools:context="com.sam.web.countryprofile.MainActivity">


    <Button

        android:id="@+id/bangladeshButtonId"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="@string/bangladesh_button"

        android:textSize="20sp"

        android:textStyle="bold"

        android:drawableLeft="@drawable/bangladesh"

        style="@style/Widget.AppCompat.Button.Colored"

        />

    <Button

        android:id="@+id/indiaButtonId"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="@string/india_button"

        android:textSize="20sp"

        android:textStyle="bold"

        android:drawableLeft="@drawable/india"

        style="@style/Widget.AppCompat.Button.Colored"

        />

    <Button

        android:id="@+id/pakistanButtonId"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="@string/pakistan_button"

        android:textSize="20sp"

        android:textStyle="bold"

        android:drawableLeft="@drawable/pakistan"

        style="@style/Widget.AppCompat.Button.Colored" />


    <AnalogClock

        android:layout_marginBottom="10dp"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" />





</LinearLayout>

==================================================================

string.xml

------------

<resources>


    <string name="app_name">CountryProfile</string>

    <string name="bangladesh_button">Bangladesh</string>

    <string name="india_button">India</string>

    <string name="pakistan_button">Pakistan</string>

    <string name="title_text">This is a title</string>

    <string name="message_text">Do you want to Exit?</string>

    <string name="bangladesh_text">Bangladesh is the east of India bay of Bengal. Bangaldesh is the east of india bay of bengal. banglaesh is the east of india bay of bengal east of india bay of bengal east of india bay of bengal east of india bay of bengal east of india bay of bengal east of india bay of bengal east of india bay of bengal east of india bay of bengal east of india bay of bengal east of india bay of bengal east of india bay of bengal east of india bay of bengal east of india bay of bengal</string>

    <string name="india_text">India is a vast south asian country with diverse terrian country-- from Himalayan peaks to indian ocean with diverse terrian country with diverse terrian country with diverse terrian country with diverse terrian country with diverse terrian country with diverse terrian country</string>

    <string name="pakistan_text">Pakistan officially republic of pakistan, pakistan officially republic of pakistan, pakistan officially republic of pakistan pakistan officially republic of pakistan pakistan officially republic of pakistan pakistan officially republic of pakistan pakistan officially republic of pakistan pakistan officially republic of pakistan</string>

</resources>

====================================================================================

Profile_Activity.java

----------------------


package com.sam.web.countryprofile;


import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.ImageView;

import android.widget.TextView;


public class ProfileActivity extends AppCompatActivity {

    private ImageView imageView;

    private TextView textView;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_profile);


        imageView=findViewById(R.id.imageViewId);

        textView=findViewById(R.id.textViewId);


        Bundle bundle=getIntent().getExtras();

        if(bundle!=null){


            String countryName=bundle.getString("name");

            showDetails(countryName);


        }

    }

    void showDetails(String countryName){


        if(countryName.equals("bangladesh")){

            imageView.setImageResource(R.drawable.bangladeshmap);

            textView.setText(R.string.bangladesh_text);




        } if(countryName.equals("india")){

            imageView.setImageResource(R.drawable.indiamap);

            textView.setText(R.string.bangladesh_text);




        } if(countryName.equals("pakistan")){

            imageView.setImageResource(R.drawable.pakistanmap);

            textView.setText(R.string.pakistan_text);




        }

    }

}

=====================================================

activity_profile.xml

----------------------

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    android:background="#22ffe9"

    android:padding="10dp"

    tools:context="com.sam.web.countryprofile.ProfileActivity">

    <LinearLayout

        android:orientation="vertical"

        android:layout_width="match_parent"

        android:layout_height="match_parent">

    

    <ImageView

        android:scaleType="fitXY"

        android:src="@drawable/bangladeshmap"

        android:id="@+id/imageViewId"

        android:layout_width="match_parent"

        android:layout_height="250dp" />


    <TextView

        android:id="@+id/textViewId"

        android:layout_marginTop="10dp"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:textStyle="bold"

        android:textSize="20sp"

        />

    </LinearLayout>


</ScrollView>