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.euphor.paperpad.GcmBroadcastReceiver.java

/**
* Sends the registration ID to your server over HTTP, so it can use GCM/HTTP
* or CCS to send messages to your app. Not needed for this demo since the
* device sends upstream messages to a server that echoes back the message
* using the 'from' address in the message.
 * @param regId //from  w w w  .  j  a v a2  s  .  com
*/
private void sendRegistrationIdToBackend(Context context, String regId) {
    int id_menu = MainActivity.params.getId();
    String application_unique_identifier = Installation.id(context);
    String application_version = "0.2.8";
    try {
        application_version = context.getPackageManager().getPackageInfo(context.getPackageName(),
                0).versionName;
    } catch (NameNotFoundException e) {

        e.printStackTrace();
    }
    ;

    String device_type = "";
    if (MainActivity.isTablet) {
        device_type = "tablet";
    } else {
        device_type = "smartphone";
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {

        display.getSize(size);
    } else {
        size.x = display.getWidth(); // deprecated
        size.y = display.getHeight();
    }

    String device_screen_resolution = size.x + "x" + size.y;

    ArrayList<AppHit> hits = new ArrayList<AppHit>();
    AppSession appSession = new AppSession(id_menu, MainActivity.prod_or_sand, "sales",
            application_unique_identifier, application_version, regId, Build.MANUFACTURER, Build.MODEL,
            "android", device_screen_resolution, 5, Build.VERSION.SDK_INT + "", device_type, "",
            System.currentTimeMillis() / 1000, System.currentTimeMillis() / 1000, hits);
    ArrayList<AppSession> appSessions = new ArrayList<AppSession>();
    appSessions.add(appSession);
    AppJsonWriter appJsonWriter = new AppJsonWriter();
    String str = appJsonWriter.writeJson(appSessions);
    String endpoint = SERVER_URL;
    String body = str;
    int status = 0;
    try {
        status = AppJsonWriter.post(endpoint, body);
    } catch (IOException e) {
        Log.e("GcmBroadcastReceiver", "request couldn't be sent " + status);
        e.printStackTrace();
    }
}

From source file:arun.com.chromer.webheads.ui.views.Trashy.java

/**
 * Returns an instance of this view. If the view is not initialized, then a new view is created
 * and returned.//  w  w w. ja v  a 2s .  co  m
 * The returned view might not have been laid out yet.
 *
 * @param context
 * @return
 */
public synchronized static Trashy get(@NonNull Context context) {
    if (INSTANCE != null)
        return INSTANCE;
    else {
        Timber.d("Creating new instance of remove web head");
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        INSTANCE = new Trashy(context, windowManager);
        return INSTANCE;
    }
}

From source file:com.andremion.floatingnavigationview.FloatingNavigationView.java

public FloatingNavigationView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setImageResource(R.drawable.ic_menu_vector);

    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    mNavigationView = (NavigationView) LayoutInflater.from(context).inflate(R.layout.navigation_view, null);
    mNavigationView.setOnTouchListener(mNavigationTouchListener);
    mNavigationMenuView = (NavigationMenuView) mNavigationView.findViewById(R.id.design_navigation_view);

    mFabView = (ImageView) mNavigationView.findViewById(R.id.fab_view);
    mFabView.setOnClickListener(mFabClickListener);
    mFabView.setContentDescription(getContentDescription());
    mFabView.bringToFront();//from  www .j  a va 2 s  .c o  m

    // Custom attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MenuView, defStyleAttr,
            R.style.Widget_Design_NavigationView);
    if (a.hasValue(R.styleable.MenuView_menu)) {
        mNavigationView.inflateMenu(a.getResourceId(R.styleable.MenuView_menu, 0));
    }
    if (a.hasValue(R.styleable.MenuView_headerLayout)) {
        mNavigationView.inflateHeaderView(a.getResourceId(R.styleable.MenuView_headerLayout, 0));
    }
    mDrawMenuBelowFab = a.getBoolean(R.styleable.MenuView_drawMenuBelowFab, false);
    a.recycle();
}

From source file:de.akquinet.android.androlog.reporter.Report.java

/**
 * Adds the device data to the report./*from   w  w  w . ja  va 2 s  .c  om*/
 * @param context 
 * @throws JSONException if the device data cannot be added
 */
