|
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 package org.mozilla.gecko.home; |
|
7 |
|
8 import org.mozilla.gecko.GeckoAppShell; |
|
9 import org.mozilla.gecko.GeckoEvent; |
|
10 import org.mozilla.gecko.R; |
|
11 import org.mozilla.gecko.home.HomeConfig.AuthConfig; |
|
12 import org.mozilla.gecko.home.HomeConfig.PanelConfig; |
|
13 |
|
14 import android.content.Context; |
|
15 import android.text.TextUtils; |
|
16 import android.view.LayoutInflater; |
|
17 import android.view.View; |
|
18 import android.widget.Button; |
|
19 import android.widget.ImageView; |
|
20 import android.widget.LinearLayout; |
|
21 import android.widget.TextView; |
|
22 |
|
23 import com.squareup.picasso.Picasso; |
|
24 |
|
25 class PanelAuthLayout extends LinearLayout { |
|
26 |
|
27 public PanelAuthLayout(Context context, PanelConfig panelConfig) { |
|
28 super(context); |
|
29 |
|
30 final AuthConfig authConfig = panelConfig.getAuthConfig(); |
|
31 if (authConfig == null) { |
|
32 throw new IllegalStateException("Can't create PanelAuthLayout without a valid AuthConfig"); |
|
33 } |
|
34 |
|
35 setOrientation(LinearLayout.VERTICAL); |
|
36 LayoutInflater.from(context).inflate(R.layout.panel_auth_layout, this); |
|
37 |
|
38 final TextView messageView = (TextView) findViewById(R.id.message); |
|
39 messageView.setText(authConfig.getMessageText()); |
|
40 |
|
41 final Button buttonView = (Button) findViewById(R.id.button); |
|
42 buttonView.setText(authConfig.getButtonText()); |
|
43 |
|
44 final String panelId = panelConfig.getId(); |
|
45 buttonView.setOnClickListener(new View.OnClickListener() { |
|
46 @Override |
|
47 public void onClick(View v) { |
|
48 GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("HomePanels:Authenticate", panelId)); |
|
49 } |
|
50 }); |
|
51 |
|
52 final ImageView imageView = (ImageView) findViewById(R.id.image); |
|
53 final String imageUrl = authConfig.getImageUrl(); |
|
54 |
|
55 if (TextUtils.isEmpty(imageUrl)) { |
|
56 // Use a default image if an image URL isn't specified. |
|
57 imageView.setImageResource(R.drawable.icon_home_empty_firefox); |
|
58 } else { |
|
59 Picasso.with(getContext()) |
|
60 .load(imageUrl) |
|
61 .into(imageView); |
|
62 } |
|
63 } |
|
64 } |