Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Commit

Permalink
Frameworks: Add new configuration qualifier for UI change on the fly …
Browse files Browse the repository at this point in the history
…(1/3)

last night I got an idea after 5 weeks of breaking stuff and
doing to much complicated things. Together with mnazim we tried
today to realize this idea. So another absolut new unique SlimBean
feature is born.

The aim we wanted at the end was to give a simple and resource friendly
way to change the complete UI of a rom on the fly. So why not use
the great fallback mechanism of AOSP and change/add a new
qualifier into the AOSP core. To explain how it works.....if you want
to add a new UI just add in /res folder of any app or framework you want
folders with the qualifier "inverted". Eg. drawable-inverted-xhdpi
or values-inverted or layout-port-inverted or whatever you want. Put in
only the files you want to modify thats it.

All qualifier in AOSP are following strict rules. You can read here.
Do not forget the order of qualifier is important. The new "inverted"
qualifier we added to the UIMode qualifier. To get more information
about read here

http://developer.android.com/guide/topics/resources/providing-resources.html

So what this commit does:

- add new qualifier "inverted"
- support for API level 13 and higher
- change the custom UI on the fly
- control default UI Mode over config.xml
- working for all apps. They just need to include folders
  with the new qualifier name
- resource friendly....no resource wasting either programmticaly
  then source blow, because you just need to put in the files you
  want to change
- cause of the qualifier structure compatible with every phone,
  language or whatever qualifier you want to use on top
- 100% compatible to theme manager. If a theme misses drawables
  they are replaced with them from the current UIMode which is set.

What is the benefit why not use just a theme? We started half year
ago TRDS which was inverted gapps system base themed....means we
morphed directly the changes into the framework. This methoed was
on of the reasons why trds got so popular. Points for that are easy
first the system is themed, means each theme you activate over
theme engine works on top the themed system. So you have a base
style and can modify more if you want. The other reason is easy
a lot faster and resource friendly. Now this idea went to the
rom to provide two core system based themes and user
can do on top what they want or not without, like you have
to roms in one.

This commit just adds the support for this

cheers

mnazim and kufikugel

Change-Id: I1ef843a42d17246373eb17b4e1ec1aa9bc20d8d4
  • Loading branch information
kufikugel authored and markp-mckinney committed Apr 26, 2013
1 parent 74de02d commit 7afc16d
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 17 deletions.
11 changes: 11 additions & 0 deletions api/13.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64802,6 +64802,17 @@
visibility="public"
>
</field>
<field name="UI_MODE_TYPE_INVERTED"
type="int"
transient="false"
volatile="false"
value="6"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="UI_MODE_TYPE_UNDEFINED"
type="int"
transient="false"
Expand Down
1 change: 1 addition & 0 deletions api/14.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6540,6 +6540,7 @@ package android.content.res {
field public static final int UI_MODE_TYPE_MASK = 15; // 0xf
field public static final int UI_MODE_TYPE_NORMAL = 1; // 0x1
field public static final int UI_MODE_TYPE_TELEVISION = 4; // 0x4
field public static final int UI_MODE_TYPE_INVERTED = 6; // 0x6
field public static final int UI_MODE_TYPE_UNDEFINED = 0; // 0x0
field public float fontScale;
field public int hardKeyboardHidden;
Expand Down
1 change: 1 addition & 0 deletions api/15.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6562,6 +6562,7 @@ package android.content.res {
field public static final int UI_MODE_TYPE_MASK = 15; // 0xf
field public static final int UI_MODE_TYPE_NORMAL = 1; // 0x1
field public static final int UI_MODE_TYPE_TELEVISION = 4; // 0x4
field public static final int UI_MODE_TYPE_INVERTED = 6; // 0x6
field public static final int UI_MODE_TYPE_UNDEFINED = 0; // 0x0
field public float fontScale;
field public int hardKeyboardHidden;
Expand Down
1 change: 1 addition & 0 deletions api/16.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6828,6 +6828,7 @@ package android.content.res {
field public static final int UI_MODE_TYPE_MASK = 15; // 0xf
field public static final int UI_MODE_TYPE_NORMAL = 1; // 0x1
field public static final int UI_MODE_TYPE_TELEVISION = 4; // 0x4
field public static final int UI_MODE_TYPE_INVERTED = 6; // 0x6
field public static final int UI_MODE_TYPE_UNDEFINED = 0; // 0x0
field public float fontScale;
field public int hardKeyboardHidden;
Expand Down
1 change: 1 addition & 0 deletions api/17.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6978,6 +6978,7 @@ package android.content.res {
field public static final int UI_MODE_TYPE_MASK = 15; // 0xf
field public static final int UI_MODE_TYPE_NORMAL = 1; // 0x1
field public static final int UI_MODE_TYPE_TELEVISION = 4; // 0x4
field public static final int UI_MODE_TYPE_INVERTED = 6; // 0x6
field public static final int UI_MODE_TYPE_UNDEFINED = 0; // 0x0
field public int densityDpi;
field public float fontScale;
Expand Down
1 change: 1 addition & 0 deletions api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6978,6 +6978,7 @@ package android.content.res {
field public static final int UI_MODE_TYPE_MASK = 15; // 0xf
field public static final int UI_MODE_TYPE_NORMAL = 1; // 0x1
field public static final int UI_MODE_TYPE_TELEVISION = 4; // 0x4
field public static final int UI_MODE_TYPE_INVERTED = 6; // 0x6
field public static final int UI_MODE_TYPE_UNDEFINED = 0; // 0x0
field public int densityDpi;
field public float fontScale;
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/app/UiModeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ public void disableCarMode(int flags) {
* {@link Configuration#UI_MODE_TYPE_NORMAL Configuration.UI_MODE_TYPE_NORMAL},
* {@link Configuration#UI_MODE_TYPE_DESK Configuration.UI_MODE_TYPE_DESK}, or
* {@link Configuration#UI_MODE_TYPE_CAR Configuration.UI_MODE_TYPE_CAR}, or
* {@link Configuration#UI_MODE_TYPE_TELEVISION Configuration.UI_MODE_TYPE_APPLIANCE}.
* {@link Configuration#UI_MODE_TYPE_TELEVISION Configuration.UI_MODE_TYPE_APPLIANCE}, or
* {@link Configuration#UI_MODE_TYPE_INVERTED Configuration.UI_MODE_TYPE_INVERTED}.
*/
public int getCurrentModeType() {
if (mService != null) {
Expand Down
10 changes: 8 additions & 2 deletions core/java/android/content/res/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ public boolean isLayoutSizeAtLeast(int size) {
* <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">appliance</a>
* resource qualifier. */
public static final int UI_MODE_TYPE_APPLIANCE = 0x05;
/** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
* value that corresponds to the
* inverted framework
* resource qualifier. */
public static final int UI_MODE_TYPE_INVERTED = 0x06;

/** Constant for {@link #uiMode}: bits that encode the night mode. */
public static final int UI_MODE_NIGHT_MASK = 0x30;
Expand All @@ -485,8 +490,8 @@ public boolean isLayoutSizeAtLeast(int size) {
* <p>The {@link #UI_MODE_TYPE_MASK} bits define the overall ui mode of the
* device. They may be one of {@link #UI_MODE_TYPE_UNDEFINED},
* {@link #UI_MODE_TYPE_NORMAL}, {@link #UI_MODE_TYPE_DESK},
* {@link #UI_MODE_TYPE_CAR}, {@link #UI_MODE_TYPE_TELEVISION}, or
* {@link #UI_MODE_TYPE_APPLIANCE}.
* {@link #UI_MODE_TYPE_CAR}, {@link #UI_MODE_TYPE_TELEVISION},
* {@link #UI_MODE_TYPE_APPLIANCE}, or {@link #UI_MODE_TYPE_INVERTED}
*
* <p>The {@link #UI_MODE_NIGHT_MASK} defines whether the screen
* is in a special mode. They may be one of {@link #UI_MODE_NIGHT_UNDEFINED},
Expand Down Expand Up @@ -725,6 +730,7 @@ public String toString() {
case UI_MODE_TYPE_CAR: sb.append(" car"); break;
case UI_MODE_TYPE_TELEVISION: sb.append(" television"); break;
case UI_MODE_TYPE_APPLIANCE: sb.append(" appliance"); break;
case UI_MODE_TYPE_INVERTED: sb.append(" inverted"); break;
default: sb.append(" uimode="); sb.append(uiMode&UI_MODE_TYPE_MASK); break;
}
switch ((uiMode&UI_MODE_NIGHT_MASK)) {
Expand Down
16 changes: 16 additions & 0 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -5716,6 +5716,20 @@ public static boolean putFloatForUser(ContentResolver cr, String name, float val
*/
public static final String UI_NIGHT_MODE = "ui_night_mode";

/**
* Whether user activated inverted UI mode or default UI mode. Owned
* and controlled by UiModeManagerService.
* @hide
*/
public static final String UI_INVERTED_MODE = "ui_inverted_mode";

/**
* force UI mode change for methods which are not observing
* UiModeManagerService
* @hide
*/
public static final String UI_MODE_IS_TOGGLED = "ui_mode_is_toggled";

/**
* Whether screensavers are enabled.
* @hide
Expand Down Expand Up @@ -5792,6 +5806,8 @@ public static boolean putFloatForUser(ContentResolver cr, String name, float val
MOUNT_UMS_PROMPT,
MOUNT_UMS_NOTIFY_ENABLED,
UI_NIGHT_MODE,
UI_INVERTED_MODE,
UI_MODE_IS_TOGGLED,
LOCK_SCREEN_OWNER_INFO,
LOCK_SCREEN_OWNER_INFO_ENABLED
};
Expand Down
7 changes: 7 additions & 0 deletions core/res/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,16 @@
1 UI_MODE_TYPE_NORMAL
4 UI_MODE_TYPE_TELEVISION
5 UI_MODE_TYPE_APPLIANCE
6 UI_MODE_TYPE_INVERTED
Any other values will have surprising consequences. -->
<integer name="config_defaultUiModeType">1</integer>

<!-- Control the alternative UI mode type to use when UI mode is toggled
from framework. One of the following values (See Configuration.java):
1 UI_MODE_TYPE_NORMAL
6 UI_MODE_TYPE_INVERTED -->
<integer name="config_alternativeUiModeType">6</integer>

<!-- Control whether being in the desk dock (and powered) always
keeps the screen on. By default it stays on when plugged in to
AC. 0 will not keep it on; or together 1 to stay on when plugged
Expand Down
1 change: 1 addition & 0 deletions core/res/res/values/symbols.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,7 @@
<java-symbol type="id" name="targets" />
<java-symbol type="integer" name="config_carDockRotation" />
<java-symbol type="integer" name="config_defaultUiModeType" />
<java-symbol type="integer" name="config_alternativeUiModeType" />
<java-symbol type="integer" name="config_deskDockRotation" />
<java-symbol type="integer" name="config_lidKeyboardAccessibility" />
<java-symbol type="integer" name="config_lidNavigationAccessibility" />
Expand Down
1 change: 1 addition & 0 deletions include/androidfw/ResourceTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,7 @@ struct ResTable_config
UI_MODE_TYPE_CAR = ACONFIGURATION_UI_MODE_TYPE_CAR,
UI_MODE_TYPE_TELEVISION = ACONFIGURATION_UI_MODE_TYPE_TELEVISION,
UI_MODE_TYPE_APPLIANCE = ACONFIGURATION_UI_MODE_TYPE_APPLIANCE,
UI_MODE_TYPE_INVERTED = ACONFIGURATION_UI_MODE_TYPE_INVERTED,

// uiMode bits for the night switch.
MASK_UI_MODE_NIGHT = 0x30,
Expand Down
3 changes: 3 additions & 0 deletions libs/androidfw/ResourceTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,9 @@ String8 ResTable_config::toString() const {
case ResTable_config::UI_MODE_TYPE_APPLIANCE:
res.append("appliance");
break;
case ResTable_config::UI_MODE_TYPE_INVERTED:
res.append("inverted");
break;
default:
res.appendFormat("uiModeType=%d",
dtohs(screenLayout&ResTable_config::MASK_UI_MODE_TYPE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public class PhoneStatusBar extends BaseStatusBar {
// settings
QuickSettingsController mQS;
boolean mHasSettingsPanel, mHideSettingsPanel, mHasFlipSettings;
boolean mUiModeIsToggled;
SettingsPanelView mSettingsPanel;
View mFlipSettingsView;
QuickSettingsContainerView mSettingsContainer;
Expand Down Expand Up @@ -564,6 +565,9 @@ public boolean onTouch(View v, MotionEvent event) {
mClearButton.setEnabled(false);
mDateView = (DateView)mStatusBarWindow.findViewById(R.id.date);

mUiModeIsToggled = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.UI_MODE_IS_TOGGLED, 0) == 1;

if (mStatusBarView.hasFullWidthNotifications()) {
mHideSettingsPanel = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.QS_DISABLE_PANEL, 0) == 1;
Expand Down Expand Up @@ -3096,7 +3100,11 @@ public TilesChangedObserver(Handler handler) {
public void onChange(boolean selfChange) {
boolean hideSettingsPanel = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.QS_DISABLE_PANEL, 0) == 1;
if (hideSettingsPanel != mHideSettingsPanel) {
boolean uiModeIsToggled = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.UI_MODE_IS_TOGGLED, 0) == 1;

if (hideSettingsPanel != mHideSettingsPanel
|| uiModeIsToggled != mUiModeIsToggled) {
recreateStatusBar();
}

Expand Down Expand Up @@ -3150,6 +3158,9 @@ public void startObserving() {
Settings.System.getUriFor(Settings.System.QUICK_TILES_TEXT_COLOR),
false, this);

cr.registerContentObserver(
Settings.Secure.getUriFor(Settings.Secure.UI_MODE_IS_TOGGLED),
false, this);
}
}
class SettingsObserver extends ContentObserver {
Expand Down
83 changes: 70 additions & 13 deletions services/java/com/android/server/UiModeManagerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
import android.app.StatusBarManager;
import android.app.UiModeManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.os.BatteryManager;
import android.os.Binder;
import android.os.Handler;
Expand Down Expand Up @@ -71,14 +73,15 @@ final class UiModeManagerService extends IUiModeManager.Stub {
private int mNightMode = UiModeManager.MODE_NIGHT_NO;
private boolean mCarModeEnabled = false;
private boolean mCharging = false;
private final int mDefaultUiModeType;
private final boolean mCarModeKeepsScreenOn;
private final boolean mDeskModeKeepsScreenOn;
private final boolean mTelevision;
private int mDefaultUiModeType;
private boolean mCarModeKeepsScreenOn;
private boolean mDeskModeKeepsScreenOn;
private boolean mTelevision;

private boolean mComputedNightMode;
private int mCurUiMode = 0;
private int mSetUiMode = 0;
private boolean mInitialVarSet;

private boolean mHoldingConfiguration = false;
private Configuration mConfiguration = new Configuration();
Expand All @@ -89,8 +92,8 @@ final class UiModeManagerService extends IUiModeManager.Stub {

private StatusBarManager mStatusBarManager;

private final PowerManager mPowerManager;
private final PowerManager.WakeLock mWakeLock;
private PowerManager mPowerManager;
private PowerManager.WakeLock mWakeLock;

static Intent buildHomeIntent(String category) {
Intent intent = new Intent(Intent.ACTION_MAIN);
Expand Down Expand Up @@ -159,7 +162,29 @@ public void onTwilightStateChanged() {
}
};

private final class SettingsObserver extends ContentObserver {
SettingsObserver(Handler handler) {
super(handler);
}

void observe() {
ContentResolver resolver = mContext.getContentResolver();
resolver.registerContentObserver(Settings.Secure.getUriFor(
Settings.Secure.UI_INVERTED_MODE),
false, this);
}

@Override
public void onChange(boolean selfChange) {
updateUiMode();
mUiContext = null;
updateLocked(0, 0);
forceUiModeChangeForNonObservingMethods();
}
}

public UiModeManagerService(Context context, TwilightService twilight) {
mInitialVarSet = true;
mContext = context;
mTwilightService = twilight;

Expand All @@ -172,24 +197,47 @@ public UiModeManagerService(Context context, TwilightService twilight) {

ThemeUtils.registerThemeChangeReceiver(mContext, mThemeChangeReceiver);

mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
mTwilightService.registerListener(mTwilightListener, mHandler);

// Register settings observer and set initial preferences
SettingsObserver settingsObserver = new SettingsObserver(new Handler());
settingsObserver.observe();

mPowerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG);

mConfiguration.setToDefaults();

mDefaultUiModeType = context.getResources().getInteger(
com.android.internal.R.integer.config_defaultUiModeType);
mCarModeKeepsScreenOn = (context.getResources().getInteger(
updateUiMode();

mCarModeKeepsScreenOn = (mContext.getResources().getInteger(
com.android.internal.R.integer.config_carDockKeepsScreenOn) == 1);
mDeskModeKeepsScreenOn = (context.getResources().getInteger(
mDeskModeKeepsScreenOn = (mContext.getResources().getInteger(
com.android.internal.R.integer.config_deskDockKeepsScreenOn) == 1);
mTelevision = context.getPackageManager().hasSystemFeature(
mTelevision = mContext.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_TELEVISION);

mNightMode = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.UI_NIGHT_MODE, UiModeManager.MODE_NIGHT_AUTO);

mTwilightService.registerListener(mTwilightListener, mHandler);
}

private void updateUiMode() {
if (Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.UI_INVERTED_MODE, 0) == 1) {
mDefaultUiModeType = mContext.getResources().getInteger(
com.android.internal.R.integer.config_alternativeUiModeType);
} else {
mDefaultUiModeType = mContext.getResources().getInteger(
com.android.internal.R.integer.config_defaultUiModeType);
}

if (mInitialVarSet && mDefaultUiModeType != Configuration.UI_MODE_TYPE_NORMAL) {
mUiContext = null;
updateLocked(0, 0);
forceUiModeChangeForNonObservingMethods();
}
mInitialVarSet = false;
}

@Override // Binder call
Expand Down Expand Up @@ -309,6 +357,15 @@ private static boolean isDeskDockState(int state) {
}
}

private void forceUiModeChangeForNonObservingMethods() {
final boolean toggleUiMode = Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.UI_MODE_IS_TOGGLED, 0) == 1;
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.UI_MODE_IS_TOGGLED,
toggleUiMode ? 0 : 1);
}

private void updateConfigurationLocked() {
int uiMode = mTelevision ? Configuration.UI_MODE_TYPE_TELEVISION : mDefaultUiModeType;
if (mCarModeEnabled) {
Expand Down
5 changes: 5 additions & 0 deletions tools/aapt/AaptAssets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,11 @@ bool AaptGroupEntry::getUiModeTypeName(const char* name,
(out->uiMode&~ResTable_config::MASK_UI_MODE_TYPE)
| ResTable_config::UI_MODE_TYPE_APPLIANCE;
return true;
} else if (strcmp(name, "inverted") == 0) {
if (out) out->uiMode =
(out->uiMode&~ResTable_config::MASK_UI_MODE_TYPE)
| ResTable_config::UI_MODE_TYPE_INVERTED;
return true;
}

return false;
Expand Down

0 comments on commit 7afc16d

Please sign in to comment.