This commit is contained in:
aminecmi 2015-07-08 19:16:41 +02:00
parent 243ee723ed
commit 62f8455e5d
21 changed files with 478 additions and 64 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,7 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amine.myterio.app" >
<manifest
package="com.amine.myterio.app"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
@ -16,6 +19,18 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SearchActivity"
android:label="@string/title_activity_search"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.amine.myterio.app.MainActivity"/>
</activity>
<activity
android:name=".DetailsActivity"
android:label="@string/title_activity_details">
</activity>
</application>
</manifest>

View File

@ -0,0 +1,39 @@
package com.amine.myterio.app;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
public class DetailsActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_details, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -1,5 +1,6 @@
package com.amine.myterio.app;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
@ -8,6 +9,8 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.amine.myterio.app.adapters.CitiesAdapter;
import com.amine.myterio.app.db.CityDAO;
import com.amine.myterio.app.model.City;
import com.melnykov.fab.FloatingActionButton;
@ -76,7 +79,13 @@ public class MainActivity extends AppCompatActivity {
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.attachToRecyclerView(mRecyclerView);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SearchActivity.class);
startActivity(intent);
}
});
}

View File

@ -0,0 +1,102 @@
package com.amine.myterio.app;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.*;
import com.amine.myterio.app.api.CitiesAdapters;
import com.amine.myterio.app.api.CitiesApi;
import com.amine.myterio.app.api.Predictions;
import com.amine.myterio.app.config.Config;
import com.amine.myterio.app.model.Countries;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
import java.util.ArrayList;
import java.util.List;
public class SearchActivity extends AppCompatActivity {
private final List<String> citiesArray = new ArrayList<String>();
private Countries countries;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
final SearchView s = (SearchView) findViewById(R.id.searchView);
ListView l = (ListView) findViewById(R.id.listView2);
final ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, citiesArray);
l.setAdapter(adapter);
l.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView t = (TextView) view;
s.setQuery(t.getText(), true);
}
});
s.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Intent intent = new Intent(SearchActivity.this, DetailsActivity.class);
startActivity(intent);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
final boolean[] found = {false};
CitiesAdapters adapters = new CitiesAdapters();
CitiesApi.AutocompleteApi s = adapters.getCitiesForAutocomplete();
s.autocompletePlace(newText, Config.placesApiKey, new Callback<Predictions>() {
@Override
public void success(Predictions predictions, Response response) {
List<String> cities = predictions.getCities();
citiesArray.clear();
found[0] = !cities.isEmpty();
citiesArray.addAll(cities);
adapter.notifyDataSetChanged();
}
@Override
public void failure(RetrofitError error) {
Toast.makeText(getApplicationContext(), "Erreur lors de la récupération des pays", Toast.LENGTH_SHORT).show();
}
});
return found[0];
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_search, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -1,4 +1,4 @@
package com.amine.myterio.app;
package com.amine.myterio.app.adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
@ -8,6 +8,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.amine.myterio.app.R;
import com.amine.myterio.app.api.WeatherAdapters;
import com.amine.myterio.app.api.WeatherApis;
import com.amine.myterio.app.model.City;
@ -21,21 +22,6 @@ public class CitiesAdapter extends RecyclerView.Adapter<CitiesAdapter.ViewHolder
private static ArrayList<City> mDataset;
private static Context c;
public class ViewHolder extends RecyclerView.ViewHolder implements RecyclerView.OnClickListener{
public View mCardView;
public ViewHolder(View itemView) {
super(itemView);
mCardView = itemView;
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// Go to details activity
}
}
public CitiesAdapter(ArrayList<City> cities, Context c) {
mDataset = cities;
this.c = c;
@ -62,6 +48,9 @@ public class CitiesAdapter extends RecyclerView.Adapter<CitiesAdapter.ViewHolder
currentCity[0] = city;
// Update with found data
TextView temp = (TextView) holder.mCardView.findViewById(R.id.temp);
temp.setText("" + city.getMain().getTemp());
TextView maxTemp = (TextView) holder.mCardView.findViewById(R.id.max_temp);
maxTemp.setText("" + city.getMain().getTemp_max());
@ -89,4 +78,19 @@ public class CitiesAdapter extends RecyclerView.Adapter<CitiesAdapter.ViewHolder
public int getItemCount() {
return mDataset.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements RecyclerView.OnClickListener {
public View mCardView;
public ViewHolder(View itemView) {
super(itemView);
mCardView = itemView;
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// Go to details activity
}
}
}

View File

@ -0,0 +1,17 @@
package com.amine.myterio.app.api;
import retrofit.RestAdapter;
public class CitiesAdapters {
RestAdapter restAdapter;
public CitiesAdapters() {
this.restAdapter = new RestAdapter.Builder()
.setEndpoint("https://maps.googleapis.com")
.build();
}
public CitiesApi.AutocompleteApi getCitiesForAutocomplete() {
return restAdapter.create(CitiesApi.AutocompleteApi.class);
}
}

View File

@ -0,0 +1,12 @@
package com.amine.myterio.app.api;
import retrofit.Callback;
import retrofit.http.GET;
import retrofit.http.Query;
public class CitiesApi {
public interface AutocompleteApi {
@GET("/maps/api/place/autocomplete/json")
void autocompletePlace(@Query("input") String location, @Query("key") String apiKey, Callback<Predictions> cb);
}
}

View File

@ -0,0 +1,19 @@
package com.amine.myterio.app.api;
import com.amine.myterio.app.model.City;
public class PredictionCities {
public String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public City toCity() {
return new City(this.description);
}
}

View File

@ -0,0 +1,24 @@
package com.amine.myterio.app.api;
import java.util.ArrayList;
import java.util.List;
public class Predictions {
public List<PredictionCities> predictions;
public List<PredictionCities> getPredictions() {
return predictions;
}
public void setPredictions(List<PredictionCities> predictions) {
this.predictions = predictions;
}
public ArrayList<String> getCities() {
ArrayList<String> cities = new ArrayList<String>();
for (PredictionCities city : predictions) {
cities.add(city.toCity().getName());
}
return cities;
}
}

View File

@ -0,0 +1,5 @@
package com.amine.myterio.app.config;
public class Config {
public static String placesApiKey = "AIzaSyDxSXMcZK1Ybjkz-IuN2EhhFCwRSbaianE";
}

View File

@ -20,6 +20,10 @@ public class City {
}
public City(String description) {
this.name = description;
}
public String getName() {
return name;

View File

@ -0,0 +1,20 @@
package com.amine.myterio.app.model;
import java.util.ArrayList;
import java.util.List;
public class Countries {
public List<Country> countries;
public Countries() {
countries = new ArrayList<Country>();
}
public List<Country> getCountries() {
return countries;
}
public void setCountries(List<Country> countries) {
this.countries = countries;
}
}

View File

@ -0,0 +1,29 @@
package com.amine.myterio.app.model;
import java.util.ArrayList;
import java.util.List;
public class Country {
public String name;
public List<City> cities;
public Country() {
cities = new ArrayList<City>();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<City> getCities() {
return cities;
}
public void setCities(List<City> cities) {
this.cities = cities;
}
}

View File

@ -5,24 +5,24 @@ public class MainInfo {
public float temp_max;
public float temp_min;
public float getTemp() {
return temp;
public int getTemp() {
return Math.round(temp);
}
public void setTemp(float temp) {
this.temp = temp;
}
public float getTemp_max() {
return temp_max;
public int getTemp_max() {
return Math.round(temp_max);
}
public void setTemp_max(float temp_max) {
this.temp_max = temp_max;
}
public float getTemp_min() {
return temp_min;
public int getTemp_min() {
return Math.round(temp_min);
}
public void setTemp_min(float temp_min) {

View File

@ -0,0 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.amine.myterio.app.DetailsActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"/>
</RelativeLayout>

View File

@ -0,0 +1,27 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.amine.myterio.app.SearchActivity">
<SearchView
android:id="@+id/searchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"/>
<ListView
android:id="@+id/listView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/searchView"/>
</RelativeLayout>

View File

@ -1,94 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="2dp"
android:orientation="vertical"
android:padding="10dp">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:padding="2dp"
card_view:cardCornerRadius="2dp"
android:elevation="2dp">
card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal">
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/left_card_part"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".5"
android:id="@+id/left_card_part">
android:layout_weight=".5">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/name"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="25dp"/>
android:layout_alignParentTop="true"
android:layout_marginTop="25dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView
android:id="@+id/temp_min"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_alignLeft="@+id/max_temp"
android:layout_alignStart="@+id/max_temp"
android:layout_alignTop="@+id/imageView2"
android:text="Medium Text"
android:id="@+id/temp_min"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="@+id/max_temp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView"
android:layout_toEndOf="@+id/imageView"
android:layout_toRightOf="@+id/imageView"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_above="@+id/imageView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="7dp"
android:src="@mipmap/ic_max"
android:tint="#d50000"/>
<ImageView
android:id="@+id/imageView2"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="25dp"/>
android:layout_marginBottom="5dp"
android:src="@mipmap/ic_min"
android:tint="#0091ea"/>
<TextView
android:id="@+id/temp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Medium Text"
android:id="@+id/max_temp"
android:layout_above="@+id/temp_min"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="25dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".5"
android:id="@+id/right_card_part">
android:textAppearance="?android:attr/textAppearanceMedium"/>
<ImageView
android:id="@+id/imageView4"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/temp"
android:layout_toStartOf="@+id/temp"
android:src="@mipmap/ic_temp"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/right_card_part"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".5">
<ImageView
android:id="@+id/weather_image"
android:layout_width="128dp"
android:layout_height="128dp"
android:id="@+id/weather_image"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<TextView
android:id="@+id/wind_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/wind_speed"
android:layout_below="@+id/weather_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"/>
android:layout_marginTop="25dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<TextView
android:id="@+id/weather_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/weather_text"
android:layout_above="@+id/weather_image"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp"/>
android:layout_marginBottom="25dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<ImageView
android:id="@+id/imageView3"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignBottom="@+id/wind_speed"
android:layout_alignLeft="@+id/weather_image"
android:layout_alignStart="@+id/weather_image"
android:src="@mipmap/ic_wind"/>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

View File

@ -0,0 +1,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.amine.myterio.app.DetailsActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
</menu>

View File

@ -0,0 +1,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.amine.myterio.app.SearchActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
</menu>

View File

@ -2,4 +2,6 @@
<string name="app_name">Myterio</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="title_activity_search">SearchActivity</string>
<string name="title_activity_details">DetailsActivity</string>
</resources>