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