您的位置:首页 > 其它

12.1工作日志

2015-12-01 17:09 375 查看
昨天是周一,boss要求我把之前的github上下下来修改的贴纸相机修改稳定弄明白,于是这周的主要任务是把相机弄明白。

11.30

相机,StickerCamera之前在一些机型存在着很严重OOM问题,周末询问作者解决的办法,在清单配置文件中的Application中加入一句largeHeap=true,意思是让系统把能分配给程序的最大内存分配给程序,之后整个程序的OOM现象得到了很大的改善。但是这个只能治标不能治本,最终还是要在程序里进行内存管理以使应用能够得到最佳的流畅度体验。

其次,相机的标签和照片是分离的,我得想办法将图片ImageView和标签LableView合成为一张图片,最后找到了一个办法,就是把LableView转化为Bitmap然后用Canvas.drawBitmap方法合成到ImageView里。但是判断标签在照片上的相对位置又让我犯了难,boss说这个问题以后再考虑,于是先放在一旁了。关于图片标签的问题个人认为流程是这样的,上传的时候要给服务器两张图片,一张合成过的,一张未合成的,合成过的可以保存到本地然后浏览时照片列表用合成的图片显示,照片详情用未合成照片显示,使用户可以操作显示隐藏标签。

贴纸显示时重复的问题还没解决。贴纸的原理同标签。

滤镜的原理是在照片表面覆盖了一层View,然后把view与照片合成产生效果。

自定义相机,自定义摄像机。

相机:

摄像机:

12.1

给第三方SDK加入摄像头切换和闪关灯开关功能

原以为SDKDemo里没有这两个功能得自己手写结果发现找不到Camera对象,于是查找SDK自定义MediaRecorderFilter的源码,发现它继承了一个自定义MediaRecoder,里面有设置摄像头切换和闪光灯开关的方法,于是两句话搞定这两个功能。以后使用第三方SDK要深入了解他们的源码才行。

屏幕适配上发现自己的魅族手机宽度比一般手机要宽,因此在屏幕适配的宽度处理上要稍微注意一下。

发现的问题:

设置动图头像时有成功有时不成功。

上传一些自己写的代码:

仿In的个性标添加页:

AddTagsActivity.java

