Wednesday, 29 May 2013

choose image from gallery android


choose image from gallery android in my app, the user need to upload their profile from gallery pop up. I write simple project to demonstrate how to code. ^^





clear notification android onclick

clear notification android onclick

When you create notification , you need to set flag property:
Notification noti = mBuilder.build();
noti.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;


Tuesday, 28 May 2013

multi language android

 multi language android is easy to config. Once you’ve decided on the languages you will support, create the resource subdirectories and string resource files.
Create additional values directories inside res/ that include a hyphen and the ISO country code at the end of the directory name. See ISO country code
 
For example:
 
MyProject/
    res/
       values/
           strings.xml
       values-es/
           strings.xml
       values-fr/
           strings.xml
 
 
 

For example, the following are some different string resource files for different languages.


English (default locale), /values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
   
<string name="title">My Application</string>
   
<string name="hello_world">Hello World!</string>
</resources> Spanish, /values-es/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
   
<string name="title">Mi Aplicación</string>
   
<string name="hello_world">Hola Mundo!</string>
</resources>
 

ISO country code

ISO-639 Language Codes

Table 20-2 ISO-639 Language Codes
Language
ISO-639 Language Code
Abkhazian
ab
Afar
aa
Afrikaans
af
Albanian
sq
Amharic
am
Arabic
ar
Armenian
hy
Assamese
as
Aymara
ay
Azerbaijani
az
Bashkir
ba
Basque
eu
Bengali (Bangla)
bn
Bhutani
dz
Bihari
bh
Bislama
bi
Breton
br
Bulgarian
bg
Burmese
my
Byelorussian (Belarusian)
be
Cambodian
km
Catalan
ca
Chinese (Simplified)
zh
Chinese (Traditional)
zh
Corsican
co
Croatian
hr
Czech
cs
Danish
da
Dutch
nl
English
en
Esperanto
eo
Estonian
et
Faeroese
fo
Farsi
fa
Fiji
fj
Finnish
fi
French
fr
Frisian
fy
Galician
gl
Gaelic (Scottish)
gd
Gaelic (Manx)
gv
Georgian
ka
German
de
Greek
el
Greenlandic
kl
Guarani
gn
Gujarati
gu
Hausa
ha
Hebrew
he
Hindi
hi
Hungarian
hu
Icelandic
is
Indonesian
id
Interlingua
ia
Interlingue
ie
Inuktitut
iu
Inupiak
ik
Irish
ga
Italian
it
Japanese
ja
Javanese
ja
Kannada
kn
Kashmiri
ks
Kazakh
kk
Kinyarwanda (Ruanda)
rw
Kirghiz
ky
Kirundi (Rundi)
rn
Korean
ko
Kurdish
ku
Laothian
lo
Latin
la
Latvian (Lettish)
lv
Limburgish ( Limburger)
li
Lingala
ln
Lithuanian
lt
Macedonian
mk
Malagasy
mg
Malay
ms
Malayalam
ml
Maltese
mt
Maori
mi
Marathi
mr
Moldavian
mo
Mongolian
mn
Nauru
na
Nepali
ne
Norwegian
no
Occitan
oc
Oriya
or
Oromo (Afan, Galla)
om
Pashto (Pushto)
ps
Polish
pl
Portuguese
pt
Punjabi
pa
Quechua
qu
Rhaeto-Romance
rm
Romanian
ro
Russian
ru
Samoan
sm
Sangro
sg
Sanskrit
sa
Serbian
sr
Serbo-Croatian
sh
Sesotho
st
Setswana
tn
Shona
sn
Sindhi
sd
Sinhalese
si
Siswati
ss
Slovak
sk
Slovenian
sl
Somali
so
Spanish
es
Sundanese
su
Swahili (Kiswahili)
sw
Swedish
sv
Tagalog
tl
Tajik
tg
Tamil
ta
Tatar
tt
Telugu
te
Thai
th
Tibetan
bo
Tigrinya
ti
Tonga
to
Tsonga
ts
Turkish
tr
Turkmen
tk
Twi
tw
Uighur
ug
Ukrainian
uk
Urdu
ur
Uzbek
uz
Vietnamese
vi
Volapük
vo
Welsh
cy
Wolof
wo
Xhosa
xh
Yiddish
yi
Yoruba
yo
Zulu
zu
Code Country Name
AF AFGHANISTAN
AX ÅLAND ISLANDS
AL ALBANIA
DZ ALGERIA
AS AMERICAN SAMOA
AD ANDORRA
AO ANGOLA
AI ANGUILLA
AQ ANTARCTICA
AG ANTIGUA AND BARBUDA
AR ARGENTINA
AM ARMENIA
AW ARUBA
AU AUSTRALIA
AT AUSTRIA
AZ AZERBAIJAN
BS BAHAMAS
BH BAHRAIN
BD BANGLADESH
BB BARBADOS
BY BELARUS
BE BELGIUM
BZ BELIZE
BJ BENIN
BM BERMUDA
BT BHUTAN
BO BOLIVIA, PLURINATIONAL STATE OF
BQ BONAIRE, SINT EUSTATIUS AND SABA
BA BOSNIA AND HERZEGOVINA
BW BOTSWANA
BV BOUVET ISLAND
BR BRAZIL
IO BRITISH INDIAN OCEAN TERRITORY
BN BRUNEI DARUSSALAM
BG BULGARIA
BF BURKINA FASO
BI BURUNDI
KH CAMBODIA
CM CAMEROON
CA CANADA
CV CAPE VERDE
KY CAYMAN ISLANDS
CF CENTRAL AFRICAN REPUBLIC
TD CHAD
CL CHILE
CN CHINA
CX CHRISTMAS ISLAND
CC COCOS (KEELING) ISLANDS
CO COLOMBIA
KM COMOROS
CG CONGO
CD CONGO, THE DEMOCRATIC REPUBLIC OF THE
CK COOK ISLANDS
CR COSTA RICA
CI CÔTE D'IVOIRE
HR CROATIA
CU CUBA
CW CURAÇAO
CY CYPRUS
CZ CZECH REPUBLIC
DK DENMARK
DJ DJIBOUTI
DM DOMINICA
DO DOMINICAN REPUBLIC
EC ECUADOR
EG EGYPT
SV EL SALVADOR
GQ EQUATORIAL GUINEA
ER ERITREA
EE ESTONIA
ET ETHIOPIA
FK FALKLAND ISLANDS (MALVINAS)
FO FAROE ISLANDS
FJ FIJI
FI FINLAND
FR FRANCE
GF FRENCH GUIANA
PF FRENCH POLYNESIA
TF FRENCH SOUTHERN TERRITORIES
GA GABON
GM GAMBIA
GE GEORGIA
DE GERMANY
GH GHANA
GI GIBRALTAR
GR GREECE
GL GREENLAND
GD GRENADA
GP GUADELOUPE
GU GUAM
GT GUATEMALA
GG GUERNSEY
GN GUINEA
GW GUINEA-BISSAU
GY GUYANA
HT HAITI
HM HEARD ISLAND AND MCDONALD ISLANDS
VA HOLY SEE (VATICAN CITY STATE)
HN HONDURAS
HK HONG KONG
HU HUNGARY
IS ICELAND
IN INDIA
ID INDONESIA
IR IRAN, ISLAMIC REPUBLIC OF
IQ IRAQ
IE IRELAND
IM ISLE OF MAN
IL ISRAEL
IT ITALY
JM JAMAICA
JP JAPAN
JE JERSEY
JO JORDAN
KZ KAZAKHSTAN
KE KENYA
KI KIRIBATI
KP KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF
KR KOREA, REPUBLIC OF
KW KUWAIT
KG KYRGYZSTAN
LA LAO PEOPLE'S DEMOCRATIC REPUBLIC
LV LATVIA
LB LEBANON
LS LESOTHO
LR LIBERIA
LY LIBYA
LI LIECHTENSTEIN
LT LITHUANIA
LU LUXEMBOURG
MO MACAO
MK MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF
MG MADAGASCAR
MW MALAWI
MY MALAYSIA
MV MALDIVES
ML MALI
MT MALTA
MH MARSHALL ISLANDS
MQ MARTINIQUE
MR MAURITANIA
MU MAURITIUS
YT MAYOTTE
MX MEXICO
FM MICRONESIA, FEDERATED STATES OF
MD MOLDOVA, REPUBLIC OF
MC MONACO
MN MONGOLIA
ME MONTENEGRO
MS MONTSERRAT
MA MOROCCO
MZ MOZAMBIQUE
MM MYANMAR
NA NAMIBIA
NR NAURU
NP NEPAL
NL NETHERLANDS
NC NEW CALEDONIA
NZ NEW ZEALAND
NI NICARAGUA
NE NIGER
NG NIGERIA
NU NIUE
NF NORFOLK ISLAND
MP NORTHERN MARIANA ISLANDS
NO NORWAY
OM OMAN
PK PAKISTAN
PW PALAU
PS PALESTINE, STATE OF
PA PANAMA
PG PAPUA NEW GUINEA
PY PARAGUAY
PE PERU
PH PHILIPPINES
PN PITCAIRN
PL POLAND
PT PORTUGAL
PR PUERTO RICO
QA QATAR
RE RÉUNION
RO ROMANIA
RU RUSSIAN FEDERATION
RW RWANDA
BL SAINT BARTHÉLEMY
SH SAINT HELENA, ASCENSION AND TRISTAN DA CUNHA
KN SAINT KITTS AND NEVIS
LC SAINT LUCIA
MF SAINT MARTIN (FRENCH PART)
PM SAINT PIERRE AND MIQUELON
VC SAINT VINCENT AND THE GRENADINES
WS SAMOA
SM SAN MARINO
ST SAO TOME AND PRINCIPE
SA SAUDI ARABIA
SN SENEGAL
RS SERBIA
SC SEYCHELLES
SL SIERRA LEONE
SG SINGAPORE
SX SINT MAARTEN (DUTCH PART)
SK SLOVAKIA
SI SLOVENIA
SB SOLOMON ISLANDS
SO SOMALIA
ZA SOUTH AFRICA
GS SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS
SS SOUTH SUDAN
ES SPAIN
LK SRI LANKA
SD SUDAN
SR SURINAME
SJ SVALBARD AND JAN MAYEN
SZ SWAZILAND
SE SWEDEN
CH SWITZERLAND
SY SYRIAN ARAB REPUBLIC
TW TAIWAN, PROVINCE OF CHINA
TJ TAJIKISTAN
TZ TANZANIA, UNITED REPUBLIC OF
TH THAILAND
TL TIMOR-LESTE
TG TOGO
TK TOKELAU
TO TONGA
TT TRINIDAD AND TOBAGO
TN TUNISIA
TR TURKEY
TM TURKMENISTAN
TC TURKS AND CAICOS ISLANDS
TV TUVALU
UG UGANDA
UA UKRAINE
AE UNITED ARAB EMIRATES
GB UNITED KINGDOM
US UNITED STATES
UM UNITED STATES MINOR OUTLYING ISLANDS
UY URUGUAY
UZ UZBEKISTAN
VU VANUATU
VE VENEZUELA, BOLIVARIAN REPUBLIC OF
VN VIET NAM
VG VIRGIN ISLANDS, BRITISH
VI VIRGIN ISLANDS, U.S.
WF WALLIS AND FUTUNA
EH WESTERN SAHARA
YE YEMEN
ZM ZAMBIA
ZW ZIMBABWE

