Example usage for android.content Context WINDOW_SERVICE

List of usage examples for android.content Context WINDOW_SERVICE

Introduction

In this page you can find the example usage for android.content Context WINDOW_SERVICE.

Prototype

String WINDOW_SERVICE

To view the source code for android.content Context WINDOW_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.view.WindowManager for accessing the system's window manager.

Usage

From source file:com.example.sdave.footballscore.SlidingTabs.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.jav a 2  s  . c  om
 */
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);

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / 3);

    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);

    return textView;
}

From source file:com.dtd.thevyshka.Utils.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)}.// ww  w .  j a  va 2  s.c  o m
 */
@SuppressLint("NewApi")
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / mTabCount);

    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(12);//TODO adapting to all
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setTextColor(ContextCompat.getColor(context, R.color.white));

    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 / 2, padding, padding / 2, padding);

    return textView;
}

From source file:com.scm.reader.livescanner.sdk.recognizers.KooabaRecognizer.java

private Bitmap fixRotation(Bitmap img) throws IOException {
    //get WINDOW_SERVICE
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

    if (isDebugLog()) {
        logDebug("Display orientation is " + display.getOrientation());
    }//from w  w  w.j av  a 2 s . c o m

    Matrix m = new Matrix();

    int angle = 0;

    //TODO: refactor
    if (img.getWidth() > img.getHeight()) {
        if (display.getOrientation() == ROTATION_0) {
            angle = 90;
        } else if (display.getOrientation() == ROTATION_270) {
            angle = 180;
        }
    } else {
        if (display.getOrientation() == ROTATION_90) {
            angle = -90;
        } else if (display.getOrientation() == ROTATION_270) {
            angle = 90;
        }
    }

    if (isDebugLog()) {
        logDebug("Preview image will be rotated by " + angle + " degrees");
    }

    m.postRotate(angle);
    return Bitmap.createBitmap(img, 0, 0, img.getWidth(), img.getHeight(), m, true);
}

From source file:com.facebook.android.friendsmash.GameFragment.java

@SuppressWarnings({ "deprecation" })
@TargetApi(13)//w  w  w  .j ava  2  s  . c  o  m
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_game, parent, false);

    gameFrame = (FrameLayout) v.findViewById(R.id.gameFrame);
    progressContainer = (FrameLayout) v.findViewById(R.id.progressContainer);
    smashPlayerNameTextView = (TextView) v.findViewById(R.id.smashPlayerNameTextView);
    scoreTextView = (TextView) v.findViewById(R.id.scoreTextView);
    livesContainer = (LinearLayout) v.findViewById(R.id.livesContainer);

    // Set the progressContainer as invisible by default
    progressContainer.setVisibility(View.INVISIBLE);

    // Set the icon width (for the images to be smashed)
    setIconWidth(getResources().getDimensionPixelSize(R.dimen.icon_width));

    // Set the screen dimensions
    WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= 13) {
        Point size = new Point();
        display.getSize(size);
        setScreenWidth(size.x);
        setScreenHeight(size.y);
    } else {
        setScreenWidth(display.getWidth());
        setScreenHeight(display.getHeight());
    }

    // Always keep the Action Bar hidden
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        getActivity().getActionBar().hide();
    }

    // Instantiate the fireImageTask for future fired images
    fireImageTask = new Runnable() {
        public void run() {
            spawnImage(false);
        }
    };

    // Refresh the score board
    setScore(getScore());

    // Refresh the lives
    setLives(getLives());

    // Note: Images will start firing in the onResume method below

    return v;
}

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  .  ja va2s  .  c  om
 */
@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.cloverstudio.spika.SpikaApp.java

/**
 * Sets sliding transport based on screen density and required offset width
 * <p>/*from  w  w  w.  j  ava  2s .  c o  m*/
 * Depends on width of side offset in dp
 * 
 * @param sideWidthInDp
 */
public static void setTransportBasedOnScreenDensity(int sideWidthInDp) {
    WindowManager wm = (WindowManager) sInstance.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);

    double sideWidthInPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sideWidthInDp,
            sInstance.getResources().getDisplayMetrics());

    double transportRate = 1 - sideWidthInPx / metrics.widthPixels;
    sInstance.mTransport = (int) Math.floor(metrics.widthPixels * transportRate);
}

From source file:com.jimish.material.sample.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)}./*w ww.  j  a v a2 s  .c o  m*/
 */
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);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    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();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / 3);

    return textView;
}

From source file:client.smrtms.com.smrtms_client.View.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   w  w  w.jav a2s. c o m
 */
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();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / 3);

    return textView;
}

From source file:com.fisheradelakin.ribbit.utils.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 w w  w .j  a va 2  s  .  c  o m
 */
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);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    // fit tabs to width of screen
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / 2); // change number by how many tabs i have

    return textView;
}

From source file:com.example.fabian.matchit.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)}.//  w w w.j  ava 2 s.  co  m
 */
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);
    textView.setTextColor(getResources().getColor(R.color.white));

    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);
    // Text evenredig verdelen
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / 3);

    return textView;
}