List of usage examples for android.app UiModeManager getCurrentModeType
public int getCurrentModeType()
From source file:org.uoyabause.android.tv.GameSelectFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //Bundle bundle = data.getExtras(); switch (requestCode) { case SETTING_ACTIVITY: if (resultCode == GAMELIST_NEED_TO_UPDATED) { refresh_level = 3;/*from w w w . java 2 s .c o m*/ if (checkStoragePermission() == 0) { updateGameList(); } } this.updateBackGraound(); break; case YABAUSE_ACTIVITY: SharedPreferences prefs = getActivity().getSharedPreferences("private", Context.MODE_PRIVATE); Boolean hasDonated = prefs.getBoolean("donated", false); if (hasDonated == false) { double rn = Math.random(); if (rn <= 0.5) { UiModeManager uiModeManager = (UiModeManager) getActivity() .getSystemService(Context.UI_MODE_SERVICE); if (uiModeManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_TELEVISION) { if (mInterstitialAd.isLoaded()) { mInterstitialAd.show(); } } } else if (rn > 0.5) { Intent intent = new Intent(getActivity(), DonateActivity.class); startActivity(intent); } } break; default: break; } }
From source file:org.uoyabause.android.tv.GameSelectFragment.java
private void loadRows() { if (!isAdded()) return;//from w ww .j ava 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); }
From source file:org.uoyabause.android.YabauseHandler.java
/** Called when the activity is first created. */ @Override/*from w w w . ja v a 2s .c o 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:github.daneren2005.dsub.activity.SubsonicActivity.java
@Override protected void onCreate(Bundle bundle) { UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE); if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) { // tv = true; }//from w w w .ja v a 2 s .co m PackageManager pm = getPackageManager(); if (!pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) { touchscreen = false; } setUncaughtExceptionHandler(); applyTheme(); applyFullscreen(); super.onCreate(bundle); startService(new Intent(this, DownloadService.class)); setVolumeControlStream(AudioManager.STREAM_MUSIC); if (getIntent().hasExtra(Constants.FRAGMENT_POSITION)) { lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0); } if (preferencesListener == null) { preferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { // When changing drawer settings change visibility switch (key) { case Constants.PREFERENCES_KEY_PODCASTS_ENABLED: setDrawerItemVisible(R.id.drawer_podcasts, false); break; case Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED: setDrawerItemVisible(R.id.drawer_bookmarks, false); break; case Constants.PREFERENCES_KEY_SHARED_ENABLED: setDrawerItemVisible(R.id.drawer_shares, false); break; case Constants.PREFERENCES_KEY_CHAT_ENABLED: setDrawerItemVisible(R.id.drawer_chat, false); break; case Constants.PREFERENCES_KEY_ADMIN_ENABLED: setDrawerItemVisible(R.id.drawer_admin, false); break; } } }; Util.getPreferences(this).registerOnSharedPreferenceChangeListener(preferencesListener); } }
From source file:github.popeen.dsub.activity.SubsonicActivity.java
@Override protected void onCreate(Bundle bundle) { sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE); if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) { // tv = true; }//ww w. j a v a 2 s . c o m PackageManager pm = getPackageManager(); if (!pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) { touchscreen = false; } setUncaughtExceptionHandler(); applyTheme(); applyFullscreen(); super.onCreate(bundle); startService(new Intent(this, DownloadService.class)); setVolumeControlStream(AudioManager.STREAM_MUSIC); if (getIntent().hasExtra(Constants.FRAGMENT_POSITION)) { lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0); } if (preferencesListener == null) { preferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { // When changing drawer settings change visibility switch (key) { case Constants.PREFERENCES_KEY_PODCASTS_ENABLED: setDrawerItemVisible(R.id.drawer_podcasts, false); break; case Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED: setDrawerItemVisible(R.id.drawer_bookmarks, false); break; case Constants.PREFERENCES_KEY_INTERNET_RADIO_ENABLED: setDrawerItemVisible(R.id.drawer_internet_radio_stations, false); break; case Constants.PREFERENCES_KEY_SHARED_ENABLED: setDrawerItemVisible(R.id.drawer_shares, false); break; case Constants.PREFERENCES_KEY_CHAT_ENABLED: setDrawerItemVisible(R.id.drawer_chat, false); break; case Constants.PREFERENCES_KEY_ADMIN_ENABLED: setDrawerItemVisible(R.id.drawer_admin, false); break; } } }; Util.getPreferences(this).registerOnSharedPreferenceChangeListener(preferencesListener); } if (ContextCompat.checkSelfPermission(this, permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } }