
package com.example.PersonalCenter;

import com.example.cmknowledgegraph.R;
import com.google.android.material.navigation.NavigationView;
import com.squareup.picasso.Picasso;

import android.os.Bundle;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/**
 * Created by mxn on 2016/12/13.
 * MenuListFragment
 */

public class MenuListFragment extends Fragment {

    private ImageView ivMenuUserProfilePhoto;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_menu, container,
                false);
        Log.i("view==","=="+view.toString()+"==");
        NavigationView linearLayout = view.findViewById(R.id.vNavigation);
         View frameLayout = linearLayout.inflateHeaderView(R.layout.view_global_menu_header);
        ivMenuUserProfilePhoto = (ImageView) frameLayout.findViewById(R.id.ivMenuUserProfilePhoto);
        Log.i("ismenu---===","====)"+ivMenuUserProfilePhoto.toString());
        NavigationView vNavigation = (NavigationView) view.findViewById(R.id.vNavigation);
        vNavigation.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem menuItem) {
                Toast.makeText(getActivity(),menuItem.getTitle(),Toast.LENGTH_SHORT).show();
                return false;
            }
        }) ;
        setupHeader();
        return  view ;
    }

    private void setupHeader() {
        int avatarSize = getResources().getDimensionPixelSize(R.dimen.global_menu_avatar_size);
        String profilePhoto = getResources().getString(R.string.user_profile_photo);
        //在这里加载对应的图片信息
//        Picasso.with(getActivity())
//                .load(R.drawable.draw1)
//                .placeholder(R.drawable.img_circle_placeholder)
//                .resize(avatarSize, avatarSize)
//                .centerCrop()
//                .transform(new CircleTransformation())
//                .into(ivMenuUserProfilePhoto);
        Picasso.with(getActivity())
                .load(R.drawable.draw1)
                .placeholder(R.drawable.img_circle_placeholder)
                .into(ivMenuUserProfilePhoto);
    }

}
