RSS

Not Yet Kenyan

chanyado

I have been trying to write this piece for the last two weeks, and it has been agonising. I wrung my brain, trying to come up with zingy openings that compel you to keep reading, descriptions that cut to the core of how I feel, and yet don’t come across as overly sentimental. I worried about over-generalising, over-simplifying, over-dramatizing. I worried about being politically correct. Most of all, I worried about laying it bare…. or starting to.

You see this one is really important to me.

In reality, I have been trying to write this piece for the last decade.

So I am just going to write it. Ungarnished.

I popped my storytelling cherry a few months ago, and was preparing to tell Trupti’s story from John Sibi Okumu’s Role Play. I usually force my family to listen to me practice. They have perfected the art of zoning out, making…

View original post 1,030 more words

 
Leave a comment

Posted by on April 30, 2014 in Uncategorized

 

2013 in review

The WordPress.com stats helper monkeys prepared a 2013 annual report for this blog.

Here’s an excerpt:

The concert hall at the Sydney Opera House holds 2,700 people. This blog was viewed about 42,000 times in 2013. If it were a concert at Sydney Opera House, it would take about 16 sold-out performances for that many people to see it.

Click here to see the complete report.

 
Leave a comment

Posted by on January 29, 2014 in Uncategorized

 

Rafiki

pschycological_footprints

Have you ever had an eternal friend.

The friend with whom you break every barrier with just to keep the friendship fire burning?

A friend you have argued with and gotten into a really bad fight with, and it seemed like it was the end? You know each other so well and know the very things that you dislike, the very things that would tear you down, and you take a spear to pierce through each other’s weak spots?You leave each other feeling naked and hopeless?And you both feel like you will be caught dead talking to each other ever again?!

true_friends6

When the wounds are healed and you no longer want to expose yourself like that to another friend, when you have finally gathered all your courage to move on, and somehow one way or another, you find yourselves pulled back together. You are both guilty about what you did…

View original post 597 more words

 
Leave a comment

Posted by on December 31, 2013 in Uncategorized

 

Proximity sensor tweek to give you Samsung galaxy s4 airwave feature

The recently released samsung galaxy s4 phone comes with some interesting features. This will be a look at how you can emulate the airwave feature on any ordinary android phone.

proximity-callThe proximity sensor is common on most smart-phones. This is because the primary function of a proximity sensor is to disable accidental touch events. The most common scenario being- The ear coming in contact with the screen and generating touch events, To solve this issue, device manufacturers came up with the idea of a placing a proximity sensor close to the speaker, which will then detect any object in the vicinity of the speaker.while on a call. We can use this to detect gestures made by user. The technology behind it is pretty neat and can be found by googling around.

The code below will allow one to detect when a user swipes across the phone without touching the screen, as soon as that event is registered the list view will scroll.

Lets start with the layout, place a list view on the layout:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context=".MainActivity" >

<ListView
 android:id="@+id/lvlist"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_alignParentTop="true" >
 </ListView>

</RelativeLayout>

And then inflate that layout on the java end. And place the following code


package com.example.proximity;

import java.util.ArrayList;

import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {

SensorManager mSensorManager;
 Sensor mproximity;

 ArrayList<String> items = new ArrayList<String>();

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

 //populate the arraylist
 for(int i = 0; i< 100; i++ ){
 items.add("Item " + i);
 }


 final ListView list = (ListView) findViewById(R.id.lvlist);
 list.setAdapter(new ArrayAdapter<String>(this,
 android.R.layout.simple_list_item_1, items));

 //Access the sensor manager
 mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
 mproximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);

//register a listener for the proximity sensor
 SensorEventListener proximityListener = new SensorEventListener() {

 //Incase of a gesture scroll the list
 @Override
 public void onSensorChanged(SensorEvent event) {
 // TODO Auto-generated method stub
 list.smoothScrollBy(200, 1000);
 }

 @Override
 public void onAccuracyChanged(Sensor sensor, int accuracy) {
 // TODO Auto-generated method stub

 }
 };

 mSensorManager.registerListener(proximityListener,
 mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY),
 SensorManager.SENSOR_DELAY_UI);

 }

&nbsp;

}

There are no permissions needed.

Screenshot_2013-08-16-15-32-49

This is just some basic implementation which has a lot of short comings, but with a few tweeks can bring up amazing features. You are welcomed to use the code and modify it.

 

 
7 Comments

Posted by on August 16, 2013 in Uncategorized

 

Voice To Text on Android

This is a code snippet in response to a request on how to recognise voice of a person. This is useful for the translator app, I built in some previous tutorial.

