Пример #1
0
 /** 加载入口 */
 public void loadEntry() {
   boolean sentry = false;
   if (null == Profile.instance().region && 0 != currentRegionId) {
     currentRegionId = 0;
     sentry = true;
   } else if (null != Profile.instance().region
       && Profile.instance().region.id != currentRegionId) {
     currentRegionId = Profile.instance().region.id;
     sentry = true;
   }
   if (null == Me.instance && null != currentUserId) {
     currentUserId = null;
     sentry = true;
   } else if (null != Me.instance && !Me.instance.id.equals(currentUserId)) {
     currentUserId = Me.instance.id;
     sentry = true;
   }
   if (sentry) {
     if (null == Me.instance) {
       browser.loadUrl(Networking.fetchURL("HomePage", "", currentRegionId));
     } else {
       browser.loadUrl(Networking.fetchURL("HomePage", Me.instance.token, currentRegionId));
     }
   }
 }
Пример #2
0
  /** 界面预设 */
  private void prepare() {
    if (listNews.getHeaderViewsCount() > 0) {
      return;
    }
    animRight =
        new RotateAnimation(
            -30, 30f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    animRight.setDuration(1000);
    animRight.setAnimationListener(listener);
    animLeft =
        new RotateAnimation(
            30f, -30f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    animLeft.setDuration(1000);
    animLeft.setAnimationListener(listener);
    View viewHead = LayoutInflater.from(this.getActivity()).inflate(R.layout.div_home_head, null);
    listNews.addHeaderView(viewHead);
    scrollEntry = (HorizontalScrollViewEx) viewHead.findViewById(R.id.home_scroll_entry);
    scrollEntry.setHorizontalScrollViewListenner(
        new HorizontalScrollViewEx.HorizontalScrollViewListenner() {
          @Override
          public void onScrollChanged(int x, int y, int oldx, int oldy) {
            if (x > oldx && x > 50) {
              imgDot1.setImageResource(R.drawable.icon_dot_unselected);
              imgDot2.setImageResource(R.drawable.icon_dot_selected);
            } else if (x < oldx && x < 50) {
              imgDot1.setImageResource(R.drawable.icon_dot_selected);
              imgDot2.setImageResource(R.drawable.icon_dot_unselected);
            }
          }
        });
    viewEntry1 = (View) viewHead.findViewById(R.id.home_layout_entry1);
    viewEntry2 = (View) viewHead.findViewById(R.id.home_layout_entry2);
    viewEntry3 = (View) viewHead.findViewById(R.id.home_layout_entry3);
    viewEntry4 = (View) viewHead.findViewById(R.id.home_layout_entry4);
    viewEntry5 = (View) viewHead.findViewById(R.id.home_layout_entry5);
    viewEntry6 = (View) viewHead.findViewById(R.id.home_layout_entry6);
    btnRegion.getBackground().setAlpha(200);
    btnSearch.getBackground().setAlpha(200);
    btnBell.setImageAlpha(200);
    imgDot1 = (ImageView) viewHead.findViewById(R.id.home_image_dot1);
    imgDot2 = (ImageView) viewHead.findViewById(R.id.home_image_dot2);
    browser = (ScrollWebView) viewHead.findViewById(R.id.home_browser);

    DisplayMetrics metrics = new DisplayMetrics();
    this.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    LayoutParams lp = (LayoutParams) browser.getLayoutParams();
    lp.height = metrics.widthPixels * 7 / 10;
    browser.setLayoutParams(lp);

    browser.getSettings().setJavaScriptEnabled(true);
    browser.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    browser.setWebViewClient(
        new WebViewClient() {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Intent intent = new Intent(HomeActivity.this.getActivity(), BrowserActivity.class);
            intent.putExtra("url", url);
            startActivity(intent);
            browser.pauseTimers();
            browser.resumeTimers();
            return true;
          }

          @Override
          public void onReceivedError(
              WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            browser.loadUrl("about:blank");
          }
        });

    View viewActivity1 = (View) viewHead.findViewById(R.id.home_layout_left);
    viewActivity1.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            String token = "";
            if (null != Me.instance) {
              token = Me.instance.token;
            }
            String regionId = "";
            if (null != Profile.instance().region) {
              regionId = String.valueOf(Profile.instance().region.id);
            }
            Helper.openBrowser(
                HomeActivity.this.getActivity(), Networking.fetchURL("activity1", token, regionId));
          }
        });
    View viewActivity2 = (View) viewHead.findViewById(R.id.home_layout_right);
    viewActivity2.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            String token = "";
            if (null != Me.instance) {
              token = Me.instance.token;
            }
            String regionId = "";
            if (null != Profile.instance().region) {
              regionId = String.valueOf(Profile.instance().region.id);
            }
            Helper.openBrowser(
                HomeActivity.this.getActivity(), Networking.fetchURL("activity2", token, regionId));
          }
        });
    this.getActivity().findViewById(R.id.home_layout_header).bringToFront();
  }