Example usage for android.content Context UI_MODE_SERVICE

List of usage examples for android.content Context UI_MODE_SERVICE

Introduction

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

Prototype

String UI_MODE_SERVICE

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

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.UiModeManager for controlling UI modes.

Usage

From source file:Main.java

public static boolean isTV(Context context) {
    UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
    return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}

From source file:Main.java

public static boolean isTv(Context context) {

    final UiModeManager manager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);

    return manager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}

From source file:com.keylesspalace.tusky.util.ThemeUtils.java

public static void setAppNightMode(String flavor, Context context) {
    int mode;//from   w  w  w.  j  a va2s.c  o  m
    switch (flavor) {
    default:
    case THEME_NIGHT:
        mode = UiModeManager.MODE_NIGHT_YES;
        break;
    case THEME_DAY:
        mode = UiModeManager.MODE_NIGHT_NO;
        break;
    case THEME_BLACK:
        mode = UiModeManager.MODE_NIGHT_YES;
        break;
    case THEME_AUTO:
        mode = UiModeManager.MODE_NIGHT_AUTO;
        break;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        UiModeManager uiModeManager = (UiModeManager) context.getApplicationContext()
                .getSystemService(Context.UI_MODE_SERVICE);
        uiModeManager.setNightMode(mode);
    } else {
        AppCompatDelegate.setDefaultNightMode(mode);
    }

}

From source file:com.grarak.kerneladiutor.utils.Utils.java

public static boolean isTv(Context context) {
    return ((UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE))
            .getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}

From source file:com.google.android.apps.santatracker.village.Village.java

