public void prepareData() { this.setHasOptionsMenu(true); mImageLoader = ImageLoader.getInstance(getActivity()); mImageLoader.setDefaultBitmap(R.drawable.ic_head_default); mServiceHelper = CampusPoServiceHelper.getInstance(getActivity()); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_refresh: if (BuildConfig.DEBUG) Log.d(TAG, "send request for user profile--begin"); mProgressBar.setVisibility(View.VISIBLE); mServiceHelper.getUserProfile(); break; default: } return super.onOptionsItemSelected(item); }
@Override public void onResume() { super.onResume(); // mProgressBar.setVisibility(View.VISIBLE); IntentFilter filter = new IntentFilter(CampusPoServiceHelper.ACTION_REQUEST_RESULT); mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int requestType = intent.getIntExtra(ServiceContants.REQUEST_TYPE, -1); if (requestType == ServiceContants.REQUEST_PROFILE) { if (BuildConfig.DEBUG) Log.d(TAG, "receive result"); int code = intent.getIntExtra(CampusPoServiceHelper.REQUEST_RESULT_CODE, -1); Bundle data = intent.getBundleExtra(CampusPoServiceHelper.REQUEST_RESULT_DATA); if (BuildConfig.DEBUG) Log.d(TAG, "fetch finished" + code); if (code == 1) { mUser = (User) data.getSerializable(ServiceContants.RESULT_SERIALIZABLE); populateUi(); } else if (code == 0) { String errorMsg = intent.getStringExtra(ServiceContants.RESULT_ERROR_MSG); Toast.makeText(getActivity(), errorMsg, Toast.LENGTH_SHORT).show(); populateUi(); } mProgressBar.setVisibility(View.GONE); } } }; getActivity().registerReceiver(mReceiver, filter); if (mUser == null) { mProgressBar.setVisibility(View.VISIBLE); mServiceHelper.getUserProfile(); } }