Android Open Source - temaki Generic Input Dialog






From Project

Back to project page temaki.

License

The source code is released under:

Apache License

If you think the Android project temaki 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.jmartin.temaki.dialog;
/*  w w  w .  ja  v a2  s  .  c o  m*/
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.jmartin.temaki.FocusActivity;
import com.jmartin.temaki.MainDrawerActivity;
import com.jmartin.temaki.MainListsFragment;
import com.jmartin.temaki.R;
import com.jmartin.temaki.model.Constants;

/**
 * Author: Jeff Martin, 2013
 */
public class GenericInputDialog extends DialogFragment {

    private EditText promptEditText;
    private String dialogTitle;
    private String optionalExistingValue;
    private int inputType;

    public GenericInputDialog() {
    }

    public GenericInputDialog(String existingInput) {
        this.optionalExistingValue = existingInput;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.generic_name_dialog_fragment, container);
        promptEditText = (EditText) rootView.findViewById(R.id.prompt_value_edittext);

        if (optionalExistingValue != null && optionalExistingValue.length() > 0) {
            promptEditText.setText(optionalExistingValue);
            promptEditText.setSelection(optionalExistingValue.length());
        }

        Button cancelButton = (Button) rootView.findViewById(R.id.cancel_dialog_button);
        Button okButton = (Button) rootView.findViewById(R.id.ok_dialog_button);

        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Fragment frag = getTargetFragment();
                if (frag != null) {
                    frag.onActivityResult(getTargetRequestCode(),
                            Constants.CANCEL_RESULT_CODE, null);
                }
                dismiss();
            }
        });

        okButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent resultIntent = new Intent();
                String input = promptEditText.getText().toString();
                resultIntent.putExtra(Constants.INTENT_RESULT_KEY, input);

                Fragment frag = getTargetFragment();
                if (frag == null) {
                    Activity activity = getActivity();
                    if (activity instanceof MainDrawerActivity) {
                        ((MainDrawerActivity) activity).onActivityResult(inputType, inputType, resultIntent);
                    } else if (activity instanceof FocusActivity) {
                        ((FocusActivity) activity).onActivityResult(inputType, inputType, resultIntent);
                    }
                } else {
                    frag.onActivityResult(getTargetRequestCode(), Constants.EDIT_ITEM_ID, resultIntent);
                }
                dismiss();
            }
        });
        getDialog().setTitle(dialogTitle);
        return rootView;
    }

    public void setTitle(String dialogTitle) {
        this.dialogTitle = dialogTitle;
    }

    public void setActionIdentifier(int inputType) {
        this.inputType = inputType;
    }
}




Java Source Code List

com.jmartin.temaki.FocusActivity.java
com.jmartin.temaki.MainDrawerActivity.java
com.jmartin.temaki.MainListsFragment.java
com.jmartin.temaki.adapter.DrawerListAdapter.java
com.jmartin.temaki.adapter.ListItemsAdapter.java
com.jmartin.temaki.dialog.DeleteConfirmationDialog.java
com.jmartin.temaki.dialog.GenericInputDialog.java
com.jmartin.temaki.model.Constants.java
com.jmartin.temaki.model.TemakiItem.java
com.jmartin.temaki.settings.InformationDialogPreference.java
com.jmartin.temaki.settings.SettingsActivity.java
com.jmartin.temaki.settings.SettingsFragment.java