com.paic.zhifu.wallet.activity.modules.creditpayment.WeakRealNameSignUpApplyActivity.java Source code

Java tutorial

Introduction

Here is the source code for com.paic.zhifu.wallet.activity.modules.creditpayment.WeakRealNameSignUpApplyActivity.java

Source

package com.paic.zhifu.wallet.activity.modules.creditpayment;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.support.v4.content.LocalBroadcastManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.paic.zhifu.wallet.activity.R;
import com.paic.zhifu.wallet.activity.bean.User;
import com.paic.zhifu.wallet.activity.cache.DataCache;
import com.paic.zhifu.wallet.activity.control.GeneralStructuralActivity;
import com.paic.zhifu.wallet.activity.control.widget.InterceptLinearLayout;
import com.paic.zhifu.wallet.activity.modules.boundcard.OpenPaymentActivity;
import com.paic.zhifu.wallet.activity.modules.creditpayment.pub.PaymentByCreditIntents;
import com.paic.zhifu.wallet.activity.tool.MyApp;
import com.paic.zhifu.wallet.activity.tool.StaticVariableTool;

/**
 * User interface about step one of applying for weak name.
 * 
 * @author Ma Xin
 *
 */
public class WeakRealNameSignUpApplyActivity extends GeneralStructuralActivity
        implements OnClickListener, TextWatcher {

    // Title bar
    private TextView titlebarTV;
    private InterceptLinearLayout titlebarBackLL;

    private Button signUpApplyBtn;
    private TextView nameTV;
    private TextView phoneTV;
    private TextView certificateTV;

    private EditText amountET;
    private TextView amountWarnningTV;

    private TextView licenseTV;

    private AlertDialog cancelApplyingDialog;

    private IntentFilter mFilter;
    private BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String intentStr = intent.getAction();
            if (intentStr.equals(PaymentByCreditIntents.PAYMENTBYCREDIT_STEP_ONE_APPLY_SUCCESSFULLY)) {
                LocalBroadcastManager.getInstance(WeakRealNameSignUpApplyActivity.this)
                        .unregisterReceiver(receiver);
                finish();
            }
        }

    };

    @Override
    public void onClick(View view) {
        int viewId = view.getId();
        switch (viewId) {
        case R.id.headtitleplus_backParentLayout:
            showCancelApplyingDialog();
            break;
        case R.id.button_paymentbycredit_register_weakapply_agree:
            disableApplyBtn();
            int amount = Integer.valueOf(amountET.getText().toString());
            DataCache.getDataCache().setCoundCardOverJumpTo(
                    StaticVariableTool.ACTIVITY_CREDITPAY_OPENPAYMENT_SUCCESS, amount, true);
            Intent openpaymentIntent = new Intent(MyApp.getContext(), OpenPaymentActivity.class);
            startActivity(openpaymentIntent);
            enableApplyBtn();
            break;
        case R.id.textview_paymentbycredit_register_weakapply_license:
            Intent gotoLicense = new Intent(WeakRealNameSignUpApplyActivity.this, LicenseStepOneActivity.class);
            startActivity(gotoLicense);
        }
    }

    @Override
    public void initIntent() {

    }

    @Override
    public void initControl() {
        setContentView(R.layout.paymentbycredit_register_weaksignupapply);
        titlebarTV = (TextView) findViewById(R.id.headtitleplus_titleText);
        titlebarTV.setText(getResources().getString(R.string.paymentbycredit_weaksignupapply));
        titlebarBackLL = (InterceptLinearLayout) findViewById(R.id.headtitleplus_backParentLayout);
        titlebarBackLL.setOnClickListener(this);
        signUpApplyBtn = (Button) findViewById(R.id.button_paymentbycredit_register_weakapply_agree);
        signUpApplyBtn.setOnClickListener(this);
        disableApplyBtn();

        amountET = (EditText) findViewById(R.id.edittext_paymentcredit_register_weakapply_money);
        amountET.addTextChangedListener(this);
        amountWarnningTV = (TextView) findViewById(R.id.textview_paymentcredit_register_weakapply_moneywarnning);

        licenseTV = (TextView) findViewById(R.id.textview_paymentbycredit_register_weakapply_license);
        licenseTV.setOnClickListener(this);

        initInfo();

        mFilter = new IntentFilter();
        mFilter.addAction(PaymentByCreditIntents.PAYMENTBYCREDIT_STEP_ONE_APPLY_SUCCESSFULLY);
        LocalBroadcastManager.getInstance(this).registerReceiver(receiver, mFilter);
    }

    private void initInfo() {
        nameTV = (TextView) findViewById(R.id.textview_paymentcredit_register_weakapply_name);
        phoneTV = (TextView) findViewById(R.id.textview_paymentcredit_register_weakapply_phone);
        certificateTV = (TextView) findViewById(R.id.textview_paymentcredit_register_weakapply_id);

        User user = DataCache.getDataCache().getUser();
        nameTV.setText(user.getRealName());
        phoneTV.setText(user.getPhoneNum());
        certificateTV.setText(user.getIdCardNo());
    }

    @Override
    public void initVariable() {

    }

    @Override
    public void initObserver() {

    }

    @Override
    public void jump(int to) {

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
    }

    @Override
    public void backBtnFunction() {
    }

    @Override
    public void onBackPressed() {
        showCancelApplyingDialog();
    }

    @Override
    public void afterTextChanged(Editable s) {

    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (!isAvailableAmount(s)) {
            if (amountWarnningTV.getVisibility() == View.GONE) {
                amountWarnningTV.setVisibility(View.VISIBLE);
            }
            disableApplyBtn();
        } else {
            if (amountWarnningTV.getVisibility() == View.VISIBLE) {
                amountWarnningTV.setVisibility(View.GONE);
            }
            enableApplyBtn();
        }
    }

    private boolean isAvailableAmount(CharSequence s) {
        if (s == null || s.toString().equals("")) {
            return false;
        }
        String inputStr = s.toString();
        int amount = Integer.valueOf(inputStr);
        if (!inputStr.equals(String.valueOf(amount))) {
            amountET.setText(String.valueOf(amount));
        }
        if (amount > PaymentByCreditIntents.PAYMENTBYCREDIT_APPLY_LIMIT_AMOUNT
                || amount < PaymentByCreditIntents.PAYMENTBYCREDIT_APPLY_LIMIT_AMOUNT_S) {
            return false;
        }
        return true;
    }

    private void disableApplyBtn() {
        signUpApplyBtn.setEnabled(false);
        signUpApplyBtn.setBackgroundResource(R.drawable.normal_btn2);
        signUpApplyBtn.setTextColor(getResources().getColor(R.color.btn_word_disable));
    }

    private void enableApplyBtn() {
        signUpApplyBtn.setEnabled(true);
        signUpApplyBtn.setBackgroundResource(R.drawable.normal_btn);
        signUpApplyBtn.setTextColor(Color.WHITE);
    }

    private void showCancelApplyingDialog() {
        if (cancelApplyingDialog == null) {
            String positiveStr = getResources().getString(R.string.paymentbycredit_applying_cancel);
            String negativeStr = getResources().getString(R.string.paymentbycredit_applying_continue);
            String message = getResources().getString(R.string.paymentbycredit_applying_message);
            cancelApplyingDialog = new AlertDialog.Builder(this).setMessage(message)
                    .setPositiveButton(positiveStr, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            finish();
                        }
                    }).setNegativeButton(negativeStr, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).create();
            cancelApplyingDialog.setCancelable(false);
            cancelApplyingDialog.setCanceledOnTouchOutside(false);
        }
        if (!cancelApplyingDialog.isShowing()) {
            cancelApplyingDialog.show();
        }
    }

}