Skip to content

Commit 59308af

Browse files
author
Arnav Gupta
committed
add progress bar to instapaper viewer webview
1 parent 4fe1014 commit 59308af

File tree

4 files changed

+50
-12
lines changed

4 files changed

+50
-12
lines changed

App/src/main/java/in/ac/dtu/subtlenews/InstapaperViewer.java

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import in.ac.dtu.subtlenews.util.SystemUiHider;
44

5+
import android.annotation.SuppressLint;
56
import android.annotation.TargetApi;
67
import android.app.Activity;
78
import android.content.DialogInterface;
@@ -13,10 +14,12 @@
1314
import android.view.View;
1415
import android.view.MenuItem;
1516
import android.support.v4.app.NavUtils;
17+
import android.webkit.WebChromeClient;
1618
import android.webkit.WebView;
1719
import android.widget.Button;
1820
import android.widget.FrameLayout;
1921
import android.widget.LinearLayout;
22+
import android.widget.ProgressBar;
2023

2124
import org.json.JSONException;
2225
import org.json.JSONObject;
@@ -63,12 +66,17 @@ public class InstapaperViewer extends Activity {
6366
*/
6467
private SystemUiHider mSystemUiHider;
6568

69+
@SuppressLint("NewApi")
6670
@Override
6771
protected void onCreate(Bundle savedInstanceState) {
6872
super.onCreate(savedInstanceState);
73+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
74+
setImmersive(true);
75+
}
76+
setTheme(R.style.AppTheme_NoActionBar);
6977

7078
setContentView(R.layout.activity_instapaper_viewer);
71-
setupActionBar();
79+
//setupActionBar();
7280

7381
Bundle extras = getIntent().getExtras();
7482
if (extras != null) {
@@ -77,6 +85,25 @@ protected void onCreate(Bundle savedInstanceState) {
7785

7886
}
7987
final WebView instapaperView = (WebView) findViewById(R.id.instapaper_viewer);
88+
final Activity activity = this;
89+
final ProgressBar progressBar;
90+
progressBar = (ProgressBar) findViewById(R.id.progressBar);
91+
92+
instapaperView.setWebChromeClient(new WebChromeClient() {
93+
public void onProgressChanged(WebView view, int progress)
94+
{
95+
if(progress < 100 && progressBar.getVisibility() == ProgressBar.GONE){
96+
progressBar.setVisibility(ProgressBar.VISIBLE);
97+
//txtview.setVisibility(View.VISIBLE);
98+
}
99+
progressBar.setProgress(progress);
100+
if(progress == 100) {
101+
progressBar.setVisibility(ProgressBar.GONE);
102+
//txtview.setVisibility(View.GONE);
103+
}
104+
}
105+
});
106+
80107

81108
final View controlsView = findViewById(R.id.fullscreen_content_controls);
82109
final View contentView = findViewById(R.id.instapaper_viewer);
@@ -97,7 +124,7 @@ protected void onCreate(Bundle savedInstanceState) {
97124
@Override
98125
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
99126
public void onVisibilityChange(boolean visible) {
100-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
127+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
101128
// If the ViewPropertyAnimator API is available
102129
// (Honeycomb MR2 and later), use it to animate the
103130
// in-layout UI controls at the bottom of the
@@ -124,13 +151,7 @@ public void onVisibilityChange(boolean visible) {
124151
delayedHide(AUTO_HIDE_DELAY_MILLIS);
125152
}
126153

127-
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)instapaperView.getLayoutParams();
128-
if (visible) {
129-
params.setMargins(0, (int)(mControlsHeight*1.5), 0, 0); //substitute parameters for left, top, right, bottom
130-
} else {
131-
params.setMargins(0, 0, 0, 0);
132-
}
133-
instapaperView.setLayoutParams(params);
154+
134155

135156
}
136157
});
@@ -158,6 +179,7 @@ public void onClick(View view) {
158179
} catch (Exception e) {
159180
e.printStackTrace();
160181
}
182+
161183
instapaperView.loadUrl(summaryUrl);
162184
prevButton.setOnClickListener(new View.OnClickListener() {
163185
@Override
@@ -197,13 +219,13 @@ protected void onPostCreate(Bundle savedInstanceState) {
197219
/**
198220
* Set up the {@link android.app.ActionBar}, if the API is available.
199221
*/
200-
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
222+
/*@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
201223
private void setupActionBar() {
202-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
224+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
203225
// Show the Up button in the action bar.
204226
getActionBar().setDisplayHomeAsUpEnabled(true);
205227
}
206-
}
228+
}*/
207229

208230
@Override
209231
public boolean onOptionsItemSelected(MenuItem item) {

App/src/main/res/layout/activity_instapaper_viewer.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<!-- The primary full-screen view. This can be replaced with whatever view
99
is needed to present your content, e.g. VideoView, SurfaceView,
1010
TextureView, etc. -->
11+
1112
<WebView android:id="@+id/instapaper_viewer"
1213
android:layout_width="fill_parent"
1314
android:layout_height="fill_parent"
@@ -43,6 +44,13 @@
4344
android:text="@string/summary_next_button" />
4445

4546
</LinearLayout>
47+
48+
<ProgressBar
49+
style="?android:attr/progressBarStyleHorizontal"
50+
android:layout_width="fill_parent"
51+
android:layout_height="wrap_content"
52+
android:id="@+id/progressBar"
53+
android:layout_gravity="center" />
4654
</FrameLayout>
4755

4856
</FrameLayout>

App/src/main/res/values-v11/styles.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
99
</style>
1010

11+
<style name="AppTheme.NoActionBar" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
12+
13+
</style>
14+
1115
<style name="FullscreenActionBarStyle" parent="android:Widget.Holo.ActionBar">
1216
<item name="android:background">@color/black_overlay</item>
1317
</style>

App/src/main/res/values/styles.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<!-- Customize your theme here. -->
77
</style>
88

9+
<style name="AppTheme.NoActionBar" parent="android:Theme.NoTitleBar.Fullscreen">
10+
11+
</style>
12+
913
<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
1014
<item name="android:windowContentOverlay">@null</item>
1115
<item name="android:windowBackground">@null</item>

0 commit comments

Comments
 (0)