Example usage for android.content Context getTheme

List of usage examples for android.content Context getTheme

Introduction

In this page you can find the example usage for android.content Context getTheme.

Prototype

@ViewDebug.ExportedProperty(deepExport = true)
public abstract Resources.Theme getTheme();

Source Link

Document

Return the Theme object associated with this Context.

Usage

From source file:com.evilduck.animtest.DraggedPanelLayout.java

public void initAttrs(Context context, AttributeSet attrs) {
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.DraggedPanelLayout, 0, 0);

    try {/*from  w  w  w .jav  a 2  s.c  om*/
        parallaxFactor = a.getFloat(R.styleable.DraggedPanelLayout_parallax_factor, PARALLAX_FACTOR);
        if (parallaxFactor < 0.1 || parallaxFactor > 0.9) {
            parallaxFactor = PARALLAX_FACTOR;
        }

        int defaultHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100,
                getResources().getDisplayMetrics());
        bottomPanelPeekHeight = a.getDimensionPixelSize(R.styleable.DraggedPanelLayout_bottom_panel_height,
                defaultHeight);
        int shadowDrawableId = a.getResourceId(R.styleable.DraggedPanelLayout_shadow_drawable, -1);
        if (shadowDrawableId != -1) {
            shadowDrawable = getResources().getDrawable(shadowDrawableId);
            willDrawShadow = true;
            setWillNotDraw(!willDrawShadow);
        }
    } finally {
        a.recycle();
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = configuration.getScaledTouchSlop();
}

From source file:com.layer.atlas.AtlasMessageComposer.java

private void parseStyle(Context context, AttributeSet attrs, int defStyle) {
    TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AtlasMessageComposer,
            R.attr.AtlasMessageComposer, defStyle);
    mEnabled = ta.getBoolean(R.styleable.AtlasMessageComposer_android_enabled, true);
    ta.recycle();/*from   w w w  .ja  v a 2 s.c  o  m*/
}

From source file:com.bilibili.magicasakura.utils.GradientDrawableUtils.java

void setGradientRadius(Context context, AttributeSet attrs, GradientDrawable drawable, int gradientType)
        throws XmlPullParserException {
    TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs,
            new int[] { android.R.attr.gradientRadius });
    TypedValue value = a.peekValue(0);/*from  w w w  .  j  av a  2s  .co m*/
    if (value != null) {
        boolean radiusRel = value.type == TypedValue.TYPE_FRACTION;
        drawable.setGradientRadius(radiusRel ? value.getFraction(1.0f, 1.0f) : value.getFloat());
    } else if (gradientType == GradientDrawable.RADIAL_GRADIENT) {
        throw new XmlPullParserException(
                "<gradient> tag requires 'gradientRadius' " + "attribute with radial type");
    }
    a.recycle();
}

From source file:com.bilibili.magicasakura.utils.GradientDrawableInflateImpl.java

float getAttrFloatOrFraction(Context context, AttributeSet attrs, int attr, float defaultValue, float base,
        float pbase) {
    TypedArray a = DrawableUtils.obtainAttributes(context.getResources(), context.getTheme(), attrs,
            new int[] { attr });
    TypedValue tv = a.peekValue(0);// w w  w .  j av a 2s .  c  o  m
    float v = defaultValue;
    if (tv != null) {
        boolean isFraction = tv.type == TypedValue.TYPE_FRACTION;
        v = isFraction ? tv.getFraction(base, pbase) : tv.getFloat();
    }
    a.recycle();
    return v;
}

From source file:com.zhengde163.netguard.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;/*from  w  w w.  ja  v  a 2 s.c  om*/

    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);
        context.setTheme(R.style.AppThemeBlue);
        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:cn.njmeter.njmeter.widget.spinner.NiceSpinner.java

private int getDefaultTextColor(Context context) {
    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.textColorPrimary, typedValue, true);
    TypedArray typedArray = context.obtainStyledAttributes(typedValue.data,
            new int[] { android.R.attr.textColorPrimary });
    int defaultTextColor = typedArray.getColor(0, Color.BLACK);
    typedArray.recycle();//from   w w w. j a  va 2s  .c  o m
    return defaultTextColor;
}

From source file:net.yanzm.mth.MaterialTabHost.java

