List of usage examples for android.content.res Resources getConfiguration
public Configuration getConfiguration()
From source file:com.edutech.eBalanbot.eBalanbotActivity.java
@Override @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; context = getApplicationContext();// w w w . j a v a 2s . c om if (!getResources().getBoolean(R.bool.isTablet)) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Set portrait mode only - for small screens like phones else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER); // Full screen rotation else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); // Full screen rotation new Handler().postDelayed(new Runnable() { // Hack to hide keyboard when the layout it rotated @Override public void run() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Hide the keyboard - this is needed when the device is rotated imm.hideSoftInputFromWindow(getWindow().getDecorView().getApplicationWindowToken(), 0); } }, 1000); } setContentView(R.layout.activity_main); // Get local Bluetooth adapter if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); else mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { showToast("Bluetooth is not available", Toast.LENGTH_LONG); finish(); return; } // get sensorManager and initialize sensor listeners SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mSensorFusion = new SensorFusion(getApplicationContext(), mSensorManager); // Set up the action bar. final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayHomeAsUpEnabled(true); // Create the adapter that will return a fragment for each of the primary sections of the app. ViewPagerAdapter mViewPagerAdapter = new ViewPagerAdapter(getApplicationContext(), getSupportFragmentManager()); // Set up the ViewPager with the adapter. CustomViewPager mViewPager = (CustomViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mViewPagerAdapter); if (getResources().getBoolean(R.bool.isTablet)) mViewPager.setOffscreenPageLimit(2); // Since two fragments is selected in landscape mode, this is used to smooth things out // Bind the underline indicator to the adapter mUnderlinePageIndicator = (UnderlinePageIndicator) findViewById(R.id.indicator); mUnderlinePageIndicator.setViewPager(mViewPager); mUnderlinePageIndicator.setFades(false); // When swiping between different sections, select the corresponding // tab. We can also use ActionBar.Tab#select() to do this if we have // a reference to the Tab. mUnderlinePageIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { if (D) Log.d(TAG, "ViewPager position: " + position); if (position < actionBar.getTabCount()) // Needed for when in landscape mode actionBar.setSelectedNavigationItem(position); else mUnderlinePageIndicator.setCurrentItem(position - 1); } }); int count = mViewPagerAdapter.getCount(); Resources mResources = getResources(); boolean landscape = false; if (mResources.getBoolean(R.bool.isTablet) && mResources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { landscape = true; count -= 1; // There is one less tab when in landscape mode } for (int i = 0; i < count; i++) { // For each of the sections in the app, add a tab to the action bar String text; if (landscape && i == count - 1) text = mViewPagerAdapter.getPageTitle(i) + " & " + mViewPagerAdapter.getPageTitle(i + 1); // Last tab in landscape mode have two titles in one tab else text = mViewPagerAdapter.getPageTitle(i).toString(); // Create a tab with text corresponding to the page title defined by // the adapter. Also specify this Activity object, which implements // the TabListener interface, as the callback (listener) for when // this tab is selected. actionBar.addTab(actionBar.newTab().setText(text).setTabListener(this)); } try { PackageManager mPackageManager = getPackageManager(); if (mPackageManager != null) eBalanbotActivity.appVersion = mPackageManager.getPackageInfo(getPackageName(), 0).versionName; // Read the app version name } catch (NameNotFoundException e) { e.printStackTrace(); } }
From source file:com.tkjelectronics.balanduino.BalanduinoActivity.java
@Override @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; context = getApplicationContext();/*from w w w . j a v a 2 s .c o m*/ if (!getResources().getBoolean(R.bool.isTablet)) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Set portrait mode only - for small screens like phones else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER); // Full screen rotation else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); // Full screen rotation new Handler().postDelayed(new Runnable() { // Hack to hide keyboard when the layout it rotated @Override public void run() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Hide the keyboard - this is needed when the device is rotated imm.hideSoftInputFromWindow(getWindow().getDecorView().getApplicationWindowToken(), 0); } }, 1000); } setContentView(R.layout.activity_main); // Get local Bluetooth adapter if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); else mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { showToast("Bluetooth is not available", Toast.LENGTH_LONG); finish(); return; } // get sensorManager and initialize sensor listeners SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mSensorFusion = new SensorFusion(getApplicationContext(), mSensorManager); // Set up the action bar. final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayHomeAsUpEnabled(true); // Create the adapter that will return a fragment for each of the primary sections of the app. ViewPagerAdapter mViewPagerAdapter = new ViewPagerAdapter(getApplicationContext(), getSupportFragmentManager()); // Set up the ViewPager with the adapter. CustomViewPager mViewPager = (CustomViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mViewPagerAdapter); if (getResources().getBoolean(R.bool.isTablet)) mViewPager.setOffscreenPageLimit(2); // Since two fragments is selected in landscape mode, this is used to smooth things out // Bind the underline indicator to the adapter mUnderlinePageIndicator = (UnderlinePageIndicator) findViewById(R.id.indicator); mUnderlinePageIndicator.setViewPager(mViewPager); mUnderlinePageIndicator.setFades(false); // When swiping between different sections, select the corresponding // tab. We can also use ActionBar.Tab#select() to do this if we have // a reference to the Tab. mUnderlinePageIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { if (D) Log.d(TAG, "ViewPager position: " + position); if (position < actionBar.getTabCount()) // Needed for when in landscape mode actionBar.setSelectedNavigationItem(position); else mUnderlinePageIndicator.setCurrentItem(position - 1); } }); int count = mViewPagerAdapter.getCount(); Resources mResources = getResources(); boolean landscape = false; if (mResources.getBoolean(R.bool.isTablet) && mResources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { landscape = true; count -= 1; // There is one less tab when in landscape mode } for (int i = 0; i < count; i++) { // For each of the sections in the app, add a tab to the action bar String text; if (landscape && i == count - 1) text = mViewPagerAdapter.getPageTitle(i) + " & " + mViewPagerAdapter.getPageTitle(i + 1); // Last tab in landscape mode have two titles in one tab else text = mViewPagerAdapter.getPageTitle(i).toString(); // Create a tab with text corresponding to the page title defined by // the adapter. Also specify this Activity object, which implements // the TabListener interface, as the callback (listener) for when // this tab is selected. actionBar.addTab(actionBar.newTab().setText(text).setTabListener(this)); } try { PackageManager mPackageManager = getPackageManager(); if (mPackageManager != null) BalanduinoActivity.appVersion = mPackageManager.getPackageInfo(getPackageName(), 0).versionName; // Read the app version name } catch (NameNotFoundException e) { e.printStackTrace(); } }
From source file:com.duinopeak.balanbot.BalanbotActivity.java
@Override @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; context = getApplicationContext();/*from ww w . j a v a2 s. c o m*/ if (!getResources().getBoolean(R.bool.isTablet)) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Set portrait mode only - for small screens like phones else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER); // Full screen rotation else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); // Full screen rotation new Handler().postDelayed(new Runnable() { // Hack to hide keyboard when the layout it rotated @Override public void run() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Hide the keyboard - this is needed when the device is rotated imm.hideSoftInputFromWindow(getWindow().getDecorView().getApplicationWindowToken(), 0); } }, 1000); } setContentView(R.layout.activity_main); // Get local Bluetooth adapter if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); else mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { showToast("Bluetooth is not available", Toast.LENGTH_LONG); finish(); return; } // get sensorManager and initialize sensor listeners SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mSensorFusion = new SensorFusion(getApplicationContext(), mSensorManager); // Set up the action bar. final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayHomeAsUpEnabled(true); // Create the adapter that will return a fragment for each of the primary sections of the app. ViewPagerAdapter mViewPagerAdapter = new ViewPagerAdapter(getApplicationContext(), getSupportFragmentManager()); // Set up the ViewPager with the adapter. CustomViewPager mViewPager = (CustomViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mViewPagerAdapter); if (getResources().getBoolean(R.bool.isTablet)) mViewPager.setOffscreenPageLimit(2); // Since two fragments is selected in landscape mode, this is used to smooth things out // Bind the underline indicator to the adapter mUnderlinePageIndicator = (UnderlinePageIndicator) findViewById(R.id.indicator); mUnderlinePageIndicator.setViewPager(mViewPager); mUnderlinePageIndicator.setFades(false); // When swiping between different sections, select the corresponding // tab. We can also use ActionBar.Tab#select() to do this if we have // a reference to the Tab. mUnderlinePageIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { if (D) Log.d(TAG, "ViewPager position: " + position); if (position < actionBar.getTabCount()) // Needed for when in landscape mode actionBar.setSelectedNavigationItem(position); else mUnderlinePageIndicator.setCurrentItem(position - 1); } }); int count = mViewPagerAdapter.getCount(); Resources mResources = getResources(); boolean landscape = false; if (mResources.getBoolean(R.bool.isTablet) && mResources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { landscape = true; count -= 1; // There is one less tab when in landscape mode } for (int i = 0; i < count; i++) { // For each of the sections in the app, add a tab to the action bar String text; if (landscape && i == count - 1) text = mViewPagerAdapter.getPageTitle(i) + " & " + mViewPagerAdapter.getPageTitle(i + 1); // Last tab in landscape mode have two titles in one tab else text = mViewPagerAdapter.getPageTitle(i).toString(); // Create a tab with text corresponding to the page title defined by // the adapter. Also specify this Activity object, which implements // the TabListener interface, as the callback (listener) for when // this tab is selected. actionBar.addTab(actionBar.newTab().setText(text).setTabListener(this)); } try { PackageManager mPackageManager = getPackageManager(); if (mPackageManager != null) BalanbotActivity.appVersion = mPackageManager.getPackageInfo(getPackageName(), 0).versionName; // Read the app version name } catch (NameNotFoundException e) { e.printStackTrace(); } }
From source file:mobile.tiis.appv2.LoginActivity.java
public void setLocale(String lang) { myLocale = new Locale(lang); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale;/* ww w. j av a 2 s. c o m*/ res.updateConfiguration(conf, dm); Intent refresh = new Intent(this, LoginActivity.class); refresh.putExtra(BackboneActivity.LANGUAGELOGIN, languagePosition); startActivity(refresh); }
From source file:org.akvo.caddisfly.ui.activity.MainActivity.java
/** * Load user preferences//w w w . j a va 2s . c o m */ private void loadSavedPreferences() { assert getApplicationContext() != null; // Set the locale according to preference Locale myLocale = new Locale(PreferencesUtils.getString(this, R.string.languageKey, Config.DEFAULT_LOCALE)); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { conf.setLayoutDirection(myLocale); } res.updateConfiguration(conf, dm); }
From source file:com.ruesga.rview.wizard.WizardActivity.java
@SuppressWarnings("unchecked") @Override//from w w w .jav a 2 s . co m protected final void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); mFragmentManager = getSupportFragmentManager(); // Load the wizard pages setupPages(); mArePagesConfigured = true; if (mPages.isEmpty()) { Log.w(getTag(), "Wizard has no pages!!"); finish(); return; } if (savedInstanceState != null) { restoreInstance(savedInstanceState); } if (mCurrentPage < 0 || mCurrentPage >= mPages.size()) { performNavigateToPage(mCurrentPage); return; } // Configure the view setupStatusBar(); final Resources res = getResources(); mMinHeaderHeight = (int) res.getDimension(R.dimen.wizard_min_actionbar_size); mMaxHeaderHeight = (int) res.getDimension(R.dimen.wizard_max_actionbar_size); // Bind the views boolean isTablet = res.getBoolean(R.bool.config_isTablet); mIsExtendedHeaderLayoutSupported = !isTablet && res.getConfiguration().orientation == ORIENTATION_PORTRAIT; mBinding = DataBindingUtil.setContentView(this, R.layout.activity_wizard); mBinding.setHandlers(new WorkFlowHandlers(this)); if (mIsExtendedHeaderLayoutSupported) { mBinding.pageHeader.getLayoutParams().height = mIsExtendedHeaderLayoutSupported && mPages.get(mCurrentPage).hasExtendedHeader() ? mMaxHeaderHeight : mMinHeaderHeight; } // Prepared the back and forward loaders mLoaders = new Pair[mPages.size()]; RxLoaderManager loaderManager = RxLoaderManagerCompat.get(this); int i = 0; for (WizardPageFragment page : mPages) { Callable<Boolean> back = page.doBackAction(); Callable<Boolean> forward = page.doForwardAction(); RxLoader<Boolean> backLoader = null; if (back != null) { backLoader = loaderManager.create("lb" + i, actionObserver(back), mBackObserver); } RxLoader<Boolean> forwardLoader = null; if (forward != null) { forwardLoader = loaderManager.create("lf" + i, actionObserver(forward), mForwardObserver); } mLoaders[i] = new Pair<>(backLoader, forwardLoader); i++; } // Navigate and draw page information if (mCurrentChooserFragmentTag != null) { WizardChooserFragment chooser = (WizardChooserFragment) mFragmentManager .findFragmentByTag(mCurrentChooserFragmentTag); performOpenChooserPage(chooser); bindChooserWorkflow(chooser); } else { performNavigateToPage(mCurrentPage); } mIsActivityConfigured = true; }
From source file:com.commonsware.cwac.crossport.design.widget.FloatingActionButton.java
private int getSizeDimension(@Size final int size) { final Resources res = getResources(); // If custom size is set, return it if (mCustomSize != NO_CUSTOM_SIZE) { return mCustomSize; }/*from ww w . ja v a 2s . c o m*/ switch (size) { case SIZE_AUTO: // If we're set to auto, grab the size from resources and refresh final int width = res.getConfiguration().screenWidthDp; final int height = res.getConfiguration().screenHeightDp; return Math.max(width, height) < AUTO_MINI_LARGEST_SCREEN_WIDTH ? getSizeDimension(SIZE_MINI) : getSizeDimension(SIZE_NORMAL); case SIZE_MINI: return res.getDimensionPixelSize(R.dimen.design_fab_size_mini); case SIZE_NORMAL: default: return res.getDimensionPixelSize(R.dimen.design_fab_size_normal); } }
From source file:com.appsimobile.appsii.module.search.SearchController.java
@Override protected void onViewCreated(View view, Bundle savedInstanceState) { mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler); mSearchView = (EditText) view.findViewById(R.id.search_view); mSuggestionsAnchor = view.findViewById(R.id.search_wrapper); mSearchRecyclerView = (RecyclerView) view.findViewById(R.id.search_recycler); mSearchDivider = view.findViewById(R.id.search_divider); mSearchRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(getContext())); mSearchRecyclerView.setAdapter(mSearchSuggestionsAdapter); mRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(getContext())); mRecyclerView.setAdapter(mSearchAdapter); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); // mRecyclerView.setOnScrollListener(new ToolbarScrollListener(this, mToolbar)); Resources res = getResources(); float density = res.getDisplayMetrics().density; // calculate the width of the sidebar int contentWidth = getContentWidth(); if (contentWidth == 0) { float pct = mPreferenceHelper.getSidebarWidth() / 100f; contentWidth = (int) (res.getConfiguration().smallestScreenWidthDp * density * pct); }/*w w w.j a v a 2s . co m*/ int dp104 = (int) (density * 104); int cellCount = contentWidth / dp104; if (cellCount < 3) cellCount = 3; if (cellCount > 3) cellCount--; mGridLayoutManager = new GridLayoutManager(getContext(), cellCount); mSearchAdapter.setSpanCount(cellCount); mRecyclerView.setLayoutManager(mGridLayoutManager); mGridLayoutManager.setSpanSizeLookup(mSearchAdapter.mSpanSizeLookup); mSearchView.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) { onSearchTextChanged(s); } }); mSearchView.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { onSearchFocusChanged(hasFocus); } }); mSearchSuggestionsAdapter.setOnItemClickListener(this); Button speechButton; /* speechButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); // intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5); mSpeechRecognizer.startListening(intent); Log.i("111111", "11111111"); } }); */ }
From source file:com.android.launcher3.Utilities.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static boolean isRtl(Resources res) { return ATLEAST_JB_MR1 && (res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL); }
From source file:com.android.launcher3.Utilities.java
public static boolean getAllowRotationDefaultValue(Context context) { if (isNycOrAbove()) { // If the device was scaled, used the original dimensions to determine if rotation // is allowed of not. Resources res = context.getResources(); int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp * res.getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEVICE_STABLE; return originalSmallestWidth >= 600; }/* w w w. j av a 2 s .co m*/ return false; }