Example usage for android.support.v4.app AlertDialog.Builder setMessage

List of usage examples for android.support.v4.app AlertDialog.Builder setMessage

Introduction

In this page you can find the example usage for android.support.v4.app AlertDialog.Builder setMessage.

Prototype

public void setMessage(CharSequence message) 

Source Link

Usage

From source file:com.iride.ayride.HomePageActivity.java

private void exitFromTheApp() {
    String exitMessage = "Do you want to exit?";
    AlertDialog.Builder builder = new AlertDialog.Builder(HomePageActivity.this);
    builder.setMessage(exitMessage);
    builder.setCancelable(true);//from www  .java 2 s  . c  o  m
    builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    builder.setPositiveButton("Logout", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            rideLocalStorage.clearStorage();
            vehicleLocalStorage.clearStorage();
            userLocalStorage.clearStorage();
            if (isFacebookUser()) {
                LoginManager.getInstance().logOut();
            }

            startActivity(new Intent(HomePageActivity.this, EntranceActivity.class));
            finish();
        }
    });
    AlertDialog alert11 = builder.create();
    alert11.show();
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddHome.java

public void ManageEvent(final String EventID, final int Position, final int viewID) {
    AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
    alertbox.setMessage("What would you like to do?");

    alertbox.setPositiveButton("Ack Event", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface arg0, int arg1) {
            AcknowledgeSingleEvent(Position);
        }/*from w  w w.jav  a  2s.c o m*/
    });

    alertbox.setNeutralButton("View Event", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface arg0, int arg1) {
            /*Intent ViewEventIntent = new Intent(RhybuddHome.this, ViewZenossEvent.class);
            try
            {
               ViewEventIntent.putExtra("EventID", EventID);
               ViewEventIntent.putExtra("Count", listOfZenossEvents.get(Position).getCount());
               ViewEventIntent.putExtra("Device", listOfZenossEvents.get(Position).getDevice());
               ViewEventIntent.putExtra("EventState", listOfZenossEvents.get(Position).getEventState());
               ViewEventIntent.putExtra("FirstTime", listOfZenossEvents.get(Position).getfirstTime());
               ViewEventIntent.putExtra("LastTime", listOfZenossEvents.get(Position).getlastTime());
               ViewEventIntent.putExtra("Severity", listOfZenossEvents.get(Position).getSeverity());
               ViewEventIntent.putExtra("Summary", listOfZenossEvents.get(Position).getSummary());
            }
            catch(Exception e)
            {
                    
            }
                    
            RhybuddHome.this.startActivity(ViewEventIntent);*/

            Intent ViewEventIntent = new Intent(RhybuddHome.this, ViewZenossEventActivity.class);
            ViewEventIntent.putExtra("EventID", EventID);
            ArrayList<String> EventNames = new ArrayList<String>();
            ArrayList<String> EVIDs = new ArrayList<String>();

            for (ZenossEvent evt : listOfZenossEvents) {
                EventNames.add(evt.getDevice());
                EVIDs.add(evt.getEVID());
            }

            ViewEventIntent.putStringArrayListExtra("eventnames", EventNames);
            ViewEventIntent.putStringArrayListExtra("evids", EVIDs);
            RhybuddHome.this.startActivityForResult(ViewEventIntent, 20);
        }
    });

    alertbox.setNegativeButton("Nothing", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface arg0, int arg1) {
        }
    });
    alertbox.show();
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddHome.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    //Forces our onResume() function to do a DB call rather than a full HTTP request just cos we returned
    //from one of our subscreens
    resumeOnResultPollAPI = false;/*from  w w w .  j  a v  a  2s . c  o  m*/

    BackupManager bm = new BackupManager(this);

    //Check what the result was from the Settings Activity
    if (requestCode == 99) {
        //Refresh the settings
        settings = PreferenceManager.getDefaultSharedPreferences(this);

        Intent intent = new Intent(this, ZenossPoller.class);
        intent.putExtra("settingsUpdate", true);
        startService(intent);
        bm.dataChanged();
    } else if (requestCode == ZenossAPI.ACTIVITYRESULT_PUSHCONFIG) {
        if (null != data && data.hasExtra(ZenossAPI.PREFERENCE_PUSHKEY)) {
            doGCMRegistration(data.getStringExtra(ZenossAPI.PREFERENCE_PUSHKEY));
        }
    } else {
        //In theory the Settings activity should perform validation and only finish() if the settings pass validation
        if (resultCode == 1) {
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("FirstRun", false);
            editor.commit();

            //Also update our onResume helper bool although it should already be set
            firstRun = false;

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage(
                    "Additional settings and functionality can be found by pressing the action bar overflow (or pressing the menu button).\r\n"
                            + "\r\nPlease note that this is app is still in Beta. If you experience issues please email;\r\nGareth@NetworksAreMadeOfString.co.uk")
                    .setTitle("Welcome to Rhybudd!").setCancelable(false)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            finishStart(true);
                        }
                    });
            AlertDialog welcomeDialog = builder.create();

            try {
                welcomeDialog.show();
            } catch (Exception e) {
                finishStart(true);
            }

            bm.dataChanged();

        } else if (resultCode == 2) {
            Toast.makeText(RhybuddHome.this, getResources().getString(R.string.FirstRunNeedSettings),
                    Toast.LENGTH_LONG).show();

            finish();
        }
        //Who knows what happened here - quit
        else {
            Toast.makeText(RhybuddHome.this, getResources().getString(R.string.FirstRunNeedSettings),
                    Toast.LENGTH_LONG).show();
            finish();
        }
    }
}

