android.content.Context#getResources ( )源码实例Demo

下面列出了android.content.Context#getResources ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: date_picker_converter   文件: YearPickerView.java
public YearPickerView(Context context, DatePickerController controller) {
    super(context);
    mController = controller;
    mController.registerOnDateChangedListener(this);
    ViewGroup.LayoutParams frame = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    setLayoutParams(frame);
    Resources res = context.getResources();
    mViewSize = mController.getVersion() == DatePickerDialog.Version.VERSION_1
        ? res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height)
        : res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height_v2);
    mChildSize = res.getDimensionPixelOffset(R.dimen.mdtp_year_label_height);
    setVerticalFadingEdgeEnabled(true);
    setFadingEdgeLength(mChildSize / 3);
    init();
    setOnItemClickListener(this);
    setSelector(new StateListDrawable());
    setDividerHeight(0);
    onDateChanged();
}
 
源代码2 项目: ViewInspector   文件: ViewInspectorToolbar.java
public static WindowManager.LayoutParams createLayoutParams(Context context) {
  Resources res = context.getResources();
  int width = res.getDimensionPixelSize(R.dimen.view_inspector_toolbar_header_width)
      + res.getDimensionPixelSize(R.dimen.view_inspector_toolbar_icon_width) * TOOLBAR_MENU_ITEMS;
  int height = res.getDimensionPixelSize(R.dimen.view_inspector_toolbar_height);
  if (Build.VERSION.SDK_INT == 23) { // MARSHMALLOW
    height = res.getDimensionPixelSize(R.dimen.view_inspector_toolbar_height_m);
  }

  final WindowManager.LayoutParams params =
      new WindowManager.LayoutParams(width, height, TYPE_SYSTEM_ERROR,
          FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL | FLAG_LAYOUT_NO_LIMITS
              | FLAG_LAYOUT_INSET_DECOR | FLAG_LAYOUT_IN_SCREEN, TRANSLUCENT);
  params.gravity = Gravity.TOP | Gravity.RIGHT;

  return params;
}
 
源代码3 项目: MTweaks-KernelAdiutorMOD   文件: BaseActivity.java
public static ContextWrapper wrap(Context context, Locale newLocale) {

        Resources res = context.getResources();
        Configuration configuration = res.getConfiguration();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            configuration.setLocale(newLocale);

            LocaleList localeList = new LocaleList(newLocale);
            LocaleList.setDefault(localeList);
            configuration.setLocales(localeList);

            context = context.createConfigurationContext(configuration);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            configuration.setLocale(newLocale);
            context = context.createConfigurationContext(configuration);
        } else {
            configuration.locale = newLocale;
            res.updateConfiguration(configuration, res.getDisplayMetrics());
        }

        return new ContextWrapper(context);
    }
 
源代码4 项目: Rudeness   文件: RudenessScreenHelper.java
/**
 * 重新计算displayMetrics.xhdpi, 使单位pt重定义为设计稿的相对长度
 * @see #activate()
 *
 * @param context
 * @param designWidth 设计稿的宽度
 */
public static void resetDensity(Context context, float designWidth){
    if(context == null)
        return;

    Point size = new Point();
    ((WindowManager)context.getSystemService(WINDOW_SERVICE)).getDefaultDisplay().getSize(size);

    Resources resources = context.getResources();

    resources.getDisplayMetrics().xdpi = size.x/designWidth*72f;

    DisplayMetrics metrics = getMetricsOnMiui(context.getResources());
    if(metrics != null)
        metrics.xdpi = size.x/designWidth*72f;
}
 
