Make aide project

in #technology8 years ago (edited)

MainActivity.java code

image

package ucsmb.apkph.com.phonecall;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
image

public class MainActivity extends AppCompatActivity {

TextView tv;

String phno = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //permission request
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (checkCallingOrSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, 0);
        }
    }
    phno = "";
    tv = findViewById(R.id.phoneNum);
    tv.setText("");
}

public void clickNum(View v) {
    Button btn = (Button) v;
    phno += btn.getText();
    tv.setText(phno);
}

public void del(View v) {
    if (!phno.equals("")) {
        phno = phno.substring(0, phno.length() - 1);
        tv.setText(phno);
    }
}

public void call(View v) {
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:" + phno.replace("#", "%23")));
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    startActivity(callIntent);
}

}
manifast
########

<uses-permission android:name="android.permission.CALL_PHONE" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

########

activity_main.xml

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp"
    android:onClick="del"
    android:text="DEL" />

<TextView
    android:id="@+id/phoneNum"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="0945"
    android:textColor="@android:color/black"
    android:textSize="30dp" />

<GridLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:columnCount="3">

    <Button
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:onClick="clickNum"
        android:text="1"
        android:textSize="30dp" />

    <Button
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:onClick="clickNum"
        android:text="2"
        android:textSize="30dp" />

    <Button
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:onClick="clickNum"
        android:text="3"
        android:textSize="30dp" />

    <Button
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:onClick="clickNum"
        android:text="4"
        android:textSize="30dp" />

    <Button
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:onClick="clickNum"
        android:text="5"
        android:textSize="30dp" />

    <Button
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:onClick="clickNum"
        android:text="6"
        android:textSize="30dp" />

    <Button
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:onClick="clickNum"
        android:text="7"
        android:textSize="30dp" />

    <Button
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:onClick="clickNum"
        android:text="8"
        android:textSize="30dp" />

    <Button
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:onClick="clickNum"
        android:text="9"
        android:textSize="30dp" />

    <Button
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:onClick="clickNum"
        android:text="*"
        android:textSize="30dp" />

    <Button
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:onClick="clickNum"
        android:text="0"
        android:textSize="30dp" />

    <Button
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:onClick="clickNum"
        android:text="#"
        android:textSize="30dp" />
</GridLayout>

<Button
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_gravity="center"
    android:onClick="call"
    android:text="Call"
    android:textAllCaps="false"
    android:textSize="20dp" />


image
Thank you all.

Sort:  

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by Kyawyhetaung from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.