implement several loading progressbars

This commit is contained in:
Andrew Dolgov 2012-09-19 16:01:31 +04:00
parent 4faeb17461
commit edbf27ffb8
7 changed files with 81 additions and 32 deletions

View File

@ -2,11 +2,13 @@ package org.fox.ttrss;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.CharBuffer;
import java.security.cert.CertificateException;
import java.util.HashMap;
@ -15,6 +17,8 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.http.util.CharArrayBuffer;
import java.security.cert.X509Certificate;
import android.content.Context;
@ -170,21 +174,25 @@ public class ApiRequest extends AsyncTask<HashMap<String,String>, Integer, JsonE
switch (m_responseCode) {
case HttpURLConnection.HTTP_OK:
BufferedReader buffer = new BufferedReader(
new InputStreamReader(conn.getInputStream()), 8192);
StringBuffer response = new StringBuffer();
InputStreamReader in = new InputStreamReader(conn.getInputStream(), "UTF-8");
char[] buf = new char[256];
int read = 0;
int total = 0;
String s = "";
String response = "";
int contentLength = conn.getHeaderFieldInt("Api-Content-Length", -1);
while ((s = buffer.readLine()) != null) {
response += s;
while ((read = in.read(buf)) >= 0) {
response.append(buf, 0, read);
total += read;
publishProgress(Integer.valueOf(total), Integer.valueOf(contentLength));
}
if (m_transportDebugging) Log.d(TAG, "<<< " + response);
JsonParser parser = new JsonParser();
JsonElement result = parser.parse(response);
JsonElement result = parser.parse(response.toString());
JsonObject resultObj = result.getAsJsonObject();
m_apiStatusCode = resultObj.get("status").getAsInt();

View File

@ -32,9 +32,11 @@ import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
@ -98,6 +100,8 @@ public class ArticleFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
m_activity.setProgressBarVisibility(true);
if (savedInstanceState != null) {
m_article = savedInstanceState.getParcelable("article");
}
@ -125,6 +129,15 @@ public class ArticleFragment extends Fragment {
WebView web = (WebView)view.findViewById(R.id.content);
if (web != null) {
web.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
m_activity.setProgress(progress * 10000);
if (progress == 100) {
m_activity.setProgressBarVisibility(false);
}
}
});
String content;
String cssOverride = "";

View File

@ -127,12 +127,22 @@ public class ArticlePager extends Fragment {
private void refresh(boolean append) {
m_activity.setLoadingStatus(R.string.blank, true);
m_activity.setProgressBarVisibility(true);
if (!m_feed.equals(GlobalState.getInstance().m_activeFeed)) {
append = false;
}
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext(), m_activity) {
@Override
protected void onProgressUpdate(Integer... progress) {
m_activity.setProgress(progress[0] / progress[1] * 10000);
}
@Override
protected void onPostExecute(JsonElement result) {
m_activity.setProgressBarVisibility(false);
super.onPostExecute(result);
if (result != null) {

View File

@ -25,6 +25,7 @@ import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
@ -127,7 +128,7 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
getActivity().getMenuInflater().inflate(R.menu.category_menu, menu);
m_activity.getMenuInflater().inflate(R.menu.category_menu, menu);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
FeedCategory cat = m_adapter.getItem(info.position);
@ -198,8 +199,7 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
}
}
if (getActivity() != null)
getActivity().setProgressBarIndeterminateVisibility(showProgress);
m_activity.setProgressBarIndeterminateVisibility(showProgress);
}
@SuppressWarnings("unchecked")
@ -210,13 +210,8 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
final boolean unreadOnly = m_activity.getUnreadOnly();
if (sessionId != null) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setLoadingStatus(R.string.blank, true);
}
});
m_activity.setProgressBarVisibility(true);
@SuppressWarnings("serial")
HashMap<String,String> map = new HashMap<String,String>() {
@ -231,7 +226,6 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
};
req.execute(map);
}
}
@ -241,7 +235,15 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
super(context);
}
@Override
protected void onProgressUpdate(Integer... progress) {
m_activity.setProgress(Math.round((((float)progress[0] / (float)progress[1]) * 10000)));
}
@Override
protected void onPostExecute(JsonElement result) {
m_activity.setProgressBarVisibility(false);
if (result != null) {
try {
JsonArray content = result.getAsJsonArray();

View File

@ -254,6 +254,8 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
public void refresh(boolean background) {
//FeedCategory cat = m_onlineServices.getActiveCategory();
m_activity.setProgressBarVisibility(true);
final int catId = (m_activeCategory != null) ? m_activeCategory.id : -4;
final String sessionId = m_activity.getSessionId();
@ -262,13 +264,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
FeedsRequest req = new FeedsRequest(getActivity().getApplicationContext(), catId);
if (sessionId != null) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setLoadingStatus(R.string.blank, true);
}
});
HashMap<String,String> map = new HashMap<String,String>() {
{
@ -354,7 +350,15 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
m_catId = catId;
}
@Override
protected void onProgressUpdate(Integer... progress) {
m_activity.setProgress(Math.round((((float)progress[0] / (float)progress[1]) * 10000)));
}
@Override
protected void onPostExecute(JsonElement result) {
m_activity.setProgressBarVisibility(false);
if (result != null) {
try {
JsonArray content = result.getAsJsonArray();

View File

@ -349,6 +349,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
if (m_activity != null) {
m_refreshInProgress = true;
m_activity.setProgressBarVisibility(true);
if (!m_feed.equals(GlobalState.getInstance().m_activeFeed)) {
append = false;
}
@ -359,7 +361,15 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
final boolean isCat = m_feed.is_cat;
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext(), m_activity) {
@Override
protected void onProgressUpdate(Integer... progress) {
m_activity.setProgress(Math.round((((float)progress[0] / (float)progress[1]) * 10000)));
}
@Override
protected void onPostExecute(JsonElement result) {
m_activity.setProgressBarVisibility(false);
super.onPostExecute(result);
if (result != null) {

View File

@ -133,7 +133,9 @@ public class OnlineActivity extends CommonActivity {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
setProgressBarVisibility(false);
setProgressBarIndeterminateVisibility(false);
// SharedPreferences localPrefs = getSharedPreferences("localprefs", Context.MODE_PRIVATE);