Example usage for android.support.v4.app Fragment getActivity

List of usage examples for android.support.v4.app Fragment getActivity

Introduction

In this page you can find the example usage for android.support.v4.app Fragment getActivity.

Prototype

public Activity getActivity() 

Source Link

Usage

From source file:io.nuclei.cyto.share.PackageTargetManager.java

/**
 * Send the startActivityForResult intent to an activity
 *
 * @param requestCode The request code to listen to in the onActivityResult
 *//*  ww  w  .ja va 2s  . c o m*/
public void onShare(Fragment fragment, Intent intent, int requestCode) {
    if (mWeights == null)
        mWeights = fragment.getActivity().getSharedPreferences(DEFAULT_SHARE_WEIGHTS, Context.MODE_PRIVATE);
    int weight = mWeights.getInt(intent.getComponent().getClassName(), 0) + 1;
    mWeights.edit().putInt(intent.getComponent().getClassName(), weight).apply();
    fragment.startActivityForResult(intent, requestCode);
}

From source file:com.Jsu.framework.image.imageChooser.BChooser.java

public BChooser(Fragment fragment, int type, boolean shouldCreateThumbnails) {
    this.fragment = fragment;
    this.type = type;
    this.shouldCreateThumbnails = shouldCreateThumbnails;
    initDirectory(fragment.getActivity().getApplicationContext());
}

From source file:com.gh.bmd.jrt.android.v4.core.DefaultContextRoutine.java

@Nonnull
@Override/*from  w  w  w. j av a 2s.  com*/
protected Invocation<INPUT, OUTPUT> newInvocation(final boolean async) {

    final Logger logger = getLogger();

    if (async) {

        return new LoaderInvocation<INPUT, OUTPUT>(mContext, mInvocationId, mClashResolutionType,
                mCacheStrategyType, mConstructor, mArgs, mOrderType, logger);
    }

    final Object context = mContext.get();

    if (context == null) {

        throw new IllegalStateException("the routine context has been destroyed");
    }

    final Context appContext;

    if (context instanceof FragmentActivity) {

        final FragmentActivity activity = (FragmentActivity) context;
        appContext = activity.getApplicationContext();

    } else if (context instanceof Fragment) {

        final Fragment fragment = (Fragment) context;
        appContext = fragment.getActivity().getApplicationContext();

    } else {

        throw new IllegalArgumentException("invalid context type: " + context.getClass().getCanonicalName());
    }

    try {

        final Constructor<? extends ContextInvocation<INPUT, OUTPUT>> constructor = mConstructor;
        logger.dbg("creating a new instance of class: %s", constructor.getDeclaringClass());
        final ContextInvocation<INPUT, OUTPUT> invocation = constructor.newInstance(mArgs);
        invocation.onContext(appContext);
        return invocation;

    } catch (final RoutineException e) {

        logger.err(e, "error creating the invocation instance");
        throw e;

    } catch (final Throwable t) {

        logger.err(t, "error creating the invocation instance");
        throw new InvocationException(t);
    }
}

From source file:com.Jsu.framework.image.imageChooser.BChooser.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public BChooser(android.app.Fragment fragment, int type, boolean shouldCreateThumbnails) {
    this.appFragment = fragment;
    this.type = type;
    this.shouldCreateThumbnails = shouldCreateThumbnails;
    initDirectory(fragment.getActivity().getApplicationContext());
}

From source file:org.alfresco.mobile.android.ui.activitystream.ActivityStreamAdapter.java

public ActivityStreamAdapter(Fragment fr, int textViewResourceId, List<ActivityEntry> listItems,
        List<ActivityEntry> selectedItems) {
    super(fr.getActivity(), textViewResourceId, listItems);
    this.vhClassName = TwoLinesCaptionViewHolder.class.getCanonicalName();
    this.selectedItems = selectedItems;
    this.activityRef = new WeakReference<>(fr.getActivity());
}

From source file:org.alfresco.mobile.android.application.fragments.sync.SyncCursorAdapter.java

public SyncCursorAdapter(Fragment fr, Cursor c, int layoutResourceId, List<String> selectedItems, int mode) {
    super(fr.getActivity(), c, layoutResourceId);
    this.fragmentRef = new WeakReference<Fragment>(fr);
    this.selectedItems = selectedItems;
    this.mode = mode;
    vhClassName = TwoLinesProgressViewHolder.class.getCanonicalName();
    hasSynchroActive = SyncContentManager.getInstance(fr.getActivity())
            .hasActivateSync(SessionUtils.getAccount(context));
}

From source file:org.alfresco.mobile.android.application.fragments.node.browser.NodeAdapter.java

public NodeAdapter(Fragment fr, int textViewResourceId, List<Node> listItems, boolean isEditable) {
    super(fr.getActivity(), textViewResourceId, listItems);
    this.fragmentRef = new WeakReference<>(fr);
    this.renditionManager = RenditionManagerImpl.getInstance(fr.getActivity());
    this.vhClassName = TwoLinesProgressViewHolder.class.getCanonicalName();
    this.isEditable = isEditable;
    this.activityRef = new WeakReference<>(fr.getActivity());
}

From source file:com.github.chilinh.android.form.Form.java

public void buildToFragment(Fragment fragment, final Callback.Submit<Fragment> submitCb) {
    View view = fragment.getView();
    FragmentManager fm = fragment.getActivity().getSupportFragmentManager();
    FormModelFragment model = (FormModelFragment) fm.findFragmentByTag(FORM_FRAGMENT_MODEL);
    if (model == null) {
        model = new FormModelFragment();
        fm.beginTransaction().add(model, FORM_FRAGMENT_MODEL).commit();
    }// w  ww.  j  av  a2s .c o  m
    mModel = model;

    if (TextUtils.isEmpty(mSubmitBtn)) {
        mSubmitBtn = "Summit";
    }

    ViewGroup group = (ViewGroup) view.findViewById(R.id.form_elements_container);
    makeFormView(group);

    View submitBtn = view.findViewById(R.id.button_form_submit);
    if (submitBtn != null) {
        submitBtn.setClickable(true);
        submitBtn.setFocusable(true);

        submitBtn.setOnClickListener((v) -> {
            if (validate(mContext)) {
                if (submitCb != null) {
                    if (submitCb.validate(fragment, Form.this)) {
                        submitCb.onSubmit(fragment, Form.this);
                    }
                    return;
                }
            }
        });
    }
}

From source file:codewrencher.gifit.tools.RequestPermissionConfirmationDialog.java

/**
 * On class instance created callback//from w  w w .  j ava2  s  . c  om
 * @param savedInstanceState: Stores saved parameters
 * @return
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Fragment parent = getParentFragment();
    return new AlertDialog.Builder(getActivity()).setMessage(getArguments().getString(ARG_MESSAGE))
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ActivityCompat.requestPermissions(parent.getActivity(),
                            new String[] { getArguments().getString(ARG_PERMISSION) },
                            getArguments().getInt(ARG_PERMISSION_INDEX));
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Activity activity = parent.getActivity();
                    if (activity != null) {
                        activity.finish();
                    }
                }
            }).create();
}

From source file:org.alfresco.mobile.android.application.fragments.node.browser.NodeAdapter.java

public NodeAdapter(Fragment fr, int textViewResourceId, List<Node> listItems, List<Node> selectedItems,
        int mode) {
    super(fr.getActivity(), textViewResourceId, listItems);
    this.fragmentRef = new WeakReference<>(fr);
    originalNodes = Collections.synchronizedList(listItems);
    this.selectedItems = selectedItems;
    this.renditionManager = RenditionManagerImpl.getInstance(fr.getActivity());
    this.mode = mode;
    this.vhClassName = TwoLinesProgressViewHolder.class.getCanonicalName();
    this.activityRef = new WeakReference<>(fr.getActivity());
    this.gridFragment = (BaseGridFragment) fr;
}