package com.epson.iprint.storage;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import epson.print.R;

public class StorageWaitingActivity extends Activity {
    static String CANCEL_REQUEST_ACTION = "StorageProgressActivity.CancelRequestAction";
    static String CHANGE_ACTION = "StorageProgressActivity.ChangeAction";
    static String DISMISS_ACTION = "StorageProgressActivity.DismissAction";
    static String EXTRA_CANCEL_ENABLED = "StorageProgressActivity.ExtraCancelEnabled";
    static String EXTRA_MESSAGE = "StorageProgressActivity.ExtraMessage";
    static String EXTRA_REQUEST_CODE = "StorageProgressActivity.ExtraRequestCode";
    static String REGISTER_ACTION = "StorageProgressActivity.RegisterAction";
    public static boolean bShowing = false;
    BroadcastReceiver mBroadcastReceiver;
    Button mCancelButton;
    TextView mMessageText;
    int mRequestCode;

    public void onBackPressed() {
    }

    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.storage_progress);
        Intent intent = getIntent();
        registerBroadcastReceiver(intent);
        setMessage(intent);
        setCancelRequest(intent);
    }

    /* access modifiers changed from: protected */
    public void onDestroy() {
        unregisterReceiver(this.mBroadcastReceiver);
        super.onDestroy();
    }

    /* access modifiers changed from: package-private */
    public void registerBroadcastReceiver(Intent intent) {
        this.mRequestCode = intent.getIntExtra(EXTRA_REQUEST_CODE, 0);
        this.mBroadcastReceiver = new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if (StorageWaitingActivity.this.mRequestCode == intent.getIntExtra(StorageWaitingActivity.EXTRA_REQUEST_CODE, 0)) {
                    if (action.equals(StorageWaitingActivity.DISMISS_ACTION)) {
                        StorageWaitingActivity.this.finish();
                    } else if (action.equals(StorageWaitingActivity.CHANGE_ACTION)) {
                        StorageWaitingActivity.this.setMessage(intent);
                    } else if (action.equals(StorageWaitingActivity.REGISTER_ACTION)) {
                        StorageWaitingActivity.this.setCancelRequest(intent);
                    }
                }
            }
        };
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(DISMISS_ACTION);
        intentFilter.addAction(CHANGE_ACTION);
        intentFilter.addAction(REGISTER_ACTION);
        registerReceiver(this.mBroadcastReceiver, intentFilter);
    }

    /* access modifiers changed from: package-private */
    public Dialog createCancelDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(getString(R.string.str_msg_scan_cancel));
        builder.setCancelable(false);
        builder.setPositiveButton(getString(R.string.str_yes), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                StorageWaitingActivity.this.mCancelButton.setEnabled(false);
                StorageWaitingActivity.this.mMessageText.setText(StorageWaitingActivity.this.getString(R.string.EPS_PRNST_CANCELLING_MSG));
                Intent intent = new Intent(StorageWaitingActivity.CANCEL_REQUEST_ACTION);
                intent.putExtra(StorageWaitingActivity.EXTRA_REQUEST_CODE, StorageWaitingActivity.this.mRequestCode);
                StorageWaitingActivity.this.sendBroadcast(intent);
                dialogInterface.cancel();
            }
        });
        builder.setNegativeButton(getString(R.string.str_no), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                StorageWaitingActivity.this.mCancelButton.setEnabled(true);
                dialogInterface.cancel();
            }
        });
        return builder.create();
    }

    /* access modifiers changed from: package-private */
    public void setCancelRequest(Intent intent) {
        this.mCancelButton = (Button) findViewById(R.id.cancelButton);
        this.mCancelButton.setText(getString(R.string.str_cancel));
        if (intent.getBooleanExtra(EXTRA_CANCEL_ENABLED, false)) {
            this.mCancelButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    StorageWaitingActivity.this.createCancelDialog().show();
                }
            });
            this.mCancelButton.setVisibility(0);
            return;
        }
        this.mCancelButton.setVisibility(8);
    }

    /* access modifiers changed from: package-private */
    public void setMessage(Intent intent) {
        this.mMessageText = (TextView) findViewById(R.id.messageText);
        String stringExtra = intent.getStringExtra(EXTRA_MESSAGE);
        if (stringExtra != null) {
            this.mMessageText.setText(stringExtra);
            this.mMessageText.setVisibility(0);
            return;
        }
        this.mMessageText.setVisibility(8);
    }

    /* access modifiers changed from: protected */
    public void onResume() {
        super.onResume();
        bShowing = true;
    }

    /* access modifiers changed from: protected */
    public void onPause() {
        super.onPause();
        bShowing = false;
    }
}
