Back to project page RoboBinding-gallery.
The source code is released under:
Apache License
If you think the Android project RoboBinding-gallery listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.robobinding.gallery.presentationmodel; // w w w . j a v a 2 s.co m import java.util.List; import java.util.Map; import org.robobinding.annotation.DependsOnStateOf; import org.robobinding.annotation.ItemPresentationModel; import org.robobinding.annotation.PresentationModel; import android.app.Activity; import android.content.Context; import android.content.Intent; import com.google.common.collect.Lists; /** * @author Cheng Wei * @version $Revision: 1.0 $ * @since 1.0 */ @PresentationModel public class GalleryPresentationModel { private Context context; private Map<String, Class<? extends Activity>> demoActivityMappings; private int selectedDemoIndex; public GalleryPresentationModel(Context context, Map<String, Class<? extends Activity>> demoActivityMappings) { this.context = context; this.demoActivityMappings = demoActivityMappings; selectedDemoIndex = 0; } @ItemPresentationModel(value = StringItemPresentationModel.class) public List<String> getDemoList() { return Lists.newArrayList(demoActivityMappings.keySet()); } public int getSelectedDemoIndex() { return selectedDemoIndex; } public void setSelectedDemoIndex(int selectedDemoIndex) { this.selectedDemoIndex = selectedDemoIndex; } @DependsOnStateOf("selectedDemoIndex") public String getSelectedDemoDescription() { return "Try " + getSelectedDemo(); } public void showDemo() { String demo = getSelectedDemo(); Class<?> activityClass = demoActivityMappings.get(demo); context.startActivity(new Intent(context, activityClass)); } private String getSelectedDemo() { return getDemoList().get(selectedDemoIndex); } }