Example usage for android.widget NumberPicker getValue

List of usage examples for android.widget NumberPicker getValue

Introduction

In this page you can find the example usage for android.widget NumberPicker getValue.

Prototype

public int getValue() 

Source Link

Document

Returns the value of the picker.

Usage

From source file:hu.fnf.devel.atlas.Atlas.java

public void onMonthSelectOkClick(View v) {
    NumberPicker y = (NumberPicker) v.getRootView().findViewById(R.id.yearpicker);
    NumberPicker m = (NumberPicker) v.getRootView().findViewById(R.id.monthpicker);

    String date = String.valueOf(y.getValue()) + "." + String.valueOf(m.getValue());

    AtlasData.config.edit().putString(AtlasData.CONFIG_DATE, date).commit();
    changeViewLevel(R.layout.category_view, AtlasData.peekPos().page);
    dialog.dismiss();/*w  w w . jav  a 2s  .  co m*/
}

From source file:com.example.google.playservices.placepicker.PlacePickerFragment.java

@Override
public void onCardClick(int cardActionId, String cardTag) {
    if (cardActionId == ACTION_PICK_PLACE) {
        // BEGIN_INCLUDE(intent)
        /* Use the PlacePicker Builder to construct an Intent.
        Note: This sample demonstrates a basic use case.
        The PlacePicker Builder supports additional properties such as search bounds.
         *//*ww w .  j a  va2 s . c o m*/
        try {
            PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
            Intent intent = intentBuilder.build(getActivity());
            // Start the Intent by requesting a result, identified by a request code.
            startActivityForResult(intent, REQUEST_PLACE_PICKER);

            // Hide the pick option in the UI to prevent users from starting the picker
            // multiple times.
            showPickAction(false);

        } catch (GooglePlayServicesRepairableException e) {
            GooglePlayServicesUtil.getErrorDialog(e.getConnectionStatusCode(), getActivity(), 0);
        } catch (GooglePlayServicesNotAvailableException e) {
            Toast.makeText(getActivity(), "Google Play Services is not available.", Toast.LENGTH_LONG).show();
        }

        // END_INCLUDE(intent)
    } else if (cardActionId == ACTION_REPORT_WAIT) {
        final Dialog dialog = new Dialog(this.getActivity());
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.report);

        final NumberPicker np = (NumberPicker) dialog.findViewById(R.id.numpicker);
        np.setMaxValue(120);
        np.setMinValue(0);

        // Report
        Button dialogButtonReport = (Button) dialog.findViewById(R.id.dialogButtonReport);
        dialogButtonReport.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HttpPost httppost = new HttpPost("http://powergrid.xyz/quickq/restaurantpost.php");
                httppost.setHeader("Content-type", "application/x-www-form-urlencoded");
                List<NameValuePair> nameValuePairs = new ArrayList<>(2);
                // TODO
                nameValuePairs.add(new BasicNameValuePair("placeid", globalplace.getId()));
                nameValuePairs.add(new BasicNameValuePair("waittime", String.valueOf(np.getValue())));
                try {
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                } catch (UnsupportedEncodingException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                powergridServerReportTime task = new powergridServerReportTime();
                task.execute(httppost);

                dialog.dismiss();
            }
        });

        // Cancel
        Button dialogButtonCancel = (Button) dialog.findViewById(R.id.dialogButtonCancel);
        // If button is clicked, close the custom dialog
        dialogButtonCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();
    }
}

From source file:com.sean.takeastand.ui.MainActivity.java

private void showPauseSettingsDialog() {
    LayoutInflater inflater = getLayoutInflater();
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    View dialogView = inflater.inflate(R.layout.dialog_pause, null);
    TextView title = new TextView(this);
    title.setPadding(50, 50, 50, 50);/*www  .java 2  s. co m*/
    title.setTextSize(22);
    title.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
    title.setText(getResources().getString(R.string.select_pause_type));
    builder.setCustomTitle(title);
    String[] valueSet = new String[pauseTimes.length];
    for (int i = 0; i < pauseTimes.length; i++) {
        valueSet[i] = Integer.toString(pauseTimes[i]);
    }
    builder.setView(dialogView);
    final NumberPicker npPause = (NumberPicker) dialogView.findViewById(R.id.pauseNumberPicker);
    npPause.setDisplayedValues(valueSet);
    npPause.setMinValue(0);
    npPause.setMaxValue(valueSet.length - 1);
    npPause.setWrapSelectorWheel(false);
    int initialValue = Utils.getDefaultPauseAmount(this);
    for (int i = 0; i < pauseTimes.length; i++) {
        if (initialValue == pauseTimes[i]) {
            initialValue = i;
        }
    }
    npPause.setValue(initialValue);
    builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            //getValue returns the index number, so need to do some math to correct correct
            //actual value
            setDefaultPauseAmount(pauseTimes[npPause.getValue()]);
            int currentStatus = Utils.getImageStatus(MainActivity.this);
            if (currentStatus == Constants.NON_SCHEDULE_ALARM_RUNNING
                    || currentStatus == Constants.NON_SCHEDULE_STOOD_UP
                    || currentStatus == Constants.NON_SCHEDULE_TIME_TO_STAND) {
                pauseUnscheduled();
            } else {
                pauseSchedule();
                sendAnalyticsEvent("Paused");
            }
            dialogInterface.dismiss();
        }
    });
    builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            mPausePlay.setIcon(getResources().getDrawable(R.drawable.ic_action_pause));
        }
    });
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

From source file:com.matthewmitchell.wakeifyplus.MinutesSecondsFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    TableRow.LayoutParams twoLP = new TableRow.LayoutParams(0, 0, 0.2f);
    TableRow.LayoutParams threeLP = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
            TableRow.LayoutParams.WRAP_CONTENT, 0.3f);

    View spacer = new View(activity);
    spacer.setLayoutParams(twoLP);/*from w  w w. jav a 2 s .c o  m*/
    spacer.setVisibility(View.INVISIBLE);

    final NumberPicker minutes = new NumberPicker(activity);
    minutes.setMaxValue(30);
    minutes.setMinValue(0);
    minutes.setValue(defaultMinute);
    minutes.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    LinearLayout minutesLayout = new LinearLayout(activity);
    minutesLayout.addView(minutes);
    minutesLayout.setGravity(Gravity.CENTER);
    minutesLayout.setLayoutParams(threeLP);

    final NumberPicker seconds = new NumberPicker(activity);
    seconds.setMaxValue(59);
    seconds.setMinValue(0);
    seconds.setValue(defaultSecond);
    seconds.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    LinearLayout secondsLayout = new LinearLayout(activity);
    secondsLayout.addView(seconds);
    secondsLayout.setGravity(Gravity.CENTER);
    secondsLayout.setLayoutParams(threeLP);

    LinearLayout layout = new LinearLayout(activity);
    layout.addView(spacer);
    layout.addView(minutesLayout);
    layout.addView(secondsLayout);
    layout.setWeightSum(1.0f);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setMessage("Set Volume Ramping Time").setView(layout)
            .setPositiveButton("Set", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    activity.rampingMinutes = minutes.getValue();
                    activity.rampingSeconds = seconds.getValue();
                    TextView edit = (TextView) activity.findViewById(R.id.volume_ramping);
                    edit.setText(activity.rampingMinutes + "m" + activity.rampingSeconds + "s");
                }

            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // Do nothing.
                }
            });
    // Create the AlertDialog object and return it
    return builder.create();

}

From source file:org.ciasaboark.tacere.activity.fragment.AdvancedSettingsFragment.java

