List of usage examples for android.content Context getTheme
@ViewDebug.ExportedProperty(deepExport = true) public abstract Resources.Theme getTheme();
From source file:com.aprz.easy_iosched.ui.widget.CustomRatingBar.java
public CustomRatingBar(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomRatingBar, 0, 0); try {/* w w w . java 2s .co m*/ mMaxRating = typedArray.getInt(R.styleable.CustomRatingBar_maxRating, DEFAULT_MAX_RATING); mFilledDrawable = typedArray.getDrawable(R.styleable.CustomRatingBar_filledDrawable); if (mFilledDrawable == null) { mFilledDrawable = ResourcesCompat.getDrawable(getResources(), DEFAULT_FILLED_DRAWABLE_ID, null); } mUnfilledDrawable = typedArray.getDrawable(R.styleable.CustomRatingBar_unfilledDrawable); if (mUnfilledDrawable == null) { mUnfilledDrawable = ResourcesCompat.getDrawable(getResources(), DEFAULT_UNFILLED_DRAWABLE_ID, null); } } finally { typedArray.recycle(); } setSaveEnabled(true); }
From source file:com.github.antoniodisanto92.swipeselector.SwipeSelector.java
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SwipeSelector, defStyleAttr, defStyleRes);//from ww w . ja va 2s . co m int indicatorSize; int indicatorMargin; int indicatorInActiveColor; int indicatorActiveColor; int leftButtonResource; int rightButtonResource; String customFontPath; int titleTextAppearance; int descriptionTextAppearance; int descriptionGravity; try { indicatorSize = (int) ta.getDimension(R.styleable.SwipeSelector_swipe_indicatorSize, PixelUtils.dpToPixel(context, DEFAULT_INDICATOR_SIZE)); indicatorMargin = (int) ta.getDimension(R.styleable.SwipeSelector_swipe_indicatorMargin, PixelUtils.dpToPixel(context, DEFAULT_INDICATOR_MARGIN)); indicatorInActiveColor = ta.getColor(R.styleable.SwipeSelector_swipe_indicatorInActiveColor, ContextCompat.getColor(context, R.color.swipeselector_color_indicator_inactive)); indicatorActiveColor = ta.getColor(R.styleable.SwipeSelector_swipe_indicatorActiveColor, ContextCompat.getColor(context, R.color.swipeselector_color_indicator_active)); leftButtonResource = ta.getResourceId(R.styleable.SwipeSelector_swipe_leftButtonResource, R.drawable.ic_action_navigation_chevron_left); rightButtonResource = ta.getResourceId(R.styleable.SwipeSelector_swipe_rightButtonResource, R.drawable.ic_action_navigation_chevron_right); customFontPath = ta.getString(R.styleable.SwipeSelector_swipe_customFontPath); titleTextAppearance = ta.getResourceId(R.styleable.SwipeSelector_swipe_titleTextAppearance, -1); descriptionTextAppearance = ta.getResourceId(R.styleable.SwipeSelector_swipe_descriptionTextAppearance, -1); descriptionGravity = ta.getInteger(R.styleable.SwipeSelector_swipe_descriptionGravity, -1); } finally { ta.recycle(); } LayoutInflater inflater = LayoutInflater.from(context); inflater.inflate(R.layout.swipeselector_layout, this); ViewPager pager = (ViewPager) findViewById(R.id.swipeselector_layout_swipePager); ViewGroup indicatorContainer = (ViewGroup) findViewById(R.id.swipeselector_layout_circleContainer); ImageView leftButton = (ImageView) findViewById(R.id.swipeselector_layout_leftButton); ImageView rightButton = (ImageView) findViewById(R.id.swipeselector_layout_rightButton); mAdapter = new SwipeAdapter.Builder().viewPager(pager).indicatorContainer(indicatorContainer) .indicatorSize(indicatorSize).indicatorMargin(indicatorMargin) .inActiveIndicatorColor(indicatorInActiveColor).activeIndicatorColor(indicatorActiveColor) .leftButtonResource(leftButtonResource).rightButtonResource(rightButtonResource) .leftButton(leftButton).rightButton(rightButton).customFontPath(customFontPath) .titleTextAppearance(titleTextAppearance).descriptionTextAppearance(descriptionTextAppearance) .descriptionGravity(descriptionGravity).build(); pager.setAdapter(mAdapter); }
From source file:eu.faircode.adblocker.Receiver.java
public static void notifyNewApplication(int uid, Context context) { if (uid < 0) return;//w w w .j a v a 2 s .c o m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); try { // Get application info String name = TextUtils.join(", ", Util.getApplicationNames(uid, context)); // Get application info PackageManager pm = context.getPackageManager(); String[] packages = pm.getPackagesForUid(uid); if (packages.length < 1) throw new PackageManager.NameNotFoundException(Integer.toString(uid)); boolean internet = Util.hasInternet(uid, context); // Build notification Intent main = new Intent(context, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_REFRESH, true); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT); Util.setTheme(context); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_security_white_24dp) .setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi) .setColor(tv.data).setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET); } // Get defaults SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE); SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE); boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true)); boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true)); // Build Wi-Fi action Intent riWifi = new Intent(context, ServiceSinkhole.class); riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi"); riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid); riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi); PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off, context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi); // Build mobile action Intent riOther = new Intent(context, ServiceSinkhole.class); riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other"); riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid); riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other); PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(other ? R.drawable.other_on : R.drawable.other_off, context.getString(other ? R.string.title_allow : R.string.title_block), piOther); // Show notification if (internet) NotificationManagerCompat.from(context).notify(uid, builder.build()); else { NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder); expanded.bigText(context.getString(R.string.msg_installed, name)); expanded.setSummaryText(context.getString(R.string.title_internet)); NotificationManagerCompat.from(context).notify(uid, expanded.build()); } } catch (PackageManager.NameNotFoundException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } }
From source file:com.tompee.funtablayout.SimpleTabAdapter.java
private void getDefaultValues(Context context) { /** Selected Appearance */ TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); theme.resolveAttribute(android.R.attr.textColorPrimary, typedValue, true); TypedArray arr = context.obtainStyledAttributes(typedValue.data, new int[] { android.R.attr.textColorPrimary }); mTabSelectedTextColor = arr.getColor(0, -1); arr.recycle();/* w w w .j a v a 2 s . c om*/ /** Tab Indicator */ mTabIndicatorHeight = context.getResources().getDimensionPixelSize(R.dimen.tabIndicatorHeight); }
From source file:org.microg.tools.ui.Condition.java
public Drawable getIcon(Context context) { if (iconRes != 0) { return ResourcesCompat.getDrawable(context.getResources(), iconRes, context.getTheme()); }/*from ww w .j a v a 2 s. c o m*/ return icon; }
From source file:com.master.metehan.filtereagle.Receiver.java
public static void notifyNewApplication(int uid, Context context) { if (uid < 0) return;//from w ww . java 2 s . c o m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); try { // Get application info String name = TextUtils.join(", ", Util.getApplicationNames(uid, context)); // Get application info PackageManager pm = context.getPackageManager(); String[] packages = pm.getPackagesForUid(uid); if (packages == null || packages.length < 1) throw new PackageManager.NameNotFoundException(Integer.toString(uid)); boolean internet = Util.hasInternet(uid, context); // Build notification Intent main = new Intent(context, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_REFRESH, true); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT); Util.setTheme(context); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_security_white_24dp) .setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi) .setColor(tv.data).setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET); } // Get defaults SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE); SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE); boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true)); boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true)); // Build Wi-Fi action Intent riWifi = new Intent(context, ServiceSinkhole.class); riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi"); riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid); riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi); PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off, context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi); // Build mobile action Intent riOther = new Intent(context, ServiceSinkhole.class); riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set); riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other"); riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid); riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other); PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(other ? R.drawable.other_on : R.drawable.other_off, context.getString(other ? R.string.title_allow : R.string.title_block), piOther); // Show notification if (internet) NotificationManagerCompat.from(context).notify(uid, builder.build()); else { NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder); expanded.bigText(context.getString(R.string.msg_installed, name)); expanded.setSummaryText(context.getString(R.string.title_internet)); NotificationManagerCompat.from(context).notify(uid, expanded.build()); } } catch (PackageManager.NameNotFoundException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } }
From source file:net.reichholf.dreamdroid.fragment.helper.HttpFragmentHelper.java
public void onActivityCreated() { if (mSwipeRefreshLayout == null) return;//from w w w.j a v a 2 s. c o m Context ctx = getAppCompatActivity(); TypedValue typed_value = new TypedValue(); ctx.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, typed_value, true); mSwipeRefreshLayout.setProgressViewOffset(false, 0, getAppCompatActivity().getResources().getDimensionPixelSize(typed_value.resourceId)); ctx.getTheme().resolveAttribute(R.attr.colorAccent, typed_value, true); int accent = ctx.getResources().getColor(typed_value.resourceId, ctx.getTheme()); mSwipeRefreshLayout.setColorSchemeColors(accent); }
From source file:com.example.jit.home.SlidingTabStrip.java
SlidingTabStrip(Context context, AttributeSet attrs) { super(context, attrs); setWillNotDraw(false);//w w w.j a va2 s . c om final float density = getResources().getDisplayMetrics().density; TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorForeground, outValue, true); final int themeForegroundColor = outValue.data; mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor, DEFAULT_BOTTOM_BORDER_COLOR_ALPHA); mDefaultTabColorizer = new SimpleTabColorizer(); mDefaultTabColorizer.setIndicatorColors(DEFAULT_SELECTED_INDICATOR_COLOR); mBottomBorderThickness = (int) (DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density); mBottomBorderPaint = new Paint(); mBottomBorderPaint.setColor(mDefaultBottomBorderColor); mSelectedIndicatorThickness = (int) (SELECTED_INDICATOR_THICKNESS_DIPS * density); mSelectedIndicatorPaint = new Paint(); }
From source file:com.auth0.android.lock.internal.configuration.Theme.java
private String resolveStringResource(Context context, @StringRes int res, @AttrRes int attrName) { if (res > 0) { return context.getString(res); }//w w w .ja va2s . co m TypedValue typedValue = new TypedValue(); context.getTheme().resolveAttribute(attrName, typedValue, true); return context.getString(typedValue.resourceId); }
From source file:id.bizdir.ui.widget.DividerItemDecoration.java
public DividerItemDecoration(Context context, int orientation) { //final TypedArray a = context.obtainStyledAttributes(ATTRS); //mDivider = context.getDrawable(0); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { mDivider = context.getResources().getDrawable(R.drawable.shape_line, context.getTheme()); } else {/* w ww .j a v a2 s. com*/ mDivider = context.getResources().getDrawable(R.drawable.shape_line); } //a.recycle(); setOrientation(orientation); }