public void initialiseVillageViews(int viewHeight, int viewWidth) {
    mViewHeight = viewHeight;/*  www  . j ava2 s .  c  o  m*/
    int maxDimension = viewHeight > viewWidth ? viewHeight : viewWidth;
    Resources resources = getResources();
    if (!mImagesInitialised) {
        UiModeManager mgr = (UiModeManager) getActivity().getApplicationContext()
                .getSystemService(Context.UI_MODE_SERVICE);
        if (Configuration.UI_MODE_TYPE_WATCH == mgr.getCurrentModeType()) {
            int referenceHeight = resources.getInteger(R.integer.wear_referenceHeight);

            mImageSkyDay = new StretchedFullWidthImage(R.drawable.sky_day,
                    resources.getInteger(R.integer.wear_skyReferenceHeight),
                    resources.getInteger(R.integer.wear_skyStart));
            mImageSkyNight = new StretchedFullWidthImage(R.drawable.sky_night,
                    resources.getInteger(R.integer.wear_skyReferenceHeight),
                    resources.getInteger(R.integer.wear_skyStart));
            mImageUfo = new HorizontalScrollingImage(R.drawable.ufo, referenceHeight,
                    resources.getInteger(R.integer.wear_ufoVerticalOffset), false,
                    resources.getInteger(R.integer.wear_ufoPercentagePerSecond));
            mImageSun = new SimpleImage(R.drawable.sun, resources.getInteger(R.integer.wear_sunReferenceHeight),
                    resources.getInteger(R.integer.wear_sunVerticalOffset),
                    resources.getInteger(R.integer.wear_sunHorizontalOffset));
            mImageMoon = new SimpleImage(R.drawable.moon,
                    resources.getInteger(R.integer.wear_sunReferenceHeight),
                    resources.getInteger(R.integer.wear_moonVerticalOffset),
                    resources.getInteger(R.integer.wear_moonHorizontalOffset));
            mImagePlane = new HorizontalScrollingImage(R.drawable.plane, referenceHeight,
                    resources.getInteger(R.integer.wear_planeVerticalOffset), true,
                    resources.getInteger(R.integer.wear_planePercentagePerSecond));

            mImageClouds = new HorizontalScrollingImageGroup(R.drawable.cloud,
                    resources.getInteger(R.integer.wear_numClouds),
                    resources.getInteger(R.integer.wear_sunVerticalOffset),
                    resources.getInteger(R.integer.wear_cloudsEnd), getParallax(R.integer.wear_cloudsParallax),
                    referenceHeight);
            mImageMountainsDay = loadImage(R.array.wear_mountainsDayIds, referenceHeight,
                    R.integer.wear_mountainsStart, R.integer.wear_mountainsParallax, R.integer.wear_med_res);
            mImageMountainsNight = loadImage(R.array.wear_mountainsNightIds, referenceHeight,
                    R.integer.wear_mountainsStart, R.integer.wear_mountainsParallax, R.integer.wear_med_res);
            mPaintMountainsDay = new SolidPaint(getString(R.color.colorMountainsDay),
                    resources.getInteger(R.integer.wear_mountainsPaintStart),
                    resources.getInteger(R.integer.wear_mountainsEnd), referenceHeight);
            mPaintMountainsNight = new SolidPaint(getString(R.color.colorMountainsNight),
                    resources.getInteger(R.integer.wear_mountainsPaintStart),
                    resources.getInteger(R.integer.wear_mountainsEnd), referenceHeight);

            mImageMonoRail = new HorizontalScrollingImage(R.drawable.monorail, referenceHeight,
                    resources.getInteger(R.integer.wear_monorailStart), false,
                    resources.getInteger(R.integer.wear_monorailPercentagePerSecond));
            mImageRail = new HorizontallyRepeatingImage(R.drawable.rail, referenceHeight,
                    resources.getInteger(R.integer.wear_railStart), getParallax(R.integer.wear_railParallax));

            mImageVillage = loadImage(R.array.wear_villageIds, referenceHeight, R.integer.wear_villageStart,
                    R.integer.wear_villageParallax, R.integer.wear_high_res);
            mImageSnow = loadImage(R.array.wear_snowIds, referenceHeight, R.integer.wear_snowStart,
                    R.integer.wear_snowParallax, R.integer.wear_low_res);
            mPaintSnow = new SolidPaint(getString(R.color.colorSnow),
                    resources.getInteger(R.integer.wear_snowPaintStart),
                    resources.getInteger(R.integer.wear_snowEnd), referenceHeight);

            mOffsetVertical = -1 * resources.getInteger(R.integer.wear_verticalOffset);
        } else {
            int referenceHeight = resources.getInteger(R.integer.referenceHeight);

            mImageSkyDay = new StretchedFullWidthImage(R.drawable.sky_day,
                    resources.getInteger(R.integer.skyReferenceHeight),
                    resources.getInteger(R.integer.skyStart));
            mImageSkyNight = new StretchedFullWidthImage(R.drawable.sky_night,
                    resources.getInteger(R.integer.skyReferenceHeight),
                    resources.getInteger(R.integer.skyStart));
            mImageUfo = new HorizontalScrollingImage(R.drawable.ufo, referenceHeight,
                    resources.getInteger(R.integer.ufoVerticalOffset), false,
                    resources.getInteger(R.integer.ufoPercentagePerSecond));
            mImageSun = new SimpleImage(R.drawable.sun, resources.getInteger(R.integer.sunReferenceHeight),
                    resources.getInteger(R.integer.sunVerticalOffset),
                    resources.getInteger(R.integer.sunHorizontalOffset));
            mImageMoon = new SimpleImage(R.drawable.moon, resources.getInteger(R.integer.sunReferenceHeight),
                    resources.getInteger(R.integer.moonVerticalOffset),
                    resources.getInteger(R.integer.moonHorizontalOffset));
            mImagePlane = new HorizontalScrollingImage(R.drawable.plane, referenceHeight,
                    resources.getInteger(R.integer.planeVerticalOffset), true,
                    resources.getInteger(R.integer.wear_planePercentagePerSecond));

            mImageClouds = new HorizontalScrollingImageGroup(R.drawable.cloud,
                    resources.getInteger(R.integer.numClouds),
                    resources.getInteger(R.integer.sunVerticalOffset),
                    resources.getInteger(R.integer.cloudsEnd), getParallax(R.integer.cloudsParallax),
                    referenceHeight);
            mImageMountainsDay = loadImage(R.array.mountainsDayIds, referenceHeight, R.integer.mountainsStart,
                    R.integer.mountainsParallax, R.integer.med_res);
            mImageMountainsNight = loadImage(R.array.mountainsNightIds, referenceHeight,
                    R.integer.mountainsStart, R.integer.mountainsParallax, R.integer.med_res);
            mPaintMountainsDay = new SolidPaint(getString(R.color.colorMountainsDay),
                    resources.getInteger(R.integer.mountainsPaintStart),
                    resources.getInteger(R.integer.mountainsEnd), referenceHeight);
            mPaintMountainsNight = new SolidPaint(getString(R.color.colorMountainsNight),
                    resources.getInteger(R.integer.mountainsPaintStart),
                    resources.getInteger(R.integer.mountainsEnd), referenceHeight);

            mImageMonoRail = new HorizontalScrollingImage(R.drawable.monorail, referenceHeight,
                    resources.getInteger(R.integer.monorailStart), false,
                    resources.getInteger(R.integer.wear_monorailPercentagePerSecond));
            mImageRail = new HorizontallyRepeatingImage(R.drawable.rail, referenceHeight,
                    resources.getInteger(R.integer.railStart), getParallax(R.integer.railParallax));

            mImageVillage = loadImage(R.array.villageIds, referenceHeight, R.integer.villageStart,
                    R.integer.villageParallax, R.integer.high_res);
            mImageSnow = loadImage(R.array.snowIds, referenceHeight, R.integer.snowStart,
                    R.integer.snowParallax, R.integer.low_res);
            mPaintSnow = new SolidPaint(getString(R.color.colorSnow),
                    resources.getInteger(R.integer.snowPaintStart), resources.getInteger(R.integer.snowEnd),
                    referenceHeight);
        }

        mImageSkyDay.loadImages(resources);
        mImageSkyNight.loadImages(resources);
        mImageUfo.loadImages(resources);
        mImageSun.loadImages(resources);
        mImageMoon.loadImages(resources);
        mImagePlane.loadImages(resources);

        mImageClouds.loadImages(resources);
        mImageMountainsDay.loadImages(resources);
        mImageMountainsNight.loadImages(resources);

        mImageMonoRail.loadImages(resources);
        mImageRail.loadImages(resources);

        mImageVillage.loadImages(resources);
        mImageSnow.loadImages(getResources());

        mImagesInitialised = true;

        setIsDay(initialiseSunMoon(), false);
    }

    // Set easter egg state to empty
    for (int i = 0; i < EGG_COUNT; i++) {
        mEasterEggTracker[i] = false;
    }
    mImageUfo.setAlpha(ImageWithAlphaAndSize.INVISIBLE);

    mMaxOffsetHorizontalVillage = mImageVillage.geTotalWidthScaled(viewHeight) / 2;
    int percentPerSecond = getResources().getInteger(R.integer.scrollPercentagePerSecond);
    mScrollPerSecond = (float) (percentPerSecond) / 100f * maxDimension;
}

