Search in sources :

Example 1 with Component

use of brunonova.drmips.simulator.Component in project drmips by brunonova.

the class DlgChangeLatency method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    Bundle args = getArguments();
    DrMIPSActivity activity = (DrMIPSActivity) getActivity();
    Component component = activity.getCPU().getComponent(args.getString("id", ""));
    txtLatency = new EditText(getActivity());
    txtLatency.setHint(R.string.latency);
    txtLatency.setInputType(InputType.TYPE_CLASS_NUMBER);
    if (savedInstanceState != null && savedInstanceState.containsKey("latency")) {
        txtLatency.setText(savedInstanceState.getString("latency"));
    } else {
        if (component != null)
            txtLatency.setText("" + component.getLatency());
    }
    return new AlertDialog.Builder(getActivity()).setTitle(getResources().getString(R.string.latency_of_x).replace("#1", args.getString("id", ""))).setView(txtLatency).setPositiveButton(android.R.string.ok, this).setNegativeButton(android.R.string.cancel, this).create();
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) Bundle(android.os.Bundle) Component(brunonova.drmips.simulator.Component) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity)

Example 2 with Component

use of brunonova.drmips.simulator.Component in project drmips by brunonova.

the class DlgChangeLatency method onClick.

@Override
public void onClick(DialogInterface dialog, int which) {
    switch(which) {
        case // OK
        AlertDialog.BUTTON_POSITIVE:
            try {
                Bundle args = getArguments();
                DrMIPSActivity activity = (DrMIPSActivity) getActivity();
                Component component = activity.getCPU().getComponent(args.getString("id", ""));
                int lat = Integer.parseInt(txtLatency.getText().toString());
                if (lat >= 0 && component != null) {
                    component.setLatency(lat);
                    activity.getCPU().calculatePerformance();
                    activity.getDatapath().refresh();
                    activity.getDatapath().invalidate();
                } else {
                    Toast.makeText(getActivity(), R.string.invalid_value, Toast.LENGTH_SHORT).show();
                }
            } catch (NumberFormatException ex) {
                Toast.makeText(getActivity(), R.string.invalid_value, Toast.LENGTH_SHORT).show();
            }
            break;
        case // Cancel
        AlertDialog.BUTTON_NEGATIVE:
            dismiss();
            break;
    }
}
Also used : Bundle(android.os.Bundle) Component(brunonova.drmips.simulator.Component) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity)

Aggregations

Bundle (android.os.Bundle)2 DrMIPSActivity (brunonova.drmips.android.DrMIPSActivity)2 Component (brunonova.drmips.simulator.Component)2 AlertDialog (android.app.AlertDialog)1 EditText (android.widget.EditText)1