Starting with Zodix User App

Firstly, we discussed about the requirements in the User app and designed the rough layout using pen and paper, so that we get some idea about the convenience of End-User.  It’s very important to think from the perspective of the person or group, to whom you are delivering the product. This is the key rule in business. Even the client company Zodix, was also concerned more about this User App.

Tomorrow on wards we will start our work on this app.

Finishing the Dashboard layout

Today, we had to give the app to the client for testing at their side. So, the last thing which I was assigned was to design the dashboard for the app.

I used grid view for that purpose.

<GridView
    android:id="@+id/gridView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none"
    android:columnWidth="90dp"
    android:numColumns="2"
    android:stretchMode="columnWidth"
    android:listSelector="@android:color/transparent"
    android:gravity="center"/>

Calling the adapter  class, which is a subclass of BaseAdapter , for inflating the views :


gridView=(GridView)findViewById(R.id.gridView);
gridView.setAdapter(new GridViewAdapter(this, list, img));

GridViewAdapter’s getView method :


@Override
public View getView(final int position, View convertView, ViewGroup parent) {
 View rowView;
 LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 rowView=inflater.inflate(R.layout.grid_item_layout,null);
 ImageView imgs=(ImageView)rowView.findViewById(R.id.imageViewItem);
 TextView txt=(TextView)rowView.findViewById(R.id.textViewItem);
 txt.setText(nameList[position]);
 imgs.setImageResource(img[position]);
 return rowView;
}

Open a PDF file using compatible application

Now I had to show a dialog showing list of applications installed in phone which can open .pdf file, on click of any PDF list item.

Here’s the output :

pdfOpen

 

Following code, I have written, for this purpose :


recView.addOnItemTouchListener(new RecyclerViewItemClickListener(ActivityPDFs.this,
new RecyclerViewItemClickListener.OnItemClickListener() {
 @Override
 public void onItemClick(View view, int position) {
 String path = ordersFileList.get(position).getFilePath();

File file = new File(path);
 Intent target = new Intent(Intent.ACTION_VIEW);
 target.setDataAndType(Uri.fromFile(file),"application/pdf");
 target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

Intent intent = Intent.createChooser(target, "Open File");
 try {
 startActivity(intent);
 } catch (ActivityNotFoundException e) {

 }
 }
}));

Showing List of PDFs from a Directory

Next task was to show the list of PDFs which has been generated by Admin.

Here is the screenshot of this Activity :

orderPDF

 

This Method fetches all the PDFs from a particular directory of phone.


void fetchPDFs(){
try{
File directory = new File(path);
if(directory.exists()){
File[] fileArr = directory.listFiles();
String fileName;
for(File file1 : fileArr){
if(!file1.isDirectory()){
fileName = file1.getName();
if(fileName.endsWith(".pdf")){
list.add(new PdfFileBean(fileName, file1.getAbsolutePath()));
}
}

}
}
}catch(Exception e){
Log.i("show","Something went wrong. "+e.toString());
}

}

Generating PDF using iTextPDF

Today’s task was to generate the PDFs of orders and package slips. I did this using very popular library iTextPDF. The best tutorial for using this library in Android is given here.

For using this library –

Add in the dependencies, the following line –

compile files('libs/itextpdf-5.5.12.jar')

Method for Generating PDF :


public String generatePDF(){
try {

String directoryPath = "sdcard/someDir/";
File directory = new File(directoryPath);
if(!directory.exists()){
directory.mkdirs();
}

Date date = new Date() ;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss") ;
String dateStr = dateFormat.format(date);

File file = new File(directoryPath+"/"+dateStr + ".pdf");
if (!file.exists()) {
file.createNewFile();
}

Document document = new Document();
PdfWriter.getInstance(document,
new FileOutputStream(file.getAbsoluteFile()));
document.open();

Paragraph p = new Paragraph();
addEmptyLine(p, 1);

Paragraph p1 = new Paragraph("DETAILS", catFont);
p1.setAlignment(Element.ALIGN_CENTER);
p.add(p1);
addEmptyLine(p, 3);

PdfPTable table = new PdfPTable(2);

PdfPCell c1 = new PdfPCell();
c1.setPadding(cellPadding);
c1.setHorizontalAlignment(Element.ALIGN_CENTER);

c1.setPhrase(new Phrase("Product", tableHeading));
table.addCell(c1);

table.setHeaderRows(1);

//populate the table using Table Cells and actual data

document.add(p);
document.add(table);

document.close();
return dateFormat.format(date)+".pdf";
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (DocumentException e) {
e.printStackTrace();
return null;
}
}

Zebra Crossing Scanner

Today, I worked on Prepare Order module where admin is allowed to scan the QR code of the package which is packaged to be delivered to customer.

I searched a lot about fast scanner  library for android. I found Zebra Crossing Scanner which is very popular and used by many.

It’s very easy to use.

Add its dependency in the build.gradle file.

'com.journeyapps:zxing-android-embedded:3.4.0'

 

In the Java file of activity :


private IntentIntegrator qrScan = new IntentIntegrator(this);

btnScanProducts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
qrScan.initiateScan();
}
});

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null) {
//if qrcode has nothing in it
if (result.getContents() != null) {
//add to list
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}

 

After the Scanner stops, the result is handled by onActivityResult.

Working on Users module

Next task was to design activities for admin where he can register Agents and Clients. Before that we also had to design Add City activity, which was being done by other fellow of mine.

agentOp

 

I completed these modules at last. Tomorrow I will start with Orders Module where admin can view all the orders.