1
0
mirror of https://github.com/etesync/android synced 2025-07-15 19:18:26 +00:00
etesync-android/app/src/main/java/at/bitfire/davdroid/syncadapter/LoginURLFragment.java
Ricki Hirner 933f99b563 Version 0.7
* new Settings activity
* Settings: display/change user name, password, preemptive auth.
* Settings: display/change sync. interval for contacts and calendars
* requires permission GET_ACCOUNTS to list accounts in Settings
* requires permission READ_SYNC_SETTINGS to display current sync intervals
* remove obsolete files from res/
* update copyright notices
* version bump to 0.7
2015-03-08 23:37:48 +01:00

155 lines
4.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2013 2015 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.davdroid.syncadapter;
import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import org.apache.commons.lang.StringUtils;
import java.net.URI;
import java.net.URISyntaxException;
import at.bitfire.davdroid.R;
public class LoginURLFragment extends Fragment implements TextWatcher {
protected Spinner spnrScheme;
protected TextView textHttpWarning;
protected EditText editBaseURI, editUserName, editPassword;
protected CheckBox checkboxPreemptive;
protected Button btnNext;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.login_url, container, false);
// protocol selection spinner
textHttpWarning = (TextView)v.findViewById(R.id.http_warning);
spnrScheme = (Spinner)v.findViewById(R.id.login_scheme);
spnrScheme.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String scheme = parent.getAdapter().getItem(position).toString();
textHttpWarning.setVisibility(scheme.equals("https://") ? View.GONE : View.VISIBLE);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
spnrScheme.setSelection(1); // HTTPS
// other input fields
editBaseURI = (EditText)v.findViewById(R.id.login_host_path);
editBaseURI.addTextChangedListener(this);
editUserName = (EditText)v.findViewById(R.id.userName);
editUserName.addTextChangedListener(this);
editPassword = (EditText)v.findViewById(R.id.password);
editPassword.addTextChangedListener(this);
checkboxPreemptive = (CheckBox) v.findViewById(R.id.auth_preemptive);
// hook into action bar
setHasOptionsMenu(true);
return v;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.only_next, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.next:
FragmentTransaction ft = getFragmentManager().beginTransaction();
Bundle args = new Bundle();
try {
args.putString(QueryServerDialogFragment.EXTRA_BASE_URI, getBaseURI().toString());
} catch (URISyntaxException e) {
}
args.putString(QueryServerDialogFragment.EXTRA_USER_NAME, editUserName.getText().toString());
args.putString(QueryServerDialogFragment.EXTRA_PASSWORD, editPassword.getText().toString());
args.putBoolean(QueryServerDialogFragment.EXTRA_AUTH_PREEMPTIVE, checkboxPreemptive.isChecked());
DialogFragment dialog = new QueryServerDialogFragment();
dialog.setArguments(args);
dialog.show(ft, QueryServerDialogFragment.class.getName());
break;
default:
return false;
}
return true;
}
private URI getBaseURI() throws URISyntaxException {
String scheme = spnrScheme.getSelectedItem().toString(),
host_path = editBaseURI.getText().toString();
return new URI(scheme + host_path);
}
// input validation
@Override
public void onPrepareOptionsMenu(Menu menu) {
boolean usernameOk = editUserName.getText().length() > 0,
passwordOk = editPassword.getText().length() > 0,
urlOk = false;
// check host name
try {
if (!StringUtils.isBlank(getBaseURI().getHost()))
urlOk = true;
} catch (Exception e) {
}
MenuItem item = menu.findItem(R.id.next);
item.setEnabled(usernameOk && passwordOk && urlOk);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
getActivity().invalidateOptionsMenu();
}
@Override
public void afterTextChanged(Editable s) {
}
}