Sunday, December 24, 2017

Android Material SearchView with Recent Search Suggestions

December 24, 2017

Welcome to this post.

In this post, I am going to cover Android Search View with Recent Search Suggestion.

In a previous post, I already cover Android Material SearchView. In that post, I use a 3rd party library. If you want to use 3rd party library to add search functionality, see this post. Android Material SearchView

But Now I don't want to use any 3rd party library.
In this post, I use:
  • Search Widget
Let's start:
create a new activity:(In my case, I named it: SearchActivity)
First jump into XML code-

Read More

Friday, November 17, 2017

Android Runtime permission

November 17, 2017

Welcome to this post.

In this post, I am going to discussing a new topic that is android runtime permission.

What is runtime permission?
Basically, when we want to access some data on the device or want to make a network request from our app, we need user permission.Basically, we need to write the permissions on the AndroidMenifest.xml
AndroidMenifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
if the user installs the app, the user must accept the permissions that we write on AndroidMenifest.xml
But in Android 6.0 API 23
The Android team want to give more control to the user and now user can install without accepting all the permission.
For an example, we want to access to the storage(external storage), so we need permission first. Now we promote to the user to accept the permission in the app runtime to access the storage.
If the user does not accept the permission that means we do not access the storage.

Read More

Tuesday, November 14, 2017

Android Settings Series (part 2)

November 14, 2017

Welcome to this series post.
In this series post, we are going to create a complete Settings for a productive app.

We already published a post-
Now I am starting where I left in the previous post.

Now we need to create other 2 XML file. (In our final settings we need 3 XML file, we already have done one.)

Read More

Saturday, November 11, 2017

Android Settings Series (part 1)

November 11, 2017

Welcome to this Series post.
In this series post, we are going to create a complete Settings for a productive app.

Basic overview of our final settings?

Our final settings contains-
  •  multiple preference screen 
In a previous post, I  cover android settings with a single preference screen (Android App Settings with Preference Fragment Compat).

we create 3 screen that's are-
  • General
  • Backup 
  • Advance
So we create multiple preference screen in the same XML file and after user click, we replace the fragment.
That's the deal,
Lets Start-

Read More

Saturday, November 4, 2017

Google Chrome Custom Tab on your Android App

November 04, 2017

Welcome to this post.
In this post, we are going to learn how to use google chrome custom tab in our app.

In our app, we basically use webview for loading a web address. Or sometimes we make an intent that opens other browser and loads the web address.

But why we use Chrome custom tab?
Chrome custom tabs offer apps additional management over their internet expertise and build transitions between native and web content more seamless while not having to resort to a WebView.

Is any customization support? 
yes. Chrome custom tab supports some customization-

  • Toolbar color 
  • Enter and exit animations 
  • Add custom actions to the Chrome toolbar and overflow menu 

It also allows the developer to pre-start Chrome and pre-fetch content for faster loading.

Ok, Lets Start
First, add the below line in your build.gradle file
//chrome custom tab
compile 'com.android.support:customtabs:26.1.0'
Now create a method-
private void customTab(String url){
}
create a builder object
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
set toolbar color
builder.setToolbarColor(R.attr.colorPrimary);
set title is shown or not
builder.setShowTitle(false);
now build chrome custom intent
CustomTabsIntent customTabsIntent = builder.build();
now launch the URL
customTabsIntent.launchUrl(this, Uri.parse(url));
full code of this method
private void customTab(String url){
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        builder.setToolbarColor(R.attr.colorPrimary);
        builder.setShowTitle(false);
        // add share action to menu list
        builder.addDefaultShareMenuItem();
        CustomTabsIntent customTabsIntent = builder.build();
        customTabsIntent.launchUrl(this, Uri.parse(url));

    }
you can use this method anywhere. you just pass a web address.

Now make some customization- 
Menu:
add menu action button for default share action button
builder.addDefaultShareMenuItem();
want to custom share action button
builder.setActionButton(icon, description, pendingIntent, tint);
here, add a menu item
builder.addMenuItem(menuItemTitle, menuItemPendingIntent);

Animation:
add enter and exit animation
builder.setStartAnimations(this, R.anim.slide_in_right, R.anim.slide_out_left);
builder.setExitAnimations(this, R.anim.slide_in_left, R.anim.slide_out_right);
 that's it today post.
Want to customize more, then don't forget to check the official document of chrome custom tab

Thank you for reading this post.
Happy coding

Read More

Wednesday, October 4, 2017

Android Material App intro (part 2)

October 04, 2017

Welcome to the second Second part of the tutorial "How to create Android Material App intro".

In the previous part, we finish all of our XML code.  In this part, we are going through the Java code and Finished the app intro.

Lets Start-
First, open the newly created activity java file.

Read More

Monday, October 2, 2017

Android Common Code

October 02, 2017

All the common android code list that used almost every android project.

Here is the list of all code in this post:
  • Support vector drawable
  • PreferenceFragment support
  • Java 8 support
Support vector drawable:
to support vector drawable add below line on the build.gradle file
compile 'com.android.support:support-vector-drawable:26.1.0'
also adds below line on those activities where you use vector drawable.
static {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

PreferenceFragment support:
add the following line on the build.gradle file
compile 'com.android.support:preference-v14:26.1.0'
adds also add below line on the style.XML file
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
note: This line is for Material Theme support.

Java 8 support:
to support Java 8 add following line on the build.gradle file
// Keep the following configuration in order to target Java 8.
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}












Read More