源代码5 项目: 365browser   文件: BookmarkWidgetService.java
@UiThread
public void initialize(Context context, final BookmarkId folderId,
        BookmarkLoaderCallback callback) {
    mCallback = callback;

    Resources res = context.getResources();
    mLargeIconBridge = new LargeIconBridge(
            Profile.getLastUsedProfile().getOriginalProfile());
    mMinIconSizeDp = (int) res.getDimension(R.dimen.default_favicon_min_size);
    mDisplayedIconSize = res.getDimensionPixelSize(R.dimen.default_favicon_size);
    mCornerRadius = res.getDimensionPixelSize(R.dimen.default_favicon_corner_radius);
    int textSize = res.getDimensionPixelSize(R.dimen.default_favicon_icon_text_size);
    int iconColor =
            ApiCompatibilityUtils.getColor(res, R.color.default_favicon_background_color);
    mIconGenerator = new RoundedIconGenerator(mDisplayedIconSize, mDisplayedIconSize,
            mCornerRadius, iconColor, textSize);

    mRemainingTaskCount = 1;
    mBookmarkModel = new BookmarkModel();
    mBookmarkModel.runAfterBookmarkModelLoaded(new Runnable() {
        @Override
        public void run() {
            loadBookmarks(folderId);
        }
    });
}
 
源代码6 项目: Slide   文件: NavigationUtils.java
public static boolean hasNavBar(Context context) {
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);

    if (hasBackKey && hasHomeKey) {
        if (Build.MANUFACTURER.toLowerCase(Locale.ENGLISH).contains("samsung") && !Build.MODEL.toLowerCase(Locale.ENGLISH).contains("nexus")) {
            return false;
        }

        Resources resources = context.getResources();
        int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
        if (id > 0) {
            return resources.getBoolean(id);
        } else {
            return false;
        }
    } else {
        return true;
    }
}
 
源代码7 项目: ridesharing-android   文件: DriverMapPresenter.java
public DriverMapPresenter(Context context, DriverMapPresenter.DriverView view) {
    super(context, view, new DriverState(context));

    Resources r = context.getResources();
    float paddingTop = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, r.getDisplayMetrics());
    float paddingBottom = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, r.getDisplayMetrics());
    mapCenterOffset = (int) ((paddingBottom - paddingTop) / 2);

    trackingPresenter = new TrackingPresenter(context, view);
}
 
源代码8 项目: TheGreatAdapter   文件: ViewUtils.java
public static int getNavigationBarHeight(Context context) {
    Resources resources = context.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }
    return 0;
}
 
源代码9 项目: andOTP   文件: LetterBitmap.java
/**
 * Constructor for <code>LetterTileProvider</code>
 *
 * @param context The {@link Context} to use
 */
public LetterBitmap(Context context) {
    final Resources res = context.getResources();

    mPaint.setTypeface(Typeface.create("sans-serif-light", Typeface.BOLD));
    mPaint.setColor(Color.WHITE);
    mPaint.setTextAlign(Paint.Align.CENTER);
    mPaint.setAntiAlias(true);

    mColors = res.obtainTypedArray(R.array.letter_tile_colors);

    TypedValue typedValue = new TypedValue();
    res.getValue(R.dimen.tile_letter_font_size_scale, typedValue, true);
    mTileLetterFontSizeScale = typedValue.getFloat();
}
 
源代码10 项目: Hangar   文件: Settings.java
static void updateMoreAppsIcon(Context context) {
    try {
        Drawable d = new BitmapDrawable(context.getResources(), new IconHelper(mContext).cachedResourceIconHelper(MORE_APPS_PACKAGE));
        PrefsFragment mGeneralSettings = (PrefsFragment) mGetFragments.getFragmentByPosition(GENERAL_TAB);
        mGeneralSettings.more_apps_icon_preference.setIcon(d);
    } catch (Exception e) {
    }
}
 
源代码11 项目: delion   文件: InfoBarContainerLayout.java
/**
 * Creates an empty InfoBarContainerLayout.
 */
InfoBarContainerLayout(Context context) {
    super(context);
    Resources res = context.getResources();
    mBackInfobarHeight = res.getDimensionPixelSize(R.dimen.infobar_peeking_height);
    mFloatingBehavior = new FloatingBehavior(this);
}
 
源代码12 项目: AndroidBase   文件: DensityUtil.java
/**
 * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
 */
public static int dip2px(Context context, float dpValue) {
    Resources r = context.getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            dpValue, r.getDisplayMetrics());
    return (int) px;
}
 
源代码13 项目: TelePlus-Android   文件: RawResourceDataSource.java
/**
 * @param context A context.
 * @param listener An optional listener.
 */
