List of usage examples for android.util TypedValue COMPLEX_UNIT_DIP
int COMPLEX_UNIT_DIP
To view the source code for android.util TypedValue COMPLEX_UNIT_DIP.
Click Source Link
From source file:com.astuetz.PagerSlidingTabStripPlus.java
public PagerSlidingTabStripPlus(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true); // ScrollView stretch his content height to fill his viewport setWillNotDraw(false);/* w w w . j a v a 2 s . com*/ // Layout parameters tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); // Converting values to floating point value 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); tabPaddingLeft = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPaddingLeft, dm); tabPaddingRight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPaddingRight, dm); tabPaddingTop = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPaddingTop, dm); tabPaddingBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPaddingBottom, 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(0, tabTextSize); tabTextColor = a.getColor(1, tabTextColor); a.recycle(); // get custom attrs a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStripPlus); indicatorColor = a.getColor(R.styleable.PagerSlidingTabStripPlus_pstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.PagerSlidingTabStripPlus_pstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.PagerSlidingTabStripPlus_pstsDividerColor, dividerColor); indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStripPlus_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStripPlus_pstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStripPlus_pstsDividerPadding, dividerPadding); tabPaddingLeft = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStripPlus_pstsTabPaddingLeft, tabPaddingLeft); tabPaddingRight = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStripPlus_pstsTabPaddingRight, tabPaddingRight); tabPaddingTop = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStripPlus_pstsTabPaddingTop, tabPaddingTop); tabPaddingBottom = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStripPlus_pstsTabPaddingBottom, tabPaddingBottom); tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStripPlus_pstsTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStripPlus_pstsShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStripPlus_pstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStripPlus_pstsTextAllCaps, textAllCaps); textColorTab = a.getColorStateList(R.styleable.PagerSlidingTabStripPlus_pstsTextColorTab); indicatorAlpha = a.getInteger(R.styleable.PagerSlidingTabStripPlus_pstsIndicatorAlpha, indicatorAlpha); hasDivider = a.getBoolean(R.styleable.PagerSlidingTabStripPlus_pstsHasDivider, hasDivider); tabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStripPlus_pstsTabTextSize, tabTextSize); tabsGravity = a.getInteger(R.styleable.PagerSlidingTabStripPlus_pstsTabsTitleGravity, tabsGravity); a.recycle(); 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.example.android.wifidirect.WiFiDirectActivity.java
private void setTabsValue() { // Tab?/*from ww w . java 2 s. c o m*/ tabs.setShouldExpand(true); // Tab? tabs.setDividerColor(Color.TRANSPARENT); // Tab tabs.setUnderlineHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, dm)); // Tab Indicator tabs.setIndicatorHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, dm)); // Tab? tabs.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, dm)); // Tab Indicator tabs.setIndicatorColor(Color.parseColor("#45c01a")); // Tab () tabs.setSelectedTextColor(Color.parseColor("#45c01a")); // ?Tab tabs.setTabBackground(0); //?tab tabs.setTabPaddingLeftRight(36); // tab?tab?tab??? //tabs.setShouldExpand(true); }
From source file:com.tapfortap.phonegap.TapForTapPhoneGapPlugin.java
private LayoutParams getLayoutParamsForOptions(JSONObject options) { int widthPx = options.optInt("width", LayoutParams.MATCH_PARENT); int heightPx = options.optInt("height", 50); float widthDip; if (widthPx > 0) { widthDip = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, widthPx, cordova.getActivity().getResources().getDisplayMetrics()); } else {//from ww w . j a v a 2 s. c o m widthDip = widthPx; } float heightDip = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, heightPx, cordova.getActivity().getResources().getDisplayMetrics()); return new LayoutParams((int) widthDip, (int) heightDip); }
From source file:com.anyline.reactnative.Document4Activity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getResources().getIdentifier("activity_scan_scanview", "layout", getPackageName())); // takes care of fading the error message out after some time with no error reported from the SDK errorMessageCleanup = new Runnable() { @Override// www. j a v a2 s . c o m public void run() { if (Document4Activity.this.isFinishing()) { return; } if (System.currentTimeMillis() > lastErrorRecieved + ERROR_MESSAGE_DELAY) { if (errorMessage == null || errorMessageAnimator == null) { return; } if (errorMessage.getAlpha() == 0f) { errorMessage.setText(""); } else if (!errorMessageAnimator.isRunning()) { errorMessageAnimator = ObjectAnimator.ofFloat(errorMessage, "alpha", errorMessage.getAlpha(), 0f); errorMessageAnimator.setDuration(ERROR_MESSAGE_DELAY); errorMessageAnimator.setInterpolator(new AccelerateInterpolator()); errorMessageAnimator.start(); } } handler.postDelayed(errorMessageCleanup, ERROR_MESSAGE_DELAY); } }; // Set the flag to keep the screen on (otherwise the screen may go dark during scanning) getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); imageViewResult = (ImageView) findViewById( getResources().getIdentifier("image_result", "id", getPackageName())); errorMessageLayout = (FrameLayout) findViewById( getResources().getIdentifier("error_message_layout", "id", getPackageName())); errorMessage = (TextView) findViewById( getResources().getIdentifier("error_message", "id", getPackageName())); documentScanView = (ScanView) findViewById( getResources().getIdentifier("document_scan_view", "id", getPackageName())); // add a camera open listener that will be called when the camera is opened or an error occurred // this is optional (if not set a RuntimeException will be thrown if an error occurs) documentScanView.setCameraOpenListener(this); // the view can be configured via a json file in the assets, and this config is set here try { final JSONObject json = new JSONObject(configJson); documentScanView.setScanConfig(json, licenseKey); } catch (Exception e) { e.printStackTrace(); } // initialize Anyline with the license key and a Listener that is called if a result is found documentScanView.getScanViewPlugin().addScanResultListener(new DocumentScanResultListener() { @Override public void onResult(ScanResult documentResult) { // handle the result document images here if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } AnylineImage transformedImage = (AnylineImage) documentResult.getResult(); AnylineImage fullFrame = documentResult.getFullImage(); // resize display view based on larger side of document, and display document int widthDP, heightDP; Bitmap bmpTransformedImage = transformedImage.getBitmap(); if (bmpTransformedImage.getHeight() > bmpTransformedImage.getWidth()) { widthDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics()); heightDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160, getResources().getDisplayMetrics()); //Add a comment to this line imageViewResult.getLayoutParams().width = widthDP; imageViewResult.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; } else { widthDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160, getResources().getDisplayMetrics()); heightDP = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics()); imageViewResult.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT; imageViewResult.getLayoutParams().height = heightDP; } imageViewResult.setImageBitmap( Bitmap.createScaledBitmap(transformedImage.getBitmap(), widthDP, heightDP, false)); /** * IMPORTANT: cache provided frames here, and release them at the end of this onResult. Because * keeping them in memory (e.g. setting the full frame to an ImageView) * will result in a OutOfMemoryError soon. This error is reported in {@link #onTakePictureError * (Throwable)} * * Use a DiskCache http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html#disk-cache * for example * */ File outDir = new File(getCacheDir(), "ok"); outDir.mkdir(); // change the file ending to png if you want a png JSONObject jsonResult = new JSONObject(); try { // convert the transformed image into a gray scaled image internally // transformedImage.getGrayCvMat(false); // get the transformed image as bitmap // Bitmap bmp = transformedImage.getBitmap(); // save the image with quality 100 (only used for jpeg, ignored for png) File imageFile = TempFileUtil.createTempFileCheckCache(Document4Activity.this, UUID.randomUUID().toString(), ".jpg"); transformedImage.save(imageFile, quality); showToast(getString( getResources().getIdentifier("document_image_saved_to", "string", getPackageName())) + " " + imageFile.getAbsolutePath()); jsonResult.put("imagePath", imageFile.getAbsolutePath()); // Save the Full Frame Image if (fullFrame != null) { imageFile = TempFileUtil.createTempFileCheckCache(Document4Activity.this, UUID.randomUUID().toString(), ".jpg"); fullFrame.save(imageFile, quality); jsonResult.put("fullImagePath", imageFile.getAbsolutePath()); } // Put outline and conficence to result jsonResult.put("outline", jsonForOutline(documentResult.getOutline())); jsonResult.put("confidence", documentResult.getConfidence()); } catch (IOException e) { e.printStackTrace(); } catch (JSONException jsonException) { //should not be possible Log.e(TAG, "Error while putting image path to json.", jsonException); } // release the images transformedImage.release(); fullFrame.release(); Boolean cancelOnResult = true; JSONObject jsonObject; try { jsonObject = new JSONObject(configJson); cancelOnResult = jsonObject.getBoolean("cancelOnResult"); } catch (Exception e) { Log.d(TAG, e.getLocalizedMessage()); } if (cancelOnResult) { ResultReporter.onResult(jsonResult, true); setResult(AnylineSDKPlugin.RESULT_OK); finish(); } else { ResultReporter.onResult(jsonResult, false); } } @Override public void onPreviewProcessingSuccess(AnylineImage anylineImage) { // this is called after the preview of the document is completed, and a full picture will be // processed automatically } @Override public void onPreviewProcessingFailure(DocumentScanViewPlugin.DocumentError documentError) { // this is called on any error while processing the document image // Note: this is called every time an error occurs in a run, so that might be quite often // An error message should only be presented to the user after some time showErrorMessageFor(documentError); } @Override public void onPictureProcessingFailure(DocumentScanViewPlugin.DocumentError documentError) { showErrorMessageFor(documentError, true); if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } // if there is a problem, here is how images could be saved in the error case // this will be a full, not cropped, not transformed image AnylineImage image = ((DocumentScanViewPlugin) documentScanView.getScanViewPlugin()) .getCurrentFullImage(); if (image != null) { File outDir = new File(getCacheDir(), "error"); outDir.mkdir(); File outFile = new File(outDir, "" + System.currentTimeMillis() + documentError.name() + ".jpg"); try { image.save(outFile, 100); Log.d(TAG, "error image saved to " + outFile.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } image.release(); } } @Override public boolean onDocumentOutlineDetected(List rect, boolean documentShapeAndBrightnessValid) { // is called when the outline of the document is detected. return true if the outline is consumed by // the implementation here, false if the outline should be drawn by the DocumentScanView lastOutline = rect; // saving the outline for the animations return true; } @Override public void onTakePictureSuccess() { // this is called after the image has been captured from the camera and is about to be processed progressDialog = ProgressDialog.show(Document4Activity.this, getString(getResources().getIdentifier("document_processing_picture_header", "string", getPackageName())), getString(getResources().getIdentifier("document_processing_picture", "string", getPackageName())), true); if (errorMessageAnimator != null && errorMessageAnimator.isRunning()) { handler.post(new Runnable() { @Override public void run() { errorMessageAnimator.cancel(); errorMessageLayout.setVisibility(View.GONE); } }); } } @Override public void onTakePictureError(Throwable throwable) { // This is called if the image could not be captured from the camera (most probably because of an // OutOfMemoryError) throw new RuntimeException(throwable); } @Override public void onPictureCornersDetected(AnylineImage anylineImage, List rect) { // this is called after manual corner detection was requested // Note: not implemented in this example } @Override public void onPictureTransformed(AnylineImage anylineImage) { // this is called after a full frame image and 4 corners were passed to the SDK for // transformation (e.g. when a user manually selected the corners in an image) // Note: not implemented in this example } @Override public void onPictureTransformError(DocumentScanViewPlugin.DocumentError documentError) { // this is called on any error while transforming the document image from the 4 corners // Note: not implemented in this example } }); // optionally stop the scan once a valid result was returned // documentScanView.setCancelOnResult(cancelOnResult); }
From source file:com.b44t.ui.Components.PasscodeView.java
public PasscodeView(final Context context) { super(context); setWillNotDraw(false);//from w w w.java 2 s . c o m setVisibility(GONE); backgroundFrameLayout = new FrameLayout(context); addView(backgroundFrameLayout); LayoutParams layoutParams = (LayoutParams) backgroundFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; backgroundFrameLayout.setLayoutParams(layoutParams); passwordFrameLayout = new FrameLayout(context); addView(passwordFrameLayout); layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP | Gravity.LEFT; passwordFrameLayout.setLayoutParams(layoutParams); ImageView imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setImageResource(R.drawable.ic_launcher /* EDIT BY MR -- was: passcode_logo */); passwordFrameLayout.addView(imageView); layoutParams = (LayoutParams) imageView.getLayoutParams(); if (AndroidUtilities.density < 1) { layoutParams.width = AndroidUtilities.dp(30); layoutParams.height = AndroidUtilities.dp(30); } else { layoutParams.width = AndroidUtilities.dp(40); layoutParams.height = AndroidUtilities.dp(40); } layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; layoutParams.bottomMargin = AndroidUtilities.dp(100); imageView.setLayoutParams(layoutParams); passcodeTextView = new TextView(context); passcodeTextView.setTextColor(0xffffffff); passcodeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); passcodeTextView.setGravity(Gravity.CENTER_HORIZONTAL); passwordFrameLayout.addView(passcodeTextView); layoutParams = (LayoutParams) passcodeTextView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.bottomMargin = AndroidUtilities.dp(62); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; passcodeTextView.setLayoutParams(layoutParams); passwordEditText = new EditText(context); passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36); passwordEditText.setTextColor(0xffffffff); passwordEditText.setMaxLines(1); passwordEditText.setLines(1); passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL); passwordEditText.setSingleLine(true); passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordEditText.setTypeface(Typeface.DEFAULT); passwordEditText.setBackgroundDrawable(null); AndroidUtilities.clearCursorDrawable(passwordEditText); passwordFrameLayout.addView(passwordEditText); layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams(); layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.leftMargin = AndroidUtilities.dp(70); layoutParams.rightMargin = AndroidUtilities.dp(70); layoutParams.bottomMargin = AndroidUtilities.dp(6); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; passwordEditText.setLayoutParams(layoutParams); passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_DONE) { processDone(false); return true; } return false; } }); passwordEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (passwordEditText.length() == 4 && UserConfig.passcodeType == 0) { processDone(false); } } }); passwordEditText.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; } }); checkImage = new ImageView(context); checkImage.setImageResource(R.drawable.passcode_check); checkImage.setScaleType(ImageView.ScaleType.CENTER); checkImage.setBackgroundResource(R.drawable.bar_selector_lock); passwordFrameLayout.addView(checkImage); layoutParams = (LayoutParams) checkImage.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(60); layoutParams.height = AndroidUtilities.dp(60); layoutParams.bottomMargin = AndroidUtilities.dp(4); layoutParams.rightMargin = AndroidUtilities.dp(10); layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; checkImage.setLayoutParams(layoutParams); checkImage.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { processDone(false); } }); FrameLayout lineFrameLayout = new FrameLayout(context); lineFrameLayout.setBackgroundColor(0x26ffffff); passwordFrameLayout.addView(lineFrameLayout); layoutParams = (LayoutParams) lineFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = AndroidUtilities.dp(1); layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT; layoutParams.leftMargin = AndroidUtilities.dp(20); layoutParams.rightMargin = AndroidUtilities.dp(20); lineFrameLayout.setLayoutParams(layoutParams); numbersFrameLayout = new FrameLayout(context); addView(numbersFrameLayout); layoutParams = (LayoutParams) numbersFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP | Gravity.LEFT; numbersFrameLayout.setLayoutParams(layoutParams); lettersTextViews = new ArrayList<>(10); numberTextViews = new ArrayList<>(10); numberFrameLayouts = new ArrayList<>(10); for (int a = 0; a < 10; a++) { TextView textView = new TextView(context); textView.setTextColor(0xffffffff); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36); textView.setGravity(Gravity.CENTER); textView.setText(String.format(Locale.US, "%d", a)); numbersFrameLayout.addView(textView); layoutParams = (LayoutParams) textView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(50); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; textView.setLayoutParams(layoutParams); numberTextViews.add(textView); textView = new TextView(context); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); textView.setTextColor(0x7fffffff); textView.setGravity(Gravity.CENTER); numbersFrameLayout.addView(textView); layoutParams = (LayoutParams) textView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(20); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; textView.setLayoutParams(layoutParams); switch (a) { case 0: textView.setText("+"); break; case 2: textView.setText("ABC"); break; case 3: textView.setText("DEF"); break; case 4: textView.setText("GHI"); break; case 5: textView.setText("JKL"); break; case 6: textView.setText("MNO"); break; case 7: textView.setText("PQRS"); break; case 8: textView.setText("TUV"); break; case 9: textView.setText("WXYZ"); break; default: break; } lettersTextViews.add(textView); } eraseView = new ImageView(context); eraseView.setScaleType(ImageView.ScaleType.CENTER); eraseView.setImageResource(R.drawable.passcode_delete); numbersFrameLayout.addView(eraseView); layoutParams = (LayoutParams) eraseView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(50); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; eraseView.setLayoutParams(layoutParams); for (int a = 0; a < 11; a++) { FrameLayout frameLayout = new FrameLayout(context); frameLayout.setBackgroundResource(R.drawable.bar_selector_lock); frameLayout.setTag(a); if (a == 10) { frameLayout.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { passwordEditText.setText(""); return true; } }); } frameLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int tag = (Integer) v.getTag(); switch (tag) { case 0: appendCharacter("0"); break; case 1: appendCharacter("1"); break; case 2: appendCharacter("2"); break; case 3: appendCharacter("3"); break; case 4: appendCharacter("4"); break; case 5: appendCharacter("5"); break; case 6: appendCharacter("6"); break; case 7: appendCharacter("7"); break; case 8: appendCharacter("8"); break; case 9: appendCharacter("9"); break; case 10: String text = passwordEditText.getText().toString(); if (text.length() > 0) { passwordEditText.setText(text.substring(0, text.length() - 1)); } break; } if (passwordEditText.getText().toString().length() == 4) { processDone(false); } } }); numberFrameLayouts.add(frameLayout); } for (int a = 10; a >= 0; a--) { FrameLayout frameLayout = numberFrameLayouts.get(a); numbersFrameLayout.addView(frameLayout); layoutParams = (LayoutParams) frameLayout.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(100); layoutParams.height = AndroidUtilities.dp(100); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; frameLayout.setLayoutParams(layoutParams); } }
From source file:com.emotiona.study.listviewpage.SwipeMenuListViewFragment.java
private int dp2px(int dp) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()); }
From source file:com.nextgis.maplibui.formcontrol.Combobox.java
@Override public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, SharedPreferences preferences) throws JSONException { JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); mFieldName = attributes.getString(JSON_FIELD_NAME_KEY); mIsShowLast = ControlHelper.isSaveLastValue(attributes); setEnabled(ControlHelper.isEnabled(fields, mFieldName)); String lastValue = null;// w ww . ja v a 2 s. com if (ControlHelper.hasKey(savedState, mFieldName)) lastValue = savedState.getString(ControlHelper.getSavedStateKey(mFieldName)); else if (null != featureCursor) { int column = featureCursor.getColumnIndex(mFieldName); if (column >= 0) lastValue = featureCursor.getString(column); } else if (mIsShowLast) lastValue = preferences.getString(mFieldName, null); int defaultPosition = 0; int lastValuePosition = -1; mAliasValueMap = new HashMap<>(); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(getContext(), R.layout.formtemplate_spinner); setAdapter(spinnerArrayAdapter); if (attributes.has(ConstantsUI.JSON_NGW_ID_KEY) && attributes.getLong(ConstantsUI.JSON_NGW_ID_KEY) != -1) { MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance(); if (null == map) throw new IllegalArgumentException("The map should extends MapContentProviderHelper or inherited"); String account = element.optString(SyncStateContract.Columns.ACCOUNT_NAME); long id = attributes.getLong(JSON_NGW_ID_KEY); for (int i = 0; i < map.getLayerCount(); i++) { if (map.getLayer(i) instanceof NGWLookupTable) { NGWLookupTable table = (NGWLookupTable) map.getLayer(i); if (table.getRemoteId() != id || !table.getAccountName().equals(account)) continue; int j = 0; for (Map.Entry<String, String> entry : table.getData().entrySet()) { mAliasValueMap.put(entry.getValue(), entry.getKey()); if (null != lastValue && lastValue.equals(entry.getKey())) lastValuePosition = j; spinnerArrayAdapter.add(entry.getValue()); j++; } break; } } } else { JSONArray values = attributes.optJSONArray(JSON_VALUES_KEY); if (values != null) { for (int j = 0; j < values.length(); j++) { JSONObject keyValue = values.getJSONObject(j); String value = keyValue.getString(JSON_VALUE_NAME_KEY); String value_alias = keyValue.getString(JSON_VALUE_ALIAS_KEY); if (keyValue.has(JSON_DEFAULT_KEY) && keyValue.getBoolean(JSON_DEFAULT_KEY)) defaultPosition = j; if (null != lastValue && lastValue.equals(value)) lastValuePosition = j; mAliasValueMap.put(value_alias, value); spinnerArrayAdapter.add(value_alias); } } } setSelection(lastValuePosition >= 0 ? lastValuePosition : defaultPosition); // The drop down view spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); float minHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, getResources().getDisplayMetrics()); setPadding(0, (int) minHeight, 0, (int) minHeight); }
From source file:alexander.martinz.libs.materialpreferences.MaterialEditTextPreference.java
private float convertDpToPixels(int dp) { DisplayMetrics metrics = getResources().getDisplayMetrics(); return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics); }
From source file:com.android.inputmethod.latin.suggestions.SuggestionStripView.java
public SuggestionStripView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); final LayoutInflater inflater = LayoutInflater.from(context); inflater.inflate(R.layout.suggestions_strip, this); mSuggestionsStrip = (ViewGroup) findViewById(R.id.suggestions_strip); mVoiceKey = (ImageButton) findViewById(R.id.suggestions_strip_voice_key); mImportantNoticeStrip = findViewById(R.id.important_notice_strip); mStripVisibilityGroup = new StripVisibilityGroup(this, mSuggestionsStrip, mImportantNoticeStrip); for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) { final TextView word = new TextView(context, null, R.attr.suggestionWordStyle); word.setContentDescription(getResources().getString(R.string.spoken_empty_suggestion)); word.setOnClickListener(this); word.setOnLongClickListener(this); mWordViews.add(word);//from ww w . ja va 2 s.c om final View divider = inflater.inflate(R.layout.suggestion_divider, null); mDividerViews.add(divider); final TextView info = new TextView(context, null, R.attr.suggestionWordStyle); info.setTextColor(Color.WHITE); info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEBUG_INFO_TEXT_SIZE_IN_DIP); mDebugInfoViews.add(info); } mLayoutHelper = new SuggestionStripLayoutHelper(context, attrs, defStyle, mWordViews, mDividerViews, mDebugInfoViews); mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null); mMoreSuggestionsView = (MoreSuggestionsView) mMoreSuggestionsContainer .findViewById(R.id.more_suggestions_view); mMoreSuggestionsBuilder = new MoreSuggestions.Builder(context, mMoreSuggestionsView); final Resources res = context.getResources(); mMoreSuggestionsModalTolerance = res .getDimensionPixelOffset(R.dimen.config_more_suggestions_modal_tolerance); mMoreSuggestionsSlidingDetector = new GestureDetector(context, mMoreSuggestionsSlidingListener); final TypedArray keyboardAttr = context.obtainStyledAttributes(attrs, R.styleable.Keyboard, defStyle, R.style.SuggestionStripView); final Drawable iconVoice = keyboardAttr.getDrawable(R.styleable.Keyboard_iconShortcutKey); keyboardAttr.recycle(); mVoiceKey.setImageDrawable(iconVoice); mVoiceKey.setOnClickListener(this); }
From source file:com.androguide.honamicontrol.MainActivity.java
@SuppressLint("NewApi") @SuppressWarnings("deprecation") @Override/* w ww . ja v a 2 s. c om*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_main); headers.add("Welcome"); headers.add("Kernel Control"); headers.add("Sound Control"); headers.add("Touch Screen"); headers.add("Help Center"); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); ArrayAdapter<String> pimpAdapter = new ArrayAdapter<String>(this, R.layout.drawer_list_item, mDrawerHeaders); mDrawerList.setAdapter(pimpAdapter); 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()); /** * ActionBarDrawerToggle ties together the proper interactions between * the sliding drawer and the action bar app icon */ mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.open_drawer, R.string.close_drawer) { public void onDrawerClosed(View view) { invalidateOptionsMenu(); } public void onDrawerOpened(View drawerView) { invalidateOptionsMenu(); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); /** Tabs adapter using the PagerSlidingStrip library */ tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs); 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(mAppColor)); pager.setOffscreenPageLimit(5); }