List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:com.android.calendar.AllInOneActivity.java
@Override protected void onCreate(Bundle icicle) { if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) { setTheme(R.style.CalendarTheme_WithActionBarWallpaper); }/* w w w .j a v a 2 s. co m*/ super.onCreate(icicle); dynamicTheme.onCreate(this); if (icicle != null && icicle.containsKey(BUNDLE_KEY_CHECK_ACCOUNTS)) { mCheckForAccounts = icicle.getBoolean(BUNDLE_KEY_CHECK_ACCOUNTS); } // Launch add google account if this is first time and there are no // accounts yet if (mCheckForAccounts && !Utils.getSharedPreference(this, GeneralPreferences.KEY_SKIP_SETUP, false)) { mHandler = new QueryHandler(this.getContentResolver()); mHandler.startQuery(0, null, Calendars.CONTENT_URI, new String[] { Calendars._ID }, null, null /* selection args */, null /* sort order */); } // This needs to be created before setContentView mController = CalendarController.getInstance(this); // Check and ask for most needed permissions checkAppPermissions(); // Get time from intent or icicle long timeMillis = -1; int viewType = -1; final Intent intent = getIntent(); if (icicle != null) { timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME); viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1); } else { String action = intent.getAction(); if (Intent.ACTION_VIEW.equals(action)) { // Open EventInfo later timeMillis = parseViewAction(intent); } if (timeMillis == -1) { timeMillis = Utils.timeFromIntentInMillis(intent); } } if (viewType == -1 || viewType > ViewType.MAX_VALUE) { viewType = Utils.getViewTypeFromIntentAndSharedPref(this); } mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater); Time t = new Time(mTimeZone); t.set(timeMillis); if (DEBUG) { if (icicle != null && intent != null) { Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString()); } else { Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent); } } Resources res = getResources(); mHideString = res.getString(R.string.hide_controls); mShowString = res.getString(R.string.show_controls); mOrientation = res.getConfiguration().orientation; if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) { mControlsAnimateWidth = (int) res.getDimension(R.dimen.calendar_controls_width); if (mControlsParams == null) { mControlsParams = new LayoutParams(mControlsAnimateWidth, 0); } mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } else { // Make sure width is in between allowed min and max width values mControlsAnimateWidth = Math.max(res.getDisplayMetrics().widthPixels * 45 / 100, (int) res.getDimension(R.dimen.min_portrait_calendar_controls_width)); mControlsAnimateWidth = Math.min(mControlsAnimateWidth, (int) res.getDimension(R.dimen.max_portrait_calendar_controls_width)); } mControlsAnimateHeight = (int) res.getDimension(R.dimen.calendar_controls_height); mHideControls = !Utils.getSharedPreference(this, GeneralPreferences.KEY_SHOW_CONTROLS, true); mIsMultipane = Utils.getConfigBool(this, R.bool.multiple_pane_config); mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config); mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month); mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls); mShowEventDetailsWithAgenda = Utils.getConfigBool(this, R.bool.show_event_details_with_agenda); mShowEventInfoFullScreenAgenda = Utils.getConfigBool(this, R.bool.agenda_show_event_info_full_screen); mShowEventInfoFullScreen = Utils.getConfigBool(this, R.bool.show_event_info_full_screen); mCalendarControlsAnimationTime = res.getInteger(R.integer.calendar_controls_animation_time); Utils.setAllowWeekForDetailView(mIsMultipane); // setContentView must be called before configureActionBar setContentView(R.layout.all_in_one_material); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mNavigationView = (NavigationView) findViewById(R.id.navigation_view); mFab = (FloatingActionButton) findViewById(R.id.floating_action_button); if (mIsTabletConfig) { mDateRange = (TextView) findViewById(R.id.date_bar); mWeekTextView = (TextView) findViewById(R.id.week_num); } else { mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null); } setupToolbar(viewType); setupNavDrawer(); setupFloatingActionButton(); mHomeTime = (TextView) findViewById(R.id.home_time); mMiniMonth = findViewById(R.id.mini_month); if (mIsTabletConfig && mOrientation == Configuration.ORIENTATION_PORTRAIT) { mMiniMonth.setLayoutParams( new RelativeLayout.LayoutParams(mControlsAnimateWidth, mControlsAnimateHeight)); } mCalendarsList = findViewById(R.id.calendar_list); mMiniMonthContainer = findViewById(R.id.mini_month_container); mSecondaryPane = findViewById(R.id.secondary_pane); // Must register as the first activity because this activity can modify // the list of event handlers in it's handle method. This affects who // the rest of the handlers the controller dispatches to are. mController.registerFirstEventHandler(HANDLER_KEY, this); initFragments(timeMillis, viewType, icicle); // Listen for changes that would require this to be refreshed SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); mContentResolver = getContentResolver(); }
From source file:org.de.jmg.learn._MainActivity.java
private void resize() { RelativeLayout.LayoutParams params;//from w w w .jav a 2s . c o m Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); int height = metrics.heightPixels; width = metrics.widthPixels; int viewTop = _main.findViewById(Window.ID_ANDROID_CONTENT).getTop(); height = height - viewTop; scale = (double) height / (double) 950; double ratio = Math.pow((double) width / (double) height, .5d); boolean blnHorizontal = width > height; if (scale < .5f) { _isSmallDevice = true; _main.isSmallDevice = true; if (scale < .4f) { scale = .4f; } } /* * lib.ShowMessage(this, "Meaning3 Bottom: " +_txtMeaning3.getBottom() + * "\nbtnRight.Top: " + _btnRight.getTop() + "\nDisplayHeight: " + * height); */ if (scale != 1) { // lib.ShowToast(_main, "Scaling font by " + scale + " Screenheight = " //+ height); float tSize = _txtMeaning1.getTextSize(); if (tSize == 40 || (_vok.getCardMode() && tSize == 25)) { _txtMeaning1.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtMeaning1.getTextSize() * scale)); } params = (android.widget.RelativeLayout.LayoutParams) _txtMeaning1.getLayoutParams(); if (params.topMargin == 120) { if (!_isSmallDevice) { params.topMargin = (int) (params.topMargin * scale); } else { params.topMargin = (int) (params.topMargin * .1f); } _txtMeaning1.setLayoutParams(params); } if (_txtMeaning2.getTextSize() == 40) { _txtMeaning2.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtMeaning2.getTextSize() * scale)); } params = (android.widget.RelativeLayout.LayoutParams) _txtMeaning2.getLayoutParams(); if (params.topMargin == 56) { params.topMargin = (int) (params.topMargin * scale); _txtMeaning2.setLayoutParams(params); } if (_txtMeaning3.getTextSize() == 40) { _txtMeaning3.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtMeaning3.getTextSize() * scale)); } params = (android.widget.RelativeLayout.LayoutParams) _txtMeaning3.getLayoutParams(); if (params.topMargin == 56) { params.topMargin = (int) (params.topMargin * scale); _txtMeaning3.setLayoutParams(params); } float size = _txtWord.getTextSize(); if (size == 60) { size *= scale; _txtWord.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); } if (_txtKom.getTextSize() == 35) { _txtKom.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtKom.getTextSize() * scale)); } if (_txtedWord.getTextSize() == 60) { _txtedWord.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtedWord.getTextSize() * scale)); } if (_txtedKom.getTextSize() == 35) { _txtedKom.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtedKom.getTextSize() * scale)); } if (_vok != null && _vok.getCardMode()) { SetViewsToCardmode(); } else { SetViewsToVokMode(); } /* * _txtMeaning1.setOnFocusChangeListener(new * View.OnFocusChangeListener() { * * @Override public void onFocusChange(View v, boolean hasFocus) { * if (_firstFocus && hasFocus) { * hideKeyboard(); _firstFocus = false; } } }); */ } if (scale != 1) { int widthButtons = _btnEdit.getRight() - _btnSkip.getLeft(); int allButtonsWidth = 520; /*_btnEdit.getWidth() +_btnRight.getWidth() +_btnView.getWidth() +_btnWrong.getWidth() +_btnEdit.getWidth(); */ if (widthButtons < allButtonsWidth) { widthButtons = allButtonsWidth; blnWrongWidth = true; } ScaleWidth = (width - 50) / (double) widthButtons; if (ScaleWidth < .7) { _btnEdit.setVisibility(View.GONE); _btnSkip.setVisibility(View.GONE); widthButtons = _btnWrong.getRight() - _btnRight.getLeft(); if (widthButtons < 330) { widthButtons = 330; blnWrongWidth = true; } ScaleWidth = ((double) (_txtMeaning1.getRight() - _txtMeaning1.getLeft())) / (double) widthButtons; if (ScaleWidth < .4d) ScaleWidth = .4d; ScaleTextButtons = ((scale > ScaleWidth) ? scale : ScaleWidth); } else { ScaleTextButtons = ((scale < ScaleWidth) ? scale : ScaleWidth); } RelativeLayout layoutButtons = (RelativeLayout) findViewById(R.id.layoutButtonsInner); params = (android.widget.RelativeLayout.LayoutParams) layoutButtons.getLayoutParams(); if (!blnWrongWidth) { params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.bottomMargin = (int) (0 * ScaleWidth); } layoutButtons.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnRight.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); _btnRight.setPadding((int) (_btnRight.getPaddingLeft() * ScaleWidth), (int) (_btnRight.getPaddingTop() * ScaleWidth), (int) (_btnRight.getPaddingRight() * ScaleWidth), (int) (_btnRight.getPaddingBottom() * ScaleWidth)); } params.width = (int) (params.width * ScaleWidth); double ScaleTextButtonsOrig = ScaleTextButtons; if (blnHorizontal) { params.height *= ratio; ScaleTextButtons *= ratio; } _btnRight.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnWrong.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); _btnWrong.setPadding((int) (_btnWrong.getPaddingLeft() * ScaleWidth), (int) (_btnWrong.getPaddingTop() * ScaleWidth), (int) (_btnWrong.getPaddingRight() * ScaleWidth), (int) (_btnWrong.getPaddingBottom() * ScaleWidth)); } params.width = (int) (params.width * ScaleWidth); if (blnHorizontal) params.height *= ratio; _btnWrong.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnSkip.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); } params.width = (int) (params.width * ScaleWidth); if (blnHorizontal) params.height *= ratio; _btnSkip.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnView.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); _btnView.setPadding((int) (_btnView.getPaddingLeft() * ScaleWidth), (int) (_btnView.getPaddingTop() * ScaleWidth), (int) (_btnView.getPaddingRight() * ScaleWidth), (int) (_btnView.getPaddingBottom() * ScaleWidth)); } params.width = (int) (params.width * ScaleWidth); if (blnHorizontal) params.height *= ratio; _btnView.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _btnEdit.getLayoutParams(); if (!blnWrongWidth) { params.height = (int) (params.height * scale); params.bottomMargin = (int) (params.bottomMargin * scale); } else { params.height = (int) (60 * ScaleWidth); params.bottomMargin = (int) (0 * ScaleWidth); } params.width = (int) (params.width * ScaleWidth); if (blnHorizontal) params.height *= ratio; _btnEdit.setLayoutParams(params); params = (android.widget.RelativeLayout.LayoutParams) _txtStatus.getLayoutParams(); if (!blnWrongWidth) { params.topMargin = (int) (params.topMargin * scale); } else { params.topMargin = (int) (0 * ScaleWidth); } _txtStatus.setLayoutParams(params); _btnRight.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnRight.getTextSize() * ScaleTextButtons)); _btnSkip.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnSkip.getTextSize() * ScaleTextButtons)); _btnView.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnView.getTextSize() * ScaleTextButtons)); _btnWrong.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnWrong.getTextSize() * ScaleTextButtons)); _btnEdit.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_btnEdit.getTextSize() * ScaleTextButtons)); _txtStatus.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) (_txtStatus.getTextSize() * ScaleTextButtonsOrig)); //_main.ActionBarOriginalTextSize = 0; resizeActionbar(0); Runnable r = new resetLayoutTask(null); rFlashs.add(r); handler.post(r); } }
From source file:com.lite.android.launcher3.allapps.AllAppsGridAdapter.java
public AllAppsGridAdapter(Launcher launcher, AlphabeticalAppsList apps, View.OnTouchListener touchListener, View.OnClickListener iconClickListener, View.OnLongClickListener iconLongClickListener) { Resources res = launcher.getResources(); mLauncher = launcher;/*ww w . java2s . c o m*/ mApps = apps; mEmptySearchMessage = res.getString(R.string.all_apps_loading_message); mGridSizer = new GridSpanSizer(); mGridLayoutMgr = new AppsGridLayoutManager(launcher); mGridLayoutMgr.setSpanSizeLookup(mGridSizer); mItemDecoration = new GridItemDecoration(); mLayoutInflater = LayoutInflater.from(launcher); mTouchListener = touchListener; mIconClickListener = iconClickListener; mIconLongClickListener = iconLongClickListener; mSectionNamesMargin = mSectionStrategy == AllAppsContainerView.SECTION_STRATEGY_GRID ? res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin) : res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin_with_sections); mAllAppsTextColor = mGridTheme == AllAppsContainerView.GRID_THEME_DARK ? res.getColor(R.color.quantum_panel_text_color_dark) : res.getColor(R.color.quantum_panel_text_color); mSectionHeaderOffset = res.getDimensionPixelSize(R.dimen.all_apps_grid_section_y_offset); mSectionTextPaint = new Paint(); mSectionTextPaint.setTextSize(res.getDimensionPixelSize(R.dimen.all_apps_grid_section_text_size)); int sectionTextColorId = mGridTheme == AllAppsContainerView.GRID_THEME_DARK ? R.color.all_apps_grid_section_text_color_dark : R.color.all_apps_grid_section_text_color; mSectionTextPaint.setColor(res.getColor(sectionTextColorId)); mSectionTextPaint.setAntiAlias(true); mPredictedAppsDividerPaint = new Paint(); mPredictedAppsDividerPaint.setStrokeWidth(Utilities.pxFromDp(1f, res.getDisplayMetrics())); mPredictedAppsDividerPaint.setColor(0x1E000000); mPredictedAppsDividerPaint.setAntiAlias(true); mPredictionBarDividerOffset = res.getDimensionPixelSize(R.dimen.all_apps_prediction_bar_divider_offset); // Resolve the market app handling additional searches PackageManager pm = launcher.getPackageManager(); ResolveInfo marketInfo = pm.resolveActivity(createMarketSearchIntent(""), PackageManager.MATCH_DEFAULT_ONLY); if (marketInfo != null) { mMarketAppName = marketInfo.loadLabel(pm).toString(); } mRemoteFolderManager = launcher.getRemoteFolderManager(); }
From source file:org.akop.ararat.view.CrosswordView.java
public CrosswordView(Context context, AttributeSet attrs) { super(context, attrs); if (!isInEditMode()) { setLayerType(View.LAYER_TYPE_HARDWARE, null); }//from w w w. java 2 s. c om // Set drawing defaults Resources r = context.getResources(); DisplayMetrics dm = r.getDisplayMetrics(); int cellFillColor = NORMAL_CELL_FILL_COLOR; int cheatedCellFillColor = CHEATED_CELL_FILL_COLOR; int mistakeCellFillColor = MISTAKE_CELL_FILL_COLOR; int selectedWordFillColor = SELECTED_WORD_FILL_COLOR; int selectedCellFillColor = SELECTED_CELL_FILL_COLOR; int markedCellFillColor = MARKED_CELL_FILL_COLOR; int numberTextColor = NUMBER_TEXT_COLOR; int cellStrokeColor = CELL_STROKE_COLOR; int circleStrokeColor = CIRCLE_STROKE_COLOR; int answerTextColor = ANSWER_TEXT_COLOR; mScaledDensity = dm.scaledDensity; float numberTextSize = NUMBER_TEXT_SIZE * mScaledDensity; mAnswerTextSize = ANSWER_TEXT_SIZE * mScaledDensity; mCellSize = CELL_SIZE * dm.density; mNumberTextPadding = NUMBER_TEXT_PADDING * dm.density; mIsEditable = true; mInputMode = INPUT_MODE_KEYBOARD; mSkipOccupiedOnType = false; mSelectFirstUnoccupiedOnNav = true; mMaxBitmapSize = DEFAULT_MAX_BITMAP_DIMENSION; // Read supplied attributes if (attrs != null) { Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.CrosswordView, 0, 0); mCellSize = a.getDimension(R.styleable.CrosswordView_cellSize, mCellSize); mNumberTextPadding = a.getDimension(R.styleable.CrosswordView_numberTextPadding, mNumberTextPadding); numberTextSize = a.getDimension(R.styleable.CrosswordView_numberTextSize, numberTextSize); mAnswerTextSize = a.getDimension(R.styleable.CrosswordView_answerTextSize, mAnswerTextSize); answerTextColor = a.getColor(R.styleable.CrosswordView_answerTextColor, answerTextColor); cellFillColor = a.getColor(R.styleable.CrosswordView_defaultCellFillColor, cellFillColor); cheatedCellFillColor = a.getColor(R.styleable.CrosswordView_cheatedCellFillColor, cheatedCellFillColor); mistakeCellFillColor = a.getColor(R.styleable.CrosswordView_mistakeCellFillColor, mistakeCellFillColor); selectedWordFillColor = a.getColor(R.styleable.CrosswordView_selectedWordFillColor, selectedWordFillColor); selectedCellFillColor = a.getColor(R.styleable.CrosswordView_selectedCellFillColor, selectedCellFillColor); markedCellFillColor = a.getColor(R.styleable.CrosswordView_markedCellFillColor, markedCellFillColor); cellStrokeColor = a.getColor(R.styleable.CrosswordView_cellStrokeColor, cellStrokeColor); circleStrokeColor = a.getColor(R.styleable.CrosswordView_circleStrokeColor, circleStrokeColor); numberTextColor = a.getColor(R.styleable.CrosswordView_numberTextColor, numberTextColor); mIsEditable = a.getBoolean(R.styleable.CrosswordView_editable, mIsEditable); mSkipOccupiedOnType = a.getBoolean(R.styleable.CrosswordView_skipOccupiedOnType, mSkipOccupiedOnType); mSelectFirstUnoccupiedOnNav = a.getBoolean(R.styleable.CrosswordView_selectFirstUnoccupiedOnNav, mSelectFirstUnoccupiedOnNav); a.recycle(); } mRevealSetsCheatFlag = true; mMarkerSideLength = mCellSize * MARKER_TRIANGLE_LENGTH_FRACTION; // Init paints mCellFillPaint = new Paint(); mCellFillPaint.setColor(cellFillColor); mCellFillPaint.setStyle(Paint.Style.FILL); mCheatedCellFillPaint = new Paint(); mCheatedCellFillPaint.setColor(cheatedCellFillColor); mCheatedCellFillPaint.setStyle(Paint.Style.FILL); mMistakeCellFillPaint = new Paint(); mMistakeCellFillPaint.setColor(mistakeCellFillColor); mMistakeCellFillPaint.setStyle(Paint.Style.FILL); mSelectedWordFillPaint = new Paint(); mSelectedWordFillPaint.setColor(selectedWordFillColor); mSelectedWordFillPaint.setStyle(Paint.Style.FILL); mSelectedCellFillPaint = new Paint(); mSelectedCellFillPaint.setColor(selectedCellFillColor); mSelectedCellFillPaint.setStyle(Paint.Style.FILL); mMarkedCellFillPaint = new Paint(); mMarkedCellFillPaint.setColor(markedCellFillColor); mMarkedCellFillPaint.setStyle(Paint.Style.FILL); mCellStrokePaint = new Paint(); mCellStrokePaint.setColor(cellStrokeColor); mCellStrokePaint.setStyle(Paint.Style.STROKE); // mCellStrokePaint.setStrokeWidth(1); mCircleStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mCircleStrokePaint.setColor(circleStrokeColor); mCircleStrokePaint.setStyle(Paint.Style.STROKE); mCircleStrokePaint.setStrokeWidth(1); mNumberTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mNumberTextPaint.setColor(numberTextColor); mNumberTextPaint.setTextAlign(Paint.Align.CENTER); mNumberTextPaint.setTextSize(numberTextSize); // Compute number height mNumberTextPaint.getTextBounds("0", 0, "0".length(), mTempRect); mNumberTextHeight = mTempRect.height(); mNumberStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mNumberStrokePaint.setColor(cellFillColor); mNumberStrokePaint.setTextAlign(Paint.Align.CENTER); mNumberStrokePaint.setTextSize(numberTextSize); mNumberStrokePaint.setStyle(Paint.Style.STROKE); mNumberStrokePaint.setStrokeWidth(NUMBER_TEXT_STROKE_WIDTH * mScaledDensity); mAnswerTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mAnswerTextPaint.setColor(answerTextColor); mAnswerTextPaint.setTextSize(mAnswerTextSize); // Init rest of the values mCircleRadius = (mCellSize / 2) - mCircleStrokePaint.getStrokeWidth(); mPuzzleCells = EMPTY_CELLS; mPuzzleWidth = 0; mPuzzleHeight = 0; mAllowedChars = EMPTY_CHARS; mRenderScale = 0; mBitmapOffset = new PointF(); mCenteredOffset = new PointF(); mTranslationBounds = new RectF(); mScaleDetector = new ScaleGestureDetector(context, new ScaleListener()); mGestureDetector = new GestureDetector(context, new GestureListener()); mContentRect = new RectF(); mPuzzleRect = new RectF(); mBitmapPaint = new Paint(Paint.FILTER_BITMAP_FLAG); mScroller = new Scroller(context, null, true); mZoomer = new Zoomer(context); mUndoBuffer = new Stack<>(); setFocusableInTouchMode(mIsEditable && mInputMode != INPUT_MODE_NONE); setOnKeyListener(this); }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java
private void reloadSwipeThresholdsSettings(final Resources res) { final float density = res.getDisplayMetrics().density; mSwipeVelocityThreshold = (int) (AnyApplication.getConfig().getSwipeVelocityThreshold() * density); mSwipeXDistanceThreshold = (int) (AnyApplication.getConfig().getSwipeDistanceThreshold() * density); Keyboard kbd = getKeyboard();/*from w w w .j a v a2 s. co m*/ if (kbd != null) { mSwipeYDistanceThreshold = (int) (mSwipeXDistanceThreshold * (((float) kbd.getHeight()) / ((float) getWidth()))); } else { mSwipeYDistanceThreshold = 0; } if (mSwipeYDistanceThreshold == 0) mSwipeYDistanceThreshold = mSwipeXDistanceThreshold; mSwipeSpaceXDistanceThreshold = mSwipeXDistanceThreshold / 2; mSwipeYDistanceThreshold = mSwipeYDistanceThreshold / 2; mScrollXDistanceThreshold = mSwipeXDistanceThreshold / 8; mScrollYDistanceThreshold = mSwipeYDistanceThreshold / 8; }
From source file:com.andrew.apolloMod.service.ApolloService.java
private synchronized void updateAlbumBitmap() { if (mAlbumBitmapTask != null) { mAlbumBitmapTask.cancel(true);/* w w w . j a v a2 s .co m*/ mAlbumBitmapTask = null; } if (mCursor == null) { return; } ImageInfo mInfo = new ImageInfo(); mInfo.type = TYPE_ALBUM; mInfo.size = SIZE_THUMB; mInfo.source = SRC_FIRST_AVAILABLE; mInfo.data = new String[] { String.valueOf(getAlbumId()), getArtistName(), getAlbumName() }; String tag = ImageUtils.createShortTag(mInfo) + SIZE_THUMB; if (tag == mAlbumBitmapTag) return; mAlbumBitmapTag = tag; mAlbumBitmap = null; Resources resources = getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); int thumbSize = (int) ((153 * (metrics.densityDpi / 160f)) + 0.5f); mAlbumBitmapTask = new GetBitmapTask(thumbSize, mInfo, this, this); mAlbumBitmapTask.execute(); }
From source file:com.ifoer.expeditionphone.MainActivity.java
public void switchLanguage(Locale locale) { Resources resources = getBaseContext().getResources(); Configuration config = resources.getConfiguration(); DisplayMetrics dm = resources.getDisplayMetrics(); config.locale = locale;//from w w w .jav a 2s. c o m resources.updateConfiguration(config, dm); }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java
public AnyKeyboardBaseView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); //creating the KeyDrawableStateProvider, as it suppose to be backward compatible int keyTypeFunctionAttrId = R.attr.key_type_function; int keyActionAttrId = R.attr.key_type_action; int keyActionTypeDoneAttrId = R.attr.action_done; int keyActionTypeSearchAttrId = R.attr.action_search; int keyActionTypeGoAttrId = R.attr.action_go; LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // int previewLayout = 0; mPreviewKeyTextSize = -1;/*w ww . j a v a 2 s .c o m*/ mPreviewLabelTextSize = -1; mPreviewKeyBackground = null; mPreviewKeyTextColor = 0xFFF; final int[] padding = new int[] { 0, 0, 0, 0 }; KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(context.getApplicationContext()); final int keyboardThemeStyleResId = getKeyboardStyleResId(theme); Log.d(TAG, "Will use keyboard theme " + theme.getName() + " id " + theme.getId() + " res " + keyboardThemeStyleResId); //creating a mapping from the remote Attribute IDs to my local attribute ID. //this is required in order to backward support any build-system (which may cause the attribute IDs to change) final SparseIntArray attributeIdMap = new SparseIntArray(R.styleable.AnyKeyboardViewTheme.length + R.styleable.AnyKeyboardViewIconsTheme.length + ACTION_KEY_TYPES.length + KEY_TYPES.length); final int[] remoteKeyboardThemeStyleable = KeyboardSupport.createBackwardCompatibleStyleable( R.styleable.AnyKeyboardViewTheme, context, theme.getPackageContext(), attributeIdMap); final int[] remoteKeyboardIconsThemeStyleable = KeyboardSupport.createBackwardCompatibleStyleable( R.styleable.AnyKeyboardViewIconsTheme, context, theme.getPackageContext(), attributeIdMap); HashSet<Integer> doneLocalAttributeIds = new HashSet<Integer>(); TypedArray a = theme.getPackageContext().obtainStyledAttributes(keyboardThemeStyleResId, remoteKeyboardThemeStyleable); final int n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardThemeStyleable[remoteIndex]); if (setValueFromTheme(a, padding, localAttrId, remoteIndex)) { doneLocalAttributeIds.add(localAttrId); if (localAttrId == R.attr.keyBackground) { //keyTypeFunctionAttrId and keyActionAttrId are remote final int[] keyStateAttributes = KeyboardSupport.createBackwardCompatibleStyleable(KEY_TYPES, context, theme.getPackageContext(), attributeIdMap); keyTypeFunctionAttrId = keyStateAttributes[0]; keyActionAttrId = keyStateAttributes[1]; } } } a.recycle(); // taking icons int iconSetStyleRes = theme.getIconsThemeResId(); Log.d(TAG, "Will use keyboard icons theme " + theme.getName() + " id " + theme.getId() + " res " + iconSetStyleRes); if (iconSetStyleRes != 0) { a = theme.getPackageContext().obtainStyledAttributes(iconSetStyleRes, remoteKeyboardIconsThemeStyleable); final int iconsCount = a.getIndexCount(); for (int i = 0; i < iconsCount; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardIconsThemeStyleable[remoteIndex]); if (setKeyIconValueFromTheme(theme, a, localAttrId, remoteIndex)) { doneLocalAttributeIds.add(localAttrId); if (localAttrId == R.attr.iconKeyAction) { //keyActionTypeDoneAttrId and keyActionTypeSearchAttrId and keyActionTypeGoAttrId are remote final int[] keyStateAttributes = KeyboardSupport.createBackwardCompatibleStyleable( ACTION_KEY_TYPES, context, theme.getPackageContext(), attributeIdMap); keyActionTypeDoneAttrId = keyStateAttributes[0]; keyActionTypeSearchAttrId = keyStateAttributes[1]; keyActionTypeGoAttrId = keyStateAttributes[2]; } } } a.recycle(); } // filling what's missing KeyboardTheme fallbackTheme = KeyboardThemeFactory.getFallbackTheme(context.getApplicationContext()); final int keyboardFallbackThemeStyleResId = getKeyboardStyleResId(fallbackTheme); Log.d(TAG, "Will use keyboard fallback theme " + fallbackTheme.getName() + " id " + fallbackTheme.getId() + " res " + keyboardFallbackThemeStyleResId); a = fallbackTheme.getPackageContext().obtainStyledAttributes(keyboardFallbackThemeStyleResId, R.styleable.AnyKeyboardViewTheme); final int fallbackCount = a.getIndexCount(); for (int i = 0; i < fallbackCount; i++) { final int index = a.getIndex(i); final int attrId = R.styleable.AnyKeyboardViewTheme[index]; if (doneLocalAttributeIds.contains(attrId)) continue; Log.d(TAG, "Falling back theme res ID " + index); setValueFromTheme(a, padding, attrId, index); } a.recycle(); // taking missing icons int fallbackIconSetStyleId = fallbackTheme.getIconsThemeResId(); Log.d(TAG, "Will use keyboard fallback icons theme " + fallbackTheme.getName() + " id " + fallbackTheme.getId() + " res " + fallbackIconSetStyleId); a = fallbackTheme.getPackageContext().obtainStyledAttributes(fallbackIconSetStyleId, R.styleable.AnyKeyboardViewIconsTheme); final int fallbackIconsCount = a.getIndexCount(); for (int i = 0; i < fallbackIconsCount; i++) { final int index = a.getIndex(i); final int attrId = R.styleable.AnyKeyboardViewIconsTheme[index]; if (doneLocalAttributeIds.contains(attrId)) continue; Log.d(TAG, "Falling back icon res ID " + index); setKeyIconValueFromTheme(fallbackTheme, a, attrId, index); } a.recycle(); //creating the key-drawable state provider, as we suppose to have the entire data now mDrawableStatesProvider = new KeyDrawableStateProvider(keyTypeFunctionAttrId, keyActionAttrId, keyActionTypeDoneAttrId, keyActionTypeSearchAttrId, keyActionTypeGoAttrId); // settings. // don't forget that there are TWO paddings, the theme's and the // background image's padding! Drawable keyboardBabground = super.getBackground(); if (keyboardBabground != null) { Rect backgroundPadding = new Rect(); keyboardBabground.getPadding(backgroundPadding); padding[0] += backgroundPadding.left; padding[1] += backgroundPadding.top; padding[2] += backgroundPadding.right; padding[3] += backgroundPadding.bottom; } super.setPadding(padding[0], padding[1], padding[2], padding[3]); final Resources res = getResources(); mKeyboardDimens.setKeyboardMaxWidth(res.getDisplayMetrics().widthPixels - padding[0] - padding[2]); mPreviewPopup = new PopupWindow(context); if (mPreviewKeyTextSize > 0) { if (mPreviewLabelTextSize <= 0) mPreviewLabelTextSize = mPreviewKeyTextSize; mPreviewLayut = inflatePreviewWindowLayout(inflate); mPreviewText = (TextView) mPreviewLayut.findViewById(R.id.key_preview_text); mPreviewText.setTextColor(mPreviewKeyTextColor); mPreviewText.setTypeface(mKeyTextStyle); mPreviewIcon = (ImageView) mPreviewLayut.findViewById(R.id.key_preview_icon); mPreviewPopup.setBackgroundDrawable(mPreviewKeyBackground); mPreviewPopup.setContentView(mPreviewLayut); mShowPreview = mPreviewLayut != null; } else { mPreviewLayut = null; mPreviewText = null; mShowPreview = false; } mPreviewPopup.setTouchable(false); mPreviewPopup .setAnimationStyle((mAnimationLevel == AnimationsLevel.None) ? 0 : R.style.KeyPreviewAnimation); mDelayBeforePreview = 0; mDelayAfterPreview = 10; mMiniKeyboardParent = this; mMiniKeyboardPopup = new PopupWindow(context.getApplicationContext()); mMiniKeyboardPopup.setBackgroundDrawable(null); mMiniKeyboardPopup .setAnimationStyle((mAnimationLevel == AnimationsLevel.None) ? 0 : R.style.MiniKeyboardAnimation); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setTextSize(mKeyTextSize); mPaint.setTextAlign(Align.CENTER); mPaint.setAlpha(255); mKeyBackgroundPadding = new Rect(0, 0, 0, 0); mKeyBackground.getPadding(mKeyBackgroundPadding); reloadSwipeThresholdsSettings(res); mMiniKeyboardSlideAllowance = res.getDimension(R.dimen.mini_keyboard_slide_allowance); AskOnGestureListener listener = new AskGestureEventsListener(this); mGestureDetector = AnyApplication.getDeviceSpecific().createGestureDetector(getContext(), listener); mGestureDetector.setIsLongpressEnabled(false); MultiTouchSupportLevel multiTouchSupportLevel = AnyApplication.getDeviceSpecific() .getMultiTouchSupportLevel(getContext()); mHasDistinctMultitouch = multiTouchSupportLevel == MultiTouchSupportLevel.Distinct; mKeyRepeatInterval = 50; AnyApplication.getConfig().addChangedListener(this); }
From source file:com.dwdesign.tweetings.util.Utils.java
private static Bitmap getTabIconFromFile(final File file, final Resources res) { if (file == null || !file.exists()) return null; final String path = file.getPath(); final BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true;//from w w w . j a va 2s. co m BitmapFactory.decodeFile(path, o); if (o.outHeight <= 0 || o.outWidth <= 0) return null; final BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = (int) (Math.max(o.outWidth, o.outHeight) / (48 * res.getDisplayMetrics().density)); return BitmapFactory.decodeFile(path, o2); }
From source file:android.support.designox.widget.CoordinatorLayout.java
public CoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); ThemeUtils.checkAppCompatTheme(context); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CoordinatorLayout, defStyleAttr, R.style.Widget_Design_CoordinatorLayout); final int keylineArrayRes = a.getResourceId(R.styleable.CoordinatorLayout_keylines, 0); if (keylineArrayRes != 0) { final Resources res = context.getResources(); mKeylines = res.getIntArray(keylineArrayRes); final float density = res.getDisplayMetrics().density; final int count = mKeylines.length; for (int i = 0; i < count; i++) { mKeylines[i] *= density;/*from ww w.ja v a 2s. c o m*/ } } mStatusBarBackground = a.getDrawable(R.styleable.CoordinatorLayout_statusBarBackground); a.recycle(); if (INSETS_HELPER != null) { INSETS_HELPER.setupForWindowInsets(this, new ApplyInsetsListener()); } super.setOnHierarchyChangeListener(new HierarchyChangeListener()); }