Android Open Source - budget-envelopes Ok Fragment






From Project

Back to project page budget-envelopes.

License

The source code is released under:

GNU General Public License

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

/*
 * This file is a part of Budget with Envelopes.
 * Copyright 2013 Michael Howell <michael@notriddle.com>
 *//from  w  w w . j a va 2s. c  o m
 * Budget 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.
 *
 * Budget 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 Budget. If not, see <http://www.gnu.org/licenses/>.
 */

package com.notriddle.budget;

import android.app.Activity;
import android.app.ActivityOptions;
import android.app.AlertDialog;
import android.app.DialogFragment;
import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.ContextThemeWrapper;
import android.view.KeyEvent;
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.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public abstract class OkFragment extends DialogFragment
                                 implements TextView.OnEditorActionListener,
                                            TitleFragment {

    boolean mRanOk;

    public static interface OnDismissListener {
        public void onDismiss();
    };

    @Override public void onCreate(Bundle state) {
        super.onCreate(state);
        setHasOptionsMenu(true);
        mRanOk = false;
    }

    @Override public void onResume() {
        super.onResume();
        refreshOkButton();
    }

    @Override public void dismiss() {
        if (!getShowsDialog()) {
            OnDismissListener l = (OnDismissListener)getActivity();
            l.onDismiss();
        } else {
            super.dismiss();
        }
    }

    @Override public View onCreateView(LayoutInflater inflater,
                                       ViewGroup cont, Bundle state) {
        View retVal = null;
        if (!getShowsDialog()) {
            retVal = onCreateInternalView(inflater, null, state);
        }
        return retVal;
    }

    @Override public AlertDialog onCreateDialog(Bundle state) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.Theme_Dialog);
        LayoutInflater inflater = LayoutInflater.from(builder.getContext());
        View v = onCreateInternalView(inflater, null, state);
        View t = inflater.inflate(R.layout.custom_title, null, false);
        ((TextView)t.findViewById(R.id.title)).setText(getTitle());
        ((LinearLayout)t).addView(v);
        return builder
               .setView(t)
               //.setView(v)
               //.setTitle(getTitle())
               .setPositiveButton(android.R.string.ok,
                   new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface d, int button) {
                           ok();
                       }
                   }
               )
               .setNegativeButton(android.R.string.cancel,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface d, int button) {
                        }
                    }
               )
               .create();
    }

    public void refreshOkButton() {
        AlertDialog d = (AlertDialog) getDialog();
        if (d != null && d.getButton(d.BUTTON_POSITIVE) != null) {
            d.getButton(d.BUTTON_POSITIVE)
              .setEnabled(isOk());
        }
        if (getActivity() != null) {
            getActivity().invalidateOptionsMenu();
        }
    }

    @Override public void onCreateOptionsMenu(Menu menu,
                                              MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.ok, menu);
    }

    @Override public void onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        menu.findItem(R.id.ok_menuItem).setEnabled(isOk());
        menu.findItem(R.id.ok_menuItem).setVisible(!getShowsDialog());
    }

    @Override public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                getActivity().onBackPressed();
                return true;
            case R.id.ok_menuItem:
                ok();
                dismiss();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override public boolean onEditorAction(TextView v, int a, KeyEvent e) {
        if (!mRanOk && isOk()) {
            mRanOk = true;
            ok();
            dismiss();
        }
        return false;
    }

    protected void changeToActivity() {
        EnvelopesActivity a = (EnvelopesActivity) getActivity();
        Bundle args = (Bundle) getArguments().clone();
        writeArgs(args);
        a.switchFragment(getClass(), getClass().getName(), args);
        dismiss();
    }

    protected void writeArgs(Bundle args) {
    }

    abstract public void ok();
    abstract public boolean isOk();
    abstract public String getTitle();
    abstract public View onCreateInternalView(LayoutInflater inflater,
                                              ViewGroup cont, Bundle state);

};




Java Source Code List

com.notriddle.budget.AboutFragment.java
com.notriddle.budget.AllTransactionsFragment.java
com.notriddle.budget.CheckableLinearLayout.java
com.notriddle.budget.CheckableRelativeLayout.java
com.notriddle.budget.ColorFragment.java
com.notriddle.budget.CustomActionBarFragment.java
com.notriddle.budget.DeleteAdapter.java
com.notriddle.budget.DeleteView.java
com.notriddle.budget.EditMoney.java
com.notriddle.budget.EditTextDefaultFocus.java
com.notriddle.budget.EditTransactionFragment.java
com.notriddle.budget.EnvelopeDetailsFragment.java
com.notriddle.budget.EnvelopesActivity.java
com.notriddle.budget.EnvelopesAdapter.java
com.notriddle.budget.EnvelopesFragment.java
com.notriddle.budget.EnvelopesOpenHelper.java
com.notriddle.budget.ExportFragment.java
com.notriddle.budget.FileCreatorFragment.java
com.notriddle.budget.GraphFragment.java
com.notriddle.budget.ImportFragment.java
com.notriddle.budget.LockedActivity.java
com.notriddle.budget.LogAdapter.java
com.notriddle.budget.MonitorScrollView.java
com.notriddle.budget.NavAdapter.java
com.notriddle.budget.OkFragment.java
com.notriddle.budget.PaycheckEnvelopesAdapter.java
com.notriddle.budget.PaycheckFragment.java
com.notriddle.budget.PinActivity.java
com.notriddle.budget.SQLiteLoader.java
com.notriddle.budget.SettingsFragment.java
com.notriddle.budget.SimpleEnvelopesAdapter.java
com.notriddle.budget.SimpleLogAdapter.java
com.notriddle.budget.SpendFragment.java
com.notriddle.budget.TACGridView.java
com.notriddle.budget.TitleFragment.java
com.notriddle.budget.TransferFragment.java
com.notriddle.budget.Util.java
com.notriddle.budget.WidgetProvider.java
com.notriddle.budget.WidgetService.java
com.notriddle.budget.csv.CSVReader.java
com.notriddle.budget.csv.CSVWriter.java