android.support.annotation.IdRes Java Examples

The following examples show how to use android.support.annotation.IdRes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SettingActivity.java    From BmapLite with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
    ConfigInteracter interacter = new ConfigInteracter(this);
    if (group.getId() == R.id.group_zoom) {
        if (checkedId == R.id.radio_zoom_left) {
            interacter.setZoomControlsPosition(false);
        } else if (checkedId == R.id.radio_zoom_right) {
            interacter.setZoomControlsPosition(true);
        }
    } else if (group.getId() == R.id.group_mode) {
        if (checkedId == R.id.radio_white) {
            interacter.setNightMode(1);
        } else if (checkedId == R.id.radio_black) {
            if (BApp.TYPE_MAP == TypeMap.TYPE_BAIDU) {
                Toast.makeText(this, "夜间模式下百度地图可能需要重启应用后生效", Toast.LENGTH_LONG).show();
            }
            interacter.setNightMode(2);
        } else {
            interacter.setNightMode(0);
        }
        ((BApp) getApplication()).setNightMode();
    }

}
 
Example #2
Source File: BaseNavControllerTest.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void assertDeeplink(@IdRes int destId, int expectedStackSize) throws Throwable {
    BaseNavigationActivity activity = launchDeepLink(R.navigation.nav_deep_link,
            destId, null);
    NavController navController = activity.getNavController();

    assertThat(navController.getCurrentDestination().getId(), is(destId));
    TestNavigator navigator = navController.getNavigatorProvider()
            .getNavigator(TestNavigator.class);
    assertThat(navigator.mBackStack.size(), is(expectedStackSize));

    // Test that the deep link Intent was passed through even though we don't pass in any args
    //noinspection ConstantConditions
    Intent deepLinkIntent = navigator.mBackStack.peekLast().second
            .getParcelable(NavController.KEY_DEEP_LINK_INTENT);
    assertThat(deepLinkIntent, is(notNullValue(Intent.class)));
    assertThat(deepLinkIntent.getAction(), is(TEST_DEEP_LINK_ACTION));
}
 
Example #3
Source File: BaseNavControllerTest.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private BaseNavigationActivity launchDeepLink(@NavigationRes int graphId, @IdRes int destId,
        Bundle args) throws Throwable {
    TaskStackBuilder intents = new NavDeepLinkBuilder(mInstrumentation.getTargetContext())
            .setGraph(graphId)
            .setDestination(destId)
            .setArguments(args)
            .createTaskStackBuilder();
    Intent intent = intents.editIntentAt(0);
    intent.setAction(TEST_DEEP_LINK_ACTION);

    // Now launch the deeplink Intent
    BaseNavigationActivity deeplinkActivity = launchActivity(intent);
    NavController navController = deeplinkActivity.getNavController();
    navController.setGraph(graphId);

    return deeplinkActivity;
}
 
Example #4
Source File: BaseNavControllerTest.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void assertUriDeepLink(String path, @IdRes int destId, int expectedStackSize)
        throws Throwable {
    Uri deepLinkUri = Uri.parse("http://www.example.com/" + path + "/" + TEST_ARG_VALUE);
    Intent intent = new Intent(Intent.ACTION_VIEW, deepLinkUri)
            .setComponent(new ComponentName(mInstrumentation.getContext(),
                    getActivityClass()))
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    BaseNavigationActivity activity = launchActivity(intent);
    NavController navController = activity.getNavController();
    navController.setGraph(R.navigation.nav_deep_link);

    assertThat(navController.getCurrentDestination().getId(), is(destId));
    TestNavigator navigator = navController.getNavigatorProvider()
            .getNavigator(TestNavigator.class);
    assertThat(navigator.mBackStack.size(), is(expectedStackSize));
    //noinspection ConstantConditions
    assertThat(navigator.mBackStack.peekLast().second.getString(TEST_ARG), is(TEST_ARG_VALUE));

    // Test that the deep link Intent was passed in alongside our args
    //noinspection ConstantConditions
    Intent deepLinkIntent = navigator.mBackStack.peekLast().second
            .getParcelable(NavController.KEY_DEEP_LINK_INTENT);
    assertThat(deepLinkIntent, is(notNullValue(Intent.class)));
    assertThat(deepLinkIntent.getData(), is(deepLinkUri));
}
 
