移动开发--微信通讯录界面

功能介绍

  1. 使用recyclerview在页面中展示好友
  2. 好友实现按照昵称首汉字字母排序
  3. 实现点击好友跳转详细资料界面

效果预览

在这里插入图片描述
在这里插入图片描述

功能实现

1. 通讯录

通讯录fragment2.xml使用的是Frame布局镶嵌于MainLayout.xml中,在FrameLayout中再添加recyclerview。

fragment2.xml

预览:
在这里插入图片描述
代码:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/RecyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
</FrameLayout>

item.xml

预览:
在这里插入图片描述
代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/item"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:orientation="vertical">

        <TextView
            android:id="@+id/title_group"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_weight="1"
            android:background="@android:color/system_neutral1_100"
            android:text="a"
            android:visibility="gone" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal">

                <ImageView
                    android:id="@+id/friend_image"
                    android:layout_width="120dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:padding="5dp"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/icon_addfriend" />

                <TextView
                    android:id="@+id/friend_text"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/border_bottom"
                    android:gravity="center_vertical"
                    android:text="新的朋友"
                    android:textSize="20dp" />
        </LinearLayout>

</LinearLayout>
  • 排序功能实现思路:每个好友设置一个group属性,在创建的时候会自动将昵称的首汉字的首字母赋值给group(特殊的,“公众号”、“标签”等功能选项不参与分组且在通讯录最前面,因此group属性应制定默认值,默认值ASCⅡ码保证最小)。
  • 然后将所有好友用List集合保存,在List集合中就按照group升序排序。
  • 然后布局中,每个item添加一个textview在最前面,默认不显示,在recyclerview加载item的时候,判断当前的当前的好友的group于上一个好友的group是否相等,如果不相等则显示textview,并用textview显示gruop,再加载item;如果相等则之家加载item。

Person.java(好友)

代码:

package com.example.whj;
public class Person implements Comparable<Person>{
    private String name;
    private int image;
    private char group;

    public char getGroup() {
        return group;
    }

    public void setGroup(char group) {
        this.group = group;
    }

    public Person(String name, int image, char gruop) {
        this.name = name;
        this.image = image;
        this.group = gruop;
    }

    public Person(String name, int image) {
        this.name = name;
        this.image = image;
        this.group = Tool.getFirstLetter(name);
    }

    @Override
    public int compareTo(Person o) {
        return this.group - o.getGroup();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getImage() {
        return image;
    }

    public void setImage(int image) {
        this.image = image;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", image=" + image +
                ", group=" + group +
                '}';
    }
}

该类实现Comparable接口方便后面使用Collections.sort()方法排序。通过Tool.getFirstLetter(name)获得昵称的首汉字的首字母,Tool类参考自https://blog.csdn.net/chenbing81/article/details/51960019

Fragment2 .java

代码:

package com.example.whj;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Fragment2 extends Fragment {

    private RecyclerView recyclerView;
    private Myadapter myadapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment2, container, false);
        List<Person> people = initData();
        recyclerView = view.findViewById(R.id.RecyclerView);
        Context context = getContext();
        myadapter = new Myadapter(people, context);
        LinearLayoutManager manager = new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(myadapter);
        return view;
    }
    public List<Person> initData() {
        List<Person> data = new ArrayList<>();
        data.add(new Person("张三",R.drawable.f_static_00));
        data.add(new Person("????",R.drawable.f_static_01));
        data.add(new Person("新的朋友",R.drawable.icon_addfriend,'0'));
        data.add(new Person("群聊",R.drawable.icon_qunliao,'0'));
        data.add(new Person("标签",R.drawable.icon_biaoqian,'0'));
        data.add(new Person("公众号",R.drawable.icon_public,'0'));
        data.add(new Person("韦海杰",R.drawable.f_static_02));
        data.add(new Person("李娜娜",R.drawable.f_static_03));
        data.add(new Person("朝锅巴",R.drawable.f_static_04));
        data.add(new Person("欧阳嘎哈",R.drawable.f_static_05));
        data.add(new Person("王老五",R.drawable.f_static_06));
        data.add(new Person("姐木心#肿么记伱",R.drawable.f_static_07));
        data.add(new Person("消遣",R.drawable.f_static_08));
        data.add(new Person("刘子俺",R.drawable.f_static_09));
        data.add(new Person("永不言败",R.drawable.f_static_010));
        data.add(new Person("滴水穿石",R.drawable.f_static_011));
        data.add(new Person("水清云淡",R.drawable.f_static_012));
        data.add(new Person("天会亮心会暖",R.drawable.f_static_013));
        data.add(new Person("张召忠",R.drawable.f_static_013));
        data.add(new Person("花落花开",R.drawable.f_static_014));
        data.add(new Person("南宫涵",R.drawable.f_static_015));
        data.add(new Person("辛格才",R.drawable.f_static_016));
        data.add(new Person("汪汪队",R.drawable.f_static_017));
        data.add(new Person("高鬼魂",R.drawable.f_static_018));
        Collections.sort(data);
        return data;
    }
}

