Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2010 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.android.gallery3d.ui;
     18 
     19 import android.content.Context;
     20 
     21 public class StaticBackground extends GLView {
     22 
     23     private Context mContext;
     24     private int mLandscapeResource;
     25     private int mPortraitResource;
     26 
     27     private BasicTexture mBackground;
     28     private boolean mIsLandscape = false;
     29 
     30     public StaticBackground(Context context) {
     31         mContext = context;
     32     }
     33 
     34     @Override
     35     protected void onLayout(boolean changeSize, int l, int t, int r, int b) {
     36         setOrientation(getWidth() >= getHeight());
     37     }
     38 
     39     private void setOrientation(boolean isLandscape) {
     40         if (mIsLandscape == isLandscape) return;
     41         mIsLandscape = isLandscape;
     42         if (mBackground != null) mBackground.recycle();
     43         mBackground = new ResourceTexture(
     44                 mContext, mIsLandscape ? mLandscapeResource : mPortraitResource);
     45         invalidate();
     46     }
     47 
     48     public void setImage(int landscapeId, int portraitId) {
     49         mLandscapeResource = landscapeId;
     50         mPortraitResource = portraitId;
     51         if (mBackground != null) mBackground.recycle();
     52         mBackground = new ResourceTexture(
     53                 mContext, mIsLandscape ? landscapeId : portraitId);
     54         invalidate();
     55     }
     56 
     57     @Override
     58     protected void render(GLCanvas canvas) {
     59         //mBackground.draw(canvas, 0, 0, getWidth(), getHeight());
     60         canvas.fillRect(0, 0, getWidth(), getHeight(), 0xFF000000);
     61     }
     62 }
     63