@Override public void onClick(View v) { switch (v.getId()) { case R.id.button_activity_details_view_all_observation: mListener.onViewAllObservationsClicked(mActivity.getId()); break; case R.id.icon_activity_details_view_map: try { ArrayList<Observation> mObservationArrayList = new ArrayList<Observation>(mObservationList); mListener.onOpenActivitiesMapClicked(mObservationArrayList); } catch (Exception e) { if (BuildConfig.DEBUG) Log.e(TAG, "onClick: ", e); } break; } }
@Override public void onClick(View v) { final String email = et_email.getText().toString().trim(); final String password = et_password.getText().toString().trim(); if (isEmailValid && isPasswordValid) { // FIXME: possible bug in additional Context dependency injection try { login(email, password, mContext); } catch (ServerUnavailableException e) { if (BuildConfig.DEBUG) Log.e(TAG, "onClick: ", e); Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_LONG).show(); } } else { // Prompt user to enter credentials Toast.makeText(mContext, "Please enter valid credentials!", Toast.LENGTH_LONG).show(); } }
/** * Subscribes to the event of success in posting locally stored Observation to the server. Once the Observation data is * uploaded, a synchronous call is made to server to store the image for the same Observation by updating the Observation * * @param onMassUploadListLoaded */ @Subscribe public void onPostOfflineObservationSuccess(ObservationEvent.OnLoaded onLoaded) { try { File imageFile = new File(mOfflineObservation.getImageUrl()); // create RequestBody to send the image to server RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), imageFile); // create dynamic file name for the image String fileParam = "file\"; filename=\"" + imageFile.getName(); // finally create ImageData object that contains RequestBody and Image name ImageData mImageData = new ImageData(requestBody, fileParam); // once done, post the File to the Bus for posting it on server. BusProvider.bus().post(new FileUploadEvent.OnLoadingInitialized(mImageData, onLoaded.getResponse().getId(), ApiRequestHandler.UPLOAD_TICK_IMAGE)); } catch (NullPointerException npe) { if (BuildConfig.DEBUG) Log.i(TAG, "onPostOfflineObservationSuccess: " + npe.getLocalizedMessage()); } catch (Exception e) { if (BuildConfig.DEBUG) Log.i(TAG, "onPostOfflineObservationSuccess: " + e.getLocalizedMessage()); } }
@Override public Activities get(String id) { Activities mActivity = null; try { Cursor c = db.query(true, EntityTable.ActivitiesTable.TABLENAME, activityEntryArray, EntityTable.ActivitiesTable.COLUMN_ID + "=?", new String[]{id + ""}, null, null, null, null); if (c != null && c.moveToFirst()) { mActivity = buildFromCursor(c); if (!c.isClosed()) { c.close(); } } } catch (Exception e) { if (BuildConfig.DEBUG) Log.e(TAG, "ActivitiesDAO get: ", e); } return mActivity; }
@Override public Activities getByName(String entityName) { Activities mActivity = null; try { Cursor c = db.query(true, EntityTable.ActivitiesTable.TABLENAME, activityEntryArray, EntityTable.ActivitiesTable.COLUMN_NAME + "=?", new String[]{entityName + ""}, null, null, null, null); if (c != null && c.moveToFirst()) { mActivity = buildFromCursor(c); if (!c.isClosed()) { c.close(); } } } catch (Exception e) { if (BuildConfig.DEBUG) Log.e(TAG, "ActivitiesDAO getByName: ", e); } return mActivity; }
@Override public List<? extends Entity> getAll() { List<Activities> activitiesList = new ArrayList<Activities>(); try { // Query the Database to get all the records. Cursor c = db.query(EntityTable.ActivitiesTable.TABLENAME, activityEntryArray, null, null, null, null, null); if (c != null && c.moveToFirst()) { // loop until the end of Cursor and add each entry to Ticks ArrayList. do { Activities mActivity = buildFromCursor(c); if (mActivity != null) { activitiesList.add(mActivity); } } while (c.moveToNext()); } } catch (Exception e) { if (BuildConfig.DEBUG) Log.e(TAG, "ActivitiesDAO getAll: ", e); } return activitiesList; }
void init() { setWebViewClient(new LoveClient()); WebSettings webSettings = getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setAllowFileAccess(true); webSettings.setDatabaseEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setSaveFormData(false); webSettings.setAppCacheEnabled(true); webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); webSettings.setLoadWithOverviewMode(false); webSettings.setUseWideViewPort(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (BuildConfig.DEBUG) { WebView.setWebContentsDebuggingEnabled(true); } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.getApplicationComponent().inject(this); overridePendingTransition(R.anim.screen_fade_in, R.anim.screen_fade_out); ButterKnife.setDebug(BuildConfig.DEBUG); ButterKnife.bind(this); viewErrorHandler = new ViewErrorHandler(bus, this); }
/** * Once all the Activities are uploaded, delete them from database */ private boolean deleteLocallyStoredObservation(Observation mOfflineObservation) { boolean check = false; try { check = dbController.delete(mOfflineObservation.getId()); } catch (Exception e) { if (BuildConfig.DEBUG) Log.i(TAG, "deleteLocallyStoredObservation: " + e.getLocalizedMessage()); } return check; }
private void populateViews() { try { et_fullName.setText(mUser.getFull_name()); et_address.setText(mUser.getAddress()); et_email.setText(mUser.getEmail()); et_city.setText(mUser.getCity()); et_state.setText(mUser.getState()); et_zip.setText(mUser.getZipCode()); } catch (NullPointerException ne) { if (BuildConfig.DEBUG) Log.e(TAG, "populateViews ", ne); } }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if (mObservationList != null && mObservationList.size() > 0) { inflater.inflate(R.menu.menu_observation_list, menu); final MenuItem item = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(item); if (searchView != null) { searchView.setOnQueryTextListener(this); } else { if (BuildConfig.DEBUG) Log.i(TAG, "search is null"); } } }
@Override public void onBindViewHolder(ObservationsListAdapter.ObservationViewHolder holder, int position) { try { if (holder != null) { Observation mObservation = mObservationList.get(position); holder.txtView_observationName.setText(mObservation.getTickName()); holder.txtView_location.setText(mObservation.getGeoLocation()); String[] dateAndTime = AppUtils.getDateAndTimeSeparate(mObservation.getTimestamp()); holder.txtView_date.setText(dateAndTime[0]);// set date holder.txtView_time.setText(dateAndTime[1]); // set time // set Image url and also the storage status if (mObservation.isOnCloud()) { holder.icon_storageStatus.setImageResource(R.mipmap.ic_cloud_done_black_36dp); } else { holder.icon_storageStatus.setImageResource(R.mipmap.ic_sd_storage_black_24dp); } // FIXME: load image into ImageView if (mObservation.getImageUrl().startsWith("http")) { Picasso.with(mContext).load(mObservation.getImageUrl()).into(holder.imageView_tickImage); } else { Bitmap bitmap = new ImageController(mContext).getBitmapForImageView(holder.imageView_tickImage, mObservation.getImageUrl()); holder.imageView_tickImage.setImageBitmap(bitmap); } if (mObservation.isVerified()) { holder.icon_verified.setImageResource(R.mipmap.ic_verified_gray_24dp); } } } catch (Exception e) { if (BuildConfig.DEBUG) Log.i(TAG, "onBindViewHolder: " + e.getCause()); } }
@Override public long save(Entity entityItem) { try { Activities mActivity = (Activities) entityItem; ContentValues contentValues = getContentValues(mActivity); // save the entity return db.insert(EntityTable.ActivitiesTable.TABLENAME, null, contentValues); } catch (Exception e) { if (BuildConfig.DEBUG) Log.e(TAG, "ActivitiesDAO save: ", e); return -1; } }
@Override public boolean delete(String id) { int deleted = 0; try { deleted = db.delete(EntityTable.ActivitiesTable.TABLENAME, EntityTable.ActivitiesTable.COLUMN_ID + " = ?", new String[]{id}); } catch (Exception e) { if (BuildConfig.DEBUG) Log.e(TAG, "ActivitiesDAO delete: ", e); } return deleted > 0; }
/** * @return Dev mode OR test mode */ public static Class getAutoMode(){ if(BuildConfig.DEBUG){ return MODE_DEV; }else { return MODE_TEST; } }
@Override public void onStart() { super.onStart(); try { // retrieve Observation from the Bundle if (getArguments() != null) { args = getArguments(); if (args.getParcelable(KEY_OBSERVATION) != null) { mObservation = args.getParcelable(KEY_OBSERVATION); } } // set all the values in respective Views // tick name textView_tickName.setText(mObservation.getTickName()); // species textView_tickSpecies.setText(mObservation.getSpecies()); // description String description = mObservation.getDescription() == "" || mObservation.getDescription() == null ? "No description" : mObservation.getDescription(); textView_description.setText(description); // geolocation String geoLocation = mObservation.getGeoLocation() == "" || mObservation.getGeo_location() == null ? "No location" : mObservation.getGeoLocation(); textView_geoLocation.setText(geoLocation); // lat long String latLng = mObservation.getLatitude() + ", " + mObservation.getLongitude(); textView_latLng.setText(latLng); // relative date time long now = System.currentTimeMillis(); CharSequence charSequence = DateUtils.getRelativeTimeSpanString(mObservation.getTimestamp(), now, DateUtils.DAY_IN_MILLIS); textView_timestamp.setText(charSequence); // set observation image if (mObservation.getImageUrl().startsWith("http")) { Picasso.with(mContext).load(mObservation.getImageUrl()).into(imageView_tickImage); } else { Bitmap bitmap = new ImageController(mContext).getBitmapForImageView(imageView_tickImage, mObservation.getImageUrl()); imageView_tickImage.setImageBitmap(bitmap); } // depending on the availability of network , make a network call and get the data or get data from DB if (AppUtils.isConnectedOnline(mContext)) { BusProvider.bus().post(new ObservationEvent.OnLoadingInitialized(mObservation.getId(), ApiRequestHandler.GET_OBSERVATION_WRAPPER)); } else { mActivity = (Activities) dbActivitiesController.get(mObservation.getActivity_id()); if (mActivity != null) { String activityName = mActivity.getActivityName() + " at " + mActivity.getLocation_area(); textView_activityName.setText(activityName); } } if (mObservation.isVerified()) { icon_verified.setImageResource(R.mipmap.ic_verified_gray_24dp); textView_tickSpecies.setText(mObservation.getSpecies()); } } catch (Exception e) { if (BuildConfig.DEBUG) Log.i(TAG, e.getMessage()); } }
@Override public void setCurrentLocation(Location mLocation) { if (BuildConfig.DEBUG) Log.i(TAG, "setCurrentLocation: " + mLocation.getLatitude() + " : " + mLocation.getLongitude()); }
@Subscribe public void onActivitiesAndObservationsCountsLoadedFailure(UserEvent.OnLoadingError onLoadingError) { if (BuildConfig.DEBUG) Log.i(TAG, onLoadingError.getErrorMessage()); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_remote_observations, container, false); ButterKnife.bind(this, rootView); animation = AnimationUtils.loadAnimation(mContext, R.anim.simple_grow); txtView_observationList_info.setVisibility(View.GONE); dbController = new DatabaseDataController(mContext, ObservationsDao.getInstance()); mUploadAlertDialog = new UploadAlertDialog(mContext, this); // get the ActivityId from the Bundle. if (getArguments() != null) { args = getArguments(); } if (args != null && args.containsKey(KEY_ACTIVITY_ID)) { activityId = args.getString(KEY_ACTIVITY_ID); FLAG_GET_ACTIVITY_OBSERVATIONS = true; } else if (args != null && args.containsKey(KEY_STATUS_FLAG)) { long statusFlag = args.getLong(KEY_STATUS_FLAG); FLAG_ACTIVITY_RUNNING = statusFlag == ObservationMasterActivity.FLAG_ACTIVITY_RUNNING ? true : false; } else { activityId = null; FLAG_GET_ACTIVITY_OBSERVATIONS = false; FLAG_ACTIVITY_RUNNING = false; } // onclick of Add Observation FAB. fab_addObservation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mInterface.onObservationAddListener(); } }); recyclerView_observations.setHasFixedSize(true); if (mContext != null) { LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(getActivity()); recyclerView_observations.setLayoutManager(mLinearLayoutManager); } else { if (BuildConfig.DEBUG) Log.d(TAG, " No Layout manager supplied"); } // Setup refresh listener which triggers new data loading mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { syncObservationWithServerAsync(); } }); // Configure the refreshing colors mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_red_dark, android.R.color.holo_blue_dark, android.R.color.holo_orange_light, android.R.color.holo_green_dark); return rootView; }
@Override public void onStart() { super.onStart(); // call to network depending on the type of call to be made. // only in case of the Observations that are stored locally and Network being available, create a background thread to // get all the Observations from the local SQLite storage // Get all the Observations for a specific Activity - Local and Online if (activityId != null) { // get all Observations depending on network connection. if (AppUtils.isConnectedOnline(mContext)) { // if the user has clicked ViewObservations in ActivityDetailFragment fragment, then show only the Activity's Observations // Observations specific to Activity dbAccessThread.start(); // get all Observations from Network BusProvider.bus().post(new ObservationEvent.OnLoadingInitialized("", activityId, ApiRequestHandler.ACT_OBSERVATIONS)); displayProgressDialog("Fetching Observations..."); } else { // network not available. // if the user has clicked ViewObservations in ActivityDetailFragment fragment, then show only the Activity's Observations localObservationList = (List<Observation>) dbController.getAll(activityId); } } // Get all the Observations - Local and Online else { // get all the observations if (AppUtils.isConnectedOnline(mContext)) { // start a background thread to get all the Observations stored in the Local Database dbAccessThread.start(); // get all the observations stored on the server in separate thread BusProvider.bus().post(new ObservationEvent.OnLoadingInitialized("", ApiRequestHandler.GET_ALL)); displayProgressDialog("Fetching Observations..."); } else { // get all the observations. When the User clicks MyObservations in Nav Drawer or from DashboardFragment localObservationList = (List<Observation>) dbController.getAll(); } /** * If network is not available, then our list of Observations will be the Observations that will be stored locally */ if (!AppUtils.isConnectedOnline(mContext)) { if (mObservationList != null) { mObservationList.clear(); } // for local observations only if (localObservationList != null) { // make observation list mObservationList = localObservationList; } // if the List is build appropriately, display it in the RecyclerView if (mObservationList.size() > 0 && mObservationList != null) { displayObservationList(); } else if (mObservationList.size() == 0) { // display text message txtView_observationList_info.setVisibility(View.VISIBLE); mRelativeLayout.setBackgroundColor(ContextCompat.getColor(mContext, R.color.lightText)); recyclerView_observations.setVisibility(View.GONE); } else { if (BuildConfig.DEBUG) Log.i(TAG, "activity list size < 0"); } } } // doesn't matter if the Network is online or offline, display the message saying Activity is running if (FLAG_ACTIVITY_RUNNING) { } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user_main); try { fragmentManager = getSupportFragmentManager(); // if Fragment container is present if (findViewById(R.id.activity_fragment_container) != null) { // if we are restored from the previous state, restore the Fragments if (savedInstanceState != null) { activityRunningFragment = (ActivityRunningFragment) fragmentManager.getFragment(savedInstanceState, "activityRunning"); activityDetailFragment = (ActivityDetailFragment) fragmentManager.getFragment(savedInstanceState, "activityDetail"); activityNewFragment = (ActivityNewFragment) fragmentManager.getFragment(savedInstanceState, "activityNew"); activityListFragment = (ActivityListFragment) fragmentManager.getFragment(savedInstanceState, "activityList"); } // if user clicks on Start Activity in DashboardFragment if (getIntent().getIntExtra(MainActivity.KEY_ADD_ACTIVITY, 0) == 1) { if (activityNewFragment == null) activityNewFragment = new ActivityNewFragment(); performAddFragmentTransaction(activityNewFragment); } // if user clicks on ActivityListFragment in DashboardFragment else if (getIntent().getIntExtra(MainActivity.KEY_VIEW_ACTIVITY_LIST, 0) == 2) { if (activityListFragment == null) activityListFragment = new ActivityListFragment(); performAddFragmentTransaction(activityListFragment); } // if user navigates back to ActivityRunningFragment fragment. else if (getIntent().getIntExtra(ObservationMasterActivity.KEY_BACK_TO_ACTIVITY_RUNNING, 0) == 11) { if (activityRunningFragment == null) activityRunningFragment = new ActivityRunningFragment(); performReplaceFragmentTransaction(activityRunningFragment); } // if user navigates back to ActivityDetailFragment fragment. else if (getIntent().getIntExtra(ObservationMasterActivity.KEY_BACK_TO_ACTIVITY_DETAILS, 0) == 11) { if (activityDetailFragment == null) activityDetailFragment = new ActivityDetailFragment(); performAddFragmentTransaction(activityDetailFragment); } // if user opens Activity by clicking on the ListView item from DashboardFragment. else if (getIntent().getIntExtra(MainActivity.KEY_OPEN_SELECTED_ACTIVITY, 0) == 24) { Activities mActivities = getIntent().getParcelableExtra(MainActivity.KEY_VIEW_ACTIVITY); if (activityDetailFragment == null) activityDetailFragment = ActivityDetailFragment.newInstance(mActivities); performAddFragmentTransaction(activityDetailFragment); } // open List of Activities by default. else { if (activityListFragment == null) activityListFragment = new ActivityListFragment(); performAddFragmentTransaction(activityListFragment); } } } catch (Exception e) { if (BuildConfig.DEBUG) Log.e(TAG, e.getMessage(), e); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(SLAMBenchApplication.LOG_TAG, getString(R.string.debug_oncreate_happened, this.getLocalClassName())); setContentView(R.layout.activity_main); _runButton = (Button) findViewById(R.id.runButton); TextView message = (TextView) findViewById(R.id.descriptionView); message.setMovementMethod(new ScrollingMovementMethod()); PackageInfo pInfo = null; try { pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String text_msg = getResources().getString(R.string.app_description) + " "; text_msg += "This is the version " + (pInfo != null ? pInfo.versionName : "unknown") + " (" + BuildConfig.BUILD_TYPE + ") of the benchmark." + "<br/>"; text_msg += "<b>" + getString(R.string.app_warning) + "</b>" + "<br/>"; if (RootUtil.isDeviceRooted()) { text_msg += "<font color='red'> <b>" + getResources().getText(R.string.live_mode_available) + "</b></font>" + "<br/>"; } long need_size = MIN_CACHE_SIZE; long current_size = (MobileStats.getAvailableInternalMemorySize() + MobileStats.getUsedInternalMemorySize(this)) / (1024 * 1024); if (current_size < need_size) { text_msg += "<font color='red'> <b>" + getResources().getString(R.string.insufficient_memory, need_size, current_size) + "</b></font>" + "<br/>"; } message.setText(Html.fromHtml(text_msg + ""), TextView.BufferType.SPANNABLE); _runButton.setOnClickListener(this); Log.d(SLAMBenchApplication.LOG_TAG, "Main activity content constructed."); }