Showing posts with label UI. Show all posts
Showing posts with label UI. Show all posts

Friday, May 25, 2018

Android Create RatingBar Review Like Google Play Store + Firebase

RatingBar review can make our product or apps become more better then before. From the reviews that given by users we able to know what problem of our product or apps.

This article will show you how to create ratingbar review that looks like rating on Google play store. As you know the user interface of review on Google Play store is great and full color.

To achieve rating look like Google Play Store, you have to know the formula of count rating view (especially for create rating that shown with color)

For create the icon of rating (icon star), you can use several library, but in this article I use library Zhanghai Material RatingBar.



Oh, In this article I also use Firebase Firestore as database to store the data of product and the reviews of product.

Create project in Firebase 


Open Firebase Console and create new project. You also can use the existing project in Firebase. After that download the google-services.json then place it on directory app in your project.

Here I created data of product in Firebase Firestore manually :

The sample product the created manually


The data above will displayed on mobile android, and then from android we will send the review of this product.

Create Android Studio Project


After the sample data in Firebase has created, now we crate the android application to display the sample data and send review that data.

Gradle Configuration


In this project, I use some libraries that support the application, you can see at the following gradle :

build.gradle (Project:RatingGooglePlayStore)

build.gradle (Module:app)

Create Page Product


The first page that will appears is page Product (MainActivity). In this page, the data that created manually in Firebase will displayed.

Recommended : Take image from gallery or camera using EasyImage Library

First, we create the model (object) that will handle the data from Firebase Firestore, here it is

ProductModel.java

After that, create Adapter that handle the list of product (even the sample product that create is one, but we still create adapter to handle much data)

item_product.xml

ProductAdapter.java

Now get the data of product from Firebase Firestore and then display it on Recyclerview by using the following code :

MainActivity.java

If you follow all the steps above, you will get result look like the following image :

The data that I created manually in firebase has displayed on mobile

Create Page Review


After the product has displayed, now we create page review that display the rating, insert review and displaying review.

ReviewModel.java

This class use to handle data of review data got from Firebase Firestore, here is the code

Now create the adapter of list review :

item_review.xml

ReviewAdapter.java

After the adapter created, then create the logic how to show rating by stars and rating by color, take a look at the following images :

Rating using stars and colors 


To achieve the goal like the image above, there are several process that you have to do :

1. Insert Review To Firestore

The code above will store the data to collection review. Take a look at the following image :

Data review has stored into Firebase Firestore


Recommended : How to insert and display file image from Firebase Firestore

After data review stored successfully, the update the rating in product

2. Update Rating Product

The following code will update the rating in data product, after that will change the display of rating view and rating color.


3. Update the rating color


4. Populating the recyclerview with data of reviews

Take a learn of those codes above, that will guide you to understand the formula of displaying rating by stars and by colors.

Recommended : Insert image from android to database (server using PHP & MySQL)

Here is the full code of ReviewActivity.java :

Don't forget to add permission of INTERNET in your AndroidManifest.xml

Okay, that's all about the tutorial how to create rating or review look like Google Play Store. I hope this article will help you. Thank you.

Download the project : LINK GITHUB

Monday, January 22, 2018

Android Simply Login Using Firebase UI

Hello everyone, today i gonna be post a nice tutorial relate with login process that provided by Firebase called Firebase UI.

 

What is Firebase UI ?


As simple as i can explain, Firebase UI will provide us the easy way  to creating login process even  login using Facebook, Google account, Email or Twitter

With Firebase UI you don't need create your login form or other API to do login, Firebase UI will handle it all.

Video Result



For achieve that goal, please follow the following steps :

Create Your Application On Firebase


Please go to firebase console and create your project

Create firebase project

After that, choose your platform, in this case choose Android Platform.

Choose platform

Add your SHA-1 key and your package name

Add package name and SHA-1

Download the google-service.json

Download google-service.json

After downloaded, place it inside your app folder. Please take a look at the following figure

App folder

Configuration Gradle


Make sure your gradles are similar with the following gradles :

build.gradle(Project : YourProjectName)


build.gradle(Module : App)


Create your Android Studio Project


You just need 1 XML layout and 1 java class to create login process using Firebase UI. Here they are :

activity_main.xml


Write the following code to create a simple view.

MainActivity.java


Run your project, and may it running well. Thank you.

Download the project here : LINK GITHUB

Saturday, September 2, 2017

Tutorial Double Navigation Drawer Android (Left and Right)

Hello everyone, today i gonna show you a good tutorial about how to creating double navigation drawer on left and right side.

In usual, you must be develop and application using one navigation drawer on left side, right?  But sometimes your application or your client requires double menu on left and right side. You can implement the right menu using dialog similar like navigation drawer, but it maybe not good for the future of your apps. Just a suggestion, on that case, you should use a navigation drawer to handle the menu on the right side.

Double navigation drawer

In this tutorial i will show you how to create double navigation drawer. I think this tutorial isn't hard if you have been understand about how to create left navigation drawer.

Crate the left navigation drawer from Android Studio


