package com.jiuqi.njt.ui; import java.io.File; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Set; import android.app.Activity; import android.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.telephony.TelephonyManager; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.TabWidget; import android.widget.TextView; import android.widget.Toast; import cn.sharesdk.framework.Platform; import cn.sharesdk.framework.Platform.ShareParams; import cn.sharesdk.framework.PlatformActionListener; import cn.sharesdk.framework.ShareSDK; import cn.sharesdk.sina.weibo.SinaWeibo; import cn.sharesdk.tencent.qzone.QZone; import cn.sharesdk.wechat.friends.Wechat; import cn.sharesdk.wechat.moments.WechatMoments; import com.jiuqi.mobile.nigo.comeclose.bean.ConvertHelper; import com.jiuqi.mobile.nigo.comeclose.bean.base.RoleCode; import com.jiuqi.mobile.nigo.comeclose.bean.client.DownLoadClientBean; import com.jiuqi.mobile.nigo.comeclose.manager.client.IDownLoadClientManager; import com.jiuqi.mobile.nigo.comeclose.ws.client.ClientContext; import com.jiuqi.njt.R; import com.jiuqi.njt.NewsAndFavor.MyFavorNewActivity; import com.jiuqi.njt.data.CheckStateInterface; import com.jiuqi.njt.data.MyApp; import com.jiuqi.njt.data.OptsharepreInterface; import com.jiuqi.njt.model.CModuleBean; import com.jiuqi.njt.model.ModuleType; import com.jiuqi.njt.receiver.ScreenOnBroadCastReceiver; import com.jiuqi.njt.register.QueryJobsActivityNew; import com.jiuqi.njt.register.RegisterUtils; import com.jiuqi.njt.service.WeatherService; import com.jiuqi.njt.son.UserSettingActivity; import com.jiuqi.njt.update.Config; import com.jiuqi.njt.util.Constants; import com.jiuqi.njt.util.ModuleUtil; import com.jiuqi.njt.util.RepairUtils; import com.jiuqi.njt.util.TitleBarUtil; import com.jiuqi.njt.util.UIUtil; import com.jiuqi.njt.widget.TabHostActivity; import com.jiuqi.njt.widget.TabItem; import com.jiuqi.njt.zxing.MipcaActivityCapture; import com.jqyd.android.module.lbs.LocationClient; import com.jqyd.android.module.lbs.Interface.ILocationListener; import com.jqyd.android.module.lbs.bean.LocationInfo; /** * <p> * NjtMainActivity * </p> * 农机通主 * <p> * Copyright: 版权所有 (c)<br> * Company: 久其 * </p> * * @author liyue * @version 2013-7-8 */ public class NjtMainActivity extends TabHostActivity { private Context context = this; private String tag = this.getClass().getName(); private LinkedHashMap<String, TabItem> mItems; // private LayoutInflater mLayoutInflater; private String str_TAB_WEATHER; private String str_TAB_ABOUT; private String str_TAB_HOME; private String str_TAB_POST; private String str_TAB_MORE; private TabWidget tabWidget; private int TAB_NORMAL_COLOR = -1; private int TAB_CURRENT_COLOR = -1; static NjtMainActivity instance = null; private int index = 0; private final String WeatherServiceName = "com.jiuqi.njt.service.WeatherService"; private MyApp application; private boolean isLocated = false; private ScreenOnBroadCastReceiver screenReceiver; private LoginSuccessReceiver loginReceiver; /** * 在初始化TabWidget前调用 和TabWidget有关的必须在这里初始化 */ @Override protected void prepare() { // 页签正常状态下的文字颜色 TAB_NORMAL_COLOR = getResources().getColor(R.color.strokeColor); // 页签被选中状态下的文字颜色 TAB_CURRENT_COLOR = getResources().getColor(R.color.main_tabhost_button_select_color); str_TAB_HOME = getResources().getString(R.string.tabBtnHome); str_TAB_POST = getResources().getString(R.string.tabBtnPost); str_TAB_WEATHER = getResources().getString(R.string.tabBtnWeather); str_TAB_ABOUT = getResources().getString(R.string.tabBtnAbout); Intent intent = null; // intent = new Intent(this, NxwActivity.class); // intent = new Intent(this, Home1Activity.class); intent = new Intent(this, IndexMainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); TabItem nxw = new TabItem(str_TAB_HOME, R.drawable.icon_home_normal, R.drawable.icon_home_pressed, R.drawable.button_btm, intent); CModuleBean cModuleBean = new CModuleBean(); cModuleBean.setModuleFlag(new ModuleUtil().getModuleType(78)); intent = new Intent(this, QueryJobsActivityNew.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(Constants.PARAM_MODULEBEAN, cModuleBean); TabItem post = new TabItem(str_TAB_POST, R.drawable.icon_notice_normal, R.drawable.icon_notice_pressed, R.drawable.bg_btm_normal, intent); intent = new Intent(this, WearthActivityNew.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); TabItem poiSearch = new TabItem(str_TAB_WEATHER, // title R.drawable.icon_weather_normal, // icon R.drawable.icon_weather_pressed, // icon pressed R.drawable.button_btm, // background intent); // intent intent = new Intent(this, AboutActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); TabItem demand = new TabItem(str_TAB_ABOUT, R.drawable.icon_about_normal, R.drawable.icon_about_pressed, R.drawable.bg_btm_normal, intent); // intent = new Intent(this, MoreActivity.class); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // TabItem more = new TabItem(str_TAB_MORE, R.drawable.icon_more_normal, // R.drawable.icon_more_pressed, R.drawable.button_btm, intent); mItems = new LinkedHashMap<String, TabItem>(); mItems.put(str_TAB_HOME, nxw); mItems.put(str_TAB_POST, post); mItems.put(str_TAB_WEATHER, poiSearch); mItems.put(str_TAB_ABOUT, demand); // mItems.put(str_TAB_MORE, more); // 设置分割线 tabWidget = getTabWidget(); tabWidget.setDividerDrawable(R.drawable.tab_divider); instance = this; startWeatherService(); } private void setShowTab() { index = getIntent().getIntExtra("index", 0); setCurrentTab(index); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setCurrentTab(1); setShowTab(); if(myApp.getIsLogin()){ String myaccout = sharePre.getPres("account"); String myname = sharePre.getPres("username"); loginUserName.setText(myname); } if (new CheckStateInterface(NjtMainActivity.this).checkConnection()) { checkFirstInstall(); getLocalProvince(); } getImage(); } private void getImage(){ String imageName = sharePre.getPres(Constants.USERIMAGENAME); if(!"".equals(imageName)){ // // 解决加载图片 内存溢出的问题 // // Options 只保存图片尺寸大小,不保存图片到内存 // BitmapFactory.Options opts = new BitmapFactory.Options(); // // 缩放的比例,缩放是很难按准备的比例进行缩放的,其值表明缩放的倍数,SDK中建议其值是2的指数值,值越大会导致图片不清晰 // opts.inSampleSize = 4; // Bitmap image = null; // image = BitmapFactory.decodeStream(imageName, null, opts); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2;//图片宽高都为原来的二分之一,即图片为原来的四分之一 Bitmap image = BitmapFactory.decodeFile(imageName, options); // Bitmap image = BitmapFactory.decodeFile(imageName); //zhiqianzhiyouzheyiju if(null!=image){ login_layout.setImageBitmap(image); } // RepairUtils.destoryBimap(image); }else{ application = (MyApp) getApplicationContext(); if(application.getIsLogin()){ // UserBean userBean = RegisterUtils.getLoginUserBean(this); // if(null!=userBean){ // imageName =null==userBean.getImagePath()?"":userBean.getImagePath(); // if(!"".equals(imageName)){ // imageName = Constants.SERVER_URL+imageName; // Log.e(tag, imageName); // Bitmap image = RegisterUtils.getBitmap(imageName); // if(null!=image){ // login_layout.setImageBitmap(image); // } // } // } imageName = sharePre.getPres("imageURL"); if(!"".equals(imageName)){ imageName = Constants.SERVER_URL+imageName; Log.e(tag, imageName); Bitmap image = RegisterUtils.getBitmap(imageName); if(null!=image){ login_layout.setImageBitmap(image); } // RepairUtils.destoryBimap(image); } } } } // 开启天气预报服务 private void startWeatherService() { screenReceiver = new ScreenOnBroadCastReceiver(); IntentFilter filter = new IntentFilter(Intent.ACTION_TIME_TICK); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_TIME_TICK); intentFilter.addAction(Intent.ACTION_SCREEN_ON); intentFilter.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(screenReceiver, filter); loginReceiver = new LoginSuccessReceiver(); IntentFilter loginFilter = new IntentFilter(); loginFilter.addAction("loginSuccess"); registerReceiver(loginReceiver, loginFilter); boolean isStart = CheckStateInterface.isServiceRunning( NjtMainActivity.this, WeatherServiceName); if (!isStart) { Log.e("service", "-----天气服务启动了-----"); startService(new Intent(NjtMainActivity.this, WeatherService.class)); } else { Log.e("service", "-----天气服务已经启动了-----"); } } private void checkFirstInstall() { // 判断是否初次安装 sharePre = new OptsharepreInterface(this); String info = sharePre.getPres("firstInstall"); String currentversion = Config.getVerName(this); if ("".equals(info) || !info.equals(currentversion)) { new InstallInfoTask().execute(); } } /** tab的title,icon,边距设定等等 */ @Override protected void setTabItemNormalState(TextView textView, TabItem tab) { textView.setDuplicateParentStateEnabled(true); int maginTop = UIUtil.floatToDP(context, 8); int maginRight = UIUtil.floatToDP(context, 1); textView.setPadding(maginRight,maginTop, maginRight, maginTop); textView.setText(tab.getTitle()); textView.setBackgroundResource(tab.getBg()); textView.setCompoundDrawablesWithIntrinsicBounds(0, tab.getIcon(), 0, 0); textView.setTextColor(TAB_NORMAL_COLOR); } private void setTabitemCurrentState(TextView textView, TabItem tab) { textView.setDuplicateParentStateEnabled(true); int maginTop = UIUtil.floatToDP(context, 8); int maginRight = UIUtil.floatToDP(context, 1); textView.setPadding(maginRight,maginTop, maginRight, maginTop); textView.setText(tab.getTitle()); // textView.setBackgroundDrawable(getResources().getDrawable( // R.drawable.bg_bottom_tab_pressed)); textView.setCompoundDrawablesWithIntrinsicBounds(0, tab.getIconPressed(), 0, 0); textView.setTextColor(TAB_CURRENT_COLOR); // textView.setTextSize(size); } @Override protected TabItem getTabItemByTitle(String key) { return mItems.get(key); } /** 点击tab时触发的事件 */ @Override protected Intent getTabItemIntent(TabItem tab) { return tab.getIntent(); } @Override protected Set<String> getTabItemKeys() { return mItems.keySet(); } @Override protected void whenTabChanged(String tabTitle) { for (int i = 0; i < tabWidget.getChildCount(); i++) { View tabView = tabWidget.getChildAt(i); if (null != tabView && tabView instanceof TextView) { TextView tv = (TextView) tabView; // .findViewById(R.id.tab_item_tv); TabItem tab = mItems.get(tv.getText().toString()); if (tabTitle.equalsIgnoreCase(tv.getText().toString())) { setTabitemCurrentState(tv, tab); } else { setTabItemNormalState(tv, tab); } } } } class InstallInfoTask extends AsyncTask<Void, Void, String> { @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected String doInBackground(Void... params) { DownLoadClientBean bean = new DownLoadClientBean(); try { if(application==null){ application = (MyApp) getApplication(); } ClientContext context = application.getClientContext(); if(context==null){ context = ClientContext.getClientContext( Constants.SERVER_URL, Constants.ANONYMOUS, Constants.ANONYMOUS); } IDownLoadClientManager clientManager = context .getManager(IDownLoadClientManager.class); TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String imsi = tm.getSubscriberId(); if(null==imsi||"".equals(imsi)){ imsi = "获取IMSI号失败"; } bean.setImsi(imsi); Log.e(tag, imsi); /** * "客户端类型 1.大众版 2.管理版" */ bean.setType(1); bean.setAccount(sharePre.getPres("account")); bean.setIp(Config.getLocalIpAddress(NjtMainActivity.this)); bean.setCreateDate(); bean.setVersion(Config.getVerName(NjtMainActivity.this)); bean.setPhoneModel(android.os.Build.BRAND+android.os.Build.MODEL); clientManager.create(bean); // 保存安装记录 sharePre.putPres("firstInstall", Config.getVerName(NjtMainActivity.this)); } catch (Exception e) { // /如果异常保存到本地 bean.setCreateDate(); if (!"".equals(sharePre.getPres("installRecordTime"))) { sharePre.putPres("installRecordTime", ConvertHelper .dateTimeToString(bean.getCreateDate())); } } return null; } } private void getLocalProvince() { application = (MyApp) getApplicationContext(); if (!isLocated) { // 开启定位,自动异步 setUpBaiduLocation(); } } // @Override // public void update(Observable observable, Object data) { // BDLocation loc = (BDLocation) data; // application.setProvince(loc.getProvince()); // application.setCity(loc.getCity()); // application.setLat(loc.getLatitude()); // application.setLon(loc.getLongitude()); // setUpAfterLocated(); // } private void setUpBaiduLocation() { LocationClient client = new LocationClient(context); client.request(new ILocationListener() { @Override public void onReceiveLocInfo(int locType, LocationInfo loc) { if(null!=loc){ isLocated =true; if(null==application){ application = (MyApp) context.getApplicationContext(); } application.setProvince(loc.getProvince()); application.setCity(loc.getCity()); application.setLat(loc.getLat()); application.setLon(loc.getLon()); for(int i=0;i<Constants.xzqh_province.length;i++){ String province = application.getProvince(); if(null!=province&&province.length()>2){ if(Constants.xzqh_province[i].contains(application.getProvince().substring(0, 2))){ application.setProvinceCode(Constants.xzqh_code[i]);//注释,pProvinceCode 应该是两位, application.setCode(Constants.xzqh_code_new[i]);//code应该是12位的 break; } } } } } }); } @Override protected void onResume() { super.onResume(); getImage(); } @Override protected void onDestroy() { super.onDestroy(); if(null!=screenReceiver){ unregisterReceiver(screenReceiver); } if(null!=loginReceiver){ unregisterReceiver(loginReceiver); } } @Override public void onClick(View v) { if(null==application){ application = (MyApp) getApplicationContext(); } if(application.getsMenu().isOpen()){ Intent intent = null; switch (v.getId()) { case R.id.btnShare: shareMethod(); break; case R.id.btnCodeScanning: intent = new Intent(); intent.setClass(NjtMainActivity.this, MipcaActivityCapture.class); startActivity(intent); break; case R.id.btnMyFavor: intent = new Intent(); intent.setClass(NjtMainActivity.this, MyFavorNewActivity.class); // intent.setClass(NjtMainActivity.this, MyFavorF.class); startActivity(intent); break; case R.id.btnYyset: intent = new Intent(); intent.setClass(NjtMainActivity.this, VoiceSet.class); startActivity(intent); break; case R.id.btnRecord: intent = new Intent(); intent.setClass(NjtMainActivity.this, UploadInBackgroundActivity.class); startActivity(intent); break; case R.id.btnModuleCustom: intent = new Intent(); intent.setClass(NjtMainActivity.this, ModulerCustomActivity.class); startActivity(intent); break; case R.id.login_layout: if(myApp.getIsLogin()){ util = new RegisterUtils(); util.takeCameraDialog(context); }else { UIUtil.showMsg(this, "请先登陆"); } break; case R.id.loginUserName: if(myApp.getIsLogin()){ intent = new Intent(NjtMainActivity.this, UserSettingActivity.class); startActivity(intent); }else{ intent = new Intent(NjtMainActivity.this, LoginActivityNew.class); startActivity(intent); } break; case R.id.btnNotice: intent = new Intent(); intent.setClass(NjtMainActivity.this, NoticeListActivity.class); CModuleBean moduleBean = new CModuleBean(); moduleBean.setModuleFlag(ModuleType.ggtz); intent.putExtra(Constants.PARAM_MODULEBEAN, moduleBean); startActivity(intent); break; case R.id.btnWzcx: intent = new Intent(); intent.setClass(NjtMainActivity.this, WzcxActivity.class); startActivity(intent); break; case R.id.btnGjhf: intent = new Intent(); intent.setClass(NjtMainActivity.this, GjhfActivity.class); startActivity(intent); break; case R.id.btnNjdd: intent = new Intent(); intent.setClass(NjtMainActivity.this, NjddActivity.class); startActivity(intent); break; default: break; } } } private File myImageFile; private RegisterUtils util; // 分享处理 private void shareMethod() { LayoutInflater mLayoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); ViewGroup rootView = (ViewGroup) mLayoutInflater.inflate( R.layout.share_activity, null); View rlTitleBar = rootView.findViewById(R.id.titleBarStub); final AlertDialog dialog = new AlertDialog.Builder(this).create(); dialog.setView(rootView, -1, -1, -1, -1); dialog.setCanceledOnTouchOutside(false); dialog.show(); TitleBarUtil.createTitleBar(this, rlTitleBar, "分享到"); Button btnCancel = (Button) rootView.findViewById(R.id.share_cancelButton); btnCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { dialog.dismiss(); } }); Button btnSina = (Button) rootView.findViewById(R.id.btnSina); Button btnTencent = (Button) rootView.findViewById(R.id.btnTencent); Button btnSMS = (Button) rootView.findViewById(R.id.btnSMS); Button btnWechat = (Button) rootView.findViewById(R.id.btnWechat); Button btnWeFriend = (Button) rootView.findViewById(R.id.btnWeiFriend); btnSina.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ShareParams sp = new ShareParams(); String name; if (null == sharePre.getPres("username")||sharePre.getPres("username").equals("")) { name = "农机通"; }else { name = sharePre.getPres("username"); } sp.setText("好友分享:" + name + "邀您安装农机通客户端大众版" + Constants.APP_SHARE_URL); Platform weibo = ShareSDK.getPlatform(v.getContext(), SinaWeibo.NAME); weibo.setPlatformActionListener(new MyListener()); // 设置分享事件回调 weibo.share(sp); } }); btnTencent.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ShareParams sp1 = new ShareParams(); if (null == sharePre.getPres("username")||sharePre.getPres("username").equals("")) { sp1.setTitle("好友分享:" +"农机通"+"邀您安装农机通客户端大众版" + Constants.APP_SHARE_URL); }else { sp1.setTitle("好友分享:" + sharePre.getPres("username") + "邀您安装农机通农机通客户端大众版" + Constants.APP_SHARE_URL); } sp1.setTitleUrl(Constants.APP_SHARE_URL); // 标题的超链接 sp1.setText("广大农机手的福利"); sp1.setSite("返回农机通"); Platform qzone = ShareSDK.getPlatform(v.getContext(), QZone.NAME); qzone.setPlatformActionListener(new MyListener()); // 设置分享事件回调 qzone.share(sp1); } }); btnSMS.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String username; if (null == sharePre.getPres("username")||sharePre.getPres("username").equals("")) { username = "农机通"; }else { username = sharePre.getPres("username"); } UIUtil.sendSmsUi(NjtMainActivity.this, "", "好友分享:" + username + "邀您安装农机通客户端大众版" + Constants.APP_SHARE_URL); } }); btnWechat.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { boolean sIsWXAppInstalledAndSupported = api.isWXAppInstalled() && api.isWXAppSupportAPI(); if (sIsWXAppInstalledAndSupported) { ShareParams sp2 = new ShareParams(); sp2.setShareType(Platform.SHARE_TEXT); sp2.setTitle("好友分享:" + "农机通邀您安装农机通客户端大众版" + Constants.APP_SHARE_URL); sp2.setText("好友分享:" + "农机通邀您安装农机通客户端大众版 " + Constants.APP_SHARE_URL); Platform weixin = ShareSDK.getPlatform(v.getContext(), Wechat.NAME); weixin.setPlatformActionListener(new MyListener()); // 设置分享事件回调 weixin.share(sp2); } else { Toast.makeText(v.getContext(), "请安装微信", Toast.LENGTH_SHORT) .show(); } } }); btnWeFriend.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { boolean sIsWXAppInstalledAndSupported = api.isWXAppInstalled() && api.isWXAppSupportAPI(); if (sIsWXAppInstalledAndSupported) { ShareParams sp3 = new ShareParams(); sp3.setShareType(Platform.SHARE_TEXT); sp3.setTitle("好友分享:" + "农机通邀您安装农机通客户端大众版" + Constants.APP_SHARE_URL); sp3.setText("好友分享:" + "农机通邀您安装农机通客户端大众版" + Constants.APP_SHARE_URL); Bitmap imageData = BitmapFactory.decodeResource( v.getResources(), R.drawable.ic_launcher_new); sp3.setImageData(imageData); Platform plat = ShareSDK.getPlatform(v.getContext(), WechatMoments.NAME); plat.setPlatformActionListener(new MyListener()); // 设置分享事件回调 plat.share(sp3); } else { Toast.makeText(v.getContext(), "请安装微信", Toast.LENGTH_SHORT) .show(); } } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RegisterUtils.PHOTOGRAPH && resultCode ==this.RESULT_OK) { try { myImageFile = util.getMyImageFile(); // Bitmap bitmap = ImageTools.getPhotoFromSDCard(myImageFile.getPath()); getImage(context,Uri.fromFile(myImageFile)); sharePre.putPres(Constants.USERIMAGENAME, myImageFile.getPath()); } catch (Exception e) { e.printStackTrace(); } } if (requestCode == RegisterUtils.PHOTO_IMAGE_CODE && null != data) { try { Uri uri = data.getData(); if (uri == null) { return; } String picturePath = RepairUtils .filePath(context, uri);//71010 // Bitmap bitmap = ImageTools.getPhotoFromSDCard(picturePath); getImage(context,uri); sharePre.putPres(Constants.USERIMAGENAME, picturePath); } catch (Exception e) { e.printStackTrace(); } } if(200 == requestCode){ if(resultCode == RESULT_OK){ // 拿到剪切数据 Bitmap bmap = data.getParcelableExtra("data"); // 显示剪切的图像 login_layout.setImageBitmap(bmap); try { File file = RepairUtils.createFile(new File("")); java.io.FileOutputStream out = new java.io.FileOutputStream(file); if (bmap.compress(Bitmap.CompressFormat.JPEG, 60, out)) {//30 是压缩率,表示压缩70%; 如果不压缩是100,表示压缩率为0,zhiqian shi 90 out.flush(); out.close(); } if (new File(file.getPath()).length() > 0) { sharePre.putPres(Constants.USERIMAGENAME, file.getPath()); Log.e(tag, "已经保存" + file.getPath()); RegisterUtils.upLoadImage(context, sharePre.getPres(Constants.USERIMAGENAME)); } } catch (Exception e) { e.printStackTrace(); } if(null!=bmap){ login_layout.setImageBitmap(bmap); } // RepairUtils.destoryBimap(image); } } } private void getImage(Context context,Uri uri){ Intent intent = new Intent(); intent.setAction("com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*");// mUri是已经选择的图片Uri intent.putExtra("crop", "true"); intent.putExtra("aspectX", 1);// 裁剪框比例 intent.putExtra("aspectY", 1); intent.putExtra("outputX", 150);// 输出图片大小 intent.putExtra("outputY", 150); intent.putExtra("return-data", true); ((Activity)(context)).startActivityForResult(intent, 200); } class MyListener implements PlatformActionListener { @Override public void onCancel(Platform arg0, int arg1) { // TODO Auto-generated method stub } @Override public void onComplete(Platform arg0, int arg1, HashMap<String, Object> arg2) { // TODO Auto-generated method stub } @Override public void onError(Platform arg0, int arg1, Throwable arg2) { // TODO Auto-generated method stub } } /** * 登录成功广播接收 * 登录成功后更新侧滑菜单 * @author joe * */ public class LoginSuccessReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if(null==application){ application = (MyApp) getApplicationContext(); } if(application.getIsLogin()){ String myname = sharePre.getPres("username"); /** * 设置登录的用户名 */ loginUserName.setText(myname); /** * 显示我的收藏功能 */ UIUtil.showView(btnMyFavor); UIUtil.showView(layMyFavor); UIUtil.showView(btnRecordLayout); showNoticeNum(); // /** // * 显示公告通知功能 // */ // UIUtil.showView(noticeLayout); String rolesString = sharePre.getPres("rolesString"); int role = UIUtil.tryToInteger(sharePre.getPres("role")); if(role == RoleCode.Cooper.getCode() ||rolesString.contains(RoleCode.Cooper.getWeiyima())){ UIUtil.showView(btnWzcx); UIUtil.showView(btnGjhf); UIUtil.showView(btnNjdd); }else{ UIUtil.hideView(btnWzcx); UIUtil.hideView(btnGjhf); UIUtil.hideView(btnNjdd); } } } } }