What makes Android GUI framework - android

Java is used to bring up gui components like View and Widgets. Official site say they dont include AWT/Swing as a part of their java bundle, then what implementation (native-wrapper if any?) they have in place? Also is it possible to create user interface from scratch for android apps without extending any View class?

It's a custom UI toolkit unrelated to AWT or Swing.
You can create custom subclasses of the View class to draw whatever custom components you would like, but most of the time you can set attributes on the existing components to change the way they're drawn (like setting the drawables for a button).

Related

How does jetpack compose work under the hood

The new Jetpack compose component added to Arch component is like Flutter Ui making.
How does it make the Ui though?
Does it use a native code engine like Skia, or it still follows the ViewGroup way like before?
Compose creates one view currently named AndroidComposeView, which inherits ViewGroup, and it draws the widget tree on its canvas. It also processes motion/keyboard events for this view.
There may be more helper views added to this view due to implementation details, but basically for the "widgets" of Compose, you won't see classical Views in view hierarchy. Layout inspector currently doesn't help for Compose - you can try it but you'll won't see your widgets.
Developers are promised to be able to create own customized widgets, which can directly paint on Canvas, set layout for itself or children, or process input events.
However, the Canvas and lots of other classes used here are not standard framework classes. For example, Canvas for Compose is redefined in Kotlin. Similar way there is new Paint, Shape, and other new classes. They internally use framework classes for their work, but that's implementation detail. When drawing, you'd use these new classes.
Since Compose is a library, and not present natively on Android devices, the library is included in each app that uses Compose.
Also there is no native code involved here, all is done in Kotlin and becomes part of your app's dexed code. By using Compose, your app won't contain any additional native library (probably, if creators don't change mind).
No, It doesn't use anything from the old UI Toolkit actually they are building it to overcome old UIToolkit's problems.
Compose is not views, It's a new set of Jetpack UI Widget, Basically, it's a Kotlin compiler plugin which renders the Android Canvas (I suppose there's no documentation for this yet) with full compatibility of existing android's view system, the last Dev summit there was a talk covers how it works internally, I/O had another talk too

How to add functionality to existing classes?

Currently, I am developing an android library. Basically the idea is to add some functionality to any android widget that there is. The library is used to create compound views, and the user should be able to convert every existing android widget/view into a compound view with some additional functionality I want to add dynamically.
Every one of these views should still be useable inside XML files, which means I cannot change the constructor too much.
Another requirement is that I need an option for the user to provide some classes for the views. By that, I mean that the created compound view is going to have a public variable named viewStore. Thy type of viewStore would either be the user's implementation of the ViewStore interface (preferred way but I am pretty sure this would require code generation as discussed later) or would be provided via generics.
In the end, a compound view would have this folder structure like this:
MyView Folder
MyView extends CoolViewWithViewStore extends AndroidWidgetChoosenByUser
MyViewStore implements ViewStore <- used in CoolViewWithViewStore
One option is to extend every single widget. I don't think I need to explain why this is a bad idea. Furthermore the user couldn't provide the additional classes that are needed.
Another one I thought of was Annotation with code generation. The problem I came across here was that the user needs access to variables of CoolViewWithViewStore inside MyView which wouldn't be possible because CoolViewWithViewStore would be generated at compile-time and furthermore the user could accidentally use his class inside XML instead of our generated one.
I would like to hear if anybody has a better idea of how to handle this or if there even is a clean solution to this to achieve this kind of architecture. If anybody has a better idea of how to structure my library I would like to hear this as well.
Using Kotlin extension function you could extend a class with new functionality without having to inherit from the class.

React Native Custom UI Component using Library

I've developed an android library which exposes some activities, include one named AuthenticiateActivity and also included some helper classes.
I have a second android project that pulls in this library. I am trying create a custom React Native UI component to be able to display the AuthenticateActivity using javascript.
I have followed as best I can the documentation on creating native UI components here, however my use case is slightly different. As I understand, I need to create a ViewManager that extends SimpleViewManager, however, the SimpleViewManager takes a custom view class as a generic parameter. In my case I'm simply trying to display the activity defined in the library, I'm not looking to create a fully custom View implementation.
Any ideas how I can achieve this?
For displaying a completely new Activity you should just use a native module.
There's a good example that shows how to wrap a custom Activity.

Android : Difference between Component and Widget?

what is the difference between Component and Widget? in the Android UI Design Level. Difference between Java Class Creative UI and using .xml layout file design?
"widget" for subclasses of View that have a visual representation to the user by default -- things like TextView, Button, ListView, etc.
I tend to use the term "view" for something that could be any subclass of View, including pure containers like LinearLayout.
But, again, there is no particular harm in referring to them by either term.

When you use Android Studio are you working with MVC?

I know in Xcode when you write an app, you have controller, model, views.
android studio doesn't have a Controller specific. Do you think in android studio are working with MVC?
No but you can build it quite easily:
On Android, you always have these XML which represent the views (actually you can do all programatically but a better practice will invite you to use these XML because they're more flexible) and they're in the ressources. The problem comes when you do custom views because you need to put a bit of logic in that and then it is part of your java code.
Then the controller is, basically, the activity but the fragments contain also, theoretically a bit of logic so they're like hybrid between controller and view (I, personally, consider them as controller but my pair developer as a view).
Then the models are very easy to separate... At the end you can get something like this: (but I do not if you would call it MVC)
-java
|_model
|_user.java
|_view
|_customView.java (extends View for example)
|_controller
|_MainActivity.java
|_fragment_contained_in_main_activity_inflating_Custom_View.java
-res
|_layout
|_customView_layout.xml
Android the activity or fragment is the "controller". You write the controlling code in java and the views in XML. You can make model classes as .java files and when populating data from a server wrap those model classes in an Array or List to be used and placed onto your view via the activity code.

Categories

Resources