package com.example.patrice.rerservation01;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

// http://en.proft.me/2017/11/27/how-get-phone-number-programmatically-android/

public class SignUpActivity extends AppCompatActivity
{
    Button btn_save_preferences;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.signup_layout);

        btn_save_preferences =(Button) findViewById(R.id.btn_save_preferences);

        btn_save_preferences.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit() .putBoolean("isFirstRun", false).commit();

                finish();

            }
        });


        String number = getPhoneNumber();


        Toast.makeText(getApplicationContext(), "Phone Number is: " + number, Toast.LENGTH_SHORT).show();

       // TextView textView = (TextView) findViewById(R.id.phone_number_view);
       // textView.setText("My Phone Nnumber is: " + number);

    }

    // http://www.learn-android-easily.com/2012/11/using-telephony-manager-in-android.html
    // https://www.codeproject.com/Articles/511455/Android-Phone-Status-Sample

    private String getPhoneNumber()
    {
        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

        String PhoneNumber = telephonyManager.getLine1Number();
        String IMEI = telephonyManager.getDeviceId();


        String IMEINumber = telephonyManager.getDeviceId();
        String subscriberID = telephonyManager.getDeviceId();
        String SIMSerialNumber = telephonyManager.getSimSerialNumber();
        String networkCountryISO = telephonyManager.getNetworkCountryIso();
        String SIMCountryISO = telephonyManager.getSimCountryIso();
        String softwareVersion = telephonyManager.getDeviceSoftwareVersion();
        String voiceMailNumber = telephonyManager.getVoiceMailNumber();

        String strphoneType="";

        int phoneType = telephonyManager.getPhoneType();

        switch (phoneType)
        {
            case (TelephonyManager.PHONE_TYPE_CDMA):
                strphoneType="CDMA";
                break;
            case (TelephonyManager.PHONE_TYPE_GSM):
                strphoneType="GSM";
                break;
            case (TelephonyManager.PHONE_TYPE_NONE):
                strphoneType="NONE";
                break;
        }

        //getting information if phone is in roaming
        boolean isRoaming = telephonyManager.isNetworkRoaming();

        String info="Phone Details:\n";
        info+="\n IMEI Number:"+IMEINumber;
        info+="\n SubscriberID:"+subscriberID;
        info+="\n Sim Serial Number:"+SIMSerialNumber;
        info+="\n Network Country ISO:"+networkCountryISO;
        info+="\n SIM Country ISO:"+SIMCountryISO;
        info+="\n Software Version:"+softwareVersion;
        info+="\n Voice Mail Number:"+voiceMailNumber;
        info+="\n Phone Network Type:"+strphoneType;
        info+="\n In Roaming? :"+isRoaming;

        //textView.setText(info);//displaying the information in the textView


        return PhoneNumber;
    }

}