1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/home/PanelAuthLayout.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko.home; 1.10 + 1.11 +import org.mozilla.gecko.GeckoAppShell; 1.12 +import org.mozilla.gecko.GeckoEvent; 1.13 +import org.mozilla.gecko.R; 1.14 +import org.mozilla.gecko.home.HomeConfig.AuthConfig; 1.15 +import org.mozilla.gecko.home.HomeConfig.PanelConfig; 1.16 + 1.17 +import android.content.Context; 1.18 +import android.text.TextUtils; 1.19 +import android.view.LayoutInflater; 1.20 +import android.view.View; 1.21 +import android.widget.Button; 1.22 +import android.widget.ImageView; 1.23 +import android.widget.LinearLayout; 1.24 +import android.widget.TextView; 1.25 + 1.26 +import com.squareup.picasso.Picasso; 1.27 + 1.28 +class PanelAuthLayout extends LinearLayout { 1.29 + 1.30 + public PanelAuthLayout(Context context, PanelConfig panelConfig) { 1.31 + super(context); 1.32 + 1.33 + final AuthConfig authConfig = panelConfig.getAuthConfig(); 1.34 + if (authConfig == null) { 1.35 + throw new IllegalStateException("Can't create PanelAuthLayout without a valid AuthConfig"); 1.36 + } 1.37 + 1.38 + setOrientation(LinearLayout.VERTICAL); 1.39 + LayoutInflater.from(context).inflate(R.layout.panel_auth_layout, this); 1.40 + 1.41 + final TextView messageView = (TextView) findViewById(R.id.message); 1.42 + messageView.setText(authConfig.getMessageText()); 1.43 + 1.44 + final Button buttonView = (Button) findViewById(R.id.button); 1.45 + buttonView.setText(authConfig.getButtonText()); 1.46 + 1.47 + final String panelId = panelConfig.getId(); 1.48 + buttonView.setOnClickListener(new View.OnClickListener() { 1.49 + @Override 1.50 + public void onClick(View v) { 1.51 + GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("HomePanels:Authenticate", panelId)); 1.52 + } 1.53 + }); 1.54 + 1.55 + final ImageView imageView = (ImageView) findViewById(R.id.image); 1.56 + final String imageUrl = authConfig.getImageUrl(); 1.57 + 1.58 + if (TextUtils.isEmpty(imageUrl)) { 1.59 + // Use a default image if an image URL isn't specified. 1.60 + imageView.setImageResource(R.drawable.icon_home_empty_firefox); 1.61 + } else { 1.62 + Picasso.with(getContext()) 1.63 + .load(imageUrl) 1.64 + .into(imageView); 1.65 + } 1.66 + } 1.67 +}