Android Dev: Top 5 Scores in a Game App in Java/Eclipse

Email Questions to developer[@]androidprogramming.mobi

Use of:
top5-Sqlite-Files-SharedPref code in Java insert in the Activity top5 used…

Use of Files – you call scoreSaveReturn(WithIntegerCurrentPlayScore)

//---FILE VER----top5 record scores------
public static int[] highscores = new int[] { 10, 8, 5, 3, 1 };  //DEFAULT

private String scoreSaveReturn2(int totalPoints) {
	performRetreiveFromFileScores4("scores7");   // not comment if use files
	//performRetreiveFromFileScores4SharedPref();  // not comment if use shared pref
	//performRetreiveFromSQLITEScores4();            // not comment if use SQLITE
	addScore(totalPoints);  // not comment
	performSaveToFileScores(highscores);           // not comment if use files
	//performSaveToFileScoresSharedPref(highscores);// not comment if use shared pref
	// performSaveToFileScoresSQLITE(highscores);       // not comment if use SQLITE
	return printScores(highscores);  // not comment

}
int k=10;
public void addScore(int score) {
for (int i = 0; i < 5; i++) {
if (highscores[i] < score) {
for (int j = 4; j > i; j--)
highscores[j] = highscores[j - 1];
highscores[i] = score;
k=i;
break;
}
}
}
private void performSaveToFileScores(int[] x) {
String strFileContent="";
for (int i = 0; i < 4; i++) {
strFileContent += ""+x[i]+",";
}
strFileContent += ""+x[4];
String f = "scores7";
try {
FileOutputStream oStream = openFileOutput(f, Context.MODE_PRIVATE);
oStream.write(strFileContent.getBytes());
oStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void performRetreiveFromFileScores(String filename) {
try {
FileInputStream in = openFileInput(filename);
//Log.i("filename", "filename as read -> " +filename);
InputStreamReader inputStreamReader = new InputStreamReader(in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder sb = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line);
}
//Log.i("line", "sb as read -> " +sb);
//Log.i("line", "line as read -> " +line);
int k=0;
StringTokenizer st = new StringTokenizer(sb.toString(), ",");
while (st.hasMoreTokens()) {
highscores[k]=Integer.parseInt(st.nextToken());
k++;
}
}
catch (IOException e){
e.printStackTrace();
}
}
private String printScores(int [] highscores1) {
String scoresTop5 = "Top Scores:\n";
int[] highscores=highscores1;
String z="";
for (int i = 0; i<5; i++) {
if (k==i) { z=" *"; } else z="";
scoresTop5 += (i+1) + ": " + highscores[i] + z +"\n";
}
return scoresTop5;
}
 //---FILE VER------top5 record scores---^---

Use of Shared Preferences – you replace performRetreiveFromFileScores(String filename) / performSaveToFileScores(int[] x)

Please remove “String filename” from first method

private void performSaveToFileScoresSharedPref(int[] x) {
	//this does the actual file saving.
	// set the filename in the interface:
	String strFileContent="";
	for (int i = 0; i < 4; i++) {
		strFileContent += ""+x[i]+",";
	}
	strFileContent += ""+x[4];

    SharedPreferences prefs = getSharedPreferences("top5",MODE_PRIVATE);
	SharedPreferences.Editor editor = prefs.edit();
	editor.putString("strFileContent", "");
	editor.commit();
}

private void performRetreiveFromFileScores4SharedPref() {
	try {

        SharedPreferences prefs = getSharedPreferences("top5",MODE_PRIVATE);
        String line;
        line = prefs.getString("strFileContent", "");

		int k=0;
		StringTokenizer st = new StringTokenizer(line, ",");
		while (st.hasMoreTokens()) {
			highscores[k]=Integer.parseInt(st.nextToken());

			k++;

		}
	}
	catch (Exception e){
		e.printStackTrace();
	}
}

Use of SQLite – you replace performRetreiveFromFileScores(String filename) / performSaveToFileScores(int[] x)


// SQLITE ONLY START
private static final String DATABASE_NAME = "TOP5";
private SQLiteDatabase database; // database object
private DatabaseOpenHelper databaseOpenHelper; // database helper
private static final int DATABASE_VERSION = 2;

private class DatabaseOpenHelper extends SQLiteOpenHelper
{
   // public constructor
   public DatabaseOpenHelper(Context context, String name,
      CursorFactory factory, int version)
   {
      super(context, name, factory, version);
   } // end DatabaseOpenHelper constructor

   // creates the contacts table when the database is created
   @Override
   public void onCreate(SQLiteDatabase db)
   {
      // query to create a new table named contacts
      String createQuery = "CREATE TABLE top " + "(_id integer primary key autoincrement," + "top5 TEXT);";

      db.execSQL(createQuery); // execute the query
   } // end method onCreate

   @Override
   public void onUpgrade(SQLiteDatabase db, int oldVersion,
       int newVersion)
   {

   } // end method onUpgrade
} // end class DatabaseOpenHelper

// SQLITE ONLY END

private void SQLITE() {
	databaseOpenHelper = new DatabaseOpenHelper(getBaseContext(), DATABASE_NAME, null, DATABASE_VERSION);
	database = databaseOpenHelper.getWritableDatabase();

}

private void performSaveToFileScoresSQLITE(int[] x) {
	//this does the actual file saving.
	// set the filename in the interface:
	String strFileContent="";
	for (int i = 0; i < 4; i++) {
		strFileContent += ""+x[i]+",";
	}
	strFileContent += ""+x[4];

    SharedPreferences prefs = getSharedPreferences("top5",MODE_PRIVATE);
	SharedPreferences.Editor editor = prefs.edit();
	editor.putString("strFileContent", "");
	editor.commit(); 

	try {
		SQLITE();
		ContentValues editContact = new ContentValues();
		editContact.put("name", strFileContent);

		database.update("contacts", editContact, "_id=" + 0, null);	

	}
	catch (Exception e){
		e.printStackTrace();
	}	

	if (database != null)
        database.close();

}
private void performRetreiveFromSQLITEScores4() {
	try {
		SQLITE();
		Cursor result = database.query("top", null, "_id=" + 0, null, null, null, null);
		result.moveToFirst();

		int nameIndex = result.getColumnIndex("name");

	int k=0;
	StringTokenizer st = new StringTokenizer(result.getString(nameIndex), ",");
	while (st.hasMoreTokens()) {
		highscores[k]=Integer.parseInt(st.nextToken());

		k++;

	}

	result.close();
	}
	catch (Exception e){
		e.printStackTrace();
	}	

	if (database != null)
        database.close();
}

 

 

Posted in android, development, eclipse ide, java, technical | Tagged , | Comments Off

Android Apps MarketPlaces

Android Apps MarketPlaces

Android Apps may get downloaded & installed from:

http://en.wikipedia.org/wiki/List_of_mobile_software_distribution_platforms

https://play.google.com/store/apps former Google App Market Place

http://www.androidpit.com/en/android-market

http://androidfreeware.net/

http://www.androidzoom.com/

http://www.bestappsmarket.com

http://www.appbrain.com/

http://www.andappstore.com

http://www.androidguys.com/home.asp

http://www.youpark.com

http://www.zeewe.com

http://www.getjar.com

http://www.mplayit.com

http://www.pocketgear.com

http://www.handango.com/homepage/Homepage.jsp?deviceId=2433

http://getandroidstuff.com

http://htcapps.com/

http://www.freewarelovers.com/android

http://slideme.org/

http://game.afreecodec.com/android/

————————————————
Mfg Sites:

http://www.samsungapps.com/

http://www.lgworld.com/

http://developer.motorola.com/shop4apps/

————————————————

www.amazon.com/b?node=2350149011 Android App Store only for US

http://www.dmoz.org/Computers/Systems/Handhelds/Android/Apps/

 

http://www.gsmarena.com/ http://www.androidphonesarena.com

 

Note: this article in Under Development, please check back soon!
Also coming Android/Java/Eclipse Forums List/Article!



Posted in android, development, eclipse ide, java, technology | Tagged , , , , , | Comments Off

The benefits and drawbacks of modern technology

When someone refers for today’s modern technology, surely he refers to the 21st century, Information Age and the Internet as the communication media of the new millennium. Of course this 17 year history of the Internet brought indirectly many significant advances in other Science and Technology fields. Without doubt Internet changed our lives for ever decisively and absolutely.

Today, just with a PC and an internet connection, without additional costs you can send instantly and receive instantly messages(emails) from the other corner of the world just not long before ago you have to await letter to get to recipient in about 7 days if not lost in transit and other so the reply to return to you. Now you can find almost any piece of info with a web browser and chat (eg.Skype), again freely using text, audio or even video.

Another area of technology bring change to us, is Mobile Communications. We are NOT away from the fact each individual, will posses a mobile phone for fun or for business, anywhere he is in the world, anytime. Today exists such services in the mobile world as talking, Small Message Service (SMS), Multimedia Message Service (MMS), or chatting with text, and also accessing the Internet from mobile phone using either wifi access point or 3G cellular internet, and hence you may browse or send email or use some other service of the Internet, anywhere and anytime. Coming is Mobile video calling.

Of course Mobile Communications is very closely related to the Internet, both networks belonging to Electronic Age Revolution of computers in general. This top edge of technology brings us many benefits as well as drawbacks too.

Benefits include fast and more accurate communications and business. Now for example in case of danger eg car accident away from the town, you can use your mobile to call the emergency number immediately and authorities to find automatically using cellular network services, your position on the map you call from, so help come accurately and immediately.

Internet makes us more Socialable people in all steps of life, Social Internet Networks are on rise these days. Now our time is better spent, and use efficiently. Rather use snail mail now we are using email, rather use standard telephone network call now we are using chatting via text, audio, video and file transfer. Almost now any info can get accessed via a web browser using an Internet search engine.

Chatting etc services brings fun, work and education too. Leaning online is a consequence of all these. Now universities provide part or full degrees online. This use of internet technology tools and cost is only from university fees. Also language learning can be taken with technology and resources of the Internet. All these are a click away.

As of security now when you are away, you can watch your office or home via security cameras through the internet. Also when you plan a trip domestic or international, on the Internet you can plan and book everything for it. Also, your Bank can accessed via internet banking with a web browser, so as access accounts, transfer money, order replacements etc.

On the other hand beyond these benefits, Internet Age brings and some subtle drawbacks.

Now when you are online your Internet PC without even know it can get compromised by bad guys, that can stole anything from company data to credit card numbers covering their tracks. The attacks can be done on Internet Servers as well, making services unavailable, may be in emergency sometimes. Banks are on instant danger for example, a bad guy may change account data and more.

Of course many anti-criminal tools exist like anti-virus tools, anti-malware, anti-spyware and so on, that must be considered by any Internet user.

Of course as internet makes us smarter, so does smarter the street thieves too. So we must be careful in using all of our possessions, and especially credit cards in front of cameras in all steps of life. Thieves continue to discover new ways, to draw your attention, and so on and so forth.

Finally I think new technology has brought many advantages and drawbacks. People behind the internet and technology think well before they create it, so as to advance our lives and NOT to degrade it. So in my opinion I believe, modern technology has brought more goods to us, rather than drawbacks. In case of drawbacks exist always an anti solution. Technology is going to advance, but as we proceed this is going more slowly, and it will stay good for us, in all its way.

Posted in internet, learning, other, security, social, technology | Tagged | 942 Comments

Leaflet: Security of your Possessions while you are traveling

When you plan to travel abroad you must take actions, “Before you go” as well as “During your stay” and also “On your return”.

Here are the most important actions you must take care of:

A) Before you go

