Monday 10 December 2018

Concept of "Callback" or listener in android | Example of Callback or listener in Android

I am going to a basic example of custom callback method in android. We will follow step by step. First of all open Android studio and create a new project and open MainActivity.java class and than click on activity_main.xml  layout and do the following:-

Step 1:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/name"
        android:layout_margin="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="==" />

    <Button
        android:id="@+id/next"
        android:gravity="center"
        android:layout_marginTop="60dp"
        android:layout_gravity="bottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Next" />


</LinearLayout>
Step 2 Open MainActivity.java and do the code like following:-
public class MainActivity extends AppCompatActivity {
    TextView tvName;
    Button next;

    @Override    
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvName = (TextView) findViewById(R.id.name);
        next = (Button) findViewById(R.id.next);
        next.setOnClickListener(new View.OnClickListener() {
            @Override            
public void onClick(View view) {
                startActivity(new Intent(MainActivity.this,ClassA.class));
            }
        });
        ClassB.setCallback(new onDataUpdateListner() {
            @Override            
public void getData(String name, String roll) {
                Toast.makeText(MainActivity.this,"Android00---",Toast.LENGTH_LONG).show();
                tvName.setText("Name="+name+"\n"+"Roll="+roll);
            }
        });
    }

}
Step 3 now create interface which will carry the callback method like following Here i created 2 interface :-
public interface onDataUpdateListner {
     //void setData();     
void getData(String name,String roll);
}

public interface onDataUpdateListnerA {
     void getDataA(String name, String roll);
}
Step 4 Now create 2 class ClassA and ClassB and code will be like following:-
ClassA:-
class_a.xml:- 

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/roll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="RollNumber"
        android:gravity="center_vertical"
        android:textAlignment="center"
        android:layout_margin="20dp"/>

    <Button
        android:id="@+id/next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/roll"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:text="Next" />

</RelativeLayout>

public class ClassA extends AppCompatActivity {
    TextView tvRoll;
    Button next;

    @Override    
protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.class_a);
        tvRoll = (TextView) findViewById(R.id.roll);
        next = (Button) findViewById(R.id.next);
        next.setOnClickListener(new View.OnClickListener() {
            @Override            
public void onClick(View view) {
                startActivity(new Intent(ClassA.this, ClassB.class));
            }
        });


        ClassB.setCallbackA(new onDataUpdateListnerA() {
            @Override            
public void getDataA(String name, String roll) {
                tvRoll.setText("Name=" + name + "\n" + "Roll=" + roll);
            }
        });
    }

}
ClassB:-
class_b.xml:- 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/enter_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:hint="Name" />

    <EditText
        android:id="@+id/enter_roll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/enter_name"
        android:layout_margin="20dp"
        android:hint="Roll Number" />

    <Button
        android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/enter_roll"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:text="Ok" />

</RelativeLayout>

public class ClassB extends AppCompatActivity {
    EditText edName, edRoll;
    Button ok;
    public static onDataUpdateListner onDataUpdateListner;
    public static onDataUpdateListnerA onDataUpdateListnerA;

    @Override    
protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.class_b);

        edName = (EditText) findViewById(R.id.enter_name);
        edRoll = (EditText) findViewById(R.id.enter_roll);
        ok = (Button) findViewById(R.id.ok);
        ok.setOnClickListener(new View.OnClickListener() {
            @Override           
 public void onClick(View view) {
                if(ClassB.onDataUpdateListner != null && ClassB.onDataUpdateListnerA!= null) {
                    onDataUpdateListner.getData(edName.getText().toString(),edRoll.getText().toString());
                    onDataUpdateListnerA.getDataA(edName.getText().toString(),edRoll.getText().toString());
                }

                finish();
            }
        });
    }

    public static void setCallbackA(onDataUpdateListnerA callbackA) {
        onDataUpdateListnerA = callbackA;
    }
    public static void setCallback(onDataUpdateListner listner ) {
        onDataUpdateListner = listner;
    }
}
Output:-

Wednesday 29 August 2018

How to show and Modified progress bar on Exo-Player in android

Example of Exoplayer ,with ProgressBar on top of the video when any error will come. Following are the steps:-
1. Open Android Studio and create a new project and open layout main_activity.xml and write following code:-
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"    
xmlns:app="http://schemas.android.com/apk/res-auto"    
xmlns:tools="http://schemas.android.com/tools"    
android:layout_width="match_parent"    
android:layout_height="match_parent"    
tools:context=".MainActivity">

    <TextView        
android:id="@+id/tvWatchVideo"        
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:text="Watch Video"        
app:layout_constraintBottom_toBottomOf="parent"        
app:layout_constraintLeft_toLeftOf="parent"        
app:layout_constraintRight_toRightOf="parent"        
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>


2. Open MainActivity.java and write following code:-
public class MainActivity extends AppCompatActivity {
    private TextView tvWatchVideo;   
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvWatchVideo = (TextView)findViewById(R.id.tvWatchVideo);
        tvWatchVideo.setOnClickListener(new View.OnClickListener() { 
public void onClick(View view) {
                startActivity(new Intent(MainActivity.this,VideoPlayActivity.class));
            }
        });
    }
}

3. Open app gradle and add exo player library like following:-
dependencies {
    // exo player   
 implementation 'com.google.android.exoplayer:exoplayer:2.7.0'
}
4. Create a separate class  with any name i am giving VideoPlayActivity.java code will be following:-
public class VideoPlayActivity extends AppCompatActivity {
    String videoURL = "http://blueappsoftware.in/layout_design_android_blog.mp4";
    private SimpleExoPlayerView simpleExoPlayerView;
    private SimpleExoPlayer exoPlayer;
    private ProgressBar progressBar;
    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.videoplay_activity);
        exoPlayerControl();
    }

    private void exoPlayerControl() {
        simpleExoPlayerView = (SimpleExoPlayerView)findViewById(R.id.exoPlayerview);
        progressBar = (ProgressBar) findViewById(R.id.progress_bar);
        try {
            BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
            TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
            exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
            Uri videoUrl = Uri.parse(videoURL);
            DefaultHttpDataSourceFactory defaultHttpDataSource = new DefaultHttpDataSourceFactory("exoplayer");
            ExtractorsFactory factory = new DefaultExtractorsFactory();
            MediaSource mediaSource = new ExtractorMediaSource(videoUrl,defaultHttpDataSource,factory,null,null);
            simpleExoPlayerView.setPlayer(exoPlayer);
            exoPlayer.prepare(mediaSource);
            exoPlayer.setPlayWhenReady(true);

        }catch (Exception e){
            e.printStackTrace();
        }

        exoPlayer.addListener(new ExoPlayer.EventListener() {
             public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {

            }

            
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {

            }
         
public void onLoadingChanged(boolean isLoading) {

            }          
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
                if (playbackState == ExoPlayer.STATE_BUFFERING){
                    progressBar.setVisibility(View.VISIBLE);
                } else {
                    progressBar.setVisibility(View.INVISIBLE);
                }

            }          
public void onRepeatModeChanged(int repeatMode) {

            }
           
public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {

            }          
public void onPlayerError(ExoPlaybackException error) {
                progressBar.setVisibility(View.VISIBLE);
                exoPlayer.stop();
                exoPlayer.setPlayWhenReady(true);

            }          
public void onPositionDiscontinuity(int reason) {

            }          
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {

            }
  
public void onSeekProcessed() {

            }
        });

    }
}
5. videoplay_activity.xml will be looks like following:--
<?xml version="1.0" encoding="utf-8"?><RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"    
android:layout_width="match_parent"   
android:layout_height="match_parent">
    <com.google.android.exoplayer2.ui.SimpleExoPlayerView        
android:layout_width="match_parent"        
android:id="@+id/exoPlayerview"        
android:layout_height="match_parent">
    </com.google.android.exoplayer2.ui.SimpleExoPlayerView>
    <ProgressBar        
android:id="@+id/progress_bar"        
android:layout_width="48dp"        
android:layout_height="48dp"        
android:layout_centerInParent="true"        
android:visibility="visible"       
android:layout_gravity="center"/>

</RelativeLayout>
6. Output wil be:-


To customise the video control we have to add two xml with the same name in our layout folder like following:-

app - res - layout here add the file .
1. exo_playback_control_view.xml
Code will be like:-
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project    
 Licensed under the Apache License, Version 2.0 (the "License");    
 you may not use this file except in compliance with the License.    
 You may obtain a copy of the License at         
 http://www.apache.org/licenses/LICENSE-2.0    
 Unless required by applicable law or agreed to in writing, software    
 distributed under the License is distributed on an "AS IS" BASIS,     
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    
 See the License for the specific language governing permissions and     
limitations under the License.-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
android:layout_width="match_parent"   
 android:layout_height="wrap_content"    
android:layout_gravity="bottom"   
android:layoutDirection="ltr"    
android:background="#CC000000"   
 android:orientation="vertical">

    <LinearLayout       
 android:layout_width="match_parent"      
 android:layout_height="wrap_content"      
 android:gravity="center"       
 android:paddingTop="4dp"       
 android:orientation="horizontal">

        <ImageButton android:id="@id/exo_prev"           
 style="@style/ExoMediaButton.Previous"/>

        <ImageButton android:id="@id/exo_rew"           
 style="@style/ExoMediaButton.Rewind"/>

        <ImageButton android:id="@id/exo_shuffle"          
  style="@style/ExoMediaButton.Shuffle"/>

        <ImageButton android:id="@id/exo_repeat_toggle"           
 style="@style/ExoMediaButton"/>

        <ImageButton android:id="@id/exo_play"           
 style="@style/ExoMediaButton.Play"/>

        <ImageButton android:id="@id/exo_pause"            
style="@style/ExoMediaButton.Pause"/>

        <ImageButton android:id="@id/exo_ffwd"           
 style="@style/ExoMediaButton.FastForward"/>

        <ImageButton android:id="@id/exo_next"          
  style="@style/ExoMediaButton.Next"/>

    </LinearLayout>

    <LinearLayout       
 android:layout_width="match_parent"     
   android:layout_height="wrap_content"       
 android:layout_marginTop="4dp"       
 android:gravity="center_vertical"       
 android:orientation="horizontal">

        <TextView android:id="@id/exo_position"           
 android:layout_width="wrap_content"           
 android:layout_height="wrap_content"           
 android:textSize="14sp"            
android:textStyle="bold"           
 android:paddingLeft="4dp"           
 android:paddingRight="4dp"          
  android:includeFontPadding="false"           
 android:textColor="#FFBEBEBE"/>

        <com.google.android.exoplayer2.ui.DefaultTimeBar           
 android:id="@id/exo_progress"          
  android:layout_width="0dp"           
 android:layout_weight="1"           
 android:layout_height="26dp"/>

        <TextView android:id="@id/exo_duration"          
  android:layout_width="wrap_content"            
android:layout_height="wrap_content"           
 android:textSize="14sp"           
 android:textStyle="bold"           
 android:paddingLeft="4dp"           
 android:paddingRight="4dp"           
 android:includeFontPadding="false"           
 android:textColor="#FFBEBEBE"/>

    </LinearLayout>

</LinearLayout>

2. exo_simple_player_view.xml
Code will be like:-
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project     
Licensed under the Apache License, Version 2.0 (the "License");     
you may not use this file except in compliance with the License.     
You may obtain a copy of the License at         
 http://www.apache.org/licenses/LICENSE-2.0     
Unless required by applicable law or agreed to in writing, software     
distributed under the License is distributed on an "AS IS" BASIS,    
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.     
See the License for the specific language governing permissions and     
limitations under the License.-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<com.google.android.exoplayer2.ui.AspectRatioFrameLayout        
android:id="@id/exo_content_frame"        
android:layout_width="match_parent"        
android:layout_height="match_parent"        
android:layout_gravity="center">
  <!-- Video surface will be inserted as the first child of the content frame. -->
 <View            
android:id="@id/exo_shutter"            
android:layout_width="match_parent"            
android:layout_height="match_parent"            
android:background="@android:color/black" />

 <ImageView            
android:layout_width="match_parent"            
android:layout_height="match_parent"            
android:scaleType="fitXY" />

 <com.google.android.exoplayer2.ui.SubtitleView            
android:id="@id/exo_subtitles"          
  android:layout_width="match_parent"          
  android:layout_height="match_parent" />

    <ProgressBar         
   android:id="@+id/exo_buffering"         
   android:layout_width="wrap_content"          
  android:layout_height="wrap_content"           
 android:layout_gravity="center"           
 android:indeterminate="true" />

        <TextView           
 android:id="@+id/exo_error_message"          
  android:layout_width="match_parent"           
 android:layout_height="match_parent"          
  android:layout_gravity="center"           
 android:gravity="center"           
 android:padding="16dp" />

    </com.google.android.exoplayer2.ui.AspectRatioFrameLayout>

    <FrameLayout        
android:id="@id/exo_overlay"        
android:layout_width="match_parent"        
android:layout_height="match_parent" />

    <View      
  android:id="@id/exo_controller_placeholder"       
 android:layout_width="match_parent"       
 android:layout_height="match_parent" />

</merge>


Basic ExoPlayer in android studio

Here we will use simple Exoplayer to play any video in android application. Steps are following:-
1. Take new project in android studio and open activity_main.xml and write following:-
activity_main.xml :-
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"    
xmlns:app="http://schemas.android.com/apk/res-auto"    
xmlns:tools="http://schemas.android.com/tools"    
android:layout_width="match_parent"    
android:layout_height="match_parent"    
tools:context=".MainActivity">   
<TextView        
android:id="@+id/tvWatchVideo"        
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:text="Watch Video"        
app:layout_constraintBottom_toBottomOf="parent"        
app:layout_constraintLeft_toLeftOf="parent"        
app:layout_constraintRight_toRightOf="parent"        
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

2. Open MainActivity.java and write following code:-
public class MainActivity extends AppCompatActivity {
    private TextView tvWatchVideo;

    @Override    
       protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvWatchVideo = (TextView)findViewById(R.id.tvWatchVideo);
        tvWatchVideo.setOnClickListener(new View.OnClickListener() {
            @Override            
public void onClick(View view) {
                startActivity(new Intent(MainActivity.this,VideoPlayActivity.class));
            }
        });
    }
}
3. Now to play video we will add Exoplayer library in gradle like following:-
dependencies {
    // exo player    
implementation 'com.google.android.exoplayer:exoplayer:2.7.0'
}
4. create new layout name of videoplay_activity.xml:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"    
android:layout_width="match_parent"    
android:layout_height="match_parent">
    <com.google.android.exoplayer2.ui.SimpleExoPlayerView        
android:layout_width="match_parent"        
android:id="@+id/exoPlayerview"        
android:layout_height="match_parent">
    </com.google.android.exoplayer2.ui.SimpleExoPlayerView>
</RelativeLayout>

