Search in sources :

Example 11 with DrMIPSActivity

use of brunonova.drmips.android.DrMIPSActivity 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 12 with DrMIPSActivity

use of brunonova.drmips.android.DrMIPSActivity 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

DrMIPSActivity (brunonova.drmips.android.DrMIPSActivity)12 Bundle (android.os.Bundle)9 File (java.io.File)5 TextView (android.widget.TextView)3 SuppressLint (android.annotation.SuppressLint)2 TableLayout (android.widget.TableLayout)2 TableRow (android.widget.TableRow)2 CPU (brunonova.drmips.simulator.CPU)2 Component (brunonova.drmips.simulator.Component)2 AlertDialog (android.app.AlertDialog)1 View (android.view.View)1 EditText (android.widget.EditText)1 Instruction (brunonova.drmips.simulator.Instruction)1 PseudoInstruction (brunonova.drmips.simulator.PseudoInstruction)1 ALU (brunonova.drmips.simulator.components.ALU)1 ExtendedALU (brunonova.drmips.simulator.components.ExtendedALU)1