Money & ID matters

Make two photocopies of your Passport, ID card, Drivers License, Credit Cards, and Airline or Sea Tickets. Also note your Laptop and Mobile phone S/Ns etc id numbers and characteristics so can identified in case found after lost. Keep one copy in your home and the other in your suitcase not near your valuables.

Do NOT take with you, all your credit cards, Social security card but only the necessary ones. Do not keep all cards or valuables in one place but in two places.

Better take with you an old mobile phone or old laptop without important data on them like passwords, you may just want to access with this laptop your bank account over the internet, but only in secure places like your hotel, but not in internet cafes.

After contact your Bank saying you plan to travel in the particular country for any advice tips has and can give. Ask in case of lost or theft of money possessions like cards or cash how to cancel and how to replace them anywhere in the places you plan to travel taking all possibilities. Learn phone numbers or web sites you can disable cards in case of lost or order new ones along with cash. Keep these along photocopies above and on your mobile phone. Also keep emergency numbers in the visited country like Hospital, Police, Fire, Hotel, Taxis, and your embassy of course.

Country profile

First read country profile, and learn about laws & customs, criminality, maps, transport routes, internet criminality, and recent news. All can found online.

General

Also it is good if, in a country where English is spoken in a small scale, to learn some local language words/phrases and bring with you a Language-to-Language Dialogs pocket-book, this could be used anywhere in your trip.

