@Override public void onClick(View v) { if (v.getId() == save.getId()) { AlertDialog.Builder builder = new AlertDialog.Builder(MapMakerActivity.this); builder.setTitle("Confirmation"); final EditText input = new EditText(MapMakerActivity.this); input.setText(level.getName()); builder.setView(input); builder.setPositiveButton( "Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String name = input.getText().toString(); level.setName(name); boolean success = QvikPuzzleApplication.getInstance().getLevelUtil().saveLevelToDisk(level); if (success) { Toast.makeText(MapMakerActivity.this, "Level saved", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MapMakerActivity.this, "Level save failed", Toast.LENGTH_SHORT) .show(); } } }); builder.setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.show(); } else if (v.getId() == fill_empty.getId()) { board.fill(Config.SQUARE_EMPTY); } else if (v.getId() == fill_wall.getId()) { board.fill(Config.SQUARE_WALL); } else if (v.getId() == playerOrientation.getId()) { int tmp = board.getPlayerOrientation() + 1; if (tmp > 3) tmp = 0; board.setPlayerOrientation(tmp); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map_maker); ButterKnife.bind(this); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); board.setEditMode(true); radioEmpty.setChecked(true); radioEmpty.setButtonTintList(ColorStateList.valueOf(Config.COLOR_BACKGROUND)); radioWall.setButtonTintList(ColorStateList.valueOf(Config.COLOR_WALL)); radioStart.setButtonTintList(ColorStateList.valueOf(Config.COLOR_START)); radioGoal.setButtonTintList(ColorStateList.valueOf(Config.COLOR_GOAL)); // See if we are to edit an existing level if (getIntent().hasExtra("level")) { String levelName = getIntent().getStringExtra("level"); level = QvikPuzzleApplication.getInstance().getLevelUtil().loadLevelFromDisk(levelName); } else { // or are we creating a new level. // use the original/default level = QvikPuzzleApplication.getInstance().getLevelUtil().getDefaultLevel(); if (level == null) { level = new Level(); } // Generate name with timestamp level.setName("Level_" + new Date().getTime()); } if (level != null) { board.setLevel(level); int[] start = level.getStart(); board.setPlayerStart(start[1], start[0], level.getStartOrientation()); } else { Toast.makeText(MapMakerActivity.this, "Level load failed", Toast.LENGTH_SHORT).show(); finish(); return; } fill_empty.setOnClickListener(this); save.setOnClickListener(this); fill_wall.setOnClickListener(this); playerOrientation.setOnClickListener(this); }
public void onRadioButtonClicked(View view) { boolean checked = ((RadioButton) view).isChecked(); if (checked) { switch (view.getId()) { case R.id.radioEmpty: board.setBrush(Config.SQUARE_EMPTY); break; case R.id.radioWall: board.setBrush(Config.SQUARE_WALL); break; case R.id.radioStart: board.setBrush(Config.SQUARE_START); break; case R.id.radioGoal: board.setBrush(Config.SQUARE_GOAL); break; } } }