Uzi maalumu kwa ajili ya kujifunza namna ya kutengeneza Android Apps


mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined
Feb 26, 2017
Messages
331
Likes
291
Points
80
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined Feb 26, 2017
331 291 80
Habari za siku,
Wakati tuliweza kuunda interface yetu ya APP ambayo tunaita tipCalculator.
Kumbuka lengo la app app hii ni kwa ajili ya kufanya mahesabu ya billi ambayo mtu atakuwa ametumia na kisha atalipa kiwango cha ziada ambacho kipo katika asilimia kutokana jumla ya bili aliyotumia kama atalizishwa na huduma.

Asilimia ya viwango vya ziada zimewekwa kwenye "progress bar" na kiwango cha juu ni 30% mtumiaji atakuwa anaimove hii bar ili kuweka asilimia ya ziada atakayolipa.

Niliamua kuiboresha hii interface na sasa itakuwa na muonekano huu,
modifiedapp-png.650147

Hatua inayofuata ni kufanya programing, baadae tutacustomize themes ili uweze kuweka rangi ambayo wewe unayoitaji kwa mfano kubadili hiyo rangi ya title bar inayoonyesha jina la app pia jinsi ya kubadili rangi ya hiyo progress bar.
 
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined
Feb 26, 2017
Messages
331
Likes
291
Points
80
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined Feb 26, 2017
331 291 80
Tuanze kufanya programming ili app yetu iweze kuendana na matukio ambayo sisi tunaitaji hiyo apps ifanye,

Hatua ya kwanza tunahitaji tu-import classes mbalimbali ambayo yataitajika kutumika na contents ambazo tumeweka katika screen(interface) yetu.

Code:
import android.os.Bundle; //kwa ajili ya kuhifadhi state ya app kwa wakati huo
import android.support.v7.AppCompatActivity ;//base class ambayo inasaidia app kurun vizuri hata kwenye versions za android za zamani
import android.widget.EditText; //class ambayo huwezesha kuingiza texts
import android.text.Editable;  //hii ni kwa ajili ya kuhandle events za text na kufanya mahesabu pindi tu text ikiingizwa
import android.widget.SeekBar; //kwa ajili ya kubadili asilimia ya kiwango cha ziada
import android.text.TextWatcher; //EditText listener
import android.widget.SeekBar.OnSeekBarChangeListener; //seekbar listener
import android.wideget.TextView ;//kwa ajili ya kuonyesha text mbalimbli
import java.text.NumberFormat;//kwa ajili ya kuset aina ya sarafu kwa hapa tutamia $(dollar)
Then baada ya hapa nitaendelea na sehemu zingine, inabidi ujaribu kufuatilia hizo class kiundani kwa hapa sitozielezea sana
 
T

Thefutureman

New Member
Joined
Dec 19, 2017
Messages
2
Likes
0
Points
3
T

Thefutureman

New Member
Joined Dec 19, 2017
2 0 3
Tuanze kufanya programming ili app yetu iweze kuendana na matukio ambayo sisi tunaitaji hiyo apps ifanye,

Hatua ya kwanza tunahitaji tu-import classes mbalimbali ambayo yataitajika kutumika na contents ambazo tumeweka katika screen(interface) yetu.

Code:
import android.os.Bundle; //kwa ajili ya kuhifadhi state ya app kwa wakati huo
import android.support.v7.AppCompatActivity ;//base class ambayo inasaidia app kurun vizuri hata kwenye versions za android za zamani
import android.widget.EditText; //class ambayo huwezesha kuingiza texts
import android.text.Editable;  //hii ni kwa ajili ya kuhandle events za text na kufanya mahesabu pindi tu text ikiingizwa
import android.widget.SeekBar; //kwa ajili ya kubadili asilimia ya kiwango cha ziada
import android.text.TextWatcher; //EditText listener
import android.widget.SeekBar.OnSeekBarChangeListener; //seekbar listener
import android.wideget.TextView ;//kwa ajili ya kuonyesha text mbalimbli
import java.text.NumberFormat;//kwa ajili ya kuset aina ya sarafu kwa hapa tutamia $(dollar)
Then baada ya hapa nitaendelea na sehemu zingine, inabidi ujaribu kufuatilia hizo class kiundani kwa hapa sitozielezea sana
asanteee sanaa mkuu, naomba tuendelee nipo pamoja na ww
 
