package com.ecom.park_jy;

import android.content.Intent;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Car_mark extends AppCompatActivity {
    ListView listView;
    String[] car_type;
    String findin,findout;
    Intent intent = new Intent();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_car_mark);

        listView = (ListView)findViewById(R.id.car_mark);
        List list = new ArrayList();
        File car = new File(Environment.getExternalStorageDirectory() + "/Park_JY/BrandOfCar.temp");

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(car)));
            while((findin = reader.readLine()) != null){
                findout = findin;
                car_type = findout.split("\n");
                for(int i = 0; i < car_type.length; i++){
                    list.add(car_type[i]);
                }
            }
            reader.close();
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
        ArrayAdapter adapter = new ArrayAdapter(this,R.layout.skin_user_list_text,R.id.textView43,list);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String name = (String)listView.getItemAtPosition(position);
                intent.putExtra("Car_MARK",name);
                setResult(RESULT_OK,intent);
                finish();
            }
        });
    }
}
