Skip to content

Commit

Permalink
Improve code generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Jun 8, 2015
1 parent b2e75d4 commit 14d7692
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public boolean onMenuItemClick(MenuItem item) {
public void startCodingActivity(View view) {
if (piyoCode == null) {
// 最初にコード入力画面に遷移するとき
startCodingActivity(lessonNumber, piyoCode);
startCodingActivity(lessonNumber, "");
} else {
// お手本確認に戻ってからコード入力画面に復帰する時
finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
lessonNumber = intent.getIntExtra("lessonNumber", 1);

String[][] cellTexts = initializeCellTexts();
String[][] cellTexts = initializeCellTexts(intent.getStringExtra("piyoCode"));
ImageView[][] cellIcons = initializeCellIcons(cellTexts);
initializeProgramIcons(cellTexts, cellIcons);
initializeNumberIcons(cellTexts, cellIcons);
Expand All @@ -35,26 +35,38 @@ public void onCreate(Bundle savedInstanceState) {
initializeMaximumStep(cellIcons, steps);
}

private String[][] initializeCellTexts() {
private String[][] initializeCellTexts(String piyoCode) {
String[][] cellTexts = new String[MAX_ROW][MAX_COLUMN];
for (int row = 0; row < cellTexts.length; row++) {
for (int column = 0; column < cellTexts[0].length; column++) {
cellTexts[row][column] = "";
}
}

String[] lines = piyoCode.split("\n");
int maxRow = Math.min(lines.length, cellTexts.length);
for (int row = 0; row < maxRow; row++) {
String[] texts = lines[row].split(" ");
int maxColumn = Math.min(texts.length, cellTexts[0].length);
for (int column = 0; column < maxColumn; column++) {
cellTexts[row][column] = texts[row];
}
}
return cellTexts;
}

private ImageView[][] initializeCellIcons(String[][] cellTexts) {
ImageView[][] cellIcons = new ImageView[cellTexts.length][cellTexts[0].length];
DragViewListener lastListener = null;
for (int row = 0; row < cellIcons.length; row++) {
for (int column = 0; column < cellIcons[0].length; column++) {
int id = getResources().getIdentifier("cell_" + row + "_" + column, "id", getPackageName());
cellIcons[row][column] = (ImageView) findViewById(id);
DragViewListener listener = new DragViewListener(this, cellIcons, cellTexts);
cellIcons[row][column].setOnTouchListener(listener);
lastListener = new DragViewListener(this, cellIcons, cellTexts);
cellIcons[row][column].setOnTouchListener(lastListener);
}
}
lastListener.setProgramIcons();
return cellIcons;
}

Expand Down Expand Up @@ -176,9 +188,6 @@ public void startCoccoActivity(View view) {

public void startEvaluationActivity(View view) {
String piyoCode = getIntent().getStringExtra("piyoCode");
if (piyoCode == null) {
piyoCode = "";
}
startEvaluationActivity(lessonNumber, piyoCode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

import com.google.common.base.Joiner;

import net.exkazuu.mimicdance.R;
import net.exkazuu.mimicdance.interpreter.IconType;

Expand Down Expand Up @@ -102,7 +104,7 @@ private void pushProgramTextsToLeft() {
}
}

private void setProgramIcons() {
public void setProgramIcons() {
for (int row = 0; row < cellTexts.length; row++) {
for (int column = 0; column < cellTexts[0].length; column++) {
IconType iconType = IconType.getByText(cellTexts[row][column]);
Expand All @@ -120,12 +122,10 @@ private void setProgramIcons() {
private void setPiyoCode() {
StringBuilder builder = new StringBuilder();
for (int row = 0; row < cellTexts.length; row++) {
for (int column = 0; column < cellTexts[0].length; column++) {
builder.append(cellTexts[row][column]);
}
builder.append("\n");
builder.append(Joiner.on(' ').join(cellTexts[row]).trim());
builder.append('\n');
}
activity.getIntent().putExtra("piyoCode", builder.toString());
activity.getIntent().putExtra("piyoCode", builder.toString().trim());
}

public Location getCellLocation(View view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected void onListItemClick(ListView l, View v, int position, long id) {

Intent intent = new Intent(this, CoccoActivity.class);
intent.putExtra("lessonNumber", position + 1);
intent.removeExtra("piyoCode");
startActivity(intent);
}
}

0 comments on commit 14d7692

Please sign in to comment.