Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 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.browser; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.graphics.Bitmap; |
| 21 | import android.graphics.Color; |
| 22 | import android.graphics.drawable.BitmapDrawable; |
| 23 | import android.graphics.drawable.Drawable; |
| 24 | import android.graphics.drawable.LayerDrawable; |
| 25 | import android.graphics.drawable.PaintDrawable; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame^] | 26 | import android.view.Gravity; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 27 | import android.view.View; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame^] | 28 | import android.widget.AbsoluteLayout; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 29 | import android.widget.ImageView; |
| 30 | import android.widget.LinearLayout; |
| 31 | |
| 32 | /** |
| 33 | * Base class for a title bar used by the browser. |
| 34 | */ |
| 35 | public class TitleBarBase extends LinearLayout { |
| 36 | // These need to be set by the subclass. |
| 37 | protected ImageView mFavicon; |
| 38 | protected ImageView mLockIcon; |
| 39 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 40 | protected Drawable mGenericFavicon; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 41 | |
| 42 | public TitleBarBase(Context context) { |
| 43 | super(context, null); |
| 44 | mGenericFavicon = context.getResources().getDrawable( |
| 45 | R.drawable.app_web_browser_sm); |
| 46 | } |
| 47 | |
| 48 | /* package */ void setProgress(int newProgress) {} |
| 49 | /* package */ void setDisplayTitle(String title) {} |
| 50 | |
| 51 | /* package */ void setLock(Drawable d) { |
| 52 | assert mLockIcon != null; |
| 53 | if (null == d) { |
| 54 | mLockIcon.setVisibility(View.GONE); |
| 55 | } else { |
| 56 | mLockIcon.setImageDrawable(d); |
| 57 | mLockIcon.setVisibility(View.VISIBLE); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /* package */ void setFavicon(Bitmap icon) { |
| 62 | assert mFavicon != null; |
| 63 | Drawable[] array = new Drawable[3]; |
| 64 | array[0] = new PaintDrawable(Color.BLACK); |
| 65 | PaintDrawable p = new PaintDrawable(Color.WHITE); |
| 66 | array[1] = p; |
| 67 | if (icon == null) { |
| 68 | array[2] = mGenericFavicon; |
| 69 | } else { |
| 70 | array[2] = new BitmapDrawable(icon); |
| 71 | } |
| 72 | LayerDrawable d = new LayerDrawable(array); |
| 73 | d.setLayerInset(1, 1, 1, 1, 1); |
| 74 | d.setLayerInset(2, 2, 2, 2, 2); |
| 75 | mFavicon.setImageDrawable(d); |
| 76 | } |
| 77 | |
| 78 | /* package */ void setInVoiceMode(boolean inVoiceMode) {} |
| 79 | |
John Reck | 117f07d | 2011-01-24 09:39:03 -0800 | [diff] [blame] | 80 | /* package */ void setIncognitoMode(boolean incognito) {} |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame^] | 81 | |
| 82 | void setTitleGravity(int gravity) { |
| 83 | int newTop = 0; |
| 84 | if (gravity != Gravity.NO_GRAVITY) { |
| 85 | View parent = (View) getParent(); |
| 86 | if (parent != null) { |
| 87 | if (gravity == Gravity.TOP) { |
| 88 | newTop = parent.getScrollY(); |
| 89 | } else if (gravity == Gravity.BOTTOM) { |
| 90 | newTop = parent.getScrollY() + parent.getHeight() - getHeight(); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) getLayoutParams(); |
| 95 | if (lp != null) { |
| 96 | lp.y = newTop; |
| 97 | setLayoutParams(lp); |
| 98 | } |
| 99 | } |
| 100 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 101 | } |