0% found this document useful (0 votes)
9 views7 pages

Phone Dialer

The document outlines the layout and functionality of a dialer application for Android, including XML layout for the user interface and Java code for the main activity. It features buttons for digits, call, save, and delete functionalities, allowing users to input phone numbers and initiate calls or save contacts. The manifest file specifies permissions and application settings necessary for the app's operation.

Uploaded by

jocox65721
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

Phone Dialer

The document outlines the layout and functionality of a dialer application for Android, including XML layout for the user interface and Java code for the main activity. It features buttons for digits, call, save, and delete functionalities, allowing users to input phone numbers and initiate calls or save contacts. The manifest file specifies permissions and application settings necessary for the app's operation.

Uploaded by

jocox65721
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

<?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:gravity="center"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dailer"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:id="@+id/txt_display"
/>

<Button
android:layout_width="80dp"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:id="@+id/btn_del"
android:text="del" />

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="30dp"
android:gravity="fill_horizontal">

<Button
android:layout_width="63dp"
android:layout_height="60dp"
android:layout_marginRight="20dp"
android:id="@+id/btn_one"
android:text="1" />

<Button
android:layout_width="63dp"
android:layout_height="60dp"
android:layout_marginRight="20dp"
android:id="@+id/btn_two"
android:text="2" />
<Button
android:layout_width="63dp"
android:layout_height="60dp"
android:id="@+id/btn_three"
android:text="3" />

</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="30dp"
android:gravity="fill_horizontal">

<Button
android:layout_width="63dp"
android:layout_height="60dp"
android:layout_marginRight="20dp"
android:id="@+id/btn_four"
android:text="4" />

<Button
android:layout_width="63dp"
android:layout_height="60dp"
android:layout_marginRight="20dp"
android:id="@+id/btn_five"
android:text="5" />

<Button
android:layout_width="63dp"
android:layout_height="60dp"
android:text="6"
android:id="@+id/btn_six"/>

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="30dp"
android:gravity="fill_horizontal">

<Button
android:layout_width="63dp"
android:layout_height="60dp"
android:layout_marginRight="20dp"
android:id="@+id/btn_seven"
android:text="7" />

<Button
android:layout_width="63dp"
android:layout_height="60dp"
android:layout_marginRight="20dp"
android:id="@+id/btn_eight"
android:text="8" />

<Button
android:layout_width="63dp"
android:layout_height="60dp"
android:id="@+id/btn_nine"
android:text="9" />
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="30dp"
android:gravity="fill_horizontal">

<Button
android:layout_width="63dp"
android:layout_height="60dp"
android:layout_marginRight="20dp"
android:id="@+id/btn_star"
android:text="*" />

<Button
android:layout_width="63dp"
android:layout_height="60dp"
android:layout_marginRight="20dp"
android:id="@+id/btn_zero"
android:text="0" />

<Button
android:layout_width="63dp"
android:layout_height="60dp"
android:id="@+id/btn_ash"
android:text="#" />

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="30dp"
android:gravity="fill_horizontal">

<Button
android:layout_width="80dp"
android:layout_height="60dp"
android:layout_marginRight="20dp"
android:id="@+id/btn_call"
android:text="Call" />

<Button
android:layout_width="80dp"
android:layout_height="60dp"
android:layout_marginRight="20dp"
android:id="@+id/btn_save"
android:text="Save" />

</LinearLayout>

</LinearLayout>
package com.example.callerapp;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import
android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener {
EditText txtNumber;
Button
btnOne, btnTwo, btnThree, btnFour, btnFive, btnSix, btnSeven,
btnEight, btnNine, btnZero, btnCall,
btnSave, btnDel, btnStar, btnHash;

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtNumber = (EditText) findViewById(R.id.txt_display);
btnOne = (Button) findViewById(R.id.btn_one);
btnOne.setOnClickListener(this);
btnTwo = (Button) findViewById(R.id.btn_two);
btnTwo.setOnClickListener(this);
btnThree = (Button) findViewById(R.id.btn_three);
btnThree.setOnClickListener(this);
btnFour = (Button) findViewById(R.id.btn_four);
btnFour.setOnClickListener(this);
btnFive = (Button) findViewById(R.id.btn_five);
btnFive.setOnClickListener(this);
btnSix = (Button) findViewById(R.id.btn_six);
btnSix.setOnClickListener(this);
btnSeven = (Button) findViewById(R.id.btn_seven);
btnSeven.setOnClickListener(this);
btnEight = (Button) findViewById(R.id.btn_eight);
btnEight.setOnClickListener(this);
btnNine = (Button) findViewById(R.id.btn_nine);
btnNine.setOnClickListener(this);
btnZero = (Button) findViewById(R.id.btn_zero);
btnZero.setOnClickListener(this);
btnSave = (Button) findViewById(R.id.btn_save);
btnSave.setOnClickListener(this);
btnCall = (Button) findViewById(R.id.btn_call);
btnCall.setOnClickListener(this);
btnStar = (Button) findViewById(R.id.btn_star);
btnStar.setOnClickListener(this);
btnHash = (Button) findViewById(R.id.btn_ash);
btnHash.setOnClickListener(this);
btnDel = (Button) findViewById(R.id.btn_del);
btnDel.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v.equals(btnOne)) {
txtNumber.append("1");
} else if (v.equals(btnTwo)) {
txtNumber.append("2");
} else if (v.equals(btnThree)) {
txtNumber.append("3");
} else if (v.equals(btnFour)) {
txtNumber.append("4");
} else if (v.equals(btnFive)) {
txtNumber.append("5");
} else if (v.equals(btnSix)) {
txtNumber.append("6");
} else if (v.equals(btnSeven)) {
txtNumber.append("7");
} else if (v.equals(btnEight)) {
txtNumber.append("8");
} else if (v.equals(btnNine)) {
txtNumber.append("9");
} else if (v.equals(btnZero)) {
txtNumber.append("0");
} else if (v.equals(btnStar)) {
txtNumber.append("*");
} else if (v.equals(btnHash)) {
txtNumber.append("#");
} else if (v.equals(btnDel)) {
String
num = txtNumber.getText().toString();
if (num.length() > 0) {
num = num.substring(0, num.length() - 1);
}
txtNumber.setText(num);
} else if (v.equals(btnCall)) {
String num = txtNumber.getText().toString();
Intent it = new Intent(Intent.ACTION_CALL);
it.setData(Uri.parse("tel:" + num));
startActivity(it);
} else if (v.equals(btnSave)) {
String num = txtNumber.getText().toString();
Intent
intent = new Intent(Intent.ACTION_INSERT,
ContactsContract.Contacts.CONTENT_URI);
intent.putExtra(ContactsContract.Intents.Insert.PHONE, num);
startActivity(intent);
}
}

}
Manifest.xml

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.CALL_PHONE" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CallerApp"
tools:targetApi="31">

<activity
android:name=".MainActivity"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>

</manifest>

You might also like