Ejemplo n.º 1
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();
  }
Ejemplo n.º 2
0
 /** 处理入口按钮 */
 public void dealEntry() {
   scrollEntry.setHorizontalScrollBarEnabled(false);
   DisplayMetrics metrics = new DisplayMetrics();
   this.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
   LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) viewEntry1.getLayoutParams();
   lp.width = metrics.widthPixels / 4;
   viewEntry1.setLayoutParams(lp);
   viewEntry1.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View v) {
           Intent intent0 =
               new Intent(HomeActivity.this.getActivity(), SelectDoctorActivity.class);
           HomeActivity.this.startActivity(intent0);
         }
       });
   lp = (LinearLayout.LayoutParams) viewEntry2.getLayoutParams();
   lp.width = metrics.widthPixels / 4;
   viewEntry2.setLayoutParams(lp);
   viewEntry2.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View v) {
           if (null == Profile.instance().region) {
             Intent intent = new Intent(HomeActivity.this.getActivity(), RegionActivity.class);
             HomeActivity.this.startActivityForResult(intent, MESSAGE_REGION);
             Toast.makeText(HomeActivity.this.getActivity(), "请设置所在小区", Toast.LENGTH_LONG).show();
             return;
           }
           if (null == Me.instance) {
             Intent intent = new Intent(HomeActivity.this.getActivity(), LoginActivity.class);
             HomeActivity.this.startActivity(intent);
             Toast.makeText(HomeActivity.this.getActivity(), "请先登录账号", Toast.LENGTH_LONG).show();
             return;
           }
           Helper.openBrowser(
               HomeActivity.this.getActivity(),
               Networking.fetchURL(
                   "yuyuetijian", Profile.instance().region.id, Me.instance.token));
         }
       });
   lp = (LinearLayout.LayoutParams) viewEntry3.getLayoutParams();
   lp.width = metrics.widthPixels / 4;
   viewEntry3.setLayoutParams(lp);
   viewEntry3.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View v) {
           if (null == Profile.instance().region) {
             Intent intent = new Intent(HomeActivity.this.getActivity(), RegionActivity.class);
             HomeActivity.this.startActivityForResult(intent, MESSAGE_REGION);
             Toast.makeText(HomeActivity.this.getActivity(), "请设置所在小区", Toast.LENGTH_LONG).show();
             return;
           }
           if (null == Me.instance) {
             Intent intent = new Intent(HomeActivity.this.getActivity(), LoginActivity.class);
             HomeActivity.this.startActivity(intent);
             Toast.makeText(HomeActivity.this.getActivity(), "请先登录账号", Toast.LENGTH_LONG).show();
             return;
           }
           Helper.openBrowser(
               HomeActivity.this.getActivity(),
               Networking.fetchURL(
                   "yuyueliliao", Profile.instance().region.id, Me.instance.token));
         }
       });
   lp = (LinearLayout.LayoutParams) viewEntry4.getLayoutParams();
   lp.width = metrics.widthPixels / 4;
   viewEntry4.setLayoutParams(lp);
   viewEntry4.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View v) {
           Intent intent = new Intent(HomeActivity.this.getActivity(), ArchiveActivity.class);
           intent.putExtra("password", 0);
           HomeActivity.this.startActivity(intent);
         }
       });
   lp = (LinearLayout.LayoutParams) viewEntry5.getLayoutParams();
   lp.width = metrics.widthPixels / 4;
   viewEntry5.setLayoutParams(lp);
   viewEntry5.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View v) {
           if (null == Profile.instance().region) {
             Intent intent = new Intent(HomeActivity.this.getActivity(), RegionActivity.class);
             HomeActivity.this.startActivityForResult(intent, MESSAGE_REGION);
             Toast.makeText(HomeActivity.this.getActivity(), "请设置所在小区", Toast.LENGTH_LONG).show();
             return;
           }
           if (null == Me.instance) {
             Intent intent = new Intent(HomeActivity.this.getActivity(), LoginActivity.class);
             HomeActivity.this.startActivity(intent);
             Toast.makeText(HomeActivity.this.getActivity(), "请先登录账号", Toast.LENGTH_LONG).show();
             return;
           }
           Helper.openBrowser(
               HomeActivity.this.getActivity(),
               Networking.fetchURL(
                   "yuyueguahao", Profile.instance().region.id, Me.instance.token));
         }
       });
   lp = (LinearLayout.LayoutParams) viewEntry6.getLayoutParams();
   lp.width = metrics.widthPixels / 4;
   viewEntry6.setLayoutParams(lp);
   viewEntry6.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View v) {
           Intent intent =
               new Intent(HomeActivity.this.getActivity(), SelfDiagnosticActivity.class);
           HomeActivity.this.startActivity(intent);
         }
       });
 }