Simple embedded Video app
First XML code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:orientation="vertical"
android:background="#1C297C"
android:gravity="center_horizontal"
tools:context=".MainActivity">
<TextView
android:id="@+id/topText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/hedar_color"
android:fontFamily="@font/font_ruposhi"
android:gravity="center"
android:padding="25dp"
android:text="Islamic Song"
android:textColor="@color/white"
android:textSize="25sp"
android:textStyle="bold" />
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/topText"/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="54dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_below="@id/topText"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:padding="150dp"
android:foregroundGravity="center"
android:visibility="visible" />
</RelativeLayout>
<RelativeLayout 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:orientation="vertical"
android:background="#1C297C"
android:gravity="center_horizontal"
tools:context=".MainActivity">
<TextView
android:id="@+id/topText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/hedar_color"
android:fontFamily="@font/font_ruposhi"
android:gravity="center"
android:padding="25dp"
android:text="Islamic Song"
android:textColor="@color/white"
android:textSize="25sp"
android:textStyle="bold" />
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/topText"/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="54dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_below="@id/topText"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:padding="150dp"
android:foregroundGravity="center"
android:visibility="visible" />
</RelativeLayout>
Second item.xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_margin="3dp"
android:layout_height="match_parent">
<WebView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="260dp"
android:scaleType="centerCrop"
android:src="@drawable/image_item" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="20sp"
android:fontFamily="@font/font_ruposhi"
android:text="Title Here" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_margin="3dp"
android:layout_height="match_parent">
<WebView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="260dp"
android:scaleType="centerCrop"
android:src="@drawable/image_item" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="20sp"
android:fontFamily="@font/font_ruposhi"
android:text="Title Here" />
</LinearLayout>
Third Java code
ListView listView;
ProgressBar progressBar;
ArrayList<HashMap<String,String>>arrayList = new ArrayList<>();
HashMap<String,String>hashMap;
ProgressBar progressBar;
ArrayList<HashMap<String,String>>arrayList = new ArrayList<>();
HashMap<String,String>hashMap;
progressBar = findViewById(R.id.progressBar);
listView = findViewById(R.id.listView);
String url = "https://thispractice.000webhostapp.com/apps/video.json";
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url, null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
progressBar.setVisibility(View.GONE);
try {
for (int x=0; x<response.length(); x++){
JSONObject jsonObject = response.getJSONObject(x);
String title =jsonObject.getString("title");
String vide_url = jsonObject.getString("video_url");
HashMap<String,String> hashMap = new HashMap<>();
hashMap.put("title",title);
hashMap.put("video_url",vide_url);
arrayList.add(hashMap);
} // <<<<<<<<----***END for Loop***---->>>>>>>>
MyAdapter myAdapter = new MyAdapter();
listView.setAdapter(myAdapter);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressBar.setVisibility(View.GONE);
}
});
RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
requestQueue.add(jsonArrayRequest);
} // <<<<<<<<----***END OnCreate Method***---->>>>>>>>
private class MyAdapter extends BaseAdapter {
@Override
public int getCount() {
return arrayList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = getLayoutInflater();
View myView = layoutInflater.inflate(R.layout.item, null);
WebView video = myView.findViewById(R.id.imageView);
TextView Title = myView.findViewById(R.id.textView);
video.getSettings().setJavaScriptEnabled(true);
HashMap<String, String> hashMap = arrayList.get(position);
String sVideo = hashMap.get("video_url");
String sTitle = hashMap.get("title");
Log.d("MyAdapter", "Title: " + sTitle);
video.loadUrl(sVideo);
Title.setText(sTitle);
return myView;
}
}
listView = findViewById(R.id.listView);
String url = "https://thispractice.000webhostapp.com/apps/video.json";
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url, null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
progressBar.setVisibility(View.GONE);
try {
for (int x=0; x<response.length(); x++){
JSONObject jsonObject = response.getJSONObject(x);
String title =jsonObject.getString("title");
String vide_url = jsonObject.getString("video_url");
HashMap<String,String> hashMap = new HashMap<>();
hashMap.put("title",title);
hashMap.put("video_url",vide_url);
arrayList.add(hashMap);
} // <<<<<<<<----***END for Loop***---->>>>>>>>
MyAdapter myAdapter = new MyAdapter();
listView.setAdapter(myAdapter);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressBar.setVisibility(View.GONE);
}
});
RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
requestQueue.add(jsonArrayRequest);
} // <<<<<<<<----***END OnCreate Method***---->>>>>>>>
private class MyAdapter extends BaseAdapter {
@Override
public int getCount() {
return arrayList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = getLayoutInflater();
View myView = layoutInflater.inflate(R.layout.item, null);
WebView video = myView.findViewById(R.id.imageView);
TextView Title = myView.findViewById(R.id.textView);
video.getSettings().setJavaScriptEnabled(true);
HashMap<String, String> hashMap = arrayList.get(position);
String sVideo = hashMap.get("video_url");
String sTitle = hashMap.get("title");
Log.d("MyAdapter", "Title: " + sTitle);
video.loadUrl(sVideo);
Title.setText(sTitle);
return myView;
}
}
Post a Comment