Search in sources :

Example 1 with SwitchDateTimeDialogFragment

use of com.kunzisoft.switchdatetime.SwitchDateTimeDialogFragment in project HumaneApp by Ganesh1010.

the class Needvolunteer method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.need_volunteer, container, false);
    textView = (TextView) view.findViewById(R.id.textView12);
    if (savedInstanceState != null) {
        textView.setText(savedInstanceState.getCharSequence(STATE_TEXTVIEW));
    }
    dateTimeFragment = (SwitchDateTimeDialogFragment) getFragmentManager().findFragmentByTag(TAG_DATETIME_FRAGMENT);
    if (dateTimeFragment == null) {
        dateTimeFragment = SwitchDateTimeDialogFragment.newInstance(getString(R.string.label_datetime_dialog), getString(R.string.positive_button_datetime_picker), getString(R.string.negative_button_datetime_picker));
    }
    final SimpleDateFormat myDateFormat = new SimpleDateFormat("d MMM yyyy HH:mm", Locale.getDefault());
    dateTimeFragment.startAtCalendarView();
    dateTimeFragment.set24HoursMode(false);
    dateTimeFragment.setMinimumDateTime(new GregorianCalendar(2015, Calendar.JANUARY, 1).getTime());
    dateTimeFragment.setMaximumDateTime(new GregorianCalendar(2025, Calendar.DECEMBER, 31).getTime());
    dateTimeFragment.setDefaultDateTime(new GregorianCalendar(2017, Calendar.MARCH, 4, 15, 20).getTime());
    try {
        dateTimeFragment.setSimpleDateMonthAndDayFormat(new SimpleDateFormat("MMMM dd", Locale.getDefault()));
    } catch (SwitchDateTimeDialogFragment.SimpleDateMonthAndDayFormatException e) {
        Log.e(TAG, e.getMessage());
    }
    dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() {

        @Override
        public void onPositiveButtonClick(Date date) {
            Log.d("hai", myDateFormat.format(date));
            textView.setText(myDateFormat.format(date));
        }

        @Override
        public void onNegativeButtonClick(Date date) {
            textView.setText("");
        }
    });
    Button buttonView = (Button) view.findViewById(R.id.button);
    buttonView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dateTimeFragment.show(getFragmentManager(), TAG_DATETIME_FRAGMENT);
        }
    });
    return view;
}
Also used : Button(android.widget.Button) GregorianCalendar(java.util.GregorianCalendar) SimpleDateFormat(java.text.SimpleDateFormat) TextView(android.widget.TextView) View(android.view.View) SwitchDateTimeDialogFragment(com.kunzisoft.switchdatetime.SwitchDateTimeDialogFragment) Date(java.util.Date)

Example 2 with SwitchDateTimeDialogFragment

use of com.kunzisoft.switchdatetime.SwitchDateTimeDialogFragment in project HumaneApp by Ganesh1010.