T

Thefutureman

New Member
Joined
Dec 19, 2017
Messages
2
Likes
0
Points
3
T

Thefutureman

New Member
Joined Dec 19, 2017
2 0 3
Tuanze kufanya programming ili app yetu iweze kuendana na matukio ambayo sisi tunaitaji hiyo apps ifanye,

Hatua ya kwanza tunahitaji tu-import classes mbalimbali ambayo yataitajika kutumika na contents ambazo tumeweka katika screen(interface) yetu.

Code:
import android.os.Bundle; //kwa ajili ya kuhifadhi state ya app kwa wakati huo
import android.support.v7.AppCompatActivity ;//base class ambayo inasaidia app kurun vizuri hata kwenye versions za android za zamani
import android.widget.EditText; //class ambayo huwezesha kuingiza texts
import android.text.Editable;  //hii ni kwa ajili ya kuhandle events za text na kufanya mahesabu pindi tu text ikiingizwa
import android.widget.SeekBar; //kwa ajili ya kubadili asilimia ya kiwango cha ziada
import android.text.TextWatcher; //EditText listener
import android.widget.SeekBar.OnSeekBarChangeListener; //seekbar listener
import android.wideget.TextView ;//kwa ajili ya kuonyesha text mbalimbli
import java.text.NumberFormat;//kwa ajili ya kuset aina ya sarafu kwa hapa tutamia $(dollar)
Then baada ya hapa nitaendelea na sehemu zingine, inabidi ujaribu kufuatilia hizo class kiundani kwa hapa sitozielezea sana
mkuu naomba tuendelee na kipindi, natamani kuendelea kujifunza zaidi.........
 
Donovan RS

Donovan RS

JF-Expert Member
Joined
Aug 10, 2017
Messages
443
Likes
486
Points
80
Donovan RS

Donovan RS