private void buildDeviceData(Context context) throws JSONException {
    device = new JSONObject();
    device.put("device", Build.DEVICE);
    device.put("brand", Build.BRAND);

    Object windowService = context.getSystemService(Context.WINDOW_SERVICE);
    if (windowService instanceof WindowManager) {
        Display display = ((WindowManager) windowService).getDefaultDisplay();
        device.put("resolution", display.getWidth() + "x" + display.getHeight());
        device.put("orientation", display.getOrientation());
    }
    device.put("display", Build.DISPLAY);
    device.put("manufacturer", Build.MANUFACTURER);
    device.put("model", Build.MODEL);
    device.put("product", Build.PRODUCT);
    device.put("build.type", Build.TYPE);
    device.put("android.version", Build.VERSION.SDK_INT);
}

From source file:com.dunrite.xpaper.utility.Utils.java

/**
 * Gets device's screen resoluton height
 *
 * @param context current context/*from   w ww . j av a2 s  . c o m*/
 * @return height value
 * //TODO: get actual value, if possible
 */
public static int getDeviceResHeight(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);
    int density = metrics.densityDpi;
    Log.d("DEVICE HEIGHT", "" + (density / 160) * metrics.heightPixels);
    return (density / 160) * metrics.heightPixels;
}

From source file:com.happysanta.vkspy.Fragments.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    context = getActivity();// w  ww.  j ava 2 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:android.percent.support.PercentLayoutHelper.java

private void getScreenSize() {
    WindowManager wm = (WindowManager) mHost.getContext().getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);
    mWidthScreen = outMetrics.widthPixels;
    mHeightScreen = outMetrics.heightPixels;
}

From source file:org.xwalk.embedding.asynctest.v6.XWalkViewTestAsync.java

@SmallTest
public void testSetInitialScale2() throws Throwable {

    WindowManager wm = (WindowManager) getInstrumentation().getTargetContext()
            .getSystemService(Context.WINDOW_SERVICE);
    Point screenSize = new Point();
    wm.getDefaultDisplay().getSize(screenSize);
    // Make sure after 50% scale, page width still larger than screen.
    int height = screenSize.y * 2 + 1;
    int width = screenSize.x * 2 + 1;
    final String page = "<html><body>" + "<p style='height:" + height + "px;width:" + width + "px'>"
            + "testSetInitialScale</p></body></html>";
    final float defaultScaleFactor = 0;
    final float defaultScale = 0.5f;
    final float scaleFactor = 0.25f;

    assertEquals(defaultScaleFactor, getScaleFactor(), .01f);
    loadDataSync(null, page, "text/html", false);
    assertEquals(scaleFactor, getScaleFactor(), .01f);

    int onScaleChangedCallCount = mTestHelperBridge.getOnScaleChangedHelper().getCallCount();
    setInitialScale(60);//ww w  . j  a v  a 2s  .  c  o  m
    loadDataSync(null, page, "text/html", false);
    mTestHelperBridge.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount);
    assertEquals(0.6f, getPixelScale(), .01f);

    onScaleChangedCallCount = mTestHelperBridge.getOnScaleChangedHelper().getCallCount();
    setInitialScale(500);
    loadDataSync(null, page, "text/html", false);
    mTestHelperBridge.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount);
    assertEquals(5.0f, getPixelScale(), .01f);

    onScaleChangedCallCount = mTestHelperBridge.getOnScaleChangedHelper().getCallCount();
    // default min-scale will be used.
    setInitialScale(0);
    loadDataSync(null, page, "text/html", false);
    mTestHelperBridge.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount);
    assertEquals(defaultScale, getPixelScale(), .01f);
}