Laptop & Mobile Phone (wifi/3G/Roaming)

Find out on your trip places and stays where could you have safe internet connection (May for internet banking) and also arrange with your cellular and internet provider in your home country, roaming costs and plans for the visited country. You may consider buying a Roaming Data plan for your internet connections, for one month from your cellular provider.

Notify some family members or some friends only of your trip, and say for example if not on the phone every 2-3 days something happened.

B) During your stay

Hotel

While you are going out of your hotel get with you 2 credit cards and some cash only, rest leave the in hotel safe along with all other ID materials. Keep the pre-referred photocopies in your suitcase.

Lock always the hotel room.

Transportation

Take only authorized taxis.

On trains, trams or buses you may drugged and robbed while sleeping. Avoid long waits in terminals; hence pickpockets, thieves, and violent offenders are common in such areas.

Laptop theft is common in Airports.

Laptop & Mobile Phone (wifi/3G/Roaming)

Use wifi or Ethernet internet connection of your Hotel, but not in internet cafes hence they are more secure. Bad guys may compromise your connection at times and steal private info or install malware in your laptop.

Do not attach Devices in your laptop like USB memory sticks.

Do Logon to company network only from company’s laptop.

If you lost your Laptop or/and Mobile Phone immediately report it, to local authorities and to your consulate with your photocopies and ID numbers.

