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

Commit 3aa0e506 authored by Josh Guilfoyle's avatar Josh Guilfoyle
Browse files

Implement buy ringtones flow in RingtonePickerActivity.

CR: Ed Carrigan
parent 93946942
Loading
Loading
Loading
Loading
+42 −14
Original line number Diff line number Diff line
@@ -59,6 +59,9 @@ public final class RingtonePickerActivity extends AlertActivity implements
    /** The position in the list of the 'Default' item. */
    private int mDefaultRingtonePos = -1;

    /** The position in the list of the 'Buy ringtone' item (should be 0). */
    private int mBuyPos = -1;

    /** The position in the list of the last clicked item. */
    private int mClickedPos = -1;
    
@@ -68,6 +71,9 @@ public final class RingtonePickerActivity extends AlertActivity implements
    /** Whether this list has the 'Silent' item. */
    private boolean mHasSilentItem;

    /** Whether this list has the 'Buy ringtone' item. */
    private boolean mHasBuyItem;

    /** The Uri to place a checkmark next to. */
    private Uri mExistingUri;
    
@@ -94,6 +100,12 @@ public final class RingtonePickerActivity extends AlertActivity implements
         * On item clicked
         */
        public void onClick(DialogInterface dialog, int which) {
            if (which == mBuyPos) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://wap.t-zones.com")));
                finish();
            }

            // Save the position of most recently clicked item
            mClickedPos = which;

@@ -124,6 +136,9 @@ public final class RingtonePickerActivity extends AlertActivity implements
        // Get whether to show the 'Silent' item
        mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);

        // Get whether to show the 'Buy ringtones' item
        mHasBuyItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_BUY, false);

        // Give the Activity so it can do managed queries
        mRingtoneManager = new RingtoneManager(this);

@@ -169,6 +184,10 @@ public final class RingtonePickerActivity extends AlertActivity implements

    public void onPrepareListView(ListView listView) {

        if (mHasBuyItem) {
            mBuyPos = addBuyItem(listView);
        }

        if (mHasDefaultItem) {
            mDefaultRingtonePos = addDefaultRingtoneItem(listView);
            
@@ -202,28 +221,37 @@ public final class RingtonePickerActivity extends AlertActivity implements
     * @param textResId The resource ID of the text for the item.
     * @return The position of the inserted item.
     */
    private int addStaticItem(ListView listView, int textResId) {
        TextView textView = (TextView) getLayoutInflater().inflate(
                com.android.internal.R.layout.select_dialog_singlechoice, listView, false);
    private int addStaticItem(ListView listView, int resId, int textResId) {
        TextView textView = (TextView) getLayoutInflater().inflate(resId, listView, false);
        textView.setText(textResId);
        listView.addHeaderView(textView);
        mStaticItemCount++;
        return listView.getHeaderViewsCount() - 1;
    }

    private int addBuyItem(ListView listView) {
        return addStaticItem(listView,
                com.android.internal.R.layout.simple_list_item_1,
                com.android.internal.R.string.buy_ringtones);
    }

    private int addDefaultRingtoneItem(ListView listView) {
        return addStaticItem(listView, com.android.internal.R.string.ringtone_default);
        return addStaticItem(listView,
                com.android.internal.R.layout.select_dialog_singlechoice,
                com.android.internal.R.string.ringtone_default);
    }
    
    private int addSilentItem(ListView listView) {
        return addStaticItem(listView, com.android.internal.R.string.ringtone_silent);
        return addStaticItem(listView,
                com.android.internal.R.layout.select_dialog_singlechoice,
                com.android.internal.R.string.ringtone_silent);
    }
    
    /*
     * On click of Ok/Cancel buttons
     */
    public void onClick(DialogInterface dialog, int which) {
        boolean positiveResult = which == BUTTON1;
        boolean positiveResult = which == BUTTON1 && mClickedPos != mBuyPos;

        // Stop playing the previous ringtone
        mRingtoneManager.stopPreviousRingtone();
+11 −0
Original line number Diff line number Diff line
@@ -117,6 +117,17 @@ public class RingtoneManager {
    public static final String EXTRA_RINGTONE_SHOW_SILENT =
            "android.intent.extra.ringtone.SHOW_SILENT";

    /**
     * Given to the ringtone picker as a boolean. Whether to show an item for
     * "Buy ringtones".
     *
     * @see #ACTION_RINGTONE_PICKER
     *
     * @hide
     */
    public static final String EXTRA_RINGTONE_SHOW_BUY =
            "com.tmobile.intent.extra.ringtone.SHOW_BUY";

    /**
     * Given to the ringtone picker as a boolean. Whether to include DRM ringtones.
     */