Skip to content

Commit

Permalink
IDs of clicked carousel elements are now shown when clicked.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin McDonagh committed Apr 8, 2012
1 parent 6daa232 commit f60a269
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 138 deletions.
2 changes: 1 addition & 1 deletion CarouselFragment/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:icon="@drawable/ic_launcher"
android:label="Carousel" >
<activity
android:name=".CarouselActivity"
android:name=".Carousel"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
28 changes: 28 additions & 0 deletions CarouselFragment/res/layout/act_carousel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal" >

<TextView
android:id="@+id/featured"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:textColor="#000000"
android:gravity="center"
android:textSize="200sp"
android:text="1"
android:clickable="true"
android:focusable="true" />

<FrameLayout
android:id="@+id/carousel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#88000000"
android:layout_gravity="bottom"
android:focusable="true" />

</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/PanoramioItem"
android:id="@+id/CarouselItem"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/image_background"
Expand Down
115 changes: 0 additions & 115 deletions CarouselFragment/res/layout/view_image.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Gallery;
import android.widget.TextView;

public class CarouselActivity extends Activity {
public class Carousel extends Activity {

private static int count;

private int visibleItemIndex;
private int selectedCarouselItemIndex;

private TextView featuredId;

private static Context mContext;

Expand All @@ -44,18 +47,16 @@ public class CarouselActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
mContext = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.view_image);
setContentView(R.layout.act_carousel);
featuredId = (TextView)findViewById(R.id.featured);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_MEDIA_REWIND:
case KeyEvent.KEYCODE_DPAD_LEFT: {
fragment = CarouselFragment.newInstance(visibleItemIndex - 1);

// Execute a transaction, replacing any existing fragment
// with this one inside the frame.
fragment = CarouselFragment.newInstance(selectedCarouselItemIndex - 1);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.carousel, fragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
Expand All @@ -66,10 +67,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
case KeyEvent.KEYCODE_DPAD_RIGHT: {

fragment = CarouselFragment.newInstance(visibleItemIndex + 1);

// Execute a transaction, replacing any existing fragment
// with this one inside the frame.
fragment = CarouselFragment.newInstance(selectedCarouselItemIndex + 1);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.carousel, fragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
Expand All @@ -79,10 +77,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
}
case KeyEvent.KEYCODE_DPAD_DOWN: {

fragment = CarouselFragment.newInstance(visibleItemIndex);

// Execute a transaction, replacing any existing fragment
// with this one inside the frame.
fragment = CarouselFragment.newInstance(selectedCarouselItemIndex);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.carousel, fragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
Expand Down Expand Up @@ -117,14 +112,14 @@ public static CarouselFragment newInstance(int index) {
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
Gallery gallery = (Gallery) inflater.inflate(R.layout.image_gallery, null);
Gallery gallery = (Gallery) inflater.inflate(R.layout.carousel_gallery, null);

// In dual-pane mode, the list view highlights the selected item.
gallery.setAdapter(new GalleryAdapter(mContext));
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
count = position;
// ((CarouselActivity) mContext).showImage();
((Carousel) mContext).setSelectedId(id);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.hide(fragment);
ft.commit();
Expand All @@ -137,4 +132,8 @@ public void onItemClick(AdapterView<?> l, View v, int position, long id) {
return gallery;
}
}

protected void setSelectedId(long id) {
featuredId.setText(Long.toString(id));
}
}
6 changes: 2 additions & 4 deletions CarouselFragment/src/novoda/demo/GalleryAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@ public Object getItem(int position) {
}

public long getItemId(int position) {
return 987654l;
return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
View view;
if (convertView == null) {
// Make up a new view
final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.gallery_item, null);
view = inflater.inflate(R.layout.carousel_gallery_li, null);
} else {
// Use convertView if it is available
view = convertView;
}
final ImageView imageView = (ImageView) view.findViewById(R.id.image);
Expand Down

0 comments on commit f60a269

Please sign in to comment.