My ViewLabel under Nutiteq doesn't work fine - android-linearlayout

I can populate the view for my ViewLabel in Nutiteq but I can't set right text in the text views of this Layout .
My code is following
//Setting Popup Label if we click the area
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View labelView = inflater.inflate(R.layout.popup_field, null);
//In order to get a dynamic "redimensionable" Ballon aka ViewLabel
labelView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
labelView.layout(0, 0, labelView.getMeasuredWidth(), labelView.getMeasuredHeight());
//labelView.measure(400, 400);
//labelView.layout(100, 100, 400, 400);
Log.info("drawField:: Nach Label fieldLabel = new ViewLabel... ");
LinearLayout lLayout = (LinearLayout)labelView.findViewById(R.id.layout1);
lLayout.setBackgroundColor(Color.RED);
TextView farmNameTV = (TextView)labelView.findViewById(R.id.farmName);
TextView areaTV = (TextView)labelView.findViewById(R.id.area);
TextView statusTV = (TextView)labelView.findViewById(R.id.status);
farmNameTV.setTextColor(Color.BLACK);
farmNameTV.setText("Farm CacoCaCoca");
areaTV.setTextColor(Color.BLACK);
String areaString = "12.34"
areaTV.setText("Area "+areaString);
statusTV.setTextColor(Color.BLACK);
String statusString = "Status:::qwertzuiopasdfghjklyxcvbnm";
statusTV.setText(statusString);
*What you can see red is my inflated View.
R.layout.popup_field looks like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/farmName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/farmName"/>
<TextView
android:id="#+id/area"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/area"/>
<TextView
android:id="#+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/status"/>
where strings are
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Nutiteq3D</string>
<string name="area">Area</string>
<string name="status">Status</string>
<string name="farmName">Farm Name</string>
</resources>
Have anyone done this task already? Can anyone help me to find out my error(s)?
With MapView of google Api is easy but I develop this with Nutiteq and just pure Activities, so, NO fragments and to inflate we typically need a ViewGroup and this ViewGroup under G-Api would be MapView so inherits from ViewGroup but in Nutiteq is not like this, MapView of Nutiteq inherits of android.view and I can't casting, I can just assign as ViewGroup a null in the call of inflateas you can see.
So, people, I'd be very thankful for your help.
Kind Regards

Solved!
It didn't have to do with ViewLabel but the normal Android.View, I wanted to assign Text to TextView's after I declared my resizable View and therefore it didn't work fine.
So the solution is writing all of tv.setText above
labelView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
labelView.layout(0, 0, labelView.getMeasuredWidth(), labelView.getMeasuredHeight());

Related

Navigation component - handle back behaviour with multiple stacks

My main problem is that the back button(device button) is not working properly as findNavController().navigateUp() does.
I have the following structure.
Main nav graph:
Login -> Home, here FlowA and FlowB are loaded in DrawerLayout
HomeFragment code:
class HomeFragment : Fragment() {
private var _binding: FragmentHomeBinding? = null
private val binding get() = _binding!!
private val viewModel: HomeViewModel by activityViewModels()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
_binding = FragmentHomeBinding.inflate(inflater, container, false)
val flow1Nav = NavHostFragment.create(R.navigation.flow_a)
val flow2Nav = NavHostFragment.create(R.navigation.flow_b)
childFragmentManager.beginTransaction()
.add(R.id.flContent, flow1Nav, flow1Nav.javaClass.name)
.add(R.id.flContent, flow2Nav, flow2Nav.javaClass.name)
.show(flow1Nav)
.hide(flow2Nav)
.commitNow()
binding.navView.findViewById<LinearLayout>(R.id.ll_flow1).setOnClickListener {
binding.drawerLayout.closeDrawers()
childFragmentManager.beginTransaction()
.show(flow1Nav)
.hide(flow2Nav)
.commit()
}
binding.navView.findViewById<LinearLayout>(R.id.ll_flow2).setOnClickListener {
binding.drawerLayout.closeDrawers()
childFragmentManager.beginTransaction()
.show(flow2Nav)
.hide(flow1Nav)
.commit()
}
}
}
fragment_home.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="#+id/flContent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- Container for contents of drawer - use NavigationView to make configuration easier -->
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/drawer_header" />
<include layout="#layout/drawer_menu" />
</LinearLayout>
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
Flow A nav graph
Flow B nav graph
Questions
Why findNavController().navigateUp() works as expected and the device back button doesn't?
Multiple stacks (navigations graphs) breaks the navigation system?
All the source code can be found here.
I've found a workarround
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) {
findNavController().navigateUp()
}

Two tabs in TabbedPage are not taking full width instead they are limited to their text width to the left corner of the tab

I have to populate two tabs in TabbedPage in such a way that two tabs should take equal half widths of the tab.
Here is my code in TabbedPage:
protected override void OnAppearing()
{
base.OnAppearing();
EquipmentGeneralInfoTab = new EquipmentGeneralInfoTab() { Title = "General" };
EquipmentMaintenanceTab = new EquipmentMaintenanceTab() { Title = "Maintenance" };
this.Children.Add(EquipmentGeneralInfoTab);
this.Children.Add(EquipmentMaintenanceTab);
}
Xaml code:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TCRMobile.Pages.EquipmentInfoTabbedPage"
Title="Equipment">
Tabbar.xaml:
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/Your.Theme"
app:tabIndicatorColor="#color/tcr_green"
app:tabSelectedTextColor="#color/tcr_green"
app:tabTextColor="#color/black"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabTextAppearance="#style/tab_text"
app:tabMode="scrollable" />
How to accomplish my requirement?
Try to change the following code in Tabbar.xaml
app:tabMode="scrollable"
To
app:tabMode="fixed"