From source file:com.iride.ayride.HomePageActivity.java

private void buildRequestAlert(final Ride ride) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    String message = getRequestAlertMessage(ride);
    builder.setMessage(message + "\n\n" + "Do you want to make request?").setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(@SuppressWarnings("unused") final DialogInterface dialog,
                        @SuppressWarnings("unused") final int id) {
                    ride.setPedestrianId(userLocalStorage.getUserId());
                    ride.setPedestrianInstanceId(rideLocalStorage.getOwnInstanceId());
                    ride.setPedestrianName(userLocalStorage.getUserName());
                    ride.setPedestrianSurName(userLocalStorage.getUserSurName());
                    rideLocalStorage.storeRide(ride);
                    HomePageActivity.this.makeRequestToRide(ride);
                }/*from w  w  w . j a  va 2  s  . c o  m*/
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                    dialog.cancel();
                }
            });
    final AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.affectiva.affdexme.MainActivity.java

private void showPermissionExplanationDialog(int requestCode) {
    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);

    // set title//from  ww w. ja  v  a 2s . c  om
    alertDialogBuilder.setTitle(getResources().getString(R.string.insufficient_permissions));

    // set dialog message
    if (requestCode == CAMERA_PERMISSIONS_REQUEST) {
        alertDialogBuilder.setMessage(getResources().getString(R.string.permissions_camera_needed_explanation))
                .setCancelable(false).setPositiveButton(getResources().getString(R.string.understood),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                                requestCameraPermissions();
                            }
                        });
    } else if (requestCode == EXTERNAL_STORAGE_PERMISSIONS_REQUEST) {
        alertDialogBuilder.setMessage(getResources().getString(R.string.permissions_storage_needed_explanation))
                .setCancelable(false).setPositiveButton(getResources().getString(R.string.understood),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                                requestStoragePermissions();
                            }
                        });
    }

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show();
}

From source file:com.softminds.matrixcalculator.OperationFragments.TransposeFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    if (PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("TRANSPOSE_PROMPT", true)
            && ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(position)
                    .isSquareMatrix()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        builder.setTitle(R.string.TransposePrompt);
        builder.setPositiveButton(R.string.Yup, new DialogInterface.OnClickListener() {
            @Override/*  ww w  .ja  va 2  s  .  com*/
            public void onClick(DialogInterface dialogInterface, int i) {
                ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(ClickPos)
                        .transposeEquals();
                Toast.makeText(getActivity(), R.string.SuccessTranspose, Toast.LENGTH_SHORT).show();
                dialogInterface.dismiss();
            }
        });
        builder.setNegativeButton(R.string.Nope, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                dialogInterface.dismiss();
                Intent i2 = new Intent(getContext(), ShowResult.class);
                MatrixV2 original = ((GlobalValues) getActivity().getApplication()).GetCompleteList()
                        .get(ClickPos);
                i2.putExtras(original.transpose().getDataBundled());
                startActivity(i2);
            }
        });
        builder.setMessage(R.string.SquareTransPrompt);
        builder.show();
    } else //Non Square MatrixV2 to transpose
    {
        Intent i2 = new Intent(getContext(), ShowResult.class);
        MatrixV2 original = ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(ClickPos);
        i2.putExtras(original.transpose().getDataBundled());
        startActivity(i2);
    }

}

