@Override
 public void onInsetsChanged(Rect insets) {
   Toolbar toolbar = getActionBarToolbar();
   ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
   lp.topMargin = insets.top;
   int top = insets.top;
   insets.top += getActionBarToolbar().getHeight();
   toolbar.setLayoutParams(lp);
   mMapFragment.setMapInsets(insets);
   insets.top = top; // revert
 }
Esempio n. 2
0
 private void configToolBar(Toolbar tb) {
   LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tb.getLayoutParams();
   lp.setMargins(0, ViewUtils.getStatusBarHeight(getActivity()), 0, 0);
   tb.setLayoutParams(lp);
   tb.setNavigationOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View view) {
           dismiss(null, null);
         }
       });
 }
Esempio n. 3
0
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHideTimer = new Timer("actionbar-hide-timer");
    if (savedInstanceState == null)
      overridePendingTransition(R.anim.slide_in_right, R.anim.fade_out);
    setContentView(R.layout.activity_imageviewer);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    try {
      setSupportActionBar(toolbar);
    } catch (Throwable t) {
    }
    if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 19)
      getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    else if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
      ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
      int resid = getResources().getIdentifier("status_bar_height", "dimen", "android");
      if (resid > 0) lp.topMargin = getResources().getDimensionPixelSize(resid);
      else lp.topMargin = getResources().getDimensionPixelSize(R.dimen.status_bar_height);
      toolbar.setLayoutParams(lp);
    }
    getSupportActionBar().setTitle("Image Viewer");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar()
        .setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_translucent));

    mImage = (WebView) findViewById(R.id.image);
    mImage.setBackgroundColor(0);
    mImage.addJavascriptInterface(new JSInterface(), "Android");
    mImage.getSettings().setBuiltInZoomControls(true);
    if (Integer.parseInt(Build.VERSION.SDK) >= 19)
      mImage.getSettings().setDisplayZoomControls(false);
    mImage.getSettings().setJavaScriptEnabled(true);
    mImage.getSettings().setLoadWithOverviewMode(true);
    mImage.getSettings().setUseWideViewPort(true);
    mImage.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onProgressChanged(WebView view, int newProgress) {
            mProgress.setProgress(newProgress);
          }
        });
    mImage.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageFinished(WebView view, String url) {
            mSpinner.setVisibility(View.GONE);
            mProgress.setVisibility(View.GONE);
            mImage.setVisibility(View.VISIBLE);
            hide_actionbar();
          }

          @Override
          public void onReceivedError(
              WebView view, int errorCode, String description, String failingUrl) {
            fail();
          }

          @Override
          public void onLoadResource(WebView view, String url) {
            mSpinner.setVisibility(View.GONE);
            mProgress.setVisibility(View.VISIBLE);
          }
        });
    mSpinner = (ProgressBar) findViewById(R.id.spinner);
    mProgress = (ProgressBar) findViewById(R.id.progress);

    findViewById(R.id.video)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                if (toolbar.getVisibility() == View.VISIBLE) {
                  if (mHideTimerTask != null) mHideTimerTask.cancel();
                  if (Build.VERSION.SDK_INT > 16) {
                    toolbar
                        .animate()
                        .alpha(0)
                        .translationY(-toolbar.getHeight())
                        .withEndAction(
                            new Runnable() {
                              @Override
                              public void run() {
                                toolbar.setVisibility(View.GONE);
                              }
                            });
                  } else {
                    toolbar.setVisibility(View.GONE);
                  }
                } else {
                  if (Build.VERSION.SDK_INT > 16) {
                    toolbar.setAlpha(0);
                    toolbar.animate().alpha(1).translationY(0);
                  }
                  toolbar.setVisibility(View.VISIBLE);
                  hide_actionbar();
                }
              }
            });

    if (getIntent() != null && getIntent().getDataString() != null) {
      String url =
          getIntent()
              .getDataString()
              .replace(getResources().getString(R.string.IMAGE_SCHEME), "http");
      String lower = url.toLowerCase().replace("https://", "").replace("http://", "");
      if (lower.startsWith("www.dropbox.com/")) {
        if (lower.startsWith("www.dropbox.com/s/")) {
          url = url.replace("://www.dropbox.com/s/", "://dl.dropboxusercontent.com/s/");
        } else {
          url = url + "?dl=1";
        }
      } else if ((lower.startsWith("d.pr/i/") || lower.startsWith("droplr.com/i/"))
          && !lower.endsWith("+")) {
        url += "+";
      } else if (lower.startsWith("imgur.com/") || lower.startsWith("www.imgur.com/")) {
        String id = url.replace("https://", "").replace("http://", "");
        id = id.substring(id.indexOf("/") + 1);

        if (!id.contains("/") && id.length() > 0) {
          new ImgurImageTask().execute(id);
        } else if (id.startsWith("gallery/") && id.length() > 8) {
          new ImgurGalleryTask().execute(id.substring(8));
        } else {
          fail();
        }
        return;
      } else if (lower.startsWith("i.imgur.com") && lower.endsWith(".gifv")) {
        String id = url.replace("https://", "").replace("http://", "");
        id = id.substring(id.indexOf("/") + 1);
        id = id.substring(0, id.length() - 5);
        new ImgurImageTask().execute(id);
        return;
      } else if (lower.startsWith("gfycat.com/") || lower.startsWith("www.gfycat.com/")) {
        String id = url;
        if (id.endsWith("/")) id = id.substring(0, id.length() - 1);
        id = id.substring(id.lastIndexOf("/") + 1, id.length());
        new GfyCatTask().execute(id);
        return;
      } else if (lower.startsWith("giphy.com/")
          || lower.startsWith("www.giphy.com/")
          || lower.startsWith("gph.is/")) {
        if (lower.contains("/gifs/") && lower.lastIndexOf("/") > lower.indexOf("/gifs/") + 6)
          url = url.substring(0, lower.lastIndexOf("/"));
        new OEmbedTask().execute("https://giphy.com/services/oembed/?url=" + url);
        return;
      } else if (lower.startsWith("flickr.com/") || lower.startsWith("www.flickr.com/")) {
        new OEmbedTask().execute("https://www.flickr.com/services/oembed/?format=json&url=" + url);
        return;
      } else if (lower.startsWith("instagram.com/")
          || lower.startsWith("www.instagram.com/")
          || lower.startsWith("instagr.am/")
          || lower.startsWith("www.instagr.am/")) {
        new OEmbedTask().execute("http://api.instagram.com/oembed?url=" + url);
        return;
      } else if (lower.startsWith("cl.ly")) {
        new ClLyTask().execute(url);
        return;
      } else if (url.contains("/wiki/File:")) {
        new WikiTask()
            .execute(
                url.replace(
                    "/wiki/",
                    "/w/api.php?action=query&format=json&prop=imageinfo&iiprop=url&titles="));
      } else if (lower.startsWith("leetfiles.com/") || lower.startsWith("www.leetfiles.com/")) {
        url =
            url.replace("www.", "")
                .replace("leetfiles.com/image/", "i.leetfiles.com/")
                .replace("?id=", "");
      } else if (lower.startsWith("leetfil.es/") || lower.startsWith("www.leetfil.es/")) {
        url =
            url.replace("www.", "")
                .replace("leetfil.es/image/", "i.leetfiles.com/")
                .replace("?id=", "");
      }
      loadImage(url);
    } else {
      finish();
    }
  }
  public ToolbarWidgetWrapper(
      Toolbar toolbar,
      boolean style,
      int defaultNavigationContentDescription,
      int defaultNavigationIcon) {
    mToolbar = toolbar;
    mTitle = toolbar.getTitle();
    mSubtitle = toolbar.getSubtitle();
    mTitleSet = mTitle != null;
    mNavIcon = toolbar.getNavigationIcon();

    if (style) {
      final TintTypedArray a =
          TintTypedArray.obtainStyledAttributes(
              toolbar.getContext(), null, R.styleable.ActionBar, R.attr.actionBarStyle, 0);

      final CharSequence title = a.getText(R.styleable.ActionBar_title);
      if (!TextUtils.isEmpty(title)) {
        setTitle(title);
      }

      final CharSequence subtitle = a.getText(R.styleable.ActionBar_subtitle);
      if (!TextUtils.isEmpty(subtitle)) {
        setSubtitle(subtitle);
      }

      final Drawable logo = a.getDrawable(R.styleable.ActionBar_logo);
      if (logo != null) {
        setLogo(logo);
      }

      final Drawable icon = a.getDrawable(R.styleable.ActionBar_icon);
      if (mNavIcon == null && icon != null) {
        setIcon(icon);
      }

      final Drawable navIcon = a.getDrawable(R.styleable.ActionBar_homeAsUpIndicator);
      if (navIcon != null) {
        setNavigationIcon(navIcon);
      }

      setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, 0));

      final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
      if (customNavId != 0) {
        setCustomView(
            LayoutInflater.from(mToolbar.getContext()).inflate(customNavId, mToolbar, false));
        setDisplayOptions(mDisplayOpts | ActionBar.DISPLAY_SHOW_CUSTOM);
      }

      final int height = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
      if (height > 0) {
        final ViewGroup.LayoutParams lp = mToolbar.getLayoutParams();
        lp.height = height;
        mToolbar.setLayoutParams(lp);
      }

      final int contentInsetStart =
          a.getDimensionPixelOffset(R.styleable.ActionBar_contentInsetStart, -1);
      final int contentInsetEnd =
          a.getDimensionPixelOffset(R.styleable.ActionBar_contentInsetEnd, -1);
      if (contentInsetStart >= 0 || contentInsetEnd >= 0) {
        mToolbar.setContentInsetsRelative(
            Math.max(contentInsetStart, 0), Math.max(contentInsetEnd, 0));
      }

      final int titleTextStyle = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
      if (titleTextStyle != 0) {
        mToolbar.setTitleTextAppearance(mToolbar.getContext(), titleTextStyle);
      }

      final int subtitleTextStyle = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);
      if (subtitleTextStyle != 0) {
        mToolbar.setSubtitleTextAppearance(mToolbar.getContext(), subtitleTextStyle);
      }

      final int popupTheme = a.getResourceId(R.styleable.ActionBar_popupTheme, 0);
      if (popupTheme != 0) {
        mToolbar.setPopupTheme(popupTheme);
      }

      a.recycle();
      // Keep the TintManager in case we need it later
      mTintManager = a.getTintManager();
    } else {
      mDisplayOpts = detectDisplayOptions();
      // Create a TintManager in case we need it later
      mTintManager = new TintManager(toolbar.getContext());
    }

    setDefaultNavigationContentDescription(defaultNavigationContentDescription);
    mHomeDescription = mToolbar.getNavigationContentDescription();

    setDefaultNavigationIcon(mTintManager.getDrawable(defaultNavigationIcon));

    mToolbar.setNavigationOnClickListener(
        new View.OnClickListener() {
          final ActionMenuItem mNavItem =
              new ActionMenuItem(mToolbar.getContext(), 0, android.R.id.home, 0, 0, mTitle);

          @Override
          public void onClick(View v) {
            if (mWindowCallback != null && mMenuPrepared) {
              mWindowCallback.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mNavItem);
            }
          }
        });
  }