Skip to content

Commit

Permalink
Merge pull request #3 from clinchergt/cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
Pikamander2 committed Jan 5, 2015
2 parents 941cacc + 8270ac4 commit 9350f84
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 115 deletions.
16 changes: 8 additions & 8 deletions src/com/pikamander2/japanesequiz/ExpandableHeightGridView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@

public class ExpandableHeightGridView extends GridView
{

boolean expanded = false;

public ExpandableHeightGridView(Context context)
{
super(context);
}

public ExpandableHeightGridView(Context context, AttributeSet attrs)
{
super(context, attrs);
}

public ExpandableHeightGridView(Context context, AttributeSet attrs,
int defStyle)
{
super(context, attrs, defStyle);
}

public boolean isExpanded()
{
return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
Expand All @@ -43,7 +43,7 @@ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
int expandSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);

ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
Expand All @@ -52,7 +52,7 @@ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}

public void setExpanded(boolean expanded)
{
this.expanded = expanded;
Expand Down
49 changes: 24 additions & 25 deletions src/com/pikamander2/japanesequiz/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,86 +11,85 @@

import com.pikamander2.japanesequiz.R;

public class MainActivity extends Activity
public class MainActivity extends Activity
{
public final static String EXTRA_QUIZ_ID = "com.example.myfirstapp.MODE_ID";

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

setupListeners();
}


private void setupListeners()
{
Button buttonHiragana = (Button)findViewById(R.id.buttonHiragana);
Button buttonKatakana = (Button)findViewById(R.id.buttonKatakana);
Button buttonMixture = (Button)findViewById(R.id.buttonMixture);

buttonHiragana.setOnClickListener(hiraganaButtonPressed);

buttonKatakana.setOnClickListener(katakanaButtonPressed);

buttonMixture.setOnClickListener(mixtureButtonPressed);
}
public OnClickListener hiraganaButtonPressed = new OnClickListener()

public OnClickListener hiraganaButtonPressed = new OnClickListener()
{
public void onClick(View view)
public void onClick(View view)
{
switchActivity(view, 1);
}
};
public OnClickListener katakanaButtonPressed = new OnClickListener()

public OnClickListener katakanaButtonPressed = new OnClickListener()
{
public void onClick(View view)
public void onClick(View view)
{
switchActivity(view, 2);
}
};
public OnClickListener mixtureButtonPressed = new OnClickListener()

public OnClickListener mixtureButtonPressed = new OnClickListener()
{
public void onClick(View view)
public void onClick(View view)
{
switchActivity(view, 4);
}
};



public void switchActivity(View view, int quizID)
{
Intent intent = new Intent(this, QuizActivity.class);
intent.putExtra(EXTRA_QUIZ_ID, quizID);
startActivity(intent);
}

public void mixtureButtonPressed(View view)
{
switchActivity(view, 4);
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();

if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}
32 changes: 16 additions & 16 deletions src/com/pikamander2/japanesequiz/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import java.util.Collections;
import java.util.Random;

public class Question
public class Question
{
private Random random = new Random();

private ArrayList<String[]> listToUse;

private int listId;

private static String[][] tempHiraganaList = {{"あ", "a"},{"い", "i"},{"う", "u"},{"え", "e"},{"お", "o"},
{"か", "ka"},{"き", "ki"},{"く", "ku"},{"け", "ke"},{"こ", "ko"},
{"さ", "sa"},{"し", "shi"},{"す", "su"},{"せ", "se"},{"そ", "so"},
Expand All @@ -30,9 +30,9 @@ public class Question
{"ば", "ba"},{"び", "bi"},{"ぶ", "bu"},{"べ", "be"},{"ぼ", "bo"},
{"ぱ", "pa"},{"ぴ", "pi"},{"ぷ", "pu"},{"ぺ", "pe"},{"ぽ", "po"}
};

private static ArrayList<String[]> hiraganaList = new ArrayList<String[]>(Arrays.asList(tempHiraganaList));

private static String[][] tempKatakanaList = {{"ア", "a"},{"イ", "i"},{"ウ", "u"},{"エ", "e"},{"オ", "o"},
{"カ", "ka"},{"キ", "ki"},{"ク", "ku"},{"ケ", "ke"},{"コ", "ko"},
{"サ", "sa"},{"シ", "shi"},{"ス", "su"},{"セ", "se"},{"ソ", "so"},
Expand All @@ -50,32 +50,32 @@ public class Question
{"バ", "ba"},{"ビ", "bi"},{"ブ", "bu"},{"ベ", "be"},{"ボ", "bo"},
{"パ", "pa"},{"ピ", "pi"},{"プ", "pu"},{"ペ", "pe"},{"ポ", "po"}
};

private static ArrayList<String[]> katakanaList = new ArrayList<String[]>(Arrays.asList(tempKatakanaList));

public Question(int tempListId)
{
listId = tempListId;
setList(tempListId);
}

public void shuffleQuestions()
{
if (listId == 4)
{
setList(4);
}

Collections.shuffle(listToUse);
}

public void setList(int tempListId)
{
if (tempListId == 4)
{
tempListId = random.nextInt(2) + 1;
}

switch(tempListId)
{
case 1:
Expand All @@ -86,27 +86,27 @@ public void setList(int tempListId)
break;
}
}

public String getAnswer(int charID, boolean romajiFirst)
{
if (romajiFirst)
{
return listToUse.get(charID)[0];
}

else
{
return listToUse.get(charID)[1];
}
}

public String getQuestion(int charID, boolean romajiFirst)
{
if (romajiFirst)
{
return listToUse.get(charID)[1];
}

else
{
return listToUse.get(charID)[0];
Expand Down
42 changes: 15 additions & 27 deletions src/com/pikamander2/japanesequiz/QuestionAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,28 @@
import android.widget.BaseAdapter;
import android.widget.Button;

public class QuestionAdapter extends BaseAdapter
public class QuestionAdapter extends BaseAdapter
{
private QuizActivity mContext;

public ArrayList<String> choices = new ArrayList<String>();
public ArrayList<Button> buttons = new ArrayList<Button>();

public Random random = new Random();
public static Question question;

public QuestionAdapter(Context c, Question q)
public QuestionAdapter(Context c, Question q)
{
mContext = (QuizActivity)c;
question = q;
}

public void changeAnswers(boolean romajiFirst)
{
if (romajiFirst)
{
buttons.get(0).setText(question.getAnswer(0, romajiFirst));
buttons.get(1).setText(question.getAnswer(1, romajiFirst));
buttons.get(2).setText(question.getAnswer(2, romajiFirst));
buttons.get(3).setText(question.getAnswer(3, romajiFirst));
}

else
{
buttons.get(0).setText(question.getAnswer(0, romajiFirst));
buttons.get(1).setText(question.getAnswer(1, romajiFirst));
buttons.get(2).setText(question.getAnswer(2, romajiFirst));
buttons.get(3).setText(question.getAnswer(3, romajiFirst));
}

buttons.get(0).setText(question.getAnswer(0, romajiFirst));
buttons.get(1).setText(question.getAnswer(1, romajiFirst));
buttons.get(2).setText(question.getAnswer(2, romajiFirst));
buttons.get(3).setText(question.getAnswer(3, romajiFirst));
}

public void makeButtons()
Expand All @@ -61,30 +49,30 @@ public void makeButtons()
newButton.setTextColor(Color.rgb(255,255,255));
}
}
public int getCount()

public int getCount()
{
return 4;
}

public Object getItem(int position)
public Object getItem(int position)
{
return null;
}

public long getItemId(int position)
public long getItemId(int position)
{
return 0;
}

// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent)
public View getView(int position, View convertView, ViewGroup parent)
{
if (buttons.size() == 0)
{
makeButtons();
}

return buttons.get(position);
}
}
Loading

0 comments on commit 9350f84

Please sign in to comment.