public void updateTabs(boolean areTabsShown) {
   if (areTabsShown) {
     mTabs.setImageLevel(TABS_EXPANDED);
     mTabs.getBackground().setLevel(TABS_EXPANDED);
   } else {
     mTabs.setImageLevel(TABS_CONTRACTED);
     mTabs.getBackground().setLevel(TABS_CONTRACTED);
   }
 }
  public void setSecurityMode(String mode) {
    mShowSiteSecurity = true;

    if (mode.equals(SiteIdentityPopup.IDENTIFIED)) {
      mSiteSecurity.setImageLevel(1);
    } else if (mode.equals(SiteIdentityPopup.VERIFIED)) {
      mSiteSecurity.setImageLevel(2);
    } else {
      mSiteSecurity.setImageLevel(0);
      mShowSiteSecurity = false;
    }
  }
Esempio n. 3
0
  public void updateTabs(int count) {
    if (mCount > count) {
      mTabsCount.setInAnimation(mSlideDownIn);
      mTabsCount.setOutAnimation(mSlideDownOut);
    } else if (mCount < count) {
      mTabsCount.setInAnimation(mSlideUpIn);
      mTabsCount.setOutAnimation(mSlideUpOut);
    }

    if (count > 1) mTabs.setImageLevel(count);
    else mTabs.setImageLevel(0);

    mTabsCount.setVisibility(View.VISIBLE);
    mTabsCount.setText(String.valueOf(count));
    mCount = count;

    mHandler.postDelayed(
        new Runnable() {
          public void run() {
            ((TextView) mTabsCount.getCurrentView()).setTextColor(mColor);
          }
        },
        mDuration);

    mHandler.postDelayed(
        new Runnable() {
          public void run() {
            if (Tabs.getInstance().getCount() == 1) {
              mTabs.setImageLevel(1);
              mTabsCount.setVisibility(View.GONE);
              ((TextView) mTabsCount.getCurrentView()).setTextColor(mCounterColor);
            } else {
              ((TextView) mTabsCount.getCurrentView()).setTextColor(mCounterColor);
            }
          }
        },
        2 * mDuration);
  }
  private void updateSiteIdentity(Tab tab, EnumSet<UpdateFlags> flags) {
    final SiteIdentity siteIdentity;
    if (tab == null) {
      siteIdentity = null;
    } else {
      siteIdentity = tab.getSiteIdentity();
    }

    mSiteIdentityPopup.setSiteIdentity(siteIdentity);

    final SecurityMode securityMode;
    final MixedMode activeMixedMode;
    final MixedMode displayMixedMode;
    final TrackingMode trackingMode;
    if (siteIdentity == null) {
      securityMode = SecurityMode.UNKNOWN;
      activeMixedMode = MixedMode.UNKNOWN;
      displayMixedMode = MixedMode.UNKNOWN;
      trackingMode = TrackingMode.UNKNOWN;
    } else {
      securityMode = siteIdentity.getSecurityMode();
      activeMixedMode = siteIdentity.getMixedModeActive();
      displayMixedMode = siteIdentity.getMixedModeDisplay();
      trackingMode = siteIdentity.getTrackingMode();
    }

    // This is a bit tricky, but we have one icon and three potential indicators.
    // Default to the identity level
    int imageLevel = securityMode.ordinal();

    // Check to see if any protection was overridden first
    if (trackingMode == TrackingMode.TRACKING_CONTENT_LOADED) {
      imageLevel = LEVEL_SHIELD_DISABLED;
    } else if (trackingMode == TrackingMode.TRACKING_CONTENT_BLOCKED) {
      imageLevel = LEVEL_SHIELD_ENABLED;
    } else if (activeMixedMode == MixedMode.MIXED_CONTENT_LOADED) {
      imageLevel = LEVEL_LOCK_DISABLED;
    } else if (displayMixedMode == MixedMode.MIXED_CONTENT_LOADED) {
      imageLevel = LEVEL_WARNING_MINOR;
    }

    if (mSecurityImageLevel != imageLevel) {
      mSecurityImageLevel = imageLevel;
      mSiteSecurity.setImageLevel(mSecurityImageLevel);
      updatePageActions(flags);
    }

    mTrackingProtectionEnabled = trackingMode == TrackingMode.TRACKING_CONTENT_BLOCKED;
  }
  private void setUpInputViewButtons() {
    boolean empty = inputView.getText().toString().trim().isEmpty();

    if (empty != isInputEmpty) {
      isInputEmpty = empty;
    }

    if (isInputEmpty) {
      sendButton.setImageResource(R.drawable.ic_button_send_inactive_24dp);
      securityButton.setVisibility(View.VISIBLE);
      if (HttpFileUploadManager.getInstance().isFileUploadSupported(account)) {
        attachButton.setVisibility(View.VISIBLE);
      } else {
        attachButton.setVisibility(View.GONE);
      }
    } else {
      sendButton.setImageResource(R.drawable.ic_button_send);
      sendButton.setImageLevel(AccountManager.getInstance().getColorLevel(account));
      securityButton.setVisibility(View.GONE);
      attachButton.setVisibility(View.GONE);
    }
  }
 private void updateSecurityButton() {
   SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user);
   securityButton.setImageLevel(securityLevel.getImageLevel());
 }
