Android Open Source - ls-vertretungsplan Login Dialog Fragment






From Project

Back to project page ls-vertretungsplan.

License

The source code is released under:

GNU General Public License

If you think the Android project ls-vertretungsplan listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.johan.vertretungsplan;
/*from  w w w .jav  a 2 s.  com*/
import org.holoeverywhere.app.Activity;
import org.holoeverywhere.app.AlertDialog;
import org.holoeverywhere.app.Dialog;
import org.holoeverywhere.app.DialogFragment;
import org.holoeverywhere.widget.Button;
import org.holoeverywhere.widget.EditText;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

public class LoginDialogFragment extends DialogFragment {

  public interface LoginDialogListener {
    public void onLogin(String login, String password);

    public void onCancel();
  }

  private LoginDialogListener mListener;
  private View view;
  private String fixedLogin;
  
  public LoginDialogFragment(String fixedLogin) {
    this.fixedLogin = fixedLogin;
  }
  
  public LoginDialogFragment() {
    fixedLogin = null;
  }

  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    view = inflater.inflate(R.layout.dialog_signin, null);
    if (fixedLogin != null) {
      EditText login = (EditText) view.findViewById(R.id.username);
      login.setText(fixedLogin);
      login.setEnabled(false);
    }
    
    builder.setView(view)
        // Add action buttons
        .setPositiveButton(R.string.signin,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int id) {

              }
            })
        .setNegativeButton(R.string.cancel,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                LoginDialogFragment.this.getDialog().cancel();
                mListener.onCancel();
              }
            });
    return builder.create();
  }

  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);
    // Verify that the host activity implements the callback interface
    try {
      // Instantiate the NoticeDialogListener so we can send events to the
      // host
      mListener = (LoginDialogListener) activity;
    } catch (ClassCastException e) {
      // The activity doesn't implement the interface, throw exception
      throw new ClassCastException(activity.toString()
          + " must implement LoginDialogListener");
    }
  }

  @Override
  public void onStart() {
    super.onStart(); // super.onStart() is where dialog.show() is actually
              // called on the underlying dialog, so we have to do
              // it after this point
    AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
      Button positiveButton = (Button) d
          .getButton(Dialog.BUTTON_POSITIVE);
      positiveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          String login = ((EditText) view.findViewById(R.id.username))
              .getText().toString();
          String password = ((EditText) view
              .findViewById(R.id.password)).getText().toString();
          mListener.onLogin(login, password);
        }
      });
    }
  }

  public void progress(boolean progress) {
    view.findViewById(R.id.progress).setVisibility(
        progress ? View.VISIBLE : View.GONE);
    view.findViewById(R.id.login).setVisibility(
        progress ? View.GONE : View.VISIBLE);
  }

}




Java Source Code List

com.joejernst.http.Message.java
com.joejernst.http.Request.java
com.joejernst.http.Response.java
com.johan.vertretungsplan.GCMIntentService.java
com.johan.vertretungsplan.LoginDialogFragment.java
com.johan.vertretungsplan.NachrichtenFragment.java
com.johan.vertretungsplan.SettingsActivity.java
com.johan.vertretungsplan.SettingsFragment.java
com.johan.vertretungsplan.StartActivity.java
com.johan.vertretungsplan.VertretungFragment.java
com.johan.vertretungsplan.VertretungsplanApplication.java
com.johan.vertretungsplan.VertretungsplanFragment.java
com.johan.vertretungsplan.additionalinfo.BaseAdditionalInfoParser.java
com.johan.vertretungsplan.additionalinfo.WinterShParser.java
com.johan.vertretungsplan.background.VertretungsplanService.java
com.johan.vertretungsplan.comparators.AlphabeticalSchoolComparator.java
com.johan.vertretungsplan.comparators.DistanceSchoolComparator.java
com.johan.vertretungsplan.objects.AdditionalInfo.java
com.johan.vertretungsplan.objects.KlassenVertretungsplan.java
com.johan.vertretungsplan.objects.Schule.java
com.johan.vertretungsplan.objects.Vertretung.java
com.johan.vertretungsplan.objects.VertretungsplanTag.java
com.johan.vertretungsplan.objects.Vertretungsplan.java
com.johan.vertretungsplan.parser.BackendConnectParser.java
com.johan.vertretungsplan.parser.BaseParser.java
com.johan.vertretungsplan.ui.LinkAlertDialog.java
com.johan.vertretungsplan.ui.TabSwipeActivity.java
com.johan.vertretungsplan.ui.WebViewAlertDialog.java
com.johan.vertretungsplan.utils.Animations.java
com.johan.vertretungsplan.utils.Utils.java
com.johan.vertretungsplan.widget.VertretungsplanWidgetProvider.java
com.johan.vertretungsplan.widget.VertretungsplanWidgetService.java