From source file:com.philliphsu.bottomsheetpickers.Utils.java

public static boolean isTv(Context context) {
    UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
    return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}

From source file:org.uoyabause.android.YabauseHandler.java

/** Called when the activity is first created. */
@Override//from  w w  w  .j a  v  a 2 s.co  m
public void onCreate(Bundle savedInstanceState) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(Yabause.this);
    boolean lock_landscape = sharedPref.getBoolean("pref_landscape", false);
    if (lock_landscape == true) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    }

    super.onCreate(savedInstanceState);
    System.gc();

    YabauseApplication application = (YabauseApplication) getApplication();
    mTracker = application.getDefaultTracker();

    setContentView(R.layout.main);
    getWindow().setSustainedPerformanceMode(true);
    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_FULLSCREEN);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);
    if (sharedPref.getBoolean("pref_analog_pad", false) == true) {
        mNavigationView.setCheckedItem(R.id.pad_mode);
    }

    DrawerLayout.DrawerListener drawerListener = new DrawerLayout.DrawerListener() {
        @Override
        public void onDrawerSlide(View view, float v) {

        }

        @Override
        public void onDrawerOpened(View view) {
            if (menu_showing == false) {
                menu_showing = true;
                YabauseRunnable.pause();
                audio.mute(audio.SYSTEM);
                String name = YabauseRunnable.getGameTitle();
                TextView tx = (TextView) findViewById(R.id.menu_title);
                if (tx != null) {
                    tx.setText(name);
                }

                if (adView != null) {
                    LinearLayout lp = (LinearLayout) findViewById(R.id.navilayer);
                    if (lp != null) {
                        final int mCount = lp.getChildCount();
                        boolean find = false;
                        for (int i = 0; i < mCount; ++i) {
                            final View mChild = lp.getChildAt(i);
                            if (mChild == adView) {
                                find = true;
                            }
                        }
                        if (find == false) {
                            lp.addView(adView);
                        }
                        AdRequest adRequest = new AdRequest.Builder()
                                .addTestDevice("303A789B146C169D4BDB5652D928FF8E").build();
                        adView.loadAd(adRequest);
                    }
                }

            }
        }

        @Override
        public void onDrawerClosed(View view) {

            if (waiting_reault == false && menu_showing == true) {
                menu_showing = false;
                YabauseRunnable.resume();
                audio.unmute(audio.SYSTEM);
            }

        }

        @Override
        public void onDrawerStateChanged(int i) {
        }
    };
    this.mDrawerLayout.setDrawerListener(drawerListener);

    audio = new YabauseAudio(this);

    Intent intent = getIntent();
    String game = intent.getStringExtra("org.uoyabause.android.FileName");
    if (game != null && game.length() > 0) {
        YabauseStorage storage = YabauseStorage.getStorage();
        gamepath = storage.getGamePath(game);
    } else
        gamepath = "";

    String exgame = intent.getStringExtra("org.uoyabause.android.FileNameEx");
    if (exgame != null) {
        gamepath = exgame;
    }

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    readPreferences();

    padm = PadManager.getPadManager();
    padm.loadSettings();
    waiting_reault = false;

    handler = new YabauseHandler(this);
    yabauseThread = new YabauseRunnable(this);

    UiModeManager uiModeManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
    if (uiModeManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_TELEVISION) {
        SharedPreferences prefs = getSharedPreferences("private", Context.MODE_PRIVATE);
        Boolean hasDonated = prefs.getBoolean("donated", false);
        if (hasDonated) {
            adView = null;
        } else {
            adView = new AdView(this);
            adView.setAdUnitId(getString(R.string.banner_ad_unit_id2));
            adView.setAdSize(AdSize.BANNER);
            AdRequest adRequest = new AdRequest.Builder().build();
            adView.loadAd(adRequest);
            adView.setAdListener(new AdListener() {
                @Override
                public void onAdOpened() {
                    // Save app state before going to the ad overlay.
                }
            });
        }
    } else {
        adView = null;
    }

}

