Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKrzysztof Paz
7,361 PointsTiny extension for the Build a Simple Android App project (Ben's CrystallBall App)
Hi, recently I've made trough the initial Android programming project called Build a Simple Android App, which is by the way great introduction to Android development in my opinion, so first of all I would like to say thank you Ben, this is good job.
In some last steps in that topic, I've realized that you could consider adding one small extension to the CrystallBall App code, that would make not only the app easy to test under emulator to the very end of the story but also provide itself some tiny addenum to the app while running on real phone.
So, the idea is really basic β just add another listener for detecting when user touches the crystal ball image, just to provide another way to trigger the event of generating answer.
//Here is the Benβs orginal approach in the MainActivity class:
mSensorMan = (SensorManager) getSystemService(SENSOR_SERVICE);
mAccelerometer = mSensorMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mShakeDet = new ShakeDetector(new OnShakeListener() {
@Override
public void onShake() {
handleNewAnswer();
}
});
//---> and here is my tiny extension, to detect touch of image area and call same event handler method as the shake detector does:
ImageView crystallBallImage = (ImageView) findViewById(R.id.imageView1);
crystallBallImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
handleNewAnswer();
}
});
//In case that now we would have two activation methods, this might be also useful screen message on starting the app (also showing users some real usage of the Toast):
Toast.makeText(this, "TOUCH or SHAKE", Toast.LENGTH_LONG).show();
Iβve tested that piece on few emulators and also with Samsung Ace2/GT-I8160 real hardware powered by Android 4.1.2/XEO and it worked fine, so if you would find that idea useful, the please feel free to use it and the mentioned code in your course for better user experience at the initial Android programming project chapters.
Best regards, Kris.
1 Answer
Ben Jakuben
Treehouse TeacherI love that, Kris! Thanks for sharing! I will consider this when it comes time to refresh that project, too.