Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The line graph below uses scalable vector graphics (SVG) to plot the data. The chart uses the element to plot the data, but plots the

The line graph below uses scalable vector graphics (SVG) to plot the data. The chart uses the element to plot the data, but plots the data in the coordinate system of the data (using values that range from 100 to 1000 in the x and y and z axes).

The chart is plotted in an SVG canvas of size 400x700 pixels (shown by the large box). The coordinates of the upper-left and lower-right corners of this box are shown, and specifically that the origin of the SVG drawing canvas is in the upper-left.

Drawing the using its data as coordinates plots the data upside down in the upper-left portion of the canvas (since the origin of the SVG canvas is the upper left, but the origin of the chart should be in the lower left). We want to transform the coordinates of the element so the path extends across the plot area as shown in the dashed green solution. The coordinates of the upper-left and lower-right corners of this plot area are displayed in these corners.

We will use the SVG group element's transform attribute to transform the coordinates of the element. In this case, we will first scale the data using the "scale(xs,ss)" command to scale the data by the factor xs in the x direction and ys in the y direction. Then we will translate the data using the translate(xo,yo) command to add xo to the scaled x coordinate and yo to the scaled y coordinate.

The order of transformations may seem backwards, but it is best to think of these as functions, e.g. translate(scale(datapoint)).

You will need to figure out the appropriate scaling factors xs, ys and translation offsets xo,yo to convert the element's vertices from the datapoint coordinates to the SVG canvas coordinates. Press the redraw button to see the effects of the new parameters, and hand in your assignment once your black element matches up with the dashed green solution. MainActivity.java

public class MainActivity extends AppCompatActivity {

ToDoListDB toDoListDB; List arrayList; ToDoListAdapter adapter; ToDo selectedToDo; int selectedPosition; EditText txtName; Button addBtn; Boolean update = false;

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

txtName = (EditText) findViewById(R.id.txtName);

toDoListDB = new ToDoListDB(this); arrayList = toDoListDB.getList();

adapter = new ToDoListAdapter(this, (ArrayList) arrayList);

ListView listView = (ListView) findViewById(R.id.lstView); listView.setAdapter(adapter); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView arg0, View arg1, int position, long arg3) { removeItemFromList(position); return true; } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { selectedToDo = arrayList.get(position); selectedPosition = position; txtName.setText(selectedToDo.getName()); addBtn = (Button) findViewById(R.id.btnAdd); addBtn = (Button) findViewById(R.id.btnAdd);addBtn.setText("Update");update = true;

// add an appropriate addBtn() call here

} });

addBtn = (Button) findViewById(R.id.btnAdd); addBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String name = txtName.getText().toString(); addBtn.setText("Add");

// add your code here

} });

Button clearBtn = (Button) findViewById(R.id.btnClear); clearBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { reset(); } });

Button allBtn = (Button) findViewById(R.id.btnAll); allBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(getBaseContext(), AllTasksActivity.class); startActivity(intent); } }); }

protected void removeItemFromList(final int position) { AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);

alert.setTitle("Delete"); alert.setMessage("Do you want delete this item?"); alert.setPositiveButton("YES", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ToDo toDo = arrayList.get(position);

arrayList.remove(position); adapter.notifyDataSetChanged(); adapter.notifyDataSetInvalidated();

toDoListDB.remove(toDo.getId()); reset(); } }); alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } });

alert.show(); }

protected void reset() { txtName.setText("");

// add an appropriate addBtn() call here

selectedToDo = null; selectedPosition = -1; } }

class ToDoListAdapter extends ArrayAdapter { public ToDoListAdapter(Context context, ArrayList toDoList) { super(context, 0, toDoList); }

@Override public View getView(int position, View convertView, ViewGroup parent) { ToDo toDo = getItem(position);

if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(android.R.layout.simple_list_item_1, parent, false); }

TextView name = (TextView) convertView.findViewById(android.R.id.text1); name.setText(toDo.getName());

return convertView; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Statistics Learning From Data

Authors: Roxy Peck

1st Edition

495553263, 978-1285966083, 1285966082, 978-0495553267

More Books

Students also viewed these Programming questions

Question

Solve the following equations for x to five-figure accuracy

Answered: 1 week ago

Question

Evaluate the following expressions to six-figure accuracy.

Answered: 1 week ago