Commit 9f8fdcc2 authored by Adrien Dorsaz's avatar Adrien Dorsaz

Apply new formatter, add Javadoc and modify files according to checkstyle.

parent 934e3416
<?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="true">
<fileset name="all" enabled="true" check-config-name="Sun Checks" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
<filter name="FilesFromPackage" enabled="true">
<filter-data value="gen"/>
</filter>
</fileset-config>
......@@ -23,24 +23,52 @@ import android.content.Intent;
* */
public class ArticleDetailActivity extends Activity implements OnClickListener {
/**
* Currently shown article.
* */
private Article mArticle = null;
/**
* Textview where to display article title.
*/
private TextView mTitle = null;
/**
* Textview where to display article author.
*/
private TextView mAuthor = null;
/**
* Textview where to display article date.
*/
private TextView mDate = null;
/**
* Webview where to display content.
*/
private WebView mContent = null;
/**
* Button to switch read state.
*/
private Button mReadButton = null;
/**
* Button to switch starred state.
*/
private Button mStarButton = null;
/**
* Button to display article in the browser.
*/
private Button mBrowserButton = null;
/**
* Boolean to know if pause is done from back button pressure or not.
* */
private boolean isBackButtonPressed = false;
@Override
public void onCreate(Bundle savedInstanceState) {
public final void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.articlelist_detail);
mArticle = this.getIntent().getParcelableExtra(
ArticleListActivity.ARTICLE_KEY);
mArticle =
this.getIntent().getParcelableExtra(
ArticleListActivity.ARTICLE_KEY);
Log.d("ArticleDetail", "Article received : " + mArticle.getId());
......@@ -78,16 +106,16 @@ public class ArticleDetailActivity extends Activity implements OnClickListener {
}
@Override
public void onClick(View v) {
public final void onClick(final View v) {
switch (v.getId()) {
case R.id.newsRead:
ArticleReadStateUpdater readUpdate = new ArticleReadStateUpdater(
this);
ArticleReadStateUpdater readUpdate =
new ArticleReadStateUpdater(this);
readUpdate.execute(mArticle);
break;
case R.id.newsStar:
ArticleStarredStateUpdater starUpdate = new ArticleStarredStateUpdater(
this);
ArticleStarredStateUpdater starUpdate =
new ArticleStarredStateUpdater(this);
starUpdate.execute(mArticle);
break;
case R.id.newsBrowser:
......@@ -95,18 +123,20 @@ public class ArticleDetailActivity extends Activity implements OnClickListener {
browserIntent.setData(Uri.parse(mArticle.getLink()));
startActivity(browserIntent);
break;
default:
break;
}
}
@Override
public void onBackPressed() {
public final void onBackPressed() {
// Here you get Back Key Press So make boolean false
isBackButtonPressed = true;
super.onBackPressed();
}
@Override
public void onPause() {
public final void onPause() {
super.onPause();
if (isBackButtonPressed) {
goBackToArticleList();
......@@ -114,12 +144,17 @@ public class ArticleDetailActivity extends Activity implements OnClickListener {
}
@Override
protected void onResume() {
protected final void onResume() {
super.onResume();
isBackButtonPressed = false;
}
public void updateReadButton() {
/**
* updateReadButton() should be called from the asynk task which updates the
* read state of the displayed article.<br/>
* It should be called only when the async task has finished his job.
* */
public final void updateReadButton() {
if (mArticle.isRead()) {
mReadButton.setText(R.string.notRead);
mReadButton.refreshDrawableState();
......@@ -133,7 +168,12 @@ public class ArticleDetailActivity extends Activity implements OnClickListener {
}
}
public void updateStarredButton() {
/**
* updateStarredButton() should be called from the asynk task which updates
* the starred state of the displayed article.<br/>
* It should be called only when the async task has finished his job.
* */
public final void updateStarredButton() {
if (mArticle.isStarred()) {
mStarButton.setText(R.string.unStar);
mReadButton.refreshDrawableState();
......@@ -147,9 +187,14 @@ public class ArticleDetailActivity extends Activity implements OnClickListener {
}
}
/**
* This method save in the intent last states of the displayed articles and
* show article list activity.
* */
private void goBackToArticleList() {
Intent intent = new Intent(ArticleDetailActivity.this,
ArticleListActivity.class);
Intent intent =
new Intent(ArticleDetailActivity.this,
ArticleListActivity.class);
intent.putExtras(getIntent());
intent.putExtra(ArticleListActivity.ARTICLE_KEY, mArticle);
......
......@@ -18,36 +18,61 @@ import android.widget.Toast;
public class SettingsActivity extends PreferenceActivity {
/* Preference constants */
/**
* Key to know where are preferences.
* */
public static final String SHARED_PREFERENCES = "shared_preferences";
/**
* Key for url server preference.
* */
public static final String URL_SERVER_PREF = "url_server_pref";
/**
* Key for displaying preference.
* */
public static final String DISPLAY_BEHAVIOUR_PREF = "todisplay_pref";
/**
* Key for url user name preference.
* */
public static final String USER_SERVER_PREF = "username_server_pref";
/**
* Key for url user password preference.
* */
public static final String PASSWORD_SERVER_PREF = "password_server_pref";
/**
* Key to store if user want edit preferences.
* */
public static final String WANT_TO_EDIT_PREF = "want_to_edit_pref";
/**
* Boolean to know if user want to edit preference (if so, show this
* activity, if not, pass to next activity).
* */
private static boolean mWantToEdit = true;
@Override
public void onCreate(Bundle savedInstanceState) {
public final void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesName(SHARED_PREFERENCES);
getPreferenceManager().setSharedPreferencesMode(Activity.MODE_PRIVATE);
SharedPreferences pref = getSharedPreferences(SHARED_PREFERENCES,
Activity.MODE_PRIVATE);
SharedPreferences pref =
getSharedPreferences(SHARED_PREFERENCES, Activity.MODE_PRIVATE);
Log.d("Preferences",
Log.d(
"Preferences",
"URL Server : " + pref.getString(URL_SERVER_PREF, ""));
if (!pref.getString(URL_SERVER_PREF, "").equals("") && !mWantToEdit) {
Intent intent = new Intent(SettingsActivity.this,
ArticleListActivity.class);
Intent intent =
new Intent(SettingsActivity.this,
ArticleListActivity.class);
startActivity(intent);
finish();
} else {
Editor editor = getSharedPreferences(
SettingsActivity.SHARED_PREFERENCES, Activity.MODE_PRIVATE)
.edit();
Editor editor =
getSharedPreferences(
SettingsActivity.SHARED_PREFERENCES,
Activity.MODE_PRIVATE).edit();
editor.remove(WANT_TO_EDIT_PREF);
editor.commit();
mWantToEdit = false;
......@@ -57,25 +82,27 @@ public class SettingsActivity extends PreferenceActivity {
}
@Override
public void onBackPressed() {
SharedPreferences pref = getSharedPreferences(SHARED_PREFERENCES,
Activity.MODE_PRIVATE);
public final void onBackPressed() {
SharedPreferences pref =
getSharedPreferences(SHARED_PREFERENCES, Activity.MODE_PRIVATE);
if (!pref.getString(URL_SERVER_PREF, "").equals("") && !mWantToEdit) {
Intent intent = new Intent(SettingsActivity.this,
ArticleListActivity.class);
Intent intent =
new Intent(SettingsActivity.this,
ArticleListActivity.class);
startActivity(intent);
finish();
} else {
Toast.makeText(
getApplicationContext(),
"You should configure as least the server url to be able to use this application",
"You should configure as least the server url to be able"
+ " to use this application",
Toast.LENGTH_LONG).show();
}
}
/**
* This method permit to alert this class that we want to edit preferences
* This method permit to alert this class that we want to edit preferences.
* */
public static void setWantToEdit() {
mWantToEdit = true;
......
/**
* Provides the classes necessary to show user interface.
* @since 1.0
* @see java.awt
* */
package ch.adorsaz.loungeDroid.activities;
......@@ -5,31 +5,84 @@ import android.os.Parcelable;
/**
* Article is the type which implements all data received from the server for
* one article.
*
* one article.<br/>
* This implements Parcelable to be able to pass it in android Intents.
* */
public class Article implements Parcelable {
/**
* article id.
* */
private Integer mId;
/**
* article publication day.
* */
private Integer mDay;
/**
* article publication month.
* */
private Integer mMonth;
/**
* article subject.
* */
private String mSubject;
/**
* article content as html file.
* */
private String mContent;
/**
* article author.
* */
private String mAuthor;
/**
* article original link.
* */
private String mLink;
/**
* icon of the article feed.
* */
private String mIcon;
/**
* article read state.
* */
private Boolean mIsRead = false;
/**
* article starred state.
* */
private Boolean mIsStarred = false;
public Article(Integer id, Integer day, Integer month, String subject,
String content, String author, String link, String icon,
Boolean isRead, Boolean isStarred) {
/**
* Complete constructor of an article.
* @param id article id
* @param day article publication day
* @param month article publication month
* @param subject article subject
* @param content article content (html format)
* @param author article author
* @param link link of original article
* @param icon icon of news feed
* @param isRead read state
* @param isStarred starred state
* */
public Article(
final Integer id,
final Integer day,
final Integer month,
final String subject,
final String content,
final String author,
final String link,
final String icon,
final Boolean isRead,
final Boolean isStarred) {
mId = id;
mDay = day;
mMonth = month;
mSubject = subject;
mContent = "<?xml version='1.0' encoding='utf-8' ?>" + "<html><body>"
+ content + " </body></html>";
mContent =
"<?xml version='1.0' encoding='utf-8' ?>"
+ "<html><body>"
+ content
+ " </body></html>";
mAuthor = author;
mLink = link;
mIcon = icon;
......@@ -37,23 +90,22 @@ public class Article implements Parcelable {
mIsStarred = isStarred;
}
public Boolean isRead() {
/**
* @return read state article
* */
public final Boolean isRead() {
return mIsRead;
}
public void setRead(Boolean isRead) {
this.mIsRead = isRead;
}
public Boolean isStarred() {
/**
* @return starred state article
* */
public final Boolean isStarred() {
return mIsStarred;
}
public void setStarred(Boolean isStarred) {
this.mIsStarred = isStarred;
}
public String toString() {
@Override
public final String toString() {
String result = "Article[\n";
result += "\tId : " + mId + ",\n";
result += "\tMonth / Day : " + mMonth + " / " + mDay + ",\n";
......@@ -67,35 +119,59 @@ public class Article implements Parcelable {
return result;
}
public Integer getId() {
/**
* @return article id
* */
public final Integer getId() {
return mId;
}
public void updateReadState() {
/**
* toggle read state.
* */
public final void updateReadState() {
mIsRead = !mIsRead;
}
public void updateStarredState() {
/**
* toggle starred state.
* */
public final void updateStarredState() {
mIsStarred = !mIsStarred;
}
public String getSubject() {
/**
* @return article subject
* */
public final String getSubject() {
return mSubject;
}
public String getAuthor() {
/**
* @return article author
* */
public final String getAuthor() {
return mAuthor;
}
public String getDate() {
/**
* @return article date (dd/mm)
* */
public final String getDate() {
return mDay + "." + mMonth;
}
public String getContent() {
/**
* @return article content
* */
public final String getContent() {
return mContent;
}
public String getLink() {
/**
* @return article original link
* */
public final String getLink() {
return mLink;
}
......@@ -103,24 +179,28 @@ public class Article implements Parcelable {
* Next field, methods and creator are needed to use Parcelabel. That's
* needed to pass easier and faster Article from one activity to another.
*/
public static final Parcelable.Creator<Article> CREATOR = new Parcelable.Creator<Article>() {
public Article createFromParcel(Parcel in) {
return new Article(in);
}
public Article[] newArray(int size) {
return new Article[size];
}
};
/**
* Implementation of Parcelable for articles.
* */
public static final Parcelable.Creator<Article> CREATOR =
new Parcelable.Creator<Article>() {
public Article createFromParcel(final Parcel in) {
return new Article(in);
}
public Article[] newArray(final int size) {
return new Article[size];
}
};
@Override
public int describeContents() {
public final int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
public final void writeToParcel(final Parcel dest, final int flags) {
dest.writeInt(mId);
dest.writeInt(mDay);
dest.writeInt(mMonth);
......@@ -133,7 +213,11 @@ public class Article implements Parcelable {
dest.writeValue(mIsStarred);
}
private Article(Parcel parcel) {
/**
* Private constructor to retrieve article from parcel.
* @param parcel parcel which contains the article
* */
private Article(final Parcel parcel) {
mId = parcel.readInt();
mDay = parcel.readInt();
mMonth = parcel.readInt();
......
......@@ -5,5 +5,8 @@ package ch.adorsaz.loungeDroid.article;
* state.
* */
public enum ToDisplay {
/**
* Choice of user to display some articles.
* */
ALWAYS_PROMPT, ALL, UNREAD, STARRED
}
/**
* Provides tools class related to Articles.
* @since 1.0
* @see java.awt
* */
package ch.adorsaz.loungeDroid.article;
......@@ -7,12 +7,12 @@ package ch.adorsaz.loungeDroid.exception;
public class GetArticleListException extends Exception {
/**
* Auto-generated ID by Eclpipse.
* Auto-generated ID by Eclipse.
*/
private static final long serialVersionUID = 8449004512651295034L;
@Override
public String getMessage() {
public final String getMessage() {
return "Unable to get article list.\n" + super.getMessage();
}
}
......@@ -12,7 +12,7 @@ public class ParseArticleException extends Exception {
private static final long serialVersionUID = -1916018652604709645L;
@Override
public String getMessage() {
public final String getMessage() {
return "Unable parse correctly messages.\n" + super.getMessage();
}
}
......@@ -12,7 +12,7 @@ public class ReadStateUpdateException extends Exception {
private static final long serialVersionUID = 859540452885060466L;
@Override
public String getMessage() {
public final String getMessage() {
return "Unable to update the read state of an article.\n"
+ super.getMessage();
}
......
......@@ -7,12 +7,13 @@ package ch.adorsaz.loungeDroid.exception;
public class StarredStateUpdateException extends Exception {
/**
* Auto-generated ID by Eclpipse.
* Auto-generated ID by Eclipse.
*/
private static final long serialVersionUID = -7137335428363481542L;
@Override
public String getMessage() {
return "Unable to update the starred state of an article.\n"+super.getMessage();
public final String getMessage() {
return "Unable to update the starred state of an article.\n"
+ super.getMessage();
}
}
/**
* Provides the exceptions managed by loungeDroid.
* @since 1.0
* @see java.awt
* */
package ch.adorsaz.loungeDroid.exception;
package ch.adorsaz.loungeDroid.servercom;
import java.net.ConnectException;
import java.util.Arrays;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;
import ch.adorsaz.loungeDroid.activities.ArticleListActivity;
......@@ -18,35 +16,56 @@ import android.widget.Toast;
* ArticleMarkAllRead is an async task to mark all articles read in
* ArticleListActivity.
* */
public class ArticleMarkAllRead extends
public class ArticleMarkAllRead
extends
AsyncTask<List<Integer>, Object, Boolean> {
/**
* Instance of the SessionManager used to communicate with server.
* */
private SessionManager mSessionManager = null;
/**
* The activity where will put articles.
* */
private ArticleListActivity mActivity = null;
/**
* ids of articles to mark as read.
* */
private List<Integer> mArticleIdList = null;
/* Some urls needed to get feeds */
private final static String MARKALL_READ_RSSLOUNGE = "/item/markall";
private final static String ITEM_POST_ID = "items[]";
public ArticleMarkAllRead(ArticleListActivity activity) {
/**
* It defines the page where will update read state for all articles.
* */
private static final String MARKALL_READ_RSSLOUNGE = "/item/markall";
/**
* HttpPost parameter to give list of items.
* */
private static final String ITEM_POST_ID = "items[]";
/**
* Public Constructor.
* @param activity Activity to update at the end of the task
* */
public ArticleMarkAllRead(final ArticleListActivity activity) {
mActivity = activity;
}
@Override
protected void onPreExecute() {
mSessionManager = SessionManager.getInstance(mActivity
.getApplicationContext());
protected final void onPreExecute() {
mSessionManager =
SessionManager.getInstance(mActivity.getApplicationContext());
}
@Override
protected Boolean doInBackground(List<Integer>... articleId) {
protected final Boolean doInBackground(final List<Integer>... articleId) {
boolean hasWorked = false;
try {
mArticleIdList = articleId[0];
hasWorked = updateArticles();
} catch (ConnectException e) {
// TODO Auto-generated catch block
Log.e(SessionManager.LOG_SERVER,
Log.e(
SessionManager.LOG_SERVER,
"There was an error with network connection.");
e.printStackTrace();
hasWorked = false;
......@@ -58,13 +77,16 @@ public class ArticleMarkAllRead extends
hasWorked = updateArticles();
} catch (ConnectException e1) {
// TODO Auto-generated catch block
Log.e(SessionManager.LOG_SERVER,
Log.e(
SessionManager.LOG_SERVER,
"There was an error with network connection.");
e1.printStackTrace();
hasWorked = false;
} catch (ReadStateUpdateException e1) {
Log.e(SessionManager.LOG_SERVER,
"Error while updating read state twice. Try again later");
Log.e(
SessionManager.LOG_SERVER,
"Error while updating read state twice."
+ " Try again later");
e1.printStackTrace();
hasWorked = false;
}
......@@ -74,16 +96,31 @@ public class ArticleMarkAllRead extends
}
@Override
protected void onPostExecute(Boolean hasWorked) {
protected final void onPostExecute(final Boolean hasWorked) {
if (hasWorked) {
Toast.makeText(
mActivity,