├── .gitignore ├── .project ├── LICENSE ├── README.adoc ├── app ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── org │ │ └── robobinding │ │ └── gallerytest │ │ └── DemoTraveller.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── org │ │ └── robobinding │ │ └── gallery │ │ ├── activity │ │ ├── AbstractActivity.java │ │ ├── AbstractFragment.java │ │ ├── AbstractFragmentActivity.java │ │ ├── AdapterViewActivity.java │ │ ├── ContextMenuDemoActivity.java │ │ ├── ContextualActionModeActivity.java │ │ ├── CustomComponentActivity.java │ │ ├── EditTextActivity.java │ │ ├── FragmentDemo.java │ │ ├── FragmentTitleTag.java │ │ ├── GalleryActivity.java │ │ ├── GalleryApp.java │ │ ├── ListFragmentDemo.java │ │ ├── ListFragmentDemoActivity.java │ │ ├── ListViewActivity.java │ │ ├── MenuItemBinding.java │ │ ├── MenuItemGroupBinding.java │ │ ├── OptionMenuFragment.java │ │ ├── OptionsMenuActivity.java │ │ ├── RecyclerViewActivity.java │ │ ├── TypedCursorActivity.java │ │ ├── ViewActivity.java │ │ ├── ViewBindingForView.java │ │ └── ViewPagerActivity.java │ │ ├── invocationlog │ │ ├── PublicMethodInvocationLog.java │ │ └── PublicMethodInvocationLogAspect.aj │ │ ├── model │ │ ├── MemoryProductStore.java │ │ ├── Product.java │ │ ├── Strings.java │ │ ├── TestData.java │ │ ├── adapterview │ │ │ ├── SampleStringType.java │ │ │ ├── SampleStrings.java │ │ │ └── StringItemLayout.java │ │ ├── customcomponent │ │ │ ├── TitleDescriptionBar.java │ │ │ └── TitleDescriptionBarBinding.java │ │ ├── listview │ │ │ └── SampleStringsFooter.java │ │ ├── typedcursor │ │ │ ├── DatabaseHelper.java │ │ │ ├── GetAllQuery.java │ │ │ ├── ProductItemPresentationModel.java │ │ │ ├── ProductRowMapper.java │ │ │ └── ProductTable.java │ │ └── view │ │ │ ├── BooleanVisibility.java │ │ │ └── IntegerVisibility.java │ │ ├── presentationmodel │ │ ├── AdapterViewPresentationModel.java │ │ ├── ContextMenuDemoPresentationModel.java │ │ ├── ContextMenuPresentationModel.java │ │ ├── ContextualActionModePresentationModel.java │ │ ├── CustomComponentPresentationModel.java │ │ ├── EditTextPresentationModel.java │ │ ├── FragmentDemoPresentationModel.java │ │ ├── FragmentTitleTagPresentationModel.java │ │ ├── GalleryPresentationModel.java │ │ ├── ListFragmentDemoPresentationModel.java │ │ ├── ListViewPresentationModel.java │ │ ├── MenuPresentationModel.java │ │ ├── RecyclerViewPresentationModel.java │ │ ├── StringItemPresentationModel.java │ │ ├── ToStringItemPresentationModel.java │ │ ├── TypedCursorPresentationModel.java │ │ └── ViewPresentationModel.java │ │ └── util │ │ └── CircularIntegers.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-ldpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable │ ├── background_activated.xml │ ├── my_custom_border.xml │ └── my_list_selector_background.xml │ ├── layout │ ├── activity_adapter_view.xml │ ├── activity_byinterface_noaspectj.xml │ ├── activity_bysubclass_noaspectj.xml │ ├── activity_context_menu_demo.xml │ ├── activity_contextual_action_mode.xml │ ├── activity_custom_component.xml │ ├── activity_edittext.xml │ ├── activity_fragment.xml │ ├── activity_gallery.xml │ ├── activity_list_view.xml │ ├── activity_recycler_view.xml │ ├── activity_typed_cursor.xml │ ├── activity_view.xml │ ├── custom_or_third_party_component.xml │ ├── fragment_demo.xml │ ├── fragment_list_demo.xml │ ├── fragment_options_menu.xml │ ├── fragment_title_tag.xml │ ├── sample_strings_footer.xml │ ├── sample_strings_header.xml │ ├── string_item_layout1.xml │ ├── string_item_layout2.xml │ └── title_description_bar.xml │ ├── menu │ ├── context_menu.xml │ ├── contextual_action_mode.xml │ └── options_menu.xml │ └── values │ ├── attrs.xml │ ├── ids.xml │ └── strings.xml ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /.idea 3 | /build 4 | /.gradle 5 | /app/app.iml 6 | /app/build 7 | /RoboBinding-gallery.iml 8 | /app/libs 9 | /local.properties 10 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | RoboBinding-gallery 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2012-2014 Cheng Wei and RoboBinding Contributors 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions 13 | and limitations under the License. 14 | 15 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | **Note:** please issue the following in command line - 'gradlew build --refresh-dependencies' in Windows or './gradlew build --refresh-dependencies' in Linux or Mac to force update to the latest RoboBinding snapshot when required. 2 | 3 | An android app to showcase the usage of https://github.com/RoboBinding/RoboBinding[RoboBinding] framework. 4 | 5 | The project can be directly imported into Android Studio. 6 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | maven() { 4 | name 'Local RoboBinding AspectJPlugin Maven Repository' 5 | url "file://D:/git/RoboBinding-aspectj-plugin/mavenRepo" 6 | } 7 | mavenCentral() 8 | maven() { 9 | name 'RoboBinding AspectJPlugin Maven Repository' 10 | url "https://github.com/RoboBinding/RoboBinding-aspectj-plugin/raw/master/mavenRepo" 11 | //url "file://D:/git/RoboBinding-aspectj-plugin/mavenRepo" 12 | } 13 | } 14 | 15 | dependencies { 16 | classpath 'com.android.tools.build:gradle:2.2.1' 17 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.+' 18 | classpath 'org.robobinding:aspectj-plugin:0.8.5' 19 | } 20 | } 21 | 22 | apply plugin: 'com.android.application' 23 | apply plugin: 'com.neenbedankt.android-apt' 24 | apply plugin: 'org.robobinding.android-aspectj' 25 | 26 | android { 27 | compileSdkVersion 22 28 | buildToolsVersion "22.0.1" 29 | 30 | defaultConfig { 31 | minSdkVersion 8 32 | targetSdkVersion 21 33 | 34 | testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" 35 | //testInstrumentationRunner "android.test.InstrumentationTestRunner" 36 | testApplicationId 'org.robobinding.gallerytest' 37 | testHandleProfiling true 38 | testFunctionalTest true 39 | 40 | } 41 | 42 | compileOptions { 43 | sourceCompatibility JavaVersion.VERSION_1_6 44 | targetCompatibility JavaVersion.VERSION_1_6 45 | } 46 | 47 | buildTypes { 48 | release { 49 | minifyEnabled false 50 | proguardFiles 'proguard-rules.pro' 51 | } 52 | } 53 | 54 | lintOptions { 55 | disable 'UnusedAttribute', 'ValidFragment', 'GradleDependency', 'OnClick', 'MissingPrefix', 'MenuTitle' 56 | abortOnError false 57 | } 58 | 59 | packagingOptions { 60 | exclude 'LICENSE.txt' 61 | } 62 | } 63 | 64 | repositories { 65 | maven() { 66 | name 'RoboBinding Framework Maven Repository' 67 | url "file://D:/git/RoboBinding/framework/mavenRepo" 68 | } 69 | maven() { 70 | name 'RoboBinding CodeGen Maven Repository' 71 | url "file://D:/git/RoboBinding/codegen/mavenRepo" 72 | } 73 | maven() { 74 | name 'RoboBinding Extras Maven Repository' 75 | url "file://D:/git/RoboBinding/extras/mavenRepo" 76 | } 77 | mavenCentral() 78 | maven() { 79 | name 'SonaType snapshot repository' 80 | url 'https://oss.sonatype.org/content/repositories/snapshots' 81 | } 82 | } 83 | 84 | ext { 85 | //robobindingVersion = 'latest.integration' 86 | robobindingVersion = '0.8.14' 87 | } 88 | 89 | dependencies { 90 | //compile fileTree(dir: 'libs', include: '*.jar') 91 | compile ("org.robobinding:robobinding:${robobindingVersion}:with-aop") { 92 | exclude group: 'com.google.guava' 93 | } 94 | compile "org.robobinding:extras:${robobindingVersion}" 95 | compile 'com.android.support:appcompat-v7:22.1.1' 96 | compile 'com.android.support:recyclerview-v7:22.1.1' 97 | compile 'com.google.guava:guava:16.0' 98 | 99 | //aspectPath fileTree(dir: 'libs', include: '*.jar') 100 | aspectPath "org.robobinding:robobinding:${robobindingVersion}:with-aop" 101 | 102 | apt "org.robobinding:codegen:$robobindingVersion" 103 | 104 | androidTestCompile('com.jakewharton.espresso:espresso-support-v4:1.1-r3') { 105 | exclude group:'com.android.support', module:'support-v4' 106 | exclude group:'com.android.support', module:'appcompat-v7' 107 | exclude group: 'com.google.guava' 108 | } 109 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\windows7\android-studio\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -optimizationpasses 5 19 | -dontusemixedcaseclassnames 20 | -dontskipnonpubliclibraryclasses 21 | -dontpreverify 22 | -verbose 23 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 24 | 25 | -keep public class * extends android.app.Activity 26 | -keep public class * extends android.app.Application 27 | -keep public class * extends android.app.Service 28 | -keep public class * extends android.content.BroadcastReceiver 29 | -keep public class * extends android.content.ContentProvider 30 | -keep public class * extends android.app.backup.BackupAgentHelper 31 | -keep public class * extends android.preference.Preference 32 | -keep public class com.android.vending.licensing.ILicensingService 33 | 34 | -keepclasseswithmembernames class * { 35 | native ; 36 | } 37 | 38 | -keepclasseswithmembers class * { 39 | public (android.content.Context, android.util.AttributeSet); 40 | } 41 | 42 | -keepclasseswithmembers class * { 43 | public (android.content.Context, android.util.AttributeSet, int); 44 | } 45 | 46 | -keepclassmembers class * extends android.app.Activity { 47 | public void *(android.view.View); 48 | } 49 | 50 | -keepclassmembers enum * { 51 | public static **[] values(); 52 | public static ** valueOf(java.lang.String); 53 | } 54 | 55 | -keep class * implements android.os.Parcelable { 56 | public static final android.os.Parcelable$Creator *; 57 | } 58 | 59 | -dontwarn sun.misc.Unsafe 60 | 61 | ########################## 62 | ### For robobinding 63 | ########################## 64 | -keepattributes *Annotation*,Signature 65 | 66 | -keep class * implements org.robobinding.property.ObservableBean { 67 | public *** *(...); 68 | } 69 | 70 | -keepclassmembers class * extends org.robobinding.widget.view.ViewListeners { 71 | public (...); 72 | } 73 | 74 | -keepclassmembers class org.robobinding.gallery.model.dynamicbinding.CustomOrThirdPartyComponent { 75 | public void set*(***); 76 | public boolean is*(); 77 | public *** get*(); 78 | } 79 | 80 | -dontwarn android.widget.AbsListView, android.view.View 81 | -dontwarn javax.annotation.** 82 | -------------------------------------------------------------------------------- /app/src/androidTest/java/org/robobinding/gallerytest/DemoTraveller.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallerytest; 2 | 3 | import android.test.ActivityInstrumentationTestCase2; 4 | import android.test.suitebuilder.annotation.LargeTest; 5 | import android.widget.Spinner; 6 | 7 | import com.google.android.apps.common.testing.ui.espresso.Espresso; 8 | import com.google.android.apps.common.testing.ui.espresso.action.ViewActions; 9 | import com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers; 10 | 11 | import org.hamcrest.Matchers; 12 | import org.robobinding.gallery.R; 13 | import org.robobinding.gallery.activity.GalleryActivity; 14 | 15 | /** 16 | * 17 | * @since 1.0 18 | * @version $Revision: 1.0 $ 19 | * @author Cheng Wei 20 | */ 21 | @LargeTest 22 | public class DemoTraveller extends ActivityInstrumentationTestCase2 { 23 | public DemoTraveller() { 24 | super(GalleryActivity.class); 25 | } 26 | 27 | public void testTravelThroughAllDemos() { 28 | Spinner demoSpinner = (Spinner)getActivity().findViewById(R.id.demoSpinner); 29 | int numDemos = demoSpinner.getCount(); 30 | 31 | for(int i=0; i 2 | 6 | 7 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/AbstractActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.MenuBinder; 4 | import org.robobinding.ViewBinder; 5 | import org.robobinding.binder.BinderFactory; 6 | import org.robobinding.gallery.model.typedcursor.DatabaseHelper; 7 | 8 | import android.support.v7.app.ActionBarActivity; 9 | import android.view.Menu; 10 | import android.view.MenuInflater; 11 | import android.view.View; 12 | 13 | /** 14 | * 15 | * @since 1.0 16 | * @version $Revision: 1.0 $ 17 | * @author Cheng Wei 18 | */ 19 | public abstract class AbstractActivity extends ActionBarActivity { 20 | public void initializeContentView(int layoutId, Object presentationModel) { 21 | ViewBinder viewBinder = createViewBinder(); 22 | View rootView = viewBinder.inflateAndBind(layoutId, presentationModel); 23 | setContentView(rootView); 24 | } 25 | 26 | private ViewBinder createViewBinder() { 27 | BinderFactory binderFactory = getReusableBinderFactory(); 28 | return binderFactory.createViewBinder(this); 29 | } 30 | 31 | protected BinderFactory getReusableBinderFactory() { 32 | BinderFactory binderFactory = getGalleryApp().getReusableBinderFactory(); 33 | return binderFactory; 34 | } 35 | 36 | private GalleryApp getGalleryApp() { 37 | return (GalleryApp)getApplicationContext(); 38 | } 39 | 40 | protected DatabaseHelper getDatabaseHelper() { 41 | return getGalleryApp().getDatabaseHelper(); 42 | } 43 | 44 | protected MenuBinder createMenuBinder(Menu menu, MenuInflater menuInflater) { 45 | BinderFactory binderFactory = getReusableBinderFactory(); 46 | return binderFactory.createMenuBinder(menu, menuInflater, this); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/AbstractFragment.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.MenuBinder; 4 | import org.robobinding.ViewBinder; 5 | import org.robobinding.binder.BinderFactory; 6 | 7 | import android.support.v4.app.Fragment; 8 | import android.view.Menu; 9 | import android.view.MenuInflater; 10 | 11 | /** 12 | * 13 | * @since 1.0 14 | * @version $Revision: 1.0 $ 15 | * @author Cheng Wei 16 | */ 17 | public abstract class AbstractFragment extends Fragment { 18 | protected ViewBinder createViewBinder() { 19 | BinderFactory binderFactory = getReusableBinderFactory(); 20 | return binderFactory.createViewBinder(getActivity()); 21 | } 22 | 23 | private BinderFactory getReusableBinderFactory() { 24 | BinderFactory binderFactory = getGalleryApp().getReusableBinderFactory(); 25 | return binderFactory; 26 | } 27 | 28 | private GalleryApp getGalleryApp() { 29 | return (GalleryApp)getActivity().getApplicationContext(); 30 | } 31 | 32 | protected MenuBinder createMenuBinder(Menu menu, MenuInflater menuInflater) { 33 | BinderFactory binderFactory = getReusableBinderFactory(); 34 | return binderFactory.createMenuBinder(menu, menuInflater, getActivity()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/AbstractFragmentActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.gallery.R; 4 | 5 | import android.os.Bundle; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v4.app.FragmentManager; 8 | import android.support.v7.app.ActionBarActivity; 9 | 10 | /** 11 | * 12 | * @since 1.0 13 | * @version $Revision: 1.0 $ 14 | * @author Cheng Wei 15 | */ 16 | public abstract class AbstractFragmentActivity extends ActionBarActivity { 17 | 18 | @Override 19 | public void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_fragment); 22 | 23 | FragmentManager fm = getSupportFragmentManager(); 24 | Fragment fragment = fm.findFragmentById(R.id.fragmentContainer); 25 | if (fragment == null) { 26 | fragment = createFragment(); 27 | fm.beginTransaction().add(R.id.fragmentContainer, fragment).commit(); 28 | } 29 | } 30 | 31 | protected abstract Fragment createFragment(); 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/AdapterViewActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.ViewBinder; 4 | import org.robobinding.binder.BinderFactory; 5 | import org.robobinding.gallery.R; 6 | import org.robobinding.gallery.presentationmodel.AdapterViewPresentationModel; 7 | 8 | import android.os.Bundle; 9 | import android.view.View; 10 | 11 | /** 12 | * 13 | * @since 1.0 14 | * @version $Revision: 1.0 $ 15 | * @author Cheng Wei 16 | */ 17 | public class AdapterViewActivity extends AbstractActivity { 18 | private AdapterViewPresentationModel presentationModel; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | 24 | presentationModel = new AdapterViewPresentationModel(); 25 | ViewBinder viewBinder = getReusableBinderFactory().createViewBinder(this, false); 26 | View rootView = viewBinder.inflateAndBind(R.layout.activity_adapter_view, presentationModel); 27 | setContentView(rootView); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/ContextMenuDemoActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.MenuBinder; 4 | import org.robobinding.gallery.R; 5 | import org.robobinding.gallery.model.MemoryProductStore; 6 | import org.robobinding.gallery.presentationmodel.ContextMenuDemoPresentationModel; 7 | import org.robobinding.gallery.presentationmodel.ContextMenuPresentationModel; 8 | 9 | import android.os.Bundle; 10 | import android.view.ContextMenu; 11 | import android.view.ContextMenu.ContextMenuInfo; 12 | import android.view.View; 13 | import android.widget.ListView; 14 | 15 | /** 16 | * 17 | * @since 1.0 18 | * @version $Revision: 1.0 $ 19 | * @author Cheng Wei 20 | */ 21 | public class ContextMenuDemoActivity extends AbstractActivity { 22 | private ContextMenuDemoPresentationModel presentationModel; 23 | private ContextMenuPresentationModel contextMenuPresentationModel; 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | 28 | MemoryProductStore productStore = MemoryProductStore.getInstance(); 29 | productStore.reset(); 30 | 31 | presentationModel = new ContextMenuDemoPresentationModel(productStore); 32 | contextMenuPresentationModel = new ContextMenuPresentationModel(productStore, presentationModel); 33 | 34 | initializeContentView(R.layout.activity_context_menu_demo, presentationModel); 35 | 36 | ListView productListView = (ListView)findViewById(R.id.productList); 37 | registerForContextMenu(productListView); 38 | } 39 | 40 | @Override 41 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 42 | MenuBinder menuBinder = createMenuBinder(menu, getMenuInflater()); 43 | menuBinder.inflateAndBind(R.menu.context_menu, contextMenuPresentationModel); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/ContextualActionModeActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.MenuBinder; 4 | import org.robobinding.gallery.R; 5 | import org.robobinding.gallery.model.MemoryProductStore; 6 | import org.robobinding.gallery.presentationmodel.ContextualActionModePresentationModel; 7 | 8 | import android.os.Bundle; 9 | import android.support.v7.view.ActionMode; 10 | import android.view.Menu; 11 | import android.view.MenuItem; 12 | import android.view.View; 13 | import android.widget.AdapterView; 14 | import android.widget.AdapterView.OnItemLongClickListener; 15 | import android.widget.ListView; 16 | 17 | /** 18 | * 19 | * @since 1.0 20 | * @version $Revision: 1.0 $ 21 | * @author Cheng Wei 22 | */ 23 | public class ContextualActionModeActivity extends AbstractActivity { 24 | private ContextualActionModePresentationModel presentationModel; 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | 29 | MemoryProductStore productStore = MemoryProductStore.getInstance(); 30 | productStore.reset(); 31 | 32 | presentationModel = new ContextualActionModePresentationModel(productStore); 33 | 34 | initializeContentView(R.layout.activity_contextual_action_mode, presentationModel); 35 | 36 | ListView productListView = (ListView)findViewById(R.id.productList); 37 | productListView.setOnItemLongClickListener(new OnItemLongClickListener() { 38 | @Override 39 | public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { 40 | startSupportActionMode(new ActionMode.Callback() { 41 | 42 | @Override 43 | public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { 44 | return false; 45 | } 46 | 47 | @Override 48 | public void onDestroyActionMode(ActionMode actionMode) { 49 | } 50 | 51 | @Override 52 | public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { 53 | MenuBinder menuBinder = createMenuBinder(menu, getMenuInflater()); 54 | menuBinder.inflateAndBind(R.menu.contextual_action_mode, presentationModel); 55 | return true; 56 | } 57 | 58 | @Override 59 | public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { 60 | return false; 61 | } 62 | }); 63 | return true; 64 | } 65 | }); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/CustomComponentActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.ViewBinder; 4 | import org.robobinding.binder.BinderFactory; 5 | import org.robobinding.binder.BinderFactoryBuilder; 6 | import org.robobinding.gallery.R; 7 | import org.robobinding.gallery.model.customcomponent.TitleDescriptionBar; 8 | import org.robobinding.gallery.model.customcomponent.TitleDescriptionBarBinding; 9 | import org.robobinding.gallery.presentationmodel.CustomComponentPresentationModel; 10 | 11 | import android.app.Activity; 12 | import android.os.Bundle; 13 | import android.view.View; 14 | 15 | /** 16 | * 17 | * @since 1.0 18 | * @version $Revision: 1.0 $ 19 | * @author Cheng Wei 20 | */ 21 | public class CustomComponentActivity extends Activity { 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | 26 | CustomComponentPresentationModel presentationModel = new CustomComponentPresentationModel(); 27 | 28 | initializeContentView(R.layout.activity_custom_component, presentationModel); 29 | } 30 | 31 | private void initializeContentView(int layoutId, Object presentationModel) { 32 | ViewBinder viewBinder = createViewBinder(); 33 | View rootView = viewBinder.inflateAndBind(layoutId, presentationModel); 34 | setContentView(rootView); 35 | } 36 | 37 | private ViewBinder createViewBinder() { 38 | BinderFactory binderFactory = new BinderFactoryBuilder() 39 | .add(new TitleDescriptionBarBinding().forView(TitleDescriptionBar.class)) 40 | .build(); 41 | return binderFactory.createViewBinder(this); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/EditTextActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.gallery.R; 4 | import org.robobinding.gallery.presentationmodel.EditTextPresentationModel; 5 | 6 | import android.os.Bundle; 7 | 8 | /** 9 | * 10 | * @since 1.0 11 | * @version $Revision: 1.0 $ 12 | * @author Cheng Wei 13 | */ 14 | public class EditTextActivity extends AbstractActivity { 15 | private EditTextPresentationModel presentationModel; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | 21 | presentationModel = new EditTextPresentationModel(); 22 | initializeContentView(R.layout.activity_edittext, presentationModel); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/FragmentDemo.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.ViewBinder; 4 | import org.robobinding.gallery.R; 5 | import org.robobinding.gallery.model.MemoryProductStore; 6 | import org.robobinding.gallery.model.Product; 7 | import org.robobinding.gallery.presentationmodel.FragmentDemoPresentationModel; 8 | 9 | import android.os.Bundle; 10 | import android.support.annotation.Nullable; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | 15 | /** 16 | * 17 | * @since 1.0 18 | * @version $Revision: 1.0 $ 19 | * @author Cheng Wei 20 | */ 21 | public class FragmentDemo extends AbstractFragment { 22 | public static final String EXTRA_PRODUCT_INDEX = "org.robobinding.gallery.FragmentDemo.productIndex"; 23 | 24 | private FragmentDemoPresentationModel presentationModel; 25 | 26 | @Override 27 | public void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | 30 | int productIndex = getArguments().getInt(EXTRA_PRODUCT_INDEX); 31 | Product product = MemoryProductStore.getInstance().getByIndex(productIndex); 32 | 33 | presentationModel = new FragmentDemoPresentationModel(product); 34 | } 35 | 36 | @Override 37 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 38 | ViewBinder viewBinder = createViewBinder(); 39 | return viewBinder.inflateAndBindWithoutAttachingToRoot(R.layout.fragment_demo, presentationModel, container); 40 | } 41 | 42 | public static FragmentDemo newInstance(int productIndex) { 43 | Bundle args = new Bundle(); 44 | args.putInt(EXTRA_PRODUCT_INDEX, productIndex); 45 | FragmentDemo fragment = new FragmentDemo(); 46 | fragment.setArguments(args); 47 | return fragment; 48 | } 49 | 50 | private FragmentDemo() { 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/FragmentTitleTag.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import org.robobinding.ViewBinder; 10 | import org.robobinding.gallery.R; 11 | import org.robobinding.gallery.model.MemoryProductStore; 12 | import org.robobinding.gallery.model.Product; 13 | import org.robobinding.gallery.presentationmodel.FragmentDemoPresentationModel; 14 | import org.robobinding.gallery.presentationmodel.FragmentTitleTagPresentationModel; 15 | 16 | /** 17 | * Created by cheng on 2015/7/26. 18 | */ 19 | public class FragmentTitleTag extends AbstractFragment { 20 | private FragmentTitleTagPresentationModel presentationModel; 21 | 22 | @Override 23 | public void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | 26 | presentationModel = new FragmentTitleTagPresentationModel(); 27 | } 28 | 29 | @Override 30 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 31 | ViewBinder viewBinder = createViewBinder(); 32 | return viewBinder.inflateAndBind(R.layout.fragment_title_tag, presentationModel); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/GalleryActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import java.util.Map; 4 | 5 | import org.robobinding.gallery.R; 6 | import org.robobinding.gallery.presentationmodel.GalleryPresentationModel; 7 | 8 | import android.app.Activity; 9 | import android.os.Bundle; 10 | 11 | import com.google.common.collect.Maps; 12 | 13 | /** 14 | * 15 | * @since 1.0 16 | * @version $Revision: 1.0 $ 17 | * @author Cheng Wei 18 | */ 19 | public class GalleryActivity extends AbstractActivity { 20 | @Override 21 | public void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | 24 | Map> demoActivityMappings = Maps.newLinkedHashMap(); 25 | demoActivityMappings.put("View", ViewActivity.class); 26 | demoActivityMappings.put("EditText", EditTextActivity.class); 27 | demoActivityMappings.put("AdapterView", AdapterViewActivity.class); 28 | demoActivityMappings.put("ListView", ListViewActivity.class); 29 | demoActivityMappings.put("RecyclerView", RecyclerViewActivity.class); 30 | demoActivityMappings.put("Custom Component", CustomComponentActivity.class); 31 | demoActivityMappings.put("TypedCursor", TypedCursorActivity.class); 32 | demoActivityMappings.put("Fragment & ViewPager", ListFragmentDemoActivity.class); 33 | demoActivityMappings.put("Options Menu", OptionsMenuActivity.class); 34 | demoActivityMappings.put("Context Menu", ContextMenuDemoActivity.class); 35 | demoActivityMappings.put("Contextual Action Mode", ContextualActionModeActivity.class); 36 | 37 | GalleryPresentationModel presentationModel = new GalleryPresentationModel(this, demoActivityMappings); 38 | initializeContentView(R.layout.activity_gallery, presentationModel); 39 | } 40 | } -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/GalleryApp.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.binder.BinderFactory; 4 | import org.robobinding.binder.BinderFactoryBuilder; 5 | import org.robobinding.customviewbinding.CustomViewBinding; 6 | import org.robobinding.gallery.model.customcomponent.TitleDescriptionBar; 7 | import org.robobinding.gallery.model.customcomponent.TitleDescriptionBarBinding; 8 | import org.robobinding.gallery.model.typedcursor.DatabaseHelper; 9 | import org.robobinding.supportwidget.recyclerview.RecyclerViewBinding; 10 | import org.robobinding.widget.menuitemgroup.MenuItemGroup; 11 | 12 | import android.app.Application; 13 | import android.support.v7.widget.RecyclerView; 14 | import android.view.MenuItem; 15 | import android.view.View; 16 | import android.widget.TextView; 17 | 18 | /** 19 | * 20 | * @since 1.0 21 | * @version $Revision: 1.0 $ 22 | * @author Cheng Wei 23 | */ 24 | public class GalleryApp extends Application { 25 | private BinderFactory reusableBinderFactory; 26 | private DatabaseHelper databaseHelper; 27 | 28 | @Override 29 | public void onCreate() { 30 | super.onCreate(); 31 | 32 | databaseHelper = new DatabaseHelper(this); 33 | reusableBinderFactory = new BinderFactoryBuilder() 34 | .add(new ViewBindingForView().extend(View.class)) 35 | .add(new MenuItemBinding().extend(MenuItem.class)) 36 | .add(new MenuItemGroupBinding().forView(MenuItemGroup.class)) 37 | .add(CustomViewBinding.forView(RecyclerView.class, new RecyclerViewBinding())) 38 | .build(); 39 | } 40 | 41 | public BinderFactory getReusableBinderFactory() { 42 | return reusableBinderFactory; 43 | } 44 | 45 | public DatabaseHelper getDatabaseHelper() { 46 | return databaseHelper; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/ListFragmentDemo.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.ViewBinder; 4 | import org.robobinding.gallery.R; 5 | import org.robobinding.gallery.model.MemoryProductStore; 6 | import org.robobinding.gallery.presentationmodel.ListFragmentDemoPresentationModel; 7 | 8 | import android.os.Bundle; 9 | import android.support.annotation.Nullable; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | 14 | /** 15 | * 16 | * @since 1.0 17 | * @version $Revision: 1.0 $ 18 | * @author Cheng Wei 19 | */ 20 | public class ListFragmentDemo extends AbstractFragment { 21 | private ListFragmentDemoPresentationModel presentationModel; 22 | 23 | @Override 24 | public void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | 27 | MemoryProductStore productStore = MemoryProductStore.getInstance(); 28 | productStore.reset(); 29 | presentationModel = new ListFragmentDemoPresentationModel(getActivity(), productStore.getAll()); 30 | } 31 | 32 | @Override 33 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 34 | ViewBinder viewBinder = createViewBinder(); 35 | return viewBinder.inflateAndBindWithoutAttachingToRoot(R.layout.fragment_list_demo, presentationModel, container); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/ListFragmentDemoActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import android.support.v4.app.Fragment; 4 | 5 | /** 6 | * 7 | * @since 1.0 8 | * @version $Revision: 1.0 $ 9 | * @author Cheng Wei 10 | */ 11 | public class ListFragmentDemoActivity extends AbstractFragmentActivity { 12 | @Override 13 | protected Fragment createFragment() { 14 | return new ListFragmentDemo(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/ListViewActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.gallery.R; 4 | import org.robobinding.gallery.presentationmodel.ListViewPresentationModel; 5 | 6 | import android.os.Bundle; 7 | 8 | /** 9 | * 10 | * @since 1.0 11 | * @version $Revision: 1.0 $ 12 | * @author Cheng Wei 13 | */ 14 | public class ListViewActivity extends AbstractActivity { 15 | private ListViewPresentationModel presentationModel; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | 21 | presentationModel = new ListViewPresentationModel(); 22 | initializeContentView(R.layout.activity_list_view, presentationModel); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/MenuItemBinding.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import android.view.MenuItem; 4 | import android.widget.TextView; 5 | 6 | import org.robobinding.annotation.ViewBinding; 7 | import org.robobinding.customviewbinding.CustomViewBinding; 8 | 9 | /** 10 | * 11 | * @since 1.0 12 | * @version $Revision: 1.0 $ 13 | * @author Cheng Wei 14 | */ 15 | @ViewBinding(simpleOneWayProperties = {"enabled", "visible"}) 16 | public class MenuItemBinding extends CustomViewBinding { 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/MenuItemGroupBinding.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import android.widget.TextView; 4 | 5 | import org.robobinding.annotation.ViewBinding; 6 | import org.robobinding.customviewbinding.CustomViewBinding; 7 | import org.robobinding.widget.menuitemgroup.MenuItemGroup; 8 | 9 | /** 10 | * 11 | * @since 1.0 12 | * @version $Revision: 1.0 $ 13 | * @author Cheng Wei 14 | */ 15 | @ViewBinding(simpleOneWayProperties = {"enabled", "visible"}) 16 | public class MenuItemGroupBinding extends CustomViewBinding { 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/OptionMenuFragment.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.MenuBinder; 4 | import org.robobinding.gallery.R; 5 | import org.robobinding.gallery.presentationmodel.MenuPresentationModel; 6 | 7 | import android.os.Bundle; 8 | import android.support.annotation.Nullable; 9 | import android.view.LayoutInflater; 10 | import android.view.Menu; 11 | import android.view.MenuInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | 15 | /** 16 | * 17 | * @since 1.0 18 | * @version $Revision: 1.0 $ 19 | * @author Cheng Wei 20 | */ 21 | public class OptionMenuFragment extends AbstractFragment { 22 | private MenuPresentationModel presentationModel; 23 | @Override 24 | public void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | 27 | presentationModel = new MenuPresentationModel(); 28 | 29 | setRetainInstance(true); 30 | setHasOptionsMenu(true); 31 | } 32 | 33 | @Override 34 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 35 | return inflater.inflate(R.layout.fragment_options_menu, container, false); 36 | } 37 | 38 | @Override 39 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 40 | super.onCreateOptionsMenu(menu, inflater); 41 | 42 | MenuBinder menuBinder = createMenuBinder(menu, inflater); 43 | menuBinder.inflateAndBind(R.menu.options_menu, presentationModel); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/OptionsMenuActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import android.support.v4.app.Fragment; 4 | 5 | /** 6 | * 7 | * @since 1.0 8 | * @version $Revision: 1.0 $ 9 | * @author Cheng Wei 10 | */ 11 | public class OptionsMenuActivity extends AbstractFragmentActivity { 12 | @Override 13 | protected Fragment createFragment() { 14 | return new OptionMenuFragment(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/RecyclerViewActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.widget.LinearLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | 7 | import org.robobinding.gallery.R; 8 | import org.robobinding.gallery.presentationmodel.ListViewPresentationModel; 9 | import org.robobinding.gallery.presentationmodel.RecyclerViewPresentationModel; 10 | 11 | /** 12 | * 13 | * @since 1.0 14 | * @version $Revision: 1.0 $ 15 | * @author Cheng Wei 16 | */ 17 | public class RecyclerViewActivity extends AbstractActivity { 18 | private RecyclerViewPresentationModel presentationModel; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | 24 | presentationModel = new RecyclerViewPresentationModel(); 25 | initializeContentView(R.layout.activity_recycler_view, presentationModel); 26 | RecyclerView recyclerView = (RecyclerView)findViewById(R.id.recyclerView); 27 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/TypedCursorActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.gallery.R; 4 | import org.robobinding.gallery.model.Product; 5 | import org.robobinding.gallery.model.typedcursor.GetAllQuery; 6 | import org.robobinding.gallery.model.typedcursor.ProductRowMapper; 7 | import org.robobinding.gallery.model.typedcursor.ProductTable; 8 | import org.robobinding.gallery.presentationmodel.TypedCursorPresentationModel; 9 | 10 | import android.database.sqlite.SQLiteDatabase; 11 | import android.os.Bundle; 12 | 13 | /** 14 | * 15 | * @since 1.0 16 | * @version $Revision: 1.0 $ 17 | * @author Cheng Wei 18 | */ 19 | public class TypedCursorActivity extends AbstractActivity { 20 | 21 | private TypedCursorPresentationModel presentationModel; 22 | private SQLiteDatabase db; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | 28 | 29 | GetAllQuery allProductsQuery = new GetAllQuery(ProductTable.TABLE_NAME, new ProductRowMapper()); 30 | db = getDatabaseHelper().getReadableDatabase(); 31 | presentationModel = new TypedCursorPresentationModel(db, allProductsQuery); 32 | 33 | initializeContentView(R.layout.activity_typed_cursor, presentationModel); 34 | } 35 | 36 | @Override 37 | protected void onDestroy() { 38 | super.onDestroy(); 39 | 40 | presentationModel.cleanUp(); 41 | db.close(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/ViewActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.gallery.R; 4 | import org.robobinding.gallery.presentationmodel.ViewPresentationModel; 5 | 6 | import android.os.Bundle; 7 | 8 | /** 9 | * 10 | * @since 1.0 11 | * @version $Revision: 1.0 $ 12 | * @author Cheng Wei 13 | */ 14 | public class ViewActivity extends AbstractActivity { 15 | private ViewPresentationModel presentationModel; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | 21 | presentationModel = new ViewPresentationModel(); 22 | initializeContentView(R.layout.activity_view, presentationModel); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/ViewBindingForView.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import android.view.View; 4 | 5 | import org.robobinding.annotation.ViewBinding; 6 | import org.robobinding.customviewbinding.CustomViewBinding; 7 | 8 | /** 9 | * 10 | * @since 1.0 11 | * @version $Revision: 1.0 $ 12 | * @author Cheng Wei 13 | */ 14 | @ViewBinding(simpleOneWayProperties = {"enabled"}) 15 | public class ViewBindingForView extends CustomViewBinding { 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/activity/ViewPagerActivity.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.activity; 2 | 3 | import org.robobinding.gallery.R; 4 | import org.robobinding.gallery.model.MemoryProductStore; 5 | 6 | import android.os.Bundle; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v4.app.FragmentActivity; 9 | import android.support.v4.app.FragmentManager; 10 | import android.support.v4.app.FragmentStatePagerAdapter; 11 | import android.support.v4.view.ViewPager; 12 | 13 | /** 14 | * 15 | * @since 1.0 16 | * @version $Revision: 1.0 $ 17 | * @author Cheng Wei 18 | */ 19 | public class ViewPagerActivity extends FragmentActivity { 20 | @Override 21 | public void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | 24 | ViewPager viewPager = new ViewPager(this); 25 | viewPager.setId(R.id.viewPager); 26 | setContentView(viewPager); 27 | 28 | final MemoryProductStore productStore = MemoryProductStore.getInstance(); 29 | FragmentManager fm = getSupportFragmentManager(); 30 | viewPager.setAdapter(new FragmentStatePagerAdapter(fm) { 31 | @Override 32 | public int getCount() { 33 | return productStore.size(); 34 | } 35 | 36 | @Override 37 | public Fragment getItem(int index) { 38 | return FragmentDemo.newInstance(index); 39 | } 40 | }); 41 | 42 | int selectedProductIndex = getIntent().getIntExtra(FragmentDemo.EXTRA_PRODUCT_INDEX, 0); 43 | viewPager.setCurrentItem(selectedProductIndex); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/invocationlog/PublicMethodInvocationLog.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.invocationlog; 2 | 3 | /** 4 | * 5 | * @since 1.0 6 | * @version $Revision: 1.0 $ 7 | * @author Cheng Wei 8 | */ 9 | public interface PublicMethodInvocationLog 10 | { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/invocationlog/PublicMethodInvocationLogAspect.aj: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.invocationlog; 2 | 3 | import org.aspectj.lang.annotation.AdviceName; 4 | 5 | 6 | /** 7 | * 8 | * @since 1.0 9 | * @version $Revision: 1.0 $ 10 | * @author Cheng Wei 11 | */ 12 | public aspect PublicMethodInvocationLogAspect 13 | { 14 | pointcut publicMethods() : execution (public * PublicMethodInvocationLog+.*(..)); 15 | 16 | @AdviceName("logInvocation") 17 | after () : publicMethods() 18 | { 19 | System.out.println(thisJoinPointStaticPart.getSignature()+" invoked"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/MemoryProductStore.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | /** 7 | * 8 | * @since 1.0 9 | * @version $Revision: 1.0 $ 10 | * @author Cheng Wei 11 | */ 12 | public class MemoryProductStore { 13 | private static final MemoryProductStore uniqueInstance = new MemoryProductStore(); 14 | 15 | private List products; 16 | 17 | private MemoryProductStore() { 18 | this.products = TestData.products(); 19 | } 20 | 21 | public void reset() { 22 | this.products = TestData.products(); 23 | } 24 | 25 | public List getAll() { 26 | return Collections.unmodifiableList(products); 27 | } 28 | 29 | public Product getByIndex(int index) { 30 | return products.get(index); 31 | } 32 | 33 | public Product remove(int index) { 34 | return products.remove(index); 35 | } 36 | 37 | public int size() { 38 | return products.size(); 39 | } 40 | 41 | public static MemoryProductStore getInstance() { 42 | return uniqueInstance; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/Product.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model; 2 | 3 | /** 4 | * 5 | * @since 1.0 6 | * @version $Revision: 1.0 $ 7 | * @author Cheng Wei 8 | */ 9 | public class Product { 10 | private String name; 11 | private String description; 12 | 13 | public Product(String name, String description) { 14 | this.name = name; 15 | this.description = description; 16 | } 17 | 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | public String getDescription() { 23 | return description; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return name; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/Strings.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model; 2 | 3 | import android.util.SparseBooleanArray; 4 | 5 | /** 6 | * 7 | * @since 1.0 8 | * @version $Revision: 1.0 $ 9 | * @author Cheng Wei 10 | */ 11 | public class Strings { 12 | public static String toString(SparseBooleanArray array) { 13 | StringBuilder sb = new StringBuilder(); 14 | for (int i = 0; i < array.size(); i++) { 15 | sb.append(array.keyAt(i)); 16 | sb.append(":"); 17 | sb.append(array.valueAt(i)); 18 | sb.append(", "); 19 | } 20 | 21 | if (sb.toString().endsWith(", ")) { 22 | sb.delete(sb.length() - 2, sb.length()); 23 | } 24 | 25 | return sb.toString(); 26 | } 27 | 28 | private Strings() { 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/TestData.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model; 2 | 3 | import com.google.common.collect.Lists; 4 | 5 | import java.util.List; 6 | import java.util.Random; 7 | 8 | /** 9 | * 10 | * @since 1.0 11 | * @version $Revision: 1.0 $ 12 | * @author Cheng Wei 13 | */ 14 | public class TestData { 15 | public static List products() { 16 | List products = Lists.newArrayList(); 17 | 18 | int numProducts = new Random().nextInt(30)+10; 19 | for(int i=1; i<=numProducts; i++) { 20 | products.add(new Product("product#"+i, "description for product#"+i)); 21 | } 22 | 23 | return products; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/adapterview/SampleStringType.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model.adapterview; 2 | 3 | import com.google.common.collect.Lists; 4 | 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | /** 9 | * 10 | * @since 1.0 11 | * @version $Revision: 1.0 $ 12 | * @author Cheng Wei 13 | */ 14 | public enum SampleStringType 15 | { 16 | SAMPLE1("Sample strings 1", SampleStrings.getSample1()), 17 | SAMPLE2("Sample strings 2", SampleStrings.getSample2()); 18 | 19 | private String name; 20 | private List sample; 21 | 22 | private SampleStringType(String name, List sample) 23 | { 24 | this.name = name; 25 | this.sample = sample; 26 | } 27 | 28 | @Override 29 | public String toString() 30 | { 31 | return name; 32 | } 33 | 34 | public List getSample() 35 | { 36 | return sample; 37 | } 38 | 39 | private static List types = Lists.newArrayList(SampleStringType.values()); 40 | 41 | public static List types() 42 | { 43 | return Collections.unmodifiableList(types); 44 | } 45 | 46 | public static SampleStringType valueOf(int index) 47 | { 48 | return types.get(index); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/adapterview/SampleStrings.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model.adapterview; 2 | 3 | import com.google.common.collect.Lists; 4 | 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | /** 9 | * 10 | * @since 1.0 11 | * @version $Revision: 1.0 $ 12 | * @author Cheng Wei 13 | */ 14 | public class SampleStrings 15 | { 16 | private static final List strings = createSample("Sample"); 17 | private static final List sample1 = createSample("Sample1"); 18 | private static final List sample2 = createSample("Sample2"); 19 | 20 | private static List createSample(String sampleName) 21 | { 22 | List strings = Lists.newArrayList(); 23 | strings.add(sampleName+" text1"); 24 | strings.add(sampleName+" text2"); 25 | strings.add(sampleName+" text3"); 26 | strings.add(sampleName+" text4"); 27 | return strings; 28 | } 29 | 30 | public static List getSample() 31 | { 32 | return Collections.unmodifiableList(strings); 33 | } 34 | 35 | public static List getSample1() 36 | { 37 | return Collections.unmodifiableList(sample1); 38 | } 39 | 40 | public static List getSample2() 41 | { 42 | return Collections.unmodifiableList(sample2); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/adapterview/StringItemLayout.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model.adapterview; 2 | 3 | import com.google.common.collect.Lists; 4 | 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | import org.robobinding.gallery.R; 9 | 10 | /** 11 | * 12 | * @since 1.0 13 | * @version $Revision: 1.0 $ 14 | * @author Cheng Wei 15 | */ 16 | public enum StringItemLayout 17 | { 18 | item_layout1("Item layout 1", R.layout.string_item_layout1), 19 | item_layout2("Item layout 2", R.layout.string_item_layout2); 20 | 21 | private String name; 22 | private int layoutResourceId; 23 | 24 | private StringItemLayout(String name, int layoutResourceId) 25 | { 26 | this.name = name; 27 | this.layoutResourceId = layoutResourceId; 28 | } 29 | 30 | @Override 31 | public String toString() 32 | { 33 | return name; 34 | } 35 | 36 | public int getLayoutResourceId() 37 | { 38 | return layoutResourceId; 39 | } 40 | 41 | private static List itemLayouts = Lists.newArrayList(StringItemLayout.values()); 42 | 43 | public static List itemLayouts() 44 | { 45 | return Collections.unmodifiableList(itemLayouts); 46 | } 47 | 48 | public static StringItemLayout valueOf(int index) 49 | { 50 | return itemLayouts.get(index); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/customcomponent/TitleDescriptionBar.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model.customcomponent; 2 | 3 | import org.robobinding.gallery.R; 4 | 5 | import android.content.Context; 6 | import android.content.res.TypedArray; 7 | import android.util.AttributeSet; 8 | import android.view.LayoutInflater; 9 | import android.widget.LinearLayout; 10 | import android.widget.TextView; 11 | 12 | /** 13 | * 14 | * @since 1.0 15 | * @version $Revision: 1.0 $ 16 | * @author Cheng Wei 17 | */ 18 | public class TitleDescriptionBar extends LinearLayout { 19 | private TextView title; 20 | private TextView description; 21 | 22 | public TitleDescriptionBar(Context context, AttributeSet attrs) { 23 | this(context, attrs, R.layout.title_description_bar); 24 | } 25 | 26 | protected TitleDescriptionBar(Context context, AttributeSet attrs, int layoutId) { 27 | super(context, attrs); 28 | 29 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 30 | inflater.inflate(layoutId, this); 31 | title = (TextView) findViewById(R.id.title); 32 | description = (TextView) findViewById(R.id.description); 33 | 34 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TitleDescriptionBar); 35 | String titleText = a.getString(R.styleable.TitleDescriptionBar_title); 36 | String descriptionText = a.getString(R.styleable.TitleDescriptionBar_description); 37 | a.recycle(); 38 | 39 | setTitle(titleText); 40 | setDescription(descriptionText); 41 | } 42 | 43 | public void setTitle(CharSequence titleText) { 44 | title.setText(titleText); 45 | } 46 | 47 | public void setDescription(CharSequence descriptionText) { 48 | description.setText(descriptionText); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/customcomponent/TitleDescriptionBarBinding.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model.customcomponent; 2 | 3 | import org.robobinding.annotation.ViewBinding; 4 | import org.robobinding.customviewbinding.CustomViewBinding; 5 | 6 | /** 7 | * 8 | * @since 1.0 9 | * @version $Revision: 1.0 $ 10 | * @author Cheng Wei 11 | */ 12 | @ViewBinding(simpleOneWayProperties = {"title", "description"}) 13 | public class TitleDescriptionBarBinding extends CustomViewBinding { 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/listview/SampleStringsFooter.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model.listview; 2 | 3 | import org.robobinding.annotation.PresentationModel; 4 | import org.robobinding.gallery.model.adapterview.SampleStrings; 5 | 6 | import android.text.Html; 7 | import android.text.Spanned; 8 | 9 | /** 10 | * 11 | * @since 1.0 12 | * @version $Revision: 1.0 $ 13 | * @author Cheng Wei 14 | */ 15 | @PresentationModel 16 | public class SampleStringsFooter 17 | { 18 | private SampleStringsFooter() 19 | { 20 | } 21 | 22 | public Spanned getDescription() 23 | { 24 | int size = SampleStrings.getSample().size(); 25 | return Html.fromHtml("There are "+size+" samples."); 26 | } 27 | 28 | private static final SampleStringsFooter uniqueInstance = new SampleStringsFooter(); 29 | 30 | public static SampleStringsFooter getInstance() 31 | { 32 | return uniqueInstance; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/typedcursor/DatabaseHelper.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model.typedcursor; 2 | 3 | import java.text.MessageFormat; 4 | import java.util.List; 5 | 6 | import org.robobinding.gallery.model.Product; 7 | import org.robobinding.gallery.model.TestData; 8 | 9 | import android.content.ContentValues; 10 | import android.content.Context; 11 | import android.database.sqlite.SQLiteDatabase; 12 | import android.database.sqlite.SQLiteOpenHelper; 13 | 14 | /** 15 | * @since 1.0 16 | * @version $Revision: $ 17 | * @author Cheng Wei 18 | * 19 | */ 20 | public class DatabaseHelper extends SQLiteOpenHelper { 21 | private static final int DB_VERSION = 2; 22 | 23 | public DatabaseHelper(Context context) { 24 | super(context, "typedcursorsample.db", null, DB_VERSION); 25 | } 26 | 27 | @Override 28 | public void onCreate(SQLiteDatabase db) { 29 | String itemTable = MessageFormat.format("create table {0} ({1} integer primary key autoincrement, {2} text not null, {3} text not null)", 30 | ProductTable.TABLE_NAME, ProductTable._ID, ProductTable.NAME, ProductTable.DESCRIPTION); 31 | db.execSQL(itemTable); 32 | 33 | List products = TestData.products(); 34 | for(Product product : products) { 35 | insertProduct(db, product); 36 | } 37 | } 38 | 39 | private long insertProduct(SQLiteDatabase db, Product product) { 40 | ContentValues values = new ContentValues(); 41 | values.put(ProductTable.NAME, product.getName()); 42 | values.put(ProductTable.DESCRIPTION, product.getDescription()); 43 | return db.insert(ProductTable.TABLE_NAME, null, values); 44 | } 45 | 46 | @Override 47 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 48 | db.execSQL("drop table if exists " + ProductTable.TABLE_NAME); 49 | onCreate(db); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/typedcursor/GetAllQuery.java: -------------------------------------------------------------------------------- 1 | /** 2 | * GetAllQuery.java 3 | * Nov 2, 2011 4 | * Copyright 2009~2011 ESCA Mobile Ltd company, Inc. All rights reserved. 5 | * ESCA Mobile Ltd PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 6 | */ 7 | package org.robobinding.gallery.model.typedcursor; 8 | 9 | import org.robobinding.itempresentationmodel.RowMapper; 10 | import org.robobinding.itempresentationmodel.TypedCursor; 11 | import org.robobinding.itempresentationmodel.TypedCursorAdapter; 12 | 13 | import android.database.Cursor; 14 | import android.database.sqlite.SQLiteDatabase; 15 | import android.provider.BaseColumns; 16 | 17 | import com.google.common.base.Preconditions; 18 | import com.google.common.base.Strings; 19 | 20 | /** 21 | * @since 1.0 22 | * @version $Revision: $ 23 | * @author Cheng Wei 24 | * 25 | */ 26 | public class GetAllQuery 27 | { 28 | private String tableName; 29 | private final RowMapper rowMapper; 30 | 31 | public GetAllQuery(String tableName, RowMapper rowMapper) 32 | { 33 | Preconditions.checkNotNull(Strings.isNullOrEmpty(tableName), "table name cannot be empty"); 34 | Preconditions.checkNotNull(rowMapper, "row mapper cannot be null"); 35 | 36 | this.tableName = tableName; 37 | this.rowMapper = rowMapper; 38 | } 39 | 40 | public TypedCursor execute(SQLiteDatabase db) 41 | { 42 | Cursor cursor = db.query( 43 | tableName, 44 | null, 45 | null, 46 | null, 47 | null, 48 | null, 49 | BaseColumns._ID+" ASC"); 50 | return new TypedCursorAdapter(cursor, rowMapper); 51 | } 52 | } -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/typedcursor/ProductItemPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model.typedcursor; 2 | 3 | import java.text.MessageFormat; 4 | 5 | import org.robobinding.gallery.model.Product; 6 | import org.robobinding.itempresentationmodel.ItemContext; 7 | import org.robobinding.itempresentationmodel.ItemPresentationModel; 8 | 9 | /** 10 | * @author Cheng Wei 11 | * @version $Revision: 1.0 $ 12 | * @since 1.0 13 | */ 14 | public class ProductItemPresentationModel implements ItemPresentationModel { 15 | private Product product; 16 | private int index; 17 | 18 | public String getProductDetails() { 19 | return MessageFormat.format("{0}.{1}: {2}", 20 | index + 1, 21 | product.getName(), 22 | product.getDescription()); 23 | } 24 | 25 | public void updateData(Product product, ItemContext itemContext) { 26 | this.index = itemContext.getPosition(); 27 | this.product = product; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/typedcursor/ProductRowMapper.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model.typedcursor; 2 | 3 | import org.robobinding.gallery.model.Product; 4 | import org.robobinding.itempresentationmodel.RowMapper; 5 | 6 | import android.database.Cursor; 7 | 8 | /** 9 | * 10 | * @since 1.0 11 | * @version $Revision: 1.0 $ 12 | * @author Cheng Wei 13 | */ 14 | public class ProductRowMapper implements RowMapper { 15 | 16 | @Override 17 | public Product mapRow(Cursor cursor) { 18 | String name = cursor.getString(cursor.getColumnIndex(ProductTable.NAME)); 19 | String description = cursor.getString(cursor.getColumnIndex(ProductTable.DESCRIPTION)); 20 | return new Product(name, description); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/typedcursor/ProductTable.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model.typedcursor; 2 | 3 | import android.provider.BaseColumns; 4 | 5 | 6 | /** 7 | * 8 | * @since 1.0 9 | * @version $Revision: 1.0 $ 10 | * @author Cheng Wei 11 | */ 12 | public interface ProductTable extends BaseColumns { 13 | String TABLE_NAME = "product"; 14 | 15 | String NAME = "name"; 16 | String DESCRIPTION = "description"; 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/view/BooleanVisibility.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model.view; 2 | 3 | /** 4 | * 5 | * @since 1.0 6 | * @version $Revision: 1.0 $ 7 | * @author Cheng Wei 8 | */ 9 | public class BooleanVisibility 10 | { 11 | private boolean visible; 12 | public BooleanVisibility() 13 | { 14 | visible = false; 15 | } 16 | 17 | public boolean getValue() 18 | { 19 | return visible; 20 | } 21 | 22 | public void nextState() 23 | { 24 | visible = !visible; 25 | } 26 | 27 | public String describe(String visibleDescription, String invisibleDescription) 28 | { 29 | return visible?visibleDescription:invisibleDescription; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/model/view/IntegerVisibility.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.model.view; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * 7 | * @since 1.0 8 | * @version $Revision: 1.0 $ 9 | * @author Cheng Wei 10 | */ 11 | public class IntegerVisibility 12 | { 13 | private int[] values; 14 | private int currentIndex; 15 | 16 | public IntegerVisibility() 17 | { 18 | values = new int[]{View.VISIBLE, View.INVISIBLE, View.GONE}; 19 | currentIndex = 2; 20 | } 21 | 22 | public int getValue() 23 | { 24 | return values[currentIndex]; 25 | } 26 | 27 | public void nextState() 28 | { 29 | currentIndex = nextIndex(); 30 | } 31 | 32 | private int nextIndex() 33 | { 34 | int nextIndex = currentIndex + 1; 35 | if(nextIndex >= values.length) 36 | { 37 | nextIndex = 0; 38 | } 39 | return nextIndex; 40 | } 41 | 42 | public String describe(String visibleDescription, String invisibleDescription, String goneDescription) 43 | { 44 | if(currentIndex == 0) 45 | { 46 | return visibleDescription; 47 | }else if(currentIndex == 1) 48 | { 49 | return invisibleDescription; 50 | }else 51 | { 52 | return goneDescription; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/AdapterViewPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import java.util.List; 4 | 5 | import org.robobinding.annotation.DependsOnStateOf; 6 | import org.robobinding.annotation.ItemPresentationModel; 7 | import org.robobinding.annotation.PreInitializingViews; 8 | import org.robobinding.annotation.PresentationModel; 9 | import org.robobinding.gallery.invocationlog.PublicMethodInvocationLog; 10 | import org.robobinding.gallery.model.adapterview.SampleStringType; 11 | import org.robobinding.gallery.model.adapterview.SampleStrings; 12 | import org.robobinding.gallery.model.adapterview.StringItemLayout; 13 | import org.robobinding.itempresentationmodel.ViewTypeSelectionContext; 14 | 15 | /** 16 | * @author Cheng Wei 17 | * @version $Revision: 1.0 $ 18 | * @since 1.0 19 | */ 20 | @PresentationModel 21 | public class AdapterViewPresentationModel implements PublicMethodInvocationLog { 22 | private static final String SELECTED_SOURCE_INDEX = "selectedSourceIndex"; 23 | 24 | private static final String SELECTED_ITEM_LAYOUT_INDEX = "selectedItemLayoutIndex"; 25 | 26 | private int selectedSourceIndex; 27 | 28 | private int selectedItemLayoutIndex; 29 | 30 | public AdapterViewPresentationModel() { 31 | selectedSourceIndex = 0; 32 | 33 | selectedItemLayoutIndex = 0; 34 | } 35 | 36 | @ItemPresentationModel(value = StringItemPresentationModel.class) 37 | @DependsOnStateOf(SELECTED_SOURCE_INDEX) 38 | public List getDynamicStrings() { 39 | return getSelectedSource().getSample(); 40 | } 41 | 42 | @ItemPresentationModel(value = ToStringItemPresentationModel.class) 43 | public List getSources() { 44 | return SampleStringType.types(); 45 | } 46 | 47 | public int getSelectedSourceIndex() { 48 | return selectedSourceIndex; 49 | } 50 | 51 | public void setSelectedSourceIndex(int selectedSourceIndex) { 52 | this.selectedSourceIndex = selectedSourceIndex; 53 | } 54 | 55 | private SampleStringType getSelectedSource() { 56 | return SampleStringType.valueOf(selectedSourceIndex); 57 | } 58 | 59 | @DependsOnStateOf(SELECTED_ITEM_LAYOUT_INDEX) 60 | public int getDynamicItemLayout() { 61 | return getSelectedItemLayout().getLayoutResourceId(); 62 | } 63 | 64 | @ItemPresentationModel(value = StringItemPresentationModel.class) 65 | public List getStaticStrings() { 66 | return SampleStrings.getSample(); 67 | } 68 | 69 | @ItemPresentationModel(value = ToStringItemPresentationModel.class) 70 | public List getItemLayouts() { 71 | return StringItemLayout.itemLayouts(); 72 | } 73 | 74 | public int getSelectedItemLayoutIndex() { 75 | return selectedItemLayoutIndex; 76 | } 77 | 78 | public void setSelectedItemLayoutIndex(int selectedItemLayoutIndex) { 79 | this.selectedItemLayoutIndex = selectedItemLayoutIndex; 80 | } 81 | 82 | private StringItemLayout getSelectedItemLayout() { 83 | return StringItemLayout.valueOf(selectedItemLayoutIndex); 84 | } 85 | 86 | @ItemPresentationModel(value = StringItemPresentationModel.class, 87 | factoryMethod = "createDifferentStringItemPresentationModel", 88 | viewTypeSelector = "selectViewType") 89 | public List getDifferentLookStrings() { 90 | return SampleStrings.getSample(); 91 | } 92 | 93 | public StringItemPresentationModel createDifferentStringItemPresentationModel(int viewType) { 94 | if(viewType == 0) { 95 | return new StringItemPresentationModel1(); 96 | } else { 97 | return new StringItemPresentationModel2(); 98 | } 99 | } 100 | 101 | public int selectViewType(ViewTypeSelectionContext context) { 102 | return context.getPosition() % context.getViewTypeCount(); 103 | } 104 | 105 | 106 | @ItemPresentationModel(value = StringItemPresentationModel.class, preInitializingViews = PreInitializingViews.DEFAULT) 107 | public List getDefaultPreInitializingViewsStrings() { 108 | return SampleStrings.getSample(); 109 | } 110 | 111 | private static class StringItemPresentationModel1 extends StringItemPresentationModel { 112 | @Override 113 | public String getValue() { 114 | return super.getValue() + " - from StringItemPresentationModel1"; 115 | } 116 | } 117 | 118 | private static class StringItemPresentationModel2 extends StringItemPresentationModel { 119 | @Override 120 | public String getValue() { 121 | return super.getValue() + " - from StringItemPresentationModel2"; 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/ContextMenuDemoPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import java.util.List; 4 | 5 | import org.robobinding.annotation.ItemPresentationModel; 6 | import org.robobinding.annotation.PresentationModel; 7 | import org.robobinding.gallery.model.MemoryProductStore; 8 | import org.robobinding.gallery.model.Product; 9 | import org.robobinding.gallery.presentationmodel.ContextMenuPresentationModel.ProductOperationListener; 10 | import org.robobinding.presentationmodel.HasPresentationModelChangeSupport; 11 | import org.robobinding.presentationmodel.PresentationModelChangeSupport; 12 | 13 | /** 14 | * @author Cheng Wei 15 | * @version $Revision: 1.0 $ 16 | * @since 1.0 17 | */ 18 | @PresentationModel 19 | public class ContextMenuDemoPresentationModel implements ProductOperationListener, HasPresentationModelChangeSupport { 20 | private final MemoryProductStore productStore; 21 | private final PresentationModelChangeSupport changeSupport; 22 | 23 | public ContextMenuDemoPresentationModel(MemoryProductStore productStore) { 24 | this.productStore = productStore; 25 | changeSupport = new PresentationModelChangeSupport(this); 26 | } 27 | 28 | @ItemPresentationModel(value = ToStringItemPresentationModel.class) 29 | public List getProducts() { 30 | return productStore.getAll(); 31 | } 32 | 33 | @Override 34 | public void onProductDeleted(Product deletedProduct) { 35 | refreshProducts(); 36 | } 37 | 38 | private void refreshProducts() { 39 | changeSupport.firePropertyChange("products"); 40 | } 41 | 42 | @Override 43 | public PresentationModelChangeSupport getPresentationModelChangeSupport() { 44 | return changeSupport; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/ContextMenuPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import org.robobinding.annotation.PresentationModel; 4 | import org.robobinding.gallery.model.MemoryProductStore; 5 | import org.robobinding.gallery.model.Product; 6 | 7 | import android.view.MenuItem; 8 | import android.widget.AdapterView.AdapterContextMenuInfo; 9 | 10 | /** 11 | * @author Cheng Wei 12 | * @version $Revision: 1.0 $ 13 | * @since 1.0 14 | */ 15 | @PresentationModel 16 | public class ContextMenuPresentationModel { 17 | private MemoryProductStore productStore; 18 | private ProductOperationListener productOperationListener; 19 | 20 | public ContextMenuPresentationModel(MemoryProductStore productStore, ProductOperationListener productOperationListener) { 21 | this.productStore = productStore; 22 | this.productOperationListener = productOperationListener; 23 | } 24 | 25 | public void deleteProduct(MenuItem menuItem) { 26 | AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) menuItem.getMenuInfo(); 27 | Product deletedProduct = productStore.remove(menuInfo.position); 28 | productOperationListener.onProductDeleted(deletedProduct); 29 | } 30 | 31 | public interface ProductOperationListener { 32 | void onProductDeleted(Product deletedProduct); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/ContextualActionModePresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.HashSet; 6 | import java.util.List; 7 | import java.util.Set; 8 | 9 | import org.robobinding.annotation.ItemPresentationModel; 10 | import org.robobinding.annotation.PresentationModel; 11 | import org.robobinding.gallery.model.MemoryProductStore; 12 | import org.robobinding.gallery.model.Product; 13 | import org.robobinding.presentationmodel.HasPresentationModelChangeSupport; 14 | import org.robobinding.presentationmodel.PresentationModelChangeSupport; 15 | 16 | /** 17 | * @author Cheng Wei 18 | * @version $Revision: 1.0 $ 19 | * @since 1.0 20 | */ 21 | @PresentationModel 22 | public class ContextualActionModePresentationModel implements HasPresentationModelChangeSupport{ 23 | private final MemoryProductStore productStore; 24 | private final PresentationModelChangeSupport changeSupport; 25 | private Set selectedProductIndexes; 26 | 27 | public ContextualActionModePresentationModel(MemoryProductStore productStore) { 28 | this.productStore = productStore; 29 | changeSupport = new PresentationModelChangeSupport(this); 30 | selectedProductIndexes = new HashSet(); 31 | } 32 | 33 | @ItemPresentationModel(value = ToStringItemPresentationModel.class) 34 | public List getProducts() { 35 | return productStore.getAll(); 36 | } 37 | 38 | public void deleteSelectedProducts() { 39 | List indexes = new ArrayList(selectedProductIndexes); 40 | selectedProductIndexes.clear(); 41 | Collections.sort(indexes); 42 | Collections.reverse(indexes); 43 | for (Integer index : indexes) { 44 | productStore.remove(index); 45 | } 46 | 47 | refreshProducts(); 48 | } 49 | 50 | private void refreshProducts() { 51 | changeSupport.firePropertyChange("selectedProductIndexes"); 52 | changeSupport.firePropertyChange("products"); 53 | } 54 | 55 | public Set getSelectedProductIndexes() { 56 | return selectedProductIndexes; 57 | } 58 | 59 | public void setSelectedProductIndexes(Set selectedProductIndexes) { 60 | this.selectedProductIndexes = selectedProductIndexes; 61 | } 62 | 63 | @Override 64 | public PresentationModelChangeSupport getPresentationModelChangeSupport() { 65 | return changeSupport; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/CustomComponentPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import org.robobinding.annotation.PresentationModel; 4 | import org.robobinding.presentationmodel.HasPresentationModelChangeSupport; 5 | import org.robobinding.presentationmodel.PresentationModelChangeSupport; 6 | 7 | 8 | /** 9 | * @author Cheng Wei 10 | * @version $Revision: 1.0 $ 11 | * @since 1.0 12 | */ 13 | @PresentationModel 14 | public class CustomComponentPresentationModel implements HasPresentationModelChangeSupport { 15 | private final PresentationModelChangeSupport changeSupport; 16 | private String title; 17 | private String description; 18 | private String newTitle; 19 | private String newDescription; 20 | 21 | public CustomComponentPresentationModel() { 22 | changeSupport = new PresentationModelChangeSupport(this); 23 | this.title = "Default title"; 24 | this.description = "Default description"; 25 | } 26 | 27 | public String getTitle() { 28 | return title; 29 | } 30 | 31 | public String getDescription() { 32 | return description; 33 | } 34 | 35 | public String getNewTitle() { 36 | return newTitle; 37 | } 38 | 39 | public void setNewTitle(String newTitle) { 40 | this.newTitle = newTitle; 41 | } 42 | 43 | public String getNewDescription() { 44 | return newDescription; 45 | } 46 | 47 | public void setNewDescription(String newDescription) { 48 | this.newDescription = newDescription; 49 | } 50 | 51 | public void applyNewTitleDescription() { 52 | title = newTitle; 53 | description = newDescription; 54 | 55 | changeSupport.firePropertyChange("title"); 56 | changeSupport.firePropertyChange("description"); 57 | } 58 | 59 | @Override 60 | public PresentationModelChangeSupport getPresentationModelChangeSupport() { 61 | return changeSupport; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/EditTextPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | 4 | import org.robobinding.annotation.PresentationModel; 5 | 6 | /** 7 | * @author Cheng Wei 8 | * @version $Revision: 1.0 $ 9 | * @since 1.0 10 | */ 11 | @PresentationModel 12 | public class EditTextPresentationModel { 13 | private String text; 14 | 15 | public String getText() { 16 | return text; 17 | } 18 | 19 | public void setText(String text) { 20 | this.text = text; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/FragmentDemoPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import org.robobinding.annotation.PresentationModel; 4 | import org.robobinding.gallery.model.Product; 5 | 6 | /** 7 | * @author Cheng Wei 8 | * @version $Revision: 1.0 $ 9 | * @since 1.0 10 | */ 11 | @PresentationModel 12 | public class FragmentDemoPresentationModel { 13 | private Product product; 14 | 15 | public FragmentDemoPresentationModel(Product product) { 16 | this.product = product; 17 | } 18 | 19 | public String getProductName() { 20 | return product.getName(); 21 | } 22 | 23 | public String getProductDescription() { 24 | return product.getDescription(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/FragmentTitleTagPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import org.robobinding.annotation.PresentationModel; 4 | import org.robobinding.gallery.model.Product; 5 | 6 | /** 7 | * @author Cheng Wei 8 | * @version $Revision: 1.0 $ 9 | * @since 1.0 10 | */ 11 | @PresentationModel 12 | public class FragmentTitleTagPresentationModel { 13 | public FragmentTitleTagPresentationModel() { 14 | } 15 | 16 | public String getTitle() { 17 | return "fragment tag title"; 18 | } 19 | 20 | public String getDescription() { 21 | return ": some description"; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/GalleryPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.robobinding.annotation.DependsOnStateOf; 7 | import org.robobinding.annotation.ItemPresentationModel; 8 | import org.robobinding.annotation.PresentationModel; 9 | 10 | import android.app.Activity; 11 | import android.content.Context; 12 | import android.content.Intent; 13 | 14 | import com.google.common.collect.Lists; 15 | 16 | /** 17 | * @author Cheng Wei 18 | * @version $Revision: 1.0 $ 19 | * @since 1.0 20 | */ 21 | @PresentationModel 22 | public class GalleryPresentationModel { 23 | private Context context; 24 | private Map> demoActivityMappings; 25 | 26 | private int selectedDemoIndex; 27 | 28 | public GalleryPresentationModel(Context context, Map> demoActivityMappings) { 29 | this.context = context; 30 | this.demoActivityMappings = demoActivityMappings; 31 | selectedDemoIndex = 0; 32 | } 33 | 34 | @ItemPresentationModel(value = StringItemPresentationModel.class) 35 | public List getDemoList() { 36 | return Lists.newArrayList(demoActivityMappings.keySet()); 37 | } 38 | 39 | public int getSelectedDemoIndex() { 40 | return selectedDemoIndex; 41 | } 42 | 43 | public void setSelectedDemoIndex(int selectedDemoIndex) { 44 | this.selectedDemoIndex = selectedDemoIndex; 45 | } 46 | 47 | @DependsOnStateOf("selectedDemoIndex") 48 | public String getSelectedDemoDescription() { 49 | return "Try " + getSelectedDemo(); 50 | } 51 | 52 | public void showDemo() { 53 | String demo = getSelectedDemo(); 54 | 55 | Class activityClass = demoActivityMappings.get(demo); 56 | context.startActivity(new Intent(context, activityClass)); 57 | } 58 | 59 | private String getSelectedDemo() { 60 | return getDemoList().get(selectedDemoIndex); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/ListFragmentDemoPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import java.util.List; 4 | 5 | import org.robobinding.annotation.ItemPresentationModel; 6 | import org.robobinding.annotation.PresentationModel; 7 | import org.robobinding.gallery.activity.FragmentDemo; 8 | import org.robobinding.gallery.activity.ViewPagerActivity; 9 | import org.robobinding.gallery.model.Product; 10 | import org.robobinding.widget.adapterview.ItemClickEvent; 11 | 12 | import android.app.Activity; 13 | import android.content.Intent; 14 | 15 | /** 16 | * @author Cheng Wei 17 | * @version $Revision: 1.0 $ 18 | * @since 1.0 19 | */ 20 | @PresentationModel 21 | public class ListFragmentDemoPresentationModel { 22 | private final Activity activity; 23 | private final List products; 24 | 25 | public ListFragmentDemoPresentationModel(Activity activity, List products) { 26 | this.activity = activity; 27 | this.products = products; 28 | } 29 | 30 | @ItemPresentationModel(value = ToStringItemPresentationModel.class) 31 | public List getProducts() { 32 | return products; 33 | } 34 | 35 | public void viewProduct(ItemClickEvent event) { 36 | Intent i = new Intent(activity, ViewPagerActivity.class); 37 | i.putExtra(FragmentDemo.EXTRA_PRODUCT_INDEX, event.getPosition()); 38 | activity.startActivity(i); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/ListViewPresentationModel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Cheng Wei, Robert Taylor 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions 14 | * and limitations under the License. 15 | */ 16 | package org.robobinding.gallery.presentationmodel; 17 | 18 | import java.util.List; 19 | 20 | import org.robobinding.annotation.DependsOnStateOf; 21 | import org.robobinding.annotation.ItemPresentationModel; 22 | import org.robobinding.annotation.PresentationModel; 23 | import org.robobinding.gallery.invocationlog.PublicMethodInvocationLog; 24 | import org.robobinding.gallery.model.Strings; 25 | import org.robobinding.gallery.model.adapterview.SampleStrings; 26 | import org.robobinding.gallery.model.listview.SampleStringsFooter; 27 | import org.robobinding.gallery.model.view.BooleanVisibility; 28 | import org.robobinding.gallery.model.view.IntegerVisibility; 29 | import org.robobinding.presentationmodel.HasPresentationModelChangeSupport; 30 | import org.robobinding.presentationmodel.PresentationModelChangeSupport; 31 | 32 | import android.util.SparseBooleanArray; 33 | 34 | /** 35 | * @author Cheng Wei 36 | * @version $Revision: 1.0 $ 37 | * @since 1.0 38 | */ 39 | @PresentationModel 40 | public class ListViewPresentationModel implements HasPresentationModelChangeSupport, PublicMethodInvocationLog { 41 | private static final String FOOTER_INTEGER_VISIBILITY = "footerIntegerVisibility"; 42 | 43 | private static final String HEADER_BOOLEAN_VISIBILITY = "headerBooleanVisibility"; 44 | 45 | private final PresentationModelChangeSupport changeSupport; 46 | 47 | private BooleanVisibility headerBooleanVisibility; 48 | 49 | private IntegerVisibility footerIntegerVisibility; 50 | 51 | private SparseBooleanArray checkedItemPositions; 52 | private int checkedItemPosition; 53 | 54 | public ListViewPresentationModel() { 55 | changeSupport = new PresentationModelChangeSupport(this); 56 | headerBooleanVisibility = new BooleanVisibility(); 57 | 58 | footerIntegerVisibility = new IntegerVisibility(); 59 | 60 | checkedItemPositions = new SparseBooleanArray(); 61 | checkedItemPositions.append(0, true); 62 | checkedItemPosition = 0; 63 | } 64 | 65 | @ItemPresentationModel(value = StringItemPresentationModel.class) 66 | public List getStrings() { 67 | return SampleStrings.getSample(); 68 | } 69 | 70 | public boolean getHeaderBooleanVisibility() { 71 | return headerBooleanVisibility.getValue(); 72 | } 73 | 74 | public void changeHeaderVisibility() { 75 | headerBooleanVisibility.nextState(); 76 | changeSupport.firePropertyChange(HEADER_BOOLEAN_VISIBILITY); 77 | } 78 | 79 | @DependsOnStateOf(HEADER_BOOLEAN_VISIBILITY) 80 | public String getHeaderBooleanVisibilityDescription() { 81 | return "Header " + headerBooleanVisibility.describe("visible", "invisible"); 82 | } 83 | 84 | public SampleStringsFooter getFooter() { 85 | return SampleStringsFooter.getInstance(); 86 | } 87 | 88 | public int getFooterIntegerVisibility() { 89 | return footerIntegerVisibility.getValue(); 90 | } 91 | 92 | public void changeFooterVisibility() { 93 | footerIntegerVisibility.nextState(); 94 | changeSupport.firePropertyChange(FOOTER_INTEGER_VISIBILITY); 95 | } 96 | 97 | @DependsOnStateOf(FOOTER_INTEGER_VISIBILITY) 98 | public String getFooterIntegerVisibilityDescription() { 99 | return "Footer " + footerIntegerVisibility.describe("visible", "invisible", "gone"); 100 | } 101 | 102 | public int getCheckedItemPosition() { 103 | return checkedItemPosition; 104 | } 105 | 106 | public void setCheckedItemPosition(int checkedItemPosition) { 107 | this.checkedItemPosition = checkedItemPosition; 108 | } 109 | 110 | @DependsOnStateOf("checkedItemPosition") 111 | public String getDescriptionOfSelectedItem() { 112 | return "" + checkedItemPosition; 113 | } 114 | 115 | public SparseBooleanArray getCheckedItemPositions() { 116 | return checkedItemPositions; 117 | } 118 | 119 | public void setCheckedItemPositions(SparseBooleanArray checkedItemPositions) { 120 | this.checkedItemPositions = checkedItemPositions; 121 | } 122 | 123 | @DependsOnStateOf("checkedItemPositions") 124 | public String getDescriptionOfSelectedItems() { 125 | return Strings.toString(checkedItemPositions); 126 | } 127 | 128 | @Override 129 | public PresentationModelChangeSupport getPresentationModelChangeSupport() { 130 | return changeSupport; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/MenuPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import org.robobinding.annotation.DependsOnStateOf; 4 | import org.robobinding.annotation.PresentationModel; 5 | 6 | /** 7 | * @author Cheng Wei 8 | * @version $Revision: 1.0 $ 9 | * @since 1.0 10 | */ 11 | @PresentationModel 12 | public class MenuPresentationModel { 13 | private boolean enabled; 14 | private boolean visible; 15 | private boolean groupEnabled; 16 | private boolean groupVisible; 17 | 18 | public MenuPresentationModel() { 19 | this.enabled = true; 20 | this.visible = true; 21 | this.groupEnabled = true; 22 | this.groupVisible = true; 23 | } 24 | 25 | public void toggleTitle() { 26 | setGroupEnabled(!groupEnabled); 27 | } 28 | 29 | @DependsOnStateOf("groupEnabled") 30 | public String getTitle() { 31 | if (groupEnabled) { 32 | return "Disable group"; 33 | } else { 34 | return "Enable group"; 35 | } 36 | } 37 | 38 | public boolean isEnabled() { 39 | return enabled; 40 | } 41 | 42 | public boolean isVisible() { 43 | return visible; 44 | } 45 | 46 | public boolean isGroupEnabled() { 47 | return groupEnabled; 48 | } 49 | 50 | public void setGroupEnabled(boolean newGroupEnabled) { 51 | this.groupEnabled = newGroupEnabled; 52 | } 53 | 54 | public boolean isGroupVisible() { 55 | return groupVisible; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/RecyclerViewPresentationModel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2012 Cheng Wei, Robert Taylor 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions 14 | * and limitations under the License. 15 | */ 16 | package org.robobinding.gallery.presentationmodel; 17 | 18 | import android.util.SparseBooleanArray; 19 | 20 | import com.google.common.collect.Lists; 21 | 22 | import org.robobinding.annotation.DependsOnStateOf; 23 | import org.robobinding.annotation.ItemPresentationModel; 24 | import org.robobinding.annotation.PresentationModel; 25 | import org.robobinding.gallery.invocationlog.PublicMethodInvocationLog; 26 | import org.robobinding.gallery.model.Strings; 27 | import org.robobinding.gallery.model.adapterview.SampleStrings; 28 | import org.robobinding.gallery.model.listview.SampleStringsFooter; 29 | import org.robobinding.gallery.model.view.BooleanVisibility; 30 | import org.robobinding.gallery.model.view.IntegerVisibility; 31 | import org.robobinding.itempresentationmodel.ListObservable; 32 | import org.robobinding.itempresentationmodel.ViewTypeSelectionContext; 33 | import org.robobinding.presentationmodel.HasPresentationModelChangeSupport; 34 | import org.robobinding.presentationmodel.PresentationModelChangeSupport; 35 | 36 | import java.util.List; 37 | 38 | /** 39 | * @author Cheng Wei 40 | * @version $Revision: 1.0 $ 41 | * @since 1.0 42 | */ 43 | @PresentationModel 44 | public class RecyclerViewPresentationModel implements HasPresentationModelChangeSupport, PublicMethodInvocationLog { 45 | private final PresentationModelChangeSupport changeSupport; 46 | private final ListObservable strings; 47 | private int sampleCounter = 0; 48 | 49 | public RecyclerViewPresentationModel() { 50 | changeSupport = new PresentationModelChangeSupport(this); 51 | strings = new ListObservable(Lists.newArrayList("sample1", "sample2", "sample3")); 52 | sampleCounter = 3; 53 | } 54 | 55 | @ItemPresentationModel(value = StringItemPresentationModel.class, 56 | viewTypeSelector = "selectViewType") 57 | public ListObservable getStrings() { 58 | return strings; 59 | } 60 | 61 | public int selectViewType(ViewTypeSelectionContext context) { 62 | return context.getPosition() % context.getViewTypeCount(); 63 | } 64 | 65 | @Override 66 | public PresentationModelChangeSupport getPresentationModelChangeSupport() { 67 | return changeSupport; 68 | } 69 | 70 | public void removeLastItem() { 71 | if (!strings.isEmpty()) { 72 | strings.remove(strings.size()-1); 73 | } 74 | } 75 | 76 | public void addItem() { 77 | sampleCounter++; 78 | strings.add("sample" + sampleCounter); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/StringItemPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import android.util.Log; 4 | 5 | import org.robobinding.itempresentationmodel.ItemContext; 6 | import org.robobinding.itempresentationmodel.ItemPresentationModel; 7 | 8 | /** 9 | * @author Cheng Wei 10 | * @version $Revision: 1.0 $ 11 | * @since 1.0 12 | */ 13 | public class StringItemPresentationModel implements ItemPresentationModel { 14 | private String value; 15 | 16 | @Override 17 | public void updateData(String bean, ItemContext itemContext) { 18 | Log.d(StringItemPresentationModel.class.getSimpleName(), "in updateData"); 19 | value = bean; 20 | } 21 | 22 | public String getValue() { 23 | Log.d(StringItemPresentationModel.class.getSimpleName(), "in getValue"); 24 | return value; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/ToStringItemPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import org.robobinding.itempresentationmodel.ItemContext; 4 | import org.robobinding.itempresentationmodel.ItemPresentationModel; 5 | 6 | /** 7 | * @author Cheng Wei 8 | * @version $Revision: 1.0 $ 9 | * @since 1.0 10 | */ 11 | public class ToStringItemPresentationModel implements ItemPresentationModel { 12 | private Object item; 13 | 14 | @Override 15 | public void updateData(Object item, ItemContext itemContext) { 16 | this.item = item; 17 | } 18 | 19 | public String getValue() { 20 | return item.toString(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/TypedCursorPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import org.robobinding.annotation.ItemPresentationModel; 4 | import org.robobinding.annotation.PresentationModel; 5 | import org.robobinding.gallery.model.Product; 6 | import org.robobinding.gallery.model.typedcursor.GetAllQuery; 7 | import org.robobinding.gallery.model.typedcursor.ProductItemPresentationModel; 8 | import org.robobinding.itempresentationmodel.TypedCursor; 9 | 10 | import android.database.sqlite.SQLiteDatabase; 11 | 12 | /** 13 | * @author Cheng Wei 14 | * @version $Revision: 1.0 $ 15 | * @since 1.0 16 | */ 17 | @PresentationModel 18 | public class TypedCursorPresentationModel { 19 | private final SQLiteDatabase db; 20 | private final GetAllQuery allProductsQuery; 21 | private TypedCursor productCursor; 22 | 23 | public TypedCursorPresentationModel(SQLiteDatabase db, GetAllQuery allProductsQuery) { 24 | this.db = db; 25 | this.allProductsQuery = allProductsQuery; 26 | } 27 | 28 | @ItemPresentationModel(value = ProductItemPresentationModel.class) 29 | public TypedCursor getProducts() { 30 | productCursor = allProductsQuery.execute(db); 31 | return productCursor; 32 | } 33 | 34 | public void cleanUp() { 35 | if (productCursor != null) { 36 | productCursor.close(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/presentationmodel/ViewPresentationModel.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.presentationmodel; 2 | 3 | import java.util.Map; 4 | 5 | import org.robobinding.annotation.PresentationModel; 6 | import org.robobinding.gallery.util.CircularIntegers; 7 | import org.robobinding.presentationmodel.HasPresentationModelChangeSupport; 8 | import org.robobinding.presentationmodel.PresentationModelChangeSupport; 9 | 10 | import android.app.Presentation; 11 | import android.view.View; 12 | 13 | import com.google.common.collect.Maps; 14 | 15 | /** 16 | * @author Cheng Wei 17 | * @version $Revision: 1.0 $ 18 | * @since 1.0 19 | */ 20 | @PresentationModel 21 | public class ViewPresentationModel implements HasPresentationModelChangeSupport { 22 | private PresentationModelChangeSupport changeSupport; 23 | private CircularIntegers integerVisibilityRotation; 24 | private Map integerVisibilityDescriptions; 25 | private boolean checked; 26 | private int numCheckedChanges; 27 | 28 | public ViewPresentationModel() { 29 | changeSupport = new PresentationModelChangeSupport(this); 30 | integerVisibilityRotation = new CircularIntegers(View.VISIBLE, View.INVISIBLE, View.GONE); 31 | 32 | integerVisibilityDescriptions = Maps.newHashMap(); 33 | integerVisibilityDescriptions.put(View.VISIBLE, "Visible"); 34 | integerVisibilityDescriptions.put(View.INVISIBLE, "Invisible"); 35 | integerVisibilityDescriptions.put(View.GONE, "Gone"); 36 | 37 | checked = false; 38 | numCheckedChanges = 0; 39 | } 40 | 41 | public int getIntegerVisibility() { 42 | return integerVisibilityRotation.value(); 43 | } 44 | 45 | public String getIntegerVisibilityState() { 46 | return integerVisibilityDescriptions.get(integerVisibilityRotation.value()); 47 | } 48 | 49 | public void integerVisibilityStateNext() { 50 | integerVisibilityRotation.next(); 51 | changeSupport.firePropertyChange("integerVisibilityState"); 52 | changeSupport.firePropertyChange("integerVisibility"); 53 | } 54 | 55 | public boolean isChecked() { 56 | return checked; 57 | } 58 | 59 | public void setChecked(boolean checked) { 60 | this.checked = checked; 61 | } 62 | 63 | public void onCheckedChange() { 64 | numCheckedChanges++; 65 | changeSupport.firePropertyChange("checkedChangeDisplay"); 66 | } 67 | 68 | public void changeChecked() { 69 | setChecked(!checked); 70 | } 71 | 72 | public String getCheckedChangeDisplay() { 73 | return "Change Checked: "+ numCheckedChanges; 74 | } 75 | 76 | @Override 77 | public PresentationModelChangeSupport getPresentationModelChangeSupport() { 78 | return changeSupport; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/org/robobinding/gallery/util/CircularIntegers.java: -------------------------------------------------------------------------------- 1 | package org.robobinding.gallery.util; 2 | 3 | /** 4 | * 5 | * @since 1.0 6 | * @version $Revision: 1.0 $ 7 | * @author Cheng Wei 8 | */ 9 | public class CircularIntegers { 10 | private int[] values; 11 | private int currentIndex; 12 | 13 | public CircularIntegers(int... values) { 14 | this.values = values; 15 | } 16 | 17 | public int start() { 18 | currentIndex = 0; 19 | return next(); 20 | } 21 | 22 | public int next() { 23 | int current = value(); 24 | 25 | currentIndex++; 26 | if(currentIndex >= values.length) { 27 | currentIndex = 0; 28 | } 29 | 30 | return current; 31 | } 32 | 33 | public int value() { 34 | return values[currentIndex]; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RoboBinding/RoboBinding-gallery/f95145662b3e7090da6a13dc5f107d8ded0cb869/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RoboBinding/RoboBinding-gallery/f95145662b3e7090da6a13dc5f107d8ded0cb869/app/src/main/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RoboBinding/RoboBinding-gallery/f95145662b3e7090da6a13dc5f107d8ded0cb869/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/background_activated.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/my_custom_border.xml: -------------------------------------------------------------------------------- 1 | 3 | 8 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/my_list_selector_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_adapter_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 18 | 19 | 25 | 26 | 36 | 37 | 38 | 39 | 40 | 41 | 46 | 47 | 51 | 52 | 57 | 58 | 68 | 69 | 70 | 71 | 72 | 73 | 78 | 79 | 83 | 84 | 89 | 90 | 91 | 92 | 93 | 98 | 99 | 103 | 104 | 110 | 111 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_byinterface_noaspectj.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_bysubclass_noaspectj.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_context_menu_demo.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_contextual_action_mode.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_custom_component.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 13 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |