private void bounceBackHeader() {
    int yTranslate =
        state == State.REFRESHING
            ? header.getHeight() - headerContainer.getHeight()
            : -headerContainer.getHeight() - headerContainer.getTop();

    TranslateAnimation bounceAnimation =
        new TranslateAnimation(
            TranslateAnimation.ABSOLUTE,
            0,
            TranslateAnimation.ABSOLUTE,
            0,
            TranslateAnimation.ABSOLUTE,
            0,
            TranslateAnimation.ABSOLUTE,
            yTranslate);

    bounceAnimation.setDuration(BOUNCE_ANIMATION_DURATION);
    bounceAnimation.setFillEnabled(true);
    bounceAnimation.setFillAfter(false);
    bounceAnimation.setFillBefore(true);
    bounceAnimation.setInterpolator(new OvershootInterpolator(BOUNCE_OVERSHOOT_TENSION));
    bounceAnimation.setAnimationListener(new HeaderAnimationListener(yTranslate));

    startAnimation(bounceAnimation);
  }
  private void init() {
    setVerticalFadingEdgeEnabled(false);

    headerContainer =
        (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.ptr_header, null);
    header = (RelativeLayout) headerContainer.findViewById(R.id.ptr_id_header);
    text = (TextView) header.findViewById(R.id.ptr_id_text);
    lastUpdatedTextView = (TextView) header.findViewById(R.id.ptr_id_last_updated);
    image = (ImageView) header.findViewById(R.id.ptr_id_image);
    spinner = (ProgressBar) header.findViewById(R.id.ptr_id_spinner);

    pullToRefreshText = getContext().getString(R.string.ptr_pull_to_refresh);
    releaseToRefreshText = getContext().getString(R.string.ptr_release_to_refresh);
    refreshingText = getContext().getString(R.string.ptr_refreshing);
    lastUpdatedText = getContext().getString(R.string.ptr_last_updated);

    flipAnimation =
        new RotateAnimation(
            0,
            -180,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    flipAnimation.setInterpolator(new LinearInterpolator());
    flipAnimation.setDuration(ROTATE_ARROW_ANIMATION_DURATION);
    flipAnimation.setFillAfter(true);

    reverseFlipAnimation =
        new RotateAnimation(
            -180,
            0,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    reverseFlipAnimation.setInterpolator(new LinearInterpolator());
    reverseFlipAnimation.setDuration(ROTATE_ARROW_ANIMATION_DURATION);
    reverseFlipAnimation.setFillAfter(true);

    addHeaderView(headerContainer);
    setState(State.PULL_TO_REFRESH);
    scrollbarEnabled = isVerticalScrollBarEnabled();

    ViewTreeObserver vto = header.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new PTROnGlobalLayoutListener());

    super.setOnItemClickListener(new PTROnItemClickListener());
    super.setOnItemLongClickListener(new PTROnItemLongClickListener());
  }
Beispiel #3
0
  public void doNav() {

    String url = urlField.getText().toString();

    if (URLUtil.isValidUrl(url) == false) {
      url = "http://" + url;
    }

    urlField.setText(url);

    webView.requestFocus();

    webView.loadUrl(url);

    navbar.startAnimation(slideUp);
  }
Beispiel #4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
    linearLayout.setBackgroundColor(Color.BLACK);

    // Navbar setup

    navbar = (LinearLayout) findViewById(R.id.navbar);
    goButton = (Button) findViewById(R.id.go_button);
    urlField = (EditText) findViewById(R.id.url);

    goButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            doNav();
          }
        });

    urlField.setOnEditorActionListener(
        new OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_GO) {

              doNav();

              handled = true;
            }
            return handled;
          }
        });

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    String lastUrl = settings.getString("lastUrl", "");

    urlField.setText(lastUrl);

    // Navbar animation settings

    AnimationListener slideListener =
        new AnimationListener() {
          @Override
          public void onAnimationEnd(Animation animation) {
            if (animation.equals(slideUp)) {
              navbar.setVisibility(View.GONE);
            }
          }

          @Override
          public void onAnimationRepeat(Animation animation) {}

          @Override
          public void onAnimationStart(Animation animation) {
            if (animation.equals(slideDown)) {
              navbar.setVisibility(View.VISIBLE);
            }
          }
        };

    slideUp =
        new TranslateAnimation(
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            -1.0f);
    slideUp.setDuration(500);
    slideUp.setAnimationListener(slideListener);

    slideDown =
        new TranslateAnimation(
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            -1.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f);
    slideDown.setDuration(500);
    slideDown.setAnimationListener(slideListener);

    // WebView setup

    webView = (WebView) findViewById(R.id.webView);

    WebSettings webSettings = webView.getSettings();

    webView.setWebChromeClient(new WebChromeClient());

    webView.setWebViewClient(
        new WebViewClient() {

          @Override
          public void onPageFinished(WebView view, String url) {

            Log.d("scale", view.getScale() + "");

            Log.d("pageFinished", url);

            view.setInitialScale(70);

            if (url.equalsIgnoreCase(HOME_PAGE)) {
              // navbar.setVisibility(View.VISIBLE);
              navbar.startAnimation(slideDown);
            }
          }

          @Override
          public void onScaleChanged(WebView view, float oldScale, float newScale) {

            Log.d("scale changed", oldScale + " - " + newScale);

            if (newScale > 0.7) {

              Log.d("scale", "reset");
              // view.setInitialScale(70);

            }
          }
        });

    webView.setInitialScale(70);

    webView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    webView.setVerticalScrollBarEnabled(false);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setOverScrollMode(WebView.OVER_SCROLL_NEVER);

    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);

    webSettings.setSupportZoom(true);

    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    webSettings.setPluginState(WebSettings.PluginState.ON);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDatabasePath(
        "/data/data/" + webView.getContext().getPackageName() + "/databases/");
    webSettings.setSaveFormData(false);
    webSettings.setLightTouchEnabled(false);
    webSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
    webSettings.setRenderPriority(RenderPriority.HIGH);
    webSettings.setUserAgentString(
        "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Large Screen Safari/534.24 GoogleTV");

    final Intent intent = getIntent();
    if ((intent.getAction() == Intent.ACTION_VIEW) && (intent.getData() != null)) {
      final String url = intent.getDataString();
      urlField.setText(url);
      webView.loadUrl(url);
      navbar.setVisibility(View.GONE);
    } else {
      webView.loadUrl(HOME_PAGE);
    }

    webView.requestFocus();
  }