package com.SkyEyesLive.SkyEyesLife.Activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.SkyEyesLive.SkyEyesLife.R;
import com.SkyEyesLive.SkyEyesLife.Utils.SharePreference;
import com.SkyEyesLive.SkyEyesLife.Utils.ToastUtil;
import com.SkyEyesLive.SkyEyesLife.VCamera.com.yixia.camera.demo.ui.record.MediaRecorderActivity;
import com.SkyEyesLive.SkyEyesLife.Volley.VolleyInterface;
import com.SkyEyesLive.SkyEyesLife.Volley.VolleyRequest;
import com.SkyEyesLive.SkyEyesLife.widget.FlowLayout;
import com.android.volley.VolleyError;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
/**
* Created by SkyEyes9
* 个性标签界面
*/
public class AddTagsActivity extends Activity{
private ImageButton back_edit;
private TextView save;
private TextView tagNum;
private EditText et_tag;
private TextView add_tag;
private FlowLayout fl1;
private FlowLayout fl2;
private Activity instance;

private int tagNums=0;//标签数量管理
private String save_tags="";//标签临时存储
private JSONObject json;
private String tagId="";//标签id临时保存存储
private String mFlag="";
private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
switch (msg.what){
case 1:
//更新偏好设置里的用户标签信息
updateUserTagSharePrefrence();
ToastUtil.toast(AddTagsActivity.this, "保存成功");
if (mFlag.equals("注册")){
Intent intent=new Intent(AddTagsActivity.this,RecommendFriendsActivity.class);
intent.putExtra("tag_id",tagId);
startActivity(intent);
}else {
finish();
}
//保存后初始化
save_tags = "";
tagId="";
break;
}
}
};
//默认标签
private String tags[]={
"穿搭","男神","明星","美食",
"宠物","摄影","旅行","手绘",
"萌娃","晒物","星座","女神",
"运动","音乐","动漫","电影",
"家居"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_add_tags);
mFlag=getIntent().getStringExtra("flag");
instance=this;
setViews();
initTags();

}
public ViewGroup.MarginLayoutParams initTextTag(){
ViewGroup.MarginLayoutParams mlp = new ViewGroup.MarginLayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mlp.leftMargin = 40;
mlp.rightMargin = 40;
mlp.topMargin = 20;
mlp.bottomMargin = 20;
return mlp;
}
//添加标签  tag,tag_id添加
public void addTag(String tag){
if (tagNums>6){
Toast.makeText(instance,"标签已经七个了",Toast.LENGTH_SHORT).show();
}else {
tagNums++;
ViewGroup.MarginLayoutParams mlp=initTextTag();
TextView tv = new TextView(instance);
tv.setText(tag);
addTAG(tag);
tv.setTextSize(20);
tv.setTextColor(Color.RED);
tv.setBackgroundResource(R.drawable.tags_textview_2);
tv.setTag(tag);//设置标签tag,以后根据标签tag来删除标签
save_tags+=tag+",";
//LogUtil.log(save_tags);
//删除标签监听器
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
removeTag("" + view.getTag());
//删除全局标签名称
save_tags = save_tags.replaceAll(
view.getTag() + "," +
"|," + view.getTag()
, "");
//删除全局标签Id
tagId = tagId.substring(0, tagId.length() - 4);
}
});
//屏幕适配
fl1.addView(tv, mlp);
updateNum(tagNums);

}
}
//添加用户标签(从偏好设置里)
public void addUserTag(String[] userTags,String[] userTag_id){
ViewGroup.MarginLayoutParams mlp=initTextTag();
for (int i=0;i<userTags.length;i++) {
if (!userTags[i].equals("")) {//
TextView tv = new TextView(instance);
tv.setText(userTags[i]);
tv.setTextSize(20);
tv.setTextColor(Color.RED);
tv.setBackgroundResource(R.drawable.tags_textview_2);
tv.setTag(userTags[i]);
//addTAG(userTags[i]);//调接口获取tag_id(异步的),这里涉及到线程的不确定性(最后的问题了)
tagId+=userTag_id[i]+",";//
save_tags+=userTags[i]+",";
//删除标签监听器
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
removeTag("" + view.getTag());
//删除全局标签集合
save_tags = save_tags.replaceAll(
view.getTag() + "," +
"|," + view.getTag()
, "");
//删除全局标签Id
tagId = tagId.substring(0, tagId.length() - 4);
}
});
fl1.addView(tv, mlp);
tagNums++;
updateNum(tagNums);
}
}
}
//移除标签
private void removeTag(String tag) {
fl1.removeView(fl1.findViewWithTag(tag));
updateNum(--tagNums);
}

//更新标签数量
private void updateNum(int tagNums) {
tagNum.setText(tagNums + "/7");
}
//初始化标签
private void initTags() {
//初始化用户标签
Pattern p=Pattern.compile(",");
String tag=SharePreference.user_tag_name(AddTagsActivity.this);
tag=tag.replaceAll("null,|,null|null","");
String[] userTags=p.split(tag);
String[] userTag_id=p.split(SharePreference.user_tag(AddTagsActivity.this));

addUserTag(userTags,userTag_id);
// 初始化推荐标签
ViewGroup.MarginLayoutParams mlp=initTextTag();
for (int i=0;i<tags.length;i++){
final TextView tv=new TextView(this);
tv.setText(tags[i]);
tv.setTextSize(20);
tv.setTextColor(Color.BLACK);
tv.setBackgroundResource(R.drawable.tags_textview_1);
//设置标签监听流式布局中的子控件
tv.setTag(tags[i]);
//点击添加
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//判断已存在的标签,存在则不操作,不存在则添加
for (int i = 0; i < fl1.getChildCount(); i++) {
if (((TextView)fl1.getChildAt(i)).getText().equals(((TextView) view).getText())) {
return;
}
}
addTag(""+view.getTag());
}
});
fl2.addView(tv,mlp);
}
}
//初始化页面
private void setViews() {
back_edit=(ImageButton)findViewById(R.id.back_edit);
save=(TextView)findViewById(R.id.save);
tagNum=(TextView)findViewById(R.id.tagNum);
et_tag=(EditText)findViewById(R.id.et_tag);

et_tag.setFocusable(true);
et_tag.setFocusableInTouchMode(true);
//请求获得焦点
et_tag.requestFocus();
//强制弹出虚拟键盘
InputMethodManager imm = ( InputMethodManager ) et_tag.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );
imm.showSoftInput(et_tag,InputMethodManager.SHOW_FORCED);
imm.showSoftInput(et_tag, 0);