该类用于加载数据和设置recyclerView。

Myadapter.java

代码:

package com.example.whj;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class Myadapter extends RecyclerView.Adapter<Myadapter.MyViewHolder> {

    private List<Person> mydata;

    private Context mycontext;

    public Myadapter(List<Person> data, Context context) {
        mydata = data;
        mycontext = context;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mycontext).inflate(R.layout.item,parent,false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        Person cur = mydata.get(position);
        Person last;
        //实现排序功能
        if (position == 0){
            holder.textView.setText(cur.getName());
            holder.imageView.setImageResource(cur.getImage());
            holder.title.setVisibility(View.GONE);
        } else {
            last = mydata.get(position - 1);
            if (cur.getGroup() != last.getGroup()) {
                holder.item.setMinimumHeight(80);
                holder.title.setText("  " + cur.getGroup());
                holder.title.setVisibility(View.VISIBLE);
                holder.textView.setText(cur.getName());
                holder.imageView.setImageResource(cur.getImage());
            } else {
                holder.textView.setText(cur.getName());
                holder.imageView.setImageResource(cur.getImage());
                holder.title.setVisibility(View.GONE);
            }
        }
        //点击跳转个人详细资料页面
        holder.item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putInt("image", cur.getImage());
                bundle.putString("name", cur.getName());
                Intent intent = new Intent(mycontext,PersonalActivity.class);
                intent.putExtra("data",bundle);
                mycontext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mydata.size();
    }
    public class MyViewHolder extends RecyclerView.ViewHolder{
        private TextView textView;
        private ImageView imageView;
        private TextView title;
        private LinearLayout item;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);

            textView = itemView.findViewById(R.id.friend_text);
            imageView = itemView.findViewById(R.id.friend_image);
            title = itemView.findViewById(R.id.title_group);
            item = itemView.findViewById(R.id.item);
        }
    }
}

该类用于加载item和实现点击跳转。

2. 详细资料

personal_document.xml

