FileDocCategorySizeDatePackage
IPControlsJB.javaAPI DocAndroid 5.1 API11902Thu Mar 12 22:22:54 GMT 2015com.android.rs.imagejb

IPControlsJB

public class IPControlsJB extends android.app.Activity

Fields Summary
private final String
TAG
public final String
RESULT_FILE
private android.widget.Spinner
mResSpinner
private android.widget.ListView
mTestListView
private android.widget.TextView
mResultView
private android.widget.ArrayAdapter
mTestListAdapter
private ArrayList
mTestList
private boolean[]
mSettings
private static final int
SETTING_USE_IO
private static final int
SETTING_ANIMATE
private static final int
SETTING_DISPLAY
private static final int
SETTING_USE_DVFS
private static final int
SETTING_LONG_RUN
private static final int
SETTING_PAUSE
private float[]
mResults
private Resolutions
mRes
private AdapterView.OnItemSelectedListener
mResSpinnerListener
Constructors Summary
Methods Summary
public voidbtnRun(android.view.View v)

        IPTestListJB.TestName t[] = IPTestListJB.TestName.values();

        int count = 0;
        for (int i = 0; i < t.length; i++) {
            if (mTestListView.isItemChecked(i)) {
                count++;
            }
        }
        if (count == 0) {
            return;
        }

        int testList[] = new int[count];
        count = 0;
        for (int i = 0; i < t.length; i++) {
            if (mTestListView.isItemChecked(i)) {
                testList[count++] = i;
            }
        }

        Intent intent = makeBasicLaunchIntent();
        intent.putExtra("tests", testList);
        startActivityForResult(intent, 0);
    
public voidbtnSelAll(android.view.View v)

        IPTestListJB.TestName t[] = IPTestListJB.TestName.values();
        for (int i=0; i < t.length; i++) {
            mTestListView.setItemChecked(i, true);
        }
    
public voidbtnSelHp(android.view.View v)

        checkGroup(0);
    
public voidbtnSelIntrinsic(android.view.View v)

        checkGroup(2);
    
public voidbtnSelLp(android.view.View v)

        checkGroup(1);
    
public voidbtnSelNone(android.view.View v)

        checkGroup(-1);
    
public voidbtnSettings(android.view.View v)

        IPSettings newFragment = new IPSettings(mSettings);
        newFragment.show(getFragmentManager(), "settings");
    
private voidcheckGroup(int group)

        IPTestListJB.TestName t[] = IPTestListJB.TestName.values();
        for (int i=0; i < t.length; i++) {
            mTestListView.setItemChecked(i, group == t[i].group);
        }
    
voidinit()


        for (int i=0; i < IPTestListJB.TestName.values().length; i++) {
            mTestList.add(IPTestListJB.TestName.values()[i].toString());
        }

        mTestListView = (ListView) findViewById(R.id.test_list);
        mTestListAdapter = new ArrayAdapter(this,
                android.R.layout.simple_list_item_activated_1,
                mTestList);

        mTestListView.setAdapter(mTestListAdapter);
        mTestListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        mTestListAdapter.notifyDataSetChanged();

        mResultView = (TextView) findViewById(R.id.results);

        mTestListView.setOnItemLongClickListener(new ListView.OnItemLongClickListener() {
                public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                        int pos, long id) {
                    launchDemo(pos);
                    return true;
                }
            });
    
voidlaunchDemo(int id)


       
        IPTestListJB.TestName t[] = IPTestListJB.TestName.values();

        int testList[] = new int[1];
        testList[0] = id;

        Intent intent = makeBasicLaunchIntent();
        intent.putExtra("tests", testList);
        intent.putExtra("demo", true);
        startActivityForResult(intent, 0);
    
android.content.IntentmakeBasicLaunchIntent()

        Intent intent = new Intent(this, ImageProcessingActivityJB.class);
        intent.putExtra("enable io", mSettings[SETTING_USE_IO]);
        intent.putExtra("enable dvfs", mSettings[SETTING_USE_DVFS]);
        intent.putExtra("enable long", mSettings[SETTING_LONG_RUN]);
        intent.putExtra("enable pause", mSettings[SETTING_PAUSE]);
        intent.putExtra("enable animate", mSettings[SETTING_ANIMATE]);
        intent.putExtra("enable display", mSettings[SETTING_DISPLAY]);
        intent.putExtra("resolution X", mRes.width);
        intent.putExtra("resolution Y", mRes.height);
        return intent;
    