add_tag=(TextView)findViewById(R.id.add_tag);
fl1=(FlowLayout)findViewById(R.id.fl1);
fl2=(FlowLayout)findViewById(R.id.fl2);
}
//点击事件
public void doClick(View view) {
switch (view.getId()){
//返回
case R.id.back_edit:
startActivity(new Intent(AddTagsActivity.this, MediaRecorderActivity.class));
break;
//保存操作
case R.id.save:
SaveTags();
break;
//添加标签
case R.id.add_tag:
addSelfTag();
et_tag.setText("");
break;
}

}
//添加个性标签
private void addSelfTag() {
Toast.makeText(AddTagsActivity.this,"添加标签",Toast.LENGTH_SHORT).show();
if (tagNums<7){
//判断已存在的标签,存在则提示,不存在则添加
for (int i = 0; i < fl1.getChildCount(); i++) {
if (((TextView)fl1.getChildAt(i)).getText().equals(et_tag.getText().toString())) {
return;
}
}
addTag(et_tag.getText().toString());
}
}
//保存标签监听
public void SaveTags(){
if (fl1.getChildCount()!=0) {
//LogUtil.log("saveTag" + tagId.substring(0, tagId.length() - 1)+",saveId"+ save_tags.substring(0, save_tags.length() - 1));
modifyTag(tagId.substring(0, tagId.length() - 1), save_tags.substring(0, save_tags.length() - 1));
}else {//标签为空的情况
modifyTag("","");
//更新偏好设置里的用户标签信息
updateUserTagSharePrefrence();
}

}

/**
* 保存标签后后台更新用户标签信息到偏好设置
*/
private void updateUserTagSharePrefrence() {
String url="http://api.skyeyeslive.com/phpbackground/Home/User/getUser";
String requestTag="getUser";
Map<String, String> comment = new HashMap<>();
comment.put("uid",SharePreference.userId(AddTagsActivity.this));
VolleyRequest.RequestPost(this, url, requestTag, comment, new VolleyInterface(this,VolleyInterface.listener,
VolleyInterface.errorListener) {
@Override
public void onMySuccess(String result) {
JSONObject userJson;
JSONObject jsonList;
int retCode=3;
try {
userJson = new JSONObject(result);//解析数据
retCode = userJson.getInt("success");
jsonList=userJson.getJSONObject("list");
//LogUtil.log(jsonList);
if (retCode==1){
try {
SharedPreferences preferences = getSharedPreferences("userinfo", 0);
SharedPreferences.Editor
editor = preferences.edit();//会创建一个editor对象,要注意。
editor.putString("user_tag_name", (jsonList.getString("user_tag_name")));
editor.putString("user_tag", (jsonList.getString("user_tag")));
editor.commit();
} catch (JSONException e) {
e.printStackTrace();
}
ToastUtil.toast(AddTagsActivity.this, "返回用户信息成功");
}else {
ToastUtil.toast(AddTagsActivity.this, "返回用户信息失败");
}
} catch (JSONException e) {
e.printStackTrace();
}
}

@Override
public void onMyError(VolleyError error) {

}
});
}

