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; ...@@ -23,24 +23,52 @@ import android.content.Intent;
* */ * */
public class ArticleDetailActivity extends Activity implements OnClickListener { public class ArticleDetailActivity extends Activity implements OnClickListener {
/**
* Currently shown article.
* */
private Article mArticle = null; private Article mArticle = null;
/**
* Textview where to display article title.
*/
private TextView mTitle = null; private TextView mTitle = null;
/**
* Textview where to display article author.
*/
private TextView mAuthor = null; private TextView mAuthor = null;
/**
* Textview where to display article date.
*/
private TextView mDate = null; private TextView mDate = null;
/**
* Webview where to display content.
*/
private WebView mContent = null; private WebView mContent = null;
/**
* Button to switch read state.
*/
private Button mReadButton = null; private Button mReadButton = null;
/**
* Button to switch starred state.
*/
private Button mStarButton = null; private Button mStarButton = null;
/**
* Button to display article in the browser.
*/
private Button mBrowserButton = null; private Button mBrowserButton = null;
/**
* Boolean to know if pause is done from back button pressure or not.
* */
private boolean isBackButtonPressed = false; private boolean isBackButtonPressed = false;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public final void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.articlelist_detail); setContentView(R.layout.articlelist_detail);
mArticle = this.getIntent().getParcelableExtra( mArticle =
ArticleListActivity.ARTICLE_KEY); this.getIntent().getParcelableExtra(
ArticleListActivity.ARTICLE_KEY);
Log.d("ArticleDetail", "Article received : " + mArticle.getId()); Log.d("ArticleDetail", "Article received : " + mArticle.getId());
...@@ -78,16 +106,16 @@ public class ArticleDetailActivity extends Activity implements OnClickListener { ...@@ -78,16 +106,16 @@ public class ArticleDetailActivity extends Activity implements OnClickListener {
} }
@Override @Override
public void onClick(View v) { public final void onClick(final View v) {
switch (v.getId()) { switch (v.getId()) {
case R.id.newsRead: case R.id.newsRead:
ArticleReadStateUpdater readUpdate = new ArticleReadStateUpdater( ArticleReadStateUpdater readUpdate =
this); new ArticleReadStateUpdater(this);
readUpdate.execute(mArticle); readUpdate.execute(mArticle);
break; break;
case R.id.newsStar: case R.id.newsStar:
ArticleStarredStateUpdater starUpdate = new ArticleStarredStateUpdater( ArticleStarredStateUpdater starUpdate =
this); new ArticleStarredStateUpdater(this);
starUpdate.execute(mArticle); starUpdate.execute(mArticle);
break; break;
case R.id.newsBrowser: case R.id.newsBrowser:
...@@ -95,18 +123,20 @@ public class ArticleDetailActivity extends Activity implements OnClickListener { ...@@ -95,18 +123,20 @@ public class ArticleDetailActivity extends Activity implements OnClickListener {
browserIntent.setData(Uri.parse(mArticle.getLink())); browserIntent.setData(Uri.parse(mArticle.getLink()));
startActivity(browserIntent); startActivity(browserIntent);
break; break;
default:
break;
} }
} }
@Override @Override
public void onBackPressed() { public final void onBackPressed() {
// Here you get Back Key Press So make boolean false // Here you get Back Key Press So make boolean false
isBackButtonPressed = true; isBackButtonPressed = true;
super.onBackPressed(); super.onBackPressed();
} }
@Override @Override
public void onPause() { public final void onPause() {
super.onPause(); super.onPause();
if (isBackButtonPressed) { if (isBackButtonPressed) {
goBackToArticleList(); goBackToArticleList();
...@@ -114,12 +144,17 @@ public class ArticleDetailActivity extends Activity implements OnClickListener { ...@@ -114,12 +144,17 @@ public class ArticleDetailActivity extends Activity implements OnClickListener {
} }
@Override @Override
protected void onResume() { protected final void onResume() {
super.onResume(); super.onResume();
isBackButtonPressed = false; 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()) { if (mArticle.isRead()) {
mReadButton.setText(R.string.notRead); mReadButton.setText(R.string.notRead);
mReadButton.refreshDrawableState(); mReadButton.refreshDrawableState();
...@@ -133,7 +168,12 @@ public class ArticleDetailActivity extends Activity implements OnClickListener { ...@@ -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()) { if (mArticle.isStarred()) {
mStarButton.setText(R.string.unStar); mStarButton.setText(R.string.unStar);
mReadButton.refreshDrawableState(); mReadButton.refreshDrawableState();
...@@ -147,9 +187,14 @@ public class ArticleDetailActivity extends Activity implements OnClickListener { ...@@ -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() { private void goBackToArticleList() {
Intent intent = new Intent(ArticleDetailActivity.this, Intent intent =
ArticleListActivity.class); new Intent(ArticleDetailActivity.this,
ArticleListActivity.class);
intent.putExtras(getIntent()); intent.putExtras(getIntent());
intent.putExtra(ArticleListActivity.ARTICLE_KEY, mArticle); intent.putExtra(ArticleListActivity.ARTICLE_KEY, mArticle);
......
...@@ -18,36 +18,61 @@ import android.widget.Toast; ...@@ -18,36 +18,61 @@ import android.widget.Toast;
public class SettingsActivity extends PreferenceActivity { public class SettingsActivity extends PreferenceActivity {
/* Preference constants */ /* Preference constants */
/**
* Key to know where are preferences.
* */
public static final String SHARED_PREFERENCES = "shared_preferences"; public static final String SHARED_PREFERENCES = "shared_preferences";
/**
* Key for url server preference.
* */
public static final String URL_SERVER_PREF = "url_server_pref"; public static final String URL_SERVER_PREF = "url_server_pref";
/**
* Key for displaying preference.
* */
public static final String DISPLAY_BEHAVIOUR_PREF = "todisplay_pref"; 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"; 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"; 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"; 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; private static boolean mWantToEdit = true;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public final void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesName(SHARED_PREFERENCES); getPreferenceManager().setSharedPreferencesName(SHARED_PREFERENCES);
getPreferenceManager().setSharedPreferencesMode(Activity.MODE_PRIVATE); getPreferenceManager().setSharedPreferencesMode(Activity.MODE_PRIVATE);
SharedPreferences pref = getSharedPreferences(SHARED_PREFERENCES, SharedPreferences pref =
Activity.MODE_PRIVATE); getSharedPreferences(SHARED_PREFERENCES, Activity.MODE_PRIVATE);
Log.d("Preferences", Log.d(
"Preferences",
"URL Server : " + pref.getString(URL_SERVER_PREF, "")); "URL Server : " + pref.getString(URL_SERVER_PREF, ""));
if (!pref.getString(URL_SERVER_PREF, "").equals("") && !mWantToEdit) { if (!pref.getString(URL_SERVER_PREF, "").equals("") && !mWantToEdit) {
Intent intent = new Intent(SettingsActivity.this, Intent intent =
ArticleListActivity.class); new Intent(SettingsActivity.this,
ArticleListActivity.class);
startActivity(intent); startActivity(intent);
finish(); finish();
} else { } else {
Editor editor = getSharedPreferences( Editor editor =
SettingsActivity.SHARED_PREFERENCES, Activity.MODE_PRIVATE) getSharedPreferences(
.edit(); SettingsActivity.SHARED_PREFERENCES,
Activity.MODE_PRIVATE).edit();
editor.remove(WANT_TO_EDIT_PREF); editor.remove(WANT_TO_EDIT_PREF);
editor.commit(); editor.commit();
mWantToEdit = false; mWantToEdit = false;
...@@ -57,25 +82,27 @@ public class SettingsActivity extends PreferenceActivity { ...@@ -57,25 +82,27 @@ public class SettingsActivity extends PreferenceActivity {
} }
@Override @Override
public void onBackPressed() { public final void onBackPressed() {
SharedPreferences pref = getSharedPreferences(SHARED_PREFERENCES, SharedPreferences pref =
Activity.MODE_PRIVATE); getSharedPreferences(SHARED_PREFERENCES, Activity.MODE_PRIVATE);
if (!pref.getString(URL_SERVER_PREF, "").equals("") && !mWantToEdit) { if (!pref.getString(URL_SERVER_PREF, "").equals("") && !mWantToEdit) {
Intent intent = new Intent(SettingsActivity.this, Intent intent =
ArticleListActivity.class); new Intent(SettingsActivity.this,
ArticleListActivity.class);
startActivity(intent); startActivity(intent);
finish(); finish();
} else { } else {
Toast.makeText( Toast.makeText(
getApplicationContext(), 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(); 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() { public static void setWantToEdit() {
mWantToEdit = true; 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; ...@@ -5,31 +5,84 @@ import android.os.Parcelable;
/** /**
* Article is the type which implements all data received from the server for * 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. * This implements Parcelable to be able to pass it in android Intents.
* */ * */
public class Article implements Parcelable { public class Article implements Parcelable {
/**
* article id.
* */
private Integer mId; private Integer mId;
/**
* article publication day.
* */
private Integer mDay; private Integer mDay;
/**
* article publication month.
* */
private Integer mMonth; private Integer mMonth;
/**
* article subject.
* */
private String mSubject; private String mSubject;
/**
* article content as html file.
* */
private String mContent; private String mContent;
/**
* article author.
* */
private String mAuthor; private String mAuthor;
/**
* article original link.
* */
private String mLink; private String mLink;
/**
* icon of the article feed.
* */
private String mIcon; private String mIcon;
/**
* article read state.
* */
private Boolean mIsRead = false; private Boolean mIsRead = false;
/**
* article starred state.
* */
private Boolean mIsStarred = false; private Boolean mIsStarred = false;
public Article(Integer id, Integer day, Integer month, String subject, /**
String content, String author, String link, String icon, * Complete constructor of an article.
Boolean isRead, Boolean isStarred) { * @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; mId = id;
mDay = day; mDay = day;
mMonth = month; mMonth = month;
mSubject = subject; mSubject = subject;
mContent = "<?xml version='1.0' encoding='utf-8' ?>" + "<html><body>" mContent =
+ content + " </body></html>"; "<?xml version='1.0' encoding='utf-8' ?>"
+ "<html><body>"
+ content
+ " </body></html>";
mAuthor = author; mAuthor = author;
mLink = link; mLink = link;
mIcon = icon; mIcon = icon;
...@@ -37,23 +90,22 @@ public class Article implements Parcelable { ...@@ -37,23 +90,22 @@ public class Article implements Parcelable {
mIsStarred = isStarred; mIsStarred = isStarred;
} }
public Boolean isRead() { /**
* @return read state article
* */
public final Boolean isRead() {
return mIsRead; return mIsRead;
} }
public void setRead(Boolean isRead) { /**
this.mIsRead = isRead; * @return starred state article
} * */
public final Boolean isStarred() {
public Boolean isStarred() {
return mIsStarred; return mIsStarred;
} }
public void setStarred(Boolean isStarred) { @Override
this.mIsStarred = isStarred; public final String toString() {
}
public String toString() {
String result = "Article[\n"; String result = "Article[\n";
result += "\tId : " + mId + ",\n"; result += "\tId : " + mId + ",\n";
result += "\tMonth / Day : " + mMonth + " / " + mDay + ",\n"; result += "\tMonth / Day : " + mMonth + " / " + mDay + ",\n";
...@@ -67,35 +119,59 @@ public class Article implements Parcelable { ...@@ -67,35 +119,59 @@ public class Article implements Parcelable {
return result; return result;
} }
public Integer getId() { /**
* @return article id
* */
public final Integer getId() {
return mId; return mId;
} }
public void updateReadState() { /**
* toggle read state.
* */
public final void updateReadState() {
mIsRead = !mIsRead; mIsRead = !mIsRead;
} }
public void updateStarredState() { /**
* toggle starred state.
* */
public final void updateStarredState() {
mIsStarred = !mIsStarred; mIsStarred = !mIsStarred;
} }
public String getSubject() { /**
* @return article subject
* */
public final String getSubject() {
return mSubject; return mSubject;
} }
public String getAuthor() { /**
* @return article author
* */
public final String getAuthor() {
return mAuthor; return mAuthor;
} }
public String getDate() { /**
* @return article date (dd/mm)
* */
public final String getDate() {
return mDay + "." + mMonth; return mDay + "." + mMonth;
} }
public String getContent() { /**
* @return article content
* */
public final String getContent() {
return mContent; return mContent;
} }
public String getLink() { /**
* @return article original link
* */
public final String getLink() {
return mLink; return mLink;
} }
...@@ -103,24 +179,28 @@ public class Article implements Parcelable { ...@@ -103,24 +179,28 @@ public class Article implements Parcelable {
* Next field, methods and creator are needed to use Parcelabel. That's * Next field, methods and creator are needed to use Parcelabel. That's
* needed to pass easier and faster Article from one activity to another. * 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) { * Implementation of Parcelable for articles.
return new Article(in); * */
} public static final Parcelable.Creator<Article> CREATOR =
new Parcelable.Creator<Article>() {
public Article[] newArray(int size) { public Article createFromParcel(final Parcel in) {
return new Article[size]; return new Article(in);
} }
};
public Article[] newArray(final int size) {
return new Article[size];
}
};
@Override @Override
public int describeContents() { public final int describeContents() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return 0;
} }
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public final void writeToParcel(final Parcel dest, final int flags) {
dest.writeInt(mId); dest.writeInt(mId);
dest.writeInt(mDay); dest.writeInt(mDay);
dest.writeInt(mMonth); dest.writeInt(mMonth);
...@@ -133,7 +213,11 @@ public class Article implements Parcelable { ...@@ -133,7 +213,11 @@ public class Article implements Parcelable {
dest.writeValue(mIsStarred); 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(); mId = parcel.readInt();
mDay = parcel.readInt(); mDay = parcel.readInt();
mMonth = parcel.readInt(); mMonth = parcel.readInt();
......
...@@ -5,5 +5,8 @@ package ch.adorsaz.loungeDroid.article; ...@@ -5,5 +5,8 @@ package ch.adorsaz.loungeDroid.article;
* state. * state.
* */ * */
public enum ToDisplay { public enum ToDisplay {
/**
* Choice of user to display some articles.
* */
ALWAYS_PROMPT, ALL, UNREAD, STARRED 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; ...@@ -7,12 +7,12 @@ package ch.adorsaz.loungeDroid.exception;
public class GetArticleListException extends Exception { public class GetArticleListException extends Exception {
/** /**
* Auto-generated ID by Eclpipse. * Auto-generated ID by Eclipse.
*/ */
private static final long serialVersionUID = 8449004512651295034L; private static final long serialVersionUID = 8449004512651295034L;
@Override @Override
public String getMessage() { public final String getMessage() {
return "Unable to get article list.\n" + super.getMessage(); return "Unable to get article list.\n" + super.getMessage();
} }
} }
...@@ -12,7 +12,7 @@ public class ParseArticleException extends Exception { ...@@ -12,7 +12,7 @@ public class ParseArticleException extends Exception {
private static final long serialVersionUID = -1916018652604709645L;