Search in sources :

Example 1 with FadeInDisplayer

use of org.aisen.android.component.bitmaploader.display.FadeInDisplayer in project AisenWeiBo by wangdan.

the class MenuHeaderView method setupHeaderView.

public void setupHeaderView(FrameLayout parent) {
    LayoutInflater inflater = LayoutInflater.from(menuFragment.getActivity());
    // 初始化View
    if (mHeaderView == null) {
        mHeaderView = inflater.inflate(R.layout.layout_menu_header, parent, false);
        int height = GlobalContext.getInstance().getResources().getDimensionPixelSize(R.dimen.material_drawer_account_header_height);
        if (Build.VERSION.SDK_INT >= 19) {
            height += SystemUtils.getStatusBarHeight(menuFragment.getActivity());
        }
        parent.addView(mHeaderView, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, height));
        // 绑定视图
        InjectUtility.initInjectedView(GlobalContext.getInstance(), this, mHeaderView);
    }
    View view = mHeaderView.findViewById(R.id.material_drawer_account_header);
    if (Build.VERSION.SDK_INT >= 19) {
        view.setPadding(view.getPaddingStart(), SystemUtils.getStatusBarHeight(menuFragment.getActivity()), view.getPaddingRight(), view.getPaddingBottom());
    }
    final WeiBoUser user = AppContext.getAccount().getUser();
    // 头像
    ImageView imgPhoto = (ImageView) mHeaderView.findViewById(R.id.material_drawer_account_header_current);
    imgPhoto.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (txtFollowersNewHint != null && txtFollowersNewHint.getVisibility() == View.VISIBLE) {
                ((MainActivity) menuFragment.getActivity()).closeDrawer();
                FriendshipPagerFragment.launch(menuFragment.getActivity(), AppContext.getAccount().getUser(), 1);
            } else {
                BizFragment.createBizFragment(menuFragment).launchProfile(AppContext.getAccount().getUser());
            }
        }
    });
    BitmapLoader.getInstance().display(menuFragment, user.getAvatar_large(), imgPhoto, ImageConfigUtils.getLargePhotoConfig());
    // 名字
    TextView txtName = (TextView) mHeaderView.findViewById(R.id.material_drawer_account_header_name);
    txtName.setText(user.getScreen_name());
    // 背景
    final ImageView imgCover = (ImageView) mHeaderView.findViewById(R.id.material_drawer_account_header_background);
    new WorkTask<Void, Void, Bitmap>() {

        @Override
        public Bitmap workInBackground(Void... params) throws TaskException {
            try {
                BitmapLoader.BitmapBytesAndFlag bitmapBytesAndFlag = BitmapLoader.getInstance().doDownload(user.getCover_image_phone(), new ImageConfig());
                return BitmapFactory.decodeByteArray(bitmapBytesAndFlag.bitmapBytes, 0, bitmapBytesAndFlag.bitmapBytes.length);
            } catch (Exception e) {
            }
            throw new TaskException("", "");
        }

        @Override
        protected void onSuccess(Bitmap bitmap) {
            super.onSuccess(bitmap);
            new FadeInDisplayer().loadCompletedisplay(imgCover, new BitmapDrawable(GlobalContext.getInstance().getResources(), bitmap));
        }

        @Override
        protected void onFailure(TaskException exception) {
            super.onFailure(exception);
            imgCover.setImageDrawable(new BitmapDrawable(GlobalContext.getInstance().getResources(), BitmapFactory.decodeResource(GlobalContext.getInstance().getResources(), R.drawable.bg_banner_dialog)));
        }
    }.execute();
    // 显示账号
    mHeaderView.findViewById(R.id.material_drawer_account_header_text_section).setOnClickListener(this);
}
Also used : ImageConfig(org.aisen.android.component.bitmaploader.core.ImageConfig) FadeInDisplayer(org.aisen.android.component.bitmaploader.display.FadeInDisplayer) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) TaskException(org.aisen.android.network.task.TaskException) Bitmap(android.graphics.Bitmap) TaskException(org.aisen.android.network.task.TaskException) LayoutInflater(android.view.LayoutInflater) FrameLayout(android.widget.FrameLayout) WeiBoUser(org.aisen.weibo.sina.sinasdk.bean.WeiBoUser) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Aggregations

Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ImageConfig (org.aisen.android.component.bitmaploader.core.ImageConfig)1 FadeInDisplayer (org.aisen.android.component.bitmaploader.display.FadeInDisplayer)1 TaskException (org.aisen.android.network.task.TaskException)1 WeiBoUser (org.aisen.weibo.sina.sinasdk.bean.WeiBoUser)1