Skip to content

Commit

Permalink
Fix NPE when RadialTimePickerDialog is embedded.
Browse files Browse the repository at this point in the history
  • Loading branch information
derekbrameyer committed Mar 21, 2014
1 parent e77c23e commit 0a72367
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.nineoldandroids.animation.ObjectAnimator;

import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.content.res.Resources;
Expand Down Expand Up @@ -132,15 +131,6 @@ public static interface OnDialogDismissListener {
public abstract void onDialogDismiss(DialogInterface dialoginterface);
}

public RadialTimePickerDialog() {
// Empty constructor required for dialog fragment.
}

public RadialTimePickerDialog(Context context, int theme, OnTimeSetListener callback,
int hourOfDay, int minute, boolean is24HourMode) {
// Empty constructor required for dialog fragment.
}

public static RadialTimePickerDialog newInstance(OnTimeSetListener callback,
int hourOfDay, int minute, boolean is24HourMode) {
RadialTimePickerDialog ret = new RadialTimePickerDialog();
Expand Down Expand Up @@ -213,7 +203,9 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
if (getShowsDialog()) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
}

View view = inflater.inflate(R.layout.radial_time_picker_dialog, null);
KeyboardListener keyboardListener = new KeyboardListener();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.doomonafireball.betterpickers.sample.activity.radialtimepicker;

import com.doomonafireball.betterpickers.radialtimepicker.RadialPickerLayout;
import com.doomonafireball.betterpickers.radialtimepicker.RadialTimePickerDialog;
import com.doomonafireball.betterpickers.sample.R;
import com.doomonafireball.betterpickers.sample.activity.BaseSampleActivity;
Expand Down Expand Up @@ -50,7 +49,7 @@ public void onClick(View v) {
}

@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
public void onTimeSet(RadialTimePickerDialog dialog, int hourOfDay, int minute) {
text.setText("" + hourOfDay + ":" + minute);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.doomonafireball.betterpickers.sample.activity.radialtimepicker;

import com.doomonafireball.betterpickers.radialtimepicker.RadialPickerLayout;
import com.doomonafireball.betterpickers.radialtimepicker.RadialTimePickerDialog;
import com.doomonafireball.betterpickers.sample.R;
import com.doomonafireball.betterpickers.sample.activity.BaseSampleActivity;

import org.joda.time.DateTime;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.Button;
Expand All @@ -25,25 +24,43 @@ public class SampleRadialTimeDefault extends BaseSampleActivity
private TextView text;
private Button button;

private boolean mHasDialogFrame;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text_and_button);

if (savedInstanceState == null) {
mHasDialogFrame = findViewById(R.id.frame) != null;
}

text = (TextView) findViewById(R.id.text);
button = (Button) findViewById(R.id.button);

text.setText("--");
if (mHasDialogFrame) {
text.setText("|");
} else {
text.setText("--");
}

button.setText("Set Time");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fm = getSupportFragmentManager();
DateTime now = DateTime.now();
RadialTimePickerDialog timePickerDialog = RadialTimePickerDialog
.newInstance(SampleRadialTimeDefault.this, now.getHourOfDay(), now.getMinuteOfHour(),
DateFormat.is24HourFormat(SampleRadialTimeDefault.this));
timePickerDialog.show(fm, FRAG_TAG_TIME_PICKER);
if (mHasDialogFrame) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

ft.add(R.id.frame, timePickerDialog, FRAG_TAG_TIME_PICKER)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
} else {
timePickerDialog.show(getSupportFragmentManager(), FRAG_TAG_TIME_PICKER);
}
}
});
}
Expand Down

0 comments on commit 0a72367

Please sign in to comment.