预览:
在这里插入图片描述
代码:

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="34dp"
        android:orientation="horizontal"
        android:background="@color/white">

        <ImageView
            android:id="@+id/document_back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="7dp"
            android:layout_weight="1"
            app:srcCompat="@drawable/icon_back" />

        <TextView
            android:layout_width="325dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <ImageView
            android:id="@+id/document_more"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/icon_more" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="303dp"
        android:orientation="vertical"
        android:background="@color/white">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/document_image"
                android:layout_width="271dp"
                android:layout_height="113dp"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:scaleType="fitCenter"
                tools:srcCompat="@drawable/f_static_01" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/document_remarks"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="35dp"
                    android:text="备注"
                    android:textColor="@color/black"
                    android:textSize="30dp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/document_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="1dp"
                    android:layout_marginTop="5dp"
                    android:text="昵称:"
                    android:textSize="15dp" />

                <TextView
                    android:id="@+id/document_number"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="1dp"
                    android:text="微信号:"
                    android:textSize="15dp" />

                <TextView
                    android:id="@+id/document_area"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="1dp"
                    android:text="地区:"
                    android:textSize="15dp" />
            </LinearLayout>

        </LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/material_dynamic_neutral95" />

        <LinearLayout
            android:id="@+id/document_setting"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:text="设置备注和标签  "
                android:textColor="@color/black"
                android:textSize="20dp" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_margin="15dp"
                android:layout_weight="1"
                android:scaleType="fitEnd"
                app:srcCompat="@drawable/right" />
        </LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/material_dynamic_neutral95" />

        <LinearLayout
            android:id="@+id/document_power"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:text="朋友权限"
                android:textColor="@color/black"
                android:textSize="20dp" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_margin="15dp"
                android:layout_weight="1"
                android:scaleType="fitEnd"
                app:srcCompat="@drawable/right" />
        </LinearLayout>

    </LinearLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:background="@color/material_dynamic_neutral95" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@color/white">

        <LinearLayout
            android:id="@+id/document_friend_circle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:text="朋友圈"
                android:textColor="@color/black"
                android:textSize="20dp" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_margin="15dp"
                android:layout_weight="1"
                android:scaleType="fitEnd"
                app:srcCompat="@drawable/right" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/document_more_information"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:text="更多信息"
                android:textColor="@color/black"
                android:textSize="20dp" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_margin="15dp"
                android:layout_weight="1"
                android:scaleType="fitEnd"
                app:srcCompat="@drawable/right" />
        </LinearLayout>
    </LinearLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:background="@color/material_dynamic_neutral95" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@color/white">

        <LinearLayout
            android:id="@+id/document_sent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:layout_weight="1"
                android:scaleType="fitEnd"
                app:srcCompat="@drawable/weixin_normal" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:text="发信息"
                android:textColor="@color/Turquoise3"
                android:textSize="20dp" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/document_call"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="5dp"
                android:layout_weight="1"
                android:scaleType="fitEnd"
                app:srcCompat="@drawable/chat_video_call_receive" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:text="音视频通话"
                android:textColor="@color/Turquoise3"
                android:textSize="20dp" />

        </LinearLayout>
    </LinearLayout>

</LinearLayout>

PersonalActivity.java

代码:

package com.example.whj;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Instrumentation;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class PersonalActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.personal_document);
        Intent intent = getIntent();
        Bundle bundle = intent.getBundleExtra("data");
        int image = bundle.getInt("image");
        String name = bundle.getString("name");

        ImageView imageView = findViewById(R.id.document_back);
        ImageView imageView1 = findViewById(R.id.document_image);
        TextView textView = findViewById(R.id.document_name);
        TextView textView1 = findViewById(R.id.document_remarks);

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        textView1.setText(name);
        imageView1.setImageResource(image);
        textView.append(name);
    }
}

源码地址

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
u-upload 添加微信文件上传方式是指,在u-upload文件上传库中增加了支持微信文件上传的功能。通常情况下,u-upload库用于实现网站或应用中的文件上传功能,但原本的u-upload库并不支持微信文件上传。 微信文件上传是指用户通过微信平台将文件上传到网站或应用的过程。为了实现这一功能,开发人员对u-upload库进行了修改和调整,使其能够与微信平台进行交互。 具体而言,为了实现u-upload的微信文件上传方式,开发人员首先需要在网站或应用上放置一个微信登录的入口,以便用户可以使用微信登录,并授权访问其文件。 一旦用户使用微信登录并授权,u-upload库会调用微信接口获取用户在微信中上传的文件,并将其上传到指定的服务器上。开发人员需要在服务器端进行文件接收和处理的逻辑实现。 这样,用户就可以通过微信平台将文件上传到网站或应用中,实现了u-upload的微信文件上传方式。 需要注意的是,开发人员在实现u-upload的微信文件上传方式时,需要遵循微信平台的开发规范和技术要求,确保用户的文件上传过程安全可靠。此外,还需要处理文件上传过程中可能出现的错误和异常,确保系统的稳定性和可用性。 总之,通过对u-upload库的修改和调整,开发人员成功实现了u-upload的微信文件上传方式,使用户能够通过微信平台方便地将文件上传到网站或应用中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值