Example usage for android.app UiModeManager getCurrentModeType

List of usage examples for android.app UiModeManager getCurrentModeType

Introduction

In this page you can find the example usage for android.app UiModeManager getCurrentModeType.

Prototype

public int getCurrentModeType() 

Source Link

Document

Return the current running mode type.

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.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.Notification.java

public void showVersionUpNOtification(RemoteMessage remoteMessage) {

    //https://play.google.com/store/apps/details?id=org.uoyabause.android

    Intent googlePlayIntent = new Intent(Intent.ACTION_VIEW);
    googlePlayIntent.setData(Uri.parse("market://details?id=org.uoyabause.android"));
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, googlePlayIntent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon)
            .setContentTitle("new uoYabause is available")
            .setContentText(remoteMessage.getNotification().getBody()).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent).setAutoCancel(false)
            //.setPriority(android.app.Notification.PRIORITY_MAX)
            .addAction(android.R.drawable.ic_media_play, "Install", pendingIntent);
    android.app.Notification notification = null;
    UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
    if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
        Resources r = getResources();
        Bitmap image = BitmapFactory.decodeResource(r, R.drawable.banner);
        mBuilder.setCategory(android.app.Notification.CATEGORY_RECOMMENDATION).setLargeIcon(image)
                .setLocalOnly(true).setOngoing(true);
        notification = new NotificationCompat.BigPictureStyle(mBuilder).build();
    } else {//w w  w.j  a v a2 s .  c o  m
        notification = mBuilder.build();
    }

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notification);
}

From source file:com.google.android.apps.santatracker.games.SplashActivity.java

private boolean isRunningOnTV() {
    UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
    return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}

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

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);

    Log.d(TAG, "From: " + remoteMessage.getFrom());
    Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());

    Map<String, String> val = remoteMessage.getData();

    PackageManager pm = this.getPackageManager();
    String sentversion = null;//from  ww  w . java  2 s  . c om
    int CurrentVersion = -1;
    try {
        PackageInfo packageInfo = pm.getPackageInfo(this.getPackageName(), 0);
        CurrentVersion = packageInfo.versionCode;
    } catch (Exception e) {

    }
    sentversion = val.get("version");

    // Version up Information
    if (sentversion != null) {

        if (Integer.parseInt(sentversion) != CurrentVersion) {
            showVersionUpNOtification(remoteMessage);
        }
        return;
    }

    Intent intent = new Intent(this, GameSelectActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon)
            .setContentTitle("uoYabause").setContentText(remoteMessage.getNotification().getBody())
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);
    android.app.Notification notification = null;
    UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
    if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
        Resources r = getResources();
        Bitmap image = BitmapFactory.decodeResource(r, R.drawable.banner);
        mBuilder.setCategory("recommendation").setLargeIcon(image).setLocalOnly(true)
                .setCategory(android.app.Notification.CATEGORY_RECOMMENDATION).setOngoing(true);
        notification = new NotificationCompat.BigPictureStyle(mBuilder).build();
    } else {
        notification = mBuilder.build();
    }

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notification);

}

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";
    }/*  w ww .ja  va 2  s .com*/

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

From source file:com.vuze.android.remote.AndroidUtils.java

public static boolean isTV() {
    if (isTV == null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
            Context context = VuzeRemoteApp.getContext();
            UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
            isTV = uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
            if (!isTV) {
                // alternate check
                isTV = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEVISION)
                        || context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)
                        || context.getPackageManager().hasSystemFeature("android.software.leanback_only");
                if (isTV && DEBUG) {
                    Log.d(TAG, "isTV: not UI_MODE_TYPE_TELEVISION, however is has system "
                            + "feature suggesting tv");
                }//from ww  w  .j a  va 2s  .c o  m

                if (!isTV) {
                    String[] names = context.getPackageManager().getSystemSharedLibraryNames();
                    for (String name : names) {
                        if (name.startsWith("com.google.android.tv")) {
                            isTV = true;
                            if (DEBUG) {
                                Log.d(TAG, "isTV: found tv shared library. Assuming tv");
                            }
                            break;
                        }
                    }
                }
            }
        } else {
            isTV = false;
        }
    }

    return isTV;
}

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

public void initialiseVillageViews(int viewHeight, int viewWidth) {
    mViewHeight = viewHeight;/*from  w ww .ja va  2  s. com*/
    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: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();//  w w w  .j av a 2  s. c om
    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();
    }
}