From source file:com.android.leanlauncher.LauncherAppState.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
static DynamicGrid createDynamicGrid(Context context, DynamicGrid dynamicGrid) {
    // Determine the dynamic grid properties
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point realSize = new Point();
    display.getRealSize(realSize);/*ww  w  .  j a  va 2  s. c  o  m*/
    DisplayMetrics dm = new DisplayMetrics();
    display.getMetrics(dm);

    if (dynamicGrid == null) {
        Point smallestSize = new Point();
        Point largestSize = new Point();
        display.getCurrentSizeRange(smallestSize, largestSize);

        dynamicGrid = new DynamicGrid(context, context.getResources(), Math.min(smallestSize.x, smallestSize.y),
                Math.min(largestSize.x, largestSize.y), realSize.x, realSize.y, dm.widthPixels,
                dm.heightPixels);
    }

    // Update the icon size
    DeviceProfile grid = dynamicGrid.getDeviceProfile();
    grid.updateFromConfiguration(context, context.getResources(), realSize.x, realSize.y, dm.widthPixels,
            dm.heightPixels);
    return dynamicGrid;
}

From source file:com.cleveroad.audiowidget.AudioWidget.java

@SuppressWarnings("deprecation")
private AudioWidget(@NonNull Builder builder) {
    this.context = builder.context.getApplicationContext();
    this.vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    this.handler = new Handler();
    this.screenSize = new Point();
    this.removeBounds = new RectF();
    this.hiddenRemWidPos = new Point();
    this.visibleRemWidPos = new Point();
    this.controller = newController();
    this.windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getSize(screenSize);
    screenSize.y -= statusBarHeight() + navigationBarHeight();

    Configuration configuration = prepareConfiguration(builder);
    playPauseButton = new PlayPauseButton(configuration);
    expandCollapseWidget = new ExpandCollapseWidget(configuration);
    removeWidgetView = new RemoveWidgetView(configuration);
    int offsetCollapsed = context.getResources().getDimensionPixelOffset(R.dimen.aw_edge_offset_collapsed);
    int offsetExpanded = context.getResources().getDimensionPixelOffset(R.dimen.aw_edge_offset_expanded);
    playPauseButtonManager = new TouchManager(playPauseButton,
            playPauseButton.newBoundsChecker(
                    builder.edgeOffsetXCollapsedSet ? builder.edgeOffsetXCollapsed : offsetCollapsed,
                    builder.edgeOffsetYCollapsedSet ? builder.edgeOffsetYCollapsed : offsetCollapsed))
                            .screenWidth(screenSize.x).screenHeight(screenSize.y);
    expandedWidgetManager = new TouchManager(expandCollapseWidget,
            expandCollapseWidget.newBoundsChecker(
                    builder.edgeOffsetXExpandedSet ? builder.edgeOffsetXExpanded : offsetExpanded,
                    builder.edgeOffsetYExpandedSet ? builder.edgeOffsetYExpanded : offsetExpanded))
                            .screenWidth(screenSize.x).screenHeight(screenSize.y);

    playPauseButtonManager.callback(new PlayPauseButtonCallback());
    expandedWidgetManager.callback(new ExpandCollapseWidgetCallback());
    expandCollapseWidget.onWidgetStateChangedListener(new OnWidgetStateChangedListener() {
        @Override//from   w  ww. java 2  s.  co m
        public void onWidgetStateChanged(@NonNull State state) {
            if (state == State.COLLAPSED) {
                playPauseButton.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
                try {
                    windowManager.removeView(expandCollapseWidget);
                } catch (IllegalArgumentException e) {
                    // view not attached to window
                }
                playPauseButton.enableProgressChanges(true);
            }
            if (onWidgetStateChangedListener != null) {
                onWidgetStateChangedListener.onWidgetStateChanged(state);
            }
        }

        @Override
        public void onWidgetPositionChanged(int cx, int cy) {

        }
    });
    onControlsClickListener = new OnControlsClickListenerWrapper();
    expandCollapseWidget.onControlsClickListener(onControlsClickListener);
    ppbToExpBoundsChecker = playPauseButton.newBoundsChecker(
            builder.edgeOffsetXExpandedSet ? builder.edgeOffsetXExpanded : offsetExpanded,
            builder.edgeOffsetYExpandedSet ? builder.edgeOffsetYExpanded : offsetExpanded);
    expToPpbBoundsChecker = expandCollapseWidget.newBoundsChecker(
            builder.edgeOffsetXCollapsedSet ? builder.edgeOffsetXCollapsed : offsetCollapsed,
            builder.edgeOffsetYCollapsedSet ? builder.edgeOffsetYCollapsed : offsetCollapsed);
}