Wednesday, May 29, 2013

Android Studio and other things

 I downloaded and installed Android Studio. Once I was able to get it running ( I had to set a PATH) it ran ok. I checked it out for a bit and I might switch to it later but at the moment all Android Tutorials are based on Eclipse so it is easier to stick with Eclipse for now.

   I've started "Sams Teach Yourself Android Application Development" and have worked through 1/3 of it so far. What I like about this book over the others I have studied is that it has exercises that do not exactly follow what you just learned. You have to do a little research to complete them. I am debating what I should do after completing this book... Well it's not so much a debate as a search for what I should do. The main thing I need to do is create my own app beyond my tic tac toe game ( which is still a little buggy). Another thing is I am thinking of getting more advanced books but I might be doing that out of fear. What I mean by that is that I might be delaying actually publishing an app because I fear I am not ready.

  It's hard coming up with an original idea for an app. I thought I had one with "Virtual graffiti tagging" but it turns out someone has already made it. I might have still pursued it if I thought I could make a better version. I have a couple other ideas but are beyond my ability at the moment. They involve rather advanced graphics.




10,000 hour to Mastery.
10,000 - 434 = 9566 hours left  

Sunday, May 5, 2013

Importance of multi-device testing

 
I was learning a bit about using the keyboard for control from an example in a book when I ran in to a problem the book seemed to overlook ( or maybe I did). The example was showing how to detect and respond to keyboard inputs. Basically you touch the enter key and the text is suppose to change indicating the enter key was pressed. The problem was when you ran the example there was no keyboard displayed. After hunting around the internet I was able to piece this part together.

// SHOW KEYBOARD
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

   That took care of getting the keyboard to display.  Next I decided go beyond the book and make it change back to the original text when the letter 'b' was pressed. Not to hard and it worked fine on my phone and also the emulator but then I tried it on my tablet. For some reason after pressing one of the keys the focus would switch to the three dots at the top right corner (settings). Pressing enter a couple of times would bring the focus back to the activity. After a bit of thought I solved that problem by adding to the layout xml

android:focusable="true"

and now it works on the devices and emulator.

The code

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.WindowManager;
import android.widget.TextView;

public class HandlerExample extends Activity {

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

// SHOW KEYBOARD
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_handler_example, menu);
return true;
}

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
textUpdate();
return true;
} else if (keyCode == KeyEvent.KEYCODE_B) {
resetText();
return true;
}
return false;
}

public void textUpdate() {
TextView text = (TextView) findViewById(R.id.testText);
text.setText(R.string.enter);

}

public void resetText() {
TextView text = (TextView) findViewById(R.id.testText);
text.setText(R.string.before);
}

}

10,000 hour to Mastery.
10,000 - 415.5 = 9584.5 hours left