JF-Expert Member
Joined Aug 10, 2017
443 486 80
Uzi mtamu ilasitashiriki
Kila la kheri...
 
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined
Feb 26, 2017
Messages
331
Likes
291
Points
80
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined Feb 26, 2017
331 291 80
Baada ya kuimport Classes tunazohitaji sasa tutaanza kudeal na MainActivity ambayo ni subclass ya AppCompatActivity, hili file java hutengenezwa automatic na IDE kazi yako itakuwa ni kuweka code zinazohitajika, kwa hiyo tunaanza kwa kufanya declarations.
Code:
public class MainActivity extends AppCompatActivity {
    private double billAmount=0.0;//hiki ni kiasi cha mwanzo kabla ya kiasi kipya kuingizwa
    private double percent=0.15; //hii ni kiwango cha asilimia cha nyongeza cha mwanzo
    private TextView amountTextView; //inaonyesha kiasi kilicholipwa
    private TextView percentTextView; // inaonyesha asilimia ya nyongeza
    private TextView tipTextView; //inaonyesha nyongeza ambayo itapatikana kwa kuchukua asilimia na kuzidisha kiwango halisi.
    private TextView totalTextView;//jumla ya kiasi chote ambayo itapatikana kwa kuchukua kiasi kilicholipwa na kiasi cha ziada 
    private static final NumberFormat percentFormat=NumberFormat.getPercentInstance();//hii kwa ajili ya kuonyesha alama ya asilimia(%)
    private static final NumberFormat currencyFormat=NumberFormat.getCurrencyInstance();//kwa ajili ya kuonyesha alama ya dola ($)
Hapo tayari tumeshafanya declaration ya variable mbalimbali, kwenye java huwa inahitaji kufanya overriding ya methods mbalimbali, na hivyo kwenye android tutakuwa tuna-override baadhi ya methods ambazo ni built in.

Kwenye android kuna method ambayo inafungua(initialize) ule muenakono wa app (GUI), hii method huitwa
Code:
onCreate
, methods hii ndio itaanzisha components zako zote za app, na pia itahifadhi state ya app endapo kunatokea app nyingine ambayo unakuwa unadeal nayo wakati kwa mfano mtu akikupigia simu utapokea simu na kuacha app hii ile state ambayo umeiacha basi inahifadhiwa kwenye hii method na pindi ukirudi utaikuta app kama ilivyo

Hii onCreate method inatakiwa iwe simple kuepukana na tatizo la ANR(application not Responding), tuweke codes zetu sasa.
Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);//inflate GUI
    //get reference programmatically manipulated TextView
    amountTextView=(TextView)findViewById(R.id.amountTextView);
    percentTextView=(TextView)findViewById(R.id.percentageTextView);
    tipTextView=(TextView)findViewById(R.id.tipTextView);
    totalTextView=(TextView)findViewById(R.id.totalAmountTextView);
    EditText amountEditText=(EditText)findViewById(R.id.amountEditText);
    amountEditText.addTextChangedListener(amountEditTextWatcher);
    //set percentSeekBar;s onseekBarChangeListener
    SeekBar percentSeekBar=(SeekBar)findViewById(R.id.percentSeekBar);
    percentSeekBar.setOnSeekBarChangeListener(seekBarListener);

}
Nitafafanua hizo code kwenye post inayofuata
 
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined
Feb 26, 2017
Messages
331
Likes
291
Points
80
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined Feb 26, 2017
331 291 80
Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);//inflate GUI
    //get reference programmatically manipulated TextView
    amountTextView=(TextView)findViewById(R.id.amountTextView);
    percentTextView=(TextView)findViewById(R.id.percentageTextView);
    tipTextView=(TextView)findViewById(R.id.tipTextView);
    totalTextView=(TextView)findViewById(R.id.totalAmountTextView);
    EditText amountEditText=(EditText)findViewById(R.id.amountEditText);
    amountEditText.addTextChangedListener(amountEditTextWatcher);
    //set percentSeekBar;s onseekBarChangeListener
    SeekBar percentSeekBar=(SeekBar)findViewById(R.id.percentSeekBar);
    percentSeekBar.setOnSeekBarChangeListener(seekBarListener);

}
Nitafafanua hizo code kwenye post inayofuata
Kwenye classes ambazo tulizi-import tunaanza kuzifanyia kazi hapa. kwenye method onCreate unaona kuna parameter iliyoondikwa Bundle saveInstanceState, hii kazi yake ku-maintain hali ya app kama ilivyo endapo kuna mabadiliko ambayo mtumiaji ameyafanya au kuna app nyingine imeingia ghafla mfano message au kupiga simu au ukafungua app nyingine.

kuna method setContentView yenye parameter R.layout.activity_main hii ndio inafungua ile interface ambayo tumeingeneza huko nyuma, kumbuka GUI kwenye android hudesigniwa kwenye xml files, R ni class linaloinvolve ints za variable mbalimbali na ndio class inayofanya mawasiliano kati ya java kuaccess xml components programmatically, layout ni folder lenye xml files zenye GUI, activity_main hii ni xml file ambapo kwa hapa ndio user interface(GUI) yetu.

Tulipokuwa tunaunda GUI mwanzoni kabisa kila component tulikuwa tunaipa ID (id). id ni class ambalo lina constants kwa ajili ya views mbalimbali tulizetengeneza hii inasaidia java kuiaccess hizo components za GUI ambazo tuliziunda programmatically na kisha kuanza kufanya programming ili app ifanye kile ambacho unakilenga.