public MaterialTabHost(Context context, AttributeSet attrs) {
    super(context, attrs);

    inflater = LayoutInflater.from(context);

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MaterialTabHost, 0, 0);
    int indicatorColor = a.getColor(R.styleable.MaterialTabHost_colorTabIndicator, Color.YELLOW);
    colorControlActivated = a.getColor(R.styleable.MaterialTabHost_colorBackground, Color.WHITE);

    setBackgroundColor(colorControlActivated);
    a.recycle();/*from w w w .j  a  va 2s  . co m*/

    // ColorDrawable on 2.x does not use getBounds() so use ShapeDrawable
    indicator = new ShapeDrawable();
    indicator.setColorFilter(indicatorColor, PorterDuff.Mode.SRC_ATOP);

    Resources res = context.getResources();
    indicatorHeight = res.getDimensionPixelSize(R.dimen.mth_tab_indicator_height);
    leftOffset = res.getDimensionPixelSize(R.dimen.mth_tab_left_offset);
    int tabHeight = res.getDimensionPixelSize(R.dimen.mth_tab_height);

    tabWidget = new TabWidget(context);
    tabWidget.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, tabHeight));
    tabWidget.setId(android.R.id.tabs);
    tabWidget.setStripEnabled(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        tabWidget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
    }
    addView(tabWidget);

    FrameLayout fl = new FrameLayout(context);
    fl.setLayoutParams(new LayoutParams(0, 0));
    fl.setId(android.R.id.tabcontent);
    addView(fl);

    setup();

    setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (listener != null) {
                listener.onTabSelected(Integer.valueOf(tabId));
            }
        }
    });

    float density = getResources().getDisplayMetrics().density;

    // set elevation for App bar
    // http://www.google.com/design/spec/what-is-material/objects-in-3d-space.html#objects-in-3d-space-elevation
    ViewCompat.setElevation(this, APP_TAB_ELEVATION * density);
}

From source file:net.reichholf.dreamdroid.fragment.helper.DreamDroidHttpFragmentHelper.java

public void onActivityCreated() {
    if (mSwipeRefreshLayout == null)
        return;/*ww w.j a va 2  s.c  o  m*/

    Context ctx = getActionBarActivity();
    TypedValue typed_value = new TypedValue();
    ctx.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, typed_value, true);
    mSwipeRefreshLayout.setProgressViewOffset(false, 0,
            getActionBarActivity().getResources().getDimensionPixelSize(typed_value.resourceId));

    ctx.getTheme().resolveAttribute(R.attr.colorAccent, typed_value, true);
    int accent = ctx.getResources().getColor(typed_value.resourceId);
    mSwipeRefreshLayout.setColorSchemeColors(accent);
}

From source file:android.support.v17.leanback.app.GuidedStepFragment.java

private static boolean isGuidedStepTheme(Context context) {
    int resId = R.attr.guidedStepThemeFlag;
    TypedValue typedValue = new TypedValue();
    boolean found = context.getTheme().resolveAttribute(resId, typedValue, true);
    if (DEBUG)//from  www  .j  ava  2  s  .c  o  m
        Log.v(TAG, "Found guided step theme flag? " + found);
    return found && typedValue.type == TypedValue.TYPE_INT_BOOLEAN && typedValue.data != 0;
}

From source file:com.bilibili.magicasakura.utils.GradientDrawableInflateImpl.java

void setGradientRadius(Context context, AttributeSet attrs, GradientDrawable drawable, int gradientType)
        throws XmlPullParserException {
    TypedArray a = DrawableUtils.obtainAttributes(context.getResources(), context.getTheme(), attrs,
            new int[] { android.R.attr.gradientRadius });
    TypedValue value = a.peekValue(0);/*www. java2 s  . com*/
    if (value != null) {
        boolean radiusRel = value.type == TypedValue.TYPE_FRACTION;
        drawable.setGradientRadius(radiusRel ? value.getFraction(1.0f, 1.0f) : value.getFloat());
    } else if (gradientType == GradientDrawable.RADIAL_GRADIENT) {
        throw new XmlPullParserException(
                "<gradient> tag requires 'gradientRadius' " + "attribute with radial type");
    }
    a.recycle();
}