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

Commit 485f5eb5 authored by Hugo Hudson's avatar Hugo Hudson Committed by Android (Google) Code Review
Browse files

Merge "Prepare playback immediately, new BackgroundTaskService."

parents f1acd266 51ada368
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -1635,7 +1635,10 @@
    <string name="voicemail_initial_time">00:05</string>

    <!-- Message to show when there is an error playing back the voicemail. [CHAR LIMIT=40] -->
    <string name="voicemail_playback_error">Could not play voicemail</string>
    <string name="voicemail_playback_error">failed to play voicemail</string>

    <!-- Message to display before we have prepared the media player, i.e. before we know duration. [CHAR LIMIT=40] -->
    <string name="voicemail_buffering">buffering...</string>

    <!-- The header in the call log used to identify missed calls and voicemail that have not yet been consumed [CHAR LIMIT=10] -->
    <string name="call_log_new_header">New</string>
+20 −25
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ package com.android.contacts;
import com.android.contacts.calllog.CallDetailHistoryAdapter;
import com.android.contacts.calllog.CallTypeHelper;
import com.android.contacts.calllog.PhoneNumberHelper;
import com.android.contacts.util.AbstractBackgroundTask;
import com.android.contacts.util.BackgroundTask;
import com.android.contacts.util.BackgroundTaskService;
import com.android.contacts.voicemail.VoicemailPlaybackFragment;
import com.android.contacts.voicemail.VoicemailStatusHelper;
import com.android.contacts.voicemail.VoicemailStatusHelper.StatusMessage;
@@ -34,7 +37,6 @@ import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
@@ -87,6 +89,7 @@ public class CallDetailActivity extends ListActivity implements
    private ImageView mMainActionView;
    private ImageButton mMainActionPushLayerView;
    private ImageView mContactBackgroundView;
    private BackgroundTaskService mBackgroundTaskService;

    private String mNumber = null;
    private String mDefaultCountryIso;
@@ -144,6 +147,8 @@ public class CallDetailActivity extends ListActivity implements

        setContentView(R.layout.call_detail);

        mBackgroundTaskService = (BackgroundTaskService) getApplicationContext().getSystemService(
                BackgroundTaskService.BACKGROUND_TASK_SERVICE);
        mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        mResources = getResources();

@@ -164,13 +169,13 @@ public class CallDetailActivity extends ListActivity implements
        mContactPhotoManager = ContactPhotoManager.getInstance(this);
        getListView().setOnItemClickListener(this);
        configureActionBar();
        optionallyHandleVoicemail();
    }

    @Override
    public void onResume() {
        super.onResume();
        updateData(getCallLogEntryUris());
        optionallyHandleVoicemail();
    }

    /**
@@ -210,15 +215,14 @@ public class CallDetailActivity extends ListActivity implements
    }

    private void markVoicemailAsRead(final Uri voicemailUri) {
        new AsyncTask<Void, Void, Void>() {
        mBackgroundTaskService.submit(new AbstractBackgroundTask() {
            @Override
            protected Void doInBackground(Void... params) {
            public void doInBackground() {
                ContentValues values = new ContentValues();
                values.put(Voicemails.IS_READ, true);
                getContentResolver().update(voicemailUri, values, null, null);
                return null;
            }
        }.execute();
        });
    }

    /**
@@ -662,12 +666,16 @@ public class CallDetailActivity extends ListActivity implements
            }
            callIds.append(ContentUris.parseId(callUri));
        }
        runInBackgroundThenFinishActivity(new Runnable() {
        mBackgroundTaskService.submit(new BackgroundTask() {
            @Override
            public void run() {
            public void doInBackground() {
                getContentResolver().delete(Calls.CONTENT_URI_WITH_VOICEMAIL,
                        Calls._ID + " IN (" + callIds + ")", null);
            }
            @Override
            public void onPostExecute() {
                finish();
            }
        });
    }
    public void onMenuEditNumberBeforeCall(MenuItem menuItem) {
@@ -680,29 +688,16 @@ public class CallDetailActivity extends ListActivity implements

    public void onMenuTrashVoicemail(MenuItem menuItem) {
        final Uri voicemailUri = getVoicemailUri();
        runInBackgroundThenFinishActivity(new Runnable() {
        mBackgroundTaskService.submit(new BackgroundTask() {
            @Override
            public void run() {
            public void doInBackground() {
                getContentResolver().delete(voicemailUri, null, null);
            }
        });
    }

    /**
     * Run a task in the background, and then finish this activity when the task is done.
     */
    private void runInBackgroundThenFinishActivity(final Runnable runnable) {
        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                runnable.run();
                return null;
            }
            @Override
            protected void onPostExecute(Void result) {
            public void onPostExecute() {
                finish();
            }
        }.execute();
        });
    }

    private void configureActionBar() {
+9 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.contacts;

import com.android.contacts.model.AccountTypeManager;
import com.android.contacts.test.InjectedServices;
import com.android.contacts.util.BackgroundTaskService;
import com.google.common.annotations.VisibleForTesting;

import android.app.Application;
@@ -33,6 +34,7 @@ public final class ContactsApplication extends Application {
    private static InjectedServices sInjectedServices;
    private AccountTypeManager mAccountTypeManager;
    private ContactPhotoManager mContactPhotoManager;
    private BackgroundTaskService mBackgroundTaskService;

    /**
     * Overrides the system services with mocks for testing.
@@ -93,6 +95,13 @@ public final class ContactsApplication extends Application {
            return mContactPhotoManager;
        }

        if (BackgroundTaskService.BACKGROUND_TASK_SERVICE.equals(name)) {
            if (mBackgroundTaskService == null) {
                mBackgroundTaskService = BackgroundTaskService.createBackgroundTaskService();
            }
            return mBackgroundTaskService;
        }

        return super.getSystemService(name);
    }

+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.contacts.util;

import com.android.contacts.util.BackgroundTask;

/**
 * Base class you can use if you only want to override the {@link #doInBackground()} method.
 */
public abstract class AbstractBackgroundTask implements BackgroundTask {
    @Override
    public void onPostExecute() {
        // No action necessary.
    }
}
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.contacts.util;

/**
 * Simple interface to improve the testability of code using AsyncTasks.
 * <p>
 * Provides a trivial replacement for no-arg versions of AsyncTask clients.  We may extend this
 * to add more functionality as we require.
 * <p>
 * The same memory-visibility guarantees are made here as are made for AsyncTask objects, namely
 * that fields set in {@link #doInBackground()} are visible to {@link #onPostExecute()}.
 */
public interface BackgroundTask {
    public void doInBackground();
    public void onPostExecute();
}
Loading