Think if the your application requires a right navigatio drawer after you create the left navigation drawer, so i assume you are have been create the left navigation drawer.

But a will guide you how to create the navigation drawer from Android Studio, here it is :

Open you android studio android and name your project as DoubleNavigationDrawer :

Give your project name

After name the project, click button next.

Choose minumu SDK Version

In this case i choose the fault minumun SDK, that is API 16 for Android Jelly Bean. Klik button Next.

Choose Navigation Drawer Activity

Then choose Navigation Drawer Activity as your first class. This will create the left navigation drawer (without right navigation drawer), after that give your first xml dan class file name, take a look the below image

Give the class and xml file name

Give name for your first class and xml file. In this case, just click button next.

Untuk this steps, you have succeed create the left navigation drawer. Just run the project for make sure. The next step is create the right navigation drawer.

Create the right navigation drawer


To create the right navigation drawer you have to create another menu and also there is one layout you have to modify.

Create new menu for the right navigation's items


Create a new file for the right navigation's items in res/menu. Name the new file as activity_navigation_drawer_right. Here the code :

The code above will appears as items of right navigation.

After you create the right navigation's items, now modify your activity_main.xml ( or the xml file where you hosting you NavigationView).

You have to create the another NavigationView to host the right navigation's items. and change its gravity to END. Just take a look the following codes :

Ok all that should be set in the xml file has been set. Now time to modify your java class.

Modify your main_menu (res/menu)


Modify your main_menu.xml (menu that hosted in page where the navigation drawer will appears). Other word this menu will displaying the right navigation drawer. Here the code :


Modify the java class


Find your class where you hosting your DrawerLayout or your NavigationView. In this case i host them in MainActivity.java.

Create new method for displaying the right navigation. In my case I named it as displayRightNavigation(). Do like the following code :

Call the method inside onCreate() method.

And your onBackPressed() method, modify like following code :

Once again, modify your onOptionItemSelecte(MenuItem item) look like the follows :



Full Code Of Java Class


That's all about the tutorial. Run your project. Hope it works well, feel free to ask me by post your comment.

Download the project here : LINK GITHUB

Thursday, August 31, 2017

Android Validation Inside Custom Alert Dialog Builder

In a development process, Alert Dialog usually used for show a message from a running process. The message usually show as an error message, success message or notification message.

Custom Alert Dialog Validation

There are two Dialog that much used, they are AlertDialog and Dialog. Both can used for display a message.   You also able to modify the view inside AlertDialog or Dialog. For custom Dialog view, please read here : Android Custom Popup Using AlertDialog And Dialog

Cannot create a validation on EditText inside AlertDialog


My experience using custom alert Dialog is i can't create a validation form and use setError() for EditText. It's because i wrote my validation inside alertDialog.setPositiveButton(). If we need to create a validation, it should outside of that area.

Recommended : Create rating and review look like google play store

Then how to do validation? Here it is, If you need to create a validation inside a custom AlertDialogBuilder, then please use the following code (at least works perfectly in my project):
Ok that's all a little explanation about how to do validation inside a custom Alert Dialog Builder. Hope it helps. Thank you.

Friday, January 20, 2017

Android Custom Popup Using AlertDialog And Dialog

There are more that one how to create a popup view in android. Generally developer using two ways for creating it, there are :
  1. AlertDialog.Builder()
  2. Dialog()
The default design of AlertDialog actually used for display message that had two option, YES or NO or something related that have two option.

But Dialog is a little bit different. Dialog used to display popup that have a specific function, maybe for input data, login, register or something like that. Generally :
  • If people uses Dialog, it must be contains external layout.
  • If people uses AlertDialog, it must be for display message that had two option, YES or NO
Correct me if i'm wrong.

But it's just on theory, in fact much of developer creating popup that using external layout (red : custom dialog), event it for AlertDialog or Dialog.
In video above, i created a same popup view using two different Dialog. These are AlertDialog and Dialog.

On that video, the external layout is same, i just use one layout for external layout named layout_alert_dialog.xml. Here is the layout :

And this is the layout of activity_main.xml :


1. Popup using AlertDialog


The set the external layout into your AlertDialog is by using LayoutInflater. After that, you just need to setView() in your builder (look at the code above)

Take a look at this code : final AlertDialog alertDialog = builder.show(); Why we have to write that code?

The answer is because if you use a custom button, you cannot find method for dismiss the AlertDialog. So by using the code, then you can find the method dismiss by type alertDialog.dismiss();

The AlertDialog has default button called NegativeButton and PositiveButton. If you use that default button, you will easy to dismiss the alert dialog by using the following code :

builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
    @Override    
    public void onClick(DialogInterface dialogInterface, int i) {
        dialogInterface.dismiss();
    }
});

That code creating the button OK, inside the onClickListener contains DialogInterface, so you easy dismiss the dialog by using dialogInterface.dismiss();


2. Popup using Dialog


I think it more easy creating a popup view by using Dialog, like code above, after you define the Dialog, you just type setContentView(R.layout.your_layout), don't need LayoutInflater method.  

