Added Apache License
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -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;
|
package com.RickBarrette.osj.forum;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -8,32 +27,29 @@ import android.view.MenuItem;
|
|||||||
|
|
||||||
public class TopicDetailActivity extends FragmentActivity {
|
public class TopicDetailActivity extends FragmentActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_topic_detail);
|
setContentView(R.layout.activity_topic_detail);
|
||||||
|
|
||||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
Bundle arguments = new Bundle();
|
final Bundle arguments = new Bundle();
|
||||||
arguments.putString(TopicDetailFragment.ARG_ITEM_ID,
|
arguments.putString(TopicDetailFragment.ARG_ITEM_ID, getIntent().getStringExtra(TopicDetailFragment.ARG_ITEM_ID));
|
||||||
getIntent().getStringExtra(TopicDetailFragment.ARG_ITEM_ID));
|
final TopicDetailFragment fragment = new TopicDetailFragment();
|
||||||
TopicDetailFragment fragment = new TopicDetailFragment();
|
fragment.setArguments(arguments);
|
||||||
fragment.setArguments(arguments);
|
getSupportFragmentManager().beginTransaction().add(R.id.topic_detail_container, fragment).commit();
|
||||||
getSupportFragmentManager().beginTransaction()
|
}
|
||||||
.add(R.id.topic_detail_container, fragment)
|
}
|
||||||
.commit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
if (item.getItemId() == android.R.id.home) {
|
if (item.getItemId() == android.R.id.home) {
|
||||||
NavUtils.navigateUpTo(this, new Intent(this, TopicListActivity.class));
|
NavUtils.navigateUpTo(this, new Intent(this, TopicListActivity.class));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
package com.RickBarrette.osj.forum;
|
||||||
|
|
||||||
import com.RickBarrette.osj.forum.dummy.DummyContent;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -9,30 +26,29 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.RickBarrette.osj.forum.dummy.DummyContent;
|
||||||
|
|
||||||
public class TopicDetailFragment extends Fragment {
|
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
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (getArguments().containsKey(ARG_ITEM_ID)) {
|
if (getArguments().containsKey(ARG_ITEM_ID))
|
||||||
mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
|
mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
|
||||||
Bundle savedInstanceState) {
|
final View rootView = inflater.inflate(R.layout.fragment_topic_detail, container, false);
|
||||||
View rootView = inflater.inflate(R.layout.fragment_topic_detail, container, false);
|
if (mItem != null)
|
||||||
if (mItem != null) {
|
((TextView) rootView.findViewById(R.id.topic_detail)).setText(mItem.content);
|
||||||
((TextView) rootView.findViewById(R.id.topic_detail)).setText(mItem.content);
|
return rootView;
|
||||||
}
|
}
|
||||||
return rootView;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
package com.RickBarrette.osj.forum;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -6,41 +25,36 @@ import android.support.v4.app.FragmentActivity;
|
|||||||
|
|
||||||
import com.TwentyCodes.android.exception.ExceptionHandler;
|
import com.TwentyCodes.android.exception.ExceptionHandler;
|
||||||
|
|
||||||
public class TopicListActivity extends FragmentActivity
|
public class TopicListActivity extends FragmentActivity implements TopicListFragment.Callbacks {
|
||||||
implements TopicListFragment.Callbacks {
|
|
||||||
|
|
||||||
private boolean mTwoPane;
|
private boolean mTwoPane;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
|
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
|
||||||
|
|
||||||
setContentView(R.layout.activity_topic_list);
|
setContentView(R.layout.activity_topic_list);
|
||||||
|
|
||||||
if (findViewById(R.id.topic_detail_container) != null) {
|
if (findViewById(R.id.topic_detail_container) != null) {
|
||||||
mTwoPane = true;
|
mTwoPane = true;
|
||||||
((TopicListFragment) getSupportFragmentManager()
|
((TopicListFragment) getSupportFragmentManager().findFragmentById(R.id.topic_list)).setActivateOnItemClick(true);
|
||||||
.findFragmentById(R.id.topic_list))
|
}
|
||||||
.setActivateOnItemClick(true);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(String id) {
|
public void onItemSelected(final String id) {
|
||||||
if (mTwoPane) {
|
if (mTwoPane) {
|
||||||
Bundle arguments = new Bundle();
|
final Bundle arguments = new Bundle();
|
||||||
arguments.putString(TopicDetailFragment.ARG_ITEM_ID, id);
|
arguments.putString(TopicDetailFragment.ARG_ITEM_ID, id);
|
||||||
TopicDetailFragment fragment = new TopicDetailFragment();
|
final TopicDetailFragment fragment = new TopicDetailFragment();
|
||||||
fragment.setArguments(arguments);
|
fragment.setArguments(arguments);
|
||||||
getSupportFragmentManager().beginTransaction()
|
getSupportFragmentManager().beginTransaction().replace(R.id.topic_detail_container, fragment).commit();
|
||||||
.replace(R.id.topic_detail_container, fragment)
|
|
||||||
.commit();
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Intent detailIntent = new Intent(this, TopicDetailActivity.class);
|
final Intent detailIntent = new Intent(this, TopicDetailActivity.class);
|
||||||
detailIntent.putExtra(TopicDetailFragment.ARG_ITEM_ID, id);
|
detailIntent.putExtra(TopicDetailFragment.ARG_ITEM_ID, id);
|
||||||
startActivity(detailIntent);
|
startActivity(detailIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
package com.RickBarrette.osj.forum;
|
||||||
|
|
||||||
import com.RickBarrette.osj.forum.dummy.DummyContent;
|
|
||||||
|
|
||||||
import android.R;
|
import android.R;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.ListFragment;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.AbsListView;
|
||||||
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
import com.RickBarrette.osj.forum.dummy.DummyContent;
|
||||||
|
|
||||||
public class TopicListFragment extends ListFragment {
|
public class TopicListFragment extends ListFragment {
|
||||||
|
|
||||||
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
public interface Callbacks {
|
||||||
|
|
||||||
private Callbacks mCallbacks = sDummyCallbacks;
|
public void onItemSelected(String id);
|
||||||
private int mActivatedPosition = ListView.INVALID_POSITION;
|
}
|
||||||
|
|
||||||
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() {
|
private static Callbacks sDummyCallbacks = new Callbacks() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(String id) {
|
public void onItemSelected(final String id) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public TopicListFragment() {
|
public TopicListFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onAttach(final Activity activity) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onAttach(activity);
|
||||||
setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(getActivity(),
|
if (!(activity instanceof Callbacks))
|
||||||
R.layout.simple_list_item_activated_1,
|
throw new IllegalStateException("Activity must implement fragment's callbacks.");
|
||||||
R.id.text1,
|
|
||||||
DummyContent.ITEMS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
mCallbacks = (Callbacks) activity;
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onAttach(activity);
|
super.onCreate(savedInstanceState);
|
||||||
if (!(activity instanceof Callbacks)) {
|
setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(getActivity(), R.layout.simple_list_item_activated_1, R.id.text1, DummyContent.ITEMS));
|
||||||
throw new IllegalStateException("Activity must implement fragment's callbacks.");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mCallbacks = (Callbacks) activity;
|
@Override
|
||||||
}
|
public void onDetach() {
|
||||||
|
super.onDetach();
|
||||||
|
mCallbacks = sDummyCallbacks;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onListItemClick(final ListView listView, final View view, final int position, final long id) {
|
||||||
super.onDetach();
|
super.onListItemClick(listView, view, position, id);
|
||||||
mCallbacks = sDummyCallbacks;
|
mCallbacks.onItemSelected(DummyContent.ITEMS.get(position).id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onListItemClick(ListView listView, View view, int position, long id) {
|
public void onSaveInstanceState(final Bundle outState) {
|
||||||
super.onListItemClick(listView, view, position, id);
|
super.onSaveInstanceState(outState);
|
||||||
mCallbacks.onItemSelected(DummyContent.ITEMS.get(position).id);
|
if (mActivatedPosition != AdapterView.INVALID_POSITION)
|
||||||
}
|
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onViewCreated(final View view, final Bundle savedInstanceState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
if (mActivatedPosition != ListView.INVALID_POSITION) {
|
if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION))
|
||||||
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
|
setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void setActivateOnItemClick(boolean activateOnItemClick) {
|
public void setActivatedPosition(final int position) {
|
||||||
getListView().setChoiceMode(activateOnItemClick
|
if (position == AdapterView.INVALID_POSITION)
|
||||||
? ListView.CHOICE_MODE_SINGLE
|
getListView().setItemChecked(mActivatedPosition, false);
|
||||||
: ListView.CHOICE_MODE_NONE);
|
else
|
||||||
}
|
getListView().setItemChecked(position, true);
|
||||||
|
|
||||||
public void setActivatedPosition(int position) {
|
mActivatedPosition = position;
|
||||||
if (position == ListView.INVALID_POSITION) {
|
}
|
||||||
getListView().setItemChecked(mActivatedPosition, false);
|
|
||||||
} else {
|
|
||||||
getListView().setItemChecked(position, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
mActivatedPosition = position;
|
public void setActivateOnItemClick(final boolean activateOnItemClick) {
|
||||||
}
|
getListView().setChoiceMode(activateOnItemClick ? AbsListView.CHOICE_MODE_SINGLE : AbsListView.CHOICE_MODE_NONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
package com.RickBarrette.osj.forum.dummy;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -7,33 +26,33 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class DummyContent {
|
public class DummyContent {
|
||||||
|
|
||||||
public static class DummyItem {
|
public static class DummyItem {
|
||||||
|
|
||||||
public String id;
|
public String id;
|
||||||
public String content;
|
public String content;
|
||||||
|
|
||||||
public DummyItem(String id, String content) {
|
public DummyItem(final String id, final String content) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<DummyItem> ITEMS = new ArrayList<DummyItem>();
|
public static List<DummyItem> ITEMS = new ArrayList<DummyItem>();
|
||||||
public static Map<String, DummyItem> ITEM_MAP = new HashMap<String, DummyItem>();
|
public static Map<String, DummyItem> ITEM_MAP = new HashMap<String, DummyItem>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
addItem(new DummyItem("1", "Item 1"));
|
addItem(new DummyItem("1", "Item 1"));
|
||||||
addItem(new DummyItem("2", "Item 2"));
|
addItem(new DummyItem("2", "Item 2"));
|
||||||
addItem(new DummyItem("3", "Item 3"));
|
addItem(new DummyItem("3", "Item 3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addItem(DummyItem item) {
|
private static void addItem(final DummyItem item) {
|
||||||
ITEMS.add(item);
|
ITEMS.add(item);
|
||||||
ITEM_MAP.put(item.id, item);
|
ITEM_MAP.put(item.id, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user