/*
* Copyright 2014 Mario Guggenberger <mg@protyposis.net>
*
* 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.
*/
package net.protyposis.android.mediaplayerdemo;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class VideoURIInputDialogFragment extends DialogFragment {
private OnVideoURISelectedListener mListener;
public VideoURIInputDialogFragment() {
// Required empty public constructor
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View dialogView = getActivity().getLayoutInflater()
.inflate(R.layout.fragment_uriinput_dialog, null);
final EditText urlText = (EditText) dialogView.findViewById(R.id.url);
builder.setTitle(getString(R.string.openvideo_type))
.setView(dialogView)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mListener.onVideoURISelected(Uri.parse(urlText.getText().toString()));
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// nothing to do here
}
});
return builder.create();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnVideoURISelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnVideoURISelectedListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnVideoURISelectedListener {
public void onVideoURISelected(Uri uri);
}
}