PhysicsLayout


Source link: https://github.com/Jawnnypoo/PhysicsLayout

PhysicsLayout

Android layout that simulates physics using JBox2D. Simply add views, enable physics, and watch them fall!

The gif is choppy, see it in action with the sample app:

Gradle Dependency

Add this in your root build.gradle file ( not your module build.gradle file):

allprojects {
  repositories {

...
maven {
 url "https://jitpack.io" 
}
  
}
 
}

Then, add the library to your project build.gradle

dependencies {

  compile 'com.github.Jawnnypoo:PhysicsLayout:2.1.0' 
}

Basic Usage

If you want to see what your layout looks like when physics is applied to it, simply change your root layout to a physics layout.

  <com.jawnnypoo.physicslayout.PhysicsLinearLayout
  android:id="@+id/physics_layout"
  android:layout_width="match_parent"
  android:layout_height="200dp">

  <ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/ic_launcher"/>

  <ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/ic_launcher"/>

 <TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hello world, I have physics!"/>

 </com.jawnnypoo.physicslayout.PhysicsLinearLayout>

Custom XML Attributes

You can also further customize the behaviour of your PhysicsLayout

  <com.jawnnypoo.physicslayout.PhysicsLinearLayout
  android:id="@+id/physics_layout"
  android:layout_width="match_parent"
  android:layout_height="200dp"
  app:physics="true"
  app:gravityX="0.0"
  app:gravityY="9.8"
  app:bounds="true"
  app:boundsSize="50dp"/>
  • physics boolean, Determines if physics will be applied to the layout (Default true)
  • gravityX float, Sets the gravity in the X direction (positive is right, negative is left) (Default 0)
  • gravityY float, Sets the gravity in the Y direction (positive is down, negative is up) (Default 9.8)
  • bounds boolean, Determines if the layout should have bounds on the edges of itself (Default true)
  • boundsSize dimenstion, Sets the width/height of the bounds on the edges (Default 20dp)

Custom Physics Configuration

Each view contained within the layout has a physics configuration that it uses to create itself in the Box2D world. This defines its shape, mass, restitutaion, and other physics related variables. A custom configuration can be applied to each view as well:

 <TextView

android:id="@+id/text"

android:layout_width="20dp"

android:layout_height="20dp"

app:layout_shape="circle"

app:layout_circleRadius="20dp"

app:layout_bodyType="kinematic"

app:layout_fixedRotation="true"

app:layout_friction="0.8"

app:layout_restitution="0.3"

app:layout_density="0.5" />

or alternatively, the Physics definition can be made programmatically:

final View circleView = findViewById(R.id.circle);
 PhysicsConfig config = PhysicsConfig.create();

config.shapeType = PhysicsConfig.SHAPE_TYPE_CIRCLE;

config.radius = dpToPx(30);

config.fixtureDef = fixtureDef;

config.bodyDef = bodyDef; Physics.setPhysicsConfig(circleView, config);

This is useful especially if you have view that would be considered circular, as the default for all views is a RETANGLE shape type. Most of the time, if you are just dealing with rectangular views, the defaults will work for you and you will not have to worry about this.

Check out the sample app to see most of these things in action.

Using this library?

I wanna see the cool ideas and stuff you guys have made with this. If you're using this library in one of your projects just send me a tweet and I'll add your project to the list.

Icon Application
[DejaVu]
[Y'U]
[LabCoat]
[DejaVu]: https://play.google.com/store/apps/details?id=vincorp.in.dejavu
[Y'U]: https://play.google.com/store/apps/details?id=com.brounie.yumultimedia
[LabCoat]: https://play.google.com/store/apps/details?id=com.commit451.gitlab

Making a Game?

This library was designed with the intention of allowing for playful animations within normal Android apps. It is not built to be a game engine or meant to compete with the likes. If you are looking to do more intense mobile games, we recommend libraries such as libGDX or Unity

License

Copyright 2016 John Carlson  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

TextInputLayout and TextInputEditText merged into one class. Just for convenience and for removing some boilerplate code.

ChromeLikeTabSwitcher is an Android-library, which provides a tab switcher similar to the one, which is used in the Android version of Google's Chrome browser. It provides layouts optimized for smartphone and tablet devices.

Wrapper of StrictMode API that can be safely called on any version of Android.

Android project to experiment the VIPER approach.

Motivations

  • Tend toward the VIPER approach
  • Make it easier to test the application
  • Simplify the set up of asynchronous job with RxJava

A demo project for showing how to use WebViews in Android.

Things covered in this project

  • Load a local html file into a WebView with the basic WebView settings.
  • Handle Javascript callbacks from the Javascript to the client.
  • Make Javascript callbacks from the client to Javascript.
  • Set WebViewClient to the WebView
  • Debugging of WebView

This is an Android Library for showing Material Dialog with little customization with icons, colors, divider line.

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