SaveMapDialog.java
Go to the documentation of this file.
1 /*
2  * Copyright 2016 Intermodalics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package eu.intermodalics.tango_ros_streamer.android;
18 
19 import android.app.DialogFragment;
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.text.Editable;
23 import android.text.TextWatcher;
24 import android.util.Log;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.ViewGroup;
28 import android.widget.Button;
29 import android.widget.EditText;
30 
31 import java.text.DateFormat;
32 import java.text.SimpleDateFormat;
33 import java.util.Date;
34 
36 
37 
41 public class SaveMapDialog extends DialogFragment implements View.OnClickListener {
42  private static final String TAG = SaveMapDialog.class.getSimpleName();
43 
44  Button mOkButton;
45  EditText mNameEditText;
46  CallbackListener mCallbackListener;
47 
48  public interface CallbackListener {
49  void onClickOkSaveMapDialog(String name);
50  }
51 
52  @Override
53  public void onAttach(Context context) {
54  super.onAttach(context);
55  mCallbackListener = (CallbackListener) context;
56  }
57 
58  @Override
59  public View onCreateView(LayoutInflater inflator, ViewGroup container,
60  Bundle savedInstanceState) {
61  View dialogView = inflator.inflate(R.layout.dialog_save_map, null);
62  getDialog().setTitle(R.string.save_map_dialog_title);
63  mOkButton = (Button) dialogView.findViewById(R.id.save_map_ok);
64  mOkButton.setOnClickListener(this);
65  dialogView.findViewById(R.id.save_map_cancel).setOnClickListener(this);
66  mNameEditText = (EditText) dialogView.findViewById(R.id.map_name);
67  DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
68  mNameEditText.setText(dateFormat.format(new Date()) + "_map");
69  mNameEditText.addTextChangedListener(new TextWatcher() {
70  @Override
71  public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
72  // Not used.
73  }
74 
75  @Override
76  public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
77  // Not used.
78  }
79 
80  @Override
81  public void afterTextChanged(Editable editable) {
82  if (mNameEditText.getText().toString().isEmpty()) {
83  mOkButton.setEnabled(false);
84  } else {
85  mOkButton.setEnabled(true);
86  }
87  }
88  });
89  return dialogView;
90  }
91 
92  @Override
93  public void onClick(View v) {
94  switch (v.getId()) {
95  case R.id.save_map_ok:
96  Log.i(TAG, "OK");
97  mCallbackListener.onClickOkSaveMapDialog(
98  mNameEditText.getText().toString());
99  dismiss();
100  break;
101  case R.id.save_map_cancel:
102  Log.i(TAG, "CANCEL");
103  dismiss();
104  break;
105  }
106  }
107 }
View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstanceState)


TangoRosStreamer
Author(s):
autogenerated on Mon Jun 10 2019 15:37:54