Created
February 3, 2016 14:49
-
-
Save ruan65/000b0d6bf05e57468e27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package premium.app.dashdots; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.text.Editable; | |
import android.text.TextWatcher; | |
import android.view.KeyEvent; | |
import android.view.View; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
import butterknife.Bind; | |
import butterknife.ButterKnife; | |
import butterknife.OnClick; | |
import butterknife.OnLongClick; | |
public class MainActivity extends AppCompatActivity implements TextWatcher { | |
@Bind(R.id.tv_display) TextView tvDisplay; | |
@Bind(R.id.tv_q) TextView tvQ; | |
@Bind(R.id.tv_result) TextView tvResult; | |
@Bind(R.id.tap) View tap; | |
boolean dash; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
ButterKnife.bind(this); | |
tvDisplay.setOnEditorActionListener(new TextView.OnEditorActionListener() { | |
@Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { | |
return false; | |
} | |
}); | |
tvDisplay.setCursorVisible(false); | |
tvDisplay.addTextChangedListener(this); | |
} | |
@OnClick(R.id.btn_prev) | |
public void prev(View v) { | |
prevNext(); | |
} | |
@OnClick(R.id.btn_next) | |
public void next(View v) { | |
prevNext(); | |
} | |
private void prevNext() { | |
dash = !dash; | |
tvDisplay.setText(""); | |
tvResult.setText(""); | |
tvQ.setText(dash ? R.string.q2 : R.string.q1); | |
} | |
@OnClick(R.id.tap) | |
public void dot() { | |
tvDisplay.setText("."); | |
} | |
@OnLongClick(R.id.tap) | |
public boolean dash(View v) { | |
tvDisplay.setText("-"); | |
return true; | |
} | |
@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
} | |
@Override public void onTextChanged(CharSequence s, int start, int before, int count) { | |
} | |
@Override public void afterTextChanged(Editable s) { | |
tvResult.setText(tvDisplay.getText().toString().equals(dash ? "-" : ".") | |
? "Correct :)" | |
: "Wrong :("); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment