package com.example.usb; <<<<<<< HEAD import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; import android.support.v4.view.GestureDetectorCompat; import android.view.LayoutInflater; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import com.example.usb.map.MapDrawer; import com.example.usb.map.graphelems.Graph; import com.example.usb.map.graphelems.Node; import com.example.usb.map.graphelems.TransitNode; import com.example.usb.map.mapelems.Floor; import java.util.ArrayList; import java.util.LinkedList; public class About extends Fragment implements View.OnClickListener { //the values manipulated to move the surfaceView around ont he users screen int left; int top; int bottom; int right; //final values set later because different screens are different sized int fLeft; int fTop; int fBottom; int fRight; //this contains all the drawables for all the floors, if this was done for a different building //then this is the one line(s) that need to be changed according to the amount of floors // and their respective resource name int floors[] = {R.drawable.floor0, R.drawable.floor1, R.drawable.floor2, R.drawable.floor3, R.drawable.floor4, R.drawable.floor5, R.drawable.floor6}; //contains the nodes for a path //outer arrayList represent floors so index 0 is floor 0 //inner arrayList represent the nodes the user will go through in order start being index 0 ArrayList> path = new ArrayList>(); //this will contain all the floors as drawable once initialised //drawable are drawn onto the canvas Drawable[] maps = new Drawable[floors.length]; //canvas is like MS paint, it is the thing everything is being drawn onto Canvas canvas; //surface is the container for canvas, it displays it SurfaceView surface; //represents the floor that is being displayed on the map currently int current = 0; //this is the ratio of the images of the floor plans so it can be scaled correctly final double RATIO = 1.41; //this class draws the path the user will take onto the map MapDrawer MD = new MapDrawer(); ======= import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.ImageView; public class About extends Fragment { >>>>>>> 45fa345199d0c35abadd9326d1efd2607f97e25f @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); getActivity().setTitle("About"); <<<<<<< HEAD surface = (SurfaceView) getView().findViewById(R.id.surface); surface.getHolder().addCallback(new SurfaceHolder.Callback() { @Override public void surfaceCreated(SurfaceHolder holder) { canvas = holder.lockCanvas(); right = canvas.getWidth(); bottom = (int)(canvas.getWidth()/ RATIO); left = 0; top = 0; fRight = right; fBottom = bottom; fLeft = left; fTop = top; surface.getHolder().setFixedSize(right,bottom); mapGeneration(); surface.layout(left, top, right, bottom); holder.unlockCanvasAndPost(canvas); loadMap(current); } @Override public void surfaceDestroyed(SurfaceHolder holder) { } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } }); ======= >>>>>>> 45fa345199d0c35abadd9326d1efd2607f97e25f } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { <<<<<<< HEAD View v = inflater.inflate(R.layout.content_map_output, null); final Button floorUpBtn = v.findViewById(R.id.floorUpBtn); floorUpBtn.setOnClickListener(this); final Button floorDownBtn = v.findViewById(R.id.floorDownBtn); floorDownBtn.setOnClickListener(this); final Button lineTestBtn = v.findViewById(R.id.lineTestBtn); lineTestBtn.setOnClickListener(this); return v; } @Override public void onClick(View v) { switch (v.getId()) { case R.id.floorUpBtn: buttonOnClickUp(v); break; case R.id.floorDownBtn: buttonOnClickDown(v); break; case R.id.lineTestBtn: buttonOnClickPathTest(v); break; } } ////loads the map public void loadMap(int current){ canvas = surface.getHolder().lockCanvas(); surface.getHolder().setFixedSize(right,bottom); clearCanvas(); maps[current].draw(canvas); MD.place(path.get(current), canvas, surface); surface.getHolder().unlockCanvasAndPost(canvas); } //******************************************* //*** this crashes for some reason (test) *** //******************************************* //mock nodes being passed through for tests public void buttonOnClickPathTest(View v){ LinkedList finalPath = new LinkedList<>(); Floor f = new Floor(0); Graph g = f.getGraph(); path.get(0).add(new TransitNode(1,200,100,g)); path.get(0).add(new TransitNode(2,400,200,g)); path.get(0).add(new TransitNode(2,350,400,g)); // for (Node node: finalPath) { // switch (node.getGraph().getFloor().getLevel()) { // case 0: // node.setXPos(200); // node.setYPos(100); // path.get(0).add(node); // break; // } // } // path.get(0).add(new NodeTest(100,100)); // path.get(0).add(new NodeTest(1000,500)); // path.get(0).add(new NodeTest(1000,1000)); // path.get(0).add(new NodeTest(500,500)); // // path.get(1).add(new NodeTest(200,100)); // path.get(1).add(new NodeTest(500,500)); // path.get(1).add(new NodeTest(300,1000)); // path.get(1).add(new NodeTest(30,250)); // // path.get(2).add(new NodeTest(50,50)); // path.get(2).add(new NodeTest(500,600)); // path.get(2).add(new NodeTest(300,100)); // path.get(2).add(new NodeTest(30,250)); loadMap(current); } // buttons used for changing the floor map Up for up and down for down public void buttonOnClickUp(View v){ if(current != 6) { current++; loadMap(current); } } //check comment above (this is the down button) public void buttonOnClickDown(View v){ if(current != 0) { current--; loadMap(current); } } public void mapGeneration(){ for(int i = 0 ; i < floors.length ; i++){ maps[i] = ContextCompat.getDrawable(getContext(), floors[i]); maps[i].setBounds(left,top,right,bottom); path.add(new ArrayList()); } } public void clearCanvas(){ canvas.drawRect(fRight, canvas.getHeight(), fLeft, fTop , new Paint()); } ======= return inflater.inflate(R.layout.content_about, null); } >>>>>>> 45fa345199d0c35abadd9326d1efd2607f97e25f }