the class NewNeedActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_need);
    DetailsPopulator detailsPopulator = new DetailsPopulator(this);
    detailsPopulator.getCountryDetailsFromAPI();
    db = new DatabaseHelper(NewNeedActivity.this);
    mainItemDetails = db.getAllMainItemDetails();
    subItemDetails = db.getAllSubItemDetails();
    this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    dateTimeFragment = (SwitchDateTimeDialogFragment) getSupportFragmentManager().findFragmentByTag(TAG_DATETIME_FRAGMENT);
    if (dateTimeFragment == null) {
        dateTimeFragment = SwitchDateTimeDialogFragment.newInstance(getString(R.string.label_datetime_dialog), getString(R.string.positive_button_datetime_picker), getString(R.string.negative_button_datetime_picker));
    }
    Calendar now = Calendar.getInstance();
    hiddenPanel = findViewById(R.id.hiddenPanel_needForm);
    toolbarSubmit = (RelativeLayout) findViewById(R.id.toolbarSubmit);
    final SimpleDateFormat myDateFormat = new SimpleDateFormat("d MMM yyyy", Locale.getDefault());
    final SimpleDateFormat myTimeFormat = new SimpleDateFormat("hh:mm a", Locale.getDefault());
    dateTimeFragment.startAtCalendarView();
    dateTimeFragment.set24HoursMode(false);
    dateTimeFragment.setMinimumDateTime(new GregorianCalendar(2015, Calendar.JANUARY, 1).getTime());
    dateTimeFragment.setMaximumDateTime(new GregorianCalendar(2025, Calendar.DECEMBER, 31).getTime());
    dateTimeFragment.setDefaultDateTime(new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR), now.get(Calendar.MINUTE), now.get(Calendar.HOUR_OF_DAY) > 12 ? (now.get(Calendar.PM)) : (now.get(Calendar.AM))).getTime());
    try {
        dateTimeFragment.setSimpleDateMonthAndDayFormat(new SimpleDateFormat("MMMM dd", Locale.getDefault()));
    } catch (SwitchDateTimeDialogFragment.SimpleDateMonthAndDayFormatException e) {
    }
    dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() {

        @Override
        public void onPositiveButtonClick(Date date) {
            datetime = date;
            textView.setText(myDateFormat.format(date) + "  " + myTimeFormat.format(date));
        }

        @Override
        public void onNegativeButtonClick(Date date) {
            textView.setText("");
        }
    });
    dateImage = (ImageView) findViewById(R.id.date_needForm);
    dateImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dateTimeFragment.show(getSupportFragmentManager(), TAG_DATETIME_FRAGMENT);
        }
    });
    textView = (TextView) findViewById(R.id.textView);
    if (savedInstanceState != null)
        textView.setText(savedInstanceState.getCharSequence(STATE_TEXTVIEW));
    recyclerView = (RecyclerView) findViewById(R.id.recyclerView_needForm);
    submit = (Button) findViewById(R.id.submit_needForm);
    fabAdd = (FloatingActionButton) findViewById(R.id.fabAdd_needForm);
    needDetails = new ArrayList<>();
    bottomUp = AnimationUtils.loadAnimation(this, R.anim.bottom_up);
    bottomDown = AnimationUtils.loadAnimation(this, R.anim.bottom_down);
    mainItemSpinner = (Spinner) findViewById(R.id.main_item_spinner_needForm);
    subItemSpinner = (Spinner) findViewById(R.id.sub_item_spinner_needForm);
    itemQuantity = (EditText) findViewById(R.id.itemQuantity_needForm);
    gender = (RadioGroup) findViewById(R.id.gender_needForm);
    age = (EditText) findViewById(R.id.age_needForm);
    clothesLayout = (LinearLayout) findViewById(R.id.clothesLayout_needForm);
    post = (Button) findViewById(R.id.post_needForm);
    cancel = (Button) findViewById(R.id.cancel_needForm);
    ArrayList<ItemSpinnerData> mainItemList = new ArrayList<>();
    for (int i = 0; i < mainItemDetails.size(); i++) {
        switch(mainItemDetails.get(i).getMainItemCode()) {
            case 1:
                mainItemList.add(new ItemSpinnerData(mainItemDetails.get(i).getMainItemName(), R.drawable.ic_food_black));
                break;
            case 2:
                mainItemList.add(new ItemSpinnerData(mainItemDetails.get(i).getMainItemName(), R.drawable.ic_cloth_black));
                break;
            case 3:
                mainItemList.add(new ItemSpinnerData(mainItemDetails.get(i).getMainItemName(), R.drawable.ic_blood_black));
                break;
            case 4:
                mainItemList.add(new ItemSpinnerData(mainItemDetails.get(i).getMainItemName(), R.drawable.ic_grocery_cart_black));
                break;
            case 5:
                mainItemList.add(new ItemSpinnerData(mainItemDetails.get(i).getMainItemName(), R.drawable.ic_stationery_black));
                break;
        }
    }
    MainItemSpinnerAdapter mainItemSpinnerAdapter = new MainItemSpinnerAdapter(NewNeedActivity.this, R.layout.main_item_spinner_layout, R.id.main_item_txt_spinner_needForm, mainItemList);
    mainItemSpinner.setAdapter(mainItemSpinnerAdapter);
    final RadioButton lastGenderRadioBtn = (RadioButton) findViewById(R.id.female);
    mainItemSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String item = ((TextView) findViewById(R.id.main_item_txt_spinner_needForm)).getText().toString();
            mainItem = item;
            ArrayList<ItemSpinnerData> subItemList = new ArrayList<>();
            itemQuantity.setText("");
            itemQuantity.setError(null);
            gender.clearCheck();
            lastGenderRadioBtn.setError(null);
            age.setText("");
            age.setError(null);
            for (int i = 0; i < subItemDetails.size(); i++) if (subItemDetails.get(i).getMainItemCode() == (id + 1))
                subItemList.add(new ItemSpinnerData(subItemDetails.get(i).getSubItemName()));
            SubItemSpinnerAdapter subItemSpinnerAdapter = new SubItemSpinnerAdapter(NewNeedActivity.this, R.layout.sub_item_spinner_layout, R.id.sub_item_txt_spinner_needForm, subItemList);
            subItemSpinner.setAdapter(subItemSpinnerAdapter);
            subItemSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    String item = ((TextView) findViewById(R.id.sub_item_txt_spinner_needForm)).getText().toString();
                    subItem = item;
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                }
            });
            if (mainItem.equals("Clothes"))
                clothesLayout.setVisibility(View.VISIBLE);
            else
                clothesLayout.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    post.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            NeedItemDetails needItemDetails = new NeedItemDetails();
            int selectedIdGender = gender.getCheckedRadioButtonId();
            radioSexButton = (RadioButton) findViewById(selectedIdGender);
            if (itemQuantity.getText().toString().isEmpty()) {
                dataFilled = false;
                itemQuantity.setError("enter the Quantity");
            } else {
                needItemDetails.setNeed_item_id(++NewNeedActivity.id);
                for (int i = 0; i <= subItemDetails.size(); i++) if (!subItem.isEmpty() && mainItemDetails != null && subItemDetails != null) {
                    if (subItem.equals(subItemDetails.get(i).getSubItemName())) {
                        needItemDetails.setItem_type_id(subItemDetails.get(i).getMainItemCode());
                        needItemDetails.setSub_item_type_id(subItemDetails.get(i).getSubItemCode());
                        break;
                    }
                }
                needItemDetails.setQuantity(Integer.parseInt(itemQuantity.getText().toString()));
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault());
                needItemDetails.setDeadline(sdf.format(datetime));
                dataFilled = true;
            }
            if (mainItem.equals("Clothes")) {
                if (gender.getCheckedRadioButtonId() <= 0) {
                    dataFilled = false;
                    lastGenderRadioBtn.setError("select gender");
                }
                if (age.getText().toString().isEmpty()) {
                    dataFilled = false;
                    age.setError("enter the age");
                } else {
                    needItemDetails.setGender(radioSexButton.getText().toString());
                    needItemDetails.setAge(Integer.parseInt(age.getText().toString()));
                    dataFilled = true;
                }
            }
            if (dataFilled) {
                needDetails.add(needItemDetails);
                recyclerView.setAdapter(new NewNeedsListAdapter(NewNeedActivity.this, needDetails, mainItemDetails, subItemDetails));
                recyclerView.setLayoutManager(new LinearLayoutManager(NewNeedActivity.this));
                hiddenPanel.startAnimation(bottomDown);
                hiddenPanel.setVisibility(View.GONE);
                toolbarSubmit.setVisibility(View.VISIBLE);
                fabAdd.setVisibility(View.VISIBLE);
                recyclerView.setVisibility(View.VISIBLE);
            }
            Toast.makeText(NewNeedActivity.this, "new need", Toast.LENGTH_SHORT).show();
        }
    });
    cancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            hiddenPanel.startAnimation(bottomDown);
            hiddenPanel.setVisibility(View.GONE);
            toolbarSubmit.setVisibility(View.VISIBLE);
            fabAdd.setVisibility(View.VISIBLE);
            recyclerView.setVisibility(View.VISIBLE);
        }
    });
    fabAdd.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!isPanelShown()) {
                hiddenPanel.startAnimation(bottomUp);
                hiddenPanel.setVisibility(View.VISIBLE);
                toolbarSubmit.setVisibility(View.GONE);
                fabAdd.setVisibility(View.GONE);
                recyclerView.setVisibility(View.GONE);
            } else {
                hiddenPanel.startAnimation(bottomDown);
                hiddenPanel.setVisibility(View.GONE);
                toolbarSubmit.setVisibility(View.VISIBLE);
                fabAdd.setVisibility(View.VISIBLE);
                recyclerView.setVisibility(View.VISIBLE);
            }
            itemQuantity.setText("");
            itemQuantity.setError(null);
            gender.clearCheck();
            lastGenderRadioBtn.setError(null);
            age.setText("");
            age.setError(null);
        }
    });
    submit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            gson = new Gson();
            new PostItemDetails().execute();
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TextView(android.widget.TextView) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) RadioButton(android.widget.RadioButton) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SwitchDateTimeDialogFragment(com.kunzisoft.switchdatetime.SwitchDateTimeDialogFragment) Date(java.util.Date) AdapterView(android.widget.AdapterView) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

View (android.view.View)2 TextView (android.widget.TextView)2 SwitchDateTimeDialogFragment (com.kunzisoft.switchdatetime.SwitchDateTimeDialogFragment)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 RadioButton (android.widget.RadioButton)1 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1