号簿助手 v4.6.31版本的 MD5 值为:9d7ff98a6bb5cc178eac2df4d1b2f0e0
以下内容为反编译后的 MyCardDetailAdapter.java 源代码,内容仅作参考
package com.chinatelecom.pim.ui.adapter.setting;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Build;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.chinatelecom.pim.R;
import com.chinatelecom.pim.core.CoreManagerFactory;
import com.chinatelecom.pim.core.IConstant;
import com.chinatelecom.pim.core.manager.ImageCacheManager;
import com.chinatelecom.pim.core.manager.MediaFileManager;
import com.chinatelecom.pim.core.manager.NameCardManager;
import com.chinatelecom.pim.core.manager.PhotoManager;
import com.chinatelecom.pim.core.manager.PimAccountManager;
import com.chinatelecom.pim.core.manager.PreferenceKeyManager;
import com.chinatelecom.pim.core.manager.SyncAndroidDeviceManager;
import com.chinatelecom.pim.foundation.common.model.ContactADResponseList;
import com.chinatelecom.pim.foundation.common.model.sync.SyncResponse;
import com.chinatelecom.pim.foundation.common.view.ViewAdapter;
import com.chinatelecom.pim.foundation.common.view.ViewModel;
import com.chinatelecom.pim.foundation.lang.KeyValuePare;
import com.chinatelecom.pim.foundation.lang.model.NameCard;
import com.chinatelecom.pim.foundation.lang.model.Theme;
import com.chinatelecom.pim.foundation.lang.model.contact.Contact;
import com.chinatelecom.pim.foundation.lang.model.contact.Website;
import com.chinatelecom.pim.foundation.lang.net.Connection;
import com.chinatelecom.pim.foundation.lang.utils.CharsUtils;
import com.chinatelecom.pim.foundation.lang.utils.ContactUtils;
import com.chinatelecom.pim.foundation.lang.utils.DateUtils;
import com.chinatelecom.pim.foundation.lang.utils.DeviceUtils;
import com.chinatelecom.pim.foundation.lang.utils.StringUtils;
import com.chinatelecom.pim.ui.model.MyCardtInfoContainer;
import com.chinatelecom.pim.ui.view.HeaderView;
import com.chinatelecom.pim.ui.view.bitmapUtils.CircleImageView;
import com.chinatelecom.pim.ui.view.scroll.DampScrollView;
import ctuab.proto.message.GetContactAdProto;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class MyCardDetailAdapter extends ViewAdapter<MyCardInfoViewModel> {
private static final int MIDDLE_LENGTH = 8;
private PimAccountManager accountManager;
private Contact contact;
private ContactADResponseList contactADResponseListList;
private Bitmap contactBg;
private Context context;
public int from;
private AsyncTask getBackgroundResTask;
private boolean hasGetBackGround;
private ImageCacheManager imageCacheManager;
private MediaFileManager mediaFileManager;
public NameCard nameCard;
public NameCardManager nameCardManager;
private GetContactAdProto.NewContactAd newContactAd;
private String phoneNumber;
public PreferenceKeyManager preferenceKeyManager;
private SyncAndroidDeviceManager syncAndroidDeviceManager;
public MyCardDetailAdapter(Activity activity, Theme theme) {
super(activity, theme);
this.context = CoreManagerFactory.getInstance().getContext();
this.hasGetBackGround = false;
this.from = -1;
this.phoneNumber = "";
this.imageCacheManager = CoreManagerFactory.getInstance().getImageCacheManager();
this.nameCardManager = CoreManagerFactory.getInstance().getNameCardManager();
this.accountManager = CoreManagerFactory.getInstance().getAccountManager();
this.syncAndroidDeviceManager = CoreManagerFactory.getInstance().getSyncAndroidDeviceManager();
this.preferenceKeyManager = CoreManagerFactory.getInstance().getPreferenceKeyManager();
this.mediaFileManager = CoreManagerFactory.getInstance().getMediaFileManager();
this.getBackgroundResTask = new AsyncTask<Object, Object, Object>() {
@Override
protected Object doInBackground(Object... params) {
MyCardDetailAdapter.this.getBackgroundRes();
MyCardDetailAdapter.this.setContactAD();
return null;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
MyCardDetailAdapter.this.getModel().getContactAvatar().setAnimation(AnimationUtils.loadAnimation(MyCardDetailAdapter.this.context, R.anim.contact_info_image_alpha));
}
};
}
@Override
public MyCardInfoViewModel doSetup() {
Activity activity = getActivity();
activity.setContentView(R.layout.my_card_detail_activity);
MyCardInfoViewModel model = new MyCardInfoViewModel();
model.setHeaderView((HeaderView) activity.findViewById(R.id.header_view));
model.setHeaderTitle((TextView) activity.findViewById(R.id.contact_detail_header_title));
model.setScrollView((DampScrollView) activity.findViewById(R.id.layout_scroll));
model.setContactAvatarLayout((RelativeLayout) activity.findViewById(R.id.contact_avatar_layout));
model.setContactAvatarBg((ImageView) activity.findViewById(R.id.contact_avatar_bg));
model.setContactAvatar((CircleImageView) activity.findViewById(R.id.contact_avatar));
model.setContactName((TextView) activity.findViewById(R.id.contact_name));
model.setContactUri((TextView) activity.findViewById(R.id.contact_jump_uri));
model.setContactPositionTitle((TextView) activity.findViewById(R.id.contact_position_title));
model.setContactCompanyName((TextView) activity.findViewById(R.id.contact_company_name));
model.setContactListLayout((LinearLayout) activity.findViewById(R.id.contact_list_layout));
model.setContactMainLists((LinearLayout) activity.findViewById(R.id.contact_main_list));
model.setRlNfcWriteTips((RelativeLayout) activity.findViewById(R.id.rl_nfc_write_tips));
model.setBtnNfcWriteRetry((Button) activity.findViewById(R.id.btn_nfc_write_retry));
model.setIvNfcWriteTipsBg((ImageView) activity.findViewById(R.id.iv_nfc_write_tips_bg));
model.setTvNfcWriteTipsNote1((TextView) activity.findViewById(R.id.tv_nfc_write_tips_note1));
model.setTvNfcWriteTipsNote2((TextView) activity.findViewById(R.id.tv_nfc_write_tips_note2));
model.setTvNfcWriteTipsNote3((TextView) activity.findViewById(R.id.tv_nfc_write_tips_note3));
model.setFloatMyCardWriteNfcLayout((RelativeLayout) activity.findViewById(R.id.float_my_card_write_nfc_layout));
model.setFloatMyCardWriteNfc((ImageView) activity.findViewById(R.id.float_my_card_write_nfc_icon));
model.setIvNfcOptionHelp((ImageView) activity.findViewById(R.id.iv_nfc_option_help));
setViewAlpha(model.getHeaderTitle(), 0.0f);
model.getScrollView().setImageView(model.getContactAvatarBg());
model.getScrollView().setFadingEdgeLength(0);
int version = Integer.valueOf(Build.VERSION.SDK).intValue();
if (version > 8) {
model.getScrollView().setOverScrollMode(2);
}
return model;
}
public int getFrom() {
return this.from;
}
public void setupContact() {
boolean fromContactDeatil = false;
if (getActivity() != null && getActivity().getIntent() != null) {
this.from = getActivity().getIntent().getIntExtra(IConstant.Params.FROM, -1);
if (this.from == 10) {
fromContactDeatil = true;
getModel().getHeaderView().getRightThreeView().setVisibility(8);
getModel().getHeaderView().getRightView().setVisibility(8);
getModel().getHeaderView().getSharedView().setVisibility(8);
this.contact = (Contact) getActivity().getIntent().getSerializableExtra(IConstant.Params.CONTACT);
if (this.contact != null && this.contact.getWebsites() != null) {
for (Website website : this.contact.getWebsites()) {
if (StringUtils.isNotBlank(website.getUrl()) && website.getUrl().contains("下载地址:http://pim.189.cn/d")) {
this.contact.getWebsites().remove(website);
}
}
}
if (this.contact != null && StringUtils.isNotBlank(this.contact.getNote()) && this.contact.getNote().contains("本名片由号簿助手写入")) {
this.contact.setNote("");
}
}
}
if (((!fromContactDeatil && this.from == 4) || (!fromContactDeatil && this.from == 11)) && this.nameCardManager.findNameCard() != null) {
this.contact = this.nameCardManager.findNameCard().getContact();
getModel().getHeaderView().getSharedView().setVisibility(8);
getModel().getHeaderView().getRightView().setImageDrawable(getActivity().getResources().getDrawable(R.drawable.mycardshared));
}
if (this.from == 10 && this.contact != null) {
String value = getMiddleValue();
if (StringUtils.isNotBlank(value)) {
getModel().getHeaderView().setMiddleView(value + "的名片");
}
}
}
public String getPhoneNumber() {
return this.phoneNumber;
}
private String getMiddleValue() {
String value = "";
if (StringUtils.isNotBlank(this.contact.getDisplayName())) {
value = this.contact.getDisplayName();
} else if (this.contact.getPhones() != null && this.contact.getPhones().size() > 0) {
value = this.contact.getPhones().get(0).getNumber();
}
if (StringUtils.isNotBlank(value)) {
char[] chars = value.toCharArray();
int count = 0;
int temp = 0;
for (char c : chars) {
temp++;
if (CharsUtils.isChinese(c)) {
count += 2;
} else {
count++;
}
if (count == 8) {
break;
}
}
return String.valueOf(chars, 0, temp);
}
return value;
}
public Contact getContact() {
return this.contact;
}
public void initAllView() {
getModel().getRlNfcWriteTips().setVisibility(8);
getModel().getScrollView().setVisibility(0);
getModel().getHeaderView().getRightThreeView().setVisibility(0);
getModel().getHeaderView().getRightNextView().setVisibility(0);
getModel().getHeaderView().getRightView().setVisibility(8);
getModel().getContactMainLists().removeAllViews();
if (this.contact != null && this.contact.getPhones().size() > 0) {
this.phoneNumber = this.contact.getPhones().get(0).getNumber();
this.phoneNumber = DeviceUtils.phoneReplaceAll(this.phoneNumber);
if (StringUtils.startsWith(this.phoneNumber, "+86")) {
this.phoneNumber = StringUtils.substring(this.phoneNumber, 3);
}
}
setupHeadView();
setupTopView();
if (this.contact != null) {
if (this.from == 10) {
loadContactPhoto();
} else {
loadMyCardPhoto();
}
setupContactInfoView();
}
if (!this.hasGetBackGround) {
this.getBackgroundResTask.execute(new Object[0]);
this.hasGetBackGround = true;
}
if (this.from == 10) {
getModel().getHeaderView().getRightThreeView().setVisibility(8);
}
}
private void setupContactInfoView() {
new MyCardtInfoContainer(getActivity(), getModel(), this.contact).buildAll();
}
private void setupTopView() {
if (this.contact != null) {
getModel().getContactName().setText(this.contact.getDisplayName());
}
}
private boolean checkTime(String startTime, String endTime) {
if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) {
Date startDate = DateUtils.parse(DateUtils.FMT_DATETIME, startTime);
Date endDate = DateUtils.parse(DateUtils.FMT_DATETIME, endTime);
Date nowDate = new Date();
if (startDate != null && endDate != null && startDate.getTime() < nowDate.getTime() && nowDate.getTime() < endDate.getTime()) {
return true;
}
}
return false;
}
public void getBackgroundRes() {
this.contactADResponseListList = this.mediaFileManager.findContactADList();
if (this.contactADResponseListList != null) {
List<GetContactAdProto.NewContactAd> tempList = new ArrayList<>();
List<GetContactAdProto.NewContactAd> temp1List = new ArrayList<>();
Date nowDate = new Date();
for (GetContactAdProto.NewContactAd contactAd : this.contactADResponseListList.getNewContactAD()) {
this.logger.debug(contactAd.getStartDate() + "=========" + contactAd.getStartDate());
Date startDate = DateUtils.parse(DateUtils.FMT_DATETIME, contactAd.getStartDate());
Date endDate = DateUtils.parse(DateUtils.FMT_DATETIME, contactAd.getEndDate());
if (startDate != null && endDate != null) {
if (startDate.getTime() < nowDate.getTime() && nowDate.getTime() < endDate.getTime()) {
tempList.add(contactAd);
} else if (nowDate.getTime() > endDate.getTime()) {
temp1List.add(contactAd);
}
}
}
List<GetContactAdProto.NewContactAd> saveList = new ArrayList<>();
saveList.addAll(this.contactADResponseListList.getNewContactAD());
saveList.removeAll(temp1List);
this.contactADResponseListList.setNewContactAD(saveList);
if (this.contactADResponseListList != null) {
this.logger.debug(this.contactADResponseListList.toString());
this.mediaFileManager.deleteContactAD();
this.mediaFileManager.saveContactAD(this.contactADResponseListList);
}
if (tempList.size() > 1) {
int index = this.mediaFileManager.contactRandom(tempList);
this.newContactAd = tempList.get(index);
} else {
this.newContactAd = tempList.get(0);
}
}
}
public void setContactAD() {
if (this.newContactAd != null) {
setupMoreView(this.newContactAd.getContactAd().getAdurl(), this.newContactAd.getTitle(), this.newContactAd.getJobServerId());
final String imgUrl = this.newContactAd.getContactAd().getImgUrl();
this.handler.post(new Runnable() {
@Override
public void run() {
MyCardDetailAdapter.this.imageCacheManager.getCacheImageLoader().DisplayImage(imgUrl, MyCardDetailAdapter.this.getModel().getContactAvatarBg(), false);
CoreManagerFactory.getInstance().getEventLogManager().insertEvent(MyCardDetailAdapter.this.newContactAd.getJobServerId(), 12);
MyCardDetailAdapter.this.getModel().getContactAvatarBg().setAnimation(AnimationUtils.loadAnimation(MyCardDetailAdapter.this.context, R.anim.contact_info_image_alpha));
}
});
}
}
private GetContactAdProto.GetContactAdResponse getContactAdResponse(String contactNum) {
KeyValuePare keyValuePare = this.accountManager.hasAccount();
ContactADResponseList contactADList = this.mediaFileManager.findContactADList();
String localNumber = "";
if (keyValuePare != null) {
localNumber = keyValuePare.key;
}
SyncResponse<GetContactAdProto.GetContactAdResponse> syncResponse = null;
try {
if (Connection.getInstance(this.context).isConnected()) {
syncResponse = this.syncAndroidDeviceManager.getContactAdResponse(contactNum, localNumber, contactADList);
}
} catch (Exception e) {
e.printStackTrace();
}
if (syncResponse == null || syncResponse.getBody() == null || !syncResponse.getBody().hasContactAd() || !syncResponse.getBody().getContactAd().hasAdurl()) {
return null;
}
GetContactAdProto.GetContactAdResponse response = syncResponse.getBody();
return response;
}
private void setupMoreView(final String adUrl, final String title, final int jobServerId) {
this.handler.post(new Runnable() {
@Override
public void run() {
if (StringUtils.isNotBlank(adUrl)) {
MyCardDetailAdapter.this.getModel().getContactAvatarBg().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (jobServerId > 0) {
CoreManagerFactory.getInstance().getEventLogManager().insertEvent(jobServerId, 13);
}
Intent intent = MyCardDetailAdapter.this.getModel().getBgResIntent();
intent.putExtra(IConstant.Intent.INTENT_WEB_URL, adUrl);
intent.putExtra(IConstant.Intent.INTENT_WEB_TITLE, title);
MyCardDetailAdapter.this.getActivity().startActivity(intent);
}
});
}
}
});
}
private void setupHeadView() {
getModel().getHeaderView().setMiddleView(" ");
getModel().getHeaderTitle().setText(this.contact.getDisplayName());
}
public void loadMyCardPhoto() {
Bitmap photo = this.nameCardManager.getMycardPhoto();
if (photo != null) {
getModel().getContactAvatar().setImageBitmap(photo);
this.hasGetBackGround = true;
} else {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
MyCardDetailAdapter.this.getModel().getContactAvatar().setImageBitmap(null);
MyCardDetailAdapter.this.getModel().getContactAvatar().setImageResource(R.drawable.icon_default_avartar);
MyCardDetailAdapter.this.getModel().getContactAvatar().invalidate();
}
});
}
}
public void loadContactPhoto() {
PhotoManager photoManager = CoreManagerFactory.getInstance().getPhotoManager();
Bitmap photo = photoManager.loadPhtoByContactRawId(this.contact.getRawContactId().longValue());
if (photo != null) {
Bitmap photo2 = ContactUtils.loadPhoto(this.context, this.contact.getContactId().longValue());
if (photo2 != null) {
photo = photo2;
}
getModel().getContactAvatar().setImageBitmap(photo);
this.hasGetBackGround = true;
return;
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
MyCardDetailAdapter.this.getModel().getContactAvatar().setImageResource(R.drawable.icon_default_avartar);
MyCardDetailAdapter.this.getModel().getContactAvatar().invalidate();
}
});
}
public void setViewAlpha(View v, float alpha) {
if (alpha > 255.0f) {
alpha = 255.0f;
} else if (alpha < 0.0f) {
alpha = 0.0f;
}
if (Build.VERSION.SDK_INT >= 11) {
v.setAlpha(alpha);
return;
}
AlphaAnimation alphaAnim = new AlphaAnimation(alpha, alpha);
alphaAnim.setDuration(0L);
alphaAnim.setFillAfter(true);
v.startAnimation(alphaAnim);
}
public class MyCardInfoViewModel extends ViewModel {
private TextView HeaderTitle;
private Intent bgResIntent;
private Button btnNfcWriteRetry;
private CircleImageView contactAvatar;
private ImageView contactAvatarBg;
private RelativeLayout contactAvatarLayout;
private TextView contactCompanyName;
private LinearLayout contactListLayout;
private LinearLayout contactMainLists;
private TextView contactName;
private TextView contactPositionTitle;
private TextView contactUri;
private ImageView floatMyCardWriteNfc;
private RelativeLayout floatMyCardWriteNfcLayout;
private HeaderView headerView;
private ImageView ivNfcOptionHelp;
private ImageView ivNfcWriteTipsBg;
private View.OnClickListener onBookClickListener;
private View.OnClickListener onRecordClickListener;
private RelativeLayout rlNfcWriteTips;
private DampScrollView scrollView;
private TextView tvNfcWriteTipsNote1;
private TextView tvNfcWriteTipsNote2;
private TextView tvNfcWriteTipsNote3;
public MyCardInfoViewModel() {
}
public HeaderView getHeaderView() {
return this.headerView;
}
public void setHeaderView(HeaderView headerView) {
this.headerView = headerView;
}
public TextView getHeaderTitle() {
return this.HeaderTitle;
}
public void setHeaderTitle(TextView headerTitle) {
this.HeaderTitle = headerTitle;
}
public DampScrollView getScrollView() {
return this.scrollView;
}
public void setScrollView(DampScrollView scrollView) {
this.scrollView = scrollView;
}
public RelativeLayout getContactAvatarLayout() {
return this.contactAvatarLayout;
}
public void setContactAvatarLayout(RelativeLayout contactAvatarLayout) {
this.contactAvatarLayout = contactAvatarLayout;
}
public ImageView getContactAvatarBg() {
return this.contactAvatarBg;
}
public void setContactAvatarBg(ImageView contactAvatarBg) {
this.contactAvatarBg = contactAvatarBg;
}
public CircleImageView getContactAvatar() {
return this.contactAvatar;
}
public void setContactAvatar(CircleImageView contactAvatar) {
this.contactAvatar = contactAvatar;
}
public TextView getContactName() {
return this.contactName;
}
public void setContactName(TextView contactName) {
this.contactName = contactName;
}
public TextView getContactPositionTitle() {
return this.contactPositionTitle;
}
public void setContactPositionTitle(TextView contactPositionTitle) {
this.contactPositionTitle = contactPositionTitle;
}
public TextView getContactCompanyName() {
return this.contactCompanyName;
}
public void setContactCompanyName(TextView contactCompanyName) {
this.contactCompanyName = contactCompanyName;
}
public TextView getContactUri() {
return this.contactUri;
}
public void setContactUri(TextView contactUri) {
this.contactUri = contactUri;
}
public LinearLayout getContactListLayout() {
return this.contactListLayout;
}
public void setContactListLayout(LinearLayout contactListLayout) {
this.contactListLayout = contactListLayout;
}
public LinearLayout getContactMainLists() {
return this.contactMainLists;
}
public void setContactMainLists(LinearLayout contactMainLists) {
this.contactMainLists = contactMainLists;
}
public Intent getBgResIntent() {
return this.bgResIntent;
}
public void setBgResIntent(Intent bgResIntent) {
this.bgResIntent = bgResIntent;
}
public View.OnClickListener getOnBookClickListener() {
return this.onBookClickListener;
}
public void setOnBookClickListener(View.OnClickListener onBookClickListener) {
this.onBookClickListener = onBookClickListener;
}
public View.OnClickListener getOnRecordClickListener() {
return this.onRecordClickListener;
}
public void setOnRecordClickListener(View.OnClickListener onRecordClickListener) {
this.onRecordClickListener = onRecordClickListener;
}
public RelativeLayout getRlNfcWriteTips() {
return this.rlNfcWriteTips;
}
public void setRlNfcWriteTips(RelativeLayout rlNfcWriteTips) {
this.rlNfcWriteTips = rlNfcWriteTips;
}
public ImageView getIvNfcWriteTipsBg() {
return this.ivNfcWriteTipsBg;
}
public void setIvNfcWriteTipsBg(ImageView ivNfcWriteTipsBg) {
this.ivNfcWriteTipsBg = ivNfcWriteTipsBg;
}
public TextView getTvNfcWriteTipsNote1() {
return this.tvNfcWriteTipsNote1;
}
public void setTvNfcWriteTipsNote1(TextView tvNfcWriteTipsNote1) {
this.tvNfcWriteTipsNote1 = tvNfcWriteTipsNote1;
}
public TextView getTvNfcWriteTipsNote2() {
return this.tvNfcWriteTipsNote2;
}
public void setTvNfcWriteTipsNote2(TextView tvNfcWriteTipsNote2) {
this.tvNfcWriteTipsNote2 = tvNfcWriteTipsNote2;
}
public TextView getTvNfcWriteTipsNote3() {
return this.tvNfcWriteTipsNote3;
}
public void setTvNfcWriteTipsNote3(TextView tvNfcWriteTipsNote3) {
this.tvNfcWriteTipsNote3 = tvNfcWriteTipsNote3;
}
public Button getBtnNfcWriteRetry() {
return this.btnNfcWriteRetry;
}
public void setBtnNfcWriteRetry(Button btnNfcWriteRetry) {
this.btnNfcWriteRetry = btnNfcWriteRetry;
}
public ImageView getIvNfcOptionHelp() {
return this.ivNfcOptionHelp;
}
public void setIvNfcOptionHelp(ImageView ivNfcOptionHelp) {
this.ivNfcOptionHelp = ivNfcOptionHelp;
}
public ImageView getFloatMyCardWriteNfc() {
return this.floatMyCardWriteNfc;
}
public void setFloatMyCardWriteNfc(ImageView floatMyCardWriteNfc) {
this.floatMyCardWriteNfc = floatMyCardWriteNfc;
}
public RelativeLayout getFloatMyCardWriteNfcLayout() {
return this.floatMyCardWriteNfcLayout;
}
public void setFloatMyCardWriteNfcLayout(RelativeLayout floatMyCardWriteNfcLayout) {
this.floatMyCardWriteNfcLayout = floatMyCardWriteNfcLayout;
}
}
}