New app in the Google Play Store!

I finished a new app yay! :). It gets your impulsiveness score by using the BIS-11 scale. With this application I learned:

  • How to change locale
  • How to support many languages
  • How to use different string.xml files for each language
  • How to create a global context to perform common tasks among activities
  • How to make a difference between android API’s
  • How to add a pop-up menu to the Action Bar
  • How to make the application make effective use of the “back button”
  • How to configure a Google Wallet account
  • How to get paid for applications
  • How to use different kinds of Dialogs

Following knowledge increased:

  • Weights
  • Layouts
  • Image Button
  • Toast
  • Android execution lifecycle

Stuff I enjoyed the most:

  • I created a chart by using buttons and weights
  • I got in contact with the research team of BIS-11
  • Providing multiple languages
  • Designing the icon
  • Providing support to Android 2.2

Challenges for the upcoming new project:

  • Use fragments
  • Use sherlock
  • Use Google API
  • Use OpenGL

https://play.google.com/store/apps/details?id=com.katzider.BIS11

Screen Shot 2014-05-18 at 12.06.21 PM

Advertisements

Refresh Options menu in API > 11 and API < 11

I let the user change the app locale whenever he feels like to do it. Menu strings have to meet the new language within this configuration change, in order to do that, the options menu has to be refreshed.

Keep in mind that there are two different ways to achieve this depending on whether you are using API > 11 or API < 11.

Code is really simple and goes as follows:

	@SuppressLint("NewApi")
	public static void refreshOptionsMenu(Activity activity, Menu menu)
	{
		int currentVersion = android.os.Build.VERSION.SDK_INT;
		if (currentVersion >= android.os.Build.VERSION_CODES.HONEYCOMB)
		{
			activity.invalidateOptionsMenu();
		}
		else if (menu != null)
		{
			menu.clear();
			activity.onCreateOptionsMenu(menu);
		}
	}

I added that method as static to a “GlobalContext” class so I can use it along with any of my activities. Enjoy.

Change locale within an Android application

I wanted users to have the ability to change application locale. Took me hours, but finally this is the code to do it. goBack() method forces a refreshment of strings among application visual elements.



public class LanguageMenu extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_language_menu);
	}
	
	public void selectEnglish (View view)
	{
		selectLanguage(new Locale("en"));
		goBack();
	}
	public void selectSpanish (View view)
	{
		selectLanguage(new Locale("es"));
		goBack();
	}
	public void selectItalian (View view)
	{
		selectLanguage(new Locale("it"));
		goBack();
	}
	public void selectPortuguese (View view)
	{
		selectLanguage(new Locale("pt"));
		goBack();
	}
	public void selectDutch (View view)
	{
		selectLanguage(new Locale("nl"));
		goBack();
	}
	public void selectLanguage(Locale locale)
	{
		Locale.setDefault(locale);
		Configuration config = new Configuration();
		config.locale = locale;
		getBaseContext().getResources().updateConfiguration(
				config, 
				getBaseContext().getResources().getDisplayMetrics());
	}
	public void goBack()
	{
		int activity_id = getIntent().getIntExtra("calling-activity", 0);
		Intent intent = null;
		switch(activity_id)
		{
			case ActivityConstants.ACTIVITY_QUESTIONS:
				intent = new Intent(this, QuestionScreen.class);
			break;
			case ActivityConstants.ACTIVITY_RESULTS:
				intent = new Intent(this, ResultsScreen.class);
			break;
			case ActivityConstants.ACTIVITY_SPLASH:
				intent = new Intent(this, SplashScreen.class);
			break;
		}
		startActivity(intent);
	}
}


Color scheme button generator for Android

Screen Shot 2014-02-10 at 9.49.21 PM

I was sicking tired of having to manually modify the HEX values of my XMLs every time I wanted to make a little change in the color. Also you have to modify three files: the idle, the pressed and the selector (at least for a basic rounded coloured button). The problem is actually bigger when you want to use a complete set of colours. I’m one of the most laziest persons all over the world and I’m a programmer so something smart was obligated to come up.

My solution for this problem is a perl script that receives the name of your color scheme, and a file with the Radius, Stroke and Color array information. At the end you will have three files per color inside a folder which you can put inside the drawable directory of your Android project.

Katziders-MacBook:Button Schemes katzider$ perl button_generator.pl -scheme_name Windows_8 -input_file windows_8.txt; ls -la Windows_8 | grep sky_blue

-rw-r--r--   1 katzider  staff  676 Feb 10 21:25 button_bg_sky_blue.xml

-rw-r--r--   1 katzider  staff  763 Feb 10 21:25 button_idle_sky_blue.xml

-rw-r--r--   1 katzider  staff  763 Feb 10 21:25 button_pressed_sky_blue.xml

Find detailed instructions in the header of the perl script. Even though the usage of this program should be straight forward, you can contact me in case of any problem =)

Download it here, includes the Windows 8 schema (or a very similar).

Screen Shot 2014-02-10 at 9.44.45 PM

P.S. I tried hard to do a good work on button_generator.pl, post your feedback if you have some.

Windows 7 button like (but rounded) Android buttons

Screen Shot 2014-02-10 at 1.01.02 AM

 

On activity code:


<Button

android:id="@+id/button24"

style="?android:attr/buttonStyleSmall"

android:layout_height="match_parent"

android:text="C"

android:textStyle="bold"

android:background="@drawable/idle_crimson"/>

On res/drawable/idle_crimson.xml


<shape xmlns:android="http://schemas.android.com/apk/res/android"

android:shape="rectangle" >

<!-- you can use any color you want I used here gray color-->

<solid android:color="#a20025"/>

<corners

android:bottomRightRadius="5dp"

android:bottomLeftRadius="5dp"

android:topLeftRadius="5dp"

android:topRightRadius="5dp"/>

<stroke

android:width="2dp"

android:color="#000000" />

</shape>

I got these colours from: google(“Windows 7 color scheme codes”);