package com.gilo.voice;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class MainActivity extends Activity {

	Button speak;
	ListView options;
	ArrayList<String> results;

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

		speak = (Button) findViewById(R.id.bSpeak);
		options = (ListView) findViewById(R.id.lvOptions);

		speak.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// This are the intents needed to start the Voice recognizer
				Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
				i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
						RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
				i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say something");

				startActivityForResult(i, 1010);
			}
		});

		// retrieves data from the previous state. This is incase the phones
		// orientation changes
		if (savedInstanceState != null) {
			results = savedInstanceState.getStringArrayList("results");

			if (results != null)
				options.setAdapter(new ArrayAdapter<String>(this,
						android.R.layout.simple_list_item_1, results));
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		// retrieves data from the VoiceRecognizer
		if (requestCode == 1010 && resultCode == RESULT_OK) {
			results = data
					.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
			options.setAdapter(new ArrayAdapter<String>(this,
					android.R.layout.simple_list_item_1, results));
		}

		super.onActivityResult(requestCode, resultCode, data);
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		// This should save all the data so that when the phone changes
		// orientation the data is saved
		super.onSaveInstanceState(outState);

		outState.putStringArrayList("results", results);
	}

}

And for the xml file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <ListView
        android:id="@+id/lvOptions"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/button1" >
    </ListView>

    <Button
        android:id="@+id/bSpeak"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="Speak" />

</RelativeLayout>

Screenshot_2013-08-09-08-22-09

Screenshot_2013-08-09-08-24-06

 
9 Comments

Posted by on August 9, 2013 in Uncategorized

 

Android App >> Tukumbuke (Swahili for Let’s not forget)

581252_558653964152688_1363415599_n (1)
The years 2007 and 2008 were the worst years Kenya has ever had. It saw neighbors rise against each other and doing all sorts of inhumane things, destroying property and even killing each other. Now, five years later, we have a chance to choose our leaders again and every Kenyan has a choice to make about which path we gonna head.
Tukumbuke is an app I built at the Apps4Election event. We were in a team of about 8 brilliant guys. With tukumbuke we want to remind Kenyans of what happened when we let ethnicity come in between us. We wanted to also highlight the injustices done to our fellow Kenyans and give a voice to the Post Election Violence victims. There is a web version though its not yet up, a facebook page and a twitter handle.


Get it on Google Play

Below are the screenshots:

Screenshot_2013-02-16-12-41-11 Screenshot_2013-02-16-12-48-35 Screenshot_2013-02-17-12-55-01 Screenshot_2013-02-17-12-55-39 Screenshot_2013-02-18-06-22-44 Screenshot_2013-02-19-21-43-14 Screenshot_2013-02-19-21-42-38 Screenshot_2013-02-19-15-37-56 Screenshot_2013-02-16-12-34-36

 
Leave a comment

Posted by on February 20, 2013 in Uncategorized

 

My Apps << Translatr

Screenshot_2013-02-06-10-43-23

Screenshot_2013-02-06-12-44-18

 
13 Comments

Posted by on February 6, 2013 in Uncategorized

 

Android Tutorials << Building a Language Translator App with Text To Speech feature

One of my friends is going abroad – to Germany. I thought I’d make her an app that would let her enter what she wants to say in English translate it to German then speak it out.

Here goes:
I am going to be using the Bing Translate API – really cool coz they give u like two million queries, that’s a lot (unfortunately Google translate API isnt free).
First, download this java library. Place this in your libs folder.

We need the Client Id and Client username from the Microsoft MarkerPlace. Here are the instructions on how to get this.
 

I am gonna build this:
Screenshot_2013-02-05-15-07-38

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/etUserText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="31dp"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/tvTranslatedText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/etUserText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="168dp"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/bTranslate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/etUserText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:text="Translate" />

    <Button
        android:id="@+id/bSpeak"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvTranslatedText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="46dp"
        android:text="Speak" />

</RelativeLayout>

To get translated text do this:

public String translate(String text) throws Exception{
	// Set the Client ID / Client Secret once per JVM. It is set statically and applies to all services
       Translate.setClientId("CLIENT USERNAME");
       Translate.setClientSecret("CLIENT SECRET");
       
       String translatedText = "";
       
       // English AUTO_DETECT -> gERMAN Change this if u wanna other languages
       translatedText = Translate.execute(text,Language.GERMAN);
       return translatedText;
   }

The Text-To-Speech bit:

public class MainActivity extends Activity implements OnInitListener {

	private TextToSpeech tts;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        tts = new TextToSpeech(this, this);
        speakOut("Ich"); //This is how you will get the phone to  speak    
}

