aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui/dialog/EditorDialog.java
blob: 4db69e52a54035e41fb092ca21dabf2f94908e93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cgeo.geocaching.ui.dialog;

import cgeo.geocaching.CacheDetailActivity;
import cgeo.geocaching.R;
import cgeo.geocaching.activity.ActivityMixin;

import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

public class EditorDialog extends Dialog {

    private CharSequence editorText;
    private EditorUpdate editorUpdate;

    public EditorDialog(CacheDetailActivity cacheDetailActivity, CharSequence editable) {
        super(cacheDetailActivity, ActivityMixin.getTheme());
        this.editorText = editable;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.editor);

        final EditText editText = (EditText) findViewById(R.id.editorEditText);
        editText.setText(editorText);

        final Button buttonSave = (Button) findViewById(R.id.editorSave);
        buttonSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editorUpdate.update(editText.getEditableText());
                EditorDialog.this.hide();
            }
        });
    }

    public interface EditorUpdate {
        public void update(CharSequence editorText);
    }

    public void setOnEditorUpdate(EditorUpdate editorUpdate) {
        this.editorUpdate = editorUpdate;

    }

    @Override
    public void show() {
        super.show();
        getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    }

}