CoffeeScene


Source link: https://github.com/geronimoagency/CoffeeScene-Android

CoffeeScene-Android

A simple scene manager for Android.
CoffeeScene allows to switch the current scene of an Activity, ViewGroup and Fragment (v4 supported).
This library can be usefull if you want to switch from a spinner loader to your main content or a placeholder for example.

Sample app

The sample app is available in this repository under sample/.
You can also try it on Google Play : https://play.google.com/store/apps/details?id=com.geronimostudios.sample.coffeescene

Gradle

Include the dependency Download (.aar) :

dependencies {

  compile 'com.geronimostudios.coffeescene:coffeescene:0.0.7' 
}

Example

How to use with a SceneCreator

You can use the SceneCreator with an activity, viewgroup or fragment.
You have to inflate your viewgroup, fragment or call setContentView(...) in your activity before using the SceneCreator.
The SceneCreator is useful if the anchors of your scenes aren't at the root of your layout.

public class SampleNoAnnotationsActivity extends AppCompatActivity implements View.OnClickListener {

@Override
  protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_no_annotations_sample);

SceneManager.create(

  SceneCreator.with(this)

 .add(Scene.MAIN_CONTENT, R.id.activity_no_annotations_sample_main_content)

 .add(Scene.MAIN_CONTENT, R.id.activity_no_annotations_sample_main_content_another_view) // you can add many layouts to the same scene id.

 .add(Scene.LOADER, R.id.activity_no_annotations_sample_loader)

 .add(Scene.PLACEHOLDER, R.id.activity_no_annotations_sample_placeholder)

 .add(EMPTY_RECYCLER_PLACEHOLDER, R.id.activity_no_annotations_sample_empty_placeholder)

 .listener(this)

 .animation(this)

 .main(Scene.LOADER)

);

  
}
 ... 
}

With a SceneCreator the scenes are registered by calling .add with an unique identifier and the id of the viewgroup that holds the scene.

How to use with annotations only

You have to declare your scenes in your activity, viewgroup or fragment. Each scene requires an unique identifier (sceneId) and a valid layout resource.

@CoffeeScene({

@Scene(scene = Scene.MAIN_CONTENT, layout = R.layout.sample_activity_main),

@Scene(scene = Scene.MAIN_CONTENT, layout = R.layout.sample_activity_main_second_anchor), // you can add many layouts to the same scene id.

@Scene(scene = Scene.LOADER, layout = R.layout.loader),

@Scene(scene = Scene.PLACEHOLDER, layout = R.layout.placeholder) 
}
) public class MainActivity extends Activity {

@Override
  protected void onCreate(Bundle savedInstanceState) {

 super.onCreate(savedInstanceState);

SceneManager.create(this);

...
  
}

  ... 
}

The class Scene provides a few scene's identifiers : Scene.MAIN_CONTENT, Scene.LOADER and Scene.PLACEHOLDER.
You are free to use it or not, but be sure that each identifier is unique.

Activities: Just call SceneManager.create(this); . You don't need to call setContentView();
ViewGroup: Just call SceneManager.create(this); . All scenes will be automatically created and added to your viewgroup.
Fragments: With fragments SceneManager.create(this) will returns the view that must be returned by onCreateView

Change the current scene

You can easily change the current scene with SceneManager.scene(this, int sceneId); .
-The first parameter must be the same object that was passed to SceneManager.create(this); .
-The second parameter is the unique identifier of the scene.

... public class SampleActivity extends AppCompatActivity implements View.OnClickListener {

  ...

 @Override
  public void onClick(View v) {

switch (v.getId()) {

 case R.id.sample_switch_to_progress:

  SceneManager.scene(this, Scene.LOADER);
 // Change the current scene

  break;

 case R.id.sample_switch_to_placeholder:

  SceneManager.scene(this, Scene.PLACEHOLDER);
 // Change the current scene

  break;

  ...

}

  
}
 
}

Release your scenes

Don't forget to release your scenes.

... public class SampleActivity extends AppCompatActivity implements View.OnClickListener {

  ...

 @Override
  protected void onDestroy() {

super.onDestroy();

SceneManager.release(this);

  
}

  ... 
}

Full example

@CoffeeScene(

value = {

  @Scene(scene = Scene.MAIN_CONTENT, layout = R.layout.sample_activity_main),

  @Scene(scene = Scene.LOADER, layout = R.layout.loader),

  @Scene(scene = Scene.PLACEHOLDER, layout = R.layout.placeholder)

}
,

defaultScene = Scene.MAIN_CONTENT ) public class SampleActivity extends AppCompatActivity implements View.OnClickListener {

@Override
  protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

SceneManager.create(this);
 // Setup scenes

 findViewById(R.id.sample_switch_to_main).setOnClickListener(this);

findViewById(R.id.sample_switch_to_progress).setOnClickListener(this);

findViewById(R.id.sample_switch_to_placeholder).setOnClickListener(this);

  
}

@Override
  public void onClick(View v) {

switch (v.getId()) {

 case R.id.sample_switch_to_main:

  SceneManager.scene(this, Scene.MAIN_CONTENT);
 // Change the current scene

  break;

 case R.id.sample_switch_to_progress:

  SceneManager.scene(this, Scene.LOADER);
 // Change the current scene

  break;

 case R.id.sample_switch_to_placeholder:

  SceneManager.scene(this, Scene.PLACEHOLDER);
 // Change the current scene

  break;

 ...

}

  
}

 @Override
  protected void onDestroy() {

super.onDestroy();

SceneManager.release(this);

  
}
 
}

License

Copyright (C) 2017 Geronimo  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

An Android image transformation library providing cropping above Face Detection (Face Centering) for Picasso.

This is a funny switch for Android.

A "quick jump" sidebar control for RecyclerView.

An Android image transformation library providing cropping above Face Detection for Glide.

Library what helps getting photo or video from device gallery, from a cloud or from a camera.

This plugin configures JavaCompile tasks to use the error-prone compiler.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes