Example usage for android.widget DatePicker setMaxDate

List of usage examples for android.widget DatePicker setMaxDate

Introduction

In this page you can find the example usage for android.widget DatePicker setMaxDate.

Prototype

public void setMaxDate(long maxDate) 

Source Link

Document

Sets the maximal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in TimeZone#getDefault() time zone.

Usage

From source file:org.gnucash.android.ui.chart.ChartDatePickerFragment.java

/**
 * {@inheritDoc}/*from   w  w  w . jav  a 2s .  c  o  m*/
 */
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    DatePickerDialog dialog = new DatePickerDialog(getActivity(), callback, mCalendar.get(Calendar.YEAR),
            mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));

    try {
        Field datePickerField = dialog.getClass().getDeclaredField("mDatePicker");
        datePickerField.setAccessible(true);
        DatePicker datePicker = (DatePicker) datePickerField.get(dialog);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            datePicker.setMinDate(minDate);
            datePicker.setMaxDate(maxDate);
        }

        for (Field field : datePicker.getClass().getDeclaredFields()) {
            if (field.getName().equals("mDaySpinner") || field.getName().equals("mDayPicker")) {
                field.setAccessible(true);
                ((View) field.get(datePicker)).setVisibility(View.GONE);
            }
        }
    } catch (Exception e) {
        Log.w(TAG, e.getMessage());
    }

    return dialog;
}

From source file:rta.ae.sharekni.RegisterVehicle.java

@Override
protected Dialog onCreateDialog(int id) {
    if (id == DILOG_ID) {
        DatePickerDialog dp = new DatePickerDialog(this, dPickerListener, year_x, month_x, day_x);
        DatePicker d = dp.getDatePicker();
        d.setMaxDate(cal.getTimeInMillis());
        return dp;
    }/*from  ww  w.j av a2s  . co m*/
    return null;
}

From source file:com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment.java

/**
 * {@inheritDoc}/*w w w.  ja v  a  2 s .  c o  m*/
 *
 * @return A new dialog to let the user choose an expiration date that will be bound to a share link.
 */
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // Chosen date received as an argument must be later than tomorrow ; default to tomorrow in other case
    final Calendar chosenDate = Calendar.getInstance();
    long tomorrowInMillis = chosenDate.getTimeInMillis() + DateUtils.DAY_IN_MILLIS;
    long chosenDateInMillis = getArguments().getLong(ARG_CHOSEN_DATE_IN_MILLIS);
    long maxDateInMillis = getArguments().getLong(ARG_MAX_DATE_IN_MILLIS);

    if (chosenDateInMillis < tomorrowInMillis) {
        chosenDateInMillis = tomorrowInMillis;
    }
    chosenDate.setTimeInMillis(chosenDateInMillis);

    // Create a new instance of DatePickerDialog
    DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, chosenDate.get(Calendar.YEAR),
            chosenDate.get(Calendar.MONTH), chosenDate.get(Calendar.DAY_OF_MONTH));

    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.share_cancel_public_link_button),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    if (which == DialogInterface.BUTTON_NEGATIVE) {
                        // Do Stuff
                        notifyDatePickerListener(null);
                    }
                }
            });

    // Prevent days in the past may be chosen
    DatePicker picker = dialog.getDatePicker();
    if (maxDateInMillis >= chosenDateInMillis) {
        // the extra second (+1000) is required to prevent a bug of DatePicker that shows
        // an extra header with the selected date if maxDateInMillis == chosenDateInMillis
        picker.setMaxDate(maxDateInMillis + 1000);
    }
    picker.setMinDate(tomorrowInMillis - 1000);

    // Enforce spinners view; ignored by MD-based theme in Android >=5, but calendar is REALLY buggy
    // in Android < 5, so let's be sure it never appears (in tablets both spinners and calendar are
    // shown by default)
    picker.setCalendarViewShown(false);

    return dialog;
}

From source file:com.facebook.react.modules.datepicker.DatePickerDialogFragment.java

static Dialog createDialog(Bundle args, Context activityContext,
        @Nullable OnDateSetListener onDateSetListener) {
    final Calendar c = Calendar.getInstance();
    if (args != null && args.containsKey(DatePickerDialogModule.ARG_DATE)) {
        c.setTimeInMillis(args.getLong(DatePickerDialogModule.ARG_DATE));
    }// ww  w. j ava  2  s  .c om
    final int year = c.get(Calendar.YEAR);
    final int month = c.get(Calendar.MONTH);
    final int day = c.get(Calendar.DAY_OF_MONTH);

    DatePickerMode mode = DatePickerMode.DEFAULT;
    if (args != null && args.getString(DatePickerDialogModule.ARG_MODE, null) != null) {
        mode = DatePickerMode.valueOf(args.getString(DatePickerDialogModule.ARG_MODE).toUpperCase(Locale.US));
    }

    DatePickerDialog dialog = null;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        switch (mode) {
        case CALENDAR:
            dialog = new DismissableDatePickerDialog(activityContext, activityContext.getResources()
                    .getIdentifier("CalendarDatePickerDialog", "style", activityContext.getPackageName()),
                    onDateSetListener, year, month, day);
            break;
        case SPINNER:
            dialog = new DismissableDatePickerDialog(activityContext, activityContext.getResources()
                    .getIdentifier("SpinnerDatePickerDialog", "style", activityContext.getPackageName()),
                    onDateSetListener, year, month, day);
            break;
        case DEFAULT:
            dialog = new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day);
            break;
        }
    } else {
        dialog = new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day);

        switch (mode) {
        case CALENDAR:
            dialog.getDatePicker().setCalendarViewShown(true);
            dialog.getDatePicker().setSpinnersShown(false);
            break;
        case SPINNER:
            dialog.getDatePicker().setCalendarViewShown(false);
            break;
        }
    }

    final DatePicker datePicker = dialog.getDatePicker();

    if (args != null && args.containsKey(DatePickerDialogModule.ARG_MINDATE)) {
        // Set minDate to the beginning of the day. We need this because of clowniness in datepicker
        // that causes it to throw an exception if minDate is greater than the internal timestamp
        // that it generates from the y/m/d passed in the constructor.
        c.setTimeInMillis(args.getLong(DatePickerDialogModule.ARG_MINDATE));
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        datePicker.setMinDate(c.getTimeInMillis());
    } else {
        // This is to work around a bug in DatePickerDialog where it doesn't display a title showing
        // the date under certain conditions.
        datePicker.setMinDate(DEFAULT_MIN_DATE);
    }
    if (args != null && args.containsKey(DatePickerDialogModule.ARG_MAXDATE)) {
        // Set maxDate to the end of the day, same reason as for minDate.
        c.setTimeInMillis(args.getLong(DatePickerDialogModule.ARG_MAXDATE));
        c.set(Calendar.HOUR_OF_DAY, 23);
        c.set(Calendar.MINUTE, 59);
        c.set(Calendar.SECOND, 59);
        c.set(Calendar.MILLISECOND, 999);
        datePicker.setMaxDate(c.getTimeInMillis());
    }

    return dialog;
}

From source file:com.nanostuffs.yurdriver.fragment.RegisterFragment.java