//后台修改标签信息
private void modifyTag(String tag_id, String tag) {
String url="http://api.skyeyeslive.com/phpbackground/Home/User/modifyUserTag";
String requestTag="modifyUserTag";
Map<String, String> comment = new HashMap<>();
comment.put("user_id", SharePreference.userId(AddTagsActivity.this));
comment.put("user_tag",tag_id);
comment.put("user_tag_name",tag);
VolleyRequest.RequestPost(this, url, requestTag, comment, new VolleyInterface(this, VolleyInterface.listener, VolleyInterface.errorListener) {
@Override
public void onMySuccess(String result) {
JSONObject json;
int retCode=3;
try {
json = new JSONObject(result);//解析数据
retCode = json.getInt("success");
} catch (JSONException e) {
e.printStackTrace();
}
if (retCode==1){
Message msg=new Message();
msg.what=1;
handler.sendMessage(msg);
}else {
ToastUtil.toast(AddTagsActivity.this, "保存失败");
}

}

@Override
public void onMyError(VolleyError error) {

}
});

}
//后台添加标签
private void addTAG(String tag) {
String url="http://api.skyeyeslive.com/phpbackground/Home/Tag/addTag";
String requestTag="addTags";
Map<String, String> comment = new HashMap<>();
comment.put("tag_name", tag);
//这是一个异步的操作,需要注意线程的不确定性
VolleyRequest.RequestPost(this, url, requestTag, comment, new VolleyInterface(this, VolleyInterface.listener, VolleyInterface.errorListener) {
@Override
public void onMySuccess(String result) {

int retCode = 3;
try {
json = new JSONObject(result);//解析数据
retCode = json.getInt("success");
} catch (JSONException e) {
e.printStackTrace();
}
if (retCode == 1) {
try {
tagId += json.getString("tag_id") + ",";
} catch (JSONException e) {
e.printStackTrace();
}
}
}

@Override
public void onMyError(VolleyError error) {

}
});
}
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
<ScrollView
android:layout_below="@+id/ll_recomend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="@color/orangered"
android:padding="@dimen/padding_item"
>
<ImageButton
android:id="@+id/back_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/back"
android:layout_marginLeft="@dimen/padding_item"
android:contentDescription="@string/A_Picture"
android:onClick="doClick"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/add_self_tags"
android:textSize="@dimen/font_size_large"
android:textColor="@color/white"
android:gravity="center"
android:layout_weight="1"/>
<TextView
android:id="@+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/savetags"
android:textSize="20sp"
android:textColor="@color/white"
android:onClick="doClick"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="15dp"
android:background="@color/hui_gray"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="已有标签"
android:textSize="18sp"
/>
<TextView
android:id="@+id/tagNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0/7"
android:textSize="17sp"
android:textColor="@color/orangered"
/>

</LinearLayout>
<com.SkyEyesLive.SkyEyesLife.widget.FlowLayout
android:id="@+id/fl1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
>
</com.SkyEyesLive.SkyEyesLife.widget.FlowLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp"
>
<EditText
android:id="@+id/et_tag"
android:layout_width="300dp"
android:layout_height="30dp"
android:layout_marginLeft="20dp"
android:background="@drawable/tags_edittext"
android:textColor="@color/grey"
android:singleLine="true"
android:hint="添加个性标签(限7个字)"
android:inputType="text"
/>
<TextView
android:id="@+id/add_tag"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="添加"
android:textSize="22sp"
android:onClick="doClick"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/et_tag"
/>
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:text="标记出你的兴趣爱好"
android:textSize="18sp"
/>
<com.SkyEyesLive.SkyEyesLife.widget.FlowLayout
android:id="@+id/fl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
>
</com.SkyEyesLive.SkyEyesLife.widget.FlowLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>


RecommendFriendsActivity.java 仿in的推荐好友界面