Money Matters

If you lose your wallet (all or part of your possessions) immediately report it, to local authorities and to your consulate along provide your photocopies. Also call your bank’s staff for this purpose, so as to cancel credit cards and send replacements to your hotel or consulate.

Before you depart for your home country

Just when everything went ok and ready for departure, in your hotel, compare/check/count all your possessions and ID Documents with photocopies like credit cards, traveler’s checks left, Passport, Driving License. If something is missing notify Authorities or Bank immediately.

C) On your return

On your return compare/check/count all your possessions and ID Documents with photocopies like credit cards, traveler’s checks left, Passport, Driving License. If something is missing notify Authorities or Bank immediately.

Also just on arrival home and too thereafter 1 or 2 months, check your Bank Accounts and credit cards statements online from your online bank account, for any malware activity. If you detected anything, you should contact your bank immediately to cancel the credit card(s).

Links: FBI, travel.state.gov, trusty-travel-tips.com, Int’l SOS, Other


Posted in internet, non-internet, other, security, social | Tagged , , | 932 Comments

Learn A New Language – via Internet

Today is the best time for new Language, learners. Of course, I mean today Internet technology. Learning of course, has to make the big effort for it. Of course if you know 2-3 languages to learn another must be easier, also language are categorized by difficulty
http://en.wikibooks.org/wiki/Language_Learning_Difficulty_for_English_Speakers.
I write this as a Russian learner, for my blog. I choose Russian as, the language has/use 20% of Greek and English words (eg robot=робот=ροπότ).