From source file:org.gluu.com.ox_push2.u2f.v2.SoftwareDevice.java

private String getDeviceType() {
    UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);

    int modeType = uiModeManager.getCurrentModeType();
    switch (modeType) {
    case Configuration.UI_MODE_TYPE_NORMAL:
        return "normal";
    case Configuration.UI_MODE_TYPE_DESK:
        return "desk";
    case Configuration.UI_MODE_TYPE_CAR:
        return "car";
    case Configuration.UI_MODE_TYPE_TELEVISION:
        return "television";
    case Configuration.UI_MODE_TYPE_APPLIANCE:
        return "appliance";
    case Configuration.UI_MODE_TYPE_WATCH:
        return "watch";
    }/*  ww w . j a v a2 s  .  co m*/

    // Cover unknown UI types
    return Integer.toString(modeType);
}

From source file:org.uoyabause.android.tv.GameSelectFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    Log.i(TAG, "onCreate");
    super.onActivityCreated(savedInstanceState);

    mFirebaseAnalytics = FirebaseAnalytics.getInstance(getActivity());

    YabauseApplication application = (YabauseApplication) getActivity().getApplication();
    mTracker = application.getDefaultTracker();

    prepareBackgroundManager();//from w  ww. j a va 2 s. co  m
    setupUIElements();
    setupEventListeners();

    if (mRowsAdapter == null) {
        mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
        HeaderItem gridHeader = new HeaderItem(0, "PREFERENCES");
        GridItemPresenter mGridPresenter = new GridItemPresenter();
        ArrayObjectAdapter gridRowAdapter = new ArrayObjectAdapter(mGridPresenter);
        gridRowAdapter.add(getResources().getString(R.string.setting));

        UiModeManager uiModeManager = (UiModeManager) getActivity().getSystemService(Context.UI_MODE_SERVICE);
        if (uiModeManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_TELEVISION) {
            //    gridRowAdapter.add(getResources().getString(R.string.invite));
        }
        gridRowAdapter.add(getResources().getString(R.string.donation));
        gridRowAdapter.add(getString(R.string.load_game));
        gridRowAdapter.add(getResources().getString(R.string.refresh_db));
        //gridRowAdapter.add("GoogleDrive");

        mRowsAdapter.add(new ListRow(gridHeader, gridRowAdapter));
        setAdapter(mRowsAdapter);
    }

    MobileAds.initialize(application, getActivity().getString(R.string.ad_app_id));
    mInterstitialAd = new InterstitialAd(getActivity());
    mInterstitialAd.setAdUnitId(getActivity().getString(R.string.banner_ad_unit_id));
    requestNewInterstitial();

    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            requestNewInterstitial();
        }
    });

    myHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case 0:
                mUpdateThread = null;
                loadRows();
                dismissDialog();
                break;
            default:
                break;
            }
        }
    };

    if (checkStoragePermission() == 0) {
        updateBackGraound();
        updateGameList();
    }
}

