实训第六周(1)

本周开始写第三个自定义的Fragment——MeFragment,对应于界面中的“我”。

里面实现的功能有修改个人资料,以及个性化手写字体库的创建

1. 设置加载的布局ID以及“我”布局文件

@Override
    public int setLayoutID() {
        return R.layout.fragment_me;
    }

fragment_me.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/interval_color"
    android:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="10dp"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="@color/white_color"
        android:gravity="center_vertical">

        <com.joooonho.SelectableRoundedImageView
            android:id="@+id/iv_head_picture"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            app:sriv_oval="true"
            android:scaleType="fitXY"
            android:src="@mipmap/app_logo_main"/>

        <RelativeLayout
            android:layout_marginLeft="10dp"
            android:id="@+id/layout_account"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_toRightOf="@id/iv_head_picture"
            android:gravity="center_vertical"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tv_user_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/app_name"
                android:textColor="@color/app_black_color"/>

            <TextView
                android:id="@+id/tv_tip"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/tv_user_name"
                android:layout_marginTop="10dp"
                android:text="@string/account_tip"
                android:textColor="@color/app_black_color"/>

            <TextView
                android:id="@+id/tv_account"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/tv_user_name"
                android:layout_marginTop="10dp"
                android:layout_toRightOf="@+id/tv_tip"
                android:text="Ezreal-520"
                android:textColor="@color/app_black_color"/>

        </RelativeLayout>

    </RelativeLayout>


    <View
        android:layout_width="match_parent"
        android:layout_height="10dp"/>

    <RelativeLayout
        android:id="@+id/layout_user_words_input"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/white_color"
        android:paddingLeft="10dp"
        android:paddingRight="10dp">

        <ImageView
            android:id="@+id/iv_user_words"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:padding="5dp"
            android:layout_marginLeft="5dp"
            android:scaleType="fitXY"
            android:src="@mipmap/setting"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@+id/iv_user_words"
            android:gravity="center"
            android:text="字体库"
            android:textColor="@color/app_black_color"
            android:textSize="16sp"/>
    </RelativeLayout>
</LinearLayout>


2. 初始化

@Override
    public void initView(View rootView) {
        ButterKnife.bind(this,rootView);
        NimUserHandler.getInstance().setUpdateListeners(new OnInfoUpdateListener() {
            @Override
            public void myInfoUpdate() {
                showOrRefreshView();
            }
        });
        showOrRefreshView();
    }

showOrRefreshView——进入“我”界面后,未点入完整信息页前,显示的是头像,昵称,账号,初始化中若这三个属性有变更要及时刷新

private void showOrRefreshView(){
        mAccountBean = NimUserHandler.getInstance().getLocalAccount();
        if (mAccountBean != null){
            ImageUtils.setImageByUrl(getContext(),mHeadView,
                    mAccountBean.getHeadImgUrl(),R.mipmap.app_logo_main);
            mTvName.setText(mAccountBean.getNick());
            mTvAccount.setText(mAccountBean.getAccount());
        }
    }


3. 进入修改信息页(AccountInfoActivity)

    @OnClick(R.id.layout_account)
    public void openAccountInfo(){
        Intent intent = new Intent(getContext(), AccountInfoActivity.class);
        startActivity(intent);
    }


4. 进入字体库(ContentActivity)

@OnClick(R.id.layout_user_words_input)
    public void openUserWordsAlbum(){
        Intent intent=new Intent(getContext(), ContentActivity.class);
        startActivity(intent);
    }


附上完整MeFragment.java

package com.ezreal.ezchat.fragment;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.ezreal.ezchat.R;
import com.ezreal.ezchat.activity.AccountInfoActivity;
import com.ezreal.ezchat.activity.ContentActivity;
import com.ezreal.ezchat.activity.CreateActivity;
import com.ezreal.ezchat.bean.LocalAccountBean;
import com.ezreal.ezchat.handler.NimUserHandler;
import com.ezreal.ezchat.handler.NimUserHandler.OnInfoUpdateListener;
import com.joooonho.SelectableRoundedImageView;
import com.ezreal.ezchat.commonlibrary.utils.ImageUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 张静
 */

public class MeFragment extends BaseFragment {

    @BindView(R.id.iv_head_picture)
    SelectableRoundedImageView mHeadView;
    @BindView(R.id.tv_user_name)
    TextView mTvName;
    @BindView(R.id.tv_account)
    TextView mTvAccount;
    private LocalAccountBean mAccountBean;

    @Override
    public int setLayoutID() {
        return R.layout.fragment_me;
    }

    @Override
    public void initView(View rootView) {
        ButterKnife.bind(this,rootView);
        NimUserHandler.getInstance().setUpdateListeners(new OnInfoUpdateListener() {
            @Override
            public void myInfoUpdate() {
                showOrRefreshView();
            }
        });
        showOrRefreshView();
    }


    @OnClick(R.id.layout_account)
    public void openAccountInfo(){
        Intent intent = new Intent(getContext(), AccountInfoActivity.class);
        startActivity(intent);
    }


    //进入字体库
    @OnClick(R.id.layout_user_words_input)
    public void openUserWordsAlbum(){
        Intent intent=new Intent(getContext(), ContentActivity.class);
        startActivity(intent);
    }

    private void showOrRefreshView(){
        mAccountBean = NimUserHandler.getInstance().getLocalAccount();
        if (mAccountBean != null){
            ImageUtils.setImageByUrl(getContext(),mHeadView,
                    mAccountBean.getHeadImgUrl(),R.mipmap.app_logo_main);
            mTvName.setText(mAccountBean.getNick());
            mTvAccount.setText(mAccountBean.getAccount());
        }
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值