2014-01-06 19:47:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 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.email.activity.setup;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
|
|
|
import com.android.email.R;
|
|
|
|
import com.android.email.activity.UiUtilities;
|
|
|
|
import com.android.emailcommon.mail.Address;
|
|
|
|
|
2014-03-05 22:08:06 +00:00
|
|
|
public class AccountSetupBasicsFragment extends AccountSetupFragment {
|
2014-01-06 19:47:56 +00:00
|
|
|
private EditText mEmailView;
|
2014-03-31 23:42:26 +00:00
|
|
|
private View mManualSetupView;
|
|
|
|
private boolean mManualSetup;
|
2014-01-06 19:47:56 +00:00
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
public interface Callback extends AccountSetupFragment.Callback {
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AccountSetupBasicsFragment newInstance() {
|
|
|
|
return new AccountSetupBasicsFragment();
|
|
|
|
}
|
|
|
|
|
2014-01-06 19:47:56 +00:00
|
|
|
public AccountSetupBasicsFragment() {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
|
Bundle savedInstanceState) {
|
2014-03-17 23:45:47 +00:00
|
|
|
final View view = inflateTemplatedView(inflater, container,
|
2014-04-22 21:02:18 +00:00
|
|
|
R.layout.account_setup_basics_fragment, -1);
|
2014-01-06 19:47:56 +00:00
|
|
|
|
|
|
|
mEmailView = UiUtilities.getView(view, R.id.account_email);
|
2014-03-05 22:08:06 +00:00
|
|
|
mManualSetupView = UiUtilities.getView(view, R.id.manual_setup);
|
2014-03-31 23:42:26 +00:00
|
|
|
mManualSetupView.setOnClickListener(this);
|
2014-01-06 19:47:56 +00:00
|
|
|
|
|
|
|
final TextWatcher textWatcher = new TextWatcher() {
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
validateFields();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
mEmailView.addTextChangedListener(textWatcher);
|
|
|
|
|
2014-03-31 23:42:26 +00:00
|
|
|
// On some layouts we want the button to only be invisible but still take up space, but on
|
|
|
|
// others we need it to be completely gone. So we divert based on resources.
|
|
|
|
final boolean prevButtonGone =
|
|
|
|
getResources().getBoolean(R.bool.setup_basics_prev_button_gone);
|
|
|
|
if (prevButtonGone) {
|
|
|
|
setPreviousButtonVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
setPreviousButtonVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
setManualSetupButtonVisibility(View.VISIBLE);
|
2014-03-17 23:45:47 +00:00
|
|
|
|
2014-01-06 19:47:56 +00:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2014-02-13 21:12:06 +00:00
|
|
|
@Override
|
|
|
|
public void onViewStateRestored(Bundle savedInstanceState) {
|
|
|
|
super.onViewStateRestored(savedInstanceState);
|
|
|
|
validateFields();
|
|
|
|
}
|
|
|
|
|
2014-03-31 23:42:26 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
final int viewId = v.getId();
|
|
|
|
final Callback callback = (Callback) getActivity();
|
|
|
|
|
|
|
|
if (viewId == R.id.next) {
|
|
|
|
// Handle "Next" button here so we can reset the manual setup diversion
|
|
|
|
mManualSetup = false;
|
|
|
|
callback.onNextButton();
|
|
|
|
} else if (viewId == R.id.manual_setup) {
|
|
|
|
mManualSetup = true;
|
|
|
|
callback.onNextButton();
|
|
|
|
} else {
|
|
|
|
super.onClick(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-06 19:47:56 +00:00
|
|
|
private void validateFields() {
|
|
|
|
final String emailField = getEmail();
|
|
|
|
final Address[] addresses = Address.parse(emailField);
|
|
|
|
|
|
|
|
final boolean emailValid = !TextUtils.isEmpty(emailField)
|
|
|
|
&& addresses.length == 1
|
|
|
|
&& !TextUtils.isEmpty(addresses[0].getAddress());
|
|
|
|
|
2014-03-17 23:45:47 +00:00
|
|
|
setNextButtonEnabled(emailValid);
|
2014-02-13 21:12:06 +00:00
|
|
|
}
|
|
|
|
|
2014-03-31 23:42:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set visibitlity of the "manual setup" button
|
|
|
|
* @param visibility {@link View#INVISIBLE}, {@link View#VISIBLE}, {@link View#GONE}
|
|
|
|
*/
|
|
|
|
public void setManualSetupButtonVisibility(int visibility) {
|
|
|
|
mManualSetupView.setVisibility(visibility);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setNextButtonEnabled(boolean enabled) {
|
|
|
|
super.setNextButtonEnabled(enabled);
|
|
|
|
mManualSetupView.setEnabled(enabled);
|
2014-04-04 17:10:25 +00:00
|
|
|
final float manualButtonAlpha;
|
|
|
|
if (enabled) {
|
|
|
|
manualButtonAlpha =
|
|
|
|
getResources().getFraction(R.fraction.manual_setup_enabled_alpha, 1, 1);
|
|
|
|
} else {
|
|
|
|
manualButtonAlpha =
|
|
|
|
getResources().getFraction(R.fraction.manual_setup_disabled_alpha, 1, 1);
|
|
|
|
}
|
|
|
|
mManualSetupView.setAlpha(manualButtonAlpha);
|
2014-03-31 23:42:26 +00:00
|
|
|
}
|
|
|
|
|
2014-01-06 19:47:56 +00:00
|
|
|
public void setEmail(final String email) {
|
|
|
|
mEmailView.setText(email);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getEmail() {
|
|
|
|
return mEmailView.getText().toString().trim();
|
|
|
|
}
|
2014-03-05 22:08:06 +00:00
|
|
|
|
|
|
|
public boolean isManualSetup() {
|
2014-03-31 23:42:26 +00:00
|
|
|
return mManualSetup;
|
2014-03-05 22:08:06 +00:00
|
|
|
}
|
2014-01-06 19:47:56 +00:00
|
|
|
}
|