Created
February 17, 2016 06:46
-
-
Save pookie13/ac26b3198d6f9fe5dab2 to your computer and use it in GitHub Desktop.
TIme Range picker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<TabHost | |
android:id="@+id/tabHost" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content"> | |
<LinearLayout | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical"> | |
<TabWidget | |
android:id="@android:id/tabs" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content"></TabWidget> | |
<FrameLayout | |
android:id="@android:id/tabcontent" | |
android:layout_width="fill_parent" | |
android:layout_height="0dp" | |
android:layout_weight="1"> | |
<LinearLayout | |
android:id="@+id/startTimeGroup" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical"> | |
<TimePicker | |
android:id="@+id/startTimePicker" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content"></TimePicker> | |
</LinearLayout> | |
<LinearLayout | |
android:id="@+id/endTimeGroup" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical"> | |
<TimePicker | |
android:id="@+id/endTimePicker" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content"></TimePicker> | |
</LinearLayout> | |
</FrameLayout> | |
<Button | |
android:id="@+id/bSetTimeRange" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:text="Done" /> | |
</LinearLayout> | |
</TabHost> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.app.pointme.voicenotificaction; | |
import android.app.DialogFragment; | |
import android.os.Bundle; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.view.Window; | |
import android.view.WindowManager; | |
import android.widget.Button; | |
import android.widget.TabHost; | |
import android.widget.TimePicker; | |
/** | |
* Created by goparties on 17/2/16. | |
*/ | |
public class TimeRangePickerDialog extends DialogFragment implements View.OnClickListener { | |
TabHost tabs; | |
Button setTimeRange; | |
TimePicker startTimePicker, endTimePicker; | |
OnTimeRangeSelectedListener onTimeRangeSelectedListener; | |
boolean is24HourMode; | |
public static TimeRangePickerDialog newInstance(OnTimeRangeSelectedListener callback, boolean is24HourMode) { | |
TimeRangePickerDialog ret = new TimeRangePickerDialog(); | |
ret.initialize(callback, is24HourMode); | |
return ret; | |
} | |
public void initialize(OnTimeRangeSelectedListener callback, | |
boolean is24HourMode) { | |
onTimeRangeSelectedListener = callback; | |
this.is24HourMode = is24HourMode; | |
} | |
public interface OnTimeRangeSelectedListener { | |
void onTimeRangeSelected(int startHour, int startMin, int endHour, int endMin); | |
} | |
public void setOnTimeRangeSetListener(OnTimeRangeSelectedListener callback) { | |
onTimeRangeSelectedListener = callback; | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View root = inflater.inflate(R.layout.time_picker, container, false); | |
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); | |
tabs = (TabHost) root.findViewById(R.id.tabHost); | |
setTimeRange = (Button) root.findViewById(R.id.bSetTimeRange); | |
startTimePicker = (TimePicker) root.findViewById(R.id.startTimePicker); | |
endTimePicker = (TimePicker) root.findViewById(R.id.endTimePicker); | |
setTimeRange.setOnClickListener(this); | |
tabs.findViewById(R.id.tabHost); | |
tabs.setup(); | |
TabHost.TabSpec tabpage1 = tabs.newTabSpec("one"); | |
tabpage1.setContent(R.id.startTimeGroup); | |
tabpage1.setIndicator("Start Time"); | |
TabHost.TabSpec tabpage2 = tabs.newTabSpec("two"); | |
tabpage2.setContent(R.id.endTimeGroup); | |
tabpage2.setIndicator("End Time"); | |
tabs.addTab(tabpage1); | |
tabs.addTab(tabpage2); | |
return root; | |
} | |
@Override | |
public void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
} | |
@Override | |
public void onStart() { | |
super.onStart(); | |
// safety check | |
if (getDialog() == null) | |
return; | |
getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); | |
} | |
@Override | |
public void onClick(View v) { | |
if (v.getId() == R.id.bSetTimeRange) { | |
dismiss(); | |
int startHour = startTimePicker.getCurrentHour(); | |
int startMin = startTimePicker.getCurrentMinute(); | |
int endHour = endTimePicker.getCurrentHour(); | |
int endMin = endTimePicker.getCurrentMinute(); | |
onTimeRangeSelectedListener.onTimeRangeSelected(startHour, startMin, endHour, endMin); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment