List of usage examples for android.content.res Configuration getLayoutDirection
public int getLayoutDirection()
From source file:com.jaredrummler.materialspinner.MaterialSpinner.java
private void init(Context context, AttributeSet attrs) { TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialSpinner); int defaultColor = getTextColors().getDefaultColor(); backgroundColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_background_color, Color.WHITE); textColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_text_color, defaultColor); arrowColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_arrow_tint, textColor); hideArrow = typedArray.getBoolean(R.styleable.MaterialSpinner_ms_hide_arrow, false); typedArray.recycle();//www . java2 s . com setGravity(Gravity.CENTER_VERTICAL | Gravity.START); boolean rtl = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Configuration config = getResources().getConfiguration(); rtl = config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; if (rtl) { setLayoutDirection(View.LAYOUT_DIRECTION_RTL); setTextDirection(View.TEXT_DIRECTION_RTL); } } Resources resources = getResources(); int left, right, bottom, top; left = right = bottom = top = resources.getDimensionPixelSize(R.dimen.ms__padding_top); if (rtl) { right = resources.getDimensionPixelSize(R.dimen.ms__padding_left); } else { left = resources.getDimensionPixelSize(R.dimen.ms__padding_left); } setClickable(true); setPadding(left, top, right, bottom); setBackgroundResource(R.drawable.ms__selector); if (!hideArrow) { arrowDrawable = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ms__arrow)); DrawableCompat.setTint(arrowDrawable, arrowColor); if (rtl) { setCompoundDrawablesWithIntrinsicBounds(arrowDrawable, null, null, null); } else { setCompoundDrawablesWithIntrinsicBounds(null, null, arrowDrawable, null); } } listView = new ListView(context); listView.setId(getId()); listView.setDivider(null); listView.setItemsCanFocus(true); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position >= selectedIndex && position < adapter.getCount()) { position++; } selectedIndex = position; nothingSelected = false; Object item = adapter.get(position); adapter.notifyItemSelected(position); setText(item.toString()); collapse(); if (onItemSelectedListener != null) { //noinspection unchecked onItemSelectedListener.onItemSelected(MaterialSpinner.this, position, id, item); } } }); popupWindow = new PopupWindow(context); popupWindow.setContentView(listView); popupWindow.setOutsideTouchable(true); popupWindow.setFocusable(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { popupWindow.setElevation(16); popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ms__drawable)); } else { popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ms__drop_down_shadow)); } if (backgroundColor != Color.WHITE) { // default color is white setBackgroundColor(backgroundColor); } if (textColor != defaultColor) { setTextColor(textColor); } popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { if (nothingSelected && onNothingSelectedListener != null) { onNothingSelectedListener.onNothingSelected(MaterialSpinner.this); } if (!hideArrow) { animateArrow(false); } } }); }
From source file:org.catrobat.paintroid.MainActivity.java
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); initLocaleConfiguration();//from w ww . j a va 2s. c om Configuration config = getApplicationContext().getResources().getConfiguration(); PaintroidApplication.isRTL = (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL); ColorPickerDialog.getInstance().dismiss(); ColorPickerDialog.init(this); boolean isShowing = IndeterminateProgressDialog.getInstance().isShowing(); IndeterminateProgressDialog.getInstance().dismiss(); IndeterminateProgressDialog.init(this); if (isShowing) { IndeterminateProgressDialog.getInstance().show(); } BrushPickerView.init(this); setContentView(R.layout.main); View mainView = findViewById(R.id.drawer_layout); mainView.setLayoutDirection( PaintroidApplication.isRTL ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR); initActionBar(); mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); hideKeyboard(); PaintroidApplication.orientation = getResources().getConfiguration().orientation; PaintroidApplication.drawingSurface = (DrawingSurface) findViewById(R.id.drawingSurfaceView); PaintroidApplication.perspective = new Perspective(PaintroidApplication.drawingSurface.getHolder()); mDrawingSurfaceListener = new DrawingSurfaceListener(); mBottomBar = new BottomBar(this); mTopBar = new TopBar(this, PaintroidApplication.openedFromCatroid); mLayerSideNav = (NavigationView) findViewById(R.id.nav_view_layer); mLayersAdapter = new LayersAdapter(this, PaintroidApplication.openedFromCatroid, PaintroidApplication.drawingSurface.getBitmapCopy()); int colorPickerBackgroundColor = PaintroidApplication.colorPickerInitialColor; ColorPickerDialog.getInstance().setInitialColor(colorPickerBackgroundColor); PaintroidApplication.drawingSurface.setOnTouchListener(mDrawingSurfaceListener); PaintroidApplication.drawingSurface.resetBitmap(LayerListener.getInstance().getCurrentLayer().getImage()); PaintroidApplication.perspective.resetScaleAndTranslation(); PaintroidApplication.currentTool.resetInternalState(Tool.StateChange.NEW_IMAGE_LOADED); LayerListener.init(this, mLayerSideNav, PaintroidApplication.drawingSurface.getBitmapCopy(), true); initNavigationDrawer(); initKeyboardIsShownListener(); setFullScreen(false); ((CommandManagerImplementation) PaintroidApplication.commandManager).setUpdateTopBarListener(mTopBar); UndoRedoManager.getInstance().update(); }
From source file:org.catrobat.paintroid.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { initLocaleConfiguration();// w w w . j av a 2 s.c om Configuration config = getApplicationContext().getResources().getConfiguration(); PaintroidApplication.isRTL = (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL); ColorPickerDialog.init(this); IndeterminateProgressDialog.init(this); super.onCreate(savedInstanceState); setContentView(R.layout.main); initActionBar(); mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); PaintroidApplication.catroidPicturePath = null; String catroidPicturePath = null; Bundle extras = getIntent().getExtras(); if (extras != null) { catroidPicturePath = extras.getString(getString(R.string.extra_picture_path_catroid)); Log.d(PaintroidApplication.TAG, "catroidPicturePath: " + catroidPicturePath); } if (catroidPicturePath != null) { PaintroidApplication.openedFromCatroid = true; if (!catroidPicturePath.equals("")) { PaintroidApplication.catroidPicturePath = catroidPicturePath; PaintroidApplication.scaleImage = false; } ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { supportActionBar.setDisplayHomeAsUpEnabled(true); supportActionBar.setDisplayShowHomeEnabled(true); } } else { PaintroidApplication.openedFromCatroid = false; } PaintroidApplication.orientation = getResources().getConfiguration().orientation; PaintroidApplication.drawingSurface = (DrawingSurface) findViewById(R.id.drawingSurfaceView); PaintroidApplication.perspective = new Perspective(PaintroidApplication.drawingSurface.getHolder()); mDrawingSurfaceListener = new DrawingSurfaceListener(); BrushPickerView.init(this); mBottomBar = new BottomBar(this); mTopBar = new TopBar(this, PaintroidApplication.openedFromCatroid); mLayerSideNav = (NavigationView) findViewById(R.id.nav_view_layer); mLayersAdapter = new LayersAdapter(this, PaintroidApplication.openedFromCatroid, PaintroidApplication.drawingSurface.getBitmapCopy()); int colorPickerBackgroundColor = PaintroidApplication.colorPickerInitialColor; ColorPickerDialog.getInstance().setInitialColor(colorPickerBackgroundColor); PaintroidApplication.drawingSurface.setOnTouchListener(mDrawingSurfaceListener); if (PaintroidApplication.openedFromCatroid && catroidPicturePath != null && catroidPicturePath.length() > 0) { initializeWhenOpenedFromCatroid(); loadBitmapFromUriAndRun(Uri.fromFile(new File(catroidPicturePath)), new RunnableWithBitmap() { @Override public void run(Bitmap bitmap) { if (!bitmap.hasAlpha()) { bitmap.setHasAlpha(true); } handleAndAssignImage(bitmap); } private void handleAndAssignImage(Bitmap bitmap) { Command command = new LoadCommand(bitmap); PaintroidApplication.commandManager.commitCommandToLayer( new LayerCommand(LayerListener.getInstance().getCurrentLayer()), command); } }); } else if (PaintroidApplication.openedFromCatroid) { initializeWhenOpenedFromCatroid(); } else { initialiseNewBitmap(); } if (PaintroidApplication.openedFromCatroid == false) LayerListener.init(this, mLayerSideNav, PaintroidApplication.drawingSurface.getBitmapCopy(), false); if (!PaintroidApplication.commandManager.isCommandManagerInitialized() || PaintroidApplication.openedFromCatroid) initCommandManager(); initNavigationDrawer(); initKeyboardIsShownListener(); }