Example #5
Source File: BaseNavControllerTest.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void assertDeepLinkWithArgs(@IdRes int destId, int expectedStackSize) throws Throwable {
    Bundle args = new Bundle();
    args.putString(TEST_ARG, TEST_ARG_VALUE);
    BaseNavigationActivity activity = launchDeepLink(R.navigation.nav_deep_link,
            destId, args);
    NavController navController = activity.getNavController();

    assertThat(navController.getCurrentDestination().getId(), is(destId));
    TestNavigator navigator = navController.getNavigatorProvider()
            .getNavigator(TestNavigator.class);
    assertThat(navigator.mBackStack.size(), is(expectedStackSize));
    //noinspection ConstantConditions
    assertThat(navigator.mBackStack.peekLast().second.getString(TEST_ARG), is(TEST_ARG_VALUE));

    // Test that the deep link Intent was passed in alongside our args
    //noinspection ConstantConditions
    Intent deepLinkIntent = navigator.mBackStack.peekLast().second
            .getParcelable(NavController.KEY_DEEP_LINK_INTENT);
    assertThat(deepLinkIntent, is(notNullValue(Intent.class)));
    assertThat(deepLinkIntent.getAction(), is(TEST_DEEP_LINK_ACTION));
}
 
Example #6
Source File: NavController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onNavigatorNavigated(@NonNull Navigator navigator, @IdRes int destId,
        @Navigator.BackStackEffect int backStackEffect) {
    if (destId != 0) {
        // First remove popped destinations off the back stack
        if (backStackEffect == Navigator.BACK_STACK_DESTINATION_POPPED) {
            while (!mBackStack.isEmpty()
                    && mBackStack.peekLast().getId() != destId) {
                mBackStack.removeLast();
            }
        }
        NavDestination newDest = findDestination(destId);
        if (newDest == null) {
            throw new IllegalArgumentException("Navigator " + navigator
                    + " reported navigation to unknown destination id "
                    + NavDestination.getDisplayName(mContext, destId));
        }
        if (backStackEffect == Navigator.BACK_STACK_DESTINATION_ADDED) {
            // Add the new destination to the back stack
            mBackStack.add(newDest);
        }
        // Don't dispatchOnNavigated if nothing changed
        if (backStackEffect != Navigator.BACK_STACK_UNCHANGED) {
            dispatchOnNavigated(newDest);
        }
    }
}
 
Example #7
Source File: SceneLifecycleDispatcher.java    From scene with Apache License 2.0 5 votes vote down vote up
public SceneLifecycleDispatcher(@IdRes int sceneContainerViewId,
                                ViewFinder viewFinder,
                                T rootScene,
                                Scope.RootScopeFactory rootScopeFactory,
                                boolean supportRestore) {
    this.mSceneContainerViewId = sceneContainerViewId;
    this.mViewFinder = viewFinder;
    this.mScene = rootScene;
    this.mRootScopeFactory = rootScopeFactory;
    this.mSupportRestore = supportRestore;
}
 
Example #8
Source File: FragmentViewFinder.java    From scene with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public <T extends View> T requireViewById(@IdRes int viewId) {
    T view = mFragment.getView().findViewById(viewId);
    if (view == null) {
        try {
            String viewIdName = mFragment.getResources().getResourceName(viewId);
            throw new IllegalArgumentException(" " + viewIdName + " view not found");
        } catch (Resources.NotFoundException exception) {
            throw new IllegalArgumentException(" " + viewId + " view not found");
        }
    }
    return view;
}
 
Example #9
Source File: PostDetailView.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
private <T extends View> T getChildView(@IdRes int viewId) {
    View childView = null;
    if (view == null) {
        childView = view.findViewById(viewId);
    }
    return (T) childView;
}
 