package com.SkyEyesLive.SkyEyesLife.Activity;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.SkyEyesLive.SkyEyesLife.Adapter.RecommendFriendsAdapter;
import com.SkyEyesLive.SkyEyesLife.Biz.DarenInfoBiz;
import com.SkyEyesLive.SkyEyesLife.Biz.GetRecomUserByTagBiz;
import com.SkyEyesLive.SkyEyesLife.R;
import com.SkyEyesLive.SkyEyesLife.Utils.LogUtil;

/**
* Created by SkyEyes9
* 推荐好友界面
*/
public class RecommendFriendsActivity extends Activity {
private TextView tvComplete;
private Button btnRecom;
private ListView mLvRecom;
private ListView mLvRecomwithTag;
int retCode=0;
private Activity context;
private DarenInfoBiz darenInfoBiz;
private GetRecomUserByTagBiz getRecomUserByTagBiz;
private Receiver receiver;
private IReceiver mreceiver;
private String mTag_id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activty_recomendfriends);
context=this;
mTag_id=getIntent().getStringExtra("tag_id");
mTag_id=mTag_id.substring(0, mTag_id.length() - 1);
receiver=new Receiver();
this.registerReceiver(receiver, new IntentFilter(
"com.getDarenInfo.SUCCESS"));

mreceiver=new IReceiver();
this.registerReceiver(mreceiver, new IntentFilter(
"com.getRecomUserByTag.SUCCESS"));
setViews();
getRecomUserByTagBiz=new GetRecomUserByTagBiz();
getRecomUserByTagBiz.getRecomUserByTags(context,mTag_id);

darenInfoBiz=new DarenInfoBiz();
darenInfoBiz.getDarenInfo(context);
}

private void setViews() {
TextView textView1=new TextView(context);
textView1.setText("推荐达人");
textView1.setTextSize(20);

mLvRecom=(ListView)findViewById(R.id.lvRecom);
mLvRecom.addHeaderView(textView1);

mLvRecomwithTag=(ListView)findViewById(R.id.lvRecomwithTag);

tvComplete= (TextView) findViewById(R.id.complete);
btnRecom=(Button)findViewById(R.id.btFind);
}

public void doClick(View view){
switch (view.getId()){
case R.id.complete:
Intent intent=new Intent(RecommendFriendsActivity.this,MainActivity.class);
startActivity(intent);
finish();
break;
case R.id.btFind:
Intent intent1=new Intent(RecommendFriendsActivity.this,RecommendContactFriends.class);
startActivity(intent1);
break;
}
}
class Receiver extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
mLvRecom.setAdapter(new RecommendFriendsAdapter(context, darenInfoBiz.recommendFriendsInfos));
}
}
class IReceiver extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
mLvRecomwithTag.setAdapter(new RecommendFriendsAdapter(context,getRecomUserByTagBiz.recommendFriendsInfosByTag));
LogUtil.log(getRecomUserByTagBiz.recommendFriendsInfosByTag);
LogUtil.log("标签推荐好友加载成功!");
}
}
@Override
protected void onDestroy() {
super.onDestroy();
context.unregisterReceiver(receiver);
context.unregisterReceiver(mreceiver);
}
}

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:fitsSystemWindows="true"
android:background="#EBEBEB">
<LinearLayout
android:id="@+id/ll_recomend"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="@color/orangered"
android:padding="@dimen/padding_item"
>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/recom_title"
android:textSize="@dimen/font_size_large"
android:textColor="@color/white"
android:gravity="center"
android:layout_weight="0.90"
android:layout_marginLeft="16dp"/>
<TextView
android:id="@+id/complete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/recom_complete"
android:textSize="18sp"
android:textColor="@color/white"
android:onClick="doClick"/>
</LinearLayout>
<ScrollView
android:layout_below="@+id/ll_recomend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/light_gray"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rv2"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#FFFFFE"
android:layout_below="@+id/ll_recomend"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="30dp"
android:textSize="18sp"
android:textColor="#3A3A3A"
android:text="    =^_^=据说每个人都有10个好友在玩天眼哦~"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="   找一找通讯录好友   "
android:textColor="#EA584B"
android:textSize="20sp"
android:id="@+id/btFind"
android:background="@drawable/recomfriends_find_shape"
android:layout_marginTop="70dp"
android:layout_centerHorizontal="true"
android:onClick="doClick"/>
</RelativeLayout>
<TextView
android:id="@+id/tvyou"
android:layout_marginTop="12dp"
android:layout_below="@+id/rv2"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="你可能对他们感兴趣"
android:textSize="20sp"
android:textColor="#3A3A3A"
android:layout_marginLeft="15dp"
/>
<com.SkyEyesLive.SkyEyesLife.widget.ListViewForScrollView
android:id="@+id/lvRecomwithTag"
android:layout_marginTop="6dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tvyou"
android:divider="@color/light_gray"
android:dividerHeight="@dimen/padding_item"
/>
<com.SkyEyesLive.SkyEyesLife.widget.ListViewForScrollView
android:id="@+id/lvRecom"
android:layout_marginTop="6dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lvRecomwithTag"
android:divider="@color/light_gray"
android:dividerHeight="@dimen/padding_item"
/>
</LinearLayout>
</ScrollView>
</RelativeLayout>


