Android Open Source - jogjakota-perizinan Permit Form Activity






From Project

Back to project page jogjakota-perizinan.

License

The source code is released under:

MIT License

If you think the Android project jogjakota-perizinan 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 id.go.jogjakota.perizinan;
/* www  .j a  v  a2 s  . c  om*/
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.ButterKnife;
import butterknife.InjectView;
import id.go.jogjakota.perizinan.data.PermitDB;
import id.go.jogjakota.perizinan.data.Session;
import id.go.jogjakota.perizinan.domain.Permit;
import id.go.jogjakota.perizinan.domain.PermitType;

import static butterknife.ButterKnife.findById;

public class PermitFormActivity extends BaseActivity {

    private PermitType mType;

    @InjectView(R.id.form_area)
    LinearLayout mFormArea;

    private List<EditText> inputs = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_permit_form);
        ButterKnife.inject(this);
        ButterKnife.inject(this);

        mType = getIntent().getParcelableExtra("type");
        setTitle(mType.getName());
        setUpForm(mType);
    }

    public void setUpForm(PermitType type) {
        for (Map.Entry<String, String> field : type.getFieldNames().entrySet()) {
            View view = getLayoutInflater().inflate(R.layout.item_field_input, null);
            TextView label = findById(view, R.id.text1);
            EditText input = findById(view, R.id.input);
            label.setText(field.getValue());
            input.setTag(field.getKey());
            mFormArea.addView(view);
            inputs.add(input);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.form, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_submit:
                submit();
                break;

            default:
                return super.onOptionsItemSelected(item);
        }

        return true;
    }

    private void submit() {
        for (EditText input : inputs) {
            if (TextUtils.isEmpty(input.getText())) {
                toast("Harap lengkapi formulir terlebih dahulu");
                return;
            }
        }

        Permit permit = new Permit();
        permit.setUser(Session.get().getUser());
        permit.setType(mType);
        for (EditText input : inputs) {
            permit.addFieldValue(input.getTag().toString(), input.getText().toString());
        }

        PermitDB.get().addPermit(permit);

        Toast.makeText(this,
                String.format("Terima kasih. " +
                        "Permohonan anda akan diproses maksimal %d hari kerja.", mType.getMaxDays()),
                Toast.LENGTH_LONG)
                .show();

        finish();
    }
}




Java Source Code List

id.go.jogjakota.perizinan.ApplicationTest.java
id.go.jogjakota.perizinan.BaseActivity.java
id.go.jogjakota.perizinan.BaseApp.java
id.go.jogjakota.perizinan.LoginActivity.java
id.go.jogjakota.perizinan.MainActivity.java
id.go.jogjakota.perizinan.PermitDetailActivity.java
id.go.jogjakota.perizinan.PermitFormActivity.java
id.go.jogjakota.perizinan.PermitListActivity.java
id.go.jogjakota.perizinan.PermitTypeListActivity.java
id.go.jogjakota.perizinan.RegisterActivity.java
id.go.jogjakota.perizinan.SplashActivity.java
id.go.jogjakota.perizinan.StatusView.java
id.go.jogjakota.perizinan.Tag.java
id.go.jogjakota.perizinan.Transition.java
id.go.jogjakota.perizinan.TwoLineViewHolder.java
id.go.jogjakota.perizinan.data.Dummies.java
id.go.jogjakota.perizinan.data.PermitDB.java
id.go.jogjakota.perizinan.data.PermitTypes.java
id.go.jogjakota.perizinan.data.Session.java
id.go.jogjakota.perizinan.data.UserDB.java
id.go.jogjakota.perizinan.domain.PermitType.java
id.go.jogjakota.perizinan.domain.Permit.java
id.go.jogjakota.perizinan.domain.User.java