Friday, August 12, 2016

HOW TO HIDE AND SHOW FLOATING ACTION BUTTON WHILE SCROLLING THE LIST

1- Add following code to your onCreate Method:-
ArrayAdapter adapter = new ArrayAdapter(this, R.layout.activity_listview, mobileArray);
final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
Animation makeInAnimation = AnimationUtils.makeInAnimation(getBaseContext(), false);
makeInAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) { }
@Override
public void onAnimationRepeat(Animation animation) { }
@Override
public void onAnimationStart(Animation animation) {
fab.setVisibility(View.VISIBLE);
}
});
Animation makeOutAnimation = AnimationUtils.makeOutAnimation(getBaseContext(), true);
makeOutAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
fab.setVisibility(View.INVISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) { }
@Override
public void onAnimationStart(Animation animation) { }
});
// ...
if (fab.isShown()) {
fab.startAnimation(makeOutAnimation);
}
if (!fab.isShown()) {
fab.startAnimation(makeInAnimation);
}
ListView listView = (ListView) findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
fab.show();
}
@Override
public void onScroll(AbsListView absListView, int i, int i1, int i2) {
fab.hide();
}
});

2- Add follwing line in xml to get tag
android:id="@+id/mobile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@android:drawable/ic_dialog_email"
app:layout_anchor="@id/mobile_list"
app:layout_anchorGravity="bottom|right|end" />


3- Activity_list.xml view

    android:id="@+id/label"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dip"
    android:textSize="16dip"
    android:textStyle="bold" >

Default
Image1

OnScroll
Image2

After Scroll
Image3

Wednesday, August 10, 2016

Android Retrofit Example

Retrofit way for calling android Web service Example
http://square.github.io/retrofit/

Add following line in our Gradle
compile 'com.squareup.retrofit2:retrofit:2.1.0'
for Maven use following 
 com.squareup.retrofit2
retrofit 2.1.0 

Step :- 1:- Use following below given code for Retrofit Class implementation in your application
package siddhu.test.com.myapplication.network;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Query;
import siddhu.test.com.myapplication.objects.NewsApiArticleResponse;
import siddhu.test.com.myapplication.objects.NewsApiSourcesResponse;
/**
* Created by admin on 8/5/2016.
*/
public class NewsAPI {
private static final String API_KEY = "xyz";
private static final String BASE_URL = "https://newsapi.org/v1/";
private static NewsAPIInterface newsAPIInterface;
public static NewsAPIInterface getNewsAPI() {
if (newsAPIInterface == null) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
newsAPIInterface = retrofit.create(NewsAPIInterface.class);
}
return newsAPIInterface;
}
public interface NewsAPIInterface {
@GET("articles?apiKey=" + API_KEY)
Call getArticles(@Query("source") String source, @Query("sortBy") String sortBy);
@GET("sources")
Call getSources();
}
}

Step :-2:- Calling class code

Call responseCall = NewsAPI.getNewsAPI().getSources();

Step to install Git hub

install git hub desktop from net i.e. https://desktop.github.com
This will give GitHub and GitHub Shell
Find the git.exe path in newly installed packages :-
—Git Hub
C:\Users\admin\AppData\Local\GitHub\PortableGit_xxx\cmd\git.exe init
– inside folder where all source code is kept
C:\Users\admin\AppData\Local\GitHub\PortableGit_xxx\cmd\git.exe add .
C:\Users\admin\AppData\Local\GitHub\PortableGit_xxx\cmd\git.exe commit -m “first commit”
C:\Users\admin\AppData\Local\GitHub\PortableGit_xxx\cmd\git.exe remote add originhttps://github.com/shdhumale/AndroidFragment.git
C:\Users\admin\AppData\Local\GitHub\PortableGit_xxx\cmd\git.exe push -u origin master