Java Code Examples for android.content.Context#getResources()

The following examples show how to use android.content.Context#getResources() . 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: YearPickerView.java    From date_picker_converter with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 2
Source File: NavigationUtils.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
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;
    }
}
 
Example 3
Source File: BookmarkWidgetService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@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);
        }
    });
}
 
Example 4
Source File: RudenessScreenHelper.java    From Rudeness with Apache License 2.0 6 votes vote down vote up
/**
 * 重新计算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;
}
 
Example 5
Source File: BaseActivity.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 6 votes vote down vote up
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);
    }
 
Example 6
Source File: ViewInspectorToolbar.java    From ViewInspector with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 7
Source File: DriverMapPresenter.java    From ridesharing-android with MIT License 5 votes vote down vote up
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);
}
 
Example 8
Source File: ViewUtils.java    From TheGreatAdapter with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: LetterBitmap.java    From andOTP with MIT License 5 votes vote down vote up
/**
 * 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();
}
 
Example 10
Source File: Settings.java    From Hangar with GNU General Public License v3.0 5 votes vote down vote up
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) {
    }
}
 
Example 11
Source File: InfoBarContainerLayout.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source File: DensityUtil.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * 根据手机的分辨率从 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;
}
 
Example 13
Source File: RawResourceDataSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @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);
  }
}
 
Example 14
Source File: IconsManager.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
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));
}
 
Example 15
Source File: UiModeManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 16
Source File: ImageLoader.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
private ImageLoader(Context context) {
  this.weakContext = new WeakReference<>(context);
  this.resources = context.getResources();
  this.windowManager = ((WindowManager) context.getSystemService(Service.WINDOW_SERVICE));
}
 
Example 17
Source File: ModDisplay.java    From GravityBox with Apache License 2.0 4 votes vote down vote up
@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);
            }
        }
    }
}
 
Example 18
Source File: ImageLoader.java    From Yahala-Messenger with MIT License 4 votes vote down vote up
protected ImageLoader(Context context, int imageSize) {
    mResources = context.getResources();
    mImageSize = imageSize;
}
 
Example 19
Source File: MessageViewHolder.java    From eternity with Apache License 2.0 3 votes vote down vote up
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;
}
 
Example 20
Source File: DictionaryInfoUtils.java    From Android-Keyboard with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}