package com.epson.mobilephone.common.wifidirect;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import epson.print.ActivityIACommon;
import epson.print.R;


/**
 * 基类
 */
public abstract class ActivityWiFiDirectBase extends ActivityIACommon {
    public static final int ID_NEXT = 10;
    public final int RESULT_BACK = 1;
    private boolean bDisplayHomeAsUpEnabled = false;
    private boolean bSupportCancel = false;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
    }

    public void setupCommonHeaderControl(boolean z, boolean z2) {
        setActionBar(R.string.str_wifidirect_settings, z);
        bDisplayHomeAsUpEnabled = z;
        bSupportCancel = z2;
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i == 10) {
            switch (i2) {
                case -1:
                    EPLog.d(getLocalClassName(), "finish with RESULT_OK");
                    setResult(-1, intent);
                    finish();
                    return;
                case 0:
                    onCancelPressed();
                    return;
                default:
                    return;
            }
        }
    }

    public void onBackPressed() {
        if (bDisplayHomeAsUpEnabled) {
            EPLog.d(getLocalClassName(), "finish with RESULT_BACK");
            setResult(1);
            finish();
            return;
        }
        onCancelPressed();
    }

    public void onCancelPressed() {
        EPLog.d(getLocalClassName(), "finish with RESULT_CANCELED");
        setResult(0);
        finish();
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        if (bSupportCancel) {
            getMenuInflater().inflate(R.menu.menu_cancel, menu);
        }
        return super.onCreateOptionsMenu(menu);
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != R.id.menuCancel) {
            return super.onOptionsItemSelected(menuItem);
        }
        onCancelPressed();
        return true;
    }

    protected void setDisplayMenu(boolean z) {
        bSupportCancel = z;
        invalidateOptionsMenu();
    }
}
