package metro.net.tehranit;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;


public class PAYMENTActivity extends Activity {

    public Typeface myfont;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.payment);
        myfont = Typeface.createFromAsset(getAssets(), "ARSHIA.TTF");
        ImageView btn1 = (ImageView) findViewById(R.id.btn1);
        ImageView btn2 = (ImageView) findViewById(R.id.btn2);
        ImageView btn3 = (ImageView) findViewById(R.id.btn3);
        TextView txt1 = (TextView) findViewById(R.id.txt1);
        final TextView txtofline = (TextView) findViewById(R.id.txtofline);
        TextView txt2 = (TextView) findViewById(R.id.txt2);
        TextView txthintofline = (TextView) findViewById(R.id.txthintofline);
        final TextView txtoflinecash = (TextView) findViewById(R.id.txtoflinecash);
        final LinearLayout liofline = (LinearLayout) findViewById(R.id.liofline);
        final LinearLayout lijiring = (LinearLayout) findViewById(R.id.lijiring);
        Button bt1 = (Button) findViewById(R.id.bt1);
        Button bt2 = (Button) findViewById(R.id.bt2);
        Button bt3 = (Button) findViewById(R.id.bt3);
        Button btnoflinem = (Button) findViewById(R.id.btnoflinem);
        Button btnoflinep = (Button) findViewById(R.id.btnoflinep);

        final EditText txtoflinec1 = (EditText) findViewById(R.id.txtoflinec1);
        final EditText txtoflinec2 = (EditText) findViewById(R.id.txtoflinec2);

        TextView jimin = (TextView) findViewById(R.id.jimin);
        TextView jipass = (TextView) findViewById(R.id.jipass);
        final TextView jiconter = (TextView) findViewById(R.id.jiconter);
        TextView jitxt = (TextView) findViewById(R.id.jitxt);
        TextView jiplus = (TextView) findViewById(R.id.jiplus);
        final TextView jiprice = (TextView) findViewById(R.id.jiprice);

        jimin.setTypeface(myfont);
        jipass.setTypeface(myfont);
        jiconter.setTypeface(myfont);
        jitxt.setTypeface(myfont);
        jiplus.setTypeface(myfont);
        jiprice.setTypeface(myfont);

        bt1.setTypeface(myfont);
        bt2.setTypeface(myfont);
        bt3.setTypeface(myfont);
        txt1.setTypeface(myfont);
        txt2.setTypeface(myfont);
        txtofline.setTypeface(myfont);
        txtoflinec1.setTypeface(myfont);
        txtoflinec2.setTypeface(myfont);
        txthintofline.setTypeface(myfont);
        txtoflinecash.setTypeface(myfont);
        final LinearLayout lin1 = (LinearLayout) findViewById(R.id.lin1);
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                // Do something after 5s = 5000ms
                lin1.setVisibility(View.GONE);

            }
        }, 3000);

        final ImageView img1 = (ImageView) findViewById(R.id.img1);
        img1.post(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                ((AnimationDrawable) img1.getBackground()).start();

            }
        });

        btn1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Intent myintent = new Intent(PAYMENTActivity.this, QRActivity.class);
                PAYMENTActivity.this.startActivity(myintent);
            }
        });
        btn2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Intent myintent1 = new Intent(PAYMENTActivity.this, NFCActivity.class);
                PAYMENTActivity.this.startActivity(myintent1);
            }
        });
        btn3.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Toast.makeText(PAYMENTActivity.this, "در همین صفحه قرار دارید !!!", Toast.LENGTH_SHORT).show();
            }
        });

        bt1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (liofline.getVisibility() == View.GONE)
                    liofline.setVisibility(View.VISIBLE);
                else
                    liofline.setVisibility(View.GONE);

            }
        });
        bt2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub55555555555555555555
                if (lijiring.getVisibility() == View.GONE)
                    lijiring.setVisibility(View.VISIBLE);
                else
                    lijiring.setVisibility(View.GONE);
            }
        });

        btnoflinem.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                int x = Integer.parseInt((String) txtofline.getText());
                int y = x - 1;
                if (y >= 0) {
                    txtofline.setText("" + y);
                    txtoflinecash.setText("" + (y * 300));
                }

                else {
                    txtofline.setText("0");
                    txtoflinecash.setText("0");
                }

            }
        });
        btnoflinep.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                int x = Integer.parseInt((String) txtofline.getText());
                int y = x + 1;
                if (y <= 100) {
                    txtofline.setText("" + y);
                    txtoflinecash.setText("" + (y * 300));
                }

                else {
                    txtofline.setText("100");
                    txtoflinecash.setText("" + (100 * 300));
                }

            }
        });
        jiplus.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub55555555555555555
                int x = Integer.parseInt((String) jiconter.getText());
                int y = x + 1;
                if (y <= 100) {
                    jiconter.setText("" + y);
                    jiprice.setText("" + (y * 300));
                }

                else {
                    txtofline.setText("100");
                    txtoflinecash.setText("" + (100 * 300));
                }
            }
        });
        jimin.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                int x = Integer.parseInt((String) jiconter.getText());
                int y = x - 1;
                if (y >= 0) {
                    jiconter.setText("" + y);
                    jiprice.setText("" + (y * 300));
                }

                else {
                    txtofline.setText("0");
                    txtoflinecash.setText("0");
                }
            }
        });
        Button btnPaymentOne = (Button) findViewById(R.id.btnPaymentOne);
        btnPaymentOne.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                int x = Integer.parseInt((String) txtofline.getText());
                Editable y = txtoflinec1.getText();
                Editable z = txtoflinec2.getText();
                txtofline.setText("0");
                txtoflinec1.setText("");
                txtoflinec2.setText("");
                txtoflinecash.setText("0");

                Toast.makeText(PAYMENTActivity.this, "* 155 *" + x + "*" + y + "*" + z + "#", Toast.LENGTH_LONG).show();
                Toast.makeText(PAYMENTActivity.this, "ارور : عدم اتصال به شبکه", Toast.LENGTH_LONG).show();

            }
        });

    }

}