Android仿人人客户端(v5,2024历年字节跳动Android面试真题解析

    android:layout_marginLeft="10dip"

    android:orientation="vertical" >



    <TextView

        android:id="@+id/tv_photo_owner_name"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:textColor="#ff005092"

        android:textSize="14sp" />



    <TextView

        android:id="@+id/tv_photo_describe"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginTop="10dip"

        android:textColor="#000000"

        android:textSize="13sp" />



    <ImageView

        android:id="@+id/iv_photo_image"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginTop="10dip" />



   <!--  人人官方的做法,显示固定大小的图片,并对原图进行剪裁。根据设置的宽高选择适中的区域进行裁剪--> 

    <!--

            <ImageView

                android:id="@+id/iv_photo_image"

                android:layout_width="150dip"

                android:layout_height="150dip"

                android:layout_marginTop="10dip"

                android:scaleType="centerCrop" />

    -->



    <TextView

        android:id="@+id/tv_photo_source"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginTop="10dip"

        android:textColor="#ff888888"

        android:textSize="13sp" />

</LinearLayout>

      在fresh\_news\_list\_item.xml布局文件中,添加用于展示分享的照片方式:



    <!-- 分享的图片-->



    <include

        android:id="@+id/ll_share_photo"

        android:layout_alignLeft="@+id/tv_nickname"

        android:layout_below="@+id/tv_message_content"

        android:layout_marginTop="10dip"

        layout="@layout/fresh_news_item_share_photo"

        android:visibility="gone" />

        新鲜事列表数据适配器(FreshNewsAdapter)文件中,添加的处理: 



    case 32: // 分享照片的新鲜事。 

    case 33: // 分享相册的新鲜事。  

        

        // 设置分享标识图标

        holder.text3.setCompoundDrawablesWithIntrinsicBounds(R.drawable.v5_0_1_newsfeed_share_icon, 0, 0, 0);



          // 内容的前缀

          String prefix1 = freshNews.getPrefix();

          if (!TextUtils.isEmpty(prefix1)) {

              holder.text2.setVisibility(View.VISIBLE);

              holder.text2.setText(prefix1);

          } else {

              holder.text2.setVisibility(View.GONE);

          }

          

        break;



   在新鲜事中包含的媒体内容中,添加的条件判断分支:



            else if ("photo".equals(media_type)) {

                holder.linearLayout3.setVisibility(View.VISIBLE);



                ImageInfo imgInfo = new ImageInfo(holder.imageView2, att.getRaw_src());

                mImageLoader.displayImage(imgInfo);



                String owner_name = att.getOwner_name();

                if(!TextUtils.isEmpty(owner_name)){

                    holder.text7.setVisibility(View.VISIBLE);

                    holder.text7.setText(owner_name);

                } else {

                    holder.text7.setVisibility(View.GONE);

                }

                

                String description = freshNews.getDescription();

                if(!TextUtils.isEmpty(description)){

                    holder.text8.setVisibility(View.VISIBLE);

                    holder.text8.setText(description);

                } else {

                    holder.text8.setVisibility(View.GONE);

                }

                

                holder.text9.setText("【" + freshNews.getTitle() + "】");



            } 

    FreshNewsAdapter文件到目前为止的完整代码如下:



package com.everyone.android.ui.freshnews;

import java.util.LinkedList;

import android.graphics.Color;

import android.text.TextUtils;

import android.util.TypedValue;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.view.ViewGroup.LayoutParams;

import android.widget.BaseAdapter;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.TextView;

import com.everyone.android.R;

import com.everyone.android.bitmap.ImageLoader;

import com.everyone.android.entity.Attachment;

import com.everyone.android.entity.Comment;

import com.everyone.android.entity.Comments;

import com.everyone.android.entity.FreshNews;

import com.everyone.android.entity.ImageInfo;

import com.everyone.android.entity.Source;

import com.everyone.android.ui.EveryoneActivity;

import com.everyone.android.utils.DensityUtil;

import com.everyone.android.utils.LogUtil;

/**

  • 功能描述:新鲜事列表数据适配器

  • @author android_ls

*/

public class FreshNewsAdapter extends BaseAdapter {

/**

 * LOG打印标签

 */

private static final String TAG = "FreshNewsAdapter";



private LayoutInflater inflater;



private LinkedList<FreshNews> mFreshNewsList;



private EveryoneActivity mActivity;



private ImageLoader mImageLoader;



public FreshNewsAdapter(EveryoneActivity activity, LinkedList<FreshNews> freshNewsList) {

    inflater = LayoutInflater.from(activity);

    mActivity = activity;

    mFreshNewsList = freshNewsList;

    this.mImageLoader = new ImageLoader(mActivity);

}



@Override

public int getCount() {

    return mFreshNewsList.size();

}



@Override

public Object getItem(int arg0) {

    return mFreshNewsList.get(arg0);

}



@Override

public long getItemId(int position) {

    return position;

}



/* (non-Javadoc)

 * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)

 */

@Override

public View getView(final int position, View convertView, ViewGroup parent) {

    ViewHolder holder = null;

    if (convertView == null) {

        convertView = inflater.inflate(R.layout.fresh_news_list_item, null);

        holder = new ViewHolder();

        holder.imageView1 = (ImageView) convertView.findViewById(R.id.iv_user_image);

        holder.text1 = (TextView) convertView.findViewById(R.id.tv_nickname);

        holder.text2 = (TextView) convertView.findViewById(R.id.tv_message_content);



        holder.linearLayout1 = (LinearLayout) convertView.findViewById(R.id.ll_comments_content);

        holder.linearLayout2 = (LinearLayout) convertView.findViewById(R.id.ll_update_status);

        holder.linearLayout3 = (LinearLayout) convertView.findViewById(R.id.ll_share_photo);



        holder.text7 = (TextView) convertView.findViewById(R.id.tv_photo_owner_name);

        holder.text8 = (TextView) convertView.findViewById(R.id.tv_photo_describe);

        holder.imageView2 = (ImageView) convertView.findViewById(R.id.iv_photo_image);

        holder.text9 = (TextView) convertView.findViewById(R.id.tv_photo_source);



        holder.text3 = (TextView) convertView.findViewById(R.id.tv_published);

        holder.text4 = (TextView) convertView.findViewById(R.id.tv_source);



        holder.text5 = (TextView) convertView.findViewById(R.id.tv_status_name);

        holder.text6 = (TextView) convertView.findViewById(R.id.tv_status_content);



        convertView.setTag(holder);

    } else {

        holder = (ViewHolder) convertView.getTag();

    }



    final FreshNews freshNews = mFreshNewsList.get(position);



    // 姓名

    holder.text1.setText(freshNews.getName());



    // 加载图像

    String headurl = freshNews.getHeadurl();

    LogUtil.i(TAG, "headurl = " + headurl);

    if (!TextUtils.isEmpty(headurl)) {

        int widthPx = DensityUtil.dip2px(mActivity, 43);

        ImageInfo imgInfo = new ImageInfo(holder.imageView1, headurl, widthPx, widthPx);

        mImageLoader.displayImage(imgInfo);

    }



    LogUtil.i(TAG, "description = " + freshNews.getDescription());

    LogUtil.i(TAG, "freshNews.getMessage() = " + freshNews.getMessage());

    LogUtil.i(TAG, "freshNews.getTitle() = " + freshNews.getTitle());

    LogUtil.i(TAG, "freshNews.getPrefix() = " + freshNews.getPrefix());



    // 用户自定义输入的内容

    String message = freshNews.getMessage();

    if (!TextUtils.isEmpty(message)) {

        holder.text2.setVisibility(View.VISIBLE);

        holder.text2.setText(message);

    } else {

        holder.text2.setVisibility(View.GONE);

    }



    // page代表公共主页新鲜事

    int feedType = freshNews.getFeed_type();

    LogUtil.i(TAG, "feedType = " + feedType);



    switch (feedType) {

    case 10: // 更新状态的新鲜事。 

    case 11: // page更新状态的新鲜事。 



        // 设置状态标识图标

        holder.text3.setCompoundDrawablesWithIntrinsicBounds(R.drawable.v5_0_1_newsfeed_status_icon, 0, 0, 0);



        // 内容的前缀

        String prefix = freshNews.getPrefix();

        if (!TextUtils.isEmpty(prefix)) {

            holder.text2.setVisibility(View.VISIBLE);

            holder.text2.setText(prefix);

        } else {

            holder.text2.setVisibility(View.GONE);

        }



        break;

    case 20: // 发表日志的新鲜事。 

    case 22: // page发表日志的新鲜事。 

        

        break;

    case 21: // 分享日志的新鲜事。 

    case 23: // page分享日志的新鲜事。 



        break;

    case 30: // 上传照片的新鲜事。

    case 31: // page上传照片的新鲜事。  

        

        break;

    case 32: // 分享照片的新鲜事。 

    case 33: // 分享相册的新鲜事。  

        

        // 设置分享标识图标

        holder.text3.setCompoundDrawablesWithIntrinsicBounds(R.drawable.v5_0_1_newsfeed_share_icon, 0, 0, 0);



          // 内容的前缀

          String prefix1 = freshNews.getPrefix();

          if (!TextUtils.isEmpty(prefix1)) {

              holder.text2.setVisibility(View.VISIBLE);

              holder.text2.setText(prefix1);

          } else {

              holder.text2.setVisibility(View.GONE);

          }

          

        break;

    // ...

    default:

        break;

    }

    

    holder.linearLayout2.setVisibility(View.GONE);

    holder.linearLayout3.setVisibility(View.GONE);

    

    // 新鲜事中包含的媒体内容

    LinkedList<Attachment> attachments = freshNews.getAttachment();

    if (attachments != null) {

        int size = attachments.size();

        LogUtil.i(TAG, "size = " + size);



        for (int i = 0; i < size; i++) {

            Attachment att = attachments.get(i);

            String media_type = att.getMedia_type();

            LogUtil.i(TAG, "media_type = " + media_type);

            LogUtil.i(TAG, "att.getContent() = " + att.getContent());

            LogUtil.i(TAG, "getHref = " + att.getHref());

            LogUtil.i(TAG, "att.getOwner_id() = " + att.getOwner_id());

            LogUtil.i(TAG, "getOwner_name() = " + att.getOwner_name());

            LogUtil.i(TAG, "getRaw_src() = " + att.getRaw_src());

            LogUtil.i(TAG, "getScr() = " + att.getScr());



            if ("status".equals(media_type)) {

                holder.linearLayout2.setVisibility(View.VISIBLE);



                holder.text5.setText(att.getOwner_name());

                holder.text6.setText(att.getContent());

            } else if ("photo".equals(media_type)) {

                holder.linearLayout3.setVisibility(View.VISIBLE);



                ImageInfo imgInfo = new ImageInfo(holder.imageView2, att.getRaw_src());

                mImageLoader.displayImage(imgInfo);



                String owner_name = att.getOwner_name();

                if(!TextUtils.isEmpty(owner_name)){

                    holder.text7.setVisibility(View.VISIBLE);

                    holder.text7.setText(owner_name);

                } else {

                    holder.text7.setVisibility(View.GONE);

                }

                

                String description = freshNews.getDescription();

                if(!TextUtils.isEmpty(description)){

                    holder.text8.setVisibility(View.VISIBLE);

                    holder.text8.setText(description);

                } else {

                    holder.text8.setVisibility(View.GONE);

                }

                

                holder.text9.setText("【" + freshNews.getTitle() + "】");



            } else if ("link".equals(media_type)) {

                

            } else if ("album".equals(media_type)) {

                

            } else if ("link".equals(media_type)) {

                

            } else if ("video".equals(media_type)) {



            } else if ("audio".equals(media_type)) {



            }



        }

    }

    

    // 动态生成显示评论信息的Item

    Comments comments = freshNews.getComments();

    if (comments != null) {

        LinkedList<Comment> commentList = comments.getComment();

        if (commentList != null) {

            holder.linearLayout1.setVisibility(View.VISIBLE);



            if (holder.linearLayout1.getChildCount() > 0) {

                holder.linearLayout1.removeAllViews();

            }



            int count = comments.getCount();

            if (count > 0) {

                TextView tvCount = new TextView(mActivity);

                tvCount.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

                tvCount.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);

                tvCount.setSingleLine();

                tvCount.setCompoundDrawablePadding(5);

                tvCount.setPadding(0, 10, 0, 0);

                tvCount.setText(count + "条评论");

                tvCount.setTextColor(Color.parseColor("#ff005092"));

                tvCount.setCompoundDrawablesWithIntrinsicBounds(R.drawable.fresh_news_comment_icon, 0, 0, 0);

                holder.linearLayout1.addView(tvCount);

            }



            int size = commentList.size();

            LogUtil.i(TAG, "commentList size = " + size);

            for (int i = 0; i < size; i++) {

                Comment comment = commentList.get(i);

                LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);



                TextView tvContent = new TextView(mActivity);

                tvContent.setLayoutParams(layoutParams);

                tvContent.setTextColor(Color.BLACK);

                tvContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);

                tvContent.setSingleLine();

                tvContent.setPadding(0, 10, 0, 0);

                tvContent.setText(comment.getName() + ":" + comment.getText());

                holder.linearLayout1.addView(tvContent);



                TextView tvTime = new TextView(mActivity);

                tvTime.setTextColor(Color.GRAY);

                tvTime.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);

                tvTime.setLayoutParams(layoutParams);

                tvContent.setPadding(0, 5, 0, 10);

                tvTime.setText(comment.getTime());

                holder.linearLayout1.addView(tvTime);

            }



        } else {

            holder.linearLayout1.setVisibility(View.GONE);

        }

    } else {

        holder.linearLayout1.setVisibility(View.GONE);

    }



    // 对获取的时间字符串的处理

    String updateTime = freshNews.getUpdate_time();

    if (!TextUtils.isEmpty(updateTime)) {

        updateTime = updateTime.substring(updateTime.indexOf("-") + 1, updateTime.lastIndexOf(":"));

        updateTime = updateTime.replace("-", "月");

        updateTime = updateTime.replace(" ", "日 ");

        int index = updateTime.indexOf("0");

        if (index == 0) {

            updateTime = updateTime.substring(index + 1);

        }



        holder.text3.setText(updateTime);

    }



    // 来自那种客户端

    Source source = freshNews.getSource();

    if (source != null) {

        holder.text4.setText("来自:" + source.getText());

    }



    return convertView;

}



