Android Open Source - Ascent Grade Graph Activity






From Project

Back to project page Ascent.

License

The source code is released under:

GNU General Public License

If you think the Android project Ascent listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package be.sourcery.ascent;
// w  ww  . java 2 s  .c  o  m
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;


public class GradeGraphActivity extends MyActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.grades);
        setTitle(R.string.grades);
        setupActionBar();
        getDataset();
    }

    private void getDataset() {
        InternalDB db = new InternalDB(this);
        addGrades(db,(GradeView) findViewById( R.id.gradeView), false);
        db.close();
    }

    private void addGrades(InternalDB db, GradeView view, final boolean allTime) {
        List<Ascent> ascents = allTime ? db.getSortedAscents() : db.getSortedAscentsForLast12Months();
        String currentGrade = null;
        int osCount = 0;
        int flCount = 0;
        int rpCount = 0;
        int tpCount = 0;
        List<GradeInfo> lines = new ArrayList<GradeInfo>();
        for (Iterator iterator = ascents.iterator(); iterator.hasNext();) {
            Ascent ascent = (Ascent)iterator.next();
            String grade = ascent.getRoute().getGrade();
            if (currentGrade == null || grade.equals(currentGrade)) {
                switch (ascent.getStyle()) {
                    case Ascent.STYLE_ONSIGHT:
                        osCount++;
                        break;
                    case Ascent.STYLE_FLASH:
                        flCount++;
                        break;
                    case Ascent.STYLE_REDPOINT:
                        rpCount++;
                        break;
                    case Ascent.STYLE_TOPROPE:
                        tpCount++;
                        break;
                    default:
                        break;
                }
            }
            if (currentGrade == null) {
                currentGrade = grade;
            } else {
                if (!grade.equals(currentGrade)) {
                    GradeInfo grades = new GradeInfo(currentGrade, osCount, flCount, rpCount, tpCount);
                    lines.add(grades);
                    currentGrade = grade;
                    osCount = ascent.getStyle() == Ascent.STYLE_ONSIGHT ? 1 : 0;
                    flCount = ascent.getStyle() == Ascent.STYLE_FLASH ? 1 : 0;
                    rpCount = ascent.getStyle() == Ascent.STYLE_REDPOINT ? 1 : 0;
                    tpCount = ascent.getStyle() == Ascent.STYLE_TOPROPE ? 1 : 0;
                }
            }
        }
        GradeInfo grades = new GradeInfo(currentGrade, osCount, flCount, rpCount, tpCount);
        lines.add(grades);
        view.setGradeInfo(lines);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                // app icon in action bar clicked; go home
                Intent intent = new Intent(this, MainActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    private void showAscents(String grade, boolean allTime) {
        Intent myIntent = new Intent(this, GradeAscentsActivity.class);
        Bundle b = new Bundle();
        b.putString("grade", grade);
        b.putBoolean("allTime", allTime);
        myIntent.putExtras(b);
        startActivity(myIntent);
    }

}




Java Source Code List

be.sourcery.ascent.AddAscentActivity.java
be.sourcery.ascent.AddCragActivity.java
be.sourcery.ascent.AddProjectActivity.java
be.sourcery.ascent.AscentApplication.java
be.sourcery.ascent.AscentProvider.java
be.sourcery.ascent.Ascent.java
be.sourcery.ascent.CragAscentsActivity.java
be.sourcery.ascent.CragListActivity.java
be.sourcery.ascent.Crag.java
be.sourcery.ascent.EditAscentActivity.java
be.sourcery.ascent.ExportDataActivity.java
be.sourcery.ascent.GradeAscentsActivity.java
be.sourcery.ascent.GradeGraphActivity.java
be.sourcery.ascent.GradeInfo.java
be.sourcery.ascent.GradeView.java
be.sourcery.ascent.ImportDataActivity.java
be.sourcery.ascent.InternalDB.java
be.sourcery.ascent.MainActivity.java
be.sourcery.ascent.MyActivity.java
be.sourcery.ascent.ProjectListActivity.java
be.sourcery.ascent.Project.java
be.sourcery.ascent.RepeatAscentActivity.java
be.sourcery.ascent.Route.java
be.sourcery.ascent.ScoreGraphActivity.java
be.sourcery.ascent.SearchAscentsActivity.java
be.sourcery.ascent.TickProjectActivity.java
be.sourcery.ascent.Top10Activity.java