@Override
public void onInit(int status) {
	// TODO Auto-generated method stub
	if (status == TextToSpeech.SUCCESS) {
		 
        int result = tts.setLanguage(Locale.GERMAN);

        if (result == TextToSpeech.LANG_MISSING_DATA
                || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("TTS", "This Language is not supported");
        } else {
            
            //speakOut("Ich");
        }

    } else {
        Log.e("TTS", "Initilization Failed!");
    }
}
   
private void speakOut(String text) {
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}

And the complete code:

package com.gilo.translatr;

import java.util.Locale;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;

public class MainActivity extends Activity implements OnInitListener {

	private TextToSpeech tts;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        tts = new TextToSpeech(this, this);
        ((Button) findViewById(R.id.bSpeak)).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				speakOut(((TextView) findViewById(R.id.tvTranslatedText)).getText().toString());
			}
		});
        
        ((Button) findViewById(R.id.bTranslate)).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				
				
				class bgStuff extends AsyncTask<Void, Void, Void>{
					
					String translatedText = "";
					@Override
					protected Void doInBackground(Void... params) {
						// TODO Auto-generated method stub
						try {
							String text = ((EditText) findViewById(R.id.etUserText)).getText().toString();
							translatedText = translate(text);
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
							translatedText = e.toString();
						}
						
						return null;
					}

					@Override
					protected void onPostExecute(Void result) {
						// TODO Auto-generated method stub
						((TextView) findViewById(R.id.tvTranslatedText)).setText(translatedText);
						super.onPostExecute(result);
					}
					
				}
				
				new bgStuff().execute();
			}
		});
    }

   public String translate(String text) throws Exception{
	  
	   
	// Set the Client ID / Client Secret once per JVM. It is set statically and applies to all services
       Translate.setClientId("CLIENT ID"); //Change this
       Translate.setClientSecret("CLIENT SECRET"); //change
       
       
       String translatedText = "";
       
       translatedText = Translate.execute(text,Language.GERMAN);
	   
       return translatedText;
   }

@Override
public void onInit(int status) {
	// TODO Auto-generated method stub
	if (status == TextToSpeech.SUCCESS) {
		 
        int result = tts.setLanguage(Locale.GERMAN);

        if (result == TextToSpeech.LANG_MISSING_DATA
                || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("TTS", "This Language is not supported");
        } else {
            
            //speakOut("Ich");
        }

    } else {
        Log.e("TTS", "Initilization Failed!");
    }
}
   
private void speakOut(String text) {
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
   
}

There is a lot you can do, but I am feeling to lazy. Hope you learnt something.

[UPDATE] Check out the App here, I just gave it a better look but its still more or less the same thing described above.
 

 
58 Comments

Posted by on February 5, 2013 in Uncategorized

 

App

 

 
Screenshot_2013-02-04-08-22-52

Screenshot_2013-02-04-08-23-00

Screenshot_2013-02-04-08-23-09

Screenshot_2013-02-04-14-22-04

 
Leave a comment

Posted by on February 4, 2013 in Uncategorized

 

Android Tutorials – Load image from URL to an ImageView

Loading an image that isn’t defined in your resource folder in android can be really tricky. The image has to be downloaded asynchronously, cached in the phone in case we want to reuse later and then display it in the ImageView. Luckily there are many libraries that do just that and better. I am going to be using the ImageLoader lib.

    1. Download the ImageLoader lib here. (Google ‘android ImageLoader’ if link fails)
    2. Place the jar file in the libs folder in your project.
    3. This piece of code should do the trick:
String image_url = "https://mycodeandlife.wordpress.com/wp-content/uploads/2013/01/384088_2317070728022_2086719259_n.jpg";
ImageView image = (ImageView) findViewById(R.id.imageView1);
                        // Get singletone instance of ImageLoader
			ImageLoader imageLoader = ImageLoader.getInstance();
			// Initialize ImageLoader with configuration. Do it once.
			imageLoader.init(ImageLoaderConfiguration.createDefault(this));
			// Load and display image asynchronously

			DisplayImageOptions options = new DisplayImageOptions.Builder()
                        .showStubImage(R.drawable.ic_launcher) //this is the image that will be displayed if download fails
			.cacheInMemory()
			.cacheOnDisc()
			.build();

			imageLoader.displayImage(image_url, image, options);

This is the image. 384088_2317070728022_2086719259_n

The last bit is to add permissions to the Android Manifest. Add the following permissions: android.permission.WRITE_EXTERNAL_STORAGE and android.permission.INTERNET.

That’s it. Of course there still a lot more. You can use this in a list view and even show progress. You can read more here

 
8 Comments

Posted by on January 28, 2013 in Uncategorized