private void datepicker() {

    final Dialog dialog = new Dialog(getActivity());
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(true);
    dialog.setContentView(R.layout.datepicker_layout);
    final DatePicker date = (DatePicker) dialog.findViewById(R.id.datePicker1);
    final Calendar c = Calendar.getInstance();
    c.add(Calendar.DAY_OF_YEAR, -1 * (16 * 365));
    date.setMaxDate(c.getTimeInMillis());

    Button text = (Button) dialog.findViewById(R.id.ok);
    text.setOnClickListener(new OnClickListener() {
        @Override//from   ww w . ja v  a  2 s . c om
        public void onClick(View v) {
            v.bringToFront();

            String dateString = String
                    .valueOf(date.getYear() + "-" + (date.getMonth() + 1) + "-" + date.getDayOfMonth());
            etDOB.setText(dateString);

            dialog.dismiss();
        }
    });
    Button cancel = (Button) dialog.findViewById(R.id.cancel);
    cancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            v.bringToFront();
            dialog.dismiss();
        }
    });
    dialog.show();

}

From source file:com.instiwork.RegistrationFacebookActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registration_facebook);

    pDialogOut = new ProgressDialog(RegistrationFacebookActivity.this);
    pDialogOut.setMessage("Signing up...");

    appSharedPref = getSharedPreferences("INSTIWORD", Context.MODE_PRIVATE);

    Picasso.with(getApplicationContext()).load(R.drawable.registrationbg).fit().centerCrop()
            .into((ImageView) findViewById(R.id.regbg));

    dateOfBirth = (TextView) findViewById(R.id.dateofbirth);
    license = (RobotoLight) findViewById(R.id.license);
    ll_license = (LinearLayout) findViewById(R.id.ll_license);
    selecteddata = (RecyclerView) findViewById(R.id.selecteddat);
    selecteddata.setVisibility(View.GONE);
    gender = (RadioGroup) findViewById(R.id.gender_group);
    maleRadio = (RadioButton) findViewById(R.id.malehit);
    femaleRadio = (RadioButton) findViewById(R.id.frmalrhit);
    fstName = (EditText) findViewById(R.id.first_name);
    companyName = (EditText) findViewById(R.id.company_name);
    email = (EditText) findViewById(R.id.email);
    mobile = (EditText) findViewById(R.id.mobile);

    countryPbar = (ProgressBar) findViewById(R.id.countryPbar);
    country_spinner = (Spinner) findViewById(R.id.country_spinner);
    countryPbar.setVisibility(View.VISIBLE);
    country_spinner.setVisibility(View.GONE);
    txt_terms_conditions = (RobotoBold) findViewById(R.id.txt_terms_conditions);

    ll_image_selection = (LinearLayout) findViewById(R.id.ll_image_selection);
    pro_img = (ImageView) findViewById(R.id.pro_img);

    ll_image_selection.setOnClickListener(new View.OnClickListener() {
        @Override/*w  w w .  jav  a  2s . com*/
        public void onClick(View v) {
            Intent i = new Intent(RegistrationFacebookActivity.this, ImageTakerActivityCamera.class);
            startActivityForResult(i, 1);
        }
    });

    try {

        if (getIntent().getStringExtra("FB_NAME").equalsIgnoreCase("")) {
            fstName.setText("");
            fstName.setClickable(true);
            fstName.setEnabled(true);
        } else {
            fstName.setText(getIntent().getStringExtra("FB_NAME"));
            fstName.setClickable(false);
            fstName.setEnabled(false);
        }
        if (getIntent().getStringExtra("FB_EMAIL").equalsIgnoreCase("")) {
            email.setText("");
            email.setClickable(true);
            email.setEnabled(true);
        } else {
            email.setText(getIntent().getStringExtra("FB_EMAIL"));
            email.setClickable(false);
            email.setEnabled(false);
        }
        //            if (getIntent().getStringExtra("FB_BIRTHDAY").equalsIgnoreCase("")) {
        //                dateOfBirth.setText(dob);
        //                dateOfBirth.setClickable(true);
        //            } else {
        //                dateOfBirth.setText(getIntent().getStringExtra("FB_BIRTHDAY"));
        //                dateOfBirth.setClickable(false);
        //            }
        if (getIntent().getStringExtra("FB_GENDER").equalsIgnoreCase("")) {
            gender.setClickable(true);
            maleRadio.setClickable(true);
            femaleRadio.setClickable(true);
        } else {
            gender.setClickable(false);
            maleRadio.setClickable(false);
            femaleRadio.setClickable(false);
            if (getIntent().getStringExtra("FB_GENDER").equalsIgnoreCase("male")) {
                genderData = "" + 1;
                maleRadio.setChecked(true);
                femaleRadio.setChecked(false);
            } else if (getIntent().getStringExtra("FB_GENDER").equalsIgnoreCase("female")) {
                genderData = "" + 2;
                maleRadio.setChecked(false);
                femaleRadio.setChecked(true);
            }
        }
        if (getIntent().getStringExtra("FB_IMG").equalsIgnoreCase("")) {
            ll_image_selection.setClickable(true);
        } else {
            ll_image_selection.setClickable(false);
            imgPath = getIntent().getStringExtra("FB_IMG");
            Picasso.with(RegistrationFacebookActivity.this).load(getIntent().getStringExtra("FB_IMG"))
                    .transform(new CornerMoldTransformation(24, 0, CornerMoldTransformation.CornerType.ALL))
                    .fit().centerCrop().placeholder(R.mipmap.ic_launcher).fit().centerCrop().into(pro_img);
        }

    } catch (Exception e) {
        Logger.showMessage(TAG, "Data Exception : " + e.toString());
    }

    txt_terms_conditions.setText(Html.fromHtml("<u>Terms and Condition</u>"));
    txt_terms_conditions.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dialogTermsUse();
        }
    });

    findViewById(R.id.help_dob).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder(
                    RegistrationFacebookActivity.this);
            alertDialogBuilder.setTitle("Date of Birth");
            alertDialogBuilder
                    .setMessage("We require date of birth to verify that no minors are bidding on the jobs.")
                    .setCancelable(false).setPositiveButton("ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });
            android.app.AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    });

    findViewById(R.id.help_license).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder(
                    RegistrationFacebookActivity.this);
            alertDialogBuilder.setTitle("License");
            alertDialogBuilder
                    .setMessage("Please select if you have any work licenses like electrician, plumber, etc...")
                    .setCancelable(false).setPositiveButton("ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });
            android.app.AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    });

    country_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            try {
                country_2_code = objectsCountry.get(position).getString("country_2_code");
                country_id = objectsCountry.get(position).getString("country_id");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    ll_license.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(RegistrationFacebookActivity.this, LicenseActivity.class);
            startActivityForResult(i, 420);
        }
    });

    dateOfBirth.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            Calendar today = Calendar.getInstance();
            //                today.add(Calendar.YEAR, -14);

            View dialoglayout = LayoutInflater.from(getApplicationContext())
                    .inflate(R.layout.dialog_date_picker, null);
            final DatePicker dPicker = (DatePicker) dialoglayout.findViewById(R.id.date_picker);

            dPicker.setMaxDate(today.getTimeInMillis()); // set DatePicker MAX Date
            today.set(dPicker.getYear(), dPicker.getMonth() + 1, dPicker.getDayOfMonth());
            today.add(Calendar.YEAR, -14);
            dPicker.updateDate(today.get(Calendar.YEAR), today.get(Calendar.MONTH) - 1,
                    today.get(Calendar.DATE));

            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationFacebookActivity.this);
            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    //                        dateOfBirth.setText("" + dPicker.getDayOfMonth() + "/" + (dPicker.getMonth() + 1) + "/" + dPicker.getYear());
                    try {
                        SimpleDateFormat changeFormat = new SimpleDateFormat("MM/dd/yyyy");
                        Calendar newDate = Calendar.getInstance();
                        newDate.set(dPicker.getYear(), dPicker.getMonth(), dPicker.getDayOfMonth());
                        dateOfBirth.setText(changeFormat.format(newDate.getTime()));
                        Logger.showMessage("DOBBBBB : ", changeFormat.format(newDate.getTime()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int id) {
                    dateOfBirth.setText(dob);
                }
            });
            builder.setView(dialoglayout);
            builder.show();
        }
    });

    gender.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            int selectedId = gender.getCheckedRadioButtonId();
            if (selectedId == maleRadio.getId()) {
                genderData = "" + 1;
            } else if (selectedId == femaleRadio.getId()) {
                genderData = "" + 2;
            } else {
                genderData = "";
            }

        }
    });

    findViewById(R.id.loginBttn).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            license_ = "";
            if (fstName.getText().toString().trim().equalsIgnoreCase("")) {
                fstName.setError("Please enter name.");
                fstName.requestFocus();
            } else {
                if (email.getText().toString().trim().equalsIgnoreCase("")) {
                    email.setError("Please enter email.");
                    email.requestFocus();
                } else {
                    if (android.util.Patterns.EMAIL_ADDRESS.matcher(email.getText().toString().trim())
                            .matches()) {
                        if (!android.util.Patterns.PHONE.matcher(mobile.getText().toString().trim())
                                .matches()) {
                            mobile.setError("Please enter valid mobile number.");
                            mobile.requestFocus();
                        } else {
                            if (dateOfBirth.getText().toString().trim().equalsIgnoreCase("Birth date")) {
                                Snackbar.make(findViewById(android.R.id.content), "Please select date of birth",
                                        Snackbar.LENGTH_LONG).setActionTextColor(Color.RED).show();
                            } else {
                                if (isValidDOB(dateOfBirth.getText().toString().trim())) {
                                    if (country_2_code.equalsIgnoreCase("0")) {
                                        Snackbar.make(findViewById(android.R.id.content),
                                                "Select Country From List", Snackbar.LENGTH_LONG)
                                                .setActionTextColor(Color.RED).show();
                                    } else {
                                        if (InstiworkApplication.getInstance()
                                                .getSelectedLicenseArray() != null) {
                                            for (int i = 0; i < InstiworkApplication.getInstance()
                                                    .getSelectedLicenseArray().size(); i++) {
                                                try {
                                                    if (i == 0) {
                                                        license_ = license_ + InstiworkApplication.getInstance()
                                                                .getSelectedLicenseArray().get(i)
                                                                .getString("id");
                                                    } else {
                                                        license_ = license_ + ","
                                                                + InstiworkApplication.getInstance()
                                                                        .getSelectedLicenseArray().get(i)
                                                                        .getString("id");
                                                    }
                                                } catch (Exception e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                        }
                                        if (((CheckBox) findViewById(R.id.trmscondi)).isChecked()) {
                                            try {
                                                gcmToken = appSharedPref.getString("GCM_TOKEN", "");
                                                String date[] = dateOfBirth.getText().toString().trim()
                                                        .split("/");

                                                final String URL = InstiworkConstants.URL_DOMAIN
                                                        + "Login_ios/facebooksignup?name="
                                                        + URLEncoder.encode(
                                                                fstName.getText().toString().trim(), "UTF-8")
                                                        + "&companyname="
                                                        + URLEncoder.encode(
                                                                companyName.getText().toString().trim(),
                                                                "UTF-8")
                                                        + "&email="
                                                        + URLEncoder.encode(email.getText().toString().trim(),
                                                                "UTF-8")
                                                        + "&gender=" + genderData + "&year=" + date[2]
                                                        + "&month=" + date[0] + "&date=" + date[1] + "&license="
                                                        + license_ + "&facebook_id="
                                                        + getIntent().getStringExtra("FB_ID")
                                                        + "&facebook_token="
                                                        + getIntent().getStringExtra("FB_ACCESS_TOKEN")
                                                        + "&devicetoken="
                                                        + getIntent().getStringExtra("FB_DEVICE_TOKEN")
                                                        + "&devicetype=2" + "&contact="
                                                        + URLEncoder.encode(mobile.getText().toString().trim(),
                                                                "UTF-8")
                                                        + "&image=" + getIntent().getStringExtra("FB_IMG")
                                                        + "&lat=" + LOCATION_LATITUDE + "&lng="
                                                        + LOCATION_LONGITUDE + "&country2_code="
                                                        + country_2_code + "&country_id=" + country_id;
                                                Logger.showMessage(TAG, "FBREG  " + URL);

                                                pDialogOut.show();

                                                txt_terms_conditions.setClickable(false);
                                                findViewById(R.id.help_dob).setClickable(false);
                                                findViewById(R.id.help_license).setClickable(false);
                                                ll_license.setClickable(false);
                                                dateOfBirth.setClickable(false);
                                                findViewById(R.id.footer).setClickable(false);
                                                findViewById(R.id.loginBttn).setClickable(false);

                                                txt_terms_conditions.setEnabled(false);
                                                findViewById(R.id.help_dob).setEnabled(false);
                                                findViewById(R.id.help_license).setEnabled(false);
                                                ll_license.setEnabled(false);
                                                dateOfBirth.setEnabled(false);
                                                findViewById(R.id.footer).setEnabled(false);
                                                findViewById(R.id.loginBttn).setEnabled(false);

                                                login_User(URL);
                                            } catch (Exception e) {
                                                e.printStackTrace();
                                            }
                                        } else {
                                            Snackbar.make(findViewById(android.R.id.content),
                                                    "Please agree to Terms And Conditions.",
                                                    Snackbar.LENGTH_LONG).setActionTextColor(Color.RED).show();
                                        }
                                    }
                                } else {
                                    Snackbar.make(findViewById(android.R.id.content),
                                            "You are under 14 years old.", Snackbar.LENGTH_LONG)
                                            .setActionTextColor(Color.RED).show();
                                }
                            }
                        }
                    } else {
                        email.setError("Please enter valid email.");
                        email.requestFocus();
                    }
                }
            }
        }
    });

    findViewById(R.id.footer).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    buildGoogleApiClient();
    if (gMapOption == null) {
        gMapOption = new GoogleMapOptions();
        gMapOption.ambientEnabled(true);
        gMapOption.compassEnabled(true);
    }
}

From source file:com.instiwork.RegistrationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registration);
    callbackManager = CallbackManager.Factory.create();

    pDialogOut = new ProgressDialog(RegistrationActivity.this);
    pDialogOut.setMessage("Signing up...");
    pDialogOut.setCancelable(false);//  w  ww  .  jav  a 2  s  .c o m
    pDialogOut.setCanceledOnTouchOutside(false);

    appSharedPref = getSharedPreferences("INSTIWORD", Context.MODE_PRIVATE);

    Picasso.with(getApplicationContext()).load(R.drawable.registrationbg).fit().centerCrop()
            .into((ImageView) findViewById(R.id.regbg));

    dateOfBirth = (TextView) findViewById(R.id.dateofbirth);
    license = (RobotoLight) findViewById(R.id.license);
    ll_license = (LinearLayout) findViewById(R.id.ll_license);
    selecteddata = (RecyclerView) findViewById(R.id.selecteddat);
    selecteddata.setVisibility(View.GONE);
    gender = (RadioGroup) findViewById(R.id.gender_group);

    fstName = (EditText) findViewById(R.id.first_name);
    lastname = (EditText) findViewById(R.id.last_name);
    email = (EditText) findViewById(R.id.email);
    email_confirm = (EditText) findViewById(R.id.email_confirm);
    password = (EditText) findViewById(R.id.password);
    conformPassword = (EditText) findViewById(R.id.con_password);
    mobile = (EditText) findViewById(R.id.mobile);

    ll_image_selection = (LinearLayout) findViewById(R.id.ll_image_selection);
    pro_img = (ImageView) findViewById(R.id.pro_img);

    countryPbar = (ProgressBar) findViewById(R.id.countryPbar);
    country_spinner = (Spinner) findViewById(R.id.country_spinner);
    countryPbar.setVisibility(View.VISIBLE);
    country_spinner.setVisibility(View.GONE);

    txt_terms_conditions = (RobotoBold) findViewById(R.id.txt_terms_conditions);

    country_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            try {
                country_2_code = objectsCountry.get(position).getString("country_2_code");
                country_id = objectsCountry.get(position).getString("country_id");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    ll_image_selection.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(RegistrationActivity.this, ImageTakerActivityCamera.class);
            startActivityForResult(i, 1);
        }
    });

    txt_terms_conditions.setText(Html.fromHtml("<u>Terms and Condition</u>"));
    txt_terms_conditions.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            dialogTermsUse();
        }
    });

    findViewById(R.id.footer).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    findViewById(R.id.help_password).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder(
                    RegistrationActivity.this);
            alertDialogBuilder.setTitle("Password Requirements");
            alertDialogBuilder.setMessage(
                    "Please Ensure that Password should have at least 6 characters (Maximum 20) long and it contains at least one lowercase letter, one uppercase letter, one number and one special character.")
                    .setCancelable(false).setPositiveButton("ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });
            android.app.AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    });

    findViewById(R.id.help_dob).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder(
                    RegistrationActivity.this);
            alertDialogBuilder.setTitle("Date of Birth");
            alertDialogBuilder
                    .setMessage("We require date of birth to verify that no minors are bidding on the jobs.")
                    .setCancelable(false).setPositiveButton("ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });
            android.app.AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    });
    findViewById(R.id.help_license).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder(
                    RegistrationActivity.this);
            alertDialogBuilder.setTitle("License");
            alertDialogBuilder
                    .setMessage("Please select if you have any work licenses like electrician, plumber, etc...")
                    .setCancelable(false).setPositiveButton("ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });
            android.app.AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    });

    gender.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            //Logger.showMessage("Geder : ", "" + checkedId);
            if (("" + checkedId).equalsIgnoreCase("2131558563")) {//female
                genderData = "" + 2;
            } else {
                genderData = "" + 1;
            }
        }
    });

    ll_license.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(RegistrationActivity.this, LicenseActivity.class);
            startActivityForResult(i, 420);
        }
    });

    findViewById(R.id.loginBttn).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            license_ = "";
            if (fstName.getText().toString().trim().equalsIgnoreCase("")) {
                fstName.setError("Please enter name.");
                fstName.requestFocus();
            } else {
                if (email.getText().toString().trim().equalsIgnoreCase("")) {
                    email.setError("Please enter email.");
                    email.requestFocus();
                } else {
                    if (android.util.Patterns.EMAIL_ADDRESS.matcher(email.getText().toString().trim())
                            .matches()) {
                        if (email_confirm.getText().toString().trim().equalsIgnoreCase("")) {
                            email_confirm.setError("Please enter email again.");
                            email_confirm.requestFocus();
                        } else {
                            if (android.util.Patterns.EMAIL_ADDRESS
                                    .matcher(email_confirm.getText().toString().trim()).matches()) {
                                if (email.getText().toString().trim()
                                        .equalsIgnoreCase(email_confirm.getText().toString().trim())) {
                                    if (!android.util.Patterns.PHONE.matcher(mobile.getText().toString().trim())
                                            .matches()) {
                                        mobile.setError("Please enter valid mobile number.");
                                        mobile.requestFocus();
                                    } else {
                                        //                                            if (password.getText().toString().trim().equalsIgnoreCase("")) {
                                        if (!isValidPassword(password.getText().toString().trim())) {
                                            password.setError(
                                                    "Please Ensure that Password should have at least 6 characters (Maximum 20) long and it contains at least one lowercase letter, one uppercase letter, one number and one special character.");
                                            password.requestFocus();
                                        } else {
                                            if (conformPassword.getText().toString().trim()
                                                    .equalsIgnoreCase("")) {
                                                conformPassword.setError("Please enter password again.");
                                                conformPassword.requestFocus();
                                            } else {
                                                if (conformPassword.getText().toString().trim()
                                                        .equals(password.getText().toString().trim())) {
                                                    if (dateOfBirth.getText().toString().trim()
                                                            .equalsIgnoreCase("Birth date")) {
                                                        Snackbar.make(findViewById(android.R.id.content),
                                                                "Please select date of birth",
                                                                Snackbar.LENGTH_LONG)
                                                                .setActionTextColor(Color.RED).show();
                                                    } else {
                                                        if (isValidDOB(
                                                                dateOfBirth.getText().toString().trim())) {
                                                            if (country_2_code.equalsIgnoreCase("0")) {
                                                                Snackbar.make(
                                                                        findViewById(android.R.id.content),
                                                                        "Select Country From List",
                                                                        Snackbar.LENGTH_LONG)
                                                                        .setActionTextColor(Color.RED).show();
                                                            } else {
                                                                if (InstiworkApplication.getInstance()
                                                                        .getSelectedLicenseArray() != null) {
                                                                    for (int i = 0; i < InstiworkApplication
                                                                            .getInstance()
                                                                            .getSelectedLicenseArray()
                                                                            .size(); i++) {
                                                                        try {
                                                                            if (i == 0) {
                                                                                license_ = license_
                                                                                        + InstiworkApplication
                                                                                                .getInstance()
                                                                                                .getSelectedLicenseArray()
                                                                                                .get(i)
                                                                                                .getString(
                                                                                                        "id");
                                                                            } else {
                                                                                license_ = license_ + ","
                                                                                        + InstiworkApplication
                                                                                                .getInstance()
                                                                                                .getSelectedLicenseArray()
                                                                                                .get(i)
                                                                                                .getString(
                                                                                                        "id");
                                                                            }
                                                                        } catch (Exception e) {
                                                                            e.printStackTrace();
                                                                        }
                                                                    }
                                                                }
                                                                if (((CheckBox) findViewById(R.id.trmscondi))
                                                                        .isChecked()) {

                                                                    ll_image_selection.setEnabled(false);
                                                                    txt_terms_conditions.setEnabled(false);
                                                                    findViewById(R.id.footer).setEnabled(false);
                                                                    findViewById(R.id.help_password)
                                                                            .setEnabled(false);
                                                                    findViewById(R.id.help_dob)
                                                                            .setEnabled(false);
                                                                    findViewById(R.id.help_license)
                                                                            .setEnabled(false);

                                                                    ll_license.setEnabled(false);
                                                                    findViewById(R.id.loginBttn)
                                                                            .setEnabled(false);
                                                                    findViewById(R.id.fb_log).setEnabled(false);
                                                                    dateOfBirth.setEnabled(false);
                                                                    ll_image_selection.setClickable(false);
                                                                    txt_terms_conditions.setClickable(false);
                                                                    findViewById(R.id.footer)
                                                                            .setClickable(false);
                                                                    findViewById(R.id.help_password)
                                                                            .setClickable(false);
                                                                    findViewById(R.id.help_dob)
                                                                            .setClickable(false);
                                                                    findViewById(R.id.help_license)
                                                                            .setClickable(false);

                                                                    ll_license.setClickable(false);
                                                                    findViewById(R.id.loginBttn)
                                                                            .setClickable(false);
                                                                    findViewById(R.id.fb_log)
                                                                            .setClickable(false);
                                                                    dateOfBirth.setClickable(false);

                                                                    try {
                                                                        if (appSharedPref
                                                                                .getString("GCM_TOKEN", "")
                                                                                .equalsIgnoreCase("")) {
                                                                            String date[] = dateOfBirth
                                                                                    .getText().toString().trim()
                                                                                    .split("/");
                                                                            final String URL = InstiworkConstants.URL_DOMAIN
                                                                                    + "Signup_ios?name="
                                                                                    + URLEncoder.encode(
                                                                                            fstName.getText()
                                                                                                    .toString()
                                                                                                    .trim(),
                                                                                            "UTF-8")
                                                                                    + "&contact="
                                                                                    + URLEncoder.encode(
                                                                                            mobile.getText()
                                                                                                    .toString()
                                                                                                    .trim(),
                                                                                            "UTF-8")
                                                                                    + "&companyname="
                                                                                    + URLEncoder.encode(
                                                                                            lastname.getText()
                                                                                                    .toString()
                                                                                                    .trim(),
                                                                                            "UTF-8")
                                                                                    + "&email="
                                                                                    + URLEncoder.encode(
                                                                                            email.getText()
                                                                                                    .toString()
                                                                                                    .trim(),
                                                                                            "UTF-8")
                                                                                    + "&password="
                                                                                    + URLEncoder.encode(
                                                                                            password.getText()
                                                                                                    .toString()
                                                                                                    .trim(),
                                                                                            "UTF-8")
                                                                                    + "&gender=" + genderData
                                                                                    + "&year=" + date[2]
                                                                                    + "&month=" + date[0]
                                                                                    + "&date=" + date[1]
                                                                                    + "&license="
                                                                                    + URLEncoder.encode(
                                                                                            license_, "UTF-8")
                                                                                    + "&device_type=2" + "&lat="
                                                                                    + LOCATION_LATITUDE
                                                                                    + "&lng="
                                                                                    + LOCATION_LONGITUDE
                                                                                    + "&country2_code="
                                                                                    + country_2_code
                                                                                    + "&country_id="
                                                                                    + country_id
                                                                                    + "&device_token=";
                                                                            (new RegistrationGCM(URL))
                                                                                    .executeOnExecutor(
                                                                                            AsyncTask.THREAD_POOL_EXECUTOR);
                                                                        } else {
                                                                            gcmToken = appSharedPref
                                                                                    .getString("GCM_TOKEN", "");
                                                                            String date[] = dateOfBirth
                                                                                    .getText().toString().trim()
                                                                                    .split("/");
                                                                            final String URL = InstiworkConstants.URL_DOMAIN
                                                                                    + "Signup_ios?name="
                                                                                    + URLEncoder.encode(
                                                                                            fstName.getText()
                                                                                                    .toString()
                                                                                                    .trim(),
                                                                                            "UTF-8")
                                                                                    + "&contact="
                                                                                    + URLEncoder.encode(
                                                                                            mobile.getText()
                                                                                                    .toString()
                                                                                                    .trim(),
                                                                                            "UTF-8")
                                                                                    + "&companyname="
                                                                                    + URLEncoder.encode(
                                                                                            lastname.getText()
                                                                                                    .toString()
                                                                                                    .trim(),
                                                                                            "UTF-8")
                                                                                    + "&email="
                                                                                    + URLEncoder.encode(
                                                                                            email.getText()
                                                                                                    .toString()
                                                                                                    .trim(),
                                                                                            "UTF-8")
                                                                                    + "&password="
                                                                                    + URLEncoder.encode(
                                                                                            password.getText()
                                                                                                    .toString()
                                                                                                    .trim(),
                                                                                            "UTF-8")
                                                                                    + "&gender=" + genderData
                                                                                    + "&year=" + date[2]
                                                                                    + "&month=" + date[0]
                                                                                    + "&date=" + date[1]
                                                                                    + "&license=" + license_
                                                                                    + "&device_type=2&device_token="
                                                                                    + URLEncoder.encode(
                                                                                            gcmToken, "UTF-8")
                                                                                    + "&lat="
                                                                                    + LOCATION_LATITUDE
                                                                                    + "&lng="
                                                                                    + LOCATION_LONGITUDE
                                                                                    + "&country2_code="
                                                                                    + country_2_code
                                                                                    + "&country_id="
                                                                                    + country_id;
                                                                            //
                                                                            login_User(URL);
                                                                        }
                                                                    } catch (Exception e) {
                                                                        e.printStackTrace();
                                                                    }
                                                                } else {
                                                                    Snackbar.make(
                                                                            findViewById(android.R.id.content),
                                                                            "Please agree to Terms And Conditions.",
                                                                            Snackbar.LENGTH_LONG)
                                                                            .setActionTextColor(Color.RED)
                                                                            .show();
                                                                }
                                                            }
                                                        } else {
                                                            Snackbar.make(findViewById(android.R.id.content),
                                                                    "You are under 14 years old.",
                                                                    Snackbar.LENGTH_LONG)
                                                                    .setActionTextColor(Color.RED).show(); //soutrik
                                                        }
                                                    }
                                                } else {
                                                    conformPassword.setError(
                                                            "Password amd confirm password should be same.");
                                                    conformPassword.requestFocus();
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    email_confirm.setError("Email amd confirm email should be same.");
                                    email_confirm.requestFocus();
                                }
                            } else {
                                email_confirm.setError("Please enter valid email.");
                                email_confirm.requestFocus();
                            }
                        }
                    } else {
                        email.setError("Please enter valid email.");
                        email.requestFocus();
                    }
                }
            }
        }
    });

    findViewById(R.id.fb_log).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (appSharedPref.getString("GCM_TOKEN", "").equalsIgnoreCase("")) {
                (new RegistrationGCMFB()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            } else {
                gcmToken = appSharedPref.getString("GCM_TOKEN", "");
                LoginManager.getInstance().logInWithReadPermissions(RegistrationActivity.this,
                        Arrays.asList("public_profile", "email"));
            }
        }
    });

    //---------Facebook
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            // App code
            fbAccessToken = loginResult.getAccessToken().getToken();
            GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {
                            //                                        Log.i("FBRESULT", object.toString());
                            pDialogOut.setMessage("Authenticate Facebook User.");
                            pDialogOut.show();
                            try {
                                final String URL = InstiworkConstants.URL_DOMAIN
                                        + "Login_ios/checkfacebooksignup?facebook_id=" + object.getString("id")
                                        + "&device_token=" + URLEncoder.encode(gcmToken, "UTF-8")
                                        + "&device_type=2";
                                FB_ChkUser(URL, object);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,email,birthday,first_name,last_name,gender");
            request.setParameters(parameters);
            request.executeAsync();
        }

        @Override
        public void onCancel() {
            // App code
            pDialogOut.dismiss();
        }

        @Override
        public void onError(FacebookException exception) {
            // App code
            pDialogOut.dismiss();
            if (exception instanceof FacebookAuthorizationException) {
                if (AccessToken.getCurrentAccessToken() != null) {
                    LoginManager.getInstance().logOut();
                    LoginManager.getInstance().logInWithReadPermissions(RegistrationActivity.this,
                            Arrays.asList("public_profile", "email"));
                } else {
                    //                                Toast.makeText(RegistrationActivity.this, "Facebook Exception : " + exception.toString(), Toast.LENGTH_SHORT).show();
                }
            } else {
                //                            Toast.makeText(RegistrationActivity.this, "Facebook Exception : " + exception.toString(), Toast.LENGTH_SHORT).show();
            }
        }
    });

    dateOfBirth.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {//soutrik

            Calendar today = Calendar.getInstance();

            View dialoglayout = LayoutInflater.from(getApplicationContext())
                    .inflate(R.layout.dialog_date_picker, null);
            final DatePicker dPicker = (DatePicker) dialoglayout.findViewById(R.id.date_picker);

            dPicker.setMaxDate(today.getTimeInMillis()); // set DatePicker MAX Date
            today.set(dPicker.getYear(), dPicker.getMonth() + 1, dPicker.getDayOfMonth());
            today.add(Calendar.YEAR, -14);
            dPicker.updateDate(today.get(Calendar.YEAR), today.get(Calendar.MONTH) - 1,
                    today.get(Calendar.DATE));

            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity.this);
            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    try {
                        SimpleDateFormat changeFormat = new SimpleDateFormat("MM/dd/yyyy");
                        Calendar newDate = Calendar.getInstance();
                        newDate.set(dPicker.getYear(), dPicker.getMonth(), dPicker.getDayOfMonth());
                        dateOfBirth.setText(changeFormat.format(newDate.getTime()));
                        Logger.showMessage("DOBBBBB : ", changeFormat.format(newDate.getTime()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int id) {
                    dateOfBirth.setText("Birth date");
                }
            });
            builder.setView(dialoglayout);
            builder.show();
        }
    });

    //        getCountryList();
    buildGoogleApiClient();
    if (gMapOption == null) {
        gMapOption = new GoogleMapOptions();
        gMapOption.ambientEnabled(true);
        gMapOption.compassEnabled(true);
    }
}