Take a look at this code :

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

That code used to hide or remove the title space. I mean the title of Dialog. But if you want to display the title, that remove that code and type like this : dialog.setTitle("your dialog title");

Take a look at this code :

dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);

That code user to set height and width of the Dialog. Why use that code? Because if you remove the title space, the dialog automatically the width and height set to WRAP_CONTENT. So we set the weight and height again. In this Dialog, i set the height as WRAP_CONTENT and the width as MATCH_PARENT.

To dismiss the dialog, you can find dismiss() method, just called inside the custom button dialog.dismiss()


Hope that poor tutorial can helps you to create popup dialog. Thank you.

Like our fans page to get new update :



Link Download Project

Friday, January 13, 2017

Android Sliding Tab - How To Open A Specific Tab

In several developers (Especially those who newbie in android ), in other case, sliding Tab will bring a difficulty  condition. One of the difficult situation is when they try to open a specific tab.

There are a lot of ways to do this. One of the simple way is using SharedPreferences. SharedPreferences will save the last index of tab that opened. When user open the activity when the sliding tab was placed, sharedPreference will retrieve the index that stored, then that index will matched with index of tab's item.


I hope you understand the explanation above, sorry for a worst english that i use. hahaha.

Okay for the detail, let's start the coding ....

I using THIS PROJECT to implementing how to open specific tab. But you can straight do in your project.

What should you do in your Fragment or on page where you start open the tab?


In every fragment, you have to store its index on sharedPreferences. Because later, that index will be leads you to open specific tab/fragment.

For example do this on your Fragment :

Case in this project : If i press the button, then the application will refresh the activity, but still open the current tab/fragment, get it?

What should you do in your Activity or on page where you hosting you sliding tab?


The activity that i mean is page where you hosting your sliding tab. Inside your onCreate() do like the following code :

In code above, the sharedPreference will retrieve the index that has stored from the specific fragment.

If SharedPreference contains null, the application will open the default tab. But if SharedPreference contains index, then the tab will opening according with the index.

What should you do after the application closed (user close the application) or if the page where you hosting the sliding tab is leaved?


It depend to you application requirements. If your apps need open the last tab that opened by user, then you don't need to do anything anymore, because the code above will open the last tab that opened by user.

But, if your apps required to open the default tab after user close the application, then you have to add a little bit code in your onDestroy() method :

That means, when the application closed by user, sharedpreference will store the default index, that is = 1. Done! I hope you guys understand what i said above. Good luck!

Tutorial Sliding Tab Using Material Design (Best & Simple)

Today i going to share a awesome tutorial about Sliding Tab. In this tutorial we don't need a custom library, but we just use from design:support (Default Material Design)

Must see : How To Open Specific Tab

By using default material design build an awesome UI is more easier that before. That will make developers reduce their stresses hahaha. Take a look at the image below.

The result
If you are interesting with the result and need to implement to your project, then follow the several steps below :

1.  Library


Compile the design:support in your build.gradle(app : Module) :

compile 'com.android.support:design:25.0.0'


2. Create Directory Color


Create new folder in directory res and name it as color (this is directory not a xml file, they are different)

Directory color

Inside the directory color, create a new xml file. Give it name as tab_selector.xml. This selector used for coloring the text of tab's item.

There are two colors, if the tab is selected the color will change to white, if not the color will change to grey.


3.  Colors.xml


For the background of the TabLayout and the color of the selector line, you can choose from Colors.xml.


4. Creating Fragments


Create 3 fragments. Because number of the tab's item is 3. Tab 1 for Home, Tab 2 for Timeline, Tab 3 for Profile.

fragment_first.xml

FirstFragment.java

Also create next fragment for SecondFragment.java and ThirdFragment.java.


5. Creating SlidingTabAdapter.java


This adapter used for set your tab's item. Tab Home for FirstFragment, Tab Timeline for SecondFragment and Tab Profile for ThirdFragment.

Don' forget return the size of your fragment. If you used 3 fragment, so return 3 on inside method getCount().


6. Modify MainActivity.java


In this project i use MainActivity as the class where i hosting my SlidingTabAdapter. You can change with your own class.

Paste the following code :

From the code above :
Code getSupportActionBar().setElevation(0) used for hide a divider between action bar and tab layout.

Codes :

private TabLayout.Tab home;
private TabLayout.Tab timeline;
private TabLayout.Tab profile;

used for set/define your tab's item. It means you creating 3 tab's item.

Codes :

home = tabLayout.newTab();
timeline = tabLayout.newTab();
profile = tabLayout.newTab();

Means home, timeline and profile as a new tabs.

Codes :

tabLayout.addTab(home, 0);
tabLayout.addTab(timeline,1);
tabLayout.addTab(profile,2);

Means you have to define the index of your tab's item. These index will used in SlidingTabAdapter to return a fragment. For example in index 0, you will return the FirstFragment, index 1 will return SecondFragment and index 3 will return ThirdFragment.

For other explanation you can read straight from the code of MainActivity. Hope this tutorial helps you. Thank you.