List of usage examples for android.support.v4.app Fragment getActivity
public Activity getActivity()
From source file:com.github.gorbin.asne.vk.VkSocialNetwork.java
public VkSocialNetwork(Fragment fragment, String key, String[] permissions) { super(fragment); this.mKey = key; this.mPermissions = permissions; this.mActivity = fragment.getActivity(); int wat = Integer.parseInt(mKey); vkAccessTokenTracker.startTracking(); VKSdk.customInitialize(mActivity.getApplicationContext(), wat, null);// initialize(mActivity.getApplicationContext()); }
From source file:com.usepropeller.routable.Router.java
public void openForResult(String url, Bundle extras, Fragment fragment, int requestCode, int intentFlags, Intent o) {//from ww w . j ava 2 s . c o m if (fragment == null) { throw new ContextNotProvided("You need to supply a fragment for Router" + this.toString()); } RouterParams params = this.paramsForUrl(url); RouterOptions options = params.routerOptions; checkState(options.getCallback() == null, "openForResult cannot be used for callback routes"); Intent intent = this.intentFor(fragment.getActivity(), url, o); if (intent == null) { // Means the options weren't opening a new activity return; } if (extras != null) { intent.putExtras(extras); } intent.addFlags(intentFlags); fragment.getActivity().startActivityFromFragment(fragment, intent, requestCode); }
From source file:com.dalaran.annotation.validator.Validator.java
public boolean validate(Fragment a) { Field[] declaredFields = a.getClass().getDeclaredFields(); boolean valid = false; for (Field field : declaredFields) { Annotation[] annotations = field.getAnnotations(); for (Annotation annotation : annotations) { if (annotation.annotationType().equals(Length.class)) { boolean b = checkToValidate(a, field, (Length) annotation); if (b) { valid = b;//from w ww .ja v a2 s.c o m } } if (annotation.annotationType().equals(Email.class)) { boolean b = checkToValidateEmail(a, field, (Email) annotation); if (b) { valid = b; } } if (annotation.annotationType().equals(EqualsWith.class)) { boolean b = checkToValidateEquals(a.getActivity(), field, (EqualsWith) annotation); if (b) { valid = b; } } } } return valid; }
From source file:org.mariotaku.twidere.activity.support.HomeActivity.java
@Override public boolean triggerRefresh(final int position) { final Fragment f = (Fragment) mPagerAdapter.instantiateItem(mViewPager, position); if (!(f instanceof RefreshScrollTopInterface)) return false; if (f.getActivity() == null || f.isDetached()) return false; return ((RefreshScrollTopInterface) f).triggerRefresh(); }
From source file:com.normalexception.app.rx8club.fragment.category.FavoritesFragment.java
/** * Update the view's list with the appropriate data *//* w ww. ja v a 2 s. c om*/ private void updateList() { final Fragment _frag = this; getActivity().runOnUiThread(new Runnable() { public void run() { getView().findViewById(R.id.mainlisttitle).setVisibility(View.VISIBLE); ((TextView) getView().findViewById(R.id.mainlisttitle)).setText("Favorite Threads"); threadlist = FavoriteFactory.getInstance().getFavorites(); tva = new ThreadViewArrayAdapter(_frag, R.layout.view_thread, threadlist); lv.setAdapter(tva); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ThreadModel itm = (ThreadModel) parent.getItemAtPosition(position); Log.v(TAG, "User clicked '" + itm.getTitle() + "'"); Bundle args = new Bundle(); args.putString("link", itm.getLink()); args.putString("title", itm.getTitle()); FragmentUtils.fragmentTransaction(_frag.getActivity(), ThreadFragment.newInstance(), false, true, args); } }); } }); }
From source file:net.evendanan.pushingpixels.PassengerFragmentSupport.java
@Nullable public static Animation onCreateAnimation(@NonNull Fragment passengerFragment, int transit, boolean enter, int nextAnim) { Log.d(TAG, "onCreateAnimation: transit: " + transit + ", enter: " + enter + ", nextAnim: " + nextAnim); final boolean validTransitionToModify = nextAnim == R.anim.ui_context_expand_add_in || nextAnim == R.anim.ui_context_expand_pop_out; if (!validTransitionToModify) return null; ScaleAnimation scale = null;/*from w ww. j a v a2s. co m*/ PointF originateViewCenterPoint = PointFCompat.getPointFromBundle(passengerFragment.getArguments(), EXTRA_ORIGINATE_VIEW_CENTER); PointF originateViewScale = PointFCompat.getPointFromBundle(passengerFragment.getArguments(), EXTRA_ORIGINATE_VIEW_SCALE); if (originateViewCenterPoint != null && originateViewScale != null) { Log.d(TAG, "originateViewCenterPoint: " + originateViewCenterPoint.toString()); if (enter && nextAnim == R.anim.ui_context_expand_add_in) { scale = new ScaleAnimation(originateViewScale.x, 1.0f, originateViewScale.y, 1.0f, ScaleAnimation.ABSOLUTE, originateViewCenterPoint.x, ScaleAnimation.ABSOLUTE, originateViewCenterPoint.y); } else if (!enter && nextAnim == R.anim.ui_context_expand_pop_out) { scale = new ScaleAnimation(1.0f, originateViewScale.x, 1.0f, originateViewScale.y, ScaleAnimation.ABSOLUTE, originateViewCenterPoint.x, ScaleAnimation.ABSOLUTE, originateViewCenterPoint.y); } } if (scale == null) { //no originate view, so I'll add generic scale-animation if (enter) { scale = new ScaleAnimation(0.4f, 1.0f, 0.4f, 1.0f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f); } else { scale = new ScaleAnimation(1.0f, 0.4f, 1.0f, 0.4f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f); } } scale.setDuration(passengerFragment.getResources().getInteger(android.R.integer.config_mediumAnimTime)); AnimationSet set = (AnimationSet) AnimationUtils .loadAnimation(passengerFragment.getActivity().getApplicationContext(), nextAnim); set.addAnimation(scale); return set; }
From source file:com.groundupworks.wings.facebook.FacebookEndpoint.java
/** * Requests for permissions to publish publicly. Requires an opened active {@link Session}. * * @param activity the {@link Activity}. * @param fragment the {@link Fragment}. May be null. * @return true if the request is made; false if no opened {@link Session} is active. *//*from w ww . j ava 2s .c om*/ private boolean startPublishPermissionsRequest(Activity activity, Fragment fragment) { boolean isSuccessful = false; // State transition. mLinkRequestState = STATE_PUBLISH_PERMISSIONS_REQUEST; Session session = Session.getActiveSession(); if (session != null && session.isOpened()) { // Construct publish permissions. List<String> publishPermissions = new LinkedList<String>(); publishPermissions.add(PERMISSION_PUBLISH_ACTIONS); publishPermissions.add(PERMISSION_MANAGE_PAGES); // Construct permissions request to publish publicly. NewPermissionsRequest permissionsRequest; if (fragment == null) { permissionsRequest = new NewPermissionsRequest(activity, publishPermissions); } else { if (fragment.getActivity() == null) { return false; } permissionsRequest = new NewPermissionsRequest(fragment, publishPermissions); } permissionsRequest.setDefaultAudience(SessionDefaultAudience.EVERYONE); // Execute publish permissions request. session.requestNewPublishPermissions(permissionsRequest); isSuccessful = true; } return isSuccessful; }
From source file:org.alfresco.mobile.android.application.fragments.actions.NodeActions.java
public static void delete(final FragmentActivity activity, final Fragment f, final List<Node> nodes) { Folder tmpParent = null;// w ww.ja v a 2 s . c o m if (f instanceof DocumentFolderBrowserFragment) { tmpParent = ((DocumentFolderBrowserFragment) f).getParent(); } else if (f instanceof PagerNodeDetailsFragment) { tmpParent = ((PagerNodeDetailsFragment) f).getParentNode(); } final Folder parent = tmpParent; // Prepare Message String nodeDescription = nodes.size() + ""; if (nodes.size() == 1) { nodeDescription = nodes.get(0).getName(); } String description = String.format( activity.getResources().getQuantityString(R.plurals.delete_items, nodes.size()), nodeDescription); // Display Dialog MaterialDialog.Builder builder = new MaterialDialog.Builder(activity).title(R.string.delete) .iconRes(R.drawable.ic_application_logo).content(description) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { String operationId; if (nodes.size() == 1) { operationId = Operator.with(activity) .load(new DeleteNodeRequest.Builder(parent, nodes.get(0)) .setNotificationVisibility(OperationRequest.VISIBILITY_TOAST)); } else { List<OperationBuilder> requestsBuilder = new ArrayList<OperationBuilder>(nodes.size()); for (Node node : nodes) { requestsBuilder.add(new DeleteNodeRequest.Builder(parent, node) .setNotificationVisibility(OperationRequest.VISIBILITY_DIALOG)); } operationId = Operator.with(activity, SessionUtils.getAccount(activity)) .load(requestsBuilder); OperationWaitingDialogFragment .newInstance(DeleteNodeRequest.TYPE_ID, R.drawable.ic_delete, f.getString(R.string.delete), null, parent, nodes.size(), operationId) .show(f.getActivity().getSupportFragmentManager(), OperationWaitingDialogFragment.TAG); } dialog.dismiss(); } @Override public void onNegative(MaterialDialog dialog) { dialog.dismiss(); } }).positiveText(R.string.confirm).negativeText(R.string.cancel); builder.show(); }
From source file:com.normalexception.app.rx8club.fragment.category.CategoryFragment.java
/** * Update the view's list with the appropriate data */// w w w. ja va 2 s .co m private void updateList() { final Fragment _frag = this; getActivity().runOnUiThread(new Runnable() { public void run() { tva = new ThreadViewArrayAdapter(_frag, R.layout.view_thread, threadlist); tva.setIsNewThread(isNewTopicActivity); lv.setAdapter(tva); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ThreadModel itm = (ThreadModel) parent.getItemAtPosition(position); if (!itm.isStub()) { Log.d(TAG, "User clicked '" + itm.getTitle() + "'"); Bundle args = new Bundle(); //Intent _intent = // new Intent(CategoryFragment.this, ThreadActivity.class); // If the user wants the last page when recently updated // threads, grab it. if (getLastPage(itm) && !itm.getLastLink().equals("#") && !itm.getLastLink().endsWith("/#")) { args.putString("link", itm.getLastLink()); args.putString("page", "last"); } else { args.putString("link", itm.getLink()); } args.putBoolean("poll", itm.isPoll()); args.putBoolean("locked", itm.isLocked()); args.putString("title", itm.getTitle()); FragmentUtils.fragmentTransaction(_frag.getActivity(), ThreadFragment.newInstance(), false, true, args); } } }); if (LoginFactory.getInstance().isLoggedIn()) registerForContextMenu(lv); if (FragmentUtils.updatePagination(_frag, thisPage, finalPage) == null) getView().findViewById(R.id.paginationView).setVisibility(View.GONE); updateFilterizedInformation(); } }); }
From source file:nu.yona.app.ui.YonaActivity.java
/** * @param clearFragmentStack : yes if require to clear fragment stack. * @param addToBackstack : yes if require to add fragment to back stack. * @param oldFragment pass oldfragment which need to add in back stack. *//*from w w w .jav a2 s . c o m*/ private void loadFragment(boolean clearFragmentStack, boolean addToBackstack, Fragment oldFragment) { if (mContent != null && !mContent.isAdded()) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); if (clearFragmentStack) { getSupportFragmentManager().removeOnBackStackChangedListener(this); int count = getSupportFragmentManager().getBackStackEntryCount(); for (int i = 0; i < count; ++i) { if (mStateSaved) { isStateActive = true; break; } else { getSupportFragmentManager().popBackStackImmediate(); } } if (mStateSaved) { return; } removeCurrentFragment(); // adding back stack change listener again. getSupportFragmentManager().addOnBackStackChangedListener(this); ft.replace(R.id.container, mContent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && mContent instanceof ProfileFragment) { View ivProfile = oldFragment.getActivity().findViewById(R.id.leftIcon); ft.addSharedElement(ivProfile, getString(R.string.profile_transition)); } ft.commitAllowingStateLoss(); getSupportFragmentManager().executePendingTransactions(); } else { oldFragment.setUserVisibleHint(false); if (!clearFragmentStack && addToBackstack) { ft.addToBackStack(mContent.getClass().getName()); } ft.add(R.id.container, mContent).commit(); oldFragment.onPause(); oldFragment.onStop(); } } }