Commit 63a11fb7 authored by adam's avatar adam

9/10

parents 592ae00f 6733f015
...@@ -143,6 +143,7 @@ ...@@ -143,6 +143,7 @@
<orderEntry type="library" exported="" name="play-services-games-8.3.0" level="project" /> <orderEntry type="library" exported="" name="play-services-games-8.3.0" level="project" />
<orderEntry type="library" exported="" name="play-services-gcm-8.3.0" level="project" /> <orderEntry type="library" exported="" name="play-services-gcm-8.3.0" level="project" />
<orderEntry type="library" exported="" name="play-services-safetynet-8.3.0" level="project" /> <orderEntry type="library" exported="" name="play-services-safetynet-8.3.0" level="project" />
<orderEntry type="library" exported="" name="universal-image-loader-1.9.4" level="project" />
<orderEntry type="library" exported="" name="materialish-progress-1.0" level="project" /> <orderEntry type="library" exported="" name="materialish-progress-1.0" level="project" />
<orderEntry type="library" exported="" name="design-23.1.1" level="project" /> <orderEntry type="library" exported="" name="design-23.1.1" level="project" />
<orderEntry type="library" exported="" name="library-1.3" level="project" /> <orderEntry type="library" exported="" name="library-1.3" level="project" />
......
...@@ -30,4 +30,5 @@ dependencies { ...@@ -30,4 +30,5 @@ dependencies {
compile 'com.android.support:design:23.1.1' compile 'com.android.support:design:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1' compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1' compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
} }
...@@ -30,7 +30,9 @@ ...@@ -30,7 +30,9 @@
</activity> </activity>
<activity <activity
android:name=".LoginAndRegistrationActivity" android:name=".LoginAndRegistrationActivity"
android:label="@string/title_activity_login_and_registration"></activity> android:label="@string/title_activity_login_and_registration"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
</activity>
<!-- <!--
The API key for Google Maps-based APIs is defined as a string resource. The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml"). (See the file "res/values/google_maps_api.xml").
...@@ -69,6 +71,15 @@ ...@@ -69,6 +71,15 @@
android:name=".BaseActivityWithMenu" android:name=".BaseActivityWithMenu"
android:label="@string/title_activity_base_activity_with_menu" android:label="@string/title_activity_base_activity_with_menu"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"></activity> android:theme="@style/Theme.AppCompat.Light.NoActionBar"></activity>
<activity
android:name=".AddApiActivity"
android:label="@string/title_activity_add_api"
android:parentActivityName=".MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="anotherlineofcode.com.jointhecityapp.MainActivity" />
</activity>
</application> </application>
</manifest> </manifest>
package anotherlineofcode.com.jointhecityapp;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import cn.pedant.SweetAlert.SweetAlertDialog;
import cz.msebera.android.httpclient.Header;
public class AddApiActivity extends AppCompatActivity {
private AsyncHttpClient client;
private SharedPreferences sharedPreferences;
private Context context = this;
private ArrayList<ApiObject> apiList;
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_api);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
listView = (ListView) findViewById(R.id.listview_api);
sharedPreferences = getSharedPreferences("JoinTheCityPreferences", Context.MODE_PRIVATE);
downloadApiList();
displayApiList();
AdapterView.OnItemClickListener itemClickListener = new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ApiObject selected = (ApiObject) parent.getItemAtPosition(position);
saveApi(selected.getUrl());
Log.d("SELECT", selected.getUrl());
}
};
listView.setOnItemClickListener(itemClickListener);
}
private void saveApi(String url){
client = new AsyncHttpClient();
client.addHeader("Authorization", "Token " + sharedPreferences.getString("token", ""));
Log.d("URL", url + "add/");
// Display progress bar
final SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE);
pDialog.getProgressHelper().setBarColor(Color.parseColor("#9FC967"));
pDialog.setTitleText("Zapisywanie danych...");
pDialog.setCancelable(false);
pDialog.show();
client.get(url + "add/", new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
client = null;
pDialog.dismiss();
// Display success dialog
SweetAlertDialog sDialog = new SweetAlertDialog(context, SweetAlertDialog.SUCCESS_TYPE)
.setTitleText("Dodano API!")
.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sDialog) {
sDialog.dismissWithAnimation();
// Finish activity
finish();
}
});
sDialog.setCancelable(false);
sDialog.show();
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
client = null;
pDialog.dismiss();
// Display error dialog
new SweetAlertDialog(context, SweetAlertDialog.ERROR_TYPE)
.setTitleText("Błąd")
.setContentText(error.toString())
.show();
Log.e("ERROR", error.toString());
}
});
}
private void downloadApiList(){
client = new AsyncHttpClient();
// Display progress bar
final SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE);
pDialog.getProgressHelper().setBarColor(Color.parseColor("#9FC967"));
pDialog.setTitleText("Pobieranie danych...");
pDialog.setCancelable(false);
pDialog.show();
client.get(getString(R.string.api_url) + "api/api/?only_new=True", new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
client = null;
pDialog.dismiss();
// Retrieve server response
JSONObject jsonResponse = JSONParser.parseObject(responseBody);
try {
apiList = new ArrayList<>();
for (int i = 0; i < jsonResponse.getInt("count"); i++) {
JSONObject api = jsonResponse.getJSONArray("results").getJSONObject(i);
apiList.add(new ApiObject(api.getInt("id"), api.getString("name"), api.getString("description"), api.getString("icon"), api.getString("url")));
}
listView.setAdapter(new ApiListAdapter(context, apiList));
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
client = null;
pDialog.dismiss();
// Display error dialog
new SweetAlertDialog(context, SweetAlertDialog.ERROR_TYPE)
.setTitleText("Błąd")
.setContentText(error.toString())
.show();
}
});
}
public void displayApiList(){
}
}
package anotherlineofcode.com.jointhecityapp;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.ArrayList;
public class ApiListAdapter extends ArrayAdapter<ApiObject> {
public ApiListAdapter(Context context, ArrayList<ApiObject> users) {
super(context, 0, users);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
ApiObject api = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.api_item, parent, false);
}
// Lookup view for data population
ImageView picture = (ImageView) convertView.findViewById(R.id.photo);
TextView name = (TextView) convertView.findViewById(R.id.name);
TextView description = (TextView) convertView.findViewById(R.id.description);
Button startUsing = (Button) convertView.findViewById(R.id.start);
// Populate the data into the template view using the data object
ImageLoader.getInstance().displayImage(api.getImageUrl(), picture);
name.setText(api.getName());
description.setText(api.getDescription());
startUsing.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("CLICK", v.toString());
}
});
// Return the completed view to render on screen
return convertView;
}
}
...@@ -2,19 +2,37 @@ package anotherlineofcode.com.jointhecityapp; ...@@ -2,19 +2,37 @@ package anotherlineofcode.com.jointhecityapp;
public class ApiObject { public class ApiObject {
private int id;
private String imageUrl;
private String name; private String name;
private int photo; private String description;
private String url;
ApiObject (String name, int photo){ ApiObject (int id, String name, String description, String imageUrl, String url){
this.id = id;
this.name = name; this.name = name;
this.photo = photo; this.description = description;
this.imageUrl = imageUrl;
this.url = url;
}
public int getId() {
return id;
} }
public String getName() { public String getName() {
return name; return name;
} }
public int getPhoto() { public String getDescription() {
return photo; return description;
}
public String getImageUrl() {
return imageUrl;
}
public String getUrl() {
return url;
} }
} }
...@@ -21,13 +21,13 @@ public class BaseActivityWithMenu extends AppCompatActivity { ...@@ -21,13 +21,13 @@ public class BaseActivityWithMenu extends AppCompatActivity {
int id = item.getItemId(); int id = item.getItemId();
if (id == R.id.map_view) { // if (id == R.id.map) {
Intent intent = new Intent(this, MapsActivity.class); // Intent intent = new Intent(this, MapsActivity.class);
startActivity(intent); // startActivity(intent);
return true; // return true;
} // }
if (id == R.id.friends) { if (id == R.id.api_list) {
Intent intent = new Intent(this, FriendsActivity.class); Intent intent = new Intent(this, FriendsActivity.class);
startActivity(intent); startActivity(intent);
return true; return true;
......
package anotherlineofcode.com.jointhecityapp;
import java.util.ArrayList;
import java.util.List;
public class Globals {
public static List<ApiObject> usedApi = new ArrayList<>();
}
...@@ -14,6 +14,7 @@ import android.view.View; ...@@ -14,6 +14,7 @@ import android.view.View;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.loopj.android.http.AsyncHttpClient; import com.loopj.android.http.AsyncHttpClient;
...@@ -30,7 +31,7 @@ public class LoginAndRegistrationActivity extends BaseActivityWithMenu { ...@@ -30,7 +31,7 @@ public class LoginAndRegistrationActivity extends BaseActivityWithMenu {
private AsyncHttpClient client; private AsyncHttpClient client;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private Button mLoginButton; private ImageView mLoginButton;
private EditText mUsername, mPassword; private EditText mUsername, mPassword;
private View focusView; private View focusView;
private Context context = this; private Context context = this;
...@@ -43,7 +44,7 @@ public class LoginAndRegistrationActivity extends BaseActivityWithMenu { ...@@ -43,7 +44,7 @@ public class LoginAndRegistrationActivity extends BaseActivityWithMenu {
sharedPreferences = getSharedPreferences("JoinTheCityPreferences", Context.MODE_PRIVATE); sharedPreferences = getSharedPreferences("JoinTheCityPreferences", Context.MODE_PRIVATE);
mLoginButton = (Button) findViewById(R.id.login_button); mLoginButton = (ImageView) findViewById(R.id.login_button);
mUsername = (EditText) findViewById(R.id.username); mUsername = (EditText) findViewById(R.id.username);
mPassword = (EditText) findViewById(R.id.password); mPassword = (EditText) findViewById(R.id.password);
mPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() { mPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
......
package anotherlineofcode.com.jointhecityapp; package anotherlineofcode.com.jointhecityapp;
import android.app.FragmentTransaction;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import com.google.android.gms.maps.MapFragment; import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import cz.msebera.android.httpclient.Header;
public class MainActivity extends BaseActivityWithMenu { public class MainActivity extends BaseActivityWithMenu {
public final static int LOGIN_REQUEST = 1; public final static int LOGIN_REQUEST = 1;
private MapFragment mMapFragment;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private Context context = this;
private GridLayoutManager lLayout; private AsyncHttpClient client;
private RecyclerView rView;
private RecyclerViewAdapter rcAdapter;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.drawable.logo_bar);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayShowTitleEnabled(false); DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder().cacheInMemory(true)
.cacheOnDisc(true).resetViewBeforeLoading(false).build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
this.getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.memoryCache(new WeakMemoryCache())
.discCacheSize(1024 * 1024).build();
ImageLoader.getInstance().init(config);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, AddApiActivity.class);
startActivity(intent);
}
});
sharedPreferences = getSharedPreferences("JoinTheCityPreferences", Context.MODE_PRIVATE); sharedPreferences = getSharedPreferences("JoinTheCityPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
...@@ -49,38 +83,63 @@ public class MainActivity extends BaseActivityWithMenu { ...@@ -49,38 +83,63 @@ public class MainActivity extends BaseActivityWithMenu {
// Add header and main menu fragments // Add header and main menu fragments
} }
List<ApiObject> rowListItem = getAllItemList(); // List<ApiObject> rowListItem = getAllItemList();
lLayout = new GridLayoutManager(MainActivity.this, 4); // RecyclerView.LayoutManager lLayout = new GridLayoutManager(MainActivity.this, 4);
final GridLayoutManager lLayout = new GridLayoutManager(context, 2);
RecyclerView rView = (RecyclerView)findViewById(R.id.recycler_view); rView = (RecyclerView)findViewById(R.id.recycler_view);
rView.setHasFixedSize(true); rView.setHasFixedSize(true);
rView.setLayoutManager(lLayout); rView.setLayoutManager(lLayout);
RecyclerViewAdapter rcAdapter = new RecyclerViewAdapter(MainActivity.this, rowListItem);
rView.setAdapter(rcAdapter);
} }
private List<ApiObject> getAllItemList(){ @Override
protected void onResume() {
List<ApiObject> allItems = new ArrayList<ApiObject>(); super.onResume();
allItems.add(new ApiObject("Kina", R.drawable.cinema512)); if (rView != null){
allItems.add(new ApiObject("Wypadki drogowe", R.drawable.invert512)); rView.invalidate();
allItems.add(new ApiObject("Kina", R.drawable.cinema512)); }
allItems.add(new ApiObject("Wypadki drogowe", R.drawable.invert512)); Globals.usedApi.clear();
allItems.add(new ApiObject("Kina", R.drawable.cinema512)); getUsedApiList();
allItems.add(new ApiObject("Wypadki drogowe", R.drawable.invert512)); }
allItems.add(new ApiObject("Kina", R.drawable.cinema512));
allItems.add(new ApiObject("Wypadki drogowe", R.drawable.invert512)); private void getUsedApiList(){
allItems.add(new ApiObject("Kina", R.drawable.cinema512)); client = new AsyncHttpClient();
allItems.add(new ApiObject("Wypadki drogowe", R.drawable.invert512)); client.addHeader("Authorization", "Token " + sharedPreferences.getString("token", ""));
allItems.add(new ApiObject("Kina", R.drawable.cinema512));
allItems.add(new ApiObject("Wypadki drogowe", R.drawable.invert512)); client.get(getString(R.string.api_url) + "api/user_api/", new AsyncHttpResponseHandler() {
allItems.add(new ApiObject("Kina", R.drawable.cinema512));
allItems.add(new ApiObject("Wypadki drogowe", R.drawable.invert512)); @Override
allItems.add(new ApiObject("Kina", R.drawable.cinema512)); public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
allItems.add(new ApiObject("Wypadki drogowe", R.drawable.invert512)); client = null;
return allItems; // Retrieve server response
JSONObject jsonResponse = JSONParser.parseObject(responseBody);
try {
for (int i = 0; i < jsonResponse.getInt("count"); i++) {
JSONObject api = jsonResponse.getJSONArray("results").getJSONObject(i).getJSONObject("api");
Globals.usedApi.add(new ApiObject(api.getInt("id"), api.getString("name"), api.getString("description"), api.getString("icon"), api.getString("url")));
}
List<ApiObject> rowListItem = Globals.usedApi;
rcAdapter = new RecyclerViewAdapter(context, rowListItem);
rView.setAdapter(rcAdapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
client = null;
}
});
} }
@Override @Override
......
...@@ -2,8 +2,10 @@ package anotherlineofcode.com.jointhecityapp; ...@@ -2,8 +2,10 @@ package anotherlineofcode.com.jointhecityapp;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap;
...@@ -11,19 +13,41 @@ import com.google.android.gms.maps.OnMapReadyCallback; ...@@ -11,19 +13,41 @@ import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.gms.maps.model.MarkerOptions;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.JsonHttpResponseHandler;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import cn.pedant.SweetAlert.SweetAlertDialog;
import cz.msebera.android.httpclient.Header;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap; private GoogleMap mMap;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private AsyncHttpClient client;
private final Context context = this;
private String url;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps); setContentView(R.layout.activity_maps);
sharedPreferences = getSharedPreferences("JoinTheCityPreferences", Context.MODE_PRIVATE);
url = getIntent().getExtras().getString("url");
Log.d("url", url);
// Obtain the SupportMapFragment and get notified when the map is ready to be used. // Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map); .findFragmentById(R.id.map);
mapFragment.getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(52.0, 20.0), 5.0f));
mapFragment.getMapAsync(this); mapFragment.getMapAsync(this);
} }
...@@ -41,15 +65,88 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback ...@@ -41,15 +65,88 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
public void onMapReady(GoogleMap googleMap) { public void onMapReady(GoogleMap googleMap) {
mMap = googleMap; mMap = googleMap;
sharedPreferences = getSharedPreferences("JoinTheCityPreferences", Context.MODE_PRIVATE); client = new AsyncHttpClient();
int lat = sharedPreferences.getInt("lat", 0); client.addHeader("Authorization", "Token " + sharedPreferences.getString("token", ""));
int lng = sharedPreferences.getInt("lng", 0);
Log.d("URL KURWA", url + "?method=object");
client.get(url + "?method=object", new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
client = null;
displayMarkers();
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
}
});
}
public void displayMarkers(){
client = new AsyncHttpClient();
client.addHeader("Authorization", "Token " + sharedPreferences.getString("token", ""));
// Display progress bar
final SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE);
pDialog.getProgressHelper().setBarColor(Color.parseColor("#9FC967"));
pDialog.setTitleText("Pobieranie danych...");
pDialog.setCancelable(false);
pDialog.show();
client.get(url + "parssed/?format=json", new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
super.onSuccess(statusCode, headers, response);
client = null;
pDialog.dismiss();
try {
Log.d("UPRARSED", response.toString());
for (int i=0; i<response.length(); i++){
Log.d("Data", response.toString());
JSONObject object = response.getJSONObject(i);
Log.d("Object", object.toString());
LatLng camera = new LatLng(object.getDouble("latitude"), object.getDouble("longitude"));
// Add a marker in Sydney and move the camera
mMap.addMarker(new MarkerOptions().position(camera).title(object.getString("name")).snippet(object.getString("address")));
}
//Move the camera to the user's location and zoom in!
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(50.0646501, 19.9449799), 11.0f));
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
super.onFailure(statusCode, headers, responseString, throwable);
client = null;
pDialog.dismiss();
// Display error dialog
new SweetAlertDialog(context, SweetAlertDialog.ERROR_TYPE)
.setTitleText("Błąd")
.setContentText(responseString)
.show();
Log.e("ERROR", responseString);
}
LatLng camera = new LatLng(lat, lng);
// // Add a marker in Sydney and move the camera });
// LatLng sydney = new LatLng(lat, lng);
// mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(camera));
} }
} }
...@@ -7,6 +7,9 @@ import android.view.LayoutInflater; ...@@ -7,6 +7,9 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.List; import java.util.List;
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewHolders> { public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewHolders> {
...@@ -30,7 +33,7 @@ public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewHolder ...@@ -30,7 +33,7 @@ public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewHolder
@Override @Override
public void onBindViewHolder(RecyclerViewHolders holder, int position) { public void onBindViewHolder(RecyclerViewHolders holder, int position) {
holder.countryName.setText(itemList.get(position).getName()); holder.countryName.setText(itemList.get(position).getName());
holder.countryPhoto.setImageResource(itemList.get(position).getPhoto()); ImageLoader.getInstance().displayImage(itemList.get(position).getImageUrl(), holder.countryPhoto);
} }
@Override @Override
......
package anotherlineofcode.com.jointhecityapp; package anotherlineofcode.com.jointhecityapp;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
...@@ -10,9 +13,11 @@ public class RecyclerViewHolders extends RecyclerView.ViewHolder implements View ...@@ -10,9 +13,11 @@ public class RecyclerViewHolders extends RecyclerView.ViewHolder implements View
public TextView countryName; public TextView countryName;
public ImageView countryPhoto; public ImageView countryPhoto;
private final Context context;
public RecyclerViewHolders(View itemView) { public RecyclerViewHolders(View itemView) {
super(itemView); super(itemView);
context = itemView.getContext();
itemView.setOnClickListener(this); itemView.setOnClickListener(this);
countryName = (TextView)itemView.findViewById(R.id.country_name); countryName = (TextView)itemView.findViewById(R.id.country_name);
countryPhoto = (ImageView)itemView.findViewById(R.id.country_photo); countryPhoto = (ImageView)itemView.findViewById(R.id.country_photo);
...@@ -20,6 +25,9 @@ public class RecyclerViewHolders extends RecyclerView.ViewHolder implements View ...@@ -20,6 +25,9 @@ public class RecyclerViewHolders extends RecyclerView.ViewHolder implements View
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Toast.makeText(view.getContext(), "Clicked position = " + getPosition(), Toast.LENGTH_SHORT).show(); String url = Globals.usedApi.get(getAdapterPosition()).getUrl();
final Intent intent = new Intent(context, MapsActivity.class);
intent.putExtra("url", url);
context.startActivity(intent);
} }
} }
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:thickness="0dp"
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<stroke android:width="2dp"
android:color="@color/green"/>
<corners android:radius="30dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/rounded_focused_input"
/> <!-- pressed -->
<item
android:state_focused="true"
android:drawable="@drawable/rounded_focused_input"
/> <!-- focused -->
<item
android:drawable="@drawable/rounded_unfocused_input"
/> <!-- default -->
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:thickness="0dp"
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<stroke android:width="1dp"
android:color="@color/input_border_gray"/>
<corners android:radius="30dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context="anotherlineofcode.com.jointhecityapp.AddApiActivity">
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_add_api" />
</android.support.design.widget.CoordinatorLayout>
...@@ -38,28 +38,10 @@ ...@@ -38,28 +38,10 @@
android:layout_alignParentTop="false" android:layout_alignParentTop="false"
android:layout_marginBottom="20dp" android:layout_marginBottom="20dp"
android:layout_above="@+id/messageEdit" android:layout_above="@+id/messageEdit"
android:layout_below="@+id/meLbl"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:listSelector="@android:color/transparent" android:listSelector="@android:color/transparent"
android:transcriptMode="alwaysScroll" android:transcriptMode="alwaysScroll"
android:divider="@null" /> android:divider="@null" />
<TextView
android:id="@+id/meLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:text="MySelf"
android:singleLine="false"
android:textSize="20dp" />
<TextView
android:id="@+id/friendLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Friend"
android:textSize="20dp" />
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -5,22 +5,38 @@ ...@@ -5,22 +5,38 @@
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical" android:orientation="vertical"
tools:context="anotherlineofcode.com.jointhecityapp.LoginAndRegistrationActivity"> tools:context="anotherlineofcode.com.jointhecityapp.LoginAndRegistrationActivity">
<!--android:background="@drawable/background"-->
<ImageView android:id="@+id/logo"
android:src="@drawable/logo"
android:layout_width="200dp"
android:layout_gravity="center_horizontal"
android:layout_height="100dp"
android:layout_marginTop="10dp"/>
<EditText android:id="@+id/username" <EditText android:id="@+id/username"
android:layout_marginTop="40dp"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="text" android:inputType="text"
android:gravity="center"
android:hint="Nazwa użytkownika" android:hint="Nazwa użytkownika"
android:maxLines="1" android:maxLines="1"
android:singleLine="true"/> android:singleLine="true"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textColor="#696969"
android:ellipsize="start"
android:background="@drawable/rounded_input"/>
<EditText android:id="@+id/password" <EditText android:id="@+id/password"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="textPassword" android:inputType="textPassword"
android:gravity="center"
android:hint="Hasło" android:hint="Hasło"
android:imeActionId="@+id/password_ime" android:imeActionId="@+id/password_ime"
android:imeActionLabel="@string/action_sign_in" android:imeActionLabel="@string/action_sign_in"
...@@ -28,14 +44,37 @@ ...@@ -28,14 +44,37 @@
android:maxLines="1" android:maxLines="1"
android:singleLine="true" android:singleLine="true"
android:layout_marginTop="30dp"/> android:layout_marginTop="20dp"
<Button android:id="@+id/login_button" android:paddingLeft="20dp"
android:layout_width="fill_parent" android:paddingTop="10dp"
android:layout_height="wrap_content" android:paddingBottom="10dp"
android:text="Zaloguj"
android:textColor="#696969"
android:ellipsize="start"
android:background="@drawable/rounded_input"/>
<ImageView android:id="@+id/login_button"
android:layout_width="100dp"
android:layout_height="50dp"
android:gravity="center" android:gravity="center"
android:layout_gravity="center_horizontal"
android:src="@drawable/login"
android:layout_marginTop="50dp"/>
android:layout_marginTop="200dp"/> <ImageView
android:layout_marginTop="30dp"
android:layout_gravity="center_horizontal"
android:layout_width="35dp"
android:layout_height="20dp"
android:src="@drawable/or"/>
<ImageView android:id="@+id/register_button"
android:layout_width="100dp"
android:layout_height="50dp"
android:gravity="center"
android:layout_gravity="center_horizontal"
android:src="@drawable/register"
android:layout_marginTop="30dp"/>
</LinearLayout> </LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
android:orientation="vertical" tools:context=".MainActivity"> <!--android:background="@drawable/background">-->
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
...@@ -12,10 +12,15 @@ ...@@ -12,10 +12,15 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:scrollbars="vertical" /> android:scrollbars="vertical" />
<FrameLayout android:id="@+id/content" <android.support.design.widget.FloatingActionButton android:id="@+id/fab"
android:layout_width="fill_parent" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"> android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/cross"
app:backgroundTint="@color/green"
android:layout_marginLeft="@dimen/fab_margin"
android:layout_marginRight="@dimen/fab_margin"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="@dimen/activity_vertical_margin"/>
</FrameLayout> </RelativeLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:layout_marginTop="20dp"
android:paddingRight="10dp"
android:paddingLeft="10dp">
<ImageView android:id="@+id/photo"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_rowSpan="2"
android:layout_column="0"
android:layout_row="0"
android:padding="5dp"
android:src="@drawable/ic_launcher" />
<TextView android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="0"
android:maxLines="1"
android:singleLine="true"
android:text="Name"/>
<TextView android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="1"
android:text="Description"/>
<Button android:id="@+id/start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnSpan="2"
android:layout_row="2"
android:text="Zacznij używać"
android:focusable="false"/>
</GridLayout>
\ No newline at end of file
...@@ -15,12 +15,10 @@ ...@@ -15,12 +15,10 @@
<ImageView <ImageView
android:id="@+id/country_photo" android:id="@+id/country_photo"
android:layout_width="50dp" android:layout_width="100dp"
android:layout_height="50dp" android:layout_height="100dp"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:padding="5dp" android:padding="2dp"
android:contentDescription="@string/action_settings"
android:src="@drawable/common_google_signin_btn_icon_dark_normal"
android:scaleType="centerCrop" /> android:scaleType="centerCrop" />
<TextView <TextView
...@@ -28,7 +26,6 @@ ...@@ -28,7 +26,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="13sp" android:textSize="13sp"
android:text="Description"
android:gravity="center" android:gravity="center"
android:layout_below="@+id/country_photo" android:layout_below="@+id/country_photo"
android:paddingBottom="4dp" android:paddingBottom="4dp"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_add_api"
tools:context="anotherlineofcode.com.jointhecityapp.AddApiActivity">
<ListView android:id="@+id/listview_api"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true">
</ListView>
</RelativeLayout>
<?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:layout_margin="20dp">
<TextView
android:id="@+id/discussion_name"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:background="@drawable/in_message_bg"
/>
<TextView
android:id="@+id/discussion_owner"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_margin="10dp"
></TextView>
</LinearLayout>
\ No newline at end of file
...@@ -6,31 +6,14 @@ ...@@ -6,31 +6,14 @@
<item <item
android:id="@+id/api_list" android:id="@+id/api_list"
android:icon="@drawable/ic_launcher" android:icon="@drawable/api_list"
android:title="Lista API" android:title="Lista API"
app:showAsAction="always"/> app:showAsAction="ifRoom"/>
<item
android:id="@+id/friends"
android:icon="@drawable/ic_launcher"
android:title="Znajomi"
app:showAsAction="always"/>
<item <item
android:id="@+id/messages" android:id="@+id/messages"
android:icon="@drawable/ic_launcher" android:icon="@drawable/message"
android:title="Wiadomości" android:title="Wiadomości"
app:showAsAction="always"/> app:showAsAction="ifRoom"/>
<item
android:id="@+id/map_view"
android:icon="@drawable/ic_launcher"
android:title="Mapa"
app:showAsAction="always"/>
<item
android:id="@+id/logo"
android:icon="@drawable/ic_launcher"
android:title="Logo"
app:showAsAction="always"/>
</menu> </menu>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="green">#9FC967</color>
<color name="white">#FFFFFF</color>
<color name="gray">#F6F6F6</color>
<color name="input_border_gray">#BABABA</color>
<color name="text_color_gray">#696969</color>
</resources>
\ No newline at end of file
...@@ -18,4 +18,5 @@ ...@@ -18,4 +18,5 @@
<string name="title_activity_base_activity_with_menu">BaseActivityWithMenu</string> <string name="title_activity_base_activity_with_menu">BaseActivityWithMenu</string>
<string name="discussion_link">Discussion link</string> <string name="discussion_link">Discussion link</string>
<string name="title_activity_add_api">AddApiActivity</string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment