// Path: app/src/main/java/com/philliphsu/clock2/dialogs/RingtonePickerDialog.java
// public class RingtonePickerDialog extends BaseAlertDialogFragment {
//     private static final String TAG = "RingtonePickerDialog";
//     private static final String KEY_RINGTONE_URI = "key_ringtone_uri";
// 
//     private RingtoneManager mRingtoneManager;
//     private OnRingtoneSelectedListener mOnRingtoneSelectedListener;
//     private Uri mRingtoneUri;
//     private RingtoneLoop mRingtone;
// 
//     public interface OnRingtoneSelectedListener {
//         void onRingtoneSelected(Uri ringtoneUri);
//     }
// 
//     /**
//      * @param ringtoneUri the URI of the ringtone to show as initially selected
//      */
//     public static RingtonePickerDialog newInstance(OnRingtoneSelectedListener l, Uri ringtoneUri) {
//         RingtonePickerDialog dialog = new RingtonePickerDialog();
//         dialog.mOnRingtoneSelectedListener = l;
//         dialog.mRingtoneUri = ringtoneUri;
//         return dialog;
//     }
// 
//     @Override
//     public void onCreate(@Nullable Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         if (savedInstanceState != null) {
//             mRingtoneUri = savedInstanceState.getParcelable(KEY_RINGTONE_URI);
//         }
//         mRingtoneManager = new RingtoneManager(getActivity());
//         mRingtoneManager.setType(RingtoneManager.TYPE_ALARM);
//     }
// 
//     @Override
//     protected AlertDialog createFrom(AlertDialog.Builder builder) {
//         // TODO: We set the READ_EXTERNAL_STORAGE permission. Verify that this includes the user's 
//         // custom ringtone files.
//         Cursor cursor = mRingtoneManager.getCursor();
//         int checkedItem = mRingtoneManager.getRingtonePosition(mRingtoneUri);
//         String labelColumn = cursor.getColumnName(RingtoneManager.TITLE_COLUMN_INDEX);
// 
//         builder.setTitle(R.string.ringtones)
//                 .setSingleChoiceItems(cursor, checkedItem, labelColumn, new DialogInterface.OnClickListener() {
//                     @Override
//                     public void onClick(DialogInterface dialog, int which) {
//                         if (mRingtone != null) {
//                             destroyLocalPlayer();
//                         }
//                         // Here, 'which' param refers to the position of the item clicked.
//                         mRingtoneUri = mRingtoneManager.getRingtoneUri(which);
//                         mRingtone = new RingtoneLoop(getActivity(), mRingtoneUri);
//                         mRingtone.play();
//                     }
//                 });
//         return super.createFrom(builder);
//     }
// 
//     @Override
//     public void onDismiss(DialogInterface dialog) {
//         super.onDismiss(dialog);
//         destroyLocalPlayer();
//     }
// 
//     @Override
//     public void onSaveInstanceState(Bundle outState) {
//         super.onSaveInstanceState(outState);
//         outState.putParcelable(KEY_RINGTONE_URI, mRingtoneUri);
//     }
// 
//     @Override
//     protected void onOk() {
//         if (mOnRingtoneSelectedListener != null) {
//             // Here, 'which' param refers to the position of the item clicked.
//             mOnRingtoneSelectedListener.onRingtoneSelected(mRingtoneUri);
//         }
//         dismiss();
//     }
// 
//     public void setOnRingtoneSelectedListener(OnRingtoneSelectedListener onRingtoneSelectedListener) {
//         mOnRingtoneSelectedListener = onRingtoneSelectedListener;
//     }
// 
//     private void destroyLocalPlayer() {
//         if (mRingtone != null) {
//             mRingtone.stop();
//             mRingtone = null;
//         }
//     }
// }
// 
// Path: app/src/main/java/com/philliphsu/clock2/dialogs/RingtonePickerDialogController.java
// public class RingtonePickerDialogController extends DialogFragmentController<RingtonePickerDialog> {
//     private static final String TAG = "RingtonePickerCtrller";
// 
//     private final RingtonePickerDialog.OnRingtoneSelectedListener mListener;
// 
//     public RingtonePickerDialogController(FragmentManager fragmentManager, RingtonePickerDialog.OnRingtoneSelectedListener l) {
//         super(fragmentManager);
//         mListener = l;
//     }
// 
//     public void show(Uri initialUri, String tag) {
//         RingtonePickerDialog dialog = RingtonePickerDialog.newInstance(mListener, initialUri);
//         show(dialog, tag);
//     }
// 
//     @Override
//     public void tryRestoreCallback(String tag) {
//         RingtonePickerDialog dialog = findDialog(tag);
//         if (dialog != null) {
//             Log.i(TAG, "Restoring on ringtone selected callback");
//             dialog.setOnRingtoneSelectedListener(mListener);
//         }
//     }
// }


