com.android.projectz.teamrocket.thebusapp.activities.SearchLineActivity.java Source code

Java tutorial

Introduction

Here is the source code for com.android.projectz.teamrocket.thebusapp.activities.SearchLineActivity.java

Source

package com.android.projectz.teamrocket.thebusapp.activities;
/*
 Copyright (C) 2016-2017  TeamRocket
    
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

import com.android.projectz.teamrocket.thebusapp.R;
import com.android.projectz.teamrocket.thebusapp.adapters.CustomListSettingMain;
import com.android.projectz.teamrocket.thebusapp.settings.SettingGeneralActivity;
import com.android.projectz.teamrocket.thebusapp.util.SharedPreferencesUtils;

/**
 * SearchLineActivity:
 * qui viene visualizzato in maniera semplice e diretta degli orari del bus
 * ***questa feature  dedicata al sito della db ma il problema che non deve
 * essere legato a questo quindi, BISOGNA CAMBIARE TUTTO***
 *
 * @author simone98dm
 * @data 04/11/2016
 */

public class SearchLineActivity extends AppCompatActivity {

    ArrayAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.setTheme(getResources().getIdentifier(SharedPreferencesUtils.getSelectedTheme(this), "style",
                getPackageName()));
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_line);

        Toolbar toolbarSearchLine = (Toolbar) findViewById(R.id.toolbarSearchLine);
        setSupportActionBar(toolbarSearchLine);
        getSupportActionBar().setTitle(R.string.title_search_line);
        getSupportActionBar().setSubtitle(R.string.subtitle_search_line);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        ListView listView = (ListView) findViewById(R.id.fullBusList);
        String[] listText = { "Belluno - Santa Giustina - Feltre", "Belluno - Mel - Feltre",
                "Belluno - Vittorio Veneto", "Belluno - Feltre - Trento", "Linea BLU", "Linea CELESTE",
                "Linea LILLA", "Linea GIALLA", "Linea ROSSA", "Linea VERDE" };

        final String[] url = { "http://dolomitibus.it/files/orari/2016-invernale/Extra/Feltrino/LINEA13_I.pdf",
                "http://dolomitibus.it/files/orari/2016-invernale/Extra/Feltrino/LINEA20_I.pdf",
                "http://dolomitibus.it/files/orari/2016-invernale/Extra/Bellunese/LINEA41_I.pdf",
                "http://dolomitibus.it/files/orari/2016-invernale/Extra/Feltrino/Linea20-27_Trento_I.pdf",
                "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950B_I.pdf",
                "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950C_I.pdf",
                "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950J_I.pdf",
                "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950L_I.pdf",
                "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950R_I.pdf",
                "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950V_I.pdf" };

        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listText);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startBrowser(url[position]);
            }
        });

        /**
         * questa editText  fatta per filtrare le linee
         */
        EditText editText = (EditText) findViewById(R.id.inputSearch);
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                SearchLineActivity.this.adapter.getFilter().filter(s);
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });
    }

    /**
     * metodo che avvia sul browser con l'url specifico
     *
     * @param url
     */
    public void startBrowser(String url) {
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(browserIntent);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            this.finish();
            SearchLineActivity.this.overridePendingTransition(R.anim.anim_slide_in_right,
                    R.anim.anim_slide_out_right);
        }
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            this.finish();
            SearchLineActivity.this.overridePendingTransition(R.anim.anim_slide_in_right,
                    R.anim.anim_slide_out_right);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}