mobile/android/base/home/PanelAuthLayout.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial