List of usage examples for android.view Display getWidth
@Deprecated public int getWidth()
From source file:com.happysanta.vkspy.Fragments.MainFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { context = getActivity();//from w ww . j a v a2 s . c o m if (savedInstanceState != null && UberFunktion.loading) { ProgressDialog dialog = new ProgressDialog(context); dialog.setMessage(context.getString(R.string.durov_function_activating_message)); UberFunktion.putNewDialogWindow(dialog); dialog.show(); } View rootView = inflater.inflate(R.layout.fragment_main, null); View happySanta = inflater.inflate(R.layout.main_santa, null); TextView happySantaText = (TextView) happySanta.findViewById(R.id.happySantaText); happySantaText.setText(Html.fromHtml(context.getString(R.string.app_description))); TextView happySantaLink = (TextView) happySanta.findViewById(R.id.happySantaLink); happySantaLink.setText(Html.fromHtml("vk.com/<b>happysanta</b>")); happySantaLink.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://vk.com/happysanta")); startActivity(browserIntent); } }); happySanta.setOnClickListener(new View.OnClickListener() { int i = 1; @Override public void onClick(View v) { if (i < 10) i++; else { i = 0; File F = Logs.getFile(); Uri U = Uri.fromFile(F); Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_STREAM, U); startActivity(Intent.createChooser(i, "What should we do with logs?")); } } }); SharedPreferences longpollPreferences = context.getSharedPreferences("longpoll", Context.MODE_MULTI_PROCESS); boolean longpollStatus = longpollPreferences.getBoolean("status", true); /*Bitmap tile = BitmapFactory.decodeResource(context.getResources(), R.drawable.underline); BitmapDrawable tiledBitmapDrawable = new BitmapDrawable(context.getResources(), tile); tiledBitmapDrawable.setTileModeX(Shader.TileMode.REPEAT); //tiledBitmapDrawable.setTileModeY(Shader.TileMode.REPEAT); santaGroundView.setBackgroundDrawable(tiledBitmapDrawable); BitmapDrawable bitmap = new BitmapDrawable(BitmapFactory.decodeResource( getResources(), R.drawable.underline2)); bitmap.setTileModeX(Shader.TileMode.REPEAT); */ LinearLayout layout = (LinearLayout) happySanta.findViewById(R.id.line); Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int width = display.getWidth(); // deprecated for (int i = 0; width % (341 * i + 1) < width; i++) { layout.addView(new ImageView(context) { { setImageResource(R.drawable.underline2); setLayoutParams(new ViewGroup.LayoutParams(341, Helper.convertToDp(4))); setScaleType(ScaleType.CENTER_CROP); } }); } ListView preferencesView = (ListView) rootView.findViewById(R.id.preference); preferencesView.addHeaderView(happySanta, null, false); ArrayList<PreferenceItem> preferences = new ArrayList<PreferenceItem>(); /* preferences.add(new PreferenceItem(getUberfunction(), getUberfunctionDescription()) { @Override public void onClick() { if(UberFunktion.loading) { ProgressDialog dialog = new ProgressDialog(context); dialog.setMessage(context.getString(R.string.durov_function_activating_message)); UberFunktion.putNewDialogWindow(dialog); dialog.show(); return; } AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final AlertDialog selector; View durov = getActivity().getLayoutInflater().inflate(R.layout.durov, null); SharedPreferences durovPreferences = context.getSharedPreferences("durov", Context.MODE_MULTI_PROCESS); boolean updateOnly = durovPreferences.getBoolean("loaded", false); if(updateOnly) ((TextView)durov.findViewById(R.id.description)).setText(R.string.durov_function_activated); if(Memory.users.getById(1)!=null && !updateOnly) { builder.setTitle(R.string.durov_joke_title); ((TextView)durov.findViewById(R.id.description)).setText(R.string.durov_joke_message); ( durov.findViewById(R.id.cat)).setVisibility(View.VISIBLE); builder.setNegativeButton(R.string.durov_joke_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { BugSenseHandler.sendEvent("? ? "); } }); BugSenseHandler.sendEvent("DUROV FRIEND CATCHED!!1"); }else{ builder.setTitle(R.string.durov_start_title); ( durov.findViewById(R.id.photo)).setVisibility(View.VISIBLE); ImageLoader.getInstance().displayImage("http://cs9591.vk.me/v9591001/70/VPSmUR954fQ.jpg",(ImageView) durov.findViewById(R.id.photo)); builder. setPositiveButton(updateOnly ? R.string.durov_start_update : R.string.durov_start_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { BugSenseHandler.sendEvent(" "); ProgressDialog uberfunctionDialog = ProgressDialog.show(getActivity(), context.getString(R.string.durov_function_activating_title), context.getString(R.string.durov_function_activating_message), true, false); UberFunktion.initialize(uberfunctionDialog); } }); builder.setNegativeButton(R.string.durov_start_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { Intent browserIntent = new Intent( Intent.ACTION_VIEW, Uri.parse("https://vk.com/id1") ); startActivity(browserIntent); }catch(Exception exp){ AlertDialog.Builder errorShower = new AlertDialog.Builder(getActivity()); if (exp instanceof ActivityNotFoundException) { errorShower.setTitle(R.string.error); errorShower.setMessage(R.string.no_browser); } else { errorShower.setTitle(R.string.error); errorShower.setMessage(R.string.unknown_error); } errorShower.show(); } BugSenseHandler.sendEvent("? ? "); } }); } builder.setView(durov); selector = builder.create(); selector.show(); } }); */ preferences.add(new ToggleablePreferenceItem(getEnableSpy(), null, longpollStatus) { @Override public void onToggle(Boolean isChecked) { longpollToggle(isChecked); } }); preferences.add(new PreferenceItem(getAdvancedSettings()) { @Override public void onClick() { startActivity(new Intent(context, SettingsActivity.class)); } }); preferences.add(new PreferenceItem(getAbout()) { @Override public void onClick() { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final AlertDialog aboutDialog; builder.setTitle(R.string.app_about).setCancelable(true) .setPositiveButton(R.string.app_about_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); View aboutView = getActivity().getLayoutInflater().inflate(R.layout.about, null); TextView aboutDescription = (TextView) aboutView.findViewById(R.id.description); aboutDescription.setText(Html.fromHtml(getResources().getString(R.string.app_about_description))); aboutDescription.setMovementMethod(LinkMovementMethod.getInstance()); aboutView.findViewById(R.id.license).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(context, InfoActivity.class); startActivity(browserIntent); } }); builder.setView(aboutView); aboutDialog = builder.create(); aboutDialog.setCanceledOnTouchOutside(true); aboutDialog.show(); } }); preferencesView.setAdapter(new PreferenceAdapter(context, preferences)); return rootView; }
From source file:org.apache.cordova.SplashScreenInternal.java
/** * Shows the splash screen over the full Activity *///from w w w .java 2 s .c om @SuppressWarnings("deprecation") private void showSplashScreen(final boolean hideAfterDelay) { final int splashscreenTime = preferences.getInteger("SplashScreenDelay", 3000); final int drawableId = preferences.getInteger("SplashDrawableId", 0); // If the splash dialog is showing don't try to show it again if (this.splashDialog != null && splashDialog.isShowing()) { return; } if (drawableId == 0 || (splashscreenTime <= 0 && hideAfterDelay)) { return; } cordova.getActivity().runOnUiThread(new Runnable() { public void run() { // Get reference to display Display display = cordova.getActivity().getWindowManager().getDefaultDisplay(); Context context = webView.getContext(); // Create the layout for the dialog LinearLayout root = new LinearLayout(context); root.setMinimumHeight(display.getHeight()); root.setMinimumWidth(display.getWidth()); root.setOrientation(LinearLayout.VERTICAL); // TODO: Use the background color of the webview's parent instead of using the // preference. root.setBackgroundColor(preferences.getInteger("backgroundColor", Color.BLACK)); root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0F)); root.setBackgroundResource(drawableId); // Create and show the dialog splashDialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar); // check to see if the splash screen should be full screen if ((cordova.getActivity().getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN) { splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } splashDialog.setContentView(root); splashDialog.setCancelable(false); splashDialog.show(); // Set Runnable to remove splash screen just in case if (hideAfterDelay) { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { removeSplashScreen(); } }, splashscreenTime); } } }); }
From source file:com.jwetherell.quick_response_code.EncoderActivity.java
@Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); com.ranorex.android.RanorexAndroidAutomation.Hook(this); // Get text views textoSsid = (TextView) findViewById(R.id.ssid); textoPassword = (TextView) findViewById(R.id.password); descripcion = (TextView) findViewById(R.id.descripcion); icon = (ImageView) findViewById(R.id.icon); //textoCifrado = (TextView) findViewById(R.id.cifrado); settings = getSharedPreferences(MainActivity.PREFS, 0); // if(settings.contains("connected_wifi_5ghz") && settings.getBoolean("connected_wifi_5ghz", false)) // descripcion.setText(""); final ProgressDialog dialog = new ProgressDialog(EncoderActivity.this); dialog.setMessage("Generando Qr..."); dialog.show();// w w w . j a v a 2s. co m dialog.setCancelable(false); try { if (settings.contains("ssid") && settings.contains("password1")) { // Get ssid, psk and encrypted of settings. if (!getIntent().getBooleanExtra("is_5ghz", false)) // Network 2.4 GHz. { cifradoSettings = settings.getString("cifrado", "WPA"); ssidSettings = settings.getString("ssid", ""); pskSettings = settings.getString("password1", ""); if (settings.contains("connected_wifi_5ghz") && !settings.getBoolean("connected_wifi_5ghz", false) || !settings.contains("connected_wifi_5ghz")) { descripcion.setVisibility(View.VISIBLE); } } else // Network 5 GHz. { cifradoSettings = settings.getString("cifrado5ghz", "WPA"); ssidSettings = settings.getString("ssid5ghz", ""); pskSettings = settings.getString("password5ghz", ""); icon.setImageResource(R.drawable.wifiplus120); ((TextView) findViewById(R.id.textView1)).setText("WifiPlus"); if (settings.contains("connected_wifi_5ghz") && settings.getBoolean("connected_wifi_5ghz", false)) { descripcion.setVisibility(View.VISIBLE); } } ssidFull = ssidSettings; pskFull = pskSettings; if (cifradoSettings.contains("WPA")) { cifradoQR = "WPA"; string = "WIFI:T:" + cifradoQR + ";S:" + ssidSettings + ";P:" + pskSettings + ";;"; } else if (cifradoSettings.contains("abierta")) { cifradoQR = "nopass"; string = "WIFI:T:" + cifradoQR + ";S:" + ssidSettings + ";;"; } else if (cifradoSettings.contains("WEP")) { cifradoQR = "WEP"; string = "WIFI:T:" + cifradoQR + ";S:" + ssidSettings + ";P:" + pskSettings + ";;"; } // Update texts textoSsid.setText(ssidSettings); try { if (pskSettings.length() > 39) pskSettings = ellipsis(pskSettings, 39); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if (pskSettings.equalsIgnoreCase("sin password") || pskSettings.equalsIgnoreCase("")) pskSettings = "Sin password"; textoPassword.setText(pskSettings); } } catch (IllegalArgumentException e) { Log.e(TAG, "Could not encode barcode", e); } new AsyncTask<String, Integer, Bitmap>() { @Override protected Bitmap doInBackground(String... params) { QRCodeEncoder qrCodeEncoder = null; // This assumes the view is full screen, which is a good assumption WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); int smallerDimension = width < height ? width : height; smallerDimension = smallerDimension * 7 / 8; try { qrCodeEncoder = new QRCodeEncoder(string, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), smallerDimension); Hashtable hints = new Hashtable(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); QRCodeWriter qrcw = new QRCodeWriter(); BitMatrix matrix = qrcw.encode(string, BarcodeFormat.QR_CODE, width, height, hints); bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); for (int y = 0; y < matrix.getHeight(); y++) { for (int x = 0; x < matrix.getWidth(); x++) { if (!matrix.get(x, y)) bm.setPixel(x, y, Color.WHITE); else bm.setPixel(x, y, Color.BLACK); } } } catch (WriterException we) { we.printStackTrace(); Log.e(TAG, "Could not encode barcode", we); } return bm; } protected void onPostExecute(Bitmap bitmap) { if (bitmap != null) { viewCode = (ImageView) findViewById(R.id.image_view); viewCode.setImageBitmap(bitmap);//bitmap); dialog.dismiss(); } else { Toast.makeText(EncoderActivity.this, "Problema al generar Qr", Toast.LENGTH_LONG).show(); } } }.execute(); if (bm != null) { dialog.dismiss(); } }
From source file:com.sudeep23.lollipoptabs.fixedtab.FixedTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}./*from w w w. ja va 2 s. com*/ */ @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int width = 0; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { Point size = new Point(); display.getSize(size); width = size.x; } else { width = display.getWidth(); // deprecated } textView.setWidth(width / tabCount); return textView; }
From source file:com.appsimobile.appsii.module.weather.WeatherActivity.java
Bitmap loadBitmapBlocking(String woeid, boolean isDay, int conditionCode) { File[] files = mWeatherUtils.getCityPhotos(WeatherActivity.this, woeid); Bitmap bitmap;/*from w w w .j a v a 2 s. c om*/ if (files != null) { int N = files.length; Random random = new Random(); int idx = random.nextInt(N); File file = files[idx]; WindowManager windowManager = mWindowManager; Display defaultDisplay = windowManager.getDefaultDisplay(); int dimen = Math.max(defaultDisplay.getWidth(), defaultDisplay.getHeight()); bitmap = mBitmapUtils.decodeSampledBitmapFromFile(file, dimen, dimen); return bitmap; } int resId = ImageDownloadHelper.getFallbackDrawableForConditionCode(isDay, conditionCode); return BitmapFactory.decodeResource(getResources(), resId); }
From source file:io.github.dector.rkpi.views.AppViewPager.java
/** * Load, scale and setup background image * * @param context activity context/*from w w w . j a v a 2s. c o m*/ */ private void initBackground(Context context) { Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); Point displaySize = new Point(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { display.getSize(displaySize); } else { displaySize.set(display.getWidth(), display.getHeight()); } BitmapFactory.Options decodeOptions = new BitmapFactory.Options(); decodeOptions.inJustDecodeBounds = true; BitmapFactory.decodeResource(context.getResources(), R.drawable.background); decodeOptions.inJustDecodeBounds = false; decodeOptions.inSampleSize = DeviceTools.getSampleSize(decodeOptions, displaySize); Bitmap sourceBackground = BitmapFactory.decodeResource(context.getResources(), R.drawable.background, decodeOptions); Bitmap background = Bitmap.createScaledBitmap(sourceBackground, displaySize.x, displaySize.y, true); Drawable bitmapDrawable = new BitmapDrawable(context.getResources(), background); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { setBackground(bitmapDrawable); } else { setBackgroundDrawable(bitmapDrawable); } sourceBackground.recycle(); }
From source file:com.duckduckgo.mobile.android.views.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}./*from ww w . j a va2 s .co m*/ */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.TOP | Gravity.CENTER); textView.setTextAppearance(context, R.style.TabTitle); textView.setHeight((int) getResources().getDimension(R.dimen.actionbar_tab_height2)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); int halfPadding = (int) (padding * 0.5); //textView.setPadding(padding, padding, padding, padding); textView.setPadding(padding, halfPadding, padding, padding); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); int width; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { Point size = new Point(); display.getSize(size); width = size.x; } else { width = display.getWidth(); } if (width > getResources().getDimension(R.dimen.tab_small) || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { textView.setWidth(width / mViewPager.getAdapter().getCount()); } return textView; }
From source file:android.support.v7.view.menu.MenuPopupHelper.java
/** * Creates the popup and assigns cached properties. * * @return an initialized popup//from w w w .jav a2s.c o m */ @NonNull private MenuPopup createPopup() { final WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); final Display display = windowManager.getDefaultDisplay(); final Point displaySize = new Point(); if (Build.VERSION.SDK_INT >= 17) { display.getRealSize(displaySize); } else if (Build.VERSION.SDK_INT >= 13) { display.getSize(displaySize); } else { displaySize.set(display.getWidth(), display.getHeight()); } final int smallestWidth = Math.min(displaySize.x, displaySize.y); final int minSmallestWidthCascading = mContext.getResources() .getDimensionPixelSize(R.dimen.abc_cascading_menus_min_smallest_width); final boolean enableCascadingSubmenus = smallestWidth >= minSmallestWidthCascading; final MenuPopup popup; if (enableCascadingSubmenus) { popup = new CascadingMenuPopup(mContext, mAnchorView, mPopupStyleAttr, mPopupStyleRes, mOverflowOnly); } else { popup = new StandardMenuPopup(mContext, mMenu, mAnchorView, mPopupStyleAttr, mPopupStyleRes, mOverflowOnly); } // Assign immutable properties. popup.addMenu(mMenu); popup.setOnDismissListener(mInternalOnDismissListener); // Assign mutable properties. These may be reassigned later. popup.setAnchorView(mAnchorView); popup.setCallback(mPresenterCallback); popup.setForceShowIcon(mForceShowIcon); popup.setGravity(mDropDownGravity); return popup; }
From source file:com.echlabsw.android.drawertab.MainActivity.java
@TargetApi(13) @SuppressWarnings("deprecation") private int getDisplayPxWidth() { Display display = getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT >= 13) { Point size = new Point(); display.getSize(size);//from w ww. j a va 2 s.c o m return size.x; } else { return display.getWidth(); } }
From source file:com.dsdar.thosearoundme.util.MemberAddContactsListFragment.java
@SuppressLint("NewApi") public static int getWidth(Context mContext) { int width = 0; WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (Build.VERSION.SDK_INT > 12) { Point size = new Point(); display.getSize(size);/*from www . ja v a 2 s. com*/ width = size.x; } else { width = display.getWidth(); // Deprecated } return width; }