Example usage for android.util TypedValue TypedValue

List of usage examples for android.util TypedValue TypedValue

Introduction

In this page you can find the example usage for android.util TypedValue TypedValue.

Prototype

TypedValue

Source Link

Usage

From source file:android_network.hetnet.vpn_service.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;/* w w  w . j av a2  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, MainActivity.class);
        main.putExtra(MainActivity.EXTRA_REFRESH, true);
        main.putExtra(MainActivity.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).setContentIntent(pi).setColor(tv.data)
                .setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            builder.setContentTitle(name).setContentText(context.getString(R.string.msg_installed_n));
        else
            builder.setContentTitle(context.getString(R.string.app_name))
                    .setContentText(context.getString(R.string.msg_installed, name));

        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);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                expanded.bigText(context.getString(R.string.msg_installed_n));
            else
                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.alimuzaffar.lib.widgets.PinEntryEditText.java

private void init(Context context, AttributeSet attrs) {
    float multi = context.getResources().getDisplayMetrics().density;
    mLineStroke = multi * mLineStroke;//from  w ww.j a v  a 2s.  c om
    mLineStrokeSelected = multi * mLineStrokeSelected;
    mSpace = multi * mSpace; //convert to pixels for our density
    mTextBottomPadding = multi * mTextBottomPadding; //convert to pixels for our density

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PinEntryEditText, 0, 0);
    try {
        TypedValue outValue = new TypedValue();
        ta.getValue(R.styleable.PinEntryEditText_pinAnimationType, outValue);
        mAnimatedType = outValue.data;
        mMask = ta.getString(R.styleable.PinEntryEditText_pinCharacterMask);
        mLineStroke = ta.getDimension(R.styleable.PinEntryEditText_pinLineStroke, mLineStroke);
        mLineStrokeSelected = ta.getDimension(R.styleable.PinEntryEditText_pinLineStrokeSelected,
                mLineStrokeSelected);
        mSpace = ta.getDimension(R.styleable.PinEntryEditText_pinCharacterSpacing, mSpace);
        mTextBottomPadding = ta.getDimension(R.styleable.PinEntryEditText_pinTextBottomPadding,
                mTextBottomPadding);
        mIsDigitSquare = ta.getBoolean(R.styleable.PinEntryEditText_pinBackgroundIsSquare, mIsDigitSquare);
        mPinBackground = ta.getDrawable(R.styleable.PinEntryEditText_pinBackgroundDrawable);
        ColorStateList colors = ta.getColorStateList(R.styleable.PinEntryEditText_pinLineColors);
        if (colors != null) {
            mColorStates = colors;
        }
    } finally {
        ta.recycle();
    }

    mCharPaint = new Paint(getPaint());
    mLastCharPaint = new Paint(getPaint());
    mLinesPaint = new Paint(getPaint());
    mLinesPaint.setStrokeWidth(mLineStroke);

    TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorControlActivated, outValue, true);
    int colorSelected = outValue.data;
    mColors[0] = colorSelected;

    int colorFocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal);
    mColors[1] = colorFocused;

    int colorUnfocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal);
    mColors[2] = colorUnfocused;

    setBackgroundResource(0);

    mMaxLength = attrs.getAttributeIntValue(XML_NAMESPACE_ANDROID, "maxLength", 4);
    mNumChars = mMaxLength;

    //Disable copy paste
    super.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });
    // When tapped, move cursor to end of text.
    super.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setSelection(getText().length());
            if (mClickListener != null) {
                mClickListener.onClick(v);
            }
        }
    });

    super.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            setSelection(getText().length());
            return true;
        }
    });

    //If input type is password and no mask is set, use a default mask
    if ((getInputType() & InputType.TYPE_TEXT_VARIATION_PASSWORD) == InputType.TYPE_TEXT_VARIATION_PASSWORD
            && TextUtils.isEmpty(mMask)) {
        mMask = "\u25CF";
    } else if ((getInputType()
            & InputType.TYPE_NUMBER_VARIATION_PASSWORD) == InputType.TYPE_NUMBER_VARIATION_PASSWORD
            && TextUtils.isEmpty(mMask)) {
        mMask = "\u25CF";
    }

    if (!TextUtils.isEmpty(mMask)) {
        mMaskChars = getMaskChars();
    }

    //Height of the characters, used if there is a background drawable
    getPaint().getTextBounds("|", 0, 1, mTextHeight);
}

From source file:cn.kavelcortex.bookpriceculculator.TotalPrice.java

private void initStatusBar() {
    TypedValue typedValue = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
    int color = typedValue.data;
    mDrawerLayout.setStatusBarBackgroundColor(color);
    initButtonAOR();/*from w w  w  . j  a  v  a 2 s.  c om*/
}

From source file:com.flexible.flexibleadapter.utils.DrawableUtils.java

/**
 * Helper to get the system default Color Control Highlight. Returns the color of the
 * {@code R.attr.colorControlHighlight} attribute in the overridden style.
 *
 * @param context the context//  w w  w.  jav  a  2 s  . com
 * @return Default Color Control Highlight
 * @since 5.0.0-b7 Created, returns the resourceId
 * <br/> 5.0.0-rc1 Now returns the real color (not the resourceId)
 */
@ColorInt
public static int getColorControlHighlight(Context context) {
    TypedValue outValue = new TypedValue();
    // It's important to not use the android.R because this wouldn't add the overridden drawable
    context.getTheme().resolveAttribute(R.attr.colorControlHighlight, outValue, true);
    if (Utils.hasMarshmallow())
        return context.getColor(outValue.resourceId);
    else
        return context.getResources().getColor(outValue.resourceId);
}

