blob: 1e944f180921339c1c89f8f5e1d5da36befe9696 [file] [log] [blame]
Leon Scroggins571b3762010-05-26 10:25:01 -04001/*
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
17package com.android.browser;
18
19import android.content.Context;
20import android.graphics.Bitmap;
21import android.graphics.Color;
22import android.graphics.drawable.BitmapDrawable;
23import android.graphics.drawable.Drawable;
24import android.graphics.drawable.LayerDrawable;
25import android.graphics.drawable.PaintDrawable;
Michael Kolb7cdc4902011-02-03 17:54:40 -080026import android.view.Gravity;
Leon Scroggins571b3762010-05-26 10:25:01 -040027import android.view.View;
Michael Kolb7cdc4902011-02-03 17:54:40 -080028import android.widget.AbsoluteLayout;
Leon Scroggins571b3762010-05-26 10:25:01 -040029import android.widget.ImageView;
30import android.widget.LinearLayout;
31
32/**
33 * Base class for a title bar used by the browser.
34 */
35public class TitleBarBase extends LinearLayout {
36 // These need to be set by the subclass.
37 protected ImageView mFavicon;
38 protected ImageView mLockIcon;
39
Michael Kolbfe251992010-07-08 15:41:55 -070040 protected Drawable mGenericFavicon;
Leon Scroggins571b3762010-05-26 10:25:01 -040041
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 Reck117f07d2011-01-24 09:39:03 -080080 /* package */ void setIncognitoMode(boolean incognito) {}
Michael Kolb7cdc4902011-02-03 17:54:40 -080081
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 Scroggins571b3762010-05-26 10:25:01 -0400101}