Monday, 27 May 2013

mvc in android example

mvc in android example : I like very much from Josh 's example. So, I summary in this blog to easier to understand.

1) MVC General Concepts:
To quickly review, MVC is a compound pattern meaning several patterns comprise this architectural pattern.
The Model represents our application’s state. Remember, objects have state (properties) and behaviors (methods). And so applications have state (the model). In essence, models are just big name-value objects that dispatch events when its state changes.
Views are the things you see and interact with. They bind to the model by registering themselves as observers.When the model changes, the  view is notified and it updates itself.

When a user interacts with the view, it sends events to a Controller. The controller is responsible for handling the input logic. It interprets the user gestures, updates the model, and may send messages back to the view. Below is a typical MVC diagram showing this relationship.



2) Organize packages:


activities – Should be should be obvious, we’ll put all our activities here.
controllers – Controllers that are the brain for our Views here.
daos – We’ll put our persistence logic here.
lists – This one I’m not incredibly found of, but I put all my custom list adapters here. I’m still experimenting.
models – These are the models are Views will bind to.
utils – All of my static classes and utilities go in here.
vos – I put all of my Value Objects also know as POJOs or Data Transfer Objects here.
widgets – This is borrowed from the Android convention. I put custom widgets controls in here.


3) Explain code

 
CODE: http://www.therealjoshua.com/wp-content/uploads/2011/11/TapCounter.zip 

