Categories
discuss

Android OpenGL texture from non-local source using Rajawali3D?

I am using the OpenGL library Rajawali3D to display my models. What I would like to know is how can I load a texture from my server based on the logged in user? I’ve searched all over the internet trying to figure this out for months with no success. I found this website that explains how to load a texture from a non-local source but when I tried it, it didn’t work with Rajawali. Any suggestions or examples would be much appreciated.

Here’s the website I attempted to use: texture from web

Answer

I’m not familiar with Rajawali, however as I just checked it out, it seems fairly easy to load a remote texture and apply it to a model.

I presume that you’ve loaded your 3D model and can show it fine. If so, you should take the following basic steps (which apply generally to all 3D modeling apps):

  1. Prepare texture
  2. Prepare material
  3. Apply material to a model

There’s a class called Texture in Rajawali, which creates a texture object from a bitmap image. So, you should first download that image from your server. Downloading process is apart from Rajawali concepts, so you can get it done via many existing libraries.

Once you’re finished downloading the image, you can feed it to the Texture class.

Texture mytexture = new Texture("texture", /*address to the downloaded image*/);

Then, you should add it to a material

try {
    material.addTexture(mytexture);

} catch (ATexture.TextureException error){
    Log.d(TAG, "Error Occurred");
}

Now, you can apply this material to a model

model.setMaterial(material);
Categories
discuss

Fragment from View Pager hiding behind Tab Bar

I am having an issue with a Tab bar and ViewPager in my android project. What the app does it has an activity which hosts a tab layout and then has 2 fragment which represents each of the tabs.

When the activity is opened it posts to an API to get some data and puts the data into a data adapter for a Recycler View and Card layout in each of the fragments.

The recycler view will contain 3 items but only 2 are being shown as the first is being hidden under the toolbar and/or the tab bar as shown in the screenshot below.

Below is the layout file of my activity

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.BoardiesITSolution.CritiMonApp.AppsActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <include layout="@layout/toolbar" />
        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed"
            app:tabGravity="fill" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
        <!--app:layout_behaviour="@string/appbar_scrolling_view_behaviour" />-->
</android.support.design.widget.CoordinatorLayout>

Below is the layout of the fragment

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <view
        android:id="@+id/recycler_view"
        class="android.support.v7.widget.RecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true" />
</LinearLayout>

Below is the layout for card layout

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:cardview="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:layout_margin="8dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:elevation="5dp">
        <TextView
            android:id="@+id/txtApplicationName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:maxLines="3"
            android:padding="8dp"
            android:textColor="#222"
            android:textSize="15dp"
            android:layout_centerInParent="true"/>

    </RelativeLayout>
</android.support.v7.widget.CardView>

Below is the screenshot as mentioned above which shows the problem. I’ve pixelated some of the text but it should you what I mean, there should be 3 items but the first item is hiding underneath the tab bar.

Screenshot showing the issue

Answer

Edit: As suggested below by @smeet and @hardik, adding the scroll behavior app:layout_behavior="@string/appbar_scrolling_view_behavior" should fix the problem while preserving the scroll behavior. Scroll behaviors only work if the view is a direct child of the coordinator layout.


Old Answer

Just Wrap your appbar layout and viewpager in a vertical LinearLayout

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.BoardiesITSolution.CritiMonApp.AppsActivity">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        //appbar layout

        //viewpager    


    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>

From the docs, CoordinatorLayout is a super-powered FrameLayout. So you can expect the typical “lay views on top of other views” FrameLayout behavior.

Categories
discuss

Android Studio – change default code style

I’m used to write code in a such way:

private String blabla()
{
    return "bla";
}

But Android Studio is adjusted for this code:

private String blabla() {
    return "bla";
    }

Question: how can I change this option for me?

Answer

Go to File -> Settings.

Then in dialog, Editor -> Code Style -> Java -> Wrapping and Braces tab, then you can adjust braces placement

Remember to “Apply” your changes.

Categories
discuss

How do I prevent Android Studio from automatically collapsing my packages in project navigation?

I have run into this annoyance over and over again and have been unable to find a solution or an answer here for it:

When I create a package in my application and then add a package within it, if I do not have a file in the directory already it will auto collapse my package in the left-side navigation of Android Studio. This prevents me from adding other sub-packages to the parent package, without manually resolving the issue within the file system.

For Example:

example of collapsed navigation

What I want is:

-presentation   
  -screens
     -devicescreen
         -adapters
         -presenters
         -views

Answer

In the 1:Project view, you have Hide Empty Middle Packages turned ON. You need to turn it off. Once turned off it will be shown as Compact Empty Middle Package. Please look at the screenshot attached.

enter image description here

Categories
discuss

Gmail login fail using Selenium webdriver. Showing element not found for password

public static void main(String[] args){
    System.setProperty("webdriver.chrome.driver","E:/softwares/chromedriver_win32/chromedriver.exe");
    WebDriver gmail= new ChromeDriver();

    gmail.get("https://www.gmail.co.in"); 
    gmail.findElement(By.id("Email")).sendKeys("abcd");
    gmail.findElement(By.id("next")).click();
    gmail.findElement(By.id("Passwd")).sendKeys("xyz");

Answer

Try setting an implicit wait of maybe 10 seconds.

gmail.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Or set an explicit wait. An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code. In your case, it is the visibility of the password input field. (Thanks to ainlolcat‘s comment)

WebDriverWait wait = new WebDriverWait(gmail, 10);
WebElement element = wait.until(
    ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));
gmail.findElement(By.id("Passwd")).sendKeys("xyz");

Explanation: The reason selenium can’t find the element is because the id of the password input field is initially Passwd-hidden. After you click on the “Next” button, Google first verifies the email address entered and then shows the password input field (by changing the id from Passwd-hidden to Passwd). So, when the password field is still hidden (i.e. Google is still verifying the email id), your webdriver starts searching for the password input field with id Passwd which is still hidden. And hence, an exception is thrown.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..