From source file:com.terraremote.terrafieldreport.OpenGroundReport.java

@OnClick(R.id.clearVehicleInfo)
void clearVehicleInfo() {
    AlertDialog.Builder builder = new AlertDialog.Builder(OpenGroundReport.this);
    builder.setMessage(R.string.clear_vehicle_info_prompt)
            .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                @Override/*  w  w  w  . j  ava2  s.co  m*/
                public void onClick(DialogInterface dialog, int which) {
                    // Vehicle Details
                    mRentalVehicle.setChecked(false);
                    tvRentalAgencyTv.setVisibility(View.GONE);
                    mRentalAgency.setVisibility(View.GONE);
                    mRentalAgency.setText("");
                    mVehicleMake.setText("");
                    mVehicleModel.setText("");
                    mVehicleColour.setText("");
                    mVehicleLicensePlate.setText("");
                    mVehicleOperatorName.setText("");
                    // Check in Contact
                    mCheckInContactRoleSpinner.setSelection(0);
                    mCheckInContactNameSpinner.setSelection(0);
                    mOtherContactName.setText("");
                }
            }).setNegativeButton(R.string.cancel, null);

    AlertDialog alert = builder.create();
    alert.show();
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddHome.java

private void ConfigureHandlers() {
    handler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == 0) {
                try {
                    if (dialog != null && dialog.isShowing()) {
                        dialog.dismiss();
                    }//  ww w . j  a v  a 2  s.c  o  m
                } catch (NullPointerException npe) {
                    //Sigh
                }

                try {
                    ((ProgressBar) findViewById(R.id.backgroundWorkingProgressBar)).setVisibility(4);
                } catch (NullPointerException npe) {
                    //Sigh
                }

                OnClickListener listener = new OnClickListener() {
                    public void onClick(View v) {
                        try {
                            //Check if we are in a big layout
                            FrameLayout EventDetailsFragmentHolder = (FrameLayout) findViewById(
                                    R.id.EventDetailsFragment);
                            if (EventDetailsFragmentHolder == null) {
                                ManageEvent(v.getTag(R.id.EVENTID).toString(),
                                        (Integer) v.getTag(R.id.EVENTPOSITIONINLIST), v.getId());
                            } else {
                                LoadEventDetailsFragment((Integer) v.getTag(R.id.EVENTPOSITIONINLIST));
                            }
                        } catch (Exception e) {
                            Toast.makeText(getApplicationContext(),
                                    "There was an internal error. A report has been sent.", Toast.LENGTH_SHORT)
                                    .show();
                            //BugSenseHandler.log("EventListOnclick", e);
                        }
                    }
                };

                OnLongClickListener listenerLong = new OnLongClickListener() {
                    public boolean onLongClick(View v) {
                        try {
                            selectForCAB((Integer) v.getTag(R.id.EVENTPOSITIONINLIST));
                        } catch (Exception e) {
                            Toast.makeText(getApplicationContext(),
                                    "There was an internal error. A report has been sent.", Toast.LENGTH_SHORT)
                                    .show();
                            //BugSenseHandler.log("RhybuddHome-onDestroy", e);
                        }
                        return true;
                    }
                };

                OnClickListener addCAB = new OnClickListener() {
                    public void onClick(View v) {
                        try {
                            addToCAB((Integer) v.getTag(R.id.EVENTPOSITIONINLIST));
                        } catch (Exception e) {
                            Toast.makeText(getApplicationContext(),
                                    "There was an internal error. A report has been sent.", Toast.LENGTH_SHORT)
                                    .show();
                            //BugSenseHandler.log("RhybuddHome-onDestroy", e);
                        }
                    }
                };

                //adapter = new ZenossEventsAdaptor(RhybuddHome.this, listOfZenossEvents,listener,listenerLong,addCAB);
                list.setAdapter(adapter);
            } else if (msg.what == 1) {
                try {
                    if (dialog != null && dialog.isShowing())
                        dialog.setMessage("Refresh Complete!");
                } catch (NullPointerException npe) {
                    //Sigh
                }
                this.sendEmptyMessageDelayed(0, 1000);
            } else if (msg.what == 2) {
                if (dialog != null && dialog.isShowing()) {
                    dialog.setMessage("DB Cache incomplete.\r\nQuerying Zenoss directly.\r\nPlease wait....");
                } else {
                    dialog = new ProgressDialog(RhybuddHome.this);
                    dialog.setMessage("DB Cache incomplete.\r\nQuerying Zenoss directly.\r\nPlease wait....");
                    dialog.setCancelable(false);
                    dialog.show();
                }
            } else if (msg.what == 50) {
                if (dialog != null && dialog.isShowing())
                    dialog.dismiss();

                try {
                    if (listOfZenossEvents != null)
                        listOfZenossEvents.clear();

                    if (adapter != null)
                        adapter.notifyDataSetChanged();
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("RhybuddHome", "handler-50", e);
                }

                Toast.makeText(RhybuddHome.this, "There are no events to display", Toast.LENGTH_LONG).show();
            } else if (msg.what == 3 || msg.what == 999) {
                if (dialog != null && dialog.isShowing())
                    dialog.dismiss();

                AlertDialog.Builder builder = new AlertDialog.Builder(RhybuddHome.this);
                builder.setMessage("An error was encountered. Please check your settings and try again.")
                        .setCancelable(false)
                        .setPositiveButton("Edit Settings", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                Intent SettingsIntent = new Intent(RhybuddHome.this, SettingsFragment.class);
                                startActivityForResult(SettingsIntent, 99);
                                alertDialog.cancel();
                            }
                        }).setNegativeButton("Close", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                alertDialog.cancel();
                            }
                        });
                alertDialog = builder.create();
                if (!isFinishing()) {
                    try {
                        alertDialog.show();
                    } catch (Exception e) {
                        //BugSenseHandler.log("alertDialog", e);
                    }
                }
            } else if (msg.what == ZenossAPI.HANDLER_REDOREFRESH) {
                Refresh();
            } else {
                if (dialog != null && dialog.isShowing()) {
                    dialog.dismiss();
                }
                Toast.makeText(RhybuddHome.this,
                        "Timed out communicating with host. Please check protocol, hostname and port.",
                        Toast.LENGTH_LONG).show();
            }
        }
    };

    AckEventHandler = new Handler() {
        public void handleMessage(Message msg) {
            try {
                if (msg.what == 0) {
                    if (adapter != null)
                        adapter.notifyDataSetChanged();
                } else if (msg.what == 1) {
                    for (ZenossEvent evt : listOfZenossEvents) {
                        if (!evt.getEventState().equals("Acknowledged") && evt.getProgress()) {
                            evt.setProgress(false);
                            evt.setAcknowledged();
                        }
                    }

                    RhybuddDataSource datasource = null;

                    try {
                        //TODO maybe do this with the bunch of ack id's we have in the thread?
                        datasource = new RhybuddDataSource(RhybuddHome.this);
                        datasource.open();
                        datasource.UpdateRhybuddEvents(listOfZenossEvents);

                    } catch (Exception e) {
                        e.printStackTrace();
                        BugSenseHandler.sendExceptionMessage("RhybuddHome", "AckEventsHandler", e);
                    } finally {
                        if (null != datasource)
                            datasource.close();
                    }

                    if (adapter != null)
                        adapter.notifyDataSetChanged();
                } else if (msg.what == 2) {
                    for (Integer i : selectedEvents) {
                        if (listOfZenossEvents.get(i).getProgress()) {
                            listOfZenossEvents.get(i).setProgress(false);
                            listOfZenossEvents.get(i).setAcknowledged();
                        }
                    }

                    if (adapter != null)
                        adapter.notifyDataSetChanged();
                } else if (msg.what == 99) {
                    for (ZenossEvent evt : listOfZenossEvents) {
                        if (!evt.getEventState().equals("Acknowledged") && evt.getProgress()) {
                            evt.setProgress(false);
                        }
                    }

                    if (adapter != null)
                        adapter.notifyDataSetChanged();

                    Toast.makeText(getApplicationContext(), "There was an error trying to ACK those events.",
                            Toast.LENGTH_SHORT).show();
                } else {

                    Toast.makeText(getApplicationContext(), "There was an error trying to ACK that event.",
                            Toast.LENGTH_SHORT).show();
                }
            } catch (Exception e) {
                //BugSenseHandler.log("AckEventsHandler", e);
            }
        }
    };
}

