SaveMapDialog.java
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 Intermodalics All Rights Reserved.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 package eu.intermodalics.tango_ros_streamer.android;
00018 
00019 import android.app.DialogFragment;
00020 import android.content.Context;
00021 import android.os.Bundle;
00022 import android.text.Editable;
00023 import android.text.TextWatcher;
00024 import android.util.Log;
00025 import android.view.LayoutInflater;
00026 import android.view.View;
00027 import android.view.ViewGroup;
00028 import android.widget.Button;
00029 import android.widget.EditText;
00030 
00031 import java.text.DateFormat;
00032 import java.text.SimpleDateFormat;
00033 import java.util.Date;
00034 
00035 import eu.intermodalics.tango_ros_streamer.R;
00036 
00037 
00041 public class SaveMapDialog extends DialogFragment implements View.OnClickListener {
00042     private static final String TAG = SaveMapDialog.class.getSimpleName();
00043 
00044     Button mOkButton;
00045     EditText mNameEditText;
00046     CallbackListener mCallbackListener;
00047 
00048     public interface CallbackListener {
00049         void onClickOkSaveMapDialog(String name);
00050     }
00051 
00052     @Override
00053     public void onAttach(Context context) {
00054         super.onAttach(context);
00055         mCallbackListener = (CallbackListener) context;
00056     }
00057 
00058     @Override
00059     public View onCreateView(LayoutInflater inflator, ViewGroup container,
00060                              Bundle savedInstanceState) {
00061         View dialogView = inflator.inflate(R.layout.dialog_save_map, null);
00062         getDialog().setTitle(R.string.save_map_dialog_title);
00063         mOkButton = (Button) dialogView.findViewById(R.id.save_map_ok);
00064         mOkButton.setOnClickListener(this);
00065         dialogView.findViewById(R.id.save_map_cancel).setOnClickListener(this);
00066         mNameEditText = (EditText) dialogView.findViewById(R.id.map_name);
00067         DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
00068         mNameEditText.setText(dateFormat.format(new Date()) + "_map");
00069         mNameEditText.addTextChangedListener(new TextWatcher() {
00070             @Override
00071             public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
00072                 // Not used.
00073             }
00074 
00075             @Override
00076             public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
00077                 // Not used.
00078             }
00079 
00080             @Override
00081             public void afterTextChanged(Editable editable) {
00082                 if (mNameEditText.getText().toString().isEmpty()) {
00083                     mOkButton.setEnabled(false);
00084                 } else {
00085                     mOkButton.setEnabled(true);
00086                 }
00087             }
00088         });
00089         return dialogView;
00090     }
00091 
00092     @Override
00093     public void onClick(View v) {
00094         switch (v.getId()) {
00095             case R.id.save_map_ok:
00096                 Log.i(TAG, "OK");
00097                 mCallbackListener.onClickOkSaveMapDialog(
00098                         mNameEditText.getText().toString());
00099                 dismiss();
00100                 break;
00101             case R.id.save_map_cancel:
00102                 Log.i(TAG, "CANCEL");
00103                 dismiss();
00104                 break;
00105         }
00106     }
00107 }


TangoRosStreamer
Author(s):
autogenerated on Thu Jun 6 2019 19:49:58