Home | History | Annotate | Download | only in rich
      1 /*
      2  * Copyright 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.example.android.sampletvinput.rich;
     18 
     19 import android.graphics.Bitmap;
     20 import android.graphics.drawable.Drawable;
     21 import android.support.v17.leanback.app.BackgroundManager;
     22 
     23 import com.squareup.picasso.Picasso;
     24 import com.squareup.picasso.Target;
     25 
     26 /**
     27  * Picasso target for updating default_background images
     28  */
     29 public class PicassoBackgroundManagerTarget implements Target {
     30     BackgroundManager mBackgroundManager;
     31 
     32     public PicassoBackgroundManagerTarget(BackgroundManager backgroundManager) {
     33         this.mBackgroundManager = backgroundManager;
     34     }
     35 
     36     @Override
     37     public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
     38         this.mBackgroundManager.setBitmap(bitmap);
     39     }
     40 
     41     @Override
     42     public void onBitmapFailed(Drawable drawable) {
     43         this.mBackgroundManager.setDrawable(drawable);
     44     }
     45 
     46     @Override
     47     public void onPrepareLoad(Drawable drawable) {
     48         // Do nothing, default_background manager has its own transitions
     49     }
     50 
     51     @Override
     52     public boolean equals(Object o) {
     53         if (this == o)
     54             return true;
     55         if (o == null || getClass() != o.getClass())
     56             return false;
     57 
     58         PicassoBackgroundManagerTarget that = (PicassoBackgroundManagerTarget) o;
     59 
     60         if (!mBackgroundManager.equals(that.mBackgroundManager))
     61             return false;
     62 
     63         return true;
     64     }
     65 
     66     @Override
     67     public int hashCode() {
     68         return mBackgroundManager.hashCode();
     69     }
     70 }
     71