The major teaching communication (with distance teacher) tool I use is the free Skype Internet messager [www.skype.com], of course you may use similar free chat/messager tools like GoogleTalk, MSN, …etc but you must use identical tool with teacher. With Skype you may have teacher to student or, teacher to students (group talk), free voice/text/video chat or even screen sharing (Skype 5). With Skype you may also send files to your talking partner… Email clients also used widely for many matters about this.

You can find a teacher easily online using special websites like
http://language-school-teachers.com
. Here you register free as a teacher or as a student saying the languages you speak and the current interested language to learn. Teachers then look for you, or you(as student) may search/browse for teachers by the language they teach, country they are located, and so on. If you want group lessons which I do not like (by one to one talking you gain more and teacher has to do only with you, although cost is bigger in this case, not as in a group which cost is shared) you may find friends locally or classmates or friends online (facebook,…etc) to learn with you.

Surely exist online websites offering ready online classes with students from around the world, not have to setup yourself the environment…
www.mgu-russian.com/programms/online-russian-course/en
www.primelanguageservices.com
(these also offer one to one Lessons).
Of course, exist for other languages identical Sites, just search for “skype online french lessons” or search the language-school-teachers.com or similar site.

Considering the vast number of sites available today, there is more than enough good information to learn/read about grammar, most common words/verbs, starter points in a language,…etc, in text, voice, or video sometimes, and also quizzes, exercises to practice on, all is free. Also you may find online, some complete ebooks in PDF format, I found 7 in “Learn Russian” (in English) but not all in beginning level. Ebooks are paperbacks in electronic format. Some listed/can-downloaded at www.torfl.eu.

As of real paperback books, there are teach yourself materials or teacher assistance materials for any language online, just search your online bookstore or google eg. “teach yourself Russian books”, or “Learn French books”. You may also find story books (eg novels or short stories) in your target language or search for books in a bookstore in that country language is spoken eg in a Russian bookstore if you look for Russian books, where also you may find all kind of books, from science to technical to social science and so on. If you have difficulty with the language you may try Google Translate to translate whole page to eg Russian->English, also if you click a link next page translated automatically. You may also request from a friend or teacher search a book for you or, even send you some books… The latter may be required for your language studies.

Online also you will find free access to online live or on demand, radio or TV station programs, just search eg “Russian online radio stations”, or any other language. Of course, you must pass the beginner level for this. There are also online newspapers and magazines in any field in your target language, just always search eg. “Russian newspapers”. Sometimes preferred find a website with a list of all newspapers by country like
www.world-newspapers.com. Same applies to magazines although they may be listed together along with newspapers sometimes.

As you know on the Internet you can find almost anything, so here is some Learn a language Tips guides
www.wikihow.com/Learn-Any-Language
http://how-to-learn-any-language.com (there’s and multi-language forum too here)

At end, if you have questions and need answer but you do not know where get it, you may post your question in a forum of your target language, just search Google “Russian language forum” register/confirm-Your-Email and post it to appropriate category. Just remember choose “email me upon reply” or you may have to return in forum/myPosts to check for a reply manually.

Other Sites:
www.languageguide.org Have categories of similar items/icons with icon and spelling/pronunciation (voice)
http://imtranslator.com
Text-to-speech voice in 10 languages, virtual-keyboards in many more languages, dictionaries, spell Checker, and some others
www.forvo.com All the words in the world pronounced
http://translate.google.com/#ru|en| Translation Gadget with pronunciation (voice)

Please visit my blog to read this online, or browse through the listed resources, as I say before for my target language:Russian.

LSE, Polis, Paphos.
Www.torfl.eu Russian resources.
Www.polisphotos.com/wordpress/blog My blog.

P.S. If you think the languages of Internet Users, see
www.internetworldstats.com/stats7.htm

Posted in internet, learning, non-internet, other, technology | Tagged , , , , , , , | 2,613 Comments

This is my blog for my web dev biz… my Office!

myself This blog is my first blog for my web development business…
rarely I do other work!
http://www.l-web-dev.net -  Polis  -  Cyprus
Mob.:+357-99-300-548

Skype: lseona [100% online] or lselwd

my Office @ Polis!
Posted in cfml, design, development, internet, java, php, technology | Tagged , , | 1,816 Comments