@SuppressLint("NewApi") @Override public void onValueSelected(Entry e, Highlight h) { int selectedDifficulty = (int) e.getX(); clearSelectedRoutes(); for (ClimbingRoute route : selectedArea.getRoutes()) { if (Utils.trimUIAARank(route.getUIAARank()) == selectedDifficulty) selectedRoutes.add(route); } // recyclerViewAdapter.notifyItemRangeChanged(0, selectedRoutes.size()); recyclerViewAdapter.notifyItemRangeRemoved(0, selectedArea.getRoutes().size()); recList.invalidate(); if (selectedRoutes.isEmpty()) onNothingSelected(); }
private void initViewPagerHeader() { // Get the ViewPager and set it's PagerAdapter so that it can display items final ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager_details_header); // TODO Get Images from Server and cache them locally List<ClimbingImage> images = new ArrayList<>(); for (int i = 0; i < 5; ++i) { ClimbingImage image = new ClimbingImage(); image.setClimbingId(i); image.setImageUrl(i % 2 == 0 ? "riederin.jpg" : "riederin2.jpg"); image.setDescription(i % 2 == 0 ? "Beschreibung 1" : "Beschreibung 2"); images.add(image); } selectedArea.setImages(images); viewPager.setAdapter( new HeaderImagePagerAdapter( getSupportFragmentManager(), ClimbingAreaDetailsActivity.this, selectedArea)); Handler handlerTimer = new Handler(); handlerTimer.postDelayed( new Runnable() { public void run() { viewPager.setCurrentItem(1, true); } }, 500); }
private void setChartData(ClimbingArea ClimbingArea) { HashMap<Integer, Integer> difficultyMap = new HashMap<>(); for (int i = AppConstants.MIN_UIAA_LEVEL; i <= AppConstants.MAX_UIAA_LEVEL; ++i) { difficultyMap.put(i, 0); } for (ClimbingRoute route : ClimbingArea.getRoutes()) { String difficulty = route.getUIAARank(); int routeDifficulty = Utils.trimUIAARank(difficulty); if (difficultyMap.containsKey(routeDifficulty)) { difficultyMap.put(routeDifficulty, difficultyMap.get(routeDifficulty) + 1); } } ArrayList<BarEntry> routeDifficulties = new ArrayList<BarEntry>(); String[] xVals = new String[difficultyMap.size()]; List<Integer> orderedList = new ArrayList<>(difficultyMap.keySet()); Collections.sort(orderedList); int indexCounter = 0; for (Integer difficulty : orderedList) { xVals[indexCounter] = difficulty + ""; // BarEntry entry = new BarEntry(difficultyMap.get(difficulty), indexCounter++ , difficulty // +""); BarEntry entry = new BarEntry(difficulty, difficultyMap.get(difficulty), indexCounter++); routeDifficulties.add(entry); } mChart.getXAxis().setLabelCount(xVals.length); BarDataSet set1 = new BarDataSet(routeDifficulties, "Schwierigkeiten"); // set1.setColor(getResources().getColor(R.color.primary_700)); int[] uiaaChartColors = new int[AppConstants.UIAA_CHART_COLORS.length]; for (int i = 0; i < uiaaChartColors.length; ++i) { uiaaChartColors[i] = getResources().getColor(AppConstants.UIAA_CHART_COLORS[i]); } set1.setColors(uiaaChartColors); ArrayList<IBarDataSet> dataSets = new ArrayList<>(); dataSets.add(set1); BarData data = new BarData(dataSets); data.setValueFormatter(new MyValueFormatter()); data.setValueTextSize(10f); mChart.setData(data); mChart.animateX(1000); mChart.animateY(1000); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.climbing_area_details); enableToolbar(); selectedArea = getIntent().getExtras().getParcelable(AppConstants.EXTRA_CLIMBING_AREA); selectedArea.setRoutes(new ArrayList<ClimbingRoute>()); CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar_climbing_details); collapsingToolbarLayout.setExpandedTitleColor( getResources().getColor(android.R.color.transparent)); collapsingToolbarLayout.setTitle(selectedArea.getName()); initViewPagerHeader(); initChart(selectedArea); initRouteList(selectedArea); initFab(); animateView(); getSupportLoaderManager().restartLoader(URL_ROUTES_LOADER_ALL, null, this); }
@Override public Loader<Cursor> onCreateLoader(int loaderID, Bundle args) { // Construct the new query in the form of a Cursor Loader. Use the id // parameter to contruct and return different loaders. String[] projection = null; String where = null; String[] whereArgs = null; String sortOrder = null; // Query URI Uri queryUri = null; switch (loaderID) { case URL_ROUTES_LOADER_ALL: queryUri = ClimbingContentProvider.ROUTES_URI; where = ClimbingDBHelper.COLUMN_ROUTES_CLIMBINGAREA_ID + "= ?"; whereArgs = new String[] {String.valueOf(selectedArea.getId())}; break; default: } // Create the new Cursor loader. return new CursorLoader(this, queryUri, projection, where, whereArgs, sortOrder); }
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Replace the result Cursor displayed by the Cursor Adapter with // the new result set. // This handler is not synchonrized with the UI thread, so you // will need to synchronize it before modiyfing any UI elements // directly. switch (loader.getId()) { case URL_ROUTES_LOADER_ALL: while (data.moveToNext()) { int climbingRouteIdColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_ID); int climbingRouteNameColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_NAME); int climbingRouteLatitudeColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_LATITUDE); int climbingRouteLongitudeColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_LONGITUDE); int climbingRouteRankingColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_RANKING); int climbingRouteImageColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_IMAGE_URL); int climbingRouteDifficultyColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_UIAA); int climbingRouteFollowClimbColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_FOLLOW_CLIMB_ACCOMPLISHED); int climbingRouteLeadingClimbColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_LEADING_CLIMB_ACCOMPLISHED); int climbingRouteRouteAccomplishedColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_ROUTE_ACCOMPLISHED); int climbingRouteClimbingAreaColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_CLIMBINGAREA_ID); int id = data.getInt(climbingRouteIdColumnIndex); String name = data.getString(climbingRouteNameColumnIndex); float latitude = data.getFloat(climbingRouteLatitudeColumnIndex); float longitude = data.getFloat(climbingRouteLongitudeColumnIndex); float ranking = data.getFloat(climbingRouteRankingColumnIndex); String difficulty = data.getString(climbingRouteDifficultyColumnIndex); String imageUrl = data.getString(climbingRouteImageColumnIndex); boolean followClimbAccomplished = data.getInt(climbingRouteFollowClimbColumnIndex) > 0; boolean leadClimbAccomplished = data.getInt(climbingRouteLeadingClimbColumnIndex) > 0; boolean routeAccomplished = data.getInt(climbingRouteRouteAccomplishedColumnIndex) > 0; int climbingArea = data.getInt(climbingRouteClimbingAreaColumnIndex); ClimbingRoute climbingRoute = new ClimbingRoute(); climbingRoute.setId(id); climbingRoute.setName(name); climbingRoute.setLatitude(latitude); climbingRoute.setLongitude(longitude); climbingRoute.setRanking(ranking); climbingRoute.setDrawableUrl(imageUrl); climbingRoute.setUIAARank(difficulty); climbingRoute.setFollowClimbAccomplished(followClimbAccomplished); climbingRoute.setLeadClimbAccomplished(leadClimbAccomplished); climbingRoute.setRouteAccomplished(routeAccomplished); Log.d(TAG, "Climbing Area loaded: " + climbingArea); selectedArea.getRoutes().add(climbingRoute); } break; default: } int size = selectedRoutes.size(); clearSelectedRoutes(); selectedRoutes.addAll(selectedArea.getRoutes()); recyclerViewAdapter.notifyItemRangeRemoved(0, size); setChartData(selectedArea); setShareIntent(selectedArea); // TextView sumRoutes = (TextView) findViewById(R.id.textView_sum_routes); // sumRoutes.setText(selectedArea.getRoutes().size() + ""); }
public void onNothingSelected() { clearSelectedRoutes(); selectedRoutes.addAll(selectedArea.getRoutes()); recyclerViewAdapter.notifyItemRangeRemoved(0, selectedArea.getRoutes().size()); };
private void clearSelectedRoutes() { int size = selectedRoutes.size(); selectedRoutes.clear(); recyclerViewAdapter.notifyItemRangeRemoved(0, selectedArea.getRoutes().size()); }