public final Resources getResources() { if(resources == null) { resources = context.getResources(); } return resources; }
@Override protected void bindSupportWebParent(WebParentLayout webParentLayout, Activity activity) { this.mActivity = activity; this.mWebParentLayout = webParentLayout; mResources = this.mActivity.getResources(); } }
final Activity activity = getActivity(); final View content = activity.findViewById(android.R.id.content).getRootView(); if (content.getWidth() > 0) { Bitmap image = BlurBuilder.blur(content); window.setBackgroundDrawable(new BitmapDrawable(activity.getResources(), image)); } else { content.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Bitmap image = BlurBuilder.blur(content); window.setBackgroundDrawable(new BitmapDrawable(activity.getResources(), image)); } }); }
/** * Set the DrawerBuilder width with a dimension resource * * @param drawerWidthRes * @return */ public DrawerBuilder withDrawerWidthRes(@DimenRes int drawerWidthRes) { if (mActivity == null) { throw new RuntimeException("please pass an activity first to use this call"); } this.mDrawerWidth = mActivity.getResources().getDimensionPixelSize(drawerWidthRes); return this; }
private void clearExtraSpacingBetweenCards(RecyclerView albumsRecyclerview) { //to clear any extra spacing between cards int spacingInPixelstoClear = -(mContext.getResources().getDimensionPixelSize(R.dimen.spacing_card)); albumsRecyclerview.addItemDecoration(new SpacesItemDecoration(spacingInPixelstoClear)); }
public LocationListElement(int requestCode) { super(getActivity().getResources().getDrawable(R.drawable.add_location), getActivity().getResources().getString(R.string.action_location), null, requestCode); }
/**展示加载进度条,无标题 * @param stringResId */ public static void showProgressDialog(Activity context, int stringResId){ try { showProgressDialog(context, null, context.getResources().getString(stringResId)); } catch (Exception e) { Log.e(TAG, "showProgressDialog showProgressDialog(Context context, null, context.getResources().getString(stringResId));"); } } /**展示加载进度条,无标题
public PeopleListElement(int requestCode) { super(getActivity().getResources().getDrawable(R.drawable.add_friends), getActivity().getResources().getString(R.string.action_people), null, requestCode); }
/** * 获取ActionBar高度 * * @param activity activity * @return ActionBar高度 */ public static int getActionBarHeight(Activity activity) { TypedValue tv = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { return TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics()); } return 0; }
private void setUpAlbums(RecyclerView albumsRecyclerview) { albumsRecyclerview.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false)); albumsRecyclerview.setHasFixedSize(true); //to add spacing between cards int spacingInPixels = mContext.getResources().getDimensionPixelSize(R.dimen.spacing_card); albumsRecyclerview.addItemDecoration(new SpacesItemDecoration(spacingInPixels)); albumsRecyclerview.setNestedScrollingEnabled(false); ArtistAlbumAdapter mAlbumAdapter = new ArtistAlbumAdapter(mContext, ArtistAlbumLoader.getAlbumsForArtist(mContext, artistID)); albumsRecyclerview.setAdapter(mAlbumAdapter); }
@Override public void onStart() { super.onStart(); //设置fragment高度 、宽度 int dialogHeight = (int) (mContext.getResources().getDisplayMetrics().heightPixels * 0.65); int dialogWidth = (int) (mContext.getResources().getDisplayMetrics().widthPixels * 0.77); getDialog().getWindow().setLayout(dialogWidth, dialogHeight); getDialog().setCanceledOnTouchOutside(true); }
@Override public void onStart() { super.onStart(); //设置fragment高度 、宽度 int dialogHeight = (int) (mContext.getResources().getDisplayMetrics().heightPixels * 0.71); int dialogWidth = (int) (mContext.getResources().getDisplayMetrics().widthPixels * 0.79); getDialog().getWindow().setLayout(dialogWidth, dialogHeight); getDialog().setCanceledOnTouchOutside(true); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int res= getActivity().getResources() .getIdentifier(getArguments().getString("resource"), "xml", getActivity().getPackageName()); addPreferencesFromResource(res); } }
@Override public void onStart() { super.onStart(); //设置fragment高度 、宽度 int dialogHeight = (int) (mContext.getResources().getDisplayMetrics().heightPixels * 0.30); getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, dialogHeight); getDialog().setCanceledOnTouchOutside(true); }
@Override public void onStart() { super.onStart(); //设置fragment高度 、宽度 int dialogHeight = (int) (mContext.getResources().getDisplayMetrics().heightPixels * heightPercent); ; // WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); // Display display = wm.getDefaultDisplay(); // int height = display.getHeight(); getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, dialogHeight); getDialog().setCanceledOnTouchOutside(true); }
private SystemBarConfig(Activity activity, boolean translucentStatusBar, boolean traslucentNavBar) { Resources res = activity.getResources(); mInPortrait = (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT); mSmallestWidthDp = getSmallestWidthDp(activity); mStatusBarHeight = getInternalDimensionSize(res, STATUS_BAR_HEIGHT_RES_NAME); mActionBarHeight = getActionBarHeight(activity); mNavigationBarHeight = getNavigationBarHeight(activity); mNavigationBarWidth = getNavigationBarWidth(activity); mHasNavigationBar = (mNavigationBarHeight > 0); mTranslucentStatusBar = translucentStatusBar; mTranslucentNavBar = traslucentNavBar; }
ForecastAdapter(List<WeatherResponse.Period> items) { super(getActivity(), R.layout.row, R.id.date, items); size=getActivity() .getResources() .getDimensionPixelSize(R.dimen.icon); dateFormat=DateFormat.getDateFormat(getActivity()); timeFormat=DateFormat.getTimeFormat(getActivity()); }
@Test public void shouldSetTextAndTextColorWhileInflatingXmlLayout() throws Exception { Activity activity = activityController.get(); activity.setContentView(R.layout.text_views); TextView black = (TextView) activity.findViewById(R.id.black_text_view); assertThat(black.getText().toString()).isEqualTo("Black Text"); assertThat(black.getCurrentTextColor()).isEqualTo(0xff000000); TextView white = (TextView) activity.findViewById(R.id.white_text_view); assertThat(white.getText().toString()).isEqualTo("White Text"); assertThat(white.getCurrentTextColor()).isEqualTo(activity.getResources().getColor(android.R.color.white)); TextView grey = (TextView) activity.findViewById(R.id.grey_text_view); assertThat(grey.getText().toString()).isEqualTo("Grey Text"); assertThat(grey.getCurrentTextColor()).isEqualTo(activity.getResources().getColor(R.color.grey42)); }
@Test public void getBackgroundDrawable() throws Exception { Drawable drawable = activity.getResources().getDrawable(android.R.drawable.bottom_bar); window.setBackgroundDrawable(drawable); assertThat(shadowOf(window).getBackgroundDrawable()).isSameAs(drawable); } }
@Test public void shouldSetHintAndHintColorWhileInflatingXmlLayout() throws Exception { Activity activity = activityController.get(); activity.setContentView(R.layout.text_views_hints); TextView black = (TextView) activity.findViewById(R.id.black_text_view_hint); assertThat(black.getHint().toString()).isEqualTo("Black Hint"); assertThat(black.getCurrentHintTextColor()).isEqualTo(0xff000000); TextView white = (TextView) activity.findViewById(R.id.white_text_view_hint); assertThat(white.getHint().toString()).isEqualTo("White Hint"); assertThat(white.getCurrentHintTextColor()).isEqualTo(activity.getResources().getColor(android.R.color.white)); TextView grey = (TextView) activity.findViewById(R.id.grey_text_view_hint); assertThat(grey.getHint().toString()).isEqualTo("Grey Hint"); assertThat(grey.getCurrentHintTextColor()).isEqualTo(activity.getResources().getColor(R.color.grey42)); }