Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc268a90 authored by Jorge Ruesga's avatar Jorge Ruesga Committed by Steve Kondik
Browse files

base: Add theme support to Ringtone and Profile pickers activities

Patchset 3: Add support for theme RingtonePreference view. The dialog is
            automatically adjusted to the caller activity base theme.
Patchset 4: Don't break the android api

For Ringtones:

http://review.cyanogenmod.org/#/c/61393/



For Profiles:

Usage:

Intent intent = new Intent(ProfileManager.ACTION_PROFILE_PICKER);
intent.putExtra(ProfileManager.EXTRA_PROFILE_DIALOG_THEME, R.style.CustomDialogTheme); <<< Add your custom dialog theme here
startActivityForResult(intent, 0);

Style Usage:

Define an style that inherits from an android base theme

<style name="CustomDialogThemeDark" parent="@*android:style/Theme.Holo.Dialog.Alert">

or

<style name="CustomDialogThemeLight" parent="@*android:style/Theme.Holo.Light.Dialog.Alert">

or define your own dialog style

Change-Id: Icadbcf2c617c51177466989acdab9435066a47a0
Signed-off-by: default avatarJorge Ruesga <jorge@ruesga.com>
parent e1839eb1
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ public class RingtonePreference extends Preference implements
    private int mRingtoneType;
    private boolean mShowDefault;
    private boolean mShowSilent;
    private int mDialogStyle;
    
    private int mRequestCode;
    private int mSubscriptionID = 0; /* Sub-1 by default */
@@ -62,6 +63,8 @@ public class RingtonePreference extends Preference implements
                true);
        mShowSilent = a.getBoolean(com.android.internal.R.styleable.RingtonePreference_showSilent,
                true);
        mDialogStyle = a.getResourceId(
                com.android.internal.R.styleable.RingtonePreference_dialogStyle, 0);
        a.recycle();
    }

@@ -158,6 +161,27 @@ public class RingtonePreference extends Preference implements
        mShowSilent = showSilent;
    }

    /**
     * Returns the resource id style of the ringtone dialog.
     *
     * @return The resource id of the style
     * @hide
     */
    public int getDialogStyle() {
        return mDialogStyle;
    }

    /**
     * Sets the resource id style of the ringtone dialog.
     *
     * @param dialogStyle The resource id of the style.
     * @see RingtoneManager#EXTRA_RINGTONE_DIALOG_THEME
     * @hide
     */
    public void setDialogStyle(int dialogStyle) {
        mDialogStyle = dialogStyle;
    }

    @Override
    protected void onClick() {
        // Launch the ringtone picker
@@ -193,6 +217,10 @@ public class RingtonePreference extends Preference implements
                    RingtoneManager.getDefaultUri(getRingtoneType()));
            }
        }
        if (mDialogStyle != 0) {
            ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DIALOG_THEME,
                    mDialogStyle);
        }

        ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, mShowSilent);
        ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, mRingtoneType);
+3 −0
Original line number Diff line number Diff line
@@ -6509,6 +6509,9 @@
        <attr name="showDefault" format="boolean" />
        <!-- Whether to show an item for 'Silent'. -->
        <attr name="showSilent" format="boolean" />
        <!-- The style of the ringtone dialog.
             @hide -->
        <attr name="dialogStyle" format="reference" />
    </declare-styleable>

    <!-- Base attributes available to VolumePreference. -->
+10 −0
Original line number Diff line number Diff line
@@ -177,6 +177,16 @@ public class RingtoneManager {
    public static final String EXTRA_RINGTONE_PICKED_URI =
            "android.intent.extra.ringtone.PICKED_URI";

    /**
     * Set the resource id theme to use for the dialog picker activity.<br/>
     * The default theme is <code>com.android.internal.R.Theme_Holo_Dialog_Alert</code>.
     *
     * @see #ACTION_RINGTONE_PICKER
     * @hide
     */
    public static final String EXTRA_RINGTONE_DIALOG_THEME =
            "android.intent.extra.ringtone.DIALOG_THEME";
    
    // Make sure the column ordering and then ..._COLUMN_INDEX are in sync
    
    private static final String[] INTERNAL_COLUMNS = new String[] {
+18 −0
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@ import android.app.ProfileManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
@@ -82,6 +85,21 @@ public final class ProfilePickerActivity extends AlertActivity implements

        Intent intent = getIntent();

        // Set custom theme
        int themeExtra = intent.getIntExtra(ProfileManager.EXTRA_PROFILE_DIALOG_THEME, 0);
        if (themeExtra != 0) {
            try {
                Resources resources = getPackageManager().getResourcesForApplication(
                        getCallingPackage());
                Theme theme = resources.newTheme();
                theme.applyStyle(themeExtra, true);
                getTheme().setTo(theme);

            } catch (NameNotFoundException e) {
                // Resource not available. Fall-through default theme
            }
        }

        if (savedInstanceState != null) {
            mClickedPos = savedInstanceState.getInt(SAVE_CLICKED_POS, -1);
        }