Esempio n. 7
0
  public void show(Panel panelToShow) {
    if (!isShown()) setVisibility(View.VISIBLE);

    if (mPanel != null) {
      // Hide the old panel.
      mPanel.hide();
    }

    final boolean showAnimation = !mVisible;
    mVisible = true;
    mCurrentPanel = panelToShow;

    int index = panelToShow.ordinal();
    mTabWidget.setCurrentTab(index);

    switch (panelToShow) {
      case NORMAL_TABS:
        mPanel = mPanelNormal;
        break;
      case PRIVATE_TABS:
        mPanel = mPanelPrivate;
        break;
      case REMOTE_TABS:
        mPanel = mPanelRemote;
        break;

      default:
        throw new IllegalArgumentException("Unknown panel type " + panelToShow);
    }
    mPanel.show();

    if (mCurrentPanel == Panel.REMOTE_TABS) {
      if (mFooter != null) mFooter.setVisibility(View.GONE);

      mAddTab.setVisibility(View.INVISIBLE);

      mMenuButton.setVisibility(View.GONE);
    } else {
      if (mFooter != null) mFooter.setVisibility(View.VISIBLE);

      mAddTab.setVisibility(View.VISIBLE);
      mAddTab.setImageLevel(index);

      if (!HardwareUtils.hasMenuButton()) {
        mMenuButton.setVisibility(View.VISIBLE);
        mMenuButton.setEnabled(true);
        mPopupMenu.setAnchor(mMenuButton);
      } else {
        mPopupMenu.setAnchor(mAddTab);
      }
    }

    if (isSideBar()) {
      if (showAnimation) dispatchLayoutChange(getWidth(), getHeight());
    } else {
      int actionBarHeight =
          mContext.getResources().getDimensionPixelSize(R.dimen.browser_toolbar_height);
      int height = actionBarHeight + getTabContainerHeight(mTabsContainer);
      dispatchLayoutChange(getWidth(), height);
    }
    mHeaderVisible = true;
  }
  public void from(LinearLayout layout) {
    mLayout = layout;

    mShowSiteSecurity = false;
    mShowReader = false;
    mReaderPopup = null;

    mAwesomeBar = (Button) mLayout.findViewById(R.id.awesome_bar);
    mAwesomeBar.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            GeckoApp.mAppContext.hideTabs();
            onAwesomeBarSearch();
          }
        });
    mAwesomeBar.setOnCreateContextMenuListener(
        new View.OnCreateContextMenuListener() {
          public void onCreateContextMenu(
              ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
            MenuInflater inflater = GeckoApp.mAppContext.getMenuInflater();
            inflater.inflate(R.menu.titlebar_contextmenu, menu);

            String clipboard = GeckoAppShell.getClipboardText();
            if (clipboard == null || TextUtils.isEmpty(clipboard)) {
              menu.findItem(R.id.pasteandgo).setVisible(false);
              menu.findItem(R.id.paste).setVisible(false);
            }

            Tab tab = Tabs.getInstance().getSelectedTab();
            if (tab != null) {
              String url = tab.getURL();
              if (url == null) {
                menu.findItem(R.id.copyurl).setVisible(false);
                menu.findItem(R.id.share).setVisible(false);
                menu.findItem(R.id.add_to_launcher).setVisible(false);
              }
            } else {
              // if there is no tab, remove anything tab dependent
              menu.findItem(R.id.copyurl).setVisible(false);
              menu.findItem(R.id.share).setVisible(false);
              menu.findItem(R.id.add_to_launcher).setVisible(false);
            }
          }
        });

    mPadding =
        new int[] {
          mAwesomeBar.getPaddingLeft(),
          mAwesomeBar.getPaddingTop(),
          mAwesomeBar.getPaddingRight(),
          mAwesomeBar.getPaddingBottom()
        };

    mTabs = (ImageButton) mLayout.findViewById(R.id.tabs);
    mTabs.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            toggleTabs();
          }
        });
    mTabs.setImageLevel(0);

    mTabsCount = (TextSwitcher) mLayout.findViewById(R.id.tabs_count);
    mTabsCount.removeAllViews();
    mTabsCount.setFactory(this);
    mTabsCount.setText("");
    mCount = 0;

    mBack = (ImageButton) mLayout.findViewById(R.id.back);
    mBack.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View view) {
            Tabs.getInstance().getSelectedTab().doBack();
          }
        });

    mForward = (ImageButton) mLayout.findViewById(R.id.forward);
    mForward.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View view) {
            Tabs.getInstance().getSelectedTab().doForward();
          }
        });

    mFavicon = (ImageButton) mLayout.findViewById(R.id.favicon);
    mSiteSecurity = (ImageButton) mLayout.findViewById(R.id.site_security);
    mSiteSecurity.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View view) {
            int[] lockLocation = new int[2];
            view.getLocationOnScreen(lockLocation);
            LayoutParams lockLayoutParams = (LayoutParams) view.getLayoutParams();

            // Calculate the left margin for the arrow based on the position of the lock icon.
            int leftMargin = lockLocation[0] - lockLayoutParams.rightMargin;
            SiteIdentityPopup.getInstance().show(mSiteSecurity, leftMargin);
          }
        });

    mProgressSpinner =
        (AnimationDrawable) mContext.getResources().getDrawable(R.drawable.progress_spinner);

    mStop = (ImageButton) mLayout.findViewById(R.id.stop);
    mStop.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            Tab tab = Tabs.getInstance().getSelectedTab();
            if (tab != null) tab.doStop();
          }
        });

    mReader = (ImageButton) mLayout.findViewById(R.id.reader);
    mReader.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View view) {
            if (mReaderPopup == null) mReaderPopup = new ReaderPopup(GeckoApp.mAppContext);

            mReaderPopup.show();
          }
        });

    mShadow = (ImageView) mLayout.findViewById(R.id.shadow);

    mHandler = new Handler();
    mSlideUpIn = new TranslateAnimation(0, 0, 40, 0);
    mSlideUpOut = new TranslateAnimation(0, 0, 0, -40);
    mSlideDownIn = new TranslateAnimation(0, 0, -40, 0);
    mSlideDownOut = new TranslateAnimation(0, 0, 0, 40);

    mDuration = 750;
    mSlideUpIn.setDuration(mDuration);
    mSlideUpOut.setDuration(mDuration);
    mSlideDownIn.setDuration(mDuration);
    mSlideDownOut.setDuration(mDuration);

    mMenu = (ImageButton) mLayout.findViewById(R.id.menu);
    mActionItemBar = (LinearLayout) mLayout.findViewById(R.id.menu_items);
    mHasSoftMenuButton = false;

    if (Build.VERSION.SDK_INT >= 11) mHasSoftMenuButton = true;

    if (Build.VERSION.SDK_INT >= 14) {
      if (!ViewConfiguration.get(GeckoApp.mAppContext).hasPermanentMenuKey())
        mHasSoftMenuButton = true;
      else mHasSoftMenuButton = false;
    }

    if (mHasSoftMenuButton) {
      mMenu.setVisibility(View.VISIBLE);
      mMenu.setOnClickListener(
          new Button.OnClickListener() {
            public void onClick(View view) {
              GeckoApp.mAppContext.openOptionsMenu();
            }
          });
    }

    if (Build.VERSION.SDK_INT >= 11) {
      View panel = GeckoApp.mAppContext.getMenuPanel();

      // If panel is null, the app is starting up for the first time;
      //    add this to the popup only if we have a soft menu button.
      // else, browser-toolbar is initialized on rotation,
      //    and we need to re-attach action-bar items.

      if (panel == null) {
        GeckoApp.mAppContext.onCreatePanelMenu(Window.FEATURE_OPTIONS_PANEL, null);
        panel = GeckoApp.mAppContext.getMenuPanel();

        if (mHasSoftMenuButton) {
          mMenuPopup = new MenuPopup(mContext);
          mMenuPopup.setPanelView(panel);
        }
      }
    }
  }
