Android Open Source - trivial-lists Generic Editor Dialog Fragment






From Project

Back to project page trivial-lists.

License

The source code is released under:

MIT License

If you think the Android project trivial-lists 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 org.hbabcock.triviallists;
//from w  w  w .j a  v a  2  s  .c  o m
import java.util.UUID;

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

public class GenericEditorDialogFragment extends DialogFragment {
  private static final String TAG = "GenericEditorDialogFragment";
  public static final String EXTRA_GENERIC_ID = "org.hbabcock.triviallist.generic_id";
  public static final String EXTRA_GENERIC_NAME = "org.hbabcock.triviallist.generic_name";
  public static final String EXTRA_EDIT_MODE = "org.hbabcock.triviallist.edit_mode";
  public static final int REQUEST_EDIT = 10;
  public static final int REQUEST_NEW = 11;

  private String mId;
  private String mName;
  private View mView;
  
  public static GenericEditorDialogFragment newInstance(UUID id, String name){
    Bundle args = new Bundle();
    args.putString(EXTRA_GENERIC_ID, id.toString());
    args.putString(EXTRA_GENERIC_NAME, name);
  
    GenericEditorDialogFragment fragment = new GenericEditorDialogFragment();
    fragment.setArguments(args);
    
    return fragment;
  }
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState){
    mId = new String(getArguments().getString(EXTRA_GENERIC_ID));
    mName = new String(getArguments().getString(EXTRA_GENERIC_NAME));

    mView = getActivity().getLayoutInflater().inflate(R.layout.generic_editor_dialog_fragment, null);
    
    ((EditText) mView.findViewById(R.id.name)).setText(mName);
    
    Integer stringId;
    if (getTargetRequestCode() == REQUEST_NEW){
      stringId = R.string.category_editor_title_new;
    }
    else{
      stringId = R.string.category_editor_title_edit;
    }
      
    return new AlertDialog.Builder(getActivity())
        .setView(mView)
        .setTitle(stringId)
        .setPositiveButton(
            android.R.string.ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                sendResult(Activity.RESULT_OK);
              }
            })
        .create();
  }
  
  private void sendResult(int resultCode){
    if (getTargetFragment() == null)
      return;

    Intent i = new Intent();
    i.putExtra(EXTRA_GENERIC_ID, mId);
    i.putExtra(EXTRA_GENERIC_NAME, ((EditText)mView.findViewById(R.id.name)).getText().toString());
    
    getTargetFragment().onActivityResult(getTargetRequestCode(), resultCode, i);
  }
}




Java Source Code List

org.hbabcock.triviallists.CategoryActivity.java
org.hbabcock.triviallists.CategoryDeleteDialog.java
org.hbabcock.triviallists.CategoryFragment.java
org.hbabcock.triviallists.CategoryItemManager.java
org.hbabcock.triviallists.Category.java
org.hbabcock.triviallists.GenericEditorDialogFragment.java
org.hbabcock.triviallists.ItemFragmentEdit.java
org.hbabcock.triviallists.ItemFragmentShop.java
org.hbabcock.triviallists.ItemFragment.java
org.hbabcock.triviallists.ItemPagerActivity.java
org.hbabcock.triviallists.Item.java
org.hbabcock.triviallists.SingleFragmentActivity.java
org.hbabcock.triviallists.TrivialListJSONSerializer.java