Android Open Source - BestBoard Main Activity






From Project

Back to project page BestBoard.

License

The source code is released under:

MIT License

If you think the Android project BestBoard 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 digitalgarden.bestboard;
/*from w w  w .j  a  v  a  2s. c om*/
import java.io.File;
import java.io.IOException;

import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import digitalgarden.magicmerlin.scribe.Scribe;

public class MainActivity extends Activity
  {
  private Button button;
  private EditText layout;
  private ImageView image;
  
  private Board boardPortrait;
  private Board boardLandscape;

  @Override
  protected void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Scribe.init();
    Scribe.setDirectoryName("_bestboard");
    Scribe.enableFileLog("bestboard.log");
    Scribe.clear();
        
    /* Parser test */
    File directory = new File(Environment.getExternalStorageDirectory(), "_bestboard");
    File descriptionFile = new File(directory, "bestboard.txt");
    
    BoardParser boardParser;

    long parsingTime = 0L;
    try
      {
      parsingTime = SystemClock.currentThreadTimeMillis();// System.nanoTime();
      boardParser = new BoardParser( this, descriptionFile );
      boardParser.parseDescriptorFile();
      parsingTime = SystemClock.currentThreadTimeMillis() - parsingTime;//( System.nanoTime() - time ) / 1000000;
      Scribe.note("Parsing time: " + parsingTime + " ms");
      
      boardPortrait = boardParser.getPortraitBoard();
      boardLandscape = boardParser.getLandscapeBoard();
      } 
    catch (IOException e)
      {
      Scribe.error("READING ERROR WHILE PARSING DESCRIPTOR FILE: " + e.toString());
      }
    /* Parser test ends */
    
    layout = (EditText) findViewById( R.id.layout );

    image = (ImageView) findViewById( R.id.image );
    image.setBackgroundColor( Color.DKGRAY );
    image.setScaleType( ScaleType.CENTER ); // mretet tartva kzpen

    button = (Button) findViewById( R.id.button );
    button.setOnClickListener( new OnClickListener()
      {
      @Override
      public void onClick(View v)
        {
        int l=0;
        long drawingTime = 0L;
        Board board;
        
        try  {
          l = Integer.parseInt(layout.getText().toString());
          }
        catch (NumberFormatException nfe)
          {
          // l is already 0
          }
        
        if ( !Board.isValidLayout(l) )
          l = 0;
        
        Configuration config = getResources().getConfiguration();
        if ( config.orientation != Configuration.ORIENTATION_LANDSCAPE ) 
          {
          board = boardPortrait;
          }
        else
          {
          board = boardLandscape;
          }
       
        if ( boardPortrait != null )
          {
          drawingTime = SystemClock.currentThreadTimeMillis();// System.nanoTime();
          image.setImageBitmap( board.getLayoutSkin( l ) );
          drawingTime = SystemClock.currentThreadTimeMillis() - drawingTime;//( System.nanoTime() - time ) / 1000000;
          Scribe.note("Drawing time: " + drawingTime + " ms");
          }
        else
          Scribe.error("FATAL ERROR - Cannot retrieve board!");
        }
      });
    
    }
  }




Java Source Code List

digitalgarden.bestboard.BoardParser.java
digitalgarden.bestboard.Board.java
digitalgarden.bestboard.MainActivity.java
digitalgarden.bestboard.Roller.java
digitalgarden.bestboard.TokenizerTest.java
digitalgarden.magicmerlin.scribe.Scribe.java
digitalgarden.magicmerlin.utils.Keyboard.java
digitalgarden.magicmerlin.utils.Rest.java
digitalgarden.magicmerlin.utils.Screen.java
digitalgarden.magicmerlin.utils.Tokenizer.java