示例#1
0
  @Override
  public void onResume() {
    super.onResume();

    shaderView.onResume();
    dataSource.open();

    loadPreferences();
  }
示例#2
0
  @Override
  public void onCreate(Bundle state) {
    super.onCreate(state);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main_activity);

    shaderView = (ShaderView) findViewById(R.id.preview);
    shaderSpinner = (Spinner) findViewById(R.id.shader);
    saveButton = (ImageButton) findViewById(R.id.save);
    sourceButton = (ImageButton) findViewById(R.id.source);
    scrollView = (LockableScrollView) findViewById(R.id.scroll);
    shaderEditor = (ShaderEditor) findViewById(R.id.editor);

    saveButton.setOnLongClickListener(
        new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            compileOnChange ^= true;
            setSaveButton();
            savePreferences();

            return true;
          }
        });

    shaderEditor.onTextChangedListener =
        new ShaderEditor.OnTextChangedListener() {
          @Override
          public void onTextChanged(String text) {
            if (compileOnChange) loadShader(text);
          }
        };

    shaderView.renderer.errorListener = this;
    shaderView.renderer.fpsListener = this;

    // create error message popup
    {
      View v =
          ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE))
              .inflate(R.layout.error_popup, null);

      errorMessage = (TextView) v.findViewById(R.id.message);
      errorPopup = new PopupWindow(v, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    }

    float density = getResources().getDisplayMetrics().scaledDensity;
    textSize = shaderEditor.getTextSize() / density;
    minimumTextSize = 9f;
    maximumTextSize = 22f;

    scrollView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent ev) {
            return pinchZoom(ev);
          }
        });

    dataSource = new ShaderDataSource(this);
    dataSource.open();

    adapter = new ShaderAdapter(this, dataSource.queryAll());

    shaderSpinner.setAdapter(adapter);
    shaderSpinner.setOnItemSelectedListener(
        new Spinner.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            Cursor c = (Cursor) parent.getItemAtPosition(pos);

            resetFps();

            if (c != null) {
              String src = c.getString(c.getColumnIndex(ShaderDataSource.COLUMN_SHADER));

              shaderEditor.setTextHighlighted(src);

              if (!compileOnChange) loadShader(src);
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {
            resetFps();
          }
        });

    registerForContextMenu(shaderSpinner);

    // show/hide source
    if (state != null && !state.getBoolean(STATE_SOURCE, showSource)) onToggleSource(null);

    // set selection
    {
      int p = 0;

      if (state != null) p = state.getInt(STATE_SHADER);

      if (shaderSpinner.getCount() <= p) p = 0;

      shaderSpinner.setSelection(p);
    }
  }