michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.home; michael@0: michael@0: import org.mozilla.gecko.GeckoAppShell; michael@0: import org.mozilla.gecko.GeckoEvent; michael@0: import org.mozilla.gecko.R; michael@0: import org.mozilla.gecko.home.HomeConfig.AuthConfig; michael@0: import org.mozilla.gecko.home.HomeConfig.PanelConfig; michael@0: michael@0: import android.content.Context; michael@0: import android.text.TextUtils; michael@0: import android.view.LayoutInflater; michael@0: import android.view.View; michael@0: import android.widget.Button; michael@0: import android.widget.ImageView; michael@0: import android.widget.LinearLayout; michael@0: import android.widget.TextView; michael@0: michael@0: import com.squareup.picasso.Picasso; michael@0: michael@0: class PanelAuthLayout extends LinearLayout { michael@0: michael@0: public PanelAuthLayout(Context context, PanelConfig panelConfig) { michael@0: super(context); michael@0: michael@0: final AuthConfig authConfig = panelConfig.getAuthConfig(); michael@0: if (authConfig == null) { michael@0: throw new IllegalStateException("Can't create PanelAuthLayout without a valid AuthConfig"); michael@0: } michael@0: michael@0: setOrientation(LinearLayout.VERTICAL); michael@0: LayoutInflater.from(context).inflate(R.layout.panel_auth_layout, this); michael@0: michael@0: final TextView messageView = (TextView) findViewById(R.id.message); michael@0: messageView.setText(authConfig.getMessageText()); michael@0: michael@0: final Button buttonView = (Button) findViewById(R.id.button); michael@0: buttonView.setText(authConfig.getButtonText()); michael@0: michael@0: final String panelId = panelConfig.getId(); michael@0: buttonView.setOnClickListener(new View.OnClickListener() { michael@0: @Override michael@0: public void onClick(View v) { michael@0: GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("HomePanels:Authenticate", panelId)); michael@0: } michael@0: }); michael@0: michael@0: final ImageView imageView = (ImageView) findViewById(R.id.image); michael@0: final String imageUrl = authConfig.getImageUrl(); michael@0: michael@0: if (TextUtils.isEmpty(imageUrl)) { michael@0: // Use a default image if an image URL isn't specified. michael@0: imageView.setImageResource(R.drawable.icon_home_empty_firefox); michael@0: } else { michael@0: Picasso.with(getContext()) michael@0: .load(imageUrl) michael@0: .into(imageView); michael@0: } michael@0: } michael@0: }