2011-10-25 05:00:37 -07:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Android code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Gian-Carlo Pascutto <gpascutto@mozilla.com>
|
2011-11-07 10:27:02 -08:00
|
|
|
* Sriram Ramasubramanian <sriram@mozilla.com>
|
2011-10-25 05:00:37 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2011-11-07 10:27:02 -08:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
2011-10-25 05:00:37 -07:00
|
|
|
import android.content.Context;
|
2011-11-07 10:27:02 -08:00
|
|
|
import android.util.Log;
|
2011-10-25 05:00:37 -07:00
|
|
|
import android.view.LayoutInflater;
|
2011-11-07 10:27:02 -08:00
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.PopupWindow;
|
2011-10-25 05:00:37 -07:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.LinearLayout.LayoutParams;
|
2011-11-07 10:27:02 -08:00
|
|
|
import android.widget.ScrollView;
|
2011-10-25 05:00:37 -07:00
|
|
|
|
|
|
|
public class DoorHangerPopup extends PopupWindow {
|
|
|
|
private Context mContext;
|
2011-11-07 10:27:02 -08:00
|
|
|
private LinearLayout mContent;
|
|
|
|
|
|
|
|
public DoorHangerPopup(Context aContext) {
|
2011-10-25 05:00:37 -07:00
|
|
|
super(aContext);
|
|
|
|
mContext = aContext;
|
|
|
|
|
2011-11-07 10:27:02 -08:00
|
|
|
setWindowLayoutMode(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
|
|
|
|
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
ScrollView scrollContent = (ScrollView) inflater.inflate(R.layout.doorhangerpopup, null);
|
|
|
|
mContent = (LinearLayout) scrollContent.findViewById(R.id.doorhanger_container);
|
|
|
|
|
|
|
|
setContentView(scrollContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
public DoorHanger addDoorHanger(Tab tab, String value) {
|
|
|
|
Log.i("DoorHangerPopup", "Adding a DoorHanger to Tab: " + tab.getId());
|
|
|
|
|
|
|
|
DoorHanger dh = tab.getDoorHanger(value);
|
|
|
|
if (dh != null) {
|
|
|
|
dh.hidePopup();
|
|
|
|
tab.removeDoorHanger(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
dh = new DoorHanger(mContent.getContext(), value);
|
|
|
|
dh.setTab(tab);
|
|
|
|
tab.addDoorHanger(value, dh);
|
|
|
|
mContent.addView(dh);
|
|
|
|
|
|
|
|
return dh;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeDoorHanger(Tab tab, String value) {
|
|
|
|
Log.i("DoorHangerPopup", "Removing a DoorHanger from Tab: " + tab.getId());
|
|
|
|
tab.removeDoorHanger(value);
|
|
|
|
|
|
|
|
if (tab.getDoorHangers().size() == 0)
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showDoorHanger(DoorHanger dh) {
|
|
|
|
if (dh == null)
|
|
|
|
return;
|
2011-10-25 05:00:37 -07:00
|
|
|
|
2011-11-07 10:27:02 -08:00
|
|
|
dh.showPopup();
|
|
|
|
show();
|
|
|
|
}
|
2011-10-25 05:00:37 -07:00
|
|
|
|
2011-11-07 10:27:02 -08:00
|
|
|
public void hideDoorHanger(DoorHanger dh) {
|
|
|
|
if (dh == null)
|
|
|
|
return;
|
2011-10-25 05:00:37 -07:00
|
|
|
|
2011-11-07 10:27:02 -08:00
|
|
|
dh.hidePopup();
|
|
|
|
show();
|
2011-10-25 05:00:37 -07:00
|
|
|
}
|
|
|
|
|
2011-11-07 10:27:02 -08:00
|
|
|
public void hideAllDoorHangers() {
|
2011-11-07 10:30:50 -08:00
|
|
|
hideAllDoorHangersExcept(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hideAllDoorHangersExcept(Tab tab) {
|
2011-11-07 10:27:02 -08:00
|
|
|
for (int i=0; i < mContent.getChildCount(); i++) {
|
|
|
|
DoorHanger dh = (DoorHanger) mContent.getChildAt(i);
|
2011-11-07 10:30:50 -08:00
|
|
|
if (dh.getTab() != tab)
|
|
|
|
dh.hidePopup();
|
2011-11-07 10:27:02 -08:00
|
|
|
}
|
|
|
|
|
2011-11-07 10:30:50 -08:00
|
|
|
if (tab == null)
|
|
|
|
hide();
|
2011-11-07 10:27:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void hide() {
|
|
|
|
if (isShowing()) {
|
|
|
|
Log.i("DoorHangerPopup", "Dismissing the DoorHangerPopup");
|
|
|
|
dismiss();
|
|
|
|
}
|
2011-10-25 05:00:37 -07:00
|
|
|
}
|
|
|
|
|
2011-11-07 10:27:02 -08:00
|
|
|
public void show() {
|
|
|
|
Log.i("DoorHangerPopup", "Showing the DoorHangerPopup");
|
|
|
|
if (isShowing())
|
|
|
|
update();
|
|
|
|
else
|
|
|
|
showAsDropDown(GeckoApp.mBrowserToolbar);
|
2011-11-01 13:26:11 -07:00
|
|
|
}
|
|
|
|
|
2011-11-07 10:27:02 -08:00
|
|
|
public void removeForTab(Tab tab) {
|
|
|
|
Log.i("DoorHangerPopup", "Removing all doorhangers for tab: " + tab.getId());
|
|
|
|
tab.removeAllDoorHangers();
|
2011-10-25 05:00:37 -07:00
|
|
|
}
|
|
|
|
|
2011-11-07 10:27:02 -08:00
|
|
|
public void showForTab(Tab tab) {
|
|
|
|
Log.i("DoorHangerPopup", "Showing all doorhangers for tab: " + tab.getId());
|
|
|
|
HashMap<String, DoorHanger> doorHangers = tab.getDoorHangers();
|
|
|
|
|
|
|
|
if (doorHangers == null) {
|
|
|
|
hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-07 10:30:50 -08:00
|
|
|
hideAllDoorHangersExcept(tab);
|
2011-11-07 10:27:02 -08:00
|
|
|
|
|
|
|
Iterator keys = doorHangers.keySet().iterator();
|
|
|
|
while (keys.hasNext()) {
|
2011-11-07 10:30:50 -08:00
|
|
|
((DoorHanger) doorHangers.get(keys.next())).showPopup();
|
2011-11-07 10:27:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (doorHangers.size() > 0)
|
|
|
|
show();
|
|
|
|
else
|
|
|
|
hide();
|
2011-10-25 05:00:37 -07:00
|
|
|
}
|
|
|
|
|
2011-11-07 10:27:02 -08:00
|
|
|
public void hideForTab(Tab tab) {
|
|
|
|
Log.i("DoorHangerPopup", "Hiding all doorhangers for tab: " + tab.getId());
|
|
|
|
HashMap<String, DoorHanger> doorHangers = tab.getDoorHangers();
|
|
|
|
|
|
|
|
if (doorHangers == null)
|
|
|
|
return;
|
2011-10-25 05:00:37 -07:00
|
|
|
|
2011-11-07 10:27:02 -08:00
|
|
|
Iterator keys = doorHangers.keySet().iterator();
|
|
|
|
while (keys.hasNext()) {
|
2011-11-07 10:30:50 -08:00
|
|
|
((DoorHanger) doorHangers.get(keys.next())).hidePopup();
|
2011-11-07 10:27:02 -08:00
|
|
|
}
|
2011-10-25 05:00:37 -07:00
|
|
|
}
|
|
|
|
}
|