static class ViewHolder {



    public LinearLayout linearLayout1;



    public LinearLayout linearLayout2;



    public LinearLayout linearLayout3;



    public ImageView imageView1;



    public ImageView imageView2;



    public TextView text1;



    public TextView text2;



    public TextView text3;



    public TextView text4;



    public TextView text5;



    public TextView text6;



    public TextView text7;



    public TextView text8;



    public TextView text9;

}

}


三、对从网络(人人的服务器端)获取的图片,本地处理部分 修改 根据指定的压缩比例,获得合适的Bitmap这一步。



   之前的处理代码如下:



/**

 * 根据指定的压缩比例,获得合适的Bitmap

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
img

题外话

我在一线互联网企业工作十余年里,指导过不少同行后辈。帮助很多人得到了学习和成长。

我意识到有很多经验和知识值得分享给大家,也可以通过我们的能力和经验解答大家在IT学习中的很多困惑,所以在工作繁忙的情况下还是坚持各种整理和分享。但苦于知识传播途径有限,很多程序员朋友无法获得正确的资料得到学习提升,故此将并将重要的Android进阶资料包括自定义view、性能优化、MVC与MVP与MVVM三大框架的区别、NDK技术、阿里面试题精编汇总、常见源码分析等学习资料。

【Android思维脑图(技能树)】

知识不体系?这里还有整理出来的Android进阶学习的思维脑图,给大家参考一个方向。

希望我能够用我的力量帮助更多迷茫、困惑的朋友们,帮助大家在IT道路上学习和发展~

。**
[外链图片转存中…(img-gqyBFpFr-1711914162133)]
[外链图片转存中…(img-9qxfxnqx-1711914162134)]
[外链图片转存中…(img-AKlFGAAr-1711914162135)]
[外链图片转存中…(img-NczovD1A-1711914162135)]
[外链图片转存中…(img-zzX5lYyi-1711914162136)]
[外链图片转存中…(img-Ftc8JmNw-1711914162137)]
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
[外链图片转存中…(img-ucYRi35m-1711914162137)]

题外话

我在一线互联网企业工作十余年里,指导过不少同行后辈。帮助很多人得到了学习和成长。

我意识到有很多经验和知识值得分享给大家,也可以通过我们的能力和经验解答大家在IT学习中的很多困惑,所以在工作繁忙的情况下还是坚持各种整理和分享。但苦于知识传播途径有限,很多程序员朋友无法获得正确的资料得到学习提升,故此将并将重要的Android进阶资料包括自定义view、性能优化、MVC与MVP与MVVM三大框架的区别、NDK技术、阿里面试题精编汇总、常见源码分析等学习资料。

【Android思维脑图(技能树)】

知识不体系?这里还有整理出来的Android进阶学习的思维脑图,给大家参考一个方向。

[外链图片转存中…(img-UMPJSYLu-1711914162138)]

希望我能够用我的力量帮助更多迷茫、困惑的朋友们,帮助大家在IT道路上学习和发展~

本文已被CODING开源项目:《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》收录

  • 28
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值