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);
......
......@@ -36,22 +36,38 @@ import android.widget.TextView;
* */
public class ArticleListActivity extends ListActivity {
/**
* The adapter to show in the list activity.
* */
private ArticleAdapter mArticleAdapter = null;
/**
* The selection of articles to display.
* */
private ToDisplay mDisplayChoice = null;
/**
* The article that user want to see details.
* */
private Article mArticleToDetail = null;
/**
* The key to save and find article in the intent.
* */
protected static final String ARTICLE_KEY = "article";
/**
* The key to remember which was the displaying choice of the user.
* */
protected static final String DISPLAYCHOICE_KEY = "mDisplayChoice";
@Override
public void onCreate(Bundle savedInstanceState) {
public final void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences pref = getSharedPreferences(
SettingsActivity.SHARED_PREFERENCES, Activity.MODE_PRIVATE);
SharedPreferences pref =
getSharedPreferences(SettingsActivity.SHARED_PREFERENCES,
Activity.MODE_PRIVATE);
mDisplayChoice = (ToDisplay) getIntent().getSerializableExtra(
DISPLAYCHOICE_KEY);
mDisplayChoice =
(ToDisplay) getIntent().getSerializableExtra(DISPLAYCHOICE_KEY);
if (mDisplayChoice == null) {
if (pref.getString(SettingsActivity.DISPLAY_BEHAVIOUR_PREF,
......@@ -67,8 +83,13 @@ public class ArticleListActivity extends ListActivity {
R.array.startdialog_values_toDisplay,
new DisplayDialogListener()).create().show();
} else {
mDisplayChoice = ToDisplay.valueOf(pref.getString(
SettingsActivity.DISPLAY_BEHAVIOUR_PREF, "ALL"));
mDisplayChoice =
ToDisplay
.valueOf(pref
.getString(
SettingsActivity
.DISPLAY_BEHAVIOUR_PREF,
"ALL"));
fetchNews();
}
......@@ -85,7 +106,7 @@ public class ArticleListActivity extends ListActivity {
DialogInterface.OnClickListener {
@Override
public void onClick(DialogInterface dialog, int which) {
public void onClick(final DialogInterface dialog, final int which) {
mDisplayChoice = ToDisplay.values()[which + 1]; // We won't show
// ALWAYS_PROMPT
Log.d("ArticleList", "have to show : " + mDisplayChoice
......@@ -100,7 +121,7 @@ public class ArticleListActivity extends ListActivity {
* server.
* */
@Override
public void onPause() {
public final void onPause() {
super.onPause();
if (mArticleToDetail == null) {
saveData();
......@@ -110,7 +131,7 @@ public class ArticleListActivity extends ListActivity {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
public final boolean onCreateOptionsMenu(final Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_article_list, menu);
disableToDisplayMenu(menu);
......@@ -118,13 +139,13 @@ public class ArticleListActivity extends ListActivity {
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
public final boolean onPrepareOptionsMenu(final Menu menu) {
disableToDisplayMenu(menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
public final boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.refresh:
fetchNews();
......@@ -151,6 +172,8 @@ public class ArticleListActivity extends ListActivity {
intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
break;
default:
break;
}
return false;
}
......@@ -158,14 +181,14 @@ public class ArticleListActivity extends ListActivity {
/**
* updateArticleList should be used by AsyncTask (especially
* loungeDroid.server.ArticleListGetter) to update data on this activity.
*
* @param articleList
* List of articles to display in the activity (will replace all
* already displayed articles)
* @param articleList List of articles to display in the activity (will
* replace all already displayed articles)
* */
public void updateArticleList(List<Article> articleList) {
mArticleAdapter = new ArticleAdapter(getApplicationContext(),
R.layout.articlelist_item, R.id.articleItemTitle, articleList);
public final void updateArticleList(final List<Article> articleList) {
mArticleAdapter =
new ArticleAdapter(getApplicationContext(),
R.layout.articlelist_item, R.id.articleItemTitle,
articleList);
updateArticleAdapter();
}
......@@ -177,8 +200,8 @@ public class ArticleListActivity extends ListActivity {
ListView listView = getListView();
listView.setScrollingCacheEnabled(false);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
public void onItemClick(final AdapterView<?> parent,
final View view, final int position, final long id) {
mArticleToDetail = mArticleAdapter.getItem(position);
saveData();
}
......@@ -196,6 +219,9 @@ public class ArticleListActivity extends ListActivity {
getter.execute(mDisplayChoice);
}
/**
* Ask to server to mark all actual articles to read state.
* */
private void markAllRead() {
if (mArticleAdapter != null) {
ArticleMarkAllRead allMarker = new ArticleMarkAllRead(this);
......@@ -208,12 +234,17 @@ public class ArticleListActivity extends ListActivity {
articleIdList.add(oneArticle.getId());
}
}
allMarker.execute(articleIdList);
}
}
private void disableToDisplayMenu(Menu menu) {
/**
* Disable item in to display submenu which correspond to actual selected
* item.
* @param menu menu where to search items.
* */
private void disableToDisplayMenu(final Menu menu) {
MenuItem showAllItem = menu.findItem(R.id.showAllMenu);
MenuItem showUnreadItem = menu.findItem(R.id.showUnreadMenu);
MenuItem showStarredItem = menu.findItem(R.id.showStarredMenu);
......@@ -235,6 +266,8 @@ public class ArticleListActivity extends ListActivity {
break;
case ALWAYS_PROMPT:
break;
default:
break;
}
}
......@@ -243,19 +276,20 @@ public class ArticleListActivity extends ListActivity {
/**
* disableMenuItem will disable the item with depending on his id and in
* which menu is it.
*
* @param menu
* Menu where to disable some menu item.
* @param id
* Id of the menuItem to disable.
* @param menu Menu where to disable some menu item.
* @param id Id of the menuItem to disable.
* */
private void disableMenuItem(Menu menu, int id) {
private void disableMenuItem(final Menu menu, final int id) {
MenuItem menuItem = menu.findItem(id);
menuItem.setVisible(false);
menuItem.setEnabled(false);
}
private void enableMenuItem(MenuItem menuItem) {
/**
* set menu item visible.
* @param menuItem menu item to activate.
* */
private void enableMenuItem(final MenuItem menuItem) {
menuItem.setVisible(true);
menuItem.setEnabled(true);
}
......@@ -270,8 +304,9 @@ public class ArticleListActivity extends ListActivity {
if (mArticleToDetail == null) {
intent = getIntent();
} else {
intent = new Intent(ArticleListActivity.this,
ArticleDetailActivity.class);
intent =
new Intent(ArticleListActivity.this,
ArticleDetailActivity.class);
}
if (mArticleAdapter != null) {
......@@ -295,8 +330,7 @@ public class ArticleListActivity extends ListActivity {
/**
* restoreAndUpdateData restores data saved in some Intent and update a
* modified article (which is also in Intent with special key).
*
* modified article (which is also in Intent with special key).<br/>
* This function is used when resume from ArticleDetailActivity because this
* activity is able to update article states (read state and starred state).
* */
......@@ -317,12 +351,14 @@ public class ArticleListActivity extends ListActivity {
.getParcelableExtra("mArticleAdapterItem" + i));
}
mArticleAdapter = new ArticleAdapter(getApplicationContext(),
R.layout.articlelist_item, R.id.articleItemTitle, articleList);
mArticleAdapter =
new ArticleAdapter(getApplicationContext(),
R.layout.articlelist_item, R.id.articleItemTitle,
articleList);
// Update one article if needed
Article articleUpdated = intent.getParcelableExtra(ARTICLE_KEY);
Integer articleUpdatedAdapterID = -1;
if (articleUpdated != null) {
for (int i = 0; i < mArticleAdapter.getCount(); i++) {
Article articleIterator = mArticleAdapter.getItem(i);
......@@ -332,52 +368,79 @@ public class ArticleListActivity extends ListActivity {
if (articleIteratorId == articleUpdatedId) {
mArticleAdapter.remove(articleIterator);
mArticleAdapter.insert(articleUpdated, i);
articleUpdatedAdapterID = i;
}
}
}
// Apply restored data
updateArticleAdapter();
// Set position of the cursor
if (articleUpdatedAdapterID > -1) {
setSelection(articleUpdatedAdapterID);
}
}
/**
* ArticleAdapter is the specific ArrayAdapter for this ArticleListActivity.
* */
private class ArticleAdapter extends ArrayAdapter<Article> {
/**
* Application context where we'll create this adapter.
* */
private Context mContext;
/**
* List of articles we'll display in the activity.
* */
private List<Article> mArticles;
public ArticleAdapter(Context context, int itemLayout, int textViewId,
List<Article> articleList) {
/**
* Constructor.
* @param context @see ArrayAdapter
* @param itemLayout @see ArrayAdapter
* @param textViewId @see ArrayAdapter
* @param articleList list of articles to put in the activity.
* */
public ArticleAdapter(final Context context, final int itemLayout,
final int textViewId, final List<Article> articleList) {
super(context, itemLayout, textViewId, articleList);
mArticles = articleList;
mContext = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
public View getView(final int position, final View convertView,
final ViewGroup parent) {
Article article = mArticles.get(position);
View view = convertView;
// Find the convertView
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.articlelist_item,
null);
if (view == null) {
LayoutInflater layoutInflater =
(LayoutInflater) this.mContext
.getSystemService(Context.
LAYOUT_INFLATER_SERVICE);
view =
layoutInflater.inflate(R.layout.articlelist_item, null);
}
// Manage article
RelativeLayout articleItem = null;
if (article != null) {
articleItem = (RelativeLayout) convertView
.findViewById(R.id.itemRelativeLayout);
articleItem =
(RelativeLayout) view
.findViewById(R.id.itemRelativeLayout);
if (articleItem != null) {
TextView articleItemTitle = (TextView) articleItem
.findViewById(R.id.articleItemTitle);
TextView articleItemAuthor = (TextView) articleItem
.findViewById(R.id.articleItemAuthor);
TextView articleItemDate = (TextView) articleItem
.findViewById(R.id.articleItemDate);
TextView articleItemTitle =
(TextView) articleItem
.findViewById(R.id.articleItemTitle);
TextView articleItemAuthor =
(TextView) articleItem
.findViewById(R.id.articleItemAuthor);
TextView articleItemDate =
(TextView) articleItem
.findViewById(R.id.articleItemDate);
if (articleItemTitle != null && articleItemAuthor != null
&& articleItemDate != null) {
......
......@@ -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