Exemplo n.º 1
0
 @Override
 public void beforeOnLyaout() {
   if (mCategoryAdapter.hasItemViewBound && !mIsFakeSearchViewPositioned) {
     mListView.setOnLayoutListener(null);
     mIsFakeSearchViewPositioned = true;
     mListView.setSelectionFromTop(
         TRUE_DATA_ITEM_IDX,
         mTopView.getHeight()
             - (int)
                 ShopApp.getContext()
                     .getResources()
                     .getDimension(R.dimen.fake_search_layout_diff));
   }
 }
Exemplo n.º 2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.category_fragment, container, false);
    mFakeBg = view.findViewById(R.id.fake_bg);
    mListView = (BaseListView) view.findViewById(android.R.id.list);
    int listPadding =
        (int) ShopApp.getContext().getResources().getDimension(R.dimen.list_item_padding);
    mListView.setPadding(0, listPadding / 2, 0, listPadding);
    mSearchUi = view.findViewById(R.id.search_ui);
    mSearchUi.setOnClickListener(mSearchClickListener);

    mTopView = inflater.inflate(R.layout.fake_top_for_search, null);
    mTopViewContent = mTopView.findViewById(R.id.top_view_content);
    mTopViewContent.setBackgroundColor(
        ShopApp.getContext().getResources().getColor(R.color.fake_search_background));
    mListView.addHeaderView(mTopView);

    mFakeSearchView = inflater.inflate(R.layout.fake_search_view, null);
    mIsFakeSearchViewPositioned = false;
    View fakeInput = mFakeSearchView.findViewById(R.id.fake_input);
    fakeInput.setOnClickListener(mSearchClickListener);
    View fakeButton = mFakeSearchView.findViewById(R.id.fake_button);
    fakeButton.setOnClickListener(mSearchClickListener);
    mFakeSearchView.setBackgroundColor(
        ShopApp.getContext().getResources().getColor(R.color.fake_search_background));
    mListView.addHeaderView(mFakeSearchView);
    mListView.setOnLayoutListener(this);

    mCategoryAdapter = new CategoryAdapter(getActivity());
    mCategoryListAdapter =
        new CategoryListAdapter(getActivity(), mCategoryAdapter, mItemClickListner);
    mListView.setAdapter(mCategoryListAdapter);
    ArrayList<Object> data = new ArrayList<Object>();
    data.add(1);
    mCategoryListAdapter.updateData(data);

    mSearchButton = mSearchUi.findViewById(R.id.search_button);
    mSearchButton.setOnClickListener(mSearchClickListener);
    mInput = (AutoCompleteTextView) mSearchUi.findViewById(R.id.input);
    mInput.setOnEditorActionListener(
        new OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
              mSearchButton.performClick();
              return true;
            }
            return false;
          }
        });
    mInput.addTextChangedListener(
        new TextWatcher() {

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {}

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void afterTextChanged(Editable s) {
            loadHint();
          }
        });
    mSearchEmptyArea = mSearchUi.findViewById(R.id.empty_area);
    mSearchEmptyArea.setOnClickListener(mSearchClickListener);
    mSearchHintListView = (ListView) mSearchEmptyArea.findViewById(android.R.id.list);
    mSearchHintListView.addHeaderView(inflater.inflate(R.layout.search_hint_list_top, null));
    mSearchHintListAdapter = new SearchHintListAdapter(getActivity());
    mSearchHintListView.setAdapter(mSearchHintListAdapter);
    mSearchHintListView.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int positon, long id) {
            View v = view.findViewById(R.id.word);
            if (v != null && v instanceof TextView) {
              doSearch(((TextView) v).getText().toString());
            }
          }
        });

    mLoadingView = (EmptyLoadingView) view.findViewById(R.id.loading);

    return view;
  }
Exemplo n.º 3
0
 public void showSearchUi(boolean show) {
   View titleBar = ((BaseActivity) getActivity()).getTitleBarContainer();
   View tabs = ((MainActivity) getActivity()).tabs;
   if (show) {
     if (mFakeTopBmp == null) {
       int w = 0,
           h = 0,
           titleBmpH = 0,
           tabsBmpH =
               (int) ShopApp.getContext().getResources().getDimension(R.dimen.tabs_visible_height);
       titleBar.setDrawingCacheEnabled(true);
       tabs.setDrawingCacheEnabled(true);
       Bitmap titleBmp = titleBar.getDrawingCache();
       Bitmap tabsBmp = tabs.getDrawingCache();
       if (titleBmp != null) {
         w = titleBmp.getWidth();
         mTitleHeight = titleBmpH = titleBmp.getHeight();
         h += titleBmpH;
       }
       if (tabsBmp != null) {
         if (w == 0) {
           w = tabsBmp.getWidth();
         }
         h += tabsBmpH;
       }
       mFakeTopBmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);
       Canvas canvas = new Canvas(mFakeTopBmp);
       Paint paint = new Paint();
       if (titleBmp != null) {
         canvas.drawBitmap(titleBmp, 0, 0, paint);
         titleBmp.recycle();
       }
       titleBar.setDrawingCacheEnabled(false);
       if (tabsBmp != null) {
         paint.setColor(
             ShopApp.getContext().getResources().getColor(R.color.fake_search_background));
         canvas.drawRect(0, titleBmpH, w, titleBmpH + tabsBmpH, paint);
         canvas.drawBitmap(tabsBmp, 0, titleBmpH, paint);
         tabsBmp.recycle();
       }
       tabs.setDrawingCacheEnabled(false);
     }
     mCategoryListAdapter.showCoverView(true);
     mFakeBg.setVisibility(View.VISIBLE);
     mFakeBg.setLayoutParams(new LayoutParams(mFakeTopBmp.getWidth(), mFakeTopBmp.getHeight()));
     mFakeBg.setBackgroundDrawable(new BitmapDrawable(mFakeTopBmp));
     mTopView.setLayoutParams(
         new AbsListView.LayoutParams(mFakeTopBmp.getWidth(), mFakeTopBmp.getHeight()));
     mTopViewContent.setBackgroundColor(
         ShopApp.getContext().getResources().getColor(R.color.transparent));
     titleBar.setVisibility(View.GONE);
     tabs.setVisibility(View.GONE);
     int scrollDis =
         mTitleHeight
             + mFakeSearchView.getTop()
             + (int)
                 ShopApp.getContext()
                     .getResources()
                     .getDimension(R.dimen.fake_search_scroll_up_diff);
     mListView.smoothScrollBy(scrollDis, ANIMATION_DURATION);
     handler.sendEmptyMessageDelayed(UiHandler.MSG_SHOW_SEARCH, ACTION_DURATION);
     loadHint();
   } else {
     mInput.setText("");
     Utils.SoftInput.hide(getActivity(), mInput.getWindowToken());
     mSearchUi.setVisibility(View.GONE);
     int scrollDis =
         -mFakeTopBmp.getHeight()
             + (int)
                 ShopApp.getContext()
                     .getResources()
                     .getDimension(R.dimen.fake_search_scroll_down_diff);
     mListView.smoothScrollBy(scrollDis, ANIMATION_DURATION);
     handler.sendEmptyMessageDelayed(UiHandler.MSG_HIDE_SEARCH, ACTION_DURATION);
   }
 }