示例#1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Logger.v("onCreateView");
    View view = inflater.inflate(R.layout.fragment_thread_detail, container, false);

    mDetailListView = (XListView) view.findViewById(R.id.lv_thread_details);
    mDetailListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    mTipBar = (TextView) view.findViewById(R.id.thread_detail_tipbar);
    mTipBar.bringToFront();

    mFam = (FloatingActionMenu) view.findViewById(R.id.multiple_actions);
    mFam.setVisibility(View.INVISIBLE);

    FloatingActionButton fabRefresh =
        (FloatingActionButton) view.findViewById(R.id.action_fab_refresh);
    fabRefresh.setImageDrawable(
        new IconicsDrawable(getActivity(), GoogleMaterial.Icon.gmd_refresh).color(Color.WHITE));
    fabRefresh.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            mFam.close(true);
            mFloorOfPage = LAST_FLOOR;
            refresh();
          }
        });

    FloatingActionButton fabQuickReply =
        (FloatingActionButton) view.findViewById(R.id.action_fab_quick_reply);
    fabQuickReply.setImageDrawable(
        new IconicsDrawable(getActivity(), GoogleMaterial.Icon.gmd_reply).color(Color.WHITE));
    fabQuickReply.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            mFam.close(false);
            mFam.setVisibility(View.INVISIBLE);
            quickReply.setVisibility(View.VISIBLE);
            quickReply.bringToFront();
            (new Handler())
                .postDelayed(
                    new Runnable() {
                      public void run() {
                        mReplyTextTv.requestFocus();
                        mReplyTextTv.dispatchTouchEvent(
                            MotionEvent.obtain(
                                SystemClock.uptimeMillis(),
                                SystemClock.uptimeMillis(),
                                MotionEvent.ACTION_DOWN,
                                0,
                                0,
                                0));
                        mReplyTextTv.dispatchTouchEvent(
                            MotionEvent.obtain(
                                SystemClock.uptimeMillis(),
                                SystemClock.uptimeMillis(),
                                MotionEvent.ACTION_UP,
                                0,
                                0,
                                0));
                      }
                    },
                    200);
          }
        });

    FloatingActionButton fabGotoPage =
        (FloatingActionButton) view.findViewById(R.id.action_fab_goto_page);
    fabGotoPage.setImageDrawable(
        new IconicsDrawable(getActivity(), GoogleMaterial.Icon.gmd_swap_horiz).color(Color.WHITE));
    fabGotoPage.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            mFam.close(true);
            showGotoPageDialog();
          }
        });

    if (!HiSettingsHelper.getInstance().getIsLandscape()) {
      mDetailListView.addHeaderView(inflater.inflate(R.layout.head_thread_detail, null));
      mTitleView = (TextView) view.findViewById(R.id.thread_detail_title);
      mTitleView.setTextSize(HiSettingsHelper.getTitleTextSize());
      mTitleView.setText(mTitle);
    }
    mDetailListView.setPullLoadEnable(false);
    mDetailListView.setPullRefreshEnable(false);
    mDetailListView.setXListViewListener(
        new XListView.IXListViewListener() {
          @Override
          public void onRefresh() {
            // Previous Page
            if (mCurrentPage > 1) {
              mCurrentPage--;
            }
            mDetailListView.stopRefresh();
            mFloorOfPage = LAST_FLOOR;
            showOrLoadPage();
            quickReply.setVisibility(View.INVISIBLE);
          }

          @Override
          public void onLoadMore() {
            // Next Page
            if (mCurrentPage < mMaxPage) {
              mCurrentPage++;
            }
            mDetailListView.stopLoadMore();
            showOrLoadPage();
          }
        });

    final GestureDetector.SimpleOnGestureListener listener =
        new GestureDetector.SimpleOnGestureListener() {
          @Override
          public boolean onDoubleTap(MotionEvent e) {
            if (mDetailListView.isFastScrollEnabled()) {
              mDetailListView.setFastScrollEnabled(false);
              mDetailListView.setFastScrollAlwaysVisible(false);
            } else {
              mDetailListView.setFastScrollEnabled(true);
              mDetailListView.setFastScrollAlwaysVisible(true);
            }
            return true;
          }
        };

    final GestureDetector detector = new GestureDetector(mCtx, listener);
    detector.setOnDoubleTapListener(listener);

    mDetailListView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View view, MotionEvent event) {
            if (mFam.isOpened()) {
              mFam.close(false);
            }
            return detector.onTouchEvent(event);
          }
        });

    quickReply = view.findViewById(R.id.quick_reply);
    mReplyTextTv = (TextView) quickReply.findViewById(R.id.tv_reply_text);
    mReplyTextTv.setTextSize(HiSettingsHelper.getPostTextSize());
    mPostReplyIb = (ImageButton) quickReply.findViewById(R.id.ib_reply_post);
    mPostReplyIb.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            String replyText = mReplyTextTv.getText().toString();
            if (replyText.length() < 5) {
              Toast.makeText(getActivity(), "字数必须大于5", Toast.LENGTH_LONG).show();
            } else {
              mReplyTextTv.setText("");
              quickReply.setVisibility(View.INVISIBLE);
              PostBean postBean = new PostBean();
              postBean.setContent(replyText);
              postBean.setTid(mTid);
              new PostAsyncTask(
                      getActivity(),
                      PostAsyncTask.MODE_QUICK_REPLY,
                      null,
                      ThreadDetailFragment.this)
                  .execute(postBean);
              // Close SoftKeyboard
              InputMethodManager imm =
                  (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
              imm.hideSoftInputFromWindow(mReplyTextTv.getWindowToken(), 0);
              mFam.setVisibility(View.VISIBLE);
            }
          }
        });

    return view;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
    super.onCreate(savedInstanceState);
    Intent data = getIntent();
    earthWallpaper = (EarthWallpaper) data.getExtras().getSerializable(WALLPAPER_OBJECT);
    // setTheme(R.style.AppTheme_NoActionBar);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
      setTheme(R.style.AppTheme_NoActionBar);
    }
    setContentView(R.layout.activity_wallpaper);

    downloadDialog = new BaseDialog(this).getDownloadDialog();

    if (!downloadDir.exists()) {
      boolean created = downloadDir.mkdir();
      Log.d("WallpaperActivity", "Download directory didn't exist : creation -> " + created);
    }

    if (!Preferences.exists()) Preferences.init(this);

    downloadDir = new File(Preferences.getInstance().getWallpaperDownloadDirectory());

    rootLayout = (CoordinatorLayout) findViewById(R.id.wallpaper_coordinator_root);
    collapsingToolbarLayout =
        (CollapsingToolbarLayout) findViewById(R.id.wallpaper_collapsing_toolbar);
    // collapsingToolbarLayout.setExpandedTitleTextAppearance(android.R.style.TextAppearance_DeviceDefault_Medium);
    collapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.FullscreenTextPreview);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_details_view);
    toolbar.setTitle(earthWallpaper.getFormattedWallpaperTitle());
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // set and load the appbar image
    appBarImage = (ImageView) findViewById(R.id.wall_preview);
    Picasso.with(this).load(earthWallpaper.getWallThumbUrl()).into(appBarImage);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      appBarImage.setTransitionName(data.getExtras().getString(IMAGE_TRANSITION_NAME));
      // toolbar.setTransitionName(data.getExtras().getString(TEXT_TRANSITION_NAME));
    }

    // assigning the information to the views
    cityTextView = (TextView) findViewById(R.id.details_location_text);
    if (earthWallpaper.getWallpaperRegion() == null) {
      cityTextView.setText(R.string.details_unknown);
    } else {
      cityTextView.setText(earthWallpaper.getWallpaperRegion());
    }
    countryTextView = (TextView) findViewById(R.id.details_country_text);
    if (earthWallpaper.getWallpaperCountry() == null) {
      countryTextView.setText(R.string.details_unknown);
    } else {
      countryTextView.setText(earthWallpaper.getWallpaperCountry());
    }
    coordinatesTextView = (TextView) findViewById(R.id.details_coords_text);
    coordinatesTextView.setText(getFormattedCoordinates());

    // setting the google maps layout stuff
    googleMapsLayout = (RelativeLayout) findViewById(R.id.gmaps_nav_layout);
    googleMapsLayout.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent googleMaps =
                new Intent(Intent.ACTION_VIEW, Uri.parse(earthWallpaper.getGoogleMapsUrl()));
            startActivity(googleMaps);
          }
        });
    googleMapsHintTextView = (TextView) findViewById(R.id.details_gmaps_link_icon_text);
    googleMapsHintTextView.setText(earthWallpaper.getGoogleMapsTitle());

    final int[] c = {0};
    attributionLayout = (RelativeLayout) findViewById(R.id.details_attribution_layout);
    attributionLayout.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            c[0]++;
            if (c[0] >= 20) unlock = true;
          }
        });

    attributionTextView = (TextView) findViewById(R.id.details_attribution_text);
    if (earthWallpaper.getWallpaperAttribution() == null) {
      attributionTextView.setText(R.string.details_unknown);
    } else {
      attributionTextView.setText(earthWallpaper.getWallpaperAttribution());
    }

    shareLinkLayout = (RelativeLayout) findViewById(R.id.share_link_layout);
    shareLinkLayout.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            onEarthViewShow();
          }
        });

    shareLinkTextView = (TextView) findViewById(R.id.details_share_link_text);
    shareLinkTextView.setText(earthWallpaper.getShareUrl());

    // inflating the fab menu and it's entries
    floatingActionMenu = (FloatingActionMenu) findViewById(R.id.details_fab_menu);
    floatingActionMenu.setClosedOnTouchOutside(true);

    floatingActionShare = (FloatingActionButton) findViewById(R.id.fab_item_share);
    floatingActionShare.setImageDrawable(
        new IconicsDrawable(this)
            .icon(CommunityMaterial.Icon.cmd_share_variant)
            .color(Color.WHITE)
            .sizeDp(16));
    floatingActionShare.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            onEarthViewShare();
            if (floatingActionMenu.isOpened()) floatingActionMenu.close(true);
          }
        });

    floatingActionApply = (FloatingActionButton) findViewById(R.id.fab_item_apply);
    floatingActionApply.setImageDrawable(
        new IconicsDrawable(this)
            .icon(CommunityMaterial.Icon.cmd_check)
            .color(Color.WHITE)
            .sizeDp(16));
    floatingActionApply.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // Snackbar.make(rootLayout, "Applying is coming soon!", Snackbar.LENGTH_SHORT).show();
            onSetAsWallpaper();
            if (floatingActionMenu.isOpened()) floatingActionMenu.close(true);
          }
        });

    floatingActionArchive = (FloatingActionButton) findViewById(R.id.fab_item_archive);
    if (Preferences.getInstance().isFavorite(earthWallpaper)) {
      floatingActionArchive.setImageDrawable(
          new IconicsDrawable(this)
              .icon(CommunityMaterial.Icon.cmd_heart_outline)
              .color(Color.WHITE)
              .sizeDp(16));
      floatingActionArchive.setLabelText(
          getResources().getString(R.string.fab_menu_item_remove_archive));
    } else {
      floatingActionArchive.setImageDrawable(
          new IconicsDrawable(this)
              .icon(CommunityMaterial.Icon.cmd_heart)
              .color(Color.WHITE)
              .sizeDp(16));
      floatingActionArchive.setLabelText(getResources().getString(R.string.fab_menu_item_archive));
    }
    floatingActionArchive.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (floatingActionMenu.isOpened()) floatingActionMenu.close(false);

            if (Preferences.getInstance().isFavorite(earthWallpaper)) {
              Preferences.getInstance().removeFavorite(earthWallpaper);
              floatingActionArchive.setImageDrawable(
                  new IconicsDrawable(WallpaperActivityPre.this)
                      .icon(CommunityMaterial.Icon.cmd_heart)
                      .color(Color.WHITE)
                      .sizeDp(16));
              floatingActionArchive.setLabelText(
                  getResources().getString(R.string.fab_menu_item_archive));
              Snackbar.make(rootLayout, R.string.fab_snack_bar_fav_removed, Snackbar.LENGTH_SHORT)
                  .setAction(
                      R.string.fab_snack_bar_fav_action,
                      new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {}
                      })
                  .show();
            } else {
              Preferences.getInstance().addFavorite(earthWallpaper);
              floatingActionArchive.setImageDrawable(
                  new IconicsDrawable(WallpaperActivityPre.this)
                      .icon(CommunityMaterial.Icon.cmd_heart_outline)
                      .color(Color.WHITE)
                      .sizeDp(16));
              floatingActionArchive.setLabelText(
                  getResources().getString(R.string.fab_menu_item_remove_archive));
              Snackbar.make(rootLayout, R.string.fab_snack_bar_fav_added, Snackbar.LENGTH_SHORT)
                  .setAction(
                      R.string.fab_snack_bar_fav_action,
                      new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {}
                      })
                  .show();
            }
          }
        });

    floatingActionDownload = (FloatingActionButton) findViewById(R.id.fab_item_download);
    floatingActionDownload.setImageDrawable(
        new IconicsDrawable(this)
            .icon(CommunityMaterial.Icon.cmd_download)
            .color(Color.WHITE)
            .sizeDp(16));
    floatingActionDownload.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (floatingActionMenu.isOpened()) floatingActionMenu.close(true);
            if (Preferences.getInstance().canWriteExternalStorage()) {
              new DownloadWallpaperTask(
                      WallpaperActivityPre.this,
                      Preferences.getInstance().getWallpaperDownloadDir(),
                      earthWallpaper)
                  .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, unlock);
            } else {
              Preferences.getInstance()
                  .requestExternalStoragePermission(
                      WallpaperActivityPre.this, WallpaperActivityPre.this, false);
            }
          }
        });

    // EarthView.withGoogle().getEarthWallpaper(earthWallpaper.getWallpaperId(), this);
    new DownloadHighResImage(this, earthWallpaper, this)
        .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

    setTypefaces();
  }