Android wear 5.0.1 activity fullscreen - android-activity

I have a problem since 5.0.1 update. My activity on moto 360 not taking full screen (light sensor is not part of the activity) anymore and I have now this screen :
I try to add some flags :
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
Or
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN);
or
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMIT);
On my manifest :
<activity
android:theme="#android:style/Theme.DeviceDefault.NoActionBar"
android:name=".activity.DreamActivity"
android:excludeFromRecents="true"
android:noHistory="true"
android:label="${watchfaceName}"
android:screenOrientation="reversePortrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
But no luck :( anyone have this problem ? Or even better a solution ? :)
Of course my activity layout is set to match_parent

Here is my working solution, maybe there is a better way (maybe an android wear bug ?)...
I have my basic layout and add a rotation = 90
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:background="#color/black"
android:id="#+id/main"
android:rotation="90"
android:padding="5dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.jaumard.commonlibrary.views.DigitalClock
android:id="#+id/watchface"
custom:onWatch="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.jaumard.commonlibrary.views.DigitalClock>
<View
android:id="#+id/dim"
android:background="#AA000000"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
And on my Manifest I remove the previous android:screenOrientation="reversePortrait"

Related

How to Disable Swipe Refresh when Bootstrap Modal Appears in Android WebView?

I am building an Android WebView app and website which I load in WebView contain Bootstrap Modal ,it appears as Login/SignUp popup or Choose Image popup.
But problem is that when Modal appears Swipe refresh is working and i am not able to scroll up as swipe refresh automatically refresh the page, So i want to disable swipe refresh only when modal opens.
In Chrome App ,swipe refresh automatically disables when Modal opens or appears so i want setting just as chrome android app.
Thanks in Advance
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
android:id="#+id/relative"
tools:context=".MainActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/swipeRefreshLayout"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="WebViewLayout">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="8dp"
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_marginTop="-2dp"
android:progress="20"
android:visibility="gone"
android:indeterminate="true"
android:indeterminateTintMode="src_atop"
android:indeterminateTint="#color/white" />
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/myWebView"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:nestedScrollingEnabled="true"
android:isScrollContainer="true"
tools:ignore="ObsoleteLayoutParam,RtlHardcoded" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
android:id="#+id/relativeLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Internet Connetion, Please Connect To Internet And Try Again. "
android:textSize="30dp"
android:textColor="#color/white"
android:layout_centerHorizontal="true"
android:textAlignment="center"
android:layout_marginTop="40dp"
android:id="#+id/txtNoConeection"
android:layout_marginRight="23dp"
android:layout_marginLeft="25dp"
android:gravity="center_horizontal" />
<Button
android:layout_width="140dp"
android:layout_height="65dp"
android:text="Retry"
android:backgroundTint="#color/white"
android:textColor="#620839"
android:layout_below="#+id/txtNoConeection"
android:layout_centerHorizontal="true"
android:layout_marginTop="400dp"
android:textSize="20dp"
android:id="#+id/btnNoConnection"/>
</RelativeLayout>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>
In onCreate
swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setColorSchemeColors(Color.rgb(0,72,85), Color.rgb(255,216,96) , Color.rgb(93,7,53) );
swipeRefreshLayout.setOnRefreshListener(() -> {
webView.reload();
if (null != swipeRefreshLayout){
swipeRefreshLayout.setRefreshing(false);
}
});
//Solved WebView SwipeUp Problem
swipeRefreshLayout.getViewTreeObserver().addOnScrollChangedListener(() -> swipeRefreshLayout.setEnabled(webView.getScrollY() == 0));
It's pretty old but since it shows up on google searches, might help some people...
I solved it with a weird method. Just added some js to my website. not using bootstrap but is there any reason it wouldn't work?
when I'm opening the div:
document.body.style.overflowY = "hidden";
document.body.style.minHeight = "calc(100vh + 1px)";
window.scrollBy(0, 1);
and when I'm closing it:
document.body.style.overflowY = "scroll";
document.body.style.minHeight = "0px";
window.scrollBy(0, -1);
if you have found a better solution i would like to hear about it as well...
i really don't understand why it's not fixed yet. chrome handles it perfectly but webview is still like this...
first i tried using
document.body.style.overscrollBehavior = "none";
but it has no effect in webview...

Activity.setProgress(int progress) is deprecated

I would like to show progress bar when android webview is loading and I used Activity.setProgess(int).
Android documentation says setProgress(int progress) was deprecated in API level 24. No longer supported starting in API 21.
So, what should I use instead to show progress when webview is loading?
Implement toolbar with progress bar or spinner.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_actionbar"
style="#style/HeaderBar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:visibility="visible"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ActionBarPopupThemeOverlay"
app:theme="#style/ActionBarThemeOverlay"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="right"
android:divider="?android:dividerVertical"
android:dividerPadding="8dp"
android:orientation="horizontal"
android:showDividers="beginning|middle">
<ProgressBar
style="#style/Widget.AppCompat.ProgressBar.Horizontal"
android:id="#+id/toolbarProgressBar"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
Then find it in your view and update.
ProgressBar progressBar = (ProgressBar)findViewById(R.id.toolbarProgressBar);
progressBar.setIndeterminate(false);
progressBar.setProgress(x);

Android ImageButton interaction

I wish to create the same activity like in google fit
And I created an activity with android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ddd"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="12dp"
android:background="#null"
android:onClick="onPreferencesClick"
android:src="#drawable/ic_more_vert_grey600_24dp" />
But when I click on three dots button it doesn't have any push effect in ui, but onPreferencesClick works fine.
How to create pushable ImageButton?
The easiest way would be to create a custom selector, for example like this (drawable xml):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#33000000"/>
<item android:drawable="#android:color/transparent"/>
</selector>
and apply it to the background of ImageButton

How to change TabWidget's background color from XML in Android

I have come across this problem. I have a tab widget on top of the view, with four tabs in it. I have been asked to change the background color of the whole tab view area. Not for any tab, but the whole area of that tab view.
I also been asked for not changing any source code for some branding reason. So I could only do it through xml file. I searched around but seems all solution is by using java code. So I wonder if there is a way that I could change the widget background color (just color, not images) by using only resources files?
Here is my layout file for the tab layout:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/tabbackgroundcolor" />
<FrameLayout
android:layout_below="#android:id/tabs"
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
/>
</RelativeLayout>
</TabHost>
You could see that I added "android:background="#color/tabbackgroundcolor"" in the TabWidget part, however it not work..
Thank you!

Aligning fonts in tabwidget

Myself designing an app which uses GPS and Maps. I have created the UI as tabs. But i couldn't able to keep the font below the image.
Code in my Mainactivity
TabSpec gpsspec = tabHost.newTabSpec("GPS");
gpsspec.setIndicator("GPS", getResources().getDrawable(R.drawable.gps));
Intent gpsIntent = new Intent(this, GpsActivity.class);
gpsspec.setContent(gpsIntent);
tabHost.addTab(gpsspec);
XML file in my drawable folder for tabs
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="#drawable/gps_icon"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="#drawable/gps_icon" />
</selector>
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
Kindly help in aligning the font.
You need to provide
Small size of icons for small density devices in drawable-ldpi folder
Medium size of icons for medium density devices in drawable-mdpi folder
Large size icons for large density devices in drawable-hdpi folder
Here is documentation guide for sizes of the drawable and layouts.
if it doesn't solve your problem, you can consider provding your own customized tab indicator, which I've used in my post here.