1e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira/*
2e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * Copyright (C) 2012 Google Inc.
3e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * Licensed to The Android Open Source Project.
4e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira *
5e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * Licensed under the Apache License, Version 2.0 (the "License");
6e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * you may not use this file except in compliance with the License.
7e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * You may obtain a copy of the License at
8e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira *
9e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira *      http://www.apache.org/licenses/LICENSE-2.0
10e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira *
11e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * Unless required by applicable law or agreed to in writing, software
12e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * distributed under the License is distributed on an "AS IS" BASIS,
13e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * See the License for the specific language governing permissions and
15e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * limitations under the License.
16e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira */
17e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira
18e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereirapackage com.android.mail.compose;
19e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira
20e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereiraimport android.os.Bundle;
21e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira
22e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira/**
23e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * An activity that will automatically queue a message, from the contents in
24e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * an ACTION_SEND intent
25e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira *
26e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * AutoSendActivity extends ComposeActivity, since the logic that handles the SEND intent
27e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira * is in ComposeActivity.
28e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira */
29e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereirapublic class AutoSendActivity extends ComposeActivity {
30e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    // For testing, this extra will cause the message not be be saved or sent
31e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    public static final String EXTRA_DONT_SEND_OR_SAVE = "dontSendOrSave";
32e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    private boolean mDontSaveOrSend = false;
33e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira
34e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira
35e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    // =============================================================================================
36e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    // ComposeActivity methods
37e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    // =============================================================================================
38e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    /**
39e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira     * Returns a boolean indicating whether warnings should be shown for empty subject
40e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira     * and body fields
41e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira     *
42e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira     * @return True if a warning should be shown for empty text fields
43e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira     */
44e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    @Override
45e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    protected boolean showEmptyTextWarnings() {
46e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira        return false;
47e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    }
48e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira
49e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    /**
50e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira     * Returns a boolean indicating whether the user should confirm each send
51e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira     * Since this is an auto send, the user doesn't confirm the send
52e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira     *
53e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira     * @return True if a warning should be on each send
54e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira     */
55e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    @Override
56e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    protected boolean showSendConfirmation() {
57e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira        return false;
58e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    }
59e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira
60e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    @Override
61d90639004a3551d7fb7086f318d4c576d54d2b86Scott Kennedy    protected void onCreate(Bundle savedInstanceState) {
62e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira        super.onCreate(savedInstanceState);
63e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira        mDontSaveOrSend = getIntent().getBooleanExtra(EXTRA_DONT_SEND_OR_SAVE, false);
64e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira        sendOrSaveWithSanityChecks(false /* send */, true /* show  toast */);
65e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    }
66e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira
671b7ad92c69b15d084aebd1b94f3176d88b3e3c19Andrew Sapperstein    /**
681b7ad92c69b15d084aebd1b94f3176d88b3e3c19Andrew Sapperstein     * This is a custom version for auto-send.
691b7ad92c69b15d084aebd1b94f3176d88b3e3c19Andrew Sapperstein     */
701b7ad92c69b15d084aebd1b94f3176d88b3e3c19Andrew Sapperstein    private void sendOrSaveWithSanityChecks(final boolean save, final boolean showToast) {
71e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira        if (mDontSaveOrSend) {
721b7ad92c69b15d084aebd1b94f3176d88b3e3c19Andrew Sapperstein            return;
73e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira        }
741b7ad92c69b15d084aebd1b94f3176d88b3e3c19Andrew Sapperstein        sendOrSaveWithSanityChecks(
751b7ad92c69b15d084aebd1b94f3176d88b3e3c19Andrew Sapperstein                save, showToast, false /* orientationChanged */, true /* autoSend */);
76e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira    }
77e011b1d1c8e2e674dfdf1985d9d13da8cc06d803Mindy Pereira}
78