MODEL:

CounterVo.java

SimpleObservable.java

So notice that our model really only does two things:
  1. It holds state. The properties id, label, count, and locked represent the object. It’s just a big name-value object: a Plain Old Java Object (POJO).
  2. It notifies its observers when properties have changed. The workhorse of this done in the subclass SimpleObservable. (Side note: Instead of using Java’s Observable, class which doesn’t have an interface and forces you to subclasses, I made my own Observable, which has an interface. This creates the option to subclass instead of being forced. Favor composition over inheritance. Bad Java, bad.)

VIEW: is activity package:
1) binding to the model.
2) sending messages to the controller.
3) handling messages from the controller.
Role 1, Data Binding:
Let’s look at TapActivity and let’s bind some data.
@Override
    public void onCreate(Bundle savedInstanceState) {


  // MODEL (Vos package)
        counter = new CounterVo();
        counter.addListener(this);
       
        // CONTROLLER
        controller = new TapController(counter);

/*
     * when MODEL change  onChange will be called.
     * */
    @Override
    public void onChange(CounterVo counter) {

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                updateView();
            }
        });
    }



Our Activity is registered as an observer and whenever our model is updated we know our UI is going to stay right in-sync.

Role 2, Sending Messages:
 TapActivity
 plusBtn.setOnClickListener(new View.OnClickListener() {
 minusBtn.setOnClickListener(new View.OnClickListener() { 

when PlusBtn is clicked.

controller.handleMessage(TapController.MESSAGE_INCREMENT_COUNT);
 
then MODEL CounterVo change ===> onChange will be called in TapActivity.

to update UI.
Role 3: Handling Messages
 check out TapListActivity

http://www.therealjoshua.com/2011/11/android-architecture-part-6-putting-it-together-2/

 






observer pattern

observer pattern summary from wikipedia

public class EventSource extends Observable implements Runnable {
}
public class ResponseHandler implements Observer {
}
main()
 final EventSource eventSource = new EventSource();

        // create an observer
        final ResponseHandler responseHandler = new ResponseHandler();

        // subscribe the observer to the event source
        eventSource.addObserver(responseHandler);

        // starts the event thread
        Thread thread = new Thread(eventSource);
        thread.start();

full link: http://en.wikipedia.org/wiki/Observer_pattern