private void drawQuickSilenceWidget() {
    LinearLayout quicksilenceBox = (LinearLayout) rootView
            .findViewById(R.id.advanced_settings_quicksilence_box);
    quicksilenceBox.setOnClickListener(new View.OnClickListener() {
        @Override//from www.ja va  2  s . c  om
        public void onClick(View v) {
            LayoutInflater inflater = LayoutInflater.from(v.getContext());
            View dialogView = inflater.inflate(R.layout.dialog_quicksilent, null);
            final AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(context, R.style.Dialog));
            builder.setTitle(R.string.notification_quicksilence_title);
            builder.setView(dialogView);

            final NumberPicker hourP = (NumberPicker) dialogView.findViewById(R.id.hourPicker);
            final NumberPicker minP = (NumberPicker) dialogView.findViewById(R.id.minutePicker);

            String[] hours = new String[25];
            String[] minutes = new String[59];

            for (int i = 0; i < hours.length; i++) {
                hours[i] = Integer.toString(i);
            }

            int i = 0;
            while (i < minutes.length) {
                minutes[i] = Integer.toString(++i);
            }

            hourP.setMinValue(1);
            hourP.setMaxValue(hours.length - 1);
            hourP.setWrapSelectorWheel(false);
            hourP.setDisplayedValues(hours);
            hourP.setValue(prefs.getQuickSilenceHours() + 1);

            minP.setMinValue(1);
            minP.setMaxValue(minutes.length - 1);
            minP.setWrapSelectorWheel(false);
            minP.setDisplayedValues(minutes);
            minP.setValue(prefs.getQuicksilenceMinutes());

            builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    prefs.setQuickSilenceHours(hourP.getValue() - 1);
                    prefs.setQuicksilenceMinutes(minP.getValue());
                    drawQuickSilenceWidget();
                }
            });

            builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    //do nothing
                }
            });

            AlertDialog dialog = builder.show();
        }
    });

    //the quick silence button
    TextView quickTV = (TextView) rootView.findViewById(R.id.quickSilenceDescription);
    String quicksilenceText = getResources()
            .getString(R.string.advanced_settings_section_interval_quicksilence_duration);
    String hrs = "";
    if (prefs.getQuickSilenceHours() > 0) {
        hrs = String.valueOf(prefs.getQuickSilenceHours()) + " " + getString(R.string.hours_lower) + " ";
    }
    quickTV.setText(String.format(quicksilenceText, hrs, prefs.getQuicksilenceMinutes()));
}

From source file:io.github.data4all.activity.MapViewActivity.java

private void bodyheightdialog() {
    PreferenceManager.setDefaultValues(this, R.xml.settings, false);
    this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
    final SharedPreferences userPrefs = getSharedPreferences("UserPrefs", 0);
    firstUse = userPrefs.getBoolean("firstUse", true);

    if (firstUse) {
        RelativeLayout linearLayout = new RelativeLayout(this);
        final NumberPicker numberPicker = new NumberPicker(this);
        numberPicker.setMaxValue(250);//from   w  w  w.  ja  va 2 s .c om
        numberPicker.setMinValue(80);
        numberPicker.setValue(180);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50, 50);
        RelativeLayout.LayoutParams numPicerParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        numPicerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        linearLayout.setLayoutParams(params);
        linearLayout.addView(numberPicker, numPicerParams);

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setTitle(R.string.pref_bodyheight_dialog_title);
        alertDialogBuilder.setMessage(R.string.pref_bodyheight_dialog_message);
        alertDialogBuilder.setView(linearLayout);
        alertDialogBuilder.setCancelable(false).setPositiveButton(R.string.ok,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Log.d(TAG, "set bodyheight to: " + numberPicker.getValue());
                        prefs.edit().putString("PREF_BODY_HEIGHT", String.valueOf(numberPicker.getValue()))
                                .commit();
                    }
                });
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
        // set firstUse to false so this dialog is not shown again. ever.
        userPrefs.edit().putBoolean("firstUse", false).commit();
        firstUse = false;
    }
}

From source file:butter.droid.base.fragments.dialog.NumberPickerDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    if (getArguments() == null || !getArguments().containsKey(MAX_VALUE)
            || !getArguments().containsKey(MIN_VALUE) || !getArguments().containsKey(TITLE)
            || mOnResultListener == null) {
        return builder.create();
    }/*from   w  w w  .j av a2  s.  c  o  m*/

    final NumberPicker numberPicker = new NumberPicker(getActivity());
    numberPicker.setLayoutParams(new NumberPicker.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    numberPicker.setWrapSelectorWheel(false);

    final int minValue = getArguments().getInt(MIN_VALUE);
    final int maxValue = getArguments().getInt(MAX_VALUE);
    final int currentValue = getArguments().getInt(DEFAULT_VALUE,
            (int) Math.floor((numberPicker.getMaxValue() - numberPicker.getMinValue()) / 2));

    List<String> displayValues = new ArrayList<>();
    for (int i = minValue; i < maxValue + 1; i++) {
        displayValues.add(Integer.toString(i));
    }
    numberPicker.setDisplayedValues(displayValues.toArray(new String[displayValues.size()]));

    if (minValue < 0) {
        numberPicker.setMinValue(0);
        numberPicker.setMaxValue(maxValue + Math.abs(minValue));
        numberPicker.setValue(currentValue + Math.abs(minValue));
    } else {
        numberPicker.setMinValue(minValue);
        numberPicker.setMaxValue(maxValue);
        numberPicker.setValue(currentValue);
    }

    if (getArguments().containsKey(FOCUSABLE) && !getArguments().getBoolean(FOCUSABLE))
        numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    builder.setView(numberPicker).setTitle(getArguments().getString(TITLE))
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mOnResultListener.onNewValue(numberPicker.getValue() + (minValue < 0 ? minValue : 0));
                    dialog.dismiss();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

    return builder.create();
}

