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:org.solovyev.android.calculator.FragmentUi.java

public void onViewCreated(@Nonnull Fragment fragment, @Nonnull View root) {
    adView = (AdView) root.findViewById(R.id.ad);
    final ViewGroup mainFragmentLayout = (ViewGroup) root.findViewById(R.id.main_fragment_layout);

    if (fragment instanceof CalculatorDisplayFragment || fragment instanceof CalculatorEditorFragment
            || fragment instanceof CalculatorKeyboardFragment) {
        // no ads in those fragments
    } else {//from  w  w  w.j av a2 s . com
        if (adView != null) {
            updateAdViewState();
        } else if (mainFragmentLayout != null) {
        }
    }

    if (fragment instanceof CalculatorKeyboardFragment) {
        processButtons(fragment.getActivity(), root);
    }
    fixFonts(root);

    if (titleResId >= 0) {
        this.setPaneTitle(fragment, titleResId);
    }
}

From source file:org.alfresco.mobile.android.application.fragments.fileexplorer.FileActions.java

private void send(Fragment fragment, List<File> selectedFiles) {
    Intent pickResult = new Intent();
    if (selectedFiles.size() == 0) {
        pickResult.setData(Uri.fromFile(selectedFiles.get(0)));
    } else if (selectedFiles.size() > 0) {
        ArrayList<Uri> uris = new ArrayList<Uri>();
        for (File file : selectedFiles) {
            Uri u = Uri.fromFile(file);/* w  w w. java2  s. c  o  m*/
            uris.add(u);
        }
        pickResult.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    }
    fragment.getActivity().setResult(FragmentActivity.RESULT_OK, pickResult);
    fragment.getActivity().finish();

}

From source file:com.mapia.asne.facebook.FacebookSocialNetwork.java

public FacebookSocialNetwork(Fragment fragment, ArrayList<String> permissions) {
    super(fragment);
    String applicationID = Utility.getMetadataApplicationId(fragment.getActivity());

    if (applicationID == null) {
        throw new IllegalStateException("applicationID can't be null\n"
                + "Please check https://developers.facebook.com/docs/android/getting-started/");
    }//from www.  j a  v a  2 s  . c o m
    this.permissions = permissions;
}

From source file:com.github.gorbin.asne.facebook.FacebookSocialNetwork.java

public FacebookSocialNetwork(Fragment fragment, ArrayList<String> permissions) {
    super(fragment);
    this.fragment = fragment;
    FacebookSdk.sdkInitialize(fragment.getActivity().getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
    shareDialog = new ShareDialog(fragment.getActivity());
    shareDialog.registerCallback(callbackManager, ShareCallBack);
    String applicationID = Utility.getMetadataApplicationId(fragment.getActivity());

    if (applicationID == null) {
        throw new IllegalStateException("applicationID can't be null\n"
                + "Please check https://developers.facebook.com/docs/android/getting-started/");
    }/* w w  w  .  j a v a 2  s . c  om*/
    this.permissions = permissions;
}

From source file:com.todoroo.astrid.adapter.UpdateAdapter.java

public static void setupImagePopupForCommentView(View view, AsyncImageView commentPictureView,
        final String pictureThumb, final String pictureFull, final Bitmap updateBitmap, final String message,
        final Fragment fragment, ImageCache imageCache) {
    if ((!TextUtils.isEmpty(pictureThumb) && !"null".equals(pictureThumb)) || updateBitmap != null) { //$NON-NLS-1$
        commentPictureView.setVisibility(View.VISIBLE);
        if (updateBitmap != null)
            commentPictureView.setImageBitmap(updateBitmap);
        else//from  w  w w  .  java2 s  .c  o  m
            commentPictureView.setUrl(pictureThumb);

        if (pictureThumb != null && imageCache.contains(pictureThumb) && updateBitmap == null) {
            try {
                commentPictureView.setDefaultImageBitmap(imageCache.get(pictureThumb));
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else if (updateBitmap == null) {
            commentPictureView.setUrl(pictureThumb);
        }

        view.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog image = new AlertDialog.Builder(fragment.getActivity()).create();
                AsyncImageView imageView = new AsyncImageView(fragment.getActivity());
                imageView
                        .setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
                imageView.setDefaultImageResource(android.R.drawable.ic_menu_gallery);
                if (updateBitmap != null)
                    imageView.setImageBitmap(updateBitmap);
                else
                    imageView.setUrl(pictureFull);
                image.setView(imageView);

                image.setMessage(message);
                image.setButton(fragment.getString(R.string.DLG_close), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        return;
                    }
                });
                image.show();
            }
        });
    } else {
        commentPictureView.setVisibility(View.GONE);
    }
}

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

public ProgressNodeAdapter(Fragment fr, int textViewResourceId, Node parentNode, List<Node> listItems,
        List<Node> selectedItems, int mode) {
    super(fr, textViewResourceId, listItems, selectedItems, mode);
    vhClassName = TwoLinesProgressViewHolder.class.getCanonicalName();
    this.parentNode = parentNode;
    if (parentNode != null) {
        fr.getActivity().getSupportLoaderManager().restartLoader(LOADER_OPERATION_ID, null, this);
        fr.getActivity().getSupportLoaderManager().restartLoader(LOADER_SYNC_ID, null, this);
        fr.getActivity().getSupportLoaderManager().restartLoader(LOADER_FAVORITE_ID, null, this);
        hasParentFavorite();/* w  w  w  . j a  v  a  2s .  c o  m*/
    }
}

From source file:com.todoroo.astrid.adapter.UpdateAdapter.java

/**
 * Constructor//from ww  w.ja  v  a  2 s . co m
 *
 * @param activity
 * @param resource
 *            layout resource to inflate
 * @param c
 *            database cursor
 * @param autoRequery
 *            whether cursor is automatically re-queried on changes
 * @param onCompletedTaskListener
 *            goal listener. can be null
 */
public UpdateAdapter(Fragment fragment, int resource, Cursor c, boolean autoRequery, String fromView) {
    super(fragment.getActivity(), c, autoRequery);
    DependencyInjectionService.getInstance().inject(this);

    linkColor = getLinkColor(fragment);

    inflater = (LayoutInflater) fragment.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageCache = AsyncImageView.getImageCache();
    this.fromView = fromView;

    this.resource = resource;
    this.fragment = fragment;
    this.self = getSelfUser();

    TypedValue tv = new TypedValue();
    fragment.getActivity().getTheme().resolveAttribute(R.attr.asTextColor, tv, false);
    color = tv.data;

    fragment.getActivity().getTheme().resolveAttribute(R.attr.asDueDateColor, tv, false);
    grayColor = tv.data;
}

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

@Override
@SuppressWarnings("unchecked")
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "class comparison with == is done")
public void onCall(@Nonnull final List<? extends INPUT> inputs, @Nonnull final ResultChannel<OUTPUT> result) {

    final Logger logger = mLogger;
    final Object context = mContext.get();

    if (context == null) {

        logger.dbg("avoiding running invocation since context is null");
        return;//from w ww.j  av a  2 s.  c o  m
    }

    final Context loaderContext;
    final LoaderManager loaderManager;

    if (context instanceof FragmentActivity) {

        final FragmentActivity activity = (FragmentActivity) context;
        loaderContext = activity.getApplicationContext();
        loaderManager = activity.getSupportLoaderManager();
        logger.dbg("running invocation bound to activity: %s", activity);

    } else if (context instanceof Fragment) {

        final Fragment fragment = (Fragment) context;
        loaderContext = fragment.getActivity().getApplicationContext();
        loaderManager = fragment.getLoaderManager();
        logger.dbg("running invocation bound to fragment: %s", fragment);

    } else {

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

    int loaderId = mLoaderId;

    if (loaderId == ContextRoutineBuilder.AUTO) {

        loaderId = mConstructor.getDeclaringClass().hashCode();

        for (final Object arg : mArgs) {

            loaderId = 31 * loaderId + recursiveHashCode(arg);
        }

        loaderId = 31 * loaderId + inputs.hashCode();
        logger.dbg("generating invocation ID: %d", loaderId);
    }

    final Loader<InvocationResult<OUTPUT>> loader = loaderManager.getLoader(loaderId);
    final boolean isClash = isClash(loader, loaderId, inputs);
    final WeakIdentityHashMap<Object, SparseArray<WeakReference<RoutineLoaderCallbacks<?>>>> callbackMap = sCallbackMap;
    SparseArray<WeakReference<RoutineLoaderCallbacks<?>>> callbackArray = callbackMap.get(context);

    if (callbackArray == null) {

        callbackArray = new SparseArray<WeakReference<RoutineLoaderCallbacks<?>>>();
        callbackMap.put(context, callbackArray);
    }

    final WeakReference<RoutineLoaderCallbacks<?>> callbackReference = callbackArray.get(loaderId);
    RoutineLoaderCallbacks<OUTPUT> callbacks = (callbackReference != null)
            ? (RoutineLoaderCallbacks<OUTPUT>) callbackReference.get()
            : null;

    if ((callbacks == null) || (loader == null) || isClash) {

        final RoutineLoader<INPUT, OUTPUT> routineLoader;

        if (!isClash && (loader != null) && (loader.getClass() == RoutineLoader.class)) {

            routineLoader = (RoutineLoader<INPUT, OUTPUT>) loader;

        } else {

            routineLoader = null;
        }

        final RoutineLoaderCallbacks<OUTPUT> newCallbacks = createCallbacks(loaderContext, loaderManager,
                routineLoader, inputs, loaderId);

        if (callbacks != null) {

            logger.dbg("resetting existing callbacks [%d]", loaderId);
            callbacks.reset();
        }

        callbackArray.put(loaderId, new WeakReference<RoutineLoaderCallbacks<?>>(newCallbacks));
        callbacks = newCallbacks;
    }

    logger.dbg("setting result cache type [%d]: %s", loaderId, mCacheStrategyType);
    callbacks.setCacheStrategy(mCacheStrategyType);

    final OutputChannel<OUTPUT> outputChannel = callbacks.newChannel();

    if (isClash) {

        logger.dbg("restarting loader [%d]", loaderId);
        loaderManager.restartLoader(loaderId, Bundle.EMPTY, callbacks);

    } else {

        logger.dbg("initializing loader [%d]", loaderId);
        loaderManager.initLoader(loaderId, Bundle.EMPTY, callbacks);
    }

    result.pass(outputChannel);
}

From source file:com.supremainc.biostar2.widget.FilterView.java

public FilterView(LayoutInflater inflater, Fragment fragment, ViewGroup parentView, Popup popup) {
    mFilterView = (LinearLayout) inflater.inflate(R.layout.view_filter, null);
    mFilterView.setOnClickListener(new OnSingleClickListener() {
        @Override//from   w  w w  . j a v  a 2 s .  c  om
        public void onSingleClick(View v) {
        }
    });
    this.mParentView = parentView;
    this.mContext = fragment;
    this.mActivity = fragment.getActivity();
    mDateTimePicker = new DateTimePicker(mActivity);
    mPopup = popup;
    mFormat = new DecimalFormat("00");
    mTimeConvertProvider = TimeConvertProvider.getInstance(mActivity);
    mDateStart = (StyledTextView) mFilterView.findViewById(R.id.filter_date_start);
    mDateEnd = (StyledTextView) mFilterView.findViewById(R.id.filter_date_end);
    mTimeStart = (StyledTextView) mFilterView.findViewById(R.id.filter_time_start);
    mTimeEnd = (StyledTextView) mFilterView.findViewById(R.id.filter_time_end);

    initDateTime();

    mUserView = (StyledTextView) mFilterView.findViewById(R.id.filter_user);
    mUserMoreView = (StyledTextView) mFilterView.findViewById(R.id.filter_user_more);
    mUserPlusView = (StyledTextView) mFilterView.findViewById(R.id.filter_user_plus);
    mDeviceView = (StyledTextView) mFilterView.findViewById(R.id.filter_device);
    mDeviceMoreView = (StyledTextView) mFilterView.findViewById(R.id.filter_device_more);
    mDevicePlusView = (StyledTextView) mFilterView.findViewById(R.id.filter_device_plus);
    mEventView = (StyledTextView) mFilterView.findViewById(R.id.filter_event);
    mEventMoreView = (StyledTextView) mFilterView.findViewById(R.id.filter_event_more);
    mEventPlusView = (StyledTextView) mFilterView.findViewById(R.id.filter_event_plus);

    mSelectDevicePopup = new SelectPopup<ListDevice>(mActivity, mPopup);
    mSelectUserPopup = new SelectPopup<ListUser>(mActivity, mPopup);
    mSelectEventPopup = new SelectPopup<EventType>(mActivity, mPopup);
    int[] ids = { R.id.filter_date_edit, R.id.filter_time_edit, R.id.filter_user_edit, R.id.filter_device_edit,
            R.id.filter_event_edit };
    for (int i : ids) {
        mFilterView.findViewById(i).setOnClickListener(mButtonClickListener);
    }

    View[] views = { mDateStart, mDateEnd, mTimeStart, mTimeEnd };
    for (View v : views) {
        v.setOnClickListener(mButtonClickListener);
    }
}

From source file:com.pizidea.imagepicker.AndroidImagePicker.java

/**
 * take picture//from  w w w  .  ja va2  s.  co m
 */
public void takePicture(Fragment fragment, int requestCode) throws IOException {

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    //Intent takePictureIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
    takePictureIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(fragment.getActivity().getPackageManager()) != null) {
        // Create the File where the photo should go
        //File photoFile = createImageFile();
        File photoFile = createImageSaveFile(fragment.getActivity());
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
            Log.i(TAG, "=====file ready to take photo:" + photoFile.getAbsolutePath());
        }
    }
    fragment.startActivityForResult(takePictureIntent, requestCode);

}