當前位置: 首頁>>代碼示例>>Java>>正文


Java Fragment.getActivity方法代碼示例

本文整理匯總了Java中android.app.Fragment.getActivity方法的典型用法代碼示例。如果您正苦於以下問題:Java Fragment.getActivity方法的具體用法?Java Fragment.getActivity怎麽用?Java Fragment.getActivity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.Fragment的用法示例。


在下文中一共展示了Fragment.getActivity方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: stopApplication

import android.app.Fragment; //導入方法依賴的package包/類
public static void stopApplication(final Fragment fragment) {
	final String tag = "stopApplication - ";
	final int waitTime = 5000;

	Analytics.getInstance().logEvent(TAG, "stopApplication", "");

	if (fragment != null && fragment.getActivity() != null) {
		fragment.getActivity().finish();

		try {
			Thread.sleep(waitTime);
		} catch (InterruptedException e) {
			Log.e(TAG,tag,e);
		}
	}

	System.exit(0);
}
 
開發者ID:videgro,項目名稱:Ships,代碼行數:19,代碼來源:FragmentUtils.java

示例2: setParentFragmentHint

import android.app.Fragment; //導入方法依賴的package包/類
/**
 * Sets a hint for which fragment is our parent which allows the fragment to return correct
 * information about its parents before pending fragment transactions have been executed.
 */
void setParentFragmentHint(Fragment parentFragmentHint) {
  this.parentFragmentHint = parentFragmentHint;
  if (parentFragmentHint != null && parentFragmentHint.getActivity() != null) {
    registerFragmentWithRoot(parentFragmentHint.getActivity());
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:RequestManagerFragment.java

示例3: parse

import android.app.Fragment; //導入方法依賴的package包/類
/**
 * 透過Fragment解析LKUI注解
 * 可以通過注解配置contentView,field的id等
 */
public static View parse(Fragment fragment, LayoutInflater inflater, ViewGroup container, boolean ignoreNoFindViewField) {
    View rView = null;
    try {
        // 解析類注解:SetContentView
        SetContentView setContentView = fragment.getClass().getAnnotation(SetContentView.class);
        if (setContentView != null && setContentView.value() > 0)
            // 可以讀到SetContentView的layout的id值
            rView = inflater.inflate(setContentView.value(), container, false);
        // 解析屬性注解:FindView
        Field[] fields = fragment.getClass().getDeclaredFields();
        for (Field fieldItem : fields) {
            fieldItem.setAccessible(true);
            if (!(View.class.isAssignableFrom(fieldItem.getType())))
                continue;
            FindView findView = fieldItem.getAnnotation(FindView.class);
            if (findView != null)
                // 配置了FindView注解
                if (findView.value() > 0)
                    fieldItem.set(fragment, container.findViewById(findView.value()));
                else // 如果沒有設置view的id,那麽自動嘗試以屬性名作為id進行查詢賦值
                    fieldItem.set(fragment, LKResourceTool.findViewByIdStr(rView, fieldItem.getName()));
            else if (!ignoreNoFindViewField)// 沒有配置FindView注解並且沒有設置忽略無注解屬性(ignoreNoFindViewField為false),嘗試以屬性名作為id,進行查詢賦值
                fieldItem.set(fragment, LKResourceTool.findViewByIdStr(rView, fieldItem.getName()));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rView == null ? new View(fragment.getActivity()) : rView;
}
 
開發者ID:LemonAppCN,項目名稱:LemonKit4Android,代碼行數:34,代碼來源:LKUIAnnotationParser.java

示例4: forFragment

import android.app.Fragment; //導入方法依賴的package包/類
/**
 * @param fragment {@link Fragment} invoking the integration.
 *                 {@link #startActivityForResult(Intent, int)} will be called on the {@link Fragment} instead
 *                 of an {@link Activity}
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static IntentIntegrator forFragment(Fragment fragment) {
    IntentIntegrator integrator = new IntentIntegrator(fragment.getActivity());
    integrator.fragment = fragment;
    return integrator;
}
 
開發者ID:yinhaojun,項目名稱:ZxingForAndroid,代碼行數:12,代碼來源:IntentIntegrator.java

示例5: Overlay

import android.app.Fragment; //導入方法依賴的package包/類
/**
 * Must be created from the Fragment onViewCreated() method
 * @param fragment
 */
public Overlay(Fragment fragment) {

    if (!fragment.isAdded()) {
        throw new IllegalStateException("Overlay must be created once the fragment is added!");
    }

    mContext = fragment.getActivity();
    ViewGroup fragmentView = (ViewGroup)fragment.getView();
    if (fragmentView==null) {
        throw new IllegalStateException("Overlay must be created once the fragment has its view created!");
    }

    int parentViewId = -1;
    if (fragment instanceof BrowseFragment) {
        parentViewId = R.id.browse_frame;
    } else if (fragment instanceof MyVerticalGridFragment) {
        parentViewId = R.id.browse_dummy;
    } else if (fragment instanceof DetailsFragment) {
        parentViewId = R.id.details_fragment_root;
    } else if (fragment instanceof GuidedStepFragment) {
        parentViewId = R.id.guidedstep_background_view_root;
    } else {
        throw new IllegalStateException("Overlay is not compatible with this fragment: "+fragment);
    }

    ViewGroup parentView = (ViewGroup)fragmentView.findViewById(parentViewId);
    if (parentView==null) {
        throw new IllegalStateException("parentView not found! Maybe IDs in the leanback library have been changed?");
    }

    LayoutInflater.from(mContext).inflate(R.layout.leanback_overlay, parentView);
    mOverlayRoot = parentView.findViewById(R.id.overlay_root);
    mScanProgress = new ScannerAndScraperProgress(mContext, mOverlayRoot);
    mClock = new Clock(mContext, mOverlayRoot);
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:40,代碼來源:Overlay.java

示例6: camera

import android.app.Fragment; //導入方法依賴的package包/類
/**
 * Open the camera from the activity.
 */
public static Camera<ImageCameraWrapper, VideoCameraWrapper> camera(Fragment fragment) {
    return new AlbumCamera(fragment.getActivity());
}
 
開發者ID:WeiXinqiao,項目名稱:Recognize-it,代碼行數:7,代碼來源:Album.java

示例7: image

import android.app.Fragment; //導入方法依賴的package包/類
/**
 * Select images.
 */
public static Choice<ImageMultipleWrapper, ImageSingleWrapper> image(Fragment fragment) {
    return new ImageChoice(fragment.getActivity());
}
 
開發者ID:WeiXinqiao,項目名稱:Recognize-it,代碼行數:7,代碼來源:Album.java

示例8: get

import android.app.Fragment; //導入方法依賴的package包/類
public static DocumentsActivity get(Fragment fragment) {
    return (DocumentsActivity) fragment.getActivity();
}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:4,代碼來源:DocumentsActivity.java

示例9: IntentIntegrator

import android.app.Fragment; //導入方法依賴的package包/類
/**
 * @param fragment {@link Fragment} invoking the integration.
 *  {@link #startActivityForResult(Intent, int)} will be called on the {@link Fragment} instead
 *  of an {@link Activity}
 */
public IntentIntegrator(Fragment fragment) {
    this.activity = fragment.getActivity();
    this.fragment = fragment;
    initializeConfiguration();
}
 
開發者ID:sd1998,項目名稱:QR-Code-Reader,代碼行數:11,代碼來源:IntentIntegrator.java

示例10: album

import android.app.Fragment; //導入方法依賴的package包/類
/**
 * Select images and videos.
 */
public static Choice<AlbumMultipleWrapper, AlbumSingleWrapper> album(Fragment fragment) {
    return new AlbumChoice(fragment.getActivity());
}
 
開發者ID:WeiXinqiao,項目名稱:Recognize-it,代碼行數:7,代碼來源:Album.java

示例11: IntentIntegrator

import android.app.Fragment; //導入方法依賴的package包/類
/**
 * @param fragment {@link Fragment} invoking the integration.
 *                 {@link #startActivityForResult(Intent, int)} will be called on the {@link Fragment} instead
 *                 of an {@link Activity}
 */
public IntentIntegrator(Fragment fragment) {
    this.activity = fragment.getActivity();
    this.fragment = fragment;
    initializeConfiguration();
}
 
開發者ID:anikraj1994,項目名稱:Remote,代碼行數:11,代碼來源:IntentIntegrator.java

示例12: init

import android.app.Fragment; //導入方法依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public static SmartAdapterBuilder init(@NonNull Fragment caller) {
    return new SmartAdapterBuilder(caller, caller.getActivity());
}
 
開發者ID:manneohlund,項目名稱:smart-recycler-adapter,代碼行數:5,代碼來源:SmartRecyclerAdapter.java

示例13: FragmentCallImpl

import android.app.Fragment; //導入方法依賴的package包/類
FragmentCallImpl(Fragment fragment) {
  super(fragment.getActivity());
  this.fragment = fragment;
}
 
開發者ID:BiaoWu,項目名稱:IntentRouter,代碼行數:5,代碼來源:FragmentCallImpl.java

示例14: get

import android.app.Fragment; //導入方法依賴的package包/類
public static BaseActivity get(Fragment fragment) {
    return (BaseActivity) fragment.getActivity();
}
 
開發者ID:gigabytedevelopers,項目名稱:FireFiles,代碼行數:4,代碼來源:StandaloneActivity.java

示例15: galleryAlbum

import android.app.Fragment; //導入方法依賴的package包/類
/**
 * Preview Album.
 */
public static BasicGalleryWrapper<GalleryAlbumWrapper, AlbumFile, String, AlbumFile> galleryAlbum(Fragment fragment) {
    return new GalleryAlbumWrapper(fragment.getActivity());
}
 
開發者ID:WeiXinqiao,項目名稱:Recognize-it,代碼行數:7,代碼來源:Album.java


注:本文中的android.app.Fragment.getActivity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。