Coder Social home page Coder Social logo

nikhil-z / range-time-picker-dialog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from puffocyano/range-time-picker-dialog

0.0 2.0 0.0 188 KB

A custom dialog that allow you to set a start time and end time.

License: Apache License 2.0

Java 100.00%

range-time-picker-dialog's Introduction

Range-Time-Picker-Dialog

API

Simple Android Library that provide you a custom dialog that allow you to set a start time and end time.

Screenshot

Install

Add this to your project build.gradle

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Add this to your module build.gradle

   dependencies {
        compile 'com.github.PuffoCyano:Range-Time-Picker-Dialog:v1.5'
    }

Usage

In your activity (Default method "newInstance()"):

    // Create an instance of the dialog fragment and show it
    RangeTimePickerDialog dialog = new RangeTimePickerDialog();
    dialog.newInstance();
    dialog.setRadiusDialog(20); // Set radius of dialog (default is 50)
    dialog.setIs24HourView(true); // Indicates if the format should be 24 hours
    dialog.setColorBackgroundHeader(R.color.colorPrimary); // Set Color of Background header dialog
    dialog.setColorTextButton(R.color.colorPrimaryDark); // Set Text color of button
    FragmentManager fragmentManager = getFragmentManager();
    dialog.show(fragmentManager, "");

You can instantiate the dialog with more parameters:

     // Create an instance of the dialog fragment and show it
     RangeTimePickerDialog dialog = new RangeTimePickerDialog();
     dialog.newInstance(R.color.CyanWater, R.color.White, R.color.Yellow, R.color.colorPrimary, true);
     FragmentManager fragmentManager = getFragmentManager();
     dialog.show(fragmentManager, "");

To read parameter from Dialog your activity have to implements the interface ISelectedTime:

public class MainActivity extends AppCompatActivity implements RangeTimePickerDialog.ISelectedTime

Then you have to override the method "onSelectedTime":

@Override
public void onSelectedTime(int hourStart, int minuteStart, int hourEnd, int minuteEnd)
{
  // Use parameters provided by Dialog
  Toast.makeText(this, "Start: "+hourStart+":"+minuteStart+"\nEnd: "+hourEnd+":"+minuteEnd, Toast.LENGTH_SHORT).show();
}

In your fragment:

   // Create an instance of the dialog fragment and show it
   RangeTimePickerDialog dialog = new RangeTimePickerDialog();
   dialog.newInstance(R.color.CyanWater, R.color.White, R.color.Yellow, R.color.colorPrimary, true);
   FragmentManager fragmentManager = getFragmentManager();
   dialog.setTargetFragment(this, MY_FRAGMENT_ID); // MY_FRAGMENT_ID is a personal identifier that allow you to get parameter from dialog into onActivityResult
   dialog.show(fragmentManager, "");

When you have to read parameter provided by Dialog you have to override onResultActivity in your fragment:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
   super.onActivityResult(requestCode, resultCode, data);
   if (requestCode == MY_FRAGMENT_ID)
   {
      if (resultCode == Activity.RESULT_OK)
      {
         if (data.getExtras().containsKey(RangeTimePickerDialog.HOUR_START))
         {
            int hourStart = data.getExtras().getInt(RangeTimePickerDialog.HOUR_START);
            int hourEnd = data.getExtras().getInt(RangeTimePickerDialog.HOUR_END);
            int minuteStart = data.getExtras().getInt(RangeTimePickerDialog.MINUTE_START);
            int minuteEnd = data.getExtras().getInt(RangeTimePickerDialog.MINUTE_END);
            // Use the returned value
            Toast.makeText(getActivity(), "Time start:"+hourStart+":"+minuteStart+"\nUntil: "+hourEnd+":"+minuteEnd, Toast.LENGTH_SHORT).show();
         }
      }
   }
}

Methods

  • setColorTabUnselected(int colorTabUnselected): Set color of tab item when it is unselected
  • setColorTabSelected(int colorTabSelected): Set color of tab item when it is selected
  • setColorTextButton(int colorTextButton): Set button text color
  • setColorBackgroundHeader(int colorBackgroundHeader): Set background color of header dialog
  • setIs24HourView(boolean is24HourView): Set true if you want see time into 24 hour format
  • setMessageErrorRangeTime(String messageErrorRangeTime): Set message error that appears when you select a end time greater than start time (only if "validateRange" is true)
  • setTextBtnPositive(String textBtnPositive): Set positive button text
  • setTextBtnNegative(String textBtnNegative): Set negative button text
  • setRadiusDialog(int radiusDialog): Set dialog radius (default is 50)
  • setTextTabStart(String textTabStart): Set tab start text
  • setTextTabEnd(String textTabEnd): Set tab end text
  • setValidateRange(boolean validateRange):Set true if you want validate the range time (start time < end time). Set false if you want select any time
  • setColorBackgroundTimePickerHeader(int colorBackgroundTimePickerHeader): Set background color of header timePicker

License

Copyright 2018 Alessandro Marino

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

range-time-picker-dialog's People

Contributors

puffocyano avatar

Watchers

James Cloos avatar Nikhil avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.