Displaying Progress Bar on Dialog Box in BB10 native

In this blog we will be looking for how to display a “progress bar” on a “dialog box”. 

Here we are reading bb10 contact list. As many contacts we read progess on progress bar is displayed accordingly.

Firstly include :

#include <bb/cascades/ProgressIndicator>
#include <bb/system/SystemProgressDialog.hpp>
#include <bb/cascades/Dialog>

 

Before defination keep in mind that progress bar value varies from 0 to 100. And in BB10 progress bar incrementation is done on integer value only, no float value is taken by it. So, here we take the size of contact list and group it so that it divides in 100 parts.             For example, if bb10 have 200 contacts than on reading 2 contacts 1 part of progress bar increases.

Now here is the code for that

QList<ContactModel> AddressBook::fetchContacts(SystemProgressDialog *progressDialog,ProgressIndicator *progressIndicator,                                                                                                                     ApplicationUI *appui) {
QList<ContactModel> list_cm;
ContactListFilters filter;

//Reads all conatcts in the phone
QList<Contact> phoneExistingContacts = m_contactService->contacts(filter);

//Gives number of contacts
qDebug() << “Existing contacts” << phoneExistingContacts.size();

//Grouping contacts and Progress Bar
QString phoneNumberstr;
QString str;
int i = 0, count = 1;
float count_float = 100 / phoneExistingContacts.size();
float max_count = 0;
foreach(Contact c, phoneExistingContacts)
{
QString str, temp;
str.setNum(count);
temp.setNum(phoneExistingContacts.size());
str = str + “/” + temp;
if (count_float < 1) {
max_count += count_float;
if (max_count >= 1) {
i += 1;
max_count–;
}
} else
i += count_float;

//For displaying progress
appui->setProgress(str, i);
count++;
// progressDialog->setBody(str);
// qDebug() << “*******************” << str;
// progressDialog->setProgress(i);

}//end of foreach

}//end of function

 

For ContactModel open ContactModel.h and ContactModel.cpp

Progress bar looks like this:

ProgressBar

2,579 total views, 1 views today

Share this OnShare on FacebookTweet about this on TwitterShare on LinkedInShare on Google+

1 comment

Leave a Reply