Android Open Source - graph-android Graph Activity






From Project

Back to project page graph-android.

License

The source code is released under:

GNU General Public License

If you think the Android project graph-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package lorian.graph.android;
//w  w  w  .jav a 2 s. c o  m
import lorian.graph.WindowSettings;
import lorian.graph.android.opengl.*;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;

public class GraphActivity extends Activity {

  
  private GraphSurfaceView gSurfaceView;
  public static final String TAG = "Graph";
  private static ProgressDialog dialog;
  public static final int MaxFunctions = 10;
  public static String[] itemTexts = new String[MaxFunctions];
  public static final Color[] functionColors = { new Color(37, 119, 255), new Color(224,0,0), new Color(211,0,224), new Color(0,158,224), new Color(0,255,90), new Color(221,224,0), new Color(224,84,0),  new Color(37, 119, 255), new Color(224,0,0), new Color(211,0,224) };  
  // NOTE: functionColors.length >= MaxFunctions!
  private static Handler handler;
  private boolean isReady = false;

  
  //@SuppressLint("NewApi")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    //setContentView(R.layout.activity_graph);
    Log.d(TAG, "GraphActivity created"); 
    
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    WindowSettingsActivity.windowsettings = new WindowSettings(prefs.getInt("window_settings_xmin", -8), prefs.getInt("window_settings_xmax", 8), prefs.getInt("window_settings_ymin", -8), prefs.getInt("window_settings_ymax", 8), prefs.getBoolean("window_settings_grid", false));
    GraphRenderer.auto_calc_ymin_ymax = prefs.getBoolean("window_settings_auto_calc_ymin_ymax", true);
    
    dialog = new ProgressDialog(GraphActivity.this, R.style.LoadingDialogTheme);
    dialog.setMessage(getResources().getString(R.string.loading));
    dialog.setCancelable(false);
    
    gSurfaceView = new GraphSurfaceView(this);
    
    setContentView(gSurfaceView); 
    gSurfaceView.setRenderAxes(true);
    gSurfaceView.setRenderFunctions(true);
    
    //TODO This is a temporary fix, since an onTouchListener will be used for other things.
    gSurfaceView.setOnTouchListener(new OnTouchListener() {
      
      // For devices without a menu button
      @Override
      public boolean onTouch(View v, MotionEvent event) {
        openOptionsMenu();
        return true;
      }
    });
    handler = new Handler();
    
  
    isReady = true;
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu)
  {
    MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.graph_menu, menu);
    return true;
  }
  @Override
  public boolean onPrepareOptionsMenu (Menu menu) {
      if (! isReady)
          menu.getItem(1).setEnabled(false);
      return true;
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle item selection
      switch (item.getItemId()) {
          case R.id.menu_input:
            startActivity(new Intent(this, InputActivity.class));
              return true;
          case R.id.menu_windowsettings:
            startActivity(new Intent(this, WindowSettingsActivity.class));
             
            return true;
          default:
              return super.onOptionsItemSelected(item);
      }
  }

  public static void showLoadingDialog()
  {
    Runnable runnable = new Runnable() {
            @Override
            public void run() {
                handler.post(new Runnable() { // This thread runs in the UI
                    @Override
                    public void run() {
                        dialog.show(); 
                    }
                });
            }
        };
    new Thread(runnable).start();
  }
  public static void hideLoadingDialog()
  {
    Runnable runnable = new Runnable() {
            @Override
            public void run() {
                handler.post(new Runnable() { // This thread runs in the UI
                    @Override
                    public void run() {
                        dialog.hide();
                    }
                });
            }
        };
    new Thread(runnable).start();
  }
  
  public static void changeLoadingDialogText(final String text) 
  {
    Runnable runnable = new Runnable() {
            @Override
            public void run() {
                handler.post(new Runnable() { // This thread runs in the UI
                    @Override
                    public void run() {
                        dialog.setMessage(text);
                    }
                });
            }
        };
    new Thread(runnable).start();
  }
  
  
  /*
  findViewById(R.id.show_input_button).setOnClickListener(new View.OnClickListener()
  {
    @Override
    public void onClick(View v) {
      showSlideMenu();
    }
    
  });
  
  findViewById(R.id.inner_content).setOnTouchListener(new View.OnTouchListener() {
    private float start_x;
    @Override
    public boolean onTouch(View v, MotionEvent event) {
  
       if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) {
            start_x=event.getX();
           // start_y=event.getY();
          } else if (event.getAction() == android.view.MotionEvent.ACTION_UP) {
            if(event.getX()>start_x)
             showSlideMenu();
         }
      return true;
    }
  });
  */
  /*
  setOnDragListener(new View.OnDragListener() {
    
    @SuppressLint("NewApi")
    @Override
    public boolean onDrag(View v, DragEvent event) {
      System.out.println("onDrag");
        switch (event.getAction()) {
          case DragEvent.ACTION_DRAG_STARTED:
            System.out.println("ACTION_DRAG_STARTED");
            break;
          case DragEvent.ACTION_DRAG_ENTERED:
            
            break;
          case DragEvent.ACTION_DRAG_EXITED:        
            
            break;
          case DragEvent.ACTION_DROP:
            
            break;
          case DragEvent.ACTION_DRAG_ENDED:
            System.out.println("ACTION_DRAG_ENDED");
            break;
          default:
            break;
        }
        return true;
    }
  });
  private void showSlideMenu()
  {
    
    int width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());
    SlideoutActivity.prepare(GraphActivity.this, R.id.inner_content, width);
    startActivity(new Intent(GraphActivity.this,
        InputMenuActivity.class));
    overridePendingTransition(0, 0);
    
  }
  */

}




Java Source Code List

com.michaelnovakjr.numberpicker.NumberPickerButton.java
com.michaelnovakjr.numberpicker.NumberPickerDialog.java
com.michaelnovakjr.numberpicker.NumberPickerPreference.java
com.michaelnovakjr.numberpicker.NumberPicker.java
lorian.graph.WindowSettings.java
lorian.graph.android.FunctionDataArray.java
lorian.graph.android.GraphActivity.java
lorian.graph.android.InputActivity.java
lorian.graph.android.Util.java
lorian.graph.android.WindowSettingsActivity.java
lorian.graph.android.opengl.Color.java
lorian.graph.android.opengl.GraphRenderer.java
lorian.graph.android.opengl.GraphSurfaceView.java
lorian.graph.function.Calculate.java
lorian.graph.function.Factor.java
lorian.graph.function.Function.java
lorian.graph.function.MathChars.java
lorian.graph.function.MathFunctions.java
lorian.graph.function.PointXY.java
lorian.graph.function.Term.java
lorian.graph.function.Util.java
lorian.graph.function.Variable.java
yuku.ambilwarna.AmbilWarnaDialog.java
yuku.ambilwarna.AmbilWarnaKotak.java