public RawResourceDataSource(Context context, @Nullable TransferListener listener) {
  super(/* isNetwork= */ false);
  this.resources = context.getResources();
  if (listener != null) {
    addTransferListener(listener);
  }
}
 
源代码14 项目: Yahala-Messenger   文件: ImageLoader.java
protected ImageLoader(Context context, int imageSize) {
    mResources = context.getResources();
    mImageSize = imageSize;
}
 
源代码15 项目: GravityBox   文件: ModDisplay.java
@Override
public void onReceive(Context context, Intent intent) {
    if (DEBUG) log("Broadcast received: " + intent.toString());
    if (intent.getAction().equals(ACTION_GET_AUTOBRIGHTNESS_CONFIG) &&
            intent.hasExtra("receiver")) {
        ResultReceiver receiver = intent.getParcelableExtra("receiver");
        Bundle data = new Bundle();
        Resources res = context.getResources();
        data.putIntArray("config_autoBrightnessLevels",
                res.getIntArray(res.getIdentifier(
                        "config_autoBrightnessLevels", "array", "android")));
        data.putIntArray("config_autoBrightnessLcdBacklightValues",
                res.getIntArray(res.getIdentifier(
                        "config_autoBrightnessLcdBacklightValues", "array", "android")));
        receiver.send(RESULT_AUTOBRIGHTNESS_CONFIG, data);
    } else if (intent.getAction().equals(ACTION_SET_AUTOBRIGHTNESS_CONFIG)) {
        int[] luxArray = intent.getIntArrayExtra("config_autoBrightnessLevels");
        int[] brightnessArray = intent.getIntArrayExtra("config_autoBrightnessLcdBacklightValues");
        updateAutobrightnessConfig(luxArray, brightnessArray);
    } else if (intent.getAction().equals(GravityBoxSettings.ACTION_PREF_BUTTON_BACKLIGHT_CHANGED)) {
        if (intent.hasExtra(GravityBoxSettings.EXTRA_BB_MODE)) {
            mButtonBacklightMode = intent.getStringExtra(GravityBoxSettings.EXTRA_BB_MODE);
            updateButtonBacklight();
        }
        if (intent.hasExtra(GravityBoxSettings.EXTRA_BB_NOTIF)) {
            mButtonBacklightNotif = intent.getBooleanExtra(GravityBoxSettings.EXTRA_BB_NOTIF, false);
            if (!mButtonBacklightNotif) {
                updateButtonBacklight();
            }
        }
    } else if ((intent.getAction().equals(Intent.ACTION_SCREEN_ON)
            || intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) &&
            !mButtonBacklightMode.equals(GravityBoxSettings.BB_MODE_DEFAULT)) {
        updateButtonBacklight(intent.getAction().equals(Intent.ACTION_SCREEN_ON));
    } else if (intent.getAction().equals(GravityBoxSettings.ACTION_PREF_LOCKSCREEN_BG_CHANGED) &&
            intent.hasExtra(GravityBoxSettings.EXTRA_LOCKSCREEN_BG)) {
        mLsBgLastScreenEnabled = intent.getStringExtra(GravityBoxSettings.EXTRA_LOCKSCREEN_BG)
                .equals(GravityBoxSettings.LOCKSCREEN_BG_LAST_SCREEN);
        if (DEBUG_KIS) log("mLsBgLastScreenEnabled = " + mLsBgLastScreenEnabled);
    } else if (intent.getAction().equals(GravityBoxSettings.ACTION_BATTERY_LED_CHANGED) &&
            intent.hasExtra(GravityBoxSettings.EXTRA_BLED_CHARGING)) {
        ChargingLed cg = ChargingLed.valueOf(intent.getStringExtra(GravityBoxSettings.EXTRA_BLED_CHARGING));
        if (cg == ChargingLed.EMULATED || cg == ChargingLed.CONSTANT) {
            resetLight(LIGHT_ID_BATTERY);
        }
        mChargingLed = cg;
        if (!mPendingNotif) {
            resetLight(LIGHT_ID_NOTIFICATIONS);
        }
    } else if (intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
        boolean charging = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
        int level = (int) (100f * intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0)
                / intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100));
        if (mCharging != charging || mBatteryLevel != level) {
            mCharging = charging;
            mBatteryLevel = level;
            if ((mChargingLed == ChargingLed.EMULATED || mChargingLed == ChargingLed.CONSTANT) &&
                    !mPendingNotif) {
                resetLight(LIGHT_ID_NOTIFICATIONS);
            }
        }
    }
}
 
源代码16 项目: android_9.0.0_r45   文件: UiModeManagerService.java
@Override
public void onStart() {
    final Context context = getContext();

    final PowerManager powerManager =
            (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG);

    context.registerReceiver(mDockModeReceiver,
            new IntentFilter(Intent.ACTION_DOCK_EVENT));
    context.registerReceiver(mBatteryReceiver,
            new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    mConfiguration.setToDefaults();

    final Resources res = context.getResources();
    mDefaultUiModeType = res.getInteger(
            com.android.internal.R.integer.config_defaultUiModeType);
    mCarModeKeepsScreenOn = (res.getInteger(
            com.android.internal.R.integer.config_carDockKeepsScreenOn) == 1);
    mDeskModeKeepsScreenOn = (res.getInteger(
            com.android.internal.R.integer.config_deskDockKeepsScreenOn) == 1);
    mEnableCarDockLaunch = res.getBoolean(
            com.android.internal.R.bool.config_enableCarDockHomeLaunch);
    mUiModeLocked = res.getBoolean(com.android.internal.R.bool.config_lockUiMode);
    mNightModeLocked = res.getBoolean(com.android.internal.R.bool.config_lockDayNightMode);

    final PackageManager pm = context.getPackageManager();
    mTelevision = pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)
            || pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK);
    mWatch = pm.hasSystemFeature(PackageManager.FEATURE_WATCH);

    final int defaultNightMode = res.getInteger(
            com.android.internal.R.integer.config_defaultNightMode);
    mNightMode = Settings.Secure.getInt(context.getContentResolver(),
            Settings.Secure.UI_NIGHT_MODE, defaultNightMode);

    // Update the initial, static configurations.
    SystemServerInitThreadPool.get().submit(() -> {
        synchronized (mLock) {
            updateConfigurationLocked();
            sendConfigurationLocked();
        }

    }, TAG + ".onStart");
    publishBinderService(Context.UI_MODE_SERVICE, mService);
}
 
源代码17 项目: LaunchEnr   文件: IconsManager.java
public Drawable getResetIconDrawable(Context context, LauncherActivityInfo app, ItemInfo info) {
    final Drawable icon = new BitmapDrawable(context.getResources(), getDrawableIconForPackage(info.getTargetComponent()));
    return new BitmapDrawable(context.getResources(), LauncherIcons.createBadgedIconBitmap(icon, info.user, context, app.getApplicationInfo().targetSdkVersion));
}
 
源代码18 项目: aptoide-client-v8   文件: ImageLoader.java
private ImageLoader(Context context) {
  this.weakContext = new WeakReference<>(context);
  this.resources = context.getResources();
  this.windowManager = ((WindowManager) context.getSystemService(Service.WINDOW_SERVICE));
}
 
源代码19 项目: eternity   文件: MessageViewHolder.java
MessageViewHolder(Context context, MessageListener listener, View view) {
  super(context, view);

  ButterKnife.bind(this, view);

  this.resolver = new StringResolver(context.getResources());
  this.formatter = new TimeFormatter(resolver);

  this.listener = listener;
}
 
源代码20 项目: Android-Keyboard   文件: DictionaryInfoUtils.java
/**
 * Find out whether a dictionary is available for this locale.
 * @param context the context on which to check resources.
 * @param locale the locale to check for.
 * @return whether a (non-placeholder) dictionary is available or not.
 */
public static boolean isDictionaryAvailable(final Context context, final Locale locale) {
    final Resources res = context.getResources();
    return 0 != getMainDictionaryResourceIdIfAvailableForLocale(res, locale);
}
 
 方法所在类
 同类方法