Skip to content

Commit

Permalink
ThemeTile: Custom QS detail header title support for theming apps
Browse files Browse the repository at this point in the history
Show the app label when applying theme as a per-app overlay. This
interface can be used on any tile as well.

Change-Id: I10ce256a80c6cda04a87d3d6852d4b190a43e8d5
  • Loading branch information
bigrushdog committed Apr 25, 2016
1 parent 23a8365 commit 205d15e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
7 changes: 4 additions & 3 deletions packages/SystemUI/res/values/du_strings.xml
Expand Up @@ -140,9 +140,10 @@

<!-- Themes QS Tile -->
<string name="quick_settings_themes">Themes</string>
<string name="quick_settings_themes_icon_packs">Icon packs</string>
<string name="quick_settings_themes_app_theme">App theme</string>
<string name="quick_settings_themes_system_theme">System theme</string>
<string name="quick_settings_themes_icon_packs">Apply icon pack</string>
<string name="quick_settings_themes_app_theme_with_label">Apply theme to <xliff:g id="application">%1$s</xliff:g></string>
<string name="quick_settings_themes_app_theme">Apply theme to app</string>
<string name="quick_settings_themes_system_theme">Apply theme</string>
<string name="quick_settings_themes_default_theme">Default</string>
<string name="quick_settings_themes_match_system">Match system theme</string>

Expand Down
3 changes: 2 additions & 1 deletion packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
Expand Up @@ -43,6 +43,7 @@
import com.android.internal.logging.MetricsLogger;
import com.android.systemui.FontSizeUtils;
import com.android.systemui.R;
import com.android.systemui.qs.QSTile.CustomTitleDetailAdapter;
import com.android.systemui.qs.QSTile.DetailAdapter;
import com.android.systemui.settings.BrightnessController;
import com.android.systemui.settings.ToggleSlider;
Expand Down Expand Up @@ -526,7 +527,7 @@ public void onClick(View v) {
MetricsLogger.visible(mContext, detailAdapter.getMetricsCategory());
announceForAccessibility(mContext.getString(
R.string.accessibility_quick_settings_detail,
mContext.getString(detailAdapter.getTitle())));
QSTile.getDetailAdapterTitle(mContext, detailAdapter)));
setDetailRecord(r);
listener = mHideGridContentWhenDone;
if (r instanceof TileRecord && visibleDiff) {
Expand Down
21 changes: 21 additions & 0 deletions packages/SystemUI/src/com/android/systemui/qs/QSTile.java
Expand Up @@ -53,6 +53,7 @@
* state update pass on tile looper.
*/
public abstract class QSTile<TState extends State> implements Listenable {
public static int USES_CUSTOM_DETAIL_ADAPTER_TITLE = -2;
protected final String TAG = "QSTile." + getClass().getSimpleName();
protected static final boolean DEBUG = Log.isLoggable("QSTile", Log.DEBUG);

Expand Down Expand Up @@ -106,6 +107,26 @@ public interface DetailAdapter {
int getMetricsCategory();
}

/**
*
* Return USES_CUSTOM_DETAIL_ADAPTER_TITLE in parent getTitle() to invoke this method
* This design is a bit "creative" but better than writing an abstract class
* and redesigning half of the tiles
*
*/
public interface CustomTitleDetailAdapter extends DetailAdapter {
String getCustomTitle();
}

public static String getDetailAdapterTitle(Context context, DetailAdapter adapter) {
int res = adapter.getTitle();
if (res == USES_CUSTOM_DETAIL_ADAPTER_TITLE && adapter instanceof CustomTitleDetailAdapter) {
return ((CustomTitleDetailAdapter) adapter).getCustomTitle();
} else {
return context.getString(res);
}
}

// safe to call from any thread

public void setCallback(Callback callback) {
Expand Down
Expand Up @@ -22,6 +22,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.ThemeChangeRequest;
Expand Down Expand Up @@ -56,6 +57,7 @@ private enum Mode {ALL_THEMES, ICON_PACK, APP_THEME}
private final ThemesDetailAdapter mDetailAdapter;
private ThemeManager mService;
private Mode mode;
private String mTopAppLabel;

public ThemesTile(Host host) {
super(host);
Expand Down Expand Up @@ -99,6 +101,7 @@ protected void handleLongClick() {
mode = Mode.ICON_PACK;
} else {
mode = Mode.APP_THEME;
mTopAppLabel = getTopAppLabel(getTopActivity());
}

showDetail(true);
Expand Down Expand Up @@ -129,7 +132,7 @@ public void onFinish(boolean isSuccess) {
}
}

private final class ThemesDetailAdapter implements DetailAdapter,
private final class ThemesDetailAdapter implements CustomTitleDetailAdapter,
AdapterView.OnItemClickListener {

private QSDetailItemsList mItemsList;
Expand All @@ -144,9 +147,21 @@ public int getTitle() {
case ICON_PACK:
return R.string.quick_settings_themes_icon_packs;
case APP_THEME:
return R.string.quick_settings_themes_app_theme;
return USES_CUSTOM_DETAIL_ADAPTER_TITLE;
default:
return -1;
return R.string.quick_settings_themes;
}
}

@Override
public String getCustomTitle() {
switch (mode) {
case APP_THEME:
final String topAppLabel = mTopAppLabel;
return mContext.getString(
R.string.quick_settings_themes_app_theme_with_label, topAppLabel);
default:
return mContext.getString(R.string.quick_settings_themes_app_theme);
}
}

Expand All @@ -172,10 +187,6 @@ private void updateItems() {

if (mItemsList == null) return;

if (isTopActivityLauncher()) {
// Log.d("ThemesTile", "This is launcher");
}

items.clear();

switch (mode) {
Expand Down Expand Up @@ -420,7 +431,6 @@ private List<Item> getAllFilteredPackages(String filter) {
return itemList;

}

}


Expand All @@ -439,6 +449,18 @@ private String getTopApp() {
return getTopActivity().getPackageName();
}

private String getTopAppLabel(ComponentName componentName) {
String label = null;
PackageManager pm = mContext.getPackageManager();
try {
ApplicationInfo info = pm.getApplicationInfo(componentName.getPackageName(), 0);
label = info.loadLabel(pm).toString();
} catch (Exception e) {
label = mContext.getString(R.string.quick_settings_themes_app_theme);
}
return label;
}

private boolean isActivityLauncher(ComponentName componentName) {
Context context = getHost().getContext();

Expand Down
Expand Up @@ -1040,7 +1040,7 @@ private void handleShowingDetail(final QSTile.DetailAdapter detail) {
transition(mQsDetailHeader, showingDetail);
mShowingDetail = showingDetail;
if (showingDetail) {
mQsDetailHeaderTitle.setText(detail.getTitle());
mQsDetailHeaderTitle.setText(QSTile.getDetailAdapterTitle(getContext(), detail));
final Boolean toggleState = detail.getToggleState();
if (toggleState == null) {
mQsDetailHeaderSwitch.setVisibility(INVISIBLE);
Expand Down

0 comments on commit 205d15e

Please sign in to comment.