5. Now to play video we will create new class with name of VideoPlayActivity:-
public class VideoPlayActivity extends AppCompatActivity {
    String videoURL = "http://blueappsoftware.in/layout_design_android_blog.mp4";
    private SimpleExoPlayerView simpleExoPlayerView;
    private SimpleExoPlayer exoPlayer;
    @Override    
protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.videoplay_activity);
        exoPlayerControl();
    }

    private void exoPlayerControl() {
        simpleExoPlayerView = (SimpleExoPlayerView)findViewById(R.id.exoPlayerview);
        try {
            BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
            TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
            exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
            Uri videoUrl = Uri.parse(videoURL);
            DefaultHttpDataSourceFactory defaultHttpDataSource = new DefaultHttpDataSourceFactory("exoplayer");
            ExtractorsFactory factory = new DefaultExtractorsFactory();
            MediaSource mediaSource = new ExtractorMediaSource(videoUrl,defaultHttpDataSource,factory,null,null);
            simpleExoPlayerView.setPlayer(exoPlayer);
            exoPlayer.prepare(mediaSource);
            exoPlayer.setPlayWhenReady(true);

        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
6.Output will be like this:-

Wednesday 27 June 2018

How to use Retrofit to call an API in android. Full example to call any API using Retrofit rx in Android

In this Post i will tell you , how to make a network call in android to GET the data from api using Retrofit .

Do the following steps:-

1. First of all Open your android studio and go to File - New - New Project -Give the project name (whatever u wants i am giving - RetrofitExmp) and then click on - Next -Next -Next -Finish.

2. Now after opening your project click on (here project display mode is - android) app -java -click on your package (com.example.retrofitexmp).

3. Now right click on your app package -New - Package and give name ModelClass.

4. We r using this model class to parse the API data into is , so the model class structure should be match with the api  structure. For this we have to see the response. Here i am using one of the free api link for testing Link is :- https://jsonplaceholder.typicode.com/albums

Note:- before calling Retrofit we needs to add some packages to our app gradle:
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:27.1.1'
compile 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
    // to use retrofit2 notation like @SerializedName("") @Expose    
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.3.0'
    // for the using of HttpLoggingInterceptor
compile 'com.squareup.okhttp3:okhttp:3.10.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.10.0'
    // For using AndroidSchedulers for io
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.3.4'}
5. Now click on ModelClass package and make a new java class with the name of GetAlbumListResponse.java. class will looks like following:-
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;

public class GetALbumListResponse implements Serializable{

    @SerializedName("userId")
    @Expose    
    public int userId;
    
    @SerializedName("id")
    @Expose    
    public int id;

    @SerializedName("title")
    @Expose    
    public String title;


}

6. Now for GET method call , I am creating a interface inside network package with the name of "AppInterface" code are following :-
import retrofit2.http.GET;
import retrofit2.http.Path;
import rx.Observable;

public interface AppInterface {

    @GET("{albums}")
    Observable<GetALbumListResponse> getAlbumListApi(@Path("albums") String albums);
}

7. Now for Retrofit Network call we have to create another class inside network package code are following  , as i made class (NetworkManager.java):-
public class NetworkManager {

    String url = "https://jsonplaceholder.typicode.com/";

    // make Retrofit network call with api link
    public AppInterface getRetrofitServices(Context context){

        HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(httpLoggingInterceptor).build();
        Gson gson = new GsonBuilder()
                .setLenient()
                .create();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(url)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();

        return retrofit.create(AppInterface.class);
    }
}

8. Now  we will call the api make separate class for this with the name of (AppApiControllerClass)code are following :-
import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.schedulers.Schedulers;
import rx.android.schedulers.AndroidSchedulers;

public class AppApiControllerClass extends NetworkManager {

    public Subscription  getApiSubscription(final Context context, final OnHttpResponseListner listner) {

        final Observable<GetALbumListResponse> observable = getRetrofitServices(context).getAlbumListApi("albums");
        Subscription subscription = observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<GetALbumListResponse>() {
                    @Override                    
                    public void onCompleted() {}

                    @Override                    
                    public void onError(Throwable e) {
                    }
                    @Override                    
                    public void onNext(GetALbumListResponse response) {
                        listner.onSuccess(123,response);
                    }
                });
        return subscription;

    }
}
8. Now  in MainActivity.java class we will just call the method to his the api code are following :-
public class MainActivity extends AppCompatActivity implements OnHttpResponseListner{
    Subscription subscription;
    AppApiControllerClass appApiControllerClass;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //call api            appApiControllerClass = new AppApiControllerClass();
        appApiControllerClass.getApiSubscription(MainActivity.this, this);


    }

    @Override    public void onSuccess(int requestCode, GetALbumListResponse response) {
        Toast.makeText(MainActivity.this, response.toString(),Toast.LENGTH_LONG).show();

    }
}
9. Output :-