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.AdapterAccess.java

public AdapterAccess(Context context, Cursor cursor) {
    super(context, cursor, 0);
    colID = cursor.getColumnIndex("ID");
    colVersion = cursor.getColumnIndex("version");
    colProtocol = cursor.getColumnIndex("protocol");
    colDaddr = cursor.getColumnIndex("daddr");
    colDPort = cursor.getColumnIndex("dport");
    colTime = cursor.getColumnIndex("time");
    colAllowed = cursor.getColumnIndex("allowed");
    colBlock = cursor.getColumnIndex("block");
    colSent = cursor.getColumnIndex("sent");
    colReceived = cursor.getColumnIndex("received");
    colConnections = cursor.getColumnIndex("connections");

    TypedArray ta = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorSecondary });
    try {/*from   w  ww  .j  a  v a2 s.c o m*/
        colorText = ta.getColor(0, 0);
    } finally {
        ta.recycle();
    }

    TypedValue tv = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    colorOn = tv.data;
    context.getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    colorOff = tv.data;
}

From source file:com.geecko.QuickLyric.AboutActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    int[] themes = new int[] { R.style.Theme_QuickLyric, R.style.Theme_QuickLyric_Red,
            R.style.Theme_QuickLyric_Purple, R.style.Theme_QuickLyric_Indigo, R.style.Theme_QuickLyric_Green,
            R.style.Theme_QuickLyric_Lime, R.style.Theme_QuickLyric_Brown, R.style.Theme_QuickLyric_Dark };
    int themeNum = Integer.valueOf(sharedPref.getString("pref_theme", "0"));
    boolean nightMode = sharedPref.getBoolean("pref_night_mode", false);
    if (nightMode && NightTimeVerifier.check(this))
        setTheme(R.style.Theme_QuickLyric_Night);
    else/*  w w  w . j a va  2s.  c o m*/
        setTheme(themes[themeNum]);
    TypedValue primaryColor = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, primaryColor, true);
    setStatusBarColor(null);

    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    Toolbar toolbar = new Toolbar(this);
    toolbar.setTitle(R.string.pref_about);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        toolbar.setElevation(8f);
    toolbar.setBackgroundColor(primaryColor.data);
    toolbar.setTitleTextColor(Color.WHITE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(null, null,
                primaryColor.data);
        this.setTaskDescription(taskDescription);
    }

    View.OnClickListener productTourAction = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setupDemoScreen();
        }
    };

    Element productTourElement = new Element().setTitle(getString(R.string.about_product_tour));
    productTourElement.setOnClickListener(productTourAction);
    Element crowdinElement = new Element().setTitle(getString(R.string.about_crowdin));
    crowdinElement
            .setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://crowdin.com/project/quicklyric")));
    Element ossLicensesElement = new Element().setTitle("Open Source Licenses");
    ossLicensesElement.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            WebView webView = new WebView(AboutActivity.this);
            String data = getResources().getString(R.string.open_source_librairies_licenses);
            webView.loadData(data, "text/html; charset=utf-8", "UTF-8");
            new AlertDialog.Builder(AboutActivity.this).setView(webView).show();
        }
    });
    Element tosElement = new Element().setTitle(getString(R.string.about_read_ToS));
    tosElement.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            WebView webView = new WebView(AboutActivity.this);
            String data = getResources().getString(R.string.QL_EULA);
            webView.loadData(data, "text/html; charset=utf-8", "UTF-8");
            new AlertDialog.Builder(AboutActivity.this).setView(webView).show();
        }
    });
    Element cookElement = new Element().setTitle("Icon Designer");
    cookElement.setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://cookicons.co/")));

    View aboutView = new AboutPage(this).setDescription("QuickLyric is made with love in Brussels, Belgium.") // FixMe
            .addEmail("contact@QuickLyric.be").addFacebook("QuickLyric").addGitHub("geecko86/QuickLyric")
            .addPlayStore("test").addTwitter("QuickLyric").addWebsite("http://www.quicklyric.be")
            .setImage(R.drawable.icon).addItem(productTourElement).addItem(crowdinElement).addItem(cookElement)
            .addItem(ossLicensesElement).addItem(tosElement).create();
    aboutView.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    linearLayout.addView(toolbar);
    linearLayout.addView(aboutView);
    setContentView(linearLayout);

    final Drawable upArrow;
    if (Build.VERSION.SDK_INT >= 21) {
        upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_material);
        upArrow.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
    } else
        upArrow = getResources().getDrawable(R.drawable.ic_arrow_back);

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(upArrow);
}

From source file:com.hangulo.powercontact.util.Utils.java

public static int getAttributeHeight(Context ctx, int resid) {
    int retHeight = 0;
    TypedValue tv = new TypedValue();
    if (ctx.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        retHeight = TypedValue.complexToDimensionPixelSize(tv.data, ctx.getResources().getDisplayMetrics());

    }//from  www .j  av a  2s. co m
    return retHeight;
}

From source file:com.example.examplersqr.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //////////////////////
    //  Setup QR Bar    //
    //////////////////////
    inAnim = AnimationUtils.loadAnimation(this, R.anim.abc_slide_in_top);
    outAnim = AnimationUtils.loadAnimation(this, R.anim.abc_slide_out_top);
    qrBar = (LinearLayout) findViewById(R.id.myQRBar);

    // In production, better to get this from a "values.xml" resource
    // in a res folder appropriate to screen size / orientation
    columnCount = 2;/*w  w w .jav  a2s  .c  o m*/

    // Set the QRBar Height to that of the ActionBar
    TypedValue tv = new TypedValue();
    if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
        qrBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    }

    tvQRBarTitle = (TextView) findViewById(R.id.tvQRBarTitle);
    tvQRBarTitle.setText("Tap to add item at top...");
    tvQRBarTitle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            addItemAtPosition(0, "NEW CARD ADDED ON: " + new Date().toString());
        }
    });

    //////////////////////////////
    //  Setup Swipe To Refresh  //
    //////////////////////////////
    swiper = (TargetedSwipeRefreshLayout) findViewById(R.id.swipe_container);
    swiper.setSize(SwipeRefreshLayout.LARGE);
    swiper.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_orange_light,
            android.R.color.holo_green_light, android.R.color.holo_red_light);

    swiper.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            // This is where you should kickoff the
            // refreshing task.

            // For now, just wait a few seconds and turn off refreshing.
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (myDataset != null && mAdapter != null) {
                        Collections.shuffle(myDataset);
                        mAdapter.notifyDataSetChanged();
                    }
                    swiper.setRefreshing(false);
                }
            }, 5000);
        }
    });

    //////////////////////////////////////////////
    //  Grab the StaggeredGrid & Layout Manager //
    //////////////////////////////////////////////
    mRecycler = (RecyclerView) findViewById(R.id.rvExampleGrid);
    mRecycler.addItemDecoration(new QRBarDecoration(columnCount, qrBarHeight));
    // mRecycler.addItemDecoration(new OverlapDecoration());

    mSGLM = new StaggeredGridLayoutManager(columnCount, StaggeredGridLayoutManager.VERTICAL);

    mRecycler.setLayoutManager(mSGLM);

    //////////////////////////////
    //  Setup Adapter & DataSet //
    //////////////////////////////
    myDataset = new ArrayList<String>();

    // Load up the dataset with random titles
    for (int x = 0; x < 50; x++) {
        myDataset.add(someTitles[randy.nextInt(someTitles.length)]);
    }

    mAdapter = new RVAdapter(this, myDataset);

    /////////////////////////////////////////////
    //  Setup the RecyclerView Scroll Listener //
    /////////////////////////////////////////////
    mRecycler.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

            // Simple check if moved vertically.
            // React to scrolls of a minimum amount (3, in this case)
            if (dy > 3) {

                if (qrBar.getVisibility() == View.VISIBLE)
                    hideQRBar();

            } else if (dy < -3) {

                if (qrBar.getVisibility() == View.GONE)
                    showQRBar();
            }
        }
    });

    // Set the RecyclerView's Adapter
    mRecycler.setAdapter(mAdapter);

    // Set the Recyclerview to be the target scrollable view
    // for the TargetedSwipeRefreshAdapter.
    swiper.setTargetScrollableView(mRecycler);

}

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

/**
 * Called by {@link #installTitleView(LayoutInflater, ViewGroup, Bundle)} to inflate
 * title view.  Default implementation uses layout file lb_browse_title.
 * Subclass may override and use its own layout, the layout must have a descendant with id
 * browse_title_group that implements {@link TitleViewAdapter.Provider}. Subclass may return
 * null if no title is needed./*from  ww w.j  a v a2 s .  c o  m*/
 *
 * @param inflater           The LayoutInflater object that can be used to inflate
 *                           any views in the fragment,
 * @param parent             Parent of title view.
 * @param savedInstanceState If non-null, this fragment is being re-constructed
 *                           from a previous saved state as given here.
 * @return Title view which must have a descendant with id browse_title_group that implements
 *         {@link TitleViewAdapter.Provider}, or null for no title view.
 */
public View onInflateTitleView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    TypedValue typedValue = new TypedValue();
    boolean found = parent.getContext().getTheme().resolveAttribute(R.attr.browseTitleViewLayout, typedValue,
            true);
    return inflater.inflate(found ? typedValue.resourceId : R.layout.lb_browse_title, parent, false);
}

From source file:com.auth0.android.lock.internal.configuration.Theme.java

@ColorInt
private int resolveColorResource(Context context, @ColorRes int res, @AttrRes int attrName) {
    if (res > 0) {
        return ContextCompat.getColor(context, res);
    }/*from www.  j a v a2 s  . c  om*/

    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(attrName, typedValue, true);
    return ContextCompat.getColor(context, typedValue.resourceId);
}

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

/**
 * Helper to get the default Selectable Background. Returns the resourceId of the
 * {@code R.attr.selectableItemBackground} attribute of the overridden style.
 *
 * @param context the context/*w  ww . ja  v a2 s.  co  m*/
 * @return Default selectable background resId
 * @since 5.0.0-b7
 * @deprecated Use {@link #getSelectableItemBackground(Context)} instead.
 */
@Deprecated
public static int getSelectableBackground(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.selectableItemBackground, outValue, true);
    return outValue.resourceId;
}

From source file:com.acrylicgoat.houstonbicyclemuseum.view.SlidingTabLayout.java

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);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }//from   w  w  w .  jav a 2s .  co  m

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        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.auth0.android.lock.internal.configuration.Theme.java

private Drawable resolveDrawableResource(Context context, @DrawableRes int res, @AttrRes int attrName) {
    if (res > 0) {
        return ContextCompat.getDrawable(context, res);
    }/*from   w w  w  .  ja  va 2s .c o  m*/

    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(attrName, typedValue, true);
    return ContextCompat.getDrawable(context, typedValue.resourceId);
}

From source file:com.bruno.distribuciones.android.SlidingTabLayout.java

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.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);/*from ww w  .j  ava 2s  .  co  m*/

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