List of usage examples for android.view View getContext
@ViewDebug.CapturedViewProperty public final Context getContext()
From source file:Main.java
/** * Announce text through the AccessibilityManager for a view. * * @param text//ww w. j a v a 2s . c om * @param view * @param manager */ public static void announceText(String text, View view, AccessibilityManager manager) { // Only announce text if the accessibility service is enabled if (!manager.isEnabled()) { return; } AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEventCompat.TYPE_ANNOUNCEMENT); event.getText().add(text); event.setEnabled(true); // Tie the event to the view event.setClassName(view.getClass().getName()); event.setPackageName(view.getContext().getPackageName()); AccessibilityEventCompat.asRecord(event).setSource(view); // Send the announcement manager.sendAccessibilityEvent(event); }
From source file:fr.cph.chicago.util.Util.java
private static void showSnackBar(@NonNull final View view, final int message) { Snackbar.make(view, view.getContext().getString(message), Snackbar.LENGTH_SHORT).show(); }
From source file:fr.cph.chicago.util.Util.java
public static void removeFromBikeFavorites(final int stationId, @NonNull final View view) { final List<String> favorites = Preferences.getBikeFavorites(view.getContext(), App.PREFERENCE_FAVORITES_BIKE); favorites.remove(Integer.toString(stationId)); Preferences.saveBikeFavorites(view.getContext(), App.PREFERENCE_FAVORITES_BIKE, favorites); showSnackBar(view, R.string.message_remove_fav); }
From source file:fr.cph.chicago.util.Util.java
public static void addToBikeFavorites(final int stationId, @NonNull final View view) { final List<String> favorites = Preferences.getBikeFavorites(view.getContext(), App.PREFERENCE_FAVORITES_BIKE); if (!favorites.contains(Integer.toString(stationId))) { favorites.add(Integer.toString(stationId)); Preferences.saveBikeFavorites(view.getContext(), App.PREFERENCE_FAVORITES_BIKE, favorites); showSnackBar(view, R.string.message_add_fav); }/*w ww .j a va 2 s . c o m*/ }
From source file:fr.cph.chicago.util.Util.java
/** * Remove train from favorites//from w ww.j a v a2s .c o m * * @param stationId the station id * @param view the view */ public static void removeFromTrainFavorites(@NonNull final Integer stationId, @NonNull final View view) { final List<Integer> favorites = Preferences.getTrainFavorites(view.getContext(), App.PREFERENCE_FAVORITES_TRAIN); favorites.remove(stationId); Preferences.saveTrainFavorites(view.getContext(), App.PREFERENCE_FAVORITES_TRAIN, favorites); showSnackBar(view, R.string.message_remove_fav); }
From source file:fr.cph.chicago.util.Util.java
/** * Add to train favorites/*ww w. j av a 2 s. co m*/ * * @param stationId the station id * @param view the view */ public static void addToTrainFavorites(@NonNull final Integer stationId, @NonNull final View view) { final List<Integer> favorites = Preferences.getTrainFavorites(view.getContext(), App.PREFERENCE_FAVORITES_TRAIN); if (!favorites.contains(stationId)) { favorites.add(stationId); Preferences.saveTrainFavorites(view.getContext(), App.PREFERENCE_FAVORITES_TRAIN, favorites); showSnackBar(view, R.string.message_add_fav); } }
From source file:com.afeng.xf.widget.snackbarlight.Light.java
/** * Make a customized {@link Snackbar} to display a message without any action. * Method {@link Light#make(View, CharSequence, Drawable, int, int, int)} * * @param view The view to find a parent from. * @param textRes The message to display. Formatted text is supported. * String id required.//from w ww . j a v a 2 s .c o m * @param textIconRes The left icon of the message. Drawable resource id required. * @param backgroundColorRes The background color of the Snackbar. Color resource id required. * @param textColorRes The color of action message text. Color resource id required. * @param duration How long to show the message. * Either {@link Light#LENGTH_SHORT} or {@link Light#LENGTH_LONG}. * @return The customized Snackbar that will be displayed. */ public static Snackbar make(@NonNull View view, @StringRes int textRes, @DrawableRes int textIconRes, @ColorRes int backgroundColorRes, @ColorRes int textColorRes, int duration) { Context context = view.getContext(); return make(view, context.getString(textRes), // DO NOT use the resource id directly. // It should be a resolved drawable or color. ContextCompat.getDrawable(context, textIconRes), // getResources().getColor() is deprecated. ContextCompat.getColor(context, backgroundColorRes), ContextCompat.getColor(context, textColorRes), duration); }
From source file:fr.cph.chicago.util.Util.java
/** * Remove from bus favorites//from w w w . j av a 2 s.c o m * * @param busRouteId the bus route id * @param busStopId the bus stop id * @param bound the bus bound * @param view the view */ public static void removeFromBusFavorites(@NonNull final String busRouteId, @NonNull final String busStopId, @NonNull final String bound, @NonNull final View view) { final String id = busRouteId + "_" + busStopId + "_" + bound; final List<String> favorites = Preferences.getBusFavorites(view.getContext(), App.PREFERENCE_FAVORITES_BUS); favorites.remove(id); Preferences.saveBusFavorites(view.getContext(), App.PREFERENCE_FAVORITES_BUS, favorites); showSnackBar(view, R.string.message_remove_fav); }
From source file:com.afeng.xf.widget.snackbarlight.Light.java
/** * Make a customized {@link Snackbar} to display a message without any action. * Method {@link Light#make(View, CharSequence, Drawable, int, int, int)}. * * @param view The view to find a parent from. * @param text The message to display. Formatted text is supported. * @param textIconRes The left icon of the message. Drawable resource id required. * @param backgroundColorRes The background color of the Snackbar. Color resource id required. * @param textColorRes The color of action message text. Color resource id required. * @param duration How long to show the message. * Either {@link Light#LENGTH_SHORT} or {@link Light#LENGTH_LONG}. * * @return The customized Snackbar that will be displayed. *///from w w w. jav a 2 s . c om public static Snackbar make(@NonNull View view, @NonNull CharSequence text, @DrawableRes int textIconRes, @ColorRes int backgroundColorRes, @ColorRes int textColorRes, int duration) { Context context = view.getContext(); return make(view, text, // DO NOT use the resource id directly. // It should be a resolved drawable or color. ContextCompat.getDrawable(context, textIconRes), // getResources().getColor() is deprecated. ContextCompat.getColor(context, backgroundColorRes), ContextCompat.getColor(context, textColorRes), duration); }
From source file:fr.cph.chicago.util.Util.java
/** * Add to bus favorites/* w ww.jav a2 s . c o m*/ * * @param busRouteId the bus route id * @param busStopId the bus stop id * @param bound the bus bound * @param view the view */ public static void addToBusFavorites(@NonNull final String busRouteId, @NonNull final String busStopId, @NonNull final String bound, @NonNull final View view) { final String id = busRouteId + "_" + busStopId + "_" + bound; final List<String> favorites = Preferences.getBusFavorites(view.getContext(), App.PREFERENCE_FAVORITES_BUS); if (!favorites.contains(id)) { favorites.add(id); Preferences.saveBusFavorites(view.getContext(), App.PREFERENCE_FAVORITES_BUS, favorites); showSnackBar(view, R.string.message_add_fav); } }