Back to project page BoxSorter.
The source code is released under:
GNU General Public License
If you think the Android project BoxSorter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.silverhillapps.boxsorter; // w w w. ja v a 2 s. com import com.silverhillapps.boxsorter.entities.Element; import com.silverhillapps.boxsorter.entities.InitialPositionConfig; import com.silverhillapps.boxsorter.loader.InitialConfLoader; import com.silverhillapps.boxsorter.loader.LoaderFactory; import com.silverhillapps.boxsorter.views.BoxCanvasView; import android.support.v7.app.ActionBarActivity; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.Button; public class BoxSorterActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_box_sorter); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment()).commit(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.box_sorter, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } /** * This is the fragment which contains the views */ public static class PlaceholderFragment extends Fragment { private Button mSuckInButton; private Button mAddShapeButton; private BoxCanvasView mCanvasView; //main view that stores the canvas for the application private InitialConfLoader loader; //Loader determined by the mCanvasView parameter origin in xml private InitialPositionConfig positions; //Initial positions generated by the loader public PlaceholderFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_box_sorter, container, false); mCanvasView = (BoxCanvasView)rootView.findViewById(R.id.boxCanvasView); mSuckInButton = (Button)rootView.findViewById(R.id.suck_in_button); mAddShapeButton = (Button)rootView.findViewById(R.id.add_shape_button); mSuckInButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mCanvasView.removeAllElements(); } }); mAddShapeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Element e = addNewElement(); mCanvasView.addNewElement(e); } }); // The loader generates the initial figures, and add them into the canvas loadElements(); mCanvasView.addInitialValues(positions); return rootView; } /** * Internal method for generating the loader and for creating the initial elements which are going to be displayed from the beginning */ private void loadElements() { //The loader is determined through the origin parameter in the layout. LoaderFactory lf = new LoaderFactory(); // This factory should be injected instead of manually created loader = lf.getLoader(mCanvasView.getSourceElements()); positions = loader.loadElements(); } /** * Method that creates a new Element from loader. * @return the new Element to be displayed */ private Element addNewElement(){ return loader.addElement(); } } }