diff --git a/OSJ Forum/src/com/RickBarrette/osj/forum/TopicDetailActivity.java b/OSJ Forum/src/com/RickBarrette/osj/forum/TopicDetailActivity.java index ecea9ba..cf076e4 100644 --- a/OSJ Forum/src/com/RickBarrette/osj/forum/TopicDetailActivity.java +++ b/OSJ Forum/src/com/RickBarrette/osj/forum/TopicDetailActivity.java @@ -1,3 +1,22 @@ +/** + * TopicDetailActivity + * @date Aug 27, 2012 + * @author ricky barrette + * + * Copyright 2012 Richard Barrette + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ package com.RickBarrette.osj.forum; import android.content.Intent; @@ -8,32 +27,29 @@ import android.view.MenuItem; public class TopicDetailActivity extends FragmentActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_topic_detail); + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_topic_detail); - getActionBar().setDisplayHomeAsUpEnabled(true); + getActionBar().setDisplayHomeAsUpEnabled(true); - if (savedInstanceState == null) { - Bundle arguments = new Bundle(); - arguments.putString(TopicDetailFragment.ARG_ITEM_ID, - getIntent().getStringExtra(TopicDetailFragment.ARG_ITEM_ID)); - TopicDetailFragment fragment = new TopicDetailFragment(); - fragment.setArguments(arguments); - getSupportFragmentManager().beginTransaction() - .add(R.id.topic_detail_container, fragment) - .commit(); - } - } + if (savedInstanceState == null) { + final Bundle arguments = new Bundle(); + arguments.putString(TopicDetailFragment.ARG_ITEM_ID, getIntent().getStringExtra(TopicDetailFragment.ARG_ITEM_ID)); + final TopicDetailFragment fragment = new TopicDetailFragment(); + fragment.setArguments(arguments); + getSupportFragmentManager().beginTransaction().add(R.id.topic_detail_container, fragment).commit(); + } + } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - NavUtils.navigateUpTo(this, new Intent(this, TopicListActivity.class)); - return true; - } + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + if (item.getItemId() == android.R.id.home) { + NavUtils.navigateUpTo(this, new Intent(this, TopicListActivity.class)); + return true; + } - return super.onOptionsItemSelected(item); - } + return super.onOptionsItemSelected(item); + } } diff --git a/OSJ Forum/src/com/RickBarrette/osj/forum/TopicDetailFragment.java b/OSJ Forum/src/com/RickBarrette/osj/forum/TopicDetailFragment.java index b299ae8..da9a075 100644 --- a/OSJ Forum/src/com/RickBarrette/osj/forum/TopicDetailFragment.java +++ b/OSJ Forum/src/com/RickBarrette/osj/forum/TopicDetailFragment.java @@ -1,7 +1,24 @@ +/** + * TopicDetailFragment + * @date Aug 27, 2012 + * @author ricky barrette + * + * Copyright 2012 Richard Barrette + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ package com.RickBarrette.osj.forum; -import com.RickBarrette.osj.forum.dummy.DummyContent; - import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; @@ -9,30 +26,29 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import com.RickBarrette.osj.forum.dummy.DummyContent; + public class TopicDetailFragment extends Fragment { - public static final String ARG_ITEM_ID = "item_id"; + public static final String ARG_ITEM_ID = "item_id"; - DummyContent.DummyItem mItem; + DummyContent.DummyItem mItem; - public TopicDetailFragment() { - } + public TopicDetailFragment() { + } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (getArguments().containsKey(ARG_ITEM_ID)) { - mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID)); - } - } + @Override + public void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments().containsKey(ARG_ITEM_ID)) + mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID)); + } - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_topic_detail, container, false); - if (mItem != null) { - ((TextView) rootView.findViewById(R.id.topic_detail)).setText(mItem.content); - } - return rootView; - } + @Override + public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { + final View rootView = inflater.inflate(R.layout.fragment_topic_detail, container, false); + if (mItem != null) + ((TextView) rootView.findViewById(R.id.topic_detail)).setText(mItem.content); + return rootView; + } } diff --git a/OSJ Forum/src/com/RickBarrette/osj/forum/TopicListActivity.java b/OSJ Forum/src/com/RickBarrette/osj/forum/TopicListActivity.java index bca5583..1b4dad3 100644 --- a/OSJ Forum/src/com/RickBarrette/osj/forum/TopicListActivity.java +++ b/OSJ Forum/src/com/RickBarrette/osj/forum/TopicListActivity.java @@ -1,3 +1,22 @@ +/** + * TopicListActivity + * @date Aug 27, 2012 + * @author ricky barrette + * + * Copyright 2012 Richard Barrette + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ package com.RickBarrette.osj.forum; import android.content.Intent; @@ -6,41 +25,36 @@ import android.support.v4.app.FragmentActivity; import com.TwentyCodes.android.exception.ExceptionHandler; -public class TopicListActivity extends FragmentActivity - implements TopicListFragment.Callbacks { +public class TopicListActivity extends FragmentActivity implements TopicListFragment.Callbacks { - private boolean mTwoPane; + private boolean mTwoPane; - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); - - setContentView(R.layout.activity_topic_list); + @Override + public void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); - if (findViewById(R.id.topic_detail_container) != null) { - mTwoPane = true; - ((TopicListFragment) getSupportFragmentManager() - .findFragmentById(R.id.topic_list)) - .setActivateOnItemClick(true); - } - } + setContentView(R.layout.activity_topic_list); - @Override - public void onItemSelected(String id) { - if (mTwoPane) { - Bundle arguments = new Bundle(); - arguments.putString(TopicDetailFragment.ARG_ITEM_ID, id); - TopicDetailFragment fragment = new TopicDetailFragment(); - fragment.setArguments(arguments); - getSupportFragmentManager().beginTransaction() - .replace(R.id.topic_detail_container, fragment) - .commit(); + if (findViewById(R.id.topic_detail_container) != null) { + mTwoPane = true; + ((TopicListFragment) getSupportFragmentManager().findFragmentById(R.id.topic_list)).setActivateOnItemClick(true); + } + } - } else { - Intent detailIntent = new Intent(this, TopicDetailActivity.class); - detailIntent.putExtra(TopicDetailFragment.ARG_ITEM_ID, id); - startActivity(detailIntent); - } - } + @Override + public void onItemSelected(final String id) { + if (mTwoPane) { + final Bundle arguments = new Bundle(); + arguments.putString(TopicDetailFragment.ARG_ITEM_ID, id); + final TopicDetailFragment fragment = new TopicDetailFragment(); + fragment.setArguments(arguments); + getSupportFragmentManager().beginTransaction().replace(R.id.topic_detail_container, fragment).commit(); + + } else { + final Intent detailIntent = new Intent(this, TopicDetailActivity.class); + detailIntent.putExtra(TopicDetailFragment.ARG_ITEM_ID, id); + startActivity(detailIntent); + } + } } diff --git a/OSJ Forum/src/com/RickBarrette/osj/forum/TopicListFragment.java b/OSJ Forum/src/com/RickBarrette/osj/forum/TopicListFragment.java index 2ca57fb..4ae160a 100644 --- a/OSJ Forum/src/com/RickBarrette/osj/forum/TopicListFragment.java +++ b/OSJ Forum/src/com/RickBarrette/osj/forum/TopicListFragment.java @@ -1,97 +1,108 @@ +/** + * TopicListFragment + * @date Aug 27, 2012 + * @author ricky barrette + * + * Copyright 2012 Richard Barrette + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ package com.RickBarrette.osj.forum; -import com.RickBarrette.osj.forum.dummy.DummyContent; - import android.R; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.view.View; +import android.widget.AbsListView; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; +import com.RickBarrette.osj.forum.dummy.DummyContent; + public class TopicListFragment extends ListFragment { - private static final String STATE_ACTIVATED_POSITION = "activated_position"; + public interface Callbacks { - private Callbacks mCallbacks = sDummyCallbacks; - private int mActivatedPosition = ListView.INVALID_POSITION; + public void onItemSelected(String id); + } - public interface Callbacks { + private static final String STATE_ACTIVATED_POSITION = "activated_position"; + private Callbacks mCallbacks = sDummyCallbacks; - public void onItemSelected(String id); - } + private int mActivatedPosition = ListView.INVALID_POSITION; - private static Callbacks sDummyCallbacks = new Callbacks() { - @Override - public void onItemSelected(String id) { - } - }; + private static Callbacks sDummyCallbacks = new Callbacks() { + @Override + public void onItemSelected(final String id) { + } + }; - public TopicListFragment() { - } + public TopicListFragment() { + } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setListAdapter(new ArrayAdapter(getActivity(), - R.layout.simple_list_item_activated_1, - R.id.text1, - DummyContent.ITEMS)); - } + @Override + public void onAttach(final Activity activity) { + super.onAttach(activity); + if (!(activity instanceof Callbacks)) + throw new IllegalStateException("Activity must implement fragment's callbacks."); - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - if (savedInstanceState != null && savedInstanceState - .containsKey(STATE_ACTIVATED_POSITION)) { - setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION)); - } - } + mCallbacks = (Callbacks) activity; + } - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - if (!(activity instanceof Callbacks)) { - throw new IllegalStateException("Activity must implement fragment's callbacks."); - } + @Override + public void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setListAdapter(new ArrayAdapter(getActivity(), R.layout.simple_list_item_activated_1, R.id.text1, DummyContent.ITEMS)); + } - mCallbacks = (Callbacks) activity; - } + @Override + public void onDetach() { + super.onDetach(); + mCallbacks = sDummyCallbacks; + } - @Override - public void onDetach() { - super.onDetach(); - mCallbacks = sDummyCallbacks; - } + @Override + public void onListItemClick(final ListView listView, final View view, final int position, final long id) { + super.onListItemClick(listView, view, position, id); + mCallbacks.onItemSelected(DummyContent.ITEMS.get(position).id); + } - @Override - public void onListItemClick(ListView listView, View view, int position, long id) { - super.onListItemClick(listView, view, position, id); - mCallbacks.onItemSelected(DummyContent.ITEMS.get(position).id); - } + @Override + public void onSaveInstanceState(final Bundle outState) { + super.onSaveInstanceState(outState); + if (mActivatedPosition != AdapterView.INVALID_POSITION) + outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition); + } - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - if (mActivatedPosition != ListView.INVALID_POSITION) { - outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition); - } - } + @Override + public void onViewCreated(final View view, final Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) + setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION)); + } - public void setActivateOnItemClick(boolean activateOnItemClick) { - getListView().setChoiceMode(activateOnItemClick - ? ListView.CHOICE_MODE_SINGLE - : ListView.CHOICE_MODE_NONE); - } + public void setActivatedPosition(final int position) { + if (position == AdapterView.INVALID_POSITION) + getListView().setItemChecked(mActivatedPosition, false); + else + getListView().setItemChecked(position, true); - public void setActivatedPosition(int position) { - if (position == ListView.INVALID_POSITION) { - getListView().setItemChecked(mActivatedPosition, false); - } else { - getListView().setItemChecked(position, true); - } + mActivatedPosition = position; + } - mActivatedPosition = position; - } + public void setActivateOnItemClick(final boolean activateOnItemClick) { + getListView().setChoiceMode(activateOnItemClick ? AbsListView.CHOICE_MODE_SINGLE : AbsListView.CHOICE_MODE_NONE); + } } diff --git a/OSJ Forum/src/com/RickBarrette/osj/forum/dummy/DummyContent.java b/OSJ Forum/src/com/RickBarrette/osj/forum/dummy/DummyContent.java index 5075027..d82edea 100644 --- a/OSJ Forum/src/com/RickBarrette/osj/forum/dummy/DummyContent.java +++ b/OSJ Forum/src/com/RickBarrette/osj/forum/dummy/DummyContent.java @@ -1,3 +1,22 @@ +/** + * DummyContent + * @date Aug 27, 2012 + * @author ricky barrette + * + * Copyright 2012 Richard Barrette + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ package com.RickBarrette.osj.forum.dummy; import java.util.ArrayList; @@ -7,33 +26,33 @@ import java.util.Map; public class DummyContent { - public static class DummyItem { + public static class DummyItem { - public String id; - public String content; + public String id; + public String content; - public DummyItem(String id, String content) { - this.id = id; - this.content = content; - } + public DummyItem(final String id, final String content) { + this.id = id; + this.content = content; + } - @Override - public String toString() { - return content; - } - } + @Override + public String toString() { + return content; + } + } - public static List ITEMS = new ArrayList(); - public static Map ITEM_MAP = new HashMap(); + public static List ITEMS = new ArrayList(); + public static Map ITEM_MAP = new HashMap(); - static { - addItem(new DummyItem("1", "Item 1")); - addItem(new DummyItem("2", "Item 2")); - addItem(new DummyItem("3", "Item 3")); - } + static { + addItem(new DummyItem("1", "Item 1")); + addItem(new DummyItem("2", "Item 2")); + addItem(new DummyItem("3", "Item 3")); + } - private static void addItem(DummyItem item) { - ITEMS.add(item); - ITEM_MAP.put(item.id, item); - } + private static void addItem(final DummyItem item) { + ITEMS.add(item); + ITEM_MAP.put(item.id, item); + } }