RecommendContactFriends.java 仿in的推荐通讯录好友界面

package com.SkyEyesLive.SkyEyesLife.Activity;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import com.SkyEyesLive.SkyEyesLife.Adapter.RecommendFriendsAdapter;
import com.SkyEyesLive.SkyEyesLife.Biz.RecomContactBiz;
import com.SkyEyesLive.SkyEyesLife.R;
import com.SkyEyesLive.SkyEyesLife.Utils.LogUtil;

/**
* Created by SkyEyes9
* 推荐联系人界面
*/
public class RecommendContactFriends extends Activity {
private String phoneNumbers="";
private Activity instance;
private Receiver receiver;
private ListView lvContact;
private RecomContactBiz recomContactBiz;
private TextView mRightBtn;
private ImageButton mLeftBtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recommend_contact_friends);
instance=this;
receiver=new Receiver();
this.registerReceiver(receiver, new IntentFilter(
"com.getUserByMobile.SUCCESS"));
setView();
getContactFromPhone();
}

private void setView() {
lvContact= (ListView) findViewById(R.id.lvRecom_contact);
mRightBtn= (TextView) findViewById(R.id.recom_contact_complete);
mLeftBtn= (ImageButton) findViewById(R.id.recom_contact_back_edit);
mRightBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(RecommendContactFriends.this,MainActivity.class));
}
});
mLeftBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}

public void getContactFromPhone() {
ContentResolver c=instance.getContentResolver();
Cursor phoneCursor=c.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[]{
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Photo.PHOTO_ID,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
}
, null, null, null);
if (phoneCursor!=null){
while(phoneCursor.moveToNext()){
//得到手机号码
String phoneNumber = phoneCursor.getString(1);
//当手机号码为空的或者为空字段 跳过当前循环
if (TextUtils.isEmpty(phoneNumber))
continue;
if(phoneNumber.length()==11){//
if (phoneNumber.charAt(0)=='0'){//11位且第一位不为0
continue;
}
phoneNumbers+=phoneNumber+",";
}else if (phoneNumber.length()==14){//14位截取为11位
phoneNumber=phoneNumber.substring(3,phoneNumber.length());
phoneNumbers+=phoneNumber+",";
}else {

}
}
phoneCursor.close();
}
phoneNumbers=phoneNumbers.substring(0,phoneNumbers.length()-1);
LogUtil.log(phoneNumbers);
recomContactBiz=new RecomContactBiz();
recomContactBiz.getUserInfoByContacts(instance, phoneNumbers);

}

@Override
protected void onDestroy() {
super.onDestroy();
instance.unregisterReceiver(receiver);
}

class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
LogUtil.log("结果:"+recomContactBiz.recommendFriendsInfos);
lvContact.setAdapter(new RecommendFriendsAdapter(instance, recomContactBiz.recommendFriendsInfos));
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: