本文整理汇总了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);
}
示例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());
}
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
示例7: image
import android.app.Fragment; //导入方法依赖的package包/类
/**
* Select images.
*/
public static Choice<ImageMultipleWrapper, ImageSingleWrapper> image(Fragment fragment) {
return new ImageChoice(fragment.getActivity());
}
示例8: get
import android.app.Fragment; //导入方法依赖的package包/类
public static DocumentsActivity get(Fragment fragment) {
return (DocumentsActivity) fragment.getActivity();
}
示例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();
}
示例10: album
import android.app.Fragment; //导入方法依赖的package包/类
/**
* Select images and videos.
*/
public static Choice<AlbumMultipleWrapper, AlbumSingleWrapper> album(Fragment fragment) {
return new AlbumChoice(fragment.getActivity());
}
示例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();
}
示例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());
}
示例13: FragmentCallImpl
import android.app.Fragment; //导入方法依赖的package包/类
FragmentCallImpl(Fragment fragment) {
super(fragment.getActivity());
this.fragment = fragment;
}
示例14: get
import android.app.Fragment; //导入方法依赖的package包/类
public static BaseActivity get(Fragment fragment) {
return (BaseActivity) fragment.getActivity();
}
示例15: galleryAlbum
import android.app.Fragment; //导入方法依赖的package包/类
/**
* Preview Album.
*/
public static BasicGalleryWrapper<GalleryAlbumWrapper, AlbumFile, String, AlbumFile> galleryAlbum(Fragment fragment) {
return new GalleryAlbumWrapper(fragment.getActivity());
}