Java Code Examples for android.support.v4.app.DialogFragment#setTargetFragment()

The following examples show how to use android.support.v4.app.DialogFragment#setTargetFragment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsActivity.java    From Camera-Roll-Android-App with Apache License 2.0 6 votes vote down vote up
@Override
public void onDisplayPreferenceDialog(Preference preference) {
    if (callback != null) {
        callback.onSettingChanged();
    }

    DialogFragment dialogFragment = null;
    if (preference instanceof StylePreference) {
        dialogFragment
                = StylePreferenceDialogFragment
                .newInstance(preference);
    } else if (preference instanceof ColumnCountPreference) {
        dialogFragment
                = ColumnCountPreferenceDialogFragment
                .newInstance(preference);
    }

    if (dialogFragment != null) {
        dialogFragment.setTargetFragment(this, 0);
        dialogFragment.show(this.getFragmentManager(), DIALOG_FRAGMENT_TAG);
        return;
    }

    super.onDisplayPreferenceDialog(preference);
}
 
Example 2
Source File: SpectrumPreferenceCompat.java    From Muzesto with GNU General Public License v3.0 6 votes vote down vote up
public static boolean onDisplayPreferenceDialog(Preference preference, PreferenceFragmentCompat target) {
    boolean handled = false;
    if (target.getTargetFragment() instanceof PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) {
        handled = ((PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) target.getTargetFragment())
                .onPreferenceDisplayDialog(target, preference);
    }
    if (!handled && target.getActivity() instanceof PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) {
        handled = ((PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) target.getActivity())
                .onPreferenceDisplayDialog(target, preference);
    }
    // check if dialog is already showing
    if (!handled && target.getFragmentManager().findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) {
        handled = true;
    }

    if (!handled && preference instanceof SpectrumPreferenceCompat) {
        DialogFragment f = SpectrumPreferenceDialogFragmentCompat.newInstance(preference.getKey());
        f.setTargetFragment(target, 0);
        f.show(target.getFragmentManager(), DIALOG_FRAGMENT_TAG);
        handled = true;
    }
    return handled;
}
 
Example 3
Source File: SettingsFragment.java    From RememBirthday with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDisplayPreferenceDialog(Preference preference) {
    DialogFragment dialogFragment = null;
    if (preference instanceof TimePreference) {
        dialogFragment = new TimePreferenceDialogFragmentCompat();
        Bundle bundle = new Bundle(1);
        bundle.putString("key", preference.getKey());
        dialogFragment.setArguments(bundle);
    }

    // Show dialog
    if (dialogFragment != null) {
        dialogFragment.setTargetFragment(this, 0);
        dialogFragment.show(getChildFragmentManager(), TAG_FRAGMENT_DIALOG);
    } else {
        super.onDisplayPreferenceDialog(preference);
    }
}
 
Example 4
Source File: CorrectedPreferenceFragment.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDisplayPreferenceDialog(Preference preference) {
  DialogFragment dialogFragment = null;

  if (preference instanceof RingtonePreference) {
    dialogFragment = RingtonePreferenceDialogFragmentCompat.newInstance(preference.getKey());
  } else if (preference instanceof ColorPickerPreference) {
    dialogFragment = ColorPickerPreferenceDialogFragmentCompat.newInstance(preference.getKey());
  } else if (preference instanceof CustomDefaultPreference) {
    dialogFragment = CustomDefaultPreference.CustomDefaultPreferenceDialogFragmentCompat.newInstance(preference.getKey());
  }

  if (dialogFragment != null) {
    dialogFragment.setTargetFragment(this, 0);
    dialogFragment.show(getFragmentManager(), "android.support.v7.preference.PreferenceFragment.DIALOG");
  } else {
    super.onDisplayPreferenceDialog(preference);
  }
}
 
Example 5
Source File: SettingsFragment.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDisplayPreferenceDialog(Preference preference) {
    DialogFragment fragment;
    if (preference instanceof DataListPreference) {
        fragment = DataListPreferenceDialogFragmentCompat.newInstance(preference);
        fragment.setTargetFragment(this, 0);
        fragment.show(getFragmentManager(),
                "android.support.v7.preference.PreferenceFragment.DIALOG");
    } else if (preference instanceof ColorPreferenceSupport) {
        fragment = ColorPickerDialogPreference.newInstance(preference.getKey());
        fragment.setTargetFragment(this, 0);
        fragment.show(getFragmentManager(),
                "android.support.v7.preference.PreferenceFragment.DIALOG");
    } else super.onDisplayPreferenceDialog(preference);
}
 
Example 6
Source File: SettingsActivity.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceDisplayDialog(PreferenceFragmentCompat preferenceFragmentCompat, @NonNull Preference preference) {
    final String key = preference.getKey();
    DialogFragment f;
    if (preference instanceof ColorPreference) {
        f = XpColorPreferenceDialogFragment.newInstance(key);
    } else {
        return false;
    }

    f.setTargetFragment(preferenceFragmentCompat, 0);
    f.show(this.getSupportFragmentManager(), key);
    return true;
}
 