Example #10
Source File: NavigationUI.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether the given <code>destId</code> matches the NavDestination. This handles
 * both the default case (the destination's id matches the given id) and the nested case where
 * the given id is a parent/grandparent/etc of the destination.
 */
private static boolean matchDestination(@NonNull NavDestination destination,
        @IdRes int destId) {
    NavDestination currentDestination = destination;
    while (currentDestination.getId() != destId && currentDestination.getParent() != null) {
        currentDestination = currentDestination.getParent();
    }
    return currentDestination.getId() == destId;
}
 
Example #11
Source File: NavigationSceneCompatUtility.java    From scene with Apache License 2.0 5 votes vote down vote up
/**
 * use {@link #setupWithFragment(Fragment, Class, int)} instead
 */
@Deprecated
@NonNull
public static SceneDelegate setupWithFragment(@NonNull final Fragment fragment,
                                              @IdRes int containerId,
                                              @Nullable Bundle savedInstanceState,
                                              @NonNull NavigationSceneOptions navigationSceneOptions,
                                              @Nullable SceneComponentFactory rootSceneComponentFactory,
                                              final boolean supportRestore,
                                              @NonNull final String tag,
                                              final boolean immediate) {
    return setupWithFragment(fragment, containerId, navigationSceneOptions, rootSceneComponentFactory, supportRestore, tag, immediate);
}
 
Example #12
Source File: NavigationSceneCompatUtility.java    From scene with Apache License 2.0 5 votes vote down vote up
/**
 * use {@link #setupWithFragment(Fragment, Class, int)} instead
 */
@Deprecated
@NonNull
public static SceneDelegate setupWithFragment(@NonNull final Fragment fragment,
                                              @IdRes int containerId,
                                              @Nullable Bundle savedInstanceState,
                                              @NonNull Class<? extends Scene> rootScene,
                                              @Nullable Bundle bundle,
                                              boolean supportRestore) {
    return setupWithFragment(fragment, containerId, savedInstanceState,
            new NavigationSceneOptions(rootScene, bundle),
            null,
            supportRestore);
}
 
Example #13
Source File: NavDestination.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the destination ID for a given action. This will recursively check the
 * {@link #getParent() parent} of this destination if the action destination is not found in
 * this destination.
 *
 * @param id action ID to fetch
 * @return destination ID mapped to the given action id, or 0 if none
 */
@Nullable
public NavAction getAction(@IdRes int id) {
    NavAction destination = mActions == null ? null : mActions.get(id);
    // Search the parent for the given action if it is not found in this destination
    return destination != null
            ? destination
            : getParent() != null ? getParent().getAction(id) : null;
}
 
Example #14
Source File: NavigationSceneUtility.java    From scene with Apache License 2.0 5 votes vote down vote up
/**
 * use {@link #setupWithActivity(Activity, Class)} instead
 */
@Deprecated
@NonNull
public static SceneDelegate setupWithActivity(@NonNull final Activity activity,
                                              @IdRes int idRes,
                                              @Nullable Bundle savedInstanceState,
                                              @NonNull NavigationSceneOptions navigationSceneOptions,
                                              @Nullable SceneComponentFactory rootSceneComponentFactory,
                                              final boolean supportRestore) {
    return setupWithActivity(activity, idRes, savedInstanceState, navigationSceneOptions,
            rootSceneComponentFactory, supportRestore, LIFE_CYCLE_FRAGMENT_TAG, true);
}
 
Example #15
Source File: Navigation.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Create an {@link android.view.View.OnClickListener} for navigating
 * to a destination. This supports both navigating via an
 * {@link NavDestination#getAction(int) action} and directly navigating to a destination.
 *
 * @param resId an {@link NavDestination#getAction(int) action} id or a destination id to
 *              navigate to when the view is clicked
 * @param args arguments to pass to the final destination
 * @return a new click listener for setting on an arbitrary view
 */
@NonNull
public static View.OnClickListener createNavigateOnClickListener(@IdRes final int resId,
        @Nullable final Bundle args) {
    return new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            findNavController(view).navigate(resId, args);
        }
    };
}
 
Example #16
Source File: GroupSceneManager.java    From scene with Apache License 2.0 5 votes vote down vote up
MoveStateOperation(@NonNull Scene scene, @IdRes int viewId, @Nullable String tag, @NonNull State dstState, boolean forceShow, boolean forceHide, boolean forceRemove) {
    super(scene, dstState, forceShow, forceHide, forceRemove);
    if (forceShow && forceHide) {
        throw new IllegalArgumentException("cant forceShow with forceHide");
    }

    this.viewId = viewId;
    this.tag = tag;
    this.dstState = dstState;
}
 
Example #17
Source File: NavOptions.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
NavOptions(int launchMode, @IdRes int popUpTo, boolean popUpToInclusive,
        @AnimRes @AnimatorRes int enterAnim, @AnimRes @AnimatorRes int exitAnim,
        @AnimRes @AnimatorRes int popEnterAnim, @AnimRes @AnimatorRes int popExitAnim) {
    mLaunchMode = launchMode;
    mPopUpTo = popUpTo;
    mPopUpToInclusive = popUpToInclusive;
    mEnterAnim = enterAnim;
    mExitAnim = exitAnim;
    mPopEnterAnim = popEnterAnim;
    mPopExitAnim = popExitAnim;
}
 
Example #18
Source File: ViewAdapter.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
@BindingAdapter(value = {"onCheckedChangedCommand"}, requireAll = false)
public static void onCheckedChangedCommand(final RadioGroup radioGroup, final BindingCommand<String> bindingCommand) {
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
            RadioButton radioButton = (RadioButton) group.findViewById(checkedId);
            bindingCommand.execute(radioButton.getText().toString());
        }
    });
}
 
