Sie sind auf Seite 1von 2

/*

* Copyright (C) 2016 The Android Open Source Project


*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.quakereport;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;
import android.app.LoaderManager;
import android.content.Loader;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.example.android.quakereport.Utilities.QueryUtils;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class EarthquakeActivity extends AppCompatActivity {

public static final String LOG_TAG = EarthquakeActivity.class.getName();


private static final String URL_STRING =
"https://earthquake.usgs.gov/fdsnws/event/1/query?
format=geojson&eventtype=earthquake&minmag=4&limit=600";
private static final String URL_STRING2 =
"https://earthquake.usgs.gov/fdsnws/event/1/query?
format=geojson&eventtype=earthquake&minmag=4&limit=6";
private ListView mMainListView;

CustomAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.earthquake_activity);

mMainListView = (ListView) findViewById(R.id.lv_main);


adapter = new CustomAdapter(getApplicationContext(),new
ArrayList<Earthquake>());
mMainListView.setAdapter(adapter);
mMainListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i,
long l) {
Earthquake earthquake = adapter.getItem(i);
Uri uri = Uri.parse(earthquake.getUri());
Intent intent = new Intent(Intent.ACTION_VIEW,uri);

if(intent.resolveActivity(getPackageManager()) != null){
startActivity(intent);
}
}
});

getLoaderManager().initLoader(0,null,callbacks);
}

LoaderManager.LoaderCallbacks<List<Earthquake>> callbacks
= new LoaderManager.LoaderCallbacks<List<Earthquake>>() {
@Override
public Loader<List<Earthquake>> onCreateLoader(int id, Bundle args) {
return new EarthquakeLoader(getApplicationContext(),URL_STRING);
}

@Override
public void onLoadFinished(Loader<List<Earthquake>> loader,
List<Earthquake> data) {
adapter.clear();
if(data != null){
adapter.addAll(data);
}else{
Toast.makeText(getApplicationContext(),"No Results
Found",Toast.LENGTH_LONG).show();
}
}

@Override
public void onLoaderReset(Loader<List<Earthquake>> loader) {
adapter.clear();
}
};