protected voidonActivityResult(int requestCode, int resultCode, android.content.Intent data)

        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                java.text.DecimalFormat df = new java.text.DecimalFormat("######.#");
                mResults = new float[IPTestListJB.TestName.values().length];

                float r[] = data.getFloatArrayExtra("results");
                int id[] = data.getIntArrayExtra("tests");

                for (int ct=0; ct < id.length; ct++) {
                    IPTestListJB.TestName t = IPTestListJB.TestName.values()[id[ct]];

                    String s = t.toString() + "   " + df.format(rebase(r[ct], t)) +
                            "X,   " + df.format(r[ct]) + "ms";
                    mTestList.set(id[ct], s);
                    mTestListAdapter.notifyDataSetChanged();
                    mResults[id[ct]] = r[ct];
                }

                double gm[] = {1.0, 1.0, 1.0};
                double count[] = {0, 0, 0};
                for (int ct=0; ct < IPTestListJB.TestName.values().length; ct++) {
                    IPTestListJB.TestName t = IPTestListJB.TestName.values()[ct];
                    gm[t.group] *= rebase(mResults[ct], t);
                    count[t.group] += 1.0;
                }
                gm[0] = java.lang.Math.pow(gm[0], 1.0 / count[0]);
                gm[1] = java.lang.Math.pow(gm[1], 1.0 / count[1]);
                gm[2] = java.lang.Math.pow(gm[2], 1.0 / count[2]);

                String s = "Results:  fp full=" + df.format(gm[0]) +
                        ",  fp relaxed=" +df.format(gm[1]) +
                        ",  intrinsics=" + df.format(gm[2]);
                mResultView.setText(s);
                writeResults();
            }
        }
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);
        setContentView(R.layout.controls);
        init();
    
public booleanonCreateOptionsMenu(android.view.Menu menu)

        // Inflate the menu items for use in the action bar
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_activity_actions, menu);

        MenuItem searchItem = menu.findItem(R.id.action_res);
        mResSpinner = (Spinner) searchItem.getActionView();

        mResSpinner.setOnItemSelectedListener(mResSpinnerListener);
        mResSpinner.setAdapter(new ArrayAdapter<Resolutions>(
            this, R.layout.spinner_layout, Resolutions.values()));

        // Choose one of the image sizes that close to the resolution
        // of the screen.
        Point size = new Point();
        getWindowManager().getDefaultDisplay().getSize(size);
        int md = (size.x > size.y) ? size.x : size.y;
        for (int ct=0; ct < Resolutions.values().length; ct++) {
            if (Resolutions.values()[ct].width <= (int)(md * 1.2)) {
                mResSpinner.setSelection(ct);
                break;
            }
        }

        return super.onCreateOptionsMenu(menu);
    
public booleanonOptionsItemSelected(android.view.MenuItem item)

        // Handle presses on the action bar items
        switch(item.getItemId()) {
            case R.id.action_settings:
                IPSettings newFragment = new IPSettings(mSettings);
                newFragment.show(getFragmentManager(), "settings");
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    
protected voidonPause()

        super.onPause();

        //cleanup();
    
protected voidonResume()

        super.onResume();

       // init();
    
floatrebase(float v, IPTestListJB.TestName t)

        if (v > 0.001) {
            v = t.baseline / v;
        }
        float pr = (1920.f / mRes.width) * (1080.f / mRes.height);
        return v / pr;
    
private voidwriteResults()

        // write result into a file
        File externalStorage = Environment.getExternalStorageDirectory();
        if (!externalStorage.canWrite()) {
            Log.v(TAG, "sdcard is not writable");
            return;
        }
        File resultFile = new File(externalStorage, RESULT_FILE);
        resultFile.setWritable(true, false);
        try {
            BufferedWriter rsWriter = new BufferedWriter(new FileWriter(resultFile));
            Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
            java.text.DecimalFormat df = new java.text.DecimalFormat("######.##");

            for (int ct=0; ct < IPTestListJB.TestName.values().length; ct++) {
                IPTestListJB.TestName t = IPTestListJB.TestName.values()[ct];
                final float r = mResults[ct];
                float r2 = rebase(r, t);
                String s = new String("" + t.toString() + ", " + df.format(r) + ", " + df.format(r2));
                rsWriter.write(s + "\n");
            }
            rsWriter.close();
        } catch (IOException e) {
            Log.v(TAG, "Unable to write result file " + e.getMessage());
        }