Skip to content

Instantly share code, notes, and snippets.

@goelvibhor4
Created November 15, 2015 08:41
Show Gist options
  • Save goelvibhor4/a611093bbef793769ec1 to your computer and use it in GitHub Desktop.
Save goelvibhor4/a611093bbef793769ec1 to your computer and use it in GitHub Desktop.
package com.dignitasdigital.location;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.webkit.ConsoleMessage;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ImageButton;
import android.widget.ImageView;
import com.andtinder.model.CardModel;
import com.andtinder.view.CardContainer;
import com.andtinder.view.SimpleCardStackAdapter;
import com.squareup.picasso.Picasso;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Tinder extends Activity {
/**
* This variable is the container that will host our cards
*/
protected static final String TAG = "dyanamic tinder";
private CardContainer mCardContainer;
private List<FeedItem> feedItemList5 = new ArrayList<FeedItem>();
private static Context VContext;
ImageView imgView;
SimpleCardStackAdapter adapter = new SimpleCardStackAdapter(this);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.tinder_swipe);
VContext = getApplicationContext();
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.setWebChromeClient(new WebChromeClient() {
public boolean onConsoleMessage(ConsoleMessage cm) {
Log.d("MyApplication", cm.message() + " -- From line "
+ cm.lineNumber() + " of "
+ cm.sourceId() );
return true;
}
});
mCardContainer = (CardContainer) findViewById(R.id.layoutview);
final String url5 ="http://54.68.65.111/mozipper/mongo_api/featured_offers.php";
new AsyncHttpTask5().execute(url5);
}
public class AsyncHttpTask5 extends AsyncTask<String, Void, Integer> {
@Override
protected void onPreExecute() {
setProgressBarIndeterminateVisibility(true);
}
@Override
protected Integer doInBackground(String... params) {
InputStream inputStream = null;
Integer result = 0;
HttpURLConnection urlConnection = null;
try {
/* forming th java.net.URL object */
URL url5 = new URL(params[0]);
urlConnection = (HttpURLConnection) url5.openConnection();
/* for Get request */
urlConnection.setRequestMethod("GET");
int statusCode = urlConnection.getResponseCode();
/* 200 represents HTTP OK */
if (statusCode == 200) {
System.out.println("Status code is:" + statusCode);
BufferedReader r = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
response.append(line);
}
System.out.println("this is response" + response.toString());
parseResult5(response.toString());
result = 1; // Successful
}else{
result = 0; //"Failed to fetch data!"// ;
}
} catch (Exception e) {
Log.d(TAG, e.getLocalizedMessage());
}
return result; //"Failed to fetch data!";
}
@Override
protected void onPostExecute(Integer result) {
setProgressBarIndeterminateVisibility(false);
/* Download complete. Lets update UI */
if (result == 1) {
mCardContainer.setAdapter(adapter);
} else {
Log.e(TAG, "Failed to fetch data!");
}
}
}
private void parseResult5(String result) {
try {
imgView = (ImageView) findViewById(com.andtinder.R.id.image);
JSONObject jsonObj = new JSONObject(result);
if(jsonObj != null){
JSONArray list = jsonObj.getJSONArray("featured");
if (null == feedItemList5) {
feedItemList5 = new ArrayList<FeedItem>();
}
for (int k = 0; k < 10; k++) {
JSONObject post4 = list.optJSONObject(k);
FeedItem item = new FeedItem();
final String PostTitle= post4.getString("name");
final String PostDescription= post4.getString("description");
final String image= post4.getString("slider");
Log.d("title", PostTitle);
Log.d("image", image);
Bitmap mBitmap = Picasso.with(VContext).load("http://54.68.65.111/mozipper/slider/linux-commands.png").get();
final Drawable d = new BitmapDrawable(getResources(), mBitmap);
CardModel card = new CardModel(PostTitle,PostDescription,d);
card.setOnClickListener(new CardModel.OnClickListener() {
@Override
public void OnClickListener() {
Log.i("Swipeable Cards", "I am pressing the card");
Log.d("TITLE", PostTitle);
}
});
card.setOnCardDismissedListener(new CardModel.OnCardDismissedListener() {
@Override
public void onLike() {
Log.i("Swipeable Cards", "I like the card");
/* CardModel card = new CardModel(PostTitle, PostDescription, d);
adapter.add(card);*/
}
@Override
public void onDislike() {
Log.i("Swipeable Cards", "I dislike the card");
/*CardModel card = new CardModel(PostTitle, PostDescription, d);
adapter.add(card);*/
}
});
adapter.add(card);
}
}
}
catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment