package com.example.mountaintravel.view;

import com.example.mountaintravel.adapter.roadAdapter;
import com.smart.gtstrvl.R;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
public class MyDialog {

	Context context;
	Dialogcallback dialogcallback;
	Dialog dialog;
	public TextView textView;
	ListView listView;
	ImageButton roadUp,roadDown;
	private int road_index;
	public MyDialog(Context con) {
		this.context = con;
		dialog = new Dialog(context, R.style.dialog);
		dialog.setContentView(R.layout.dialog);
		textView=(TextView) dialog.findViewById(R.id.road_title);
		roadUp=(ImageButton) dialog.findViewById(R.id.road_list_up);
		roadDown=(ImageButton) dialog.findViewById(R.id.road_list_down);
		listView = (ListView) dialog.findViewById(R.id.device_list);
		road_index = listView.getFirstVisiblePosition();
		roadUp.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(road_index!=3){
					road_index++;
				}
				listView.setSelectionFromTop(road_index, 0);
				
			}
		});
		roadDown.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
					if(road_index!=0){
						road_index--;
					}
					listView.setSelectionFromTop(road_index, 0);
			}
		});
		
		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				dialogcallback.dialogdo(arg2);
				dismiss();
			}
		});
	}

	public interface Dialogcallback {
		public void dialogdo(int string);
	}

	public void setDialogCallback(Dialogcallback dialogcallback) {
		this.dialogcallback = dialogcallback;
	}
	
	public void setContent(roadAdapter adapter) {
		listView.setAdapter(adapter);
	}

	public void show() {
		dialog.show();
	}

	public void hide() {
		dialog.hide();
	}

	public void dismiss() {
		dialog.dismiss();
	}

}
