Android Open Source - KendaliPintuAndroid User Dialog Manager






From Project

Back to project page KendaliPintuAndroid.

License

The source code is released under:

GNU General Public License

If you think the Android project KendaliPintuAndroid 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

/*******************************************************************************
 * Copyright (c) 2014 Dimas Rullyan Danu
 * //  w  w w  .java  2 s  .  co  m
 * Kendali Pintu is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kendali Pintu is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kendali Pintu. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package com.dimasdanz.kendalipintu.usermodel;

import java.util.ArrayList;

import com.dimasdanz.kendalipintu.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class UserDialogManager extends DialogFragment{
  UserDialogManagerListener mListener;
  
  public interface UserDialogManagerListener {
        public void onDialogPositiveClick(DialogFragment dialog, ArrayList<String> data);
        public void onDialogNegativeClick(DialogFragment dialog, ArrayList<String> data);
    }
  
  public static UserDialogManager newInstance(ArrayList<String> data) {
    UserDialogManager f = new UserDialogManager();
        Bundle args = new Bundle();
        if(data != null){
          args.putStringArrayList("data", data);
        }
        f.setArguments(args);
        return f;
    }
  
  public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mListener = (UserDialogManagerListener) activity;
        } catch (ClassCastException e) {
          e.toString();
        }
    }
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
        LayoutInflater inflater = getActivity().getLayoutInflater();
        final ArrayList<String> userData = new ArrayList<String>();
        final View view = inflater.inflate(R.layout.dialog_user_form, null);
        final TextView txtUserID = (TextView)view.findViewById(R.id.txtUserID);
        final EditText txtUsername = (EditText)view.findViewById(R.id.txtUserName);
        final EditText txtUserPass = (EditText)view.findViewById(R.id.txtUserPass);
        int btnText = R.string.action_add_account;
        if(!getArguments().isEmpty()){
          btnText = R.string.change;
          txtUserID.setText(getArguments().getStringArrayList("data").get(0));
          txtUsername.setText(getArguments().getStringArrayList("data").get(1));
          txtUserPass.setText(getArguments().getStringArrayList("data").get(2));
        }
        
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), 4);
    builder.setIcon(R.drawable.ic_action_group);
      builder.setTitle(R.string.dialog_title_userform);
    builder.setView(view);
    builder.setPositiveButton(btnText, new DialogInterface.OnClickListener() {
      @Override
          public void onClick(DialogInterface dialog, int id) {
            if(txtUsername.getText().toString().length() > 0 || txtUserPass.getText().length() > 0){
              userData.add(txtUserID.getText().toString());
                userData.add(txtUsername.getText().toString());
                userData.add(txtUserPass.getText().toString());
                mListener.onDialogPositiveClick(UserDialogManager.this, userData);
            }else{
              //TODO Change string, use a better listener
              Toast.makeText(getActivity(), "Please fill all field", Toast.LENGTH_SHORT).show();
            }
          }
        });
    builder.setNegativeButton(R.string.delete, new DialogInterface.OnClickListener() {
      @Override
          public void onClick(DialogInterface dialog, int id) {
        if(txtUserID.getText().toString().length() > 0){
          userData.add(txtUserID.getText().toString());
              mListener.onDialogNegativeClick(UserDialogManager.this, userData);
        }else{
          //TODO Change string, use a better listener
          Toast.makeText(getActivity(), "Please fill all field", Toast.LENGTH_SHORT).show();
        }            
          }
        });
    builder.setNeutralButton(R.string.close, null);
    return builder.create();
  }
}




Java Source Code List

com.dimasdanz.kendalipintu.BarcodeOpenDoorActivity.java
com.dimasdanz.kendalipintu.DeviceStatusActivity.java
com.dimasdanz.kendalipintu.LogActivity.java
com.dimasdanz.kendalipintu.LoginActivity.java
com.dimasdanz.kendalipintu.MainActivity.java
com.dimasdanz.kendalipintu.NFCOpenDoorActivity.java
com.dimasdanz.kendalipintu.RemoteOpenDoor.java
com.dimasdanz.kendalipintu.SettingsActivity.java
com.dimasdanz.kendalipintu.SettingsFragment.java
com.dimasdanz.kendalipintu.SetupActivity.java
com.dimasdanz.kendalipintu.UserActivity.java
com.dimasdanz.kendalipintu.devicestatusmodel.DeviceStatusLoadData.java
com.dimasdanz.kendalipintu.devicestatusmodel.DeviceStatusSendData.java
com.dimasdanz.kendalipintu.logmodel.LogAdapter.java
com.dimasdanz.kendalipintu.logmodel.LogLoadData.java
com.dimasdanz.kendalipintu.logmodel.LogLoadDetail.java
com.dimasdanz.kendalipintu.logmodel.LogModel.java
com.dimasdanz.kendalipintu.opendoor.BarcodePreview.java
com.dimasdanz.kendalipintu.usermodel.UserAdapter.java
com.dimasdanz.kendalipintu.usermodel.UserDialogManager.java
com.dimasdanz.kendalipintu.usermodel.UserListView.java
com.dimasdanz.kendalipintu.usermodel.UserLoadData.java
com.dimasdanz.kendalipintu.usermodel.UserModel.java
com.dimasdanz.kendalipintu.usermodel.UserSendData.java
com.dimasdanz.kendalipintu.util.AdminLoginDialog.java
com.dimasdanz.kendalipintu.util.CommonUtilities.java
com.dimasdanz.kendalipintu.util.GcmBroadcastReceiver.java
com.dimasdanz.kendalipintu.util.GcmIntentService.java
com.dimasdanz.kendalipintu.util.JSONParser.java
com.dimasdanz.kendalipintu.util.LoginAuth.java
com.dimasdanz.kendalipintu.util.ServerUtilities.java
com.dimasdanz.kendalipintu.util.SharedPreferencesManager.java
com.dimasdanz.kendalipintu.util.StaticString.java
com.dimasdanz.kendalipintu.util.UniversalDialogManager.java