ili uweze kuaccess hizo views baada ya kufanya declaration basi utatumia method ya
Code:
findViewById(R.id.jina_la_id_uliyoiandika)
mfano,
Code:
totalTextView=(TextView)findViewById(R.id.totalAmountTextView);
lakini u-typecast kama apo juu inavyoonekana. ni vizuri ukachimba kiundani zaidi
 
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined
Feb 26, 2017
Messages
331
Likes
291
Points
80
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined Feb 26, 2017
331 291 80
METHOD YA KUFANYA CALCULATIONS YA KIASI CHA JUMLA
Code:
private void calculate(){
    percentTextView.setText(percentFormat.format(percent));//kwa ajili ya kuonyesaha alama ya asilimia(%)
    double tip=billAmount*percent;
    double total=billAmount+tip;
    tipTextView.setText(currencyFormat.format(tip));//kwa ajili ya kuonyesha text ambapo hapa kiasi cha ziada
    totalTextView.setText(currencyFormat.format(total));// kwa ajili ya kuonyesha kiasi cha jumla

}
 
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined
Feb 26, 2017
Messages
331
Likes
291
Points
80
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined Feb 26, 2017
331 291 80
Congiguration ya seekBar
seekbar ni kama progress bar ambayo mtumiaji wa app anaweza aka-imove ni kama inavoonekana kwenye interface yetu kule juu.
Hii yenyewe inaonyesha asilimia ambazo mtu yuko tiyari kulipa kama kiasi cha ziada kutokana na kiasi alichoingiza kutoka 0 hadi 30, ambapo mtu akimove inakuwa inajicalculate mara kwa mara na kwa kutumia method ya hapo juu, code zake ni hizi zifuatazo.
Code:
private final OnSeekBarChangeListener seekBarListener=new OnSeekBarChangeListener() {
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        percent=(double)progress/100.0;//hapa inaibadili hiyo asilimia kuwa kwenye desimali
        calculate();//hapa inafanya calculation kadri seekBar inavyomove

    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
};
 
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined
Feb 26, 2017
Messages
331
Likes
291
Points
80
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined Feb 26, 2017
331 291 80
CONFIGURATION KUINGIZA KIASI (TEXTS)
Hii app tunataka mabadiliko ya kiasi cha jumla yawe yanatokea pindi tu mtumiaji akiingiza kiasi au seekbar ikibadilishwa level yake, hivyo hapa pia methods za textWatcher na Editable zitahusika,

Code:
 private final TextWatcher amountEditTextWatcher=new TextWatcher(){
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            try {
                billAmount = Double.parseDouble(s.toString()) / 100;//android text zake huwa inaziconsider kama Strings kwa hiyo hii method hubadili string na kuwa mtindo wa Double.
                amountTextView.setText(currencyFormat.format(billAmount));//
            }
            catch(NumberFormatException e){
                amountTextView.setText("");//endapo hakuna kiasi kilichoingizwa basi kiasi cha jumla kitakuwa zero
                billAmount=0.0;
            }
            calculate();//inafanya calculations tena

        }

        @Override
        public void afterTextChanged(Editable s) {

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }
    };


}
Hapa ndipo tumekamilisha app yetu na hivyo kujiandaa kwa ajili ya app inayofuata. Nashauri ungeingia kiundani zaidi kwa sababu sina muda wa kutosha wa kueleza kila kitu. tuwe pamoja kwenye sehemu zinazofuata
screenshot_2017-12-30-13-46-14-png.663499

screenshot_2017-12-30-13-46-24-png.663501


Hivi ndivyo inavofanya kazi kwenye simu.
 
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined
Feb 26, 2017
Messages
331
Likes
291
Points
80
mwaminifuhalisi

mwaminifuhalisi

JF-Expert Member
Joined Feb 26, 2017
331 291 80
App Inayofuata itakuwa kwa ajili ya kuplay Music au audio yoyote ile, app tutaita JF Music Player, tutamia icon ya JamiiForums kama launch icon, pia itakuwa na feautures za play, previous na next. applications hii itakuwa na feature hizo chache kwa kuanzia ni hii itakuwa ni app namba tatu katika mfululizo wa hii training. kwa leo niishie hapa mpaka next time.
 
Kibosho1

Kibosho1

JF-Expert Member
Joined
Dec 12, 2017
Messages
545
Likes
333
Points
80
Kibosho1

Kibosho1

JF-Expert Member
Joined Dec 12, 2017
545 333 80
App Inayofuata itakuwa kwa ajili ya kuplay Music au audio yoyote ile, app tutaita JF Music Player, tutamia icon ya JamiiForums kama launch icon, pia itakuwa na feautures za play, previous na next. applications hii itakuwa na feature hizo chache kwa kuanzia ni hii itakuwa ni app namba tatu katika mfululizo wa hii training. kwa leo niishie hapa mpaka next time.
 
Mzururaji

Mzururaji

JF-Expert Member
Joined
Apr 6, 2012
Messages
1,260
Likes
624
Points
280
Mzururaji

Mzururaji

JF-Expert Member
Joined Apr 6, 2012
1,260 624 280
Ukitengeneza app wewe mtengenezaji utafaidika na nn ama nan atakuwa anakulipa.
 
Locci

Locci

JF-Expert Member
Joined
Dec 16, 2017
Messages
1,022
Likes
780
Points
280
Age
25
Locci

Locci

JF-Expert Member
Joined Dec 16, 2017
1,022 780 280
Mkuu samahani kidogo hii JAVA unayoizungumzia ni tofauti na javascript? Mi bado ni mchanga kwenye ulimwengu huu wa programming baada ya kumaliza kujifunza html + CSS sasa nmeanza kujifunza javascript sasa ndo hii hii unayoizungumzia au ni kitu kingine?

Sent using Jamii Forums mobile app
yeah java na JavaScript in tofauti...
 
mwanaspotiapp

mwanaspotiapp

Senior Member
Joined
Sep 21, 2017
Messages
103
Likes
105
Points
60
mwanaspotiapp

mwanaspotiapp

Senior Member
Joined Sep 21, 2017
103 105 60
Nakaribisha kumbe wewe mwenyewe hujui, Mimi nilidhani nakuja kuona Codes za XML na strings zake zinavyoshushwa class to class za hex

Kumbe null
Kama manifest ya freebadics.com app
Lol, tanzanian (include me) washazoea kutafuniwa tyu, mtu analipwa mshahara kaja na idea aliyoikopy google ya database za ukusanyaji kodi za nyumba ya mzee wake halafu anamwambia nimefanya bure, wakati had I wifi alikuwa anatumia freely , humu jf wamejaa experter kibao about apps coding likin wametulia kama Nokia kuhusu symbian, jamani watanzania mmbadilike hata kama umepata kidogo muwe mnakihelehele kama cha Tiecno(vigezo na masharti nafuata wasijetaka kunitafuta wenye brand) kuingiza sokon hiyo itachochea uvumbuzi mwing
Acheni uchoyo
Uchoyo sumu
Sumu ilimuua kaka Libya
Kuwa muwazj kama Dada China
Na usiogope kama anko north.Korea
Nitume kama anti japani
Kuwa na kauli kama bibi urusi
Lakini kuwa mtulivu mwenye vingi vya kuongea kama step.mom British
Na
Sema kwa uhakika kama mama wa kufikia German..

Lakini usikubali kuwa inferior kama mzazi Afrika.....
Washangaze watu kama mnafiki kaka mkubwa ameliko



Code<finish*/>
<*ask*="?"*/>
<kesho*/>. Echo <najibu/strings.xml//
"Upuuzi"<$>
<=[ ] <{null"*/}>
>acha kusoma"=class.e"**/
>
>
>.
Your idiot
 

Forum statistics

Threads 1,238,925
Members 476,277
Posts 29,336,972