Android仿人人客户端(v5(2),重庆字节跳动android面试

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

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

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

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

如果你需要这些资料,可以添加V获取:vip204888 (备注Android)
img

正文

新鲜事列表数据适配器(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 mFreshNewsList;

private EveryoneActivity mActivity;

private ImageLoader mImageLoader;

public FreshNewsAdapter(EveryoneActivity activity, LinkedList 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 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 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

  • @param inStream InputStream

  • @param width 指定的宽度

  • @param height 指定的高度

  • @return Bitmap

  • @throws IOException

*/

public static Bitmap decodeStream(InputStream inStream, int width, int height) throws IOException {

// 从输入流读取数据

byte[] data = StreamTool.read(inStream);

BitmapFactory.Options options = new BitmapFactory.Options();

options.inJustDecodeBounds = true;

BitmapFactory.decodeByteArray(data, 0, data.length, options);

int w = options.outWidth;

int h = options.outHeight;

// 缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可

int ratio = 1; // 默认为不缩放

if (w >= h && w > width) {

ratio = (int) (w / width);

} else if (w < h && h > height) {

ratio = (int) (h / height);

}

if (ratio <= 0) {

ratio = 1;

}

System.out.println("图片的缩放比例值ratio = " + ratio);

options = new BitmapFactory.Options();

// 属性值inSampleSize表示缩略图大小为原始图片大小的几分之一,即如果这个值为2,

// 则取出的缩略图的宽和高都是原始图片的1/2,图片大小就为原始大小的1/4。

options.inSampleSize = ratio;

options.inJustDecodeBounds = false;

return BitmapFactory.decodeByteArray(data, 0, data.length, options);

}

仔细阅读上面的代码,会发现其只满足用于显示固定大小图片的处理。可是在实际需求中往往有,我不知道服务器端返回的图片是什么样的(主要指尺寸大小、长宽比),但是我要求不管服务器端返回的图片是什么样,客户端都能“正确”的显示。这时就需要有一种算法,能根据服务器端返回的图片大小自动计算缩放比,以便我们获取合适的图片。

修改后的处理代码如下:

/**

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

  • @param inStream InputStream

  • @param width 指定的宽度

  • @param height 指定的高度

  • @return Bitmap

  • @throws IOException

*/

public static Bitmap decodeStream(InputStream inStream, int width, int height) throws IOException {

// 从输入流读取数据

byte[] data = StreamTool.read(inStream);

BitmapFactory.Options options = new BitmapFactory.Options();

最后

针对Android程序员,我这边给大家整理了一些资料,包括不限于高级UI、性能优化、架构师课程、NDK、混合式开发(ReactNative+Weex)微信小程序、Flutter等全方面的Android进阶实践技术;希望能帮助到大家,也节省大家在网上搜索资料的时间来学习,也可以分享动态给身边好友一起学习!

往期Android高级架构资料、源码、笔记、视频。高级UI、性能优化、架构师课程、混合式开发(ReactNative+Weex)全方面的Android进阶实践技术,群内还有技术大牛一起讨论交流解决问题。

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注Android)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

@param inStream InputStream

  • @param width 指定的宽度

  • @param height 指定的高度

  • @return Bitmap

  • @throws IOException

*/

public static Bitmap decodeStream(InputStream inStream, int width, int height) throws IOException {

// 从输入流读取数据

byte[] data = StreamTool.read(inStream);

BitmapFactory.Options options = new BitmapFactory.Options();

最后

针对Android程序员,我这边给大家整理了一些资料,包括不限于高级UI、性能优化、架构师课程、NDK、混合式开发(ReactNative+Weex)微信小程序、Flutter等全方面的Android进阶实践技术;希望能帮助到大家,也节省大家在网上搜索资料的时间来学习,也可以分享动态给身边好友一起学习!

往期Android高级架构资料、源码、笔记、视频。高级UI、性能优化、架构师课程、混合式开发(ReactNative+Weex)全方面的Android进阶实践技术,群内还有技术大牛一起讨论交流解决问题。

[外链图片转存中…(img-zZFkSJDY-1713708476315)]

[外链图片转存中…(img-L0TxNyBq-1713708476316)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注Android)
[外链图片转存中…(img-g1X9Kc6l-1713708476316)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值