Example #19
Source File: BaseHeaderFooterAdapter.java    From SimpleAdapterDemo with Apache License 2.0 5 votes vote down vote up
public <V extends View> V findViewById(@IdRes int id) {
    View child = childrenCache.get(id);
    if (child == null) {
        child = itemView.findViewById(id);
        if (child != null)
            childrenCache.put(id, child);
    }
    return (V) child;
}
 
Example #20
Source File: NavDestination.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Sets a destination ID for an action ID.
 *
 * @param actionId action ID to bind
 * @param action action to associate with this action ID
 */
public void putAction(@IdRes int actionId, @NonNull NavAction action) {
    if (actionId == 0) {
        throw new IllegalArgumentException("Cannot have an action with actionId 0");
    }
    if (mActions == null) {
        mActions = new SparseArrayCompat<>();
    }
    mActions.put(actionId, action);
}
 
Example #21
Source File: AbsFloatBase.java    From FloatWindow with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected <T extends View> T findView(@IdRes int id) {
    if (mInflate != null) {
        return (T) mInflate.findViewById(id);
    }
    return null;
}
 
Example #22
Source File: FragmentNavigator.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@NonNull
private String getBackStackName(@IdRes int destinationId) {
    // This gives us the resource name if it exists,
    // or just the destinationId if it doesn't exist
    try {
        return mContext.getResources().getResourceName(destinationId);
    } catch (Resources.NotFoundException e) {
        return Integer.toString(destinationId);
    }
}
 
Example #23
Source File: NavDeepLinkBuilder.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the destination id to deep link to.
 *
 * @param destId destination ID to deep link to.
 * @return this object for chaining
 */
@NonNull
public NavDeepLinkBuilder setDestination(@IdRes int destId) {
    mDestId = destId;
    if (mGraph != null) {
        fillInIntent();
    }
    return this;
}
 
Example #24
Source File: BaseHeaderFooterAdapter.java    From SimpleAdapterDemo with Apache License 2.0 5 votes vote down vote up
public BaseViewHolder setCompoundDrawables(@IdRes int id,
                                           @Nullable Drawable left,
                                           @Nullable Drawable top,
                                           @Nullable Drawable right,
                                           @Nullable Drawable bottom) {
    View view = findViewById(id);
    if (view instanceof TextView)
        ((TextView) view).setCompoundDrawables(left, top, right, bottom);
    return this;
}
 
Example #25
Source File: BaseActivity.java    From landlord_client with Apache License 2.0 5 votes vote down vote up
/**
 * 根据resid隐藏view
 */
protected void gone(@IdRes int... id) {
    if(id != null && id.length > 0) {
        for(int resId : id) {
            View view = findViewById(resId);
            if(view != null) gone(view);
        }
    }
}
 
Example #26
Source File: NavGraph.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
NavDestination findNode(@IdRes int resid, boolean searchParents) {
    NavDestination destination = mNodes.get(resid);
    // Search the parent for the NavDestination if it is not a child of this navigation graph
    // and searchParents is true
    return destination != null
            ? destination
            : searchParents && getParent() != null ? getParent().findNode(resid) : null;
}
 
Example #27
Source File: BaseHeaderFooterAdapter.java    From SimpleAdapterDemo with Apache License 2.0 4 votes vote down vote up
public BaseViewHolder setTag(@IdRes int id, int key, final Object tag) {
    View view = findViewById(id);
    if (view != null)
        view.setTag(key, tag);
    return this;
}
 
Example #28
Source File: BaseItemAdapter.java    From SimpleAdapterDemo with Apache License 2.0 4 votes vote down vote up
public BaseItemViewHolder setTextColor(@IdRes int id, @ColorInt int color) {
    View view = findViewById(id);
    if (view instanceof TextView)
        ((TextView) view).setTextColor(color);
    return this;
}
 
Example #29
Source File: BaseItemAdapter.java    From SimpleAdapterDemo with Apache License 2.0 4 votes vote down vote up
public BaseItemViewHolder setTextSize(@IdRes int id, float size) {
    View view = findViewById(id);
    if (view instanceof TextView)
        ((TextView) view).setTextSize(size);
    return this;
}
 
Example #30
Source File: BaseItemAdapter.java    From SimpleAdapterDemo with Apache License 2.0 4 votes vote down vote up
public BaseItemViewHolder setTextSize(@IdRes int id, int unit, float size) {
    View view = findViewById(id);
    if (view instanceof TextView)
        ((TextView) view).setTextSize(unit, size);
    return this;
}