From source file:org.uoyabause.android.tv.GameSelectFragment.java

private void loadRows() {

    if (!isAdded())
        return;//  w  w  w.  j a  v  a 2 s .c o m

    int addindex = 0;
    mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());

    //-----------------------------------------------------------------
    // Recent Play Game
    List<GameInfo> rlist = null;
    try {
        rlist = new Select().from(GameInfo.class).orderBy("lastplay_date DESC").limit(5).execute();
    } catch (Exception e) {
        System.out.println(e);
    }

    HeaderItem recentHeader = new HeaderItem(addindex, "RECENT");
    Iterator<GameInfo> itx = rlist.iterator();
    CardPresenter cardPresenter_recent = new CardPresenter();
    ArrayObjectAdapter listRowAdapter_recent = new ArrayObjectAdapter(cardPresenter_recent);
    boolean hit = false;
    while (itx.hasNext()) {
        GameInfo game = itx.next();
        listRowAdapter_recent.add(game);
        hit = true;
    }

    //----------------------------------------------------------------------
    // Refernce
    if (hit) {
        mRowsAdapter.add(new ListRow(recentHeader, listRowAdapter_recent));
        addindex++;
    }

    HeaderItem gridHeader = new HeaderItem(addindex, "PREFERENCES");
    GridItemPresenter mGridPresenter = new GridItemPresenter();
    ArrayObjectAdapter gridRowAdapter = new ArrayObjectAdapter(mGridPresenter);
    gridRowAdapter.add(getResources().getString(R.string.setting));

    UiModeManager uiModeManager = (UiModeManager) getActivity().getSystemService(Context.UI_MODE_SERVICE);
    if (uiModeManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_TELEVISION) {
        //    gridRowAdapter.add(getResources().getString(R.string.invite));
    }
    gridRowAdapter.add(getResources().getString(R.string.donation));
    gridRowAdapter.add(getString(R.string.load_game));
    gridRowAdapter.add(getResources().getString(R.string.refresh_db));
    //gridRowAdapter.add("GoogleDrive");

    mRowsAdapter.add(new ListRow(gridHeader, gridRowAdapter));
    addindex++;

    //-----------------------------------------------------------------
    //
    List<GameInfo> list = null;
    try {
        list = new Select().from(GameInfo.class).orderBy("game_title ASC").execute();
    } catch (Exception e) {
        System.out.println(e);
    }

    //        itx = list.iterator();
    //        while(itx.hasNext()){
    //            GameInfo game = itx.next();
    //            Log.d("GameSelect",game.game_title + ":" + game.file_path + ":" + game.iso_file_path );
    //        }

    int i;
    for (i = 0; i < alphabet.length; i++) {

        hit = false;
        CardPresenter cardPresenter = new CardPresenter();
        ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
        Iterator<GameInfo> it = list.iterator();
        while (it.hasNext()) {
            GameInfo game = it.next();
            if (game.game_title.toUpperCase().indexOf(alphabet[i]) == 0) {
                listRowAdapter.add(game);
                Log.d("GameSelect", alphabet[i] + ":" + game.game_title);
                it.remove();
                hit = true;
            }
        }

        if (hit) {
            HeaderItem header = new HeaderItem(addindex, alphabet[i]);
            mRowsAdapter.add(new ListRow(header, listRowAdapter));
            addindex++;
        }
    }

    CardPresenter cardPresenter = new CardPresenter();
    ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
    Iterator<GameInfo> it = list.iterator();
    while (it.hasNext()) {
        GameInfo game = it.next();
        Log.d("GameSelect", "Others:" + game.game_title);
        listRowAdapter.add(game);
    }
    HeaderItem header = new HeaderItem(addindex, "Others");
    mRowsAdapter.add(new ListRow(header, listRowAdapter));
    addindex++;

    setAdapter(mRowsAdapter);

}