From source file:com.terraremote.terrafieldreport.OpenGroundReport.java

@OnClick(R.id.clearAllBtn)
void clearAll() {
    AlertDialog.Builder builder = new AlertDialog.Builder(OpenGroundReport.this);
    builder.setMessage(R.string.are_you_sure)
            .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                @Override/*from w  w  w.  j  a v  a2  s.c  o  m*/
                public void onClick(DialogInterface dialog, int which) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    showDate.setText(sdf.format(new Date()));
                    mTransitDay.setChecked(false);
                    transitDayCard.setBackgroundColor(Color.WHITE);
                    transitDayText.setTextColor(getResources().getColor(android.R.color.tertiary_text_dark));
                    workLocationCard.setVisibility(View.VISIBLE);
                    workDescriptionCard.setVisibility(View.VISIBLE);
                    mWorkingAlone.setChecked(false);
                    tvColleaguesTextView.setVisibility(View.VISIBLE);
                    mColleagues.setVisibility(View.VISIBLE);
                    mColleagues.setText("");
                    mLocationStart.setText("");
                    mGpsLatitude.setText("");
                    mGpsLongitude.setText("");
                    // PPE Checklist
                    mHiVisApparel.setChecked(false);
                    mClothingForSeason.setChecked(false);
                    mSafetyRatedFootwear.setChecked(false);
                    mPersonalSurvivalKit.setChecked(false);
                    mHearingProtection.setChecked(false);
                    mHardHat.setChecked(false);
                    mPpeComments.setText("");
                    // Vehicle Details
                    //                                hasRentalVehicle.setChecked(false);
                    //                                rentalAgencyTextView.setVisibility(View.GONE);
                    //                                hasRentalAgency.setVisibility(View.GONE);
                    //                                hasRentalAgency.setText("");
                    //                                hasVehicleMake.setText("");
                    //                                hasVehicleModel.setText("");
                    //                                hasVehicleColor.setText("");
                    //                                hasVehicleLicensePlate.setText("");
                    //                                hasVehicleOperatorsName.setText("");
                    // Ground Operations Information
                    mCityOfDeparture.setText("");
                    mCityOfArrival.setText("");
                    mProjectLocation.setText("");
                    mProjectDescription.setText("");
                    mEstimatedWorkDuration.setText("");
                    // Check in Contact
                    //                                checkInContactRoleSpinner.setSelection(0);
                    //                                checkInContactNameSpinner.setSelection(0);
                    //                                otherContactName.setText("");
                    mSatellitePhone.setChecked(false);
                    mSatellitePhoneNumberTableRow.setVisibility(View.GONE);
                    mSatellitePhoneNumber.setText("");
                    mRadio.setChecked(false);
                    mFirstAidKit.setChecked(false);
                    mFireExtinguisher.setChecked(false);
                    mTransportingFuel.setChecked(false);
                    mTdgPlacards.setChecked(false);
                    mSpillKit.setChecked(false);
                    mWorkingInTraffic.setChecked(false);
                    mPylons.setChecked(false);
                    mTrafficSigns.setChecked(false);
                    mAppropriateVehicle.setChecked(false);
                    // Hazard / Risk Assessment
                    mRemoteArea.setChecked(false);
                    mWorkingInIsolation.setChecked(false);
                    mExtremeWeather.setChecked(false);
                    mTransmissionLines.setChecked(false);
                    mActiveMineSite.setChecked(false);
                    mActiveLoggingArea.setChecked(false);
                    mWildlife.setChecked(false);
                    mFatigue.setChecked(false);
                    mPoliticalConflict.setChecked(false);
                    mMinimalRisk.setChecked(false);
                    mLowRisk.setChecked(false);
                    mMediumRisk.setChecked(true);
                    mHighRisk.setChecked(false);
                    mVeryHighRisk.setChecked(false);
                    mPreventionMeasures.setText("");
                    mPostMinimalRisk.setChecked(false);
                    mPostLowRisk.setChecked(false);
                    mPostMediumRisk.setChecked(true);
                    mPostHighRisk.setChecked(false);
                    mPostVeryHighRisk.setChecked(false);
                    mGeneralComments.setText("");
                }
            }).setNegativeButton(R.string.cancel, null);

    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.bt.heliniumstudentapp.GradesFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
    mainContext = (AppCompatActivity) getActivity();
    gradesLayout = inflater.inflate(R.layout.fragment_grades, viewGroup, false);

    boolean pass = true;

    if (gradesHtml == null) {
        termFocus = Integer.parseInt(
                PreferenceManager.getDefaultSharedPreferences(mainContext).getString("pref_grades_term", "1"));
        yearFocus = 0;/*  w w w  .ja v  a2  s  .c o m*/

        if (Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(mainContext)
                .getString("pref_general_class", "0")) == 0) {
            try { //TODO Improve
                maxYear = Integer.parseInt(((TextView) mainContext.findViewById(R.id.tv_class_hd)).getText()
                        .toString().replaceAll("\\D+", ""));
            } catch (NumberFormatException e) {
                pass = false;

                MainActivity.drawerNV.getMenu().findItem(R.id.i_schedule_md).setChecked(true);
                MainActivity.FM.beginTransaction()
                        .replace(R.id.fl_container_am, new ScheduleFragment(), "SCHEDULE").commit();

                final AlertDialog.Builder classDialogBuilder = new AlertDialog.Builder(
                        new ContextThemeWrapper(mainContext, MainActivity.themeDialog));

                classDialogBuilder.setTitle(R.string.error);
                classDialogBuilder.setMessage(R.string.error_class);

                classDialogBuilder.setCancelable(false);

                classDialogBuilder.setPositiveButton(android.R.string.ok,
                        new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                mainContext.startActivity(new Intent(mainContext, SettingsActivity.class));
                            }
                        });

                classDialogBuilder.setNegativeButton(android.R.string.cancel, null);

                final AlertDialog classDialog = classDialogBuilder.create();

                classDialog.setCanceledOnTouchOutside(false);
                classDialog.show();

                classDialog.getButton(AlertDialog.BUTTON_POSITIVE)
                        .setTextColor(ContextCompat.getColor(mainContext, MainActivity.accentSecondaryColor));
                classDialog.getButton(AlertDialog.BUTTON_NEGATIVE)
                        .setTextColor(ContextCompat.getColor(mainContext, MainActivity.accentSecondaryColor));
            }
        } else {
            maxYear = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(mainContext)
                    .getString("pref_general_class", "1"));
        }
    }

    if (pass) {
        MainActivity.setToolbarTitle(mainContext, getString(R.string.grades), null);

        gradesELV = (ExpandableListView) gradesLayout.findViewById(R.id.lv_course_fg);

        final boolean online = MainActivity.isOnline();

        if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades", null) == null) { //TODO Simpler
            if (online) {
                getGrades(termFocus, HeliniumStudentApp.df_date().format(new Date()),
                        HeliniumStudentApp.DIREC_CURRENT, HeliniumStudentApp.ACTION_INIT_IN);
            } else { //TODO Display empty GradesFragment with retry option
                Toast.makeText(mainContext, getString(R.string.database_no), Toast.LENGTH_SHORT).show();

                MainActivity.drawerNV.getMenu().findItem(R.id.i_schedule_md).setChecked(true);
                MainActivity.FM.beginTransaction()
                        .replace(R.id.fl_container_am, new ScheduleFragment(), "SCHEDULE").commit();
            }
        } else if (online && gradesHtml == null && PreferenceManager.getDefaultSharedPreferences(mainContext)
                .getBoolean("pref_grades_init", true)) {
            getGrades(termFocus, HeliniumStudentApp.df_date().format(new Date()),
                    HeliniumStudentApp.DIREC_CURRENT, HeliniumStudentApp.ACTION_INIT_IN);
        } else {
            if (gradesHtml == null)
                gradesHtml = PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades",
                        null);

            if (online)
                parseData(HeliniumStudentApp.ACTION_ONLINE);
            else
                parseData(HeliniumStudentApp.ACTION_OFFLINE);
        }

        ((SwipeRefreshLayout) gradesLayout).setColorSchemeResources(MainActivity.accentSecondaryColor,
                MainActivity.accentPrimaryColor, MainActivity.primaryColor);
        ((SwipeRefreshLayout) gradesLayout).setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

            @Override
            public void onRefresh() {
                refresh();
            }
        });

        gradesELV.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
            int previousPosition = -1;

            @Override
            public void onGroupExpand(int position) {
                if (position != previousPosition)
                    gradesELV.collapseGroup(previousPosition);
                previousPosition = position;
            }
        });

        gradesELV.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { //Just a little easter egg
            int clickCount = 1;

            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int position,
                    long id) {
                if (clickCount >= 80) {
                    Toast.makeText(mainContext, "Is this what you wanted?", Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://youtu.be/dQw4w9WgXcQ")));
                } else {
                    switch (clickCount) {
                    case 2:
                        Toast.makeText(mainContext, "Good for you!", Toast.LENGTH_SHORT).show();
                        break;
                    case 10:
                        Toast.makeText(mainContext, "You're really proud of that, aren't you?",
                                Toast.LENGTH_SHORT).show();
                        break;
                    case 20:
                        Toast.makeText(mainContext, "It's really not that big of a deal...", Toast.LENGTH_SHORT)
                                .show();
                        break;
                    case 40:
                        Toast.makeText(mainContext, "You can stop now.", Toast.LENGTH_SHORT).show();
                        break;
                    case 50:
                        Toast.makeText(mainContext, "Please...", Toast.LENGTH_SHORT).show();
                    case 60:
                        Toast.makeText(mainContext, "F* OFF!", Toast.LENGTH_SHORT).show();
                        break;
                    }
                }

                clickCount++;
                return false;
            }
        });

        MainActivity.prevIV.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (MainActivity.isOnline()) {
                    if (termFocus != 1) {
                        termFocus--;

                        getGrades(termFocus, HeliniumStudentApp.df_grades(yearFocus),
                                HeliniumStudentApp.DIREC_BACK, HeliniumStudentApp.ACTION_REFRESH_IN);
                    } else {
                        MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_ONLINE);
                    }
                } else {
                    final int databaseFocus = Integer.parseInt(PreferenceManager
                            .getDefaultSharedPreferences(mainContext).getString("pref_grades_term", "1"));

                    if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades",
                            null) != null && yearFocus == 0 && termFocus > databaseFocus) {
                        yearFocus = 0;
                        termFocus = databaseFocus;

                        gradesHtml = PreferenceManager.getDefaultSharedPreferences(mainContext)
                                .getString("html_grades", null);
                        parseData(HeliniumStudentApp.ACTION_OFFLINE);
                    } else {
                        MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_OFFLINE);
                    }
                }
            }
        });

        MainActivity.historyIV.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (MainActivity.isOnline()) {
                    if (maxYear != 1) {
                        MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_ONLINE);

                        final AlertDialog.Builder gradesDialogBuilder = new AlertDialog.Builder(
                                new ContextThemeWrapper(mainContext, MainActivity.themeDialog));
                        final View gradesLayout = View.inflate(mainContext, R.layout.dialog_grades, null);

                        gradesDialogBuilder.setTitle(getString(R.string.year, maxYear));

                        final NumberPicker yearNP = (NumberPicker) gradesLayout.findViewById(R.id.np_year_dg);

                        gradesDialogBuilder.setView(gradesLayout);

                        //TODO Listen for year change.

                        gradesDialogBuilder.setPositiveButton(android.R.string.ok,
                                new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (MainActivity.isOnline()) {
                                            final int oldValue = yearFocus;

                                            yearFocus = yearNP.getValue() - maxYear;
                                            getGrades(termFocus, HeliniumStudentApp.df_grades(yearFocus),
                                                    oldValue + HeliniumStudentApp.FOCUS_YEAR,
                                                    HeliniumStudentApp.ACTION_REFRESH_IN);
                                        } else {
                                            Toast.makeText(mainContext, getString(R.string.error_conn_no),
                                                    Toast.LENGTH_SHORT).show();
                                        }
                                    }
                                });

                        yearNP.setMinValue(1);
                        yearNP.setMaxValue(maxYear);

                        yearNP.setValue(maxYear);

                        java.lang.reflect.Field[] pickerFields = NumberPicker.class.getDeclaredFields();
                        for (java.lang.reflect.Field pf : pickerFields) {
                            if (pf.getName().equals("mSelectionDivider")) {
                                pf.setAccessible(true);

                                try {
                                    pf.set(yearNP, new ColorDrawable(ContextCompat.getColor(mainContext,
                                            MainActivity.accentPrimaryColor)));
                                } catch (IllegalArgumentException | IllegalAccessException ignored) {
                                }
                                break;
                                /*} else if(pf.getName().equals("mSelectorWheelPaint")) {
                                   pf.setAccessible(true);
                                        
                                   try {
                                      ((Paint) pf.get(yearNP))
                                            .setColor(getColor(MainActivity.themePrimaryTextColor));
                                   } catch (IllegalArgumentException |
                                         IllegalAccessException ignored) {}*/ //FIXME Doesn't work... yet
                            } else if (pf.getName().equals("mInputText")) {
                                pf.setAccessible(true);

                                try {
                                    ((EditText) pf.get(yearNP)).setTextColor(ContextCompat.getColor(mainContext,
                                            MainActivity.themePrimaryTextColor));
                                } catch (IllegalArgumentException | IllegalAccessException ignored) {
                                }
                            }
                        }

                        yearNP.invalidate();

                        gradesDialogBuilder.setNegativeButton(android.R.string.cancel, null);

                        AlertDialog gradesDialog = gradesDialogBuilder.create();

                        gradesDialog.setCanceledOnTouchOutside(true);
                        gradesDialog.show();

                        gradesDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(
                                ContextCompat.getColor(mainContext, MainActivity.accentSecondaryColor));
                        gradesDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(
                                ContextCompat.getColor(mainContext, MainActivity.accentSecondaryColor));
                    }
                } else {
                    final int databaseFocus = Integer.parseInt(PreferenceManager
                            .getDefaultSharedPreferences(mainContext).getString("pref_grades_term", "1"));

                    if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades",
                            null) != null && yearFocus != 0 || termFocus != databaseFocus) {
                        yearFocus = 0;
                        termFocus = databaseFocus;

                        gradesHtml = PreferenceManager.getDefaultSharedPreferences(mainContext)
                                .getString("html_grades", null);
                        parseData(HeliniumStudentApp.ACTION_OFFLINE);
                    } else {
                        MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_OFFLINE);
                    }
                }
            }
        });

        MainActivity.nextIV.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (MainActivity.isOnline()) {
                    if (termFocus != 4) {
                        termFocus++;

                        getGrades(termFocus, HeliniumStudentApp.df_grades(yearFocus),
                                HeliniumStudentApp.DIREC_NEXT, HeliniumStudentApp.ACTION_REFRESH_IN);
                    } else {
                        MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_ONLINE);
                    }
                } else {
                    final int databaseFocus = Integer.parseInt(PreferenceManager
                            .getDefaultSharedPreferences(mainContext).getString("pref_grades_term", "1"));

                    if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades",
                            null) != null && yearFocus == 0 && termFocus < databaseFocus) {
                        yearFocus = 0;
                        termFocus = databaseFocus;

                        gradesHtml = PreferenceManager.getDefaultSharedPreferences(mainContext)
                                .getString("html_grades", null);
                        parseData(HeliniumStudentApp.ACTION_OFFLINE);
                    } else {
                        MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_OFFLINE);
                    }
                }
            }
        });
    }

    return gradesLayout;
}