From source file:obdii.starter.automotive.iot.ibm.com.iot4a_obdii.Home.java

public void changeFrequency(View view) {
    // called from UI panel
    final AlertDialog.Builder alertDialog = new AlertDialog.Builder(Home.this,
            R.style.AppCompatAlertDialogStyle);
    final View changeFrequencyAlert = getLayoutInflater().inflate(R.layout.activity_home_changefrequency, null,
            false);//ww  w.  j a va 2s.c om

    final NumberPicker numberPicker = (NumberPicker) changeFrequencyAlert.findViewById(R.id.numberPicker);
    final int frequency_sec = getUploadFrequencySec();
    numberPicker.setMinValue(MIN_FREQUENCY_SEC);
    numberPicker.setMaxValue(MAX_FREQUENCY_SEC);
    numberPicker.setValue(frequency_sec);

    alertDialog.setView(changeFrequencyAlert);
    alertDialog.setCancelable(false).setTitle("Change the Frequency of Data Being Sent (in Seconds)")
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int which) {
                    final int value = numberPicker.getValue();
                    if (value != frequency_sec) {
                        setUploadFrequencySec(value);
                        startObdScan();
                        startPublishingProbeData();
                    }
                }
            }).setNegativeButton("Cancel", null).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  ww .j a v  a 2 s  .c  om*/

        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;
}

From source file:com.untie.daywal.activity.MainActivity.java

private void showDayPicker() {

    Calendar calender = Calendar.getInstance();
    pickedYear = calender.get(Calendar.YEAR);
    pickedMonth = calender.get(Calendar.MONTH) + 1;
    final Dialog dayPickerDialog = new Dialog(this);
    dayPickerDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dayPickerDialog.setContentView(R.layout.dialog);
    Button okBtn = (Button) dayPickerDialog.findViewById(R.id.birthday_btn_ok);
    Button cancelBtn = (Button) dayPickerDialog.findViewById(R.id.birthday_btn_cancel);
    dialog_year_title = (TextView) dayPickerDialog.findViewById(R.id.dialog_year_title);
    dialog_month_title = (TextView) dayPickerDialog.findViewById(R.id.dialog_month_title);
    final NumberPicker yearPicker = (NumberPicker) dayPickerDialog.findViewById(R.id.yearPicker);
    final NumberPicker monthPicker = (NumberPicker) dayPickerDialog.findViewById(R.id.monthPicker);

    dialog_year_title.setText(String.valueOf(pickedYear) + "");
    dialog_month_title.setText(String.valueOf(pickedMonth) + "");
    yearPicker.setMinValue(pickedYear - 100);
    yearPicker.setMaxValue(pickedYear + 40);
    yearPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    //   setDividerColor(yearPicker, android.R.color.white );
    yearPicker.setWrapSelectorWheel(false);
    yearPicker.setValue(pickedYear);/* w w  w.  j a va2  s. com*/
    yearPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            dialog_year_title.setText(String.valueOf(newVal) + "");
        }
    });

    monthPicker.setMinValue(1);
    monthPicker.setMaxValue(12);
    monthPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    //   setDividerColor(monthPicker, android.R.color.white);
    //monthPicker.setWrapSelectorWheel(false);
    monthPicker.setValue(pickedMonth);
    monthPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            dialog_month_title.setText(String.valueOf(newVal) + "");
        }
    });

    okBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //TODO :  ?? yearPicker.getValue() monthPicker.getValue()

            //Toast.makeText(MainActivity.this, String.valueOf(yearPicker.getValue())+"/"+monthPicker.getValue(), Toast.LENGTH_SHORT).show();

            Intent intent = new Intent(MainActivity.this, MainActivity.class);
            intent.putExtra("year", yearPicker.getValue());
            intent.putExtra("month", monthPicker.getValue());
            intent.putExtra("order", 1);
            dayPickerDialog.dismiss();
            startActivity(intent);
            overridePendingTransition(0, 0);

        }
    });
    cancelBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dayPickerDialog.dismiss();
        }
    });
    dayPickerDialog.show();

}