From source file:org.telegram.ui.ChannelAdminLogActivity.java

@Override
public View createView(Context context) {
    if (chatMessageCellsCache.isEmpty()) {
        for (int a = 0; a < 8; a++) {
            chatMessageCellsCache.add(new ChatMessageCell(context));
        }//w  w w. j  a  v a2s  .  c o m
    }

    searchWas = false;
    hasOwnBackground = true;

    Theme.createChatResources(context, false);

    actionBar.setAddToContainer(false);
    actionBar.setOccupyStatusBar(Build.VERSION.SDK_INT >= 21 && !AndroidUtilities.isTablet());
    actionBar.setBackButtonDrawable(new BackDrawable(false));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(final int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    avatarContainer = new ChatAvatarContainer(context, null, false);
    avatarContainer.setOccupyStatusBar(!AndroidUtilities.isTablet());
    actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0));

    ActionBarMenu menu = actionBar.createMenu();
    searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true)
            .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

                @Override
                public void onSearchCollapse() {
                    searchQuery = "";
                    avatarContainer.setVisibility(View.VISIBLE);
                    if (searchWas) {
                        searchWas = false;
                        loadMessages(true);
                    }
                    /*highlightMessageId = Integer.MAX_VALUE;
                    updateVisibleRows();
                    scrollToLastMessage(false);
                    */
                    updateBottomOverlay();
                }

                @Override
                public void onSearchExpand() {
                    avatarContainer.setVisibility(View.GONE);
                    updateBottomOverlay();
                }

                @Override
                public void onSearchPressed(EditText editText) {
                    searchWas = true;
                    searchQuery = editText.getText().toString();
                    loadMessages(true);
                    //updateSearchButtons(0, 0, 0);
                }
            });
    searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));

    avatarContainer.setEnabled(false);

    avatarContainer.setTitle(currentChat.title);
    avatarContainer.setSubtitle(LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents));
    avatarContainer.setChatAvatar(currentChat);

    fragmentView = new SizeNotifierFrameLayout(context) {

        @Override
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
            if (messageObject != null && messageObject.isRoundVideo() && messageObject.eventId != 0
                    && messageObject.getDialogId() == -currentChat.id) {
                MediaController.getInstance().setTextureView(createTextureView(false), aspectRatioFrameLayout,
                        roundVideoContainer, true);
            }
        }

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (child == actionBar && parentLayout != null) {
                parentLayout.drawHeaderShadow(canvas,
                        actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() : 0);
            }
            return result;
        }

        @Override
        protected boolean isActionBarVisible() {
            return actionBar.getVisibility() == VISIBLE;
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int allHeight;
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);

            setMeasuredDimension(widthSize, heightSize);
            heightSize -= getPaddingTop();

            measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
            int actionBarHeight = actionBar.getMeasuredHeight();
            if (actionBar.getVisibility() == VISIBLE) {
                heightSize -= actionBarHeight;
            }

            int keyboardSize = getKeyboardHeight();

            int childCount = getChildCount();

            for (int i = 0; i < childCount; i++) {
                View child = getChildAt(i);
                if (child == null || child.getVisibility() == GONE || child == actionBar) {
                    continue;
                }
                if (child == chatListView || child == progressView) {
                    int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
                    int contentHeightSpec = MeasureSpec.makeMeasureSpec(
                            Math.max(AndroidUtilities.dp(10), heightSize - AndroidUtilities.dp(48 + 2)),
                            MeasureSpec.EXACTLY);
                    child.measure(contentWidthSpec, contentHeightSpec);
                } else if (child == emptyViewContainer) {
                    int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
                    int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
                    child.measure(contentWidthSpec, contentHeightSpec);
                } else {
                    measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
                }
            }
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            final int count = getChildCount();

            for (int i = 0; i < count; i++) {
                final View child = getChildAt(i);
                if (child.getVisibility() == GONE) {
                    continue;
                }
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();

                final int width = child.getMeasuredWidth();
                final int height = child.getMeasuredHeight();

                int childLeft;
                int childTop;

                int gravity = lp.gravity;
                if (gravity == -1) {
                    gravity = Gravity.TOP | Gravity.LEFT;
                }

                final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

                switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
                    break;
                case Gravity.RIGHT:
                    childLeft = r - width - lp.rightMargin;
                    break;
                case Gravity.LEFT:
                default:
                    childLeft = lp.leftMargin;
                }

                switch (verticalGravity) {
                case Gravity.TOP:
                    childTop = lp.topMargin + getPaddingTop();
                    if (child != actionBar && actionBar.getVisibility() == VISIBLE) {
                        childTop += actionBar.getMeasuredHeight();
                    }
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = (b - t - height) / 2 + lp.topMargin - lp.bottomMargin;
                    break;
                case Gravity.BOTTOM:
                    childTop = (b - t) - height - lp.bottomMargin;
                    break;
                default:
                    childTop = lp.topMargin;
                }

                if (child == emptyViewContainer) {
                    childTop -= AndroidUtilities.dp(24)
                            - (actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() / 2 : 0);
                } else if (child == actionBar) {
                    childTop -= getPaddingTop();
                }
                child.layout(childLeft, childTop, childLeft + width, childTop + height);
            }

            updateMessagesVisisblePart();
            notifyHeightChanged();
        }
    };

    contentView = (SizeNotifierFrameLayout) fragmentView;

    contentView.setOccupyStatusBar(!AndroidUtilities.isTablet());
    contentView.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion());

    emptyViewContainer = new FrameLayout(context);
    emptyViewContainer.setVisibility(View.INVISIBLE);
    contentView.addView(emptyViewContainer,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
    emptyViewContainer.setOnTouchListener((v, event) -> true);

    emptyView = new TextView(context);
    emptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    emptyView.setGravity(Gravity.CENTER);
    emptyView.setTextColor(Theme.getColor(Theme.key_chat_serviceText));
    emptyView.setBackgroundDrawable(
            Theme.createRoundRectDrawable(AndroidUtilities.dp(10), Theme.getServiceMessageColor()));
    emptyView.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(16),
            AndroidUtilities.dp(16));
    emptyViewContainer.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 16, 0, 16, 0));

    chatListView = new RecyclerListView(context) {

        @Override
        public boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (child instanceof ChatMessageCell) {
                ChatMessageCell chatMessageCell = (ChatMessageCell) child;
                ImageReceiver imageReceiver = chatMessageCell.getAvatarImage();
                if (imageReceiver != null) {
                    int top = child.getTop();
                    if (chatMessageCell.isPinnedBottom()) {
                        ViewHolder holder = chatListView.getChildViewHolder(child);
                        if (holder != null) {
                            holder = chatListView
                                    .findViewHolderForAdapterPosition(holder.getAdapterPosition() + 1);
                            if (holder != null) {
                                imageReceiver.setImageY(-AndroidUtilities.dp(1000));
                                imageReceiver.draw(canvas);
                                return result;
                            }
                        }
                    }
                    if (chatMessageCell.isPinnedTop()) {
                        ViewHolder holder = chatListView.getChildViewHolder(child);
                        if (holder != null) {
                            while (true) {
                                holder = chatListView
                                        .findViewHolderForAdapterPosition(holder.getAdapterPosition() - 1);
                                if (holder != null) {
                                    top = holder.itemView.getTop();
                                    if (!(holder.itemView instanceof ChatMessageCell)
                                            || !((ChatMessageCell) holder.itemView).isPinnedTop()) {
                                        break;
                                    }
                                } else {
                                    break;
                                }
                            }
                        }
                    }
                    int y = child.getTop() + chatMessageCell.getLayoutHeight();
                    int maxY = chatListView.getHeight() - chatListView.getPaddingBottom();
                    if (y > maxY) {
                        y = maxY;
                    }
                    if (y - AndroidUtilities.dp(48) < top) {
                        y = top + AndroidUtilities.dp(48);
                    }
                    imageReceiver.setImageY(y - AndroidUtilities.dp(44));
                    imageReceiver.draw(canvas);
                }
            }
            return result;
        }
    };
    chatListView.setOnItemClickListener((view, position) -> createMenu(view));
    chatListView.setTag(1);
    chatListView.setVerticalScrollBarEnabled(true);
    chatListView.setAdapter(chatAdapter = new ChatActivityAdapter(context));
    chatListView.setClipToPadding(false);
    chatListView.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(3));
    chatListView.setItemAnimator(null);
    chatListView.setLayoutAnimation(null);
    chatLayoutManager = new LinearLayoutManager(context) {
        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }

        @Override
        public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
            LinearSmoothScrollerMiddle linearSmoothScroller = new LinearSmoothScrollerMiddle(
                    recyclerView.getContext());
            linearSmoothScroller.setTargetPosition(position);
            startSmoothScroll(linearSmoothScroller);
        }
    };
    chatLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    chatLayoutManager.setStackFromEnd(true);
    chatListView.setLayoutManager(chatLayoutManager);
    contentView.addView(chatListView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    chatListView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        private float totalDy = 0;
        private final int scrollValue = AndroidUtilities.dp(100);

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                scrollingFloatingDate = true;
                checkTextureViewPosition = true;
            } else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                scrollingFloatingDate = false;
                checkTextureViewPosition = false;
                hideFloatingDateView(true);
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            chatListView.invalidate();
            if (dy != 0 && scrollingFloatingDate && !currentFloatingTopIsNotMessage) {
                if (floatingDateView.getTag() == null) {
                    if (floatingDateAnimation != null) {
                        floatingDateAnimation.cancel();
                    }
                    floatingDateView.setTag(1);
                    floatingDateAnimation = new AnimatorSet();
                    floatingDateAnimation.setDuration(150);
                    floatingDateAnimation.playTogether(ObjectAnimator.ofFloat(floatingDateView, "alpha", 1.0f));
                    floatingDateAnimation.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (animation.equals(floatingDateAnimation)) {
                                floatingDateAnimation = null;
                            }
                        }
                    });
                    floatingDateAnimation.start();
                }
            }
            checkScrollForLoad(true);
            updateMessagesVisisblePart();
        }
    });
    if (scrollToPositionOnRecreate != -1) {
        chatLayoutManager.scrollToPositionWithOffset(scrollToPositionOnRecreate, scrollToOffsetOnRecreate);
        scrollToPositionOnRecreate = -1;
    }

    progressView = new FrameLayout(context);
    progressView.setVisibility(View.INVISIBLE);
    contentView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));

    progressView2 = new View(context);
    progressView2.setBackgroundResource(R.drawable.system_loader);
    progressView2.getBackground().setColorFilter(Theme.colorFilter);
    progressView.addView(progressView2, LayoutHelper.createFrame(36, 36, Gravity.CENTER));

    progressBar = new RadialProgressView(context);
    progressBar.setSize(AndroidUtilities.dp(28));
    progressBar.setProgressColor(Theme.getColor(Theme.key_chat_serviceText));
    progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));

    floatingDateView = new ChatActionCell(context);
    floatingDateView.setAlpha(0.0f);
    contentView.addView(floatingDateView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 4, 0, 0));

    contentView.addView(actionBar);

    bottomOverlayChat = new FrameLayout(context) {
        @Override
        public void onDraw(Canvas canvas) {
            int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight();
            Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom);
            Theme.chat_composeShadowDrawable.draw(canvas);
            canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(),
                    Theme.chat_composeBackgroundPaint);
        }
    };
    bottomOverlayChat.setWillNotDraw(false);
    bottomOverlayChat.setPadding(0, AndroidUtilities.dp(3), 0, 0);
    contentView.addView(bottomOverlayChat,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));
    bottomOverlayChat.setOnClickListener(view -> {
        if (getParentActivity() == null) {
            return;
        }
        AdminLogFilterAlert adminLogFilterAlert = new AdminLogFilterAlert(getParentActivity(), currentFilter,
                selectedAdmins, currentChat.megagroup);
        adminLogFilterAlert.setCurrentAdmins(admins);
        adminLogFilterAlert.setAdminLogFilterAlertDelegate((filter, admins) -> {
            currentFilter = filter;
            selectedAdmins = admins;
            if (currentFilter != null || selectedAdmins != null) {
                avatarContainer.setSubtitle(
                        LocaleController.getString("EventLogSelectedEvents", R.string.EventLogSelectedEvents));
            } else {
                avatarContainer.setSubtitle(
                        LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents));
            }
            loadMessages(true);
        });
        showDialog(adminLogFilterAlert);
    });

    bottomOverlayChatText = new TextView(context);
    bottomOverlayChatText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    bottomOverlayChatText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    bottomOverlayChatText.setTextColor(Theme.getColor(Theme.key_chat_fieldOverlayText));
    bottomOverlayChatText.setText(LocaleController.getString("SETTINGS", R.string.SETTINGS).toUpperCase());
    bottomOverlayChat.addView(bottomOverlayChatText,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));

    bottomOverlayImage = new ImageView(context);
    bottomOverlayImage.setImageResource(R.drawable.log_info);
    bottomOverlayImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_fieldOverlayText),
            PorterDuff.Mode.MULTIPLY));
    bottomOverlayImage.setScaleType(ImageView.ScaleType.CENTER);
    bottomOverlayChat.addView(bottomOverlayImage,
            LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP, 3, 0, 0, 0));
    bottomOverlayImage.setOnClickListener(v -> {
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        if (currentChat.megagroup) {
            builder.setMessage(AndroidUtilities.replaceTags(
                    LocaleController.getString("EventLogInfoDetail", R.string.EventLogInfoDetail)));
        } else {
            builder.setMessage(AndroidUtilities.replaceTags(LocaleController
                    .getString("EventLogInfoDetailChannel", R.string.EventLogInfoDetailChannel)));
        }
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
        builder.setTitle(LocaleController.getString("EventLogInfoTitle", R.string.EventLogInfoTitle));
        showDialog(builder.create());
    });

    searchContainer = new FrameLayout(context) {
        @Override
        public void onDraw(Canvas canvas) {
            int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight();
            Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom);
            Theme.chat_composeShadowDrawable.draw(canvas);
            canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(),
                    Theme.chat_composeBackgroundPaint);
        }
    };
    searchContainer.setWillNotDraw(false);
    searchContainer.setVisibility(View.INVISIBLE);
    searchContainer.setFocusable(true);
    searchContainer.setFocusableInTouchMode(true);
    searchContainer.setClickable(true);
    searchContainer.setPadding(0, AndroidUtilities.dp(3), 0, 0);
    contentView.addView(searchContainer,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));

    /*searchUpButton = new ImageView(context);
    searchUpButton.setScaleType(ImageView.ScaleType.CENTER);
    searchUpButton.setImageResource(R.drawable.search_up);
    searchUpButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
    searchContainer.addView(searchUpButton, LayoutHelper.createFrame(48, 48));
    searchUpButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 1);
    }
    });
            
    searchDownButton = new ImageView(context);
    searchDownButton.setScaleType(ImageView.ScaleType.CENTER);
    searchDownButton.setImageResource(R.drawable.search_down);
    searchDownButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
    searchContainer.addView(searchDownButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP, 48, 0, 0, 0));
    searchDownButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 2);
    }
    });*/

    searchCalendarButton = new ImageView(context);
    searchCalendarButton.setScaleType(ImageView.ScaleType.CENTER);
    searchCalendarButton.setImageResource(R.drawable.search_calendar);
    searchCalendarButton.setColorFilter(new PorterDuffColorFilter(
            Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
    searchContainer.addView(searchCalendarButton,
            LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP));
    searchCalendarButton.setOnClickListener(view -> {
        if (getParentActivity() == null) {
            return;
        }
        AndroidUtilities.hideKeyboard(searchItem.getSearchField());
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int monthOfYear = calendar.get(Calendar.MONTH);
        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        try {
            DatePickerDialog dialog = new DatePickerDialog(getParentActivity(),
                    (view1, year1, month, dayOfMonth1) -> {
                        Calendar calendar1 = Calendar.getInstance();
                        calendar1.clear();
                        calendar1.set(year1, month, dayOfMonth1);
                        int date = (int) (calendar1.getTime().getTime() / 1000);
                        loadMessages(true);
                    }, year, monthOfYear, dayOfMonth);
            final DatePicker datePicker = dialog.getDatePicker();
            datePicker.setMinDate(1375315200000L);
            datePicker.setMaxDate(System.currentTimeMillis());
            dialog.setButton(DialogInterface.BUTTON_POSITIVE,
                    LocaleController.getString("JumpToDate", R.string.JumpToDate), dialog);
            dialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                    LocaleController.getString("Cancel", R.string.Cancel), (dialog12, which) -> {

                    });
            if (Build.VERSION.SDK_INT >= 21) {
                dialog.setOnShowListener(dialog1 -> {
                    int count = datePicker.getChildCount();
                    for (int a = 0; a < count; a++) {
                        View child = datePicker.getChildAt(a);
                        ViewGroup.LayoutParams layoutParams = child.getLayoutParams();
                        layoutParams.width = LayoutHelper.MATCH_PARENT;
                        child.setLayoutParams(layoutParams);
                    }
                });
            }
            showDialog(dialog);
        } catch (Exception e) {
            FileLog.e(e);
        }
    });

    searchCountText = new SimpleTextView(context);
    searchCountText.setTextColor(Theme.getColor(Theme.key_chat_searchPanelText));
    searchCountText.setTextSize(15);
    searchCountText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    searchContainer.addView(searchCountText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 108, 0, 0, 0));

    chatAdapter.updateRows();
    if (loading && messages.isEmpty()) {
        progressView.setVisibility(View.VISIBLE);
        chatListView.setEmptyView(null);
    } else {
        progressView.setVisibility(View.INVISIBLE);
        chatListView.setEmptyView(emptyViewContainer);
    }

    updateEmptyPlaceholder();

    return fragmentView;
}