-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.java
101 lines (78 loc) · 3.38 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.example.memeshare;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.ViewTarget;
import com.squareup.picasso.Picasso;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity {
// ImageView img;
// ProgressBar progressBar;
// final ProgressBar progressBar = (ProgressBar) findViewById(R.id.loader);
String currentURL = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadMeme();
}
private void loadMeme () {
// progressBar.setVisibility(View.VISIBLE);
RequestQueue requestQueue = Volley.newRequestQueue(this);
currentURL = "https://meme-api.herokuapp.com/gimme";
final ImageView imageView = (ImageView) findViewById(R.id.memeImg);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, currentURL, null, new Response.Listener<JSONObject>(){
@Override
public void onResponse(JSONObject response) {
try {
String display_url = response.getString("url");
Glide.with(MainActivity.this).load(display_url).into(imageView);
// Picasso.with(this).load(url).into(imageView);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Log.d("myApp", "Error hai bhai..");
Toast.makeText(MainActivity.this, "Something went wrong!", Toast.LENGTH_SHORT).show();
}
});
requestQueue.add(jsonObjectRequest);
}
public void shareMeme(View view) {
// Intent intent = new Intent(Intent.ACTION_SEND);
// intent.setType("text/plain");
// intent.putExtra(Intent.EXTRA_TEXT, "Hey Buddy! Checkout this awesome meme $url");
// Intent chooser = Intent.createChooser(intent, "Checkout this meme..");
// startActivity(chooser);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Hey! Checkout this meme I got from Reddit! \n\n" + currentURL);
Intent chooser = Intent.createChooser(intent, "Share this meme using..");
startActivity(chooser);
}
public void nextMeme(View view) {
loadMeme();
}
}