import com.philliphsu.clock2.dialogs.RingtonePickerDialog;
import com.philliphsu.clock2.dialogs.RingtonePickerDialogController;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Parcelable;
import android.preference.RingtonePreference;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.util.AttributeSet;
    }

    @Override
    protected Object onGetDefaultValue(TypedArray a, int index) {
        // Our picker does not show a 'Default' item, so our defaultValue
        // "content://settings/system/alarm_alert" set in XML will not show as initially selected.
        // The default ringtone and its sound file URI is different for every device,
        // so there isn't a string literal we can specify in XML.
        // This is the same as calling:
        //     `RingtoneManager.getActualDefaultRingtoneUri(
        //         getContext(), RingtoneManager.TYPE_ALARM).toString();`
        // but skips the toString().
        return Settings.System.getString(getContext().getContentResolver(), Settings.System.ALARM_ALERT);
    }

    @Override
    public void onRingtoneSelected(Uri uri) {
        if (callChangeListener(uri != null ? uri.toString() : "")) {
            onSaveRingtone(uri);
        }
    }

    @Override
    public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
        return false;
    }

    private RingtonePickerDialogController newController() {
        // TODO: BAD!
        AppCompatActivity a = (AppCompatActivity) getContext();
// Path: app/src/main/java/com/philliphsu/clock2/dialogs/RingtonePickerDialog.java
// public class RingtonePickerDialog extends BaseAlertDialogFragment {
//     private static final String TAG = "RingtonePickerDialog";
//     private static final String KEY_RINGTONE_URI = "key_ringtone_uri";
// 
//     private RingtoneManager mRingtoneManager;
//     private OnRingtoneSelectedListener mOnRingtoneSelectedListener;
//     private Uri mRingtoneUri;
//     private RingtoneLoop mRingtone;
// 
//     public interface OnRingtoneSelectedListener {
//         void onRingtoneSelected(Uri ringtoneUri);
//     }
// 
//     /**
//      * @param ringtoneUri the URI of the ringtone to show as initially selected
//      */
//     public static RingtonePickerDialog newInstance(OnRingtoneSelectedListener l, Uri ringtoneUri) {
//         RingtonePickerDialog dialog = new RingtonePickerDialog();
//         dialog.mOnRingtoneSelectedListener = l;
//         dialog.mRingtoneUri = ringtoneUri;
//         return dialog;
//     }
// 
//     @Override
//     public void onCreate(@Nullable Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         if (savedInstanceState != null) {
//             mRingtoneUri = savedInstanceState.getParcelable(KEY_RINGTONE_URI);
//         }
//         mRingtoneManager = new RingtoneManager(getActivity());
//         mRingtoneManager.setType(RingtoneManager.TYPE_ALARM);
//     }
// 
//     @Override
//     protected AlertDialog createFrom(AlertDialog.Builder builder) {
//         // TODO: We set the READ_EXTERNAL_STORAGE permission. Verify that this includes the user's 
//         // custom ringtone files.
//         Cursor cursor = mRingtoneManager.getCursor();
//         int checkedItem = mRingtoneManager.getRingtonePosition(mRingtoneUri);
//         String labelColumn = cursor.getColumnName(RingtoneManager.TITLE_COLUMN_INDEX);
// 
//         builder.setTitle(R.string.ringtones)
//                 .setSingleChoiceItems(cursor, checkedItem, labelColumn, new DialogInterface.OnClickListener() {
//                     @Override
//                     public void onClick(DialogInterface dialog, int which) {
//                         if (mRingtone != null) {
//                             destroyLocalPlayer();
//                         }
//                         // Here, 'which' param refers to the position of the item clicked.
//                         mRingtoneUri = mRingtoneManager.getRingtoneUri(which);
//                         mRingtone = new RingtoneLoop(getActivity(), mRingtoneUri);
//                         mRingtone.play();
//                     }
//                 });
//         return super.createFrom(builder);
//     }
// 
//     @Override
//     public void onDismiss(DialogInterface dialog) {
//         super.onDismiss(dialog);
//         destroyLocalPlayer();
//     }
// 
//     @Override
//     public void onSaveInstanceState(Bundle outState) {
//         super.onSaveInstanceState(outState);
//         outState.putParcelable(KEY_RINGTONE_URI, mRingtoneUri);
//     }
// 
//     @Override
//     protected void onOk() {
//         if (mOnRingtoneSelectedListener != null) {
//             // Here, 'which' param refers to the position of the item clicked.
//             mOnRingtoneSelectedListener.onRingtoneSelected(mRingtoneUri);
//         }
//         dismiss();
//     }
// 
//     public void setOnRingtoneSelectedListener(OnRingtoneSelectedListener onRingtoneSelectedListener) {
//         mOnRingtoneSelectedListener = onRingtoneSelectedListener;
//     }
// 
//     private void destroyLocalPlayer() {
//         if (mRingtone != null) {
//             mRingtone.stop();
//             mRingtone = null;
//         }
//     }
// }
// 
// Path: app/src/main/java/com/philliphsu/clock2/dialogs/RingtonePickerDialogController.java
// public class RingtonePickerDialogController extends DialogFragmentController<RingtonePickerDialog> {
//     private static final String TAG = "RingtonePickerCtrller";
// 
//     private final RingtonePickerDialog.OnRingtoneSelectedListener mListener;
// 
//     public RingtonePickerDialogController(FragmentManager fragmentManager, RingtonePickerDialog.OnRingtoneSelectedListener l) {
//         super(fragmentManager);
//         mListener = l;
//     }
// 
//     public void show(Uri initialUri, String tag) {
//         RingtonePickerDialog dialog = RingtonePickerDialog.newInstance(mListener, initialUri);
//         show(dialog, tag);
//     }
// 
//     @Override
//     public void tryRestoreCallback(String tag) {
//         RingtonePickerDialog dialog = findDialog(tag);
//         if (dialog != null) {
//             Log.i(TAG, "Restoring on ringtone selected callback");
//             dialog.setOnRingtoneSelectedListener(mListener);
//         }
//     }
// }


// Path: app/src/main/java/com/philliphsu/clock2/settings/ThemedRingtonePreference.java
import com.philliphsu.clock2.dialogs.RingtonePickerDialog;
import com.philliphsu.clock2.dialogs.RingtonePickerDialogController;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Parcelable;
import android.preference.RingtonePreference;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.util.AttributeSet;

    }

    @Override
    protected Object onGetDefaultValue(TypedArray a, int index) {
        // Our picker does not show a 'Default' item, so our defaultValue
        // "content://settings/system/alarm_alert" set in XML will not show as initially selected.
        // The default ringtone and its sound file URI is different for every device,
        // so there isn't a string literal we can specify in XML.
        // This is the same as calling:
        //     `RingtoneManager.getActualDefaultRingtoneUri(
        //         getContext(), RingtoneManager.TYPE_ALARM).toString();`
        // but skips the toString().
        return Settings.System.getString(getContext().getContentResolver(), Settings.System.ALARM_ALERT);
    }

    @Override
    public void onRingtoneSelected(Uri uri) {
        if (callChangeListener(uri != null ? uri.toString() : "")) {
            onSaveRingtone(uri);
        }
    }

    @Override
    public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
        return false;
    }

    private RingtonePickerDialogController newController() {
        // TODO: BAD!
        AppCompatActivity a = (AppCompatActivity) getContext();
        return new RingtonePickerDialogController(a.getSupportFragmentManager(), this);