From source file:com.greencode.enticement_android.UI.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from w  w  w. j a va  2s  .co  m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    //        textView.setBackgroundColor(R.color.bg_horizontal_item);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.androzic.waypoint.WaypointInfo.java

@SuppressLint("NewApi")
private void updateWaypointInfo(double lat, double lon) {
    Androzic application = Androzic.getApplication();
    Activity activity = getActivity();/*from   ww  w.  java 2 s.co m*/
    Dialog dialog = getDialog();
    View view = getView();

    WebView description = (WebView) view.findViewById(R.id.description);

    if ("".equals(waypoint.description)) {
        description.setVisibility(View.GONE);
    } else {
        String descriptionHtml;
        try {
            TypedValue tv = new TypedValue();
            Theme theme = activity.getTheme();
            Resources resources = getResources();
            theme.resolveAttribute(android.R.attr.textColorSecondary, tv, true);
            int secondaryColor = resources.getColor(tv.resourceId);
            String css = String.format(
                    "<style type=\"text/css\">html,body{margin:0;background:transparent} *{color:#%06X}</style>\n",
                    (secondaryColor & 0x00FFFFFF));
            descriptionHtml = css + waypoint.description;
            description.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageFinished(WebView view, String url) {
                    view.setBackgroundColor(Color.TRANSPARENT);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                        view.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
                }
            });
            description.setBackgroundColor(Color.TRANSPARENT);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                description.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
        } catch (Resources.NotFoundException e) {
            description.setBackgroundColor(Color.LTGRAY);
            descriptionHtml = waypoint.description;
        }

        WebSettings settings = description.getSettings();
        settings.setDefaultTextEncodingName("utf-8");
        settings.setAllowFileAccess(true);
        Uri baseUrl = Uri.fromFile(new File(application.dataPath));
        description.loadDataWithBaseURL(baseUrl.toString() + "/", descriptionHtml, "text/html", "utf-8", null);
    }

    String coords = StringFormatter.coordinates(" ", waypoint.latitude, waypoint.longitude);
    ((TextView) view.findViewById(R.id.coordinates)).setText(coords);

    if (waypoint.altitude != Integer.MIN_VALUE) {
        ((TextView) view.findViewById(R.id.altitude)).setText(StringFormatter.elevationH(waypoint.altitude));
    }

    double dist = Geo.distance(lat, lon, waypoint.latitude, waypoint.longitude);
    double bearing = Geo.bearing(lat, lon, waypoint.latitude, waypoint.longitude);
    bearing = application.fixDeclination(bearing);
    String distance = StringFormatter.distanceH(dist) + " " + StringFormatter.angleH(bearing);
    ((TextView) view.findViewById(R.id.distance)).setText(distance);

    if (waypoint.date != null)
        ((TextView) view.findViewById(R.id.date))
                .setText(DateFormat.getDateFormat(activity).format(waypoint.date) + " "
                        + DateFormat.getTimeFormat(activity).format(waypoint.date));
    else
        ((TextView) view.findViewById(R.id.date)).setVisibility(View.GONE);

    dialog.setTitle(waypoint.name);
}

From source file:android.support.v7.app.MediaRouterThemeHelper.java

private static boolean isLightTheme(Context context) {
    TypedValue value = new TypedValue();
    return context.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.isLightTheme, value, true)
            && value.data != 0;//from   w w w.  j  a v  a  2  s . c o m
}

From source file:com.jackie.movies.ui.MovieActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    loaderManager = getLoaderManager();//from ww w.j  ava 2s  . com

    recyclerView = getViewById(R.id.rec_view);
    RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, 2);
    recyclerView.setLayoutManager(layoutManager);
    TypedValue value = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, value, true);
    int colorPrimary = value.data;
    getTheme().resolveAttribute(R.attr.colorPrimaryDark, value, true);
    int colorPrimaryDark = value.data;
    recyclerView.setRefreshingColor(colorPrimary, colorPrimary, colorPrimary, colorPrimaryDark);
    recyclerView.setRefreshListener(this);
    recyclerView.setRefreshing(true);
    recyclerView.setupMoreListener(this, 1);

    if (savedInstanceState == null) {
        preferences = PreferenceManager.getDefaultSharedPreferences(this);
        mIsPopular = preferences.getBoolean(PREF_IS_POPULAR_KEY, false);
        updateMovies();
    } else {
        mIsFavourite = savedInstanceState.getBoolean(EXTRA_IS_FAVOUR, false);
        mIsPopular = savedInstanceState.getBoolean(EXTRA_IS_POPULAR, false);
        entity = savedInstanceState.getParcelable(EXTRA_ENTITY);
        mAdapter = new Adapter(this, entity.getResults());

        recyclerView.setAdapter(mAdapter);
    }
}

From source file:com.agenmate.lollipop.util.ColorUtils.java

public static int getAccentColorFromThemeIfAvailable(Context context) {
    TypedValue typedValue = new TypedValue();
    // First, try the android:colorAccent
    if (Build.VERSION.SDK_INT >= 21) {
        context.getTheme().resolveAttribute(android.R.attr.colorAccent, typedValue, true);
        return typedValue.data;
    }/*from ww  w  .  jav  a 2s . com*/
    // Next, try colorAccent from support lib
    int colorAccentResId = context.getResources().getIdentifier("colorAccent", "attr",
            context.getPackageName());
    if (colorAccentResId != 0 && context.getTheme().resolveAttribute(colorAccentResId, typedValue, true)) {
        return typedValue.data;
    }
    // Return the value in mdtp_accent_color
    return ContextCompat.getColor(context, R.color.colorAccent);
}

From source file:com.android.design.material.widgets.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*ww w  .j a  v a2  s . c om*/
 */
protected TextView createDefaultTabView(Context context) {
    final TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTabTextViewSize);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    final TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);
    final int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);
    return textView;
}