Display image from network in ARCore

I'm attempting to use Glide to fetch an image using HTTP and display it in AR using ARCore Sceneform. The layout file is working because the border described in it is being displayed, but the image itself is not being displayed or even fetched.
Here is my code:
View view = View.inflate(context, R.layout.test_view, null);
if (v == 2) {
//ImageView imageView = (ImageView) renderable.getView();
Glide.with(context)
.asDrawable()
.load("http://i.imgur.com/DvpvklR.png")
//.into(view);
.submit(-1,-1);
rendobject =
ViewRenderable.builder()
.setView(context, view)
.setVerticalAlignment(ViewRenderable.VerticalAlignment.BOTTOM)
//.setSizer(new FixedWidthViewSizer(0.2f))
.setSizer(new FixedHeightViewSizer(0.15f))
.build()
.thenAccept(renderable -> {
testViewRenderable = renderable;
});
Here is the layout file:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/planetInfoCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/rounded_bg"
android:gravity="center"
android:orientation="vertical"
android:padding="4dp"
/>
Here are the network permission declarations in the Manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I don't know what I'm missing/doing incorrectly.
Edit:
Here is something I also tried, but nothing is displayed after successfully scanning the augmented image:
rendobject =
ViewRenderable.builder()
.setView(context, R.layout.test_view)
.setVerticalAlignment(ViewRenderable.VerticalAlignment.BOTTOM)
.setSizer(new FixedHeightViewSizer(0.1f))
.build()
.thenAccept(renderable -> {
testViewRenderable = renderable;
ImageView imageView = (ImageView) renderable.getView();
Picasso.get()
.load("http://i.imgur.com/DvpvklR.png")
.fit()
.centerInside()
.into(imageView);
I don't see that the Glide call and the view are connected in any way. You have to load the image into the ImageView.

How replace a navigation icon with a navigation title in xamarin forms

I trying to add a navigation title icon to my app in one of the page and the code that i have used is:
For iOS:
NavigationPage.SetTitleIcon(this, "icon.png");
For Android in the ToolBar.axml I have added a ImageView as shown below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<ImageView
android:id="#+id/titleicon"
android:src="#drawable/UstNameIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
The issue is that, I want my Navigtion icon to get disabled in my next Page and put a title instead of icon.
For that, I tried
For iOS:
NavigationPage.SetTitleIcon(this, null);
NavigationPage.Title="Title";
For Android, How can i achieve the change of Navigation title?
In MainActivity.cs
[Activity (Label = "Todo.Android.Android", MainLauncher = true, Icon="#android:color/transparent")]
For Title, you can set Title property in xaml or c#
To change text you just simple need to find that element by id, and set up a title:
var toolbar =
FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); // it may be simplifed
SetSupportActionBar(toolbar);
toolbar.Title = "title";
And image is under toolbar.Logo, so you can just try:
toolbar.Logo = null;
If you have some data in resources which you want to put in, you can use also:
toolbar.SetTitle();
toolbar.SetLogo();

Error inflating imageview in scrollview android

I tried to have a scrolling image in my android app but have this error in my debugger:
Binary xml error in line 10 :inflating android widget imageview
This the xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bgabout">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/aboutscroll" />
</ScrollView>
</LinearLayout>
And this is the stack trace:
08-26 11:43:58.102: E/AndroidRuntime(24553): FATAL EXCEPTION: main 08-26 11:43:58.102:
E/AndroidRuntime(24553): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.albir/com.example.albir.About}: android.view.InflateException: Binary XML file line #10: Error inflating class android.widget.ImageView
i used the guidelines and i maked same changes so now i can scroll only image that had 700*1900 px rather than this large the debuguer show this trace :exception out of memory this the code :
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
</HorizontalScroll>
the java class
public class About extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
ImageView iv = (ImageView) findViewById(R.id.imageView1);
Resources res = getResources();
BitmapDrawable bitmap = (BitmapDrawable) res.
getDrawable(R.drawable.aboutscroll);
int imgW = bitmap.getIntrinsicWidth();
int imgH = bitmap.getIntrinsicHeight();
iv.setImageDrawable(bitmap);
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) iv.getLayoutParams();
params.width = imgW;
params.height = imgH;
}
}
i want to know if i can modify this code to show more large image
It seems as though the image you're loading is too large and is causing some sort of out of memory exception. You could try to use smaller images and put them into the appropriate folders (drawable-hdpi, drawable-mdpi etc).
If this isn't suitable for you, please read through the following guides to best understand how you should be handling large bitmaps in Android:
http://developer.android.com/training/displaying-bitmaps/index.html
Finally, you could try to find a library (like Picasso) that handles image relates things in your app..
I had this issue and spent some time pulling my hair out.
It ended up being due to the image I was trying to load was accidentally copied into the drawable-en-rIE (a locale-specific) folder instead of the top-level drawable folder.
Simply moving the source image into the drawable folder solved the issue for me.

Resources