Esempio n. 9
0
  public BrowserToolbar(Context context, AttributeSet attrs) {
    super(context, attrs);

    mContext = context;

    // Get the device's highlight color
    ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext, android.R.style.TextAppearance);
    TypedArray typedArray =
        wrapper.getTheme().obtainStyledAttributes(new int[] {android.R.attr.textColorHighlight});
    mColor = typedArray.getColor(typedArray.getIndex(0), 0);

    // Load layout into the custom view
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    inflater.inflate(R.layout.browser_toolbar, this);

    mAwesomeBar = (Button) findViewById(R.id.awesome_bar);
    mAwesomeBar.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            onAwesomeBarSearch();
          }
        });

    Resources resources = getResources();

    int padding[] = {
      mAwesomeBar.getPaddingLeft(),
      mAwesomeBar.getPaddingTop(),
      mAwesomeBar.getPaddingRight(),
      mAwesomeBar.getPaddingBottom()
    };

    GeckoStateListDrawable states = new GeckoStateListDrawable();
    states.initializeFilter(mColor);
    states.addState(
        new int[] {android.R.attr.state_pressed},
        resources.getDrawable(R.drawable.address_bar_url_pressed));
    states.addState(new int[] {}, resources.getDrawable(R.drawable.address_bar_url_default));
    mAwesomeBar.setBackgroundDrawable(states);

    mAwesomeBar.setPadding(padding[0], padding[1], padding[2], padding[3]);

    mTabs = (ImageButton) findViewById(R.id.tabs);
    mTabs.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            if (Tabs.getInstance().getCount() > 1) showTabs();
            else addTab();
          }
        });
    mTabs.setImageLevel(1);

    mCounterColor = 0x99ffffff;

    mTabsCount = (TextSwitcher) findViewById(R.id.tabs_count);
    mTabsCount.setFactory(
        new ViewFactory() {
          public View makeView() {
            TextView text = new TextView(mContext);
            text.setGravity(Gravity.CENTER);
            text.setTextSize(16);
            text.setTextColor(mCounterColor);
            text.setTypeface(text.getTypeface(), Typeface.BOLD);
            return text;
          }
        });
    mCount = 0;
    mTabsCount.setText("0");

    mFavicon = (ImageButton) findViewById(R.id.favicon);
    mSiteSecurity = (ImageButton) findViewById(R.id.site_security);
    mProgressSpinner = (AnimationDrawable) resources.getDrawable(R.drawable.progress_spinner);

    mStop = (ImageButton) findViewById(R.id.stop);
    mStop.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            doStop();
          }
        });

    mHandler = new Handler();
    mSlideUpIn = new TranslateAnimation(0, 0, 30, 0);
    mSlideUpOut = new TranslateAnimation(0, 0, 0, -30);
    mSlideDownIn = new TranslateAnimation(0, 0, -30, 0);
    mSlideDownOut = new TranslateAnimation(0, 0, 0, 30);

    mDuration = 750;
    mSlideUpIn.setDuration(mDuration);
    mSlideUpOut.setDuration(mDuration);
    mSlideDownIn.setDuration(mDuration);
    mSlideDownOut.setDuration(mDuration);
  }
Esempio n. 10
0
 public void setSecurityMode(String mode) {
   if (mode.equals("identified") || mode.equals("verified")) mSiteSecurity.setImageLevel(1);
   else mSiteSecurity.setImageLevel(0);
 }