List of usage examples for android.util TypedValue applyDimension
public static float applyDimension(int unit, float value, DisplayMetrics metrics)
From source file:com.aptoide.amethyst.utils.AptoideUtils.java
public static int getPixels(Context context, int dipValue) { Resources r = context.getResources(); int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, r.getDisplayMetrics()); Logger.d("getPixels", "" + px); return px;/* w w w. j a v a 2s . c o m*/ }
From source file:ch.gianulli.flashcards.ui.Flashcard.java
/** * @param view Instance of flashcard.xml *///from ww w . j a va 2 s .c o m public Flashcard(View view, OnCardAnsweredListener listener) { mListener = listener; mView = view; mQuestion = (StyledMarkdownView) view.findViewById(R.id.question); mAnswer = (StyledMarkdownView) view.findViewById(R.id.answer); mCardView = (CardView) view.findViewById(R.id.card); mButtonBar = view.findViewById(R.id.button_bar); mCorrectButton = (Button) view.findViewById(R.id.correct_button); mWrongButton = (Button) view.findViewById(R.id.wrong_button); mContext = mView.getContext(); // Load colors int[] attrs = { android.R.attr.textColorSecondary, android.R.attr.textColorPrimary }; TypedArray ta = mView.getContext().obtainStyledAttributes(R.style.AppTheme, attrs); sDeactivatedTextColor = colorToCSSString(ta.getColor(0, 0)); sDefaultTextColor = colorToCSSString(ta.getColor(1, 0)); ta.recycle(); sGreenTextColor = colorToCSSString(ContextCompat.getColor(mContext, R.color.green)); mQuestionColor = sDefaultTextColor; mAnswerColor = sGreenTextColor; // Make question visible mQuestion.setAlpha(1.0f); mAnswer.setAlpha(0.0f); // Setup WebViews WebSettings settings = mQuestion.getSettings(); settings.setDefaultFontSize(mFontSize); settings.setLoadsImagesAutomatically(true); settings.setGeolocationEnabled(false); settings.setAllowFileAccess(false); settings.setDisplayZoomControls(false); settings.setNeedInitialFocus(false); settings.setSupportZoom(false); settings.setSaveFormData(false); settings.setJavaScriptEnabled(true); mQuestion.setHorizontalScrollBarEnabled(false); mQuestion.setVerticalScrollBarEnabled(false); settings = mAnswer.getSettings(); settings.setDefaultFontSize(mFontSize); settings.setLoadsImagesAutomatically(true); settings.setGeolocationEnabled(false); settings.setAllowFileAccess(false); settings.setDisplayZoomControls(false); settings.setNeedInitialFocus(false); settings.setSupportZoom(false); settings.setSaveFormData(false); settings.setJavaScriptEnabled(true); mAnswer.setHorizontalScrollBarEnabled(false); mAnswer.setVerticalScrollBarEnabled(false); // Hack to disable text selection in WebViews mQuestion.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View v) { return true; } }); mAnswer.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View v) { return true; } }); // Card should "turn" on click final FrameLayout questionLayout = (FrameLayout) view.findViewById(R.id.question_layout); questionLayout.setClickable(true); questionLayout.setOnTouchListener(mTurnCardListener); mQuestion.setOnTouchListener(mTurnCardListener); mAnswer.setOnTouchListener(mTurnCardListener); // Deactivate card when user answers it mCorrectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { deactivateCard(true); mListener.onCardAnswered(mCard, true); } }); mWrongButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { deactivateCard(false); mListener.onCardAnswered(mCard, false); } }); // Limit card width to 400dp ViewTreeObserver observer = mCardView.getViewTreeObserver(); final int width480dp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 400, view.getContext().getResources().getDisplayMetrics()); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (mCardView.getWidth() > width480dp) { ViewGroup.LayoutParams layoutParams = mCardView.getLayoutParams(); layoutParams.width = width480dp; mCardView.setLayoutParams(layoutParams); mCardView.requestLayout(); return false; } return true; } }); }
From source file:fm.krui.kruifm.ScheduleFragment.java
/** * Converts dp values to an appropriate amount of pixels based on screen density of this device. * @param dp value of dp to convert// w w w . jav a 2 s . c o m * @return equivalent pixel count */ private int dpToPixels(int dp) { Resources r = getResources(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); }
From source file:com.QuarkLabs.BTCeClient.fragments.OrdersBookFragment.java
@Override public void onLoadFinished(Loader<JSONObject> loader, JSONObject data) { if (data == null) { Toast.makeText(getActivity(), R.string.GeneralErrorText, Toast.LENGTH_LONG).show(); } else if (data.length() == 0) { Toast.makeText(getActivity(), R.string.GeneralErrorText, Toast.LENGTH_LONG).show(); } else {/*from w w w .j a v a2 s . c om*/ final JSONArray asks = data.optJSONArray("asks"); final JSONArray bids = data.optJSONArray("bids"); mAsksAdapter.pushData(asks); mBidsAdapter.pushData(bids); mAsksList.setAdapter(mAsksAdapter); mBidsList.setAdapter(mBidsAdapter); mChartArea.removeAllViews(); StockChartView chartView = new StockChartView(getActivity()); final LinearSeries asksSeries = new LinearSeries(); final LinearSeries bidsSeries = new LinearSeries(); asksSeries.getAppearance().setOutlineColor(0xffff4444); bidsSeries.getAppearance().setOutlineColor(0xff0099cc); double sumAsks = 0.0; double sumBids = 0.0; for (int i = 0; i < bids.length(); i++) { sumBids += bids.optJSONArray(i).optDouble(1); } for (int i = bids.length() - 1; i >= 0; i--) { sumBids -= bids.optJSONArray(i).optDouble(1); bidsSeries.addPoint(sumBids); } for (int i = 0; i < asks.length(); i++) { asksSeries.addPoint(sumAsks); sumAsks += asks.optJSONArray(i).optDouble(1); } asksSeries.setIndexOffset(bidsSeries.getPointCount()); chartView.addArea().getSeries().add(asksSeries); chartView.getAreas().get(0).getSeries().add(bidsSeries); Axis.ILabelFormatProvider provider = new Axis.ILabelFormatProvider() { @Override public String getAxisLabel(Axis axis, double v) { int index = bidsSeries.convertToArrayIndex(v); if (index < 0) { index = 0; } if (index >= 0) { if (index >= bidsSeries.getPointCount()) { index = asksSeries.convertToArrayIndex(v); if (index < 0) { index = 0; } if (index >= 0) { if (index >= asksSeries.getPointCount()) { index = asksSeries.getPointCount() - 1; } } return asks.optJSONArray(index).optString(0); } return bids.optJSONArray(bidsSeries.getPointCount() - 1 - index).optString(0); } return null; } }; chartView.getAreas().get(0).getBottomAxis().setLabelFormatProvider(provider); //customizing fonts for chart chartView.getAreas().get(0).setTitle( "Market Depth for " + mPairsSpinner.getSelectedItem().toString() + " (Price vs. Volume)"); chartView.getAreas().get(0).getPlot().getAppearance().getFont().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 14, getResources().getDisplayMetrics())); chartView.getAreas().get(0).getLeftAxis().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics())); chartView.getAreas().get(0).getTopAxis().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics())); chartView.getAreas().get(0).getBottomAxis().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, getResources().getDisplayMetrics())); chartView.getAreas().get(0).getRightAxis().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics())); chartView.getAreas().get(0).getBottomAxis().getAppearance().getFont().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 9, getResources().getDisplayMetrics())); chartView.getAreas().get(0).getRightAxis().getAppearance().getFont().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 9, getResources().getDisplayMetrics())); mChartArea.addView(chartView); chartView.invalidate(); } }
From source file:com.eccyan.widget.SpinningTabStrip.java
public SpinningTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);/* w w w . j ava 2 s .c om*/ setWillNotDraw(false); tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(tabsContainer); flingVelocity = new Scroller(getContext()); flinger = new Flinger(); gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { flingVelocity.forceFinished(true); flingVelocity.fling(getScrollX(), getScrollY(), -(int) velocityX, -(int) velocityY, Integer.MIN_VALUE, Integer.MAX_VALUE, 0, getHeight()); scrollStopped.set(false); Log.d(TAG, "scroll fling started"); return true; } @Override public boolean onDown(MotionEvent e) { if (!flingVelocity.isFinished()) { flingVelocity.forceFinished(true); } if (!flinger.isFinished()) { flinger.forceFinished(true); } return super.onDown(e); } }); DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); tabTextSize = a.getDimensionPixelSize(TEXT_SIZE_INDEX, tabTextSize); ColorStateList colorStateList = a.getColorStateList(TEXT_COLOR_INDEX); int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, android.R.color.white); if (colorStateList != null) { tabTextColor = colorStateList; } else { tabTextColor = getColorStateList(textPrimaryColor); } underlineColor = textPrimaryColor; dividerColor = textPrimaryColor; indicatorColor = textPrimaryColor; // get custom attrs a = context.obtainStyledAttributes(attrs, R.styleable.SpinningTabStrip); indicatorColor = a.getColor(R.styleable.SpinningTabStrip_pstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.SpinningTabStrip_pstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.SpinningTabStrip_pstsDividerColor, dividerColor); dividerWidth = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsDividerWidth, dividerWidth); indicatorHeight = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsDividerPadding, dividerPadding); tabPadding = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.getResourceId(R.styleable.SpinningTabStrip_pstsTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.SpinningTabStrip_pstsShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.SpinningTabStrip_pstsTextAllCaps, textAllCaps); tabTypefaceStyle = a.getInt(R.styleable.SpinningTabStrip_pstsTextStyle, Typeface.BOLD); tabTypefaceSelectedStyle = a.getInt(R.styleable.SpinningTabStrip_pstsTextSelectedStyle, Typeface.BOLD); tabTextAlpha = a.getFloat(R.styleable.SpinningTabStrip_pstsTextAlpha, HALF_TRANSP); tabTextSelectedAlpha = a.getFloat(R.styleable.SpinningTabStrip_pstsTextSelectedAlpha, OPAQUE); a.recycle(); setMarginBottomTabContainer(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } }
From source file:com.daitu_liang.study.mytest.svg.AnimatedSvgView.java
private void rebuildGlyphData() { SvgPathParser parser = new SvgPathParser() { @Override//from ww w. jav a 2s . c o m protected float transformX(float x) { return x * mWidth / mViewport.x; } @Override protected float transformY(float y) { return y * mHeight / mViewport.y; } }; Log.i(TAG, "---mWidth = " + mWidth + "---mViewport.x = " + mViewport.x); if (mGlyphStrings != null) { mGlyphData = new GlyphData[mGlyphStrings.length]; } for (int i = 0; i < mGlyphStrings.length; i++) { mGlyphData[i] = new GlyphData(); try { mGlyphData[i].path = parser.parsePath(mGlyphStrings[i]); } catch (ParseException e) { mGlyphData[i].path = new Path(); Log.e(TAG, "Couldn't parse path", e); } PathMeasure pm = new PathMeasure(mGlyphData[i].path, true); while (true) { mGlyphData[i].length = Math.max(mGlyphData[i].length, pm.getLength()); if (!pm.nextContour()) { break; } } mGlyphData[i].paint = new Paint(); mGlyphData[i].paint.setStyle(Paint.Style.STROKE); mGlyphData[i].paint.setAntiAlias(true); mGlyphData[i].paint.setColor(Color.WHITE); mGlyphData[i].paint.setStrokeWidth( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics())); } }
From source file:ca.uwaterloo.sh6choi.czshopper.ui.FloatLabelLayout.java
/** * Helper method to convert dips to pixels. *//*ww w . ja v a 2s.c o m*/ private int dipsToPix(float dps) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dps, getResources().getDisplayMetrics()); }
From source file:cc.kenai.common.AnimatedSvgView.java
private void rebuildGlyphData() { SvgPathParser parser = new SvgPathParser() { @Override//from w w w . jav a2 s. c om protected float transformX(float x) { return x * mWidth / mViewport.x; } @Override protected float transformY(float y) { return y * mHeight / mViewport.y; } }; Log.i(TAG, "---mWidth = " + mWidth + "---mViewport.x = " + mViewport.x); Log.i(TAG, "mGlyphStrings.length = " + mGlyphStrings.length); mGlyphData = new GlyphData[mGlyphStrings.length]; for (int i = 0; i < mGlyphStrings.length; i++) { mGlyphData[i] = new GlyphData(); try { mGlyphData[i].path = parser.parsePath(mGlyphStrings[i]); } catch (ParseException e) { mGlyphData[i].path = new Path(); Log.e(TAG, "Couldn't parse path", e); } PathMeasure pm = new PathMeasure(mGlyphData[i].path, true); while (true) { mGlyphData[i].length = Math.max(mGlyphData[i].length, pm.getLength()); if (!pm.nextContour()) { break; } } mGlyphData[i].paint = new Paint(); mGlyphData[i].paint.setStyle(Paint.Style.STROKE); mGlyphData[i].paint.setAntiAlias(true); mGlyphData[i].paint.setColor(Color.WHITE); mGlyphData[i].paint.setStrokeWidth( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics())); } }
From source file:com.androguide.apkreator.MainActivity.java
@SuppressLint("NewApi") @SuppressWarnings("deprecation") @Override//from w w w. ja v a 2 s . c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_main); /** * Before anything we need to check if the config files exist to avoid * FC is they don't * * @see #checkIfConfigExists() */ checkIfConfigExists(); /** * Now it's all good because if no configuration was found we have * copied a default one over. * * @see #checkIfConfigExists() */ setAppConfigInPrefs(); headers = getPluginTabs(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); /* * set a custom shadow that overlays the main content when the drawer * opens */ mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); /* set up the drawer's list view with items and click listener */ ArrayAdapter<String> pimpAdapter = new ArrayAdapter<String>(this, R.layout.drawer_list_item, mDrawerHeaders); mDrawerList.setAdapter(pimpAdapter); Log.e("FIRST POS", mDrawerList.getFirstVisiblePosition() + ""); Log.e("LAST POS", mDrawerList.getLastVisiblePosition() + ""); View child = mDrawerList.getChildAt(mDrawerList.getFirstVisiblePosition()); if (child != null && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) child.setBackground(getColouredTouchFeedback()); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); /** Set the user-defined ActionBar icon */ File file = new File(getFilesDir() + "/.APKreator/icon.png"); if (file.exists()) { try { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); Uri iconUri = Uri.fromFile(new File(getFilesDir() + "/.APKreator/icon.png")); Bitmap icon = BitmapFactory.decodeFile(iconUri.getPath()); Drawable ic = new BitmapDrawable(icon); getSupportActionBar().setIcon(ic); } catch (NullPointerException e) { Log.e("NPE", e.getMessage()); } } /* * ActionBarDrawerToggle ties together the proper interactions between * the sliding drawer and the action bar app icon */ mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.app_name, /* "open drawer" description for accessibility */ R.string.app_name /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { invalidateOptionsMenu(); /* * creates call to * onPrepareOptionsMenu() */ } public void onDrawerOpened(View drawerView) { invalidateOptionsMenu(); /* * creates call to * onPrepareOptionsMenu() */ } }; mDrawerLayout.setDrawerListener(mDrawerToggle); /** Tabs adapter using the PagerSlidingStrip library */ tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs); ViewPager pager = (ViewPager) findViewById(R.id.pager); MyPagerAdapter adapter = new MyPagerAdapter(this.getSupportFragmentManager()); pager.setAdapter(adapter); pager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int arg0) { } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics()); pager.setPageMargin(pageMargin); tabs.setViewPager(pager); tabs.setOnPageChangeListener(this); changeColor(Color.parseColor(getPluginColor())); pager.setOffscreenPageLimit(5); }