本文整理匯總了Java中android.app.UiModeManager類的典型用法代碼示例。如果您正苦於以下問題:Java UiModeManager類的具體用法?Java UiModeManager怎麽用?Java UiModeManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
UiModeManager類屬於android.app包,在下文中一共展示了UiModeManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onSharedPreferenceChanged
import android.app.UiModeManager; //導入依賴的package包/類
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
if (s.equals("nightmode_use")) {
boolean night = sharedPreferences.getBoolean("nightmode_use", false);
int startH = sharedPreferences.getInt("nightmode_use_start", AnotherRSS.Config.DEFAULT_NIGHT_START);
int stopH = sharedPreferences.getInt("nightmode_use_stop", AnotherRSS.Config.DEFAULT_NIGHT_STOP);
if (night && AnotherRSS.inTimeSpan(startH, stopH)) {
umm.setNightMode(UiModeManager.MODE_NIGHT_YES);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
umm.setNightMode(UiModeManager.MODE_NIGHT_NO);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
getActivity().recreate();
}
}
}
示例2: getDeviceType
import android.app.UiModeManager; //導入依賴的package包/類
/**
* Returns true when running Android TV
*
* @param c Context to detect UI Mode.
* @return true when device is running in tv mode, false otherwise.
*/
public static String getDeviceType(Context c) {
UiModeManager uiModeManager = (UiModeManager) c.getSystemService(Context.UI_MODE_SERVICE);
int modeType = uiModeManager.getCurrentModeType();
switch (modeType){
case Configuration.UI_MODE_TYPE_TELEVISION:
return "TELEVISION";
case Configuration.UI_MODE_TYPE_WATCH:
return "WATCH";
case Configuration.UI_MODE_TYPE_NORMAL:
String type = isTablet(c) ? "TABLET" : "PHONE";
return type;
case Configuration.UI_MODE_TYPE_UNDEFINED:
return "UNKOWN";
default:
return "";
}
}
示例3: mapNightModeToYesNo
import android.app.UiModeManager; //導入依賴的package包/類
private int mapNightModeToYesNo(int mode) {
switch (mode) {
case -1:
switch (((UiModeManager) this.mContext.getSystemService("uimode")).getNightMode()) {
case 0:
return 0;
case 2:
return 2;
default:
return 1;
}
case 0:
if (getTwilightManager().isNight()) {
return 2;
}
return 1;
case 2:
return 2;
default:
return 1;
}
}
示例4: setupNightModeSwitch
import android.app.UiModeManager; //導入依賴的package包/類
private void setupNightModeSwitch() {
// 設置夜間模式
uiManager = (UiModeManager) getActivity().getSystemService(Context.UI_MODE_SERVICE);
nightModeSwitch = (SwitchPreference) getPreferenceManager().findPreference("night_mode_switch");
nightModeSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean nextNightMode = !PreferenceHelper.isNightModeEnabled();
if (nextNightMode) {
uiManager.setNightMode(UiModeManager.MODE_NIGHT_YES);
} else {
uiManager.setNightMode(UiModeManager.MODE_NIGHT_NO);
}
return true;
}
});
}
示例5: mapNightModeToYesNo
import android.app.UiModeManager; //導入依賴的package包/類
@BinaryNightMode
private int mapNightModeToYesNo(@NightMode final int mode) {
switch (mode) {
case MODE_NIGHT_AUTO:
return getTwilightManager().isNight() ? MODE_NIGHT_YES : MODE_NIGHT_NO;
case MODE_NIGHT_FOLLOW_SYSTEM:
final UiModeManager uiModeManager = (UiModeManager)
mContext.getSystemService(Context.UI_MODE_SERVICE);
switch (uiModeManager.getNightMode()) {
case UiModeManager.MODE_NIGHT_YES:
return MODE_NIGHT_YES;
case UiModeManager.MODE_NIGHT_AUTO:
return MODE_NIGHT_AUTO;
case UiModeManager.MODE_NIGHT_NO:
default:
return MODE_NIGHT_NO;
}
case MODE_NIGHT_YES:
return MODE_NIGHT_YES;
case MODE_NIGHT_NO:
default:
return MODE_NIGHT_NO;
}
}
示例6: onSharedPreferenceChanged
import android.app.UiModeManager; //導入依賴的package包/類
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
if (s.equals("nightmode_use")) {
boolean night = sharedPreferences.getBoolean("nightmode_use", false);
int startH = sharedPreferences.getInt("nightmode_use_start", ViboraApp.Config.DEFAULT_NIGHT_START);
int stopH = sharedPreferences.getInt("nightmode_use_stop", ViboraApp.Config.DEFAULT_NIGHT_STOP);
if (night && ViboraApp.inTimeSpan(startH, stopH)) {
umm.setNightMode(UiModeManager.MODE_NIGHT_YES);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
umm.setNightMode(UiModeManager.MODE_NIGHT_NO);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
getActivity().recreate();
}
}
}
示例7: onCreate
import android.app.UiModeManager; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogHelper.d(TAG, "onCreate");
Intent newIntent;
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
LogHelper.d(TAG, "Running on a TV Device");
newIntent = new Intent(this, TvPlaybackActivity.class);
} else {
LogHelper.d(TAG, "Running on a non-TV Device");
newIntent = new Intent(this, MusicPlayerActivity.class);
}
startActivity(newIntent);
finish();
}
示例8: SoundWaveWallpaperEngine
import android.app.UiModeManager; //導入依賴的package包/類
public SoundWaveWallpaperEngine() {
// Enable automatic NightMode switch
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
uiModeManager.setNightMode(UiModeManager.MODE_NIGHT_AUTO);
Paint wavePaint = new Paint();
wavePaint.setColor(waveColor);
wavePaint.setAlpha(150);
// Define all three waves
wave1 = new Wave(wavePaint, 50, 15, timePerValue);
wave2 = new Wave(wavePaint, 35, 20, timePerValue);
wave3 = new Wave(wavePaint, 25, 25, timePerValue);
handler.post(drawRunner);
}
示例9: onCreate
import android.app.UiModeManager; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate");
Intent newIntent;
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
Log.d(TAG, "Running on a TV Device");
// TODO: add launch Android TV "Now Playing" activity
// newIntent = new Intent(this, TvNowPlayingActivity.class);
throw new UnsupportedOperationException("Android TV is not yet supported");
} else {
Log.d(TAG, "Running on a non-TV Device");
newIntent = new Intent(this, MusicPlayerActivity.class);
}
startActivity(newIntent);
finish();
}
示例10: notifyNewRootView
import android.app.UiModeManager; //導入依賴的package包/類
public static void notifyNewRootView(Activity activity)
{
View rootView = activity.findViewById(android.R.id.content);
UiModeManager modeMgr = (UiModeManager) activity.getSystemService(Context.UI_MODE_SERVICE);
if (modeMgr.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION)
{
// Increase view padding on TVs
float scale = activity.getResources().getDisplayMetrics().density;
int verticalPaddingPixels = (int) (TV_VERTICAL_PADDING_DP*scale + 0.5f);
int horizontalPaddingPixels = (int) (TV_HORIZONTAL_PADDING_DP*scale + 0.5f);
rootView.setPadding(horizontalPaddingPixels, verticalPaddingPixels,
horizontalPaddingPixels, verticalPaddingPixels);
}
}
示例11: onResume
import android.app.UiModeManager; //導入依賴的package包/類
@Override
protected void onResume() {
Log.d(AnotherRSS.TAG, "onResume");
AnotherRSS.withGui = true;
new DbExpunge().execute();
SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean night = mPreferences.getBoolean("nightmode_use", false);
if (night) {
int startH = mPreferences.getInt("nightmode_use_start", AnotherRSS.Config.DEFAULT_NIGHT_START);
int stopH = mPreferences.getInt("nightmode_use_stop", AnotherRSS.Config.DEFAULT_NIGHT_STOP);
if (AnotherRSS.inTimeSpan(startH, stopH) && umm.getNightMode() != UiModeManager.MODE_NIGHT_YES) {
umm.setNightMode(UiModeManager.MODE_NIGHT_YES);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}
if (!AnotherRSS.inTimeSpan(startH, stopH) && umm.getNightMode() != UiModeManager.MODE_NIGHT_NO) {
umm.setNightMode(UiModeManager.MODE_NIGHT_NO);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
} else {
if (umm.getNightMode() == UiModeManager.MODE_NIGHT_YES) {
umm.setNightMode(UiModeManager.MODE_NIGHT_NO);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
super.onResume();
}
示例12: onCreate
import android.app.UiModeManager; //導入依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
// 創建Activity時設置夜間模式
uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
if (PreferenceHelper.isNightModeEnabled()) {
uiManager.setNightMode(UiModeManager.MODE_NIGHT_YES);
}
super.onCreate(savedInstanceState);
}
示例13: isRunningOnOUYA
import android.app.UiModeManager; //導入依賴的package包/類
public boolean isRunningOnOUYA() {
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo("tv.ouya", 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
return (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) || Globals.OuyaEmulation;
}
示例14: isAndroidTV
import android.app.UiModeManager; //導入依賴的package包/類
public boolean isAndroidTV() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
} else {
return false;
}
}
示例15: onCreate
import android.app.UiModeManager; //導入依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
uiManager.setNightMode(UiModeManager.MODE_NIGHT_AUTO);
}