Example 7
Source File: SingleRvFragment.java    From ExpandableRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    MyAdapter adapter = (MyAdapter) mRv.getAdapter();
    int id = item.getItemId();
    switch (id) {
        case R.id.action_test:
            DialogFragment dialog =
                    (DialogFragment) getChildFragmentManager().findFragmentByTag("dialog");
            if (dialog == null) dialog = new MyDialog();
            dialog.setTargetFragment(this, REQUEST_RESULT);
            dialog.show(getChildFragmentManager(), "dialog");
            break;
        case R.id.action_refresh:
            adapter.notifyAllChanged();
            break;
        case R.id.action_toggle_expandable_1:
            adapter.toggleExpandable(1);
            break;
        case R.id.action_expand_all:
            adapter.expandAllParents();
            break;
        case R.id.action_collapse_all:
            adapter.collapseAllParents();
            break;
        case R.id.action_expand_1:
            adapter.expandParent(1);
            break;
        case R.id.action_collapse_1:
            adapter.collapseParent(1);
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 8
Source File: MultipleRvFragment.java    From ExpandableRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
        case  R.id.action_test:
            DialogFragment dialog = (DialogFragment) getChildFragmentManager()
                    .findFragmentByTag("dialog");
            if (dialog == null) dialog = new MyDialog();
            dialog.setTargetFragment(this, REQUEST_RESULT);
            dialog.show(getChildFragmentManager(), "dialog");
            break;
        case R.id.action_refresh:
            mAdapter.notifyAllChanged();
            break;
        case R.id.action_toggle_expandable_1:
            mAdapter.toggleExpandable(1);
            break;
        case R.id.action_expand_all:
            mAdapter.expandAllParents();
            break;
        case R.id.action_collapse_all:
            mAdapter.collapseAllParents();
            break;
        case R.id.action_expand_1:
            mAdapter.expandParent(1);
            break;
        case R.id.action_collapse_1:
            mAdapter.collapseParent(1);
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 9
Source File: SettingsFragment.java    From walt with Apache License 2.0 5 votes vote down vote up
@Override
public void onDisplayPreferenceDialog(Preference preference) {
    if (preference instanceof NumberPickerPreference) {
        DialogFragment fragment = NumberPickerPreference.
                NumberPickerPreferenceDialogFragmentCompat.newInstance(preference.getKey());
        fragment.setTargetFragment(this, 0);
        fragment.show(getFragmentManager(),
                "android.support.v7.preference.PreferenceFragment.DIALOG");
    } else {
        super.onDisplayPreferenceDialog(preference);
    }
}
 
Example 10
Source File: AbstractSettingsFragment.java    From android_external_MicroGUiTools with Apache License 2.0 5 votes vote down vote up
@Override
public void onDisplayPreferenceDialog(Preference preference) {
    if (preference instanceof DialogPreference) {
        DialogFragment f = DialogPreference.DialogPreferenceCompatDialogFragment.newInstance(preference.getKey());
        f.setTargetFragment(this, 0);
        f.show(getFragmentManager(), DIALOG_FRAGMENT_TAG);
    } else {
        super.onDisplayPreferenceDialog(preference);
    }
}
 
Example 11
Source File: PreferenceFragmentCompatHack.java    From ChipHellClient with Apache License 2.0 5 votes vote down vote up
/**
 * Displays preference dialogs which aren't supported by default in PreferenceFragmentCompat.
 *
 * @return true if we managed a preference which isn't supported by default, false otherwise.
 */
public static boolean onDisplayPreferenceDialog(PreferenceFragmentCompat preferenceFragmentCompat, Preference preference) {
    DialogFragment dialogFragment = (DialogFragment) preferenceFragmentCompat.getFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
    if (dialogFragment != null) return false;


    // Hack to allow a MultiSelectListPreference
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH
            && preference instanceof MultiSelectListPreference) {
        dialogFragment = MultiSelectListPreferenceDialogFragmentCompat.newInstance(preference.getKey());
    }
    // Hack to allow a PasswordPreference
    //else if (preference instanceof PasswordPreference) {
    //    dialogFragment = PasswordPreferenceDialogFragmentCompat.newInstance(preference.getKey());
    //}


    // We've created our own fragment:
    if (dialogFragment != null) {
        dialogFragment.setTargetFragment(preferenceFragmentCompat, 0);
        dialogFragment.show(preferenceFragmentCompat.getFragmentManager(), FRAGMENT_TAG_DIALOG);
        return true;
    }


    return false;
}
 
Example 12
Source File: PreferencesFragment.java    From ShaderEditor with MIT License 5 votes vote down vote up
@Override
public void onDisplayPreferenceDialog(Preference preference) {
	if (preference instanceof ShaderListPreference) {
		DialogFragment f = ShaderListPreferenceDialogFragment
				.newInstance(preference.getKey());

		f.setTargetFragment(this, 0);
		f.show(getFragmentManager(),
				"ShaderListPreferenceDialogFragment");

		return;
	}

	super.onDisplayPreferenceDialog(preference);
}
 
Example 13
Source File: UTilitiesPreferenceFragment.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
@Override
public void onDisplayPreferenceDialog(Preference preference) {
    final String DIALOG_FRAGMENT_TAG =
            "android.support.v7.preference.PreferenceFragment.DIALOG";
    if (preference.getKey().equals("password")) {
        DialogFragment f = PasswordEditTextPreferenceDialogFragmentCompat.newInstance(preference.getKey());
        f.setTargetFragment(this, 0);
        f.show(getFragmentManager(), DIALOG_FRAGMENT_TAG);
    }  else {
        super.onDisplayPreferenceDialog(preference);
    }
}