how could i change brightness 1. click 50% second click 100% 3. click 0% via widget button? i am actuali stack on premission becouse it telling me This Premission is only gatanted to system apps, so is it possible to even do that ?
my target is to add all this to my widget -
<LinearLayout
android:id="#+id/widget_button_layout"
android:layout_width="match_parent"
android:layout_height="53dp"
android:layout_alignParentBottom="true"
android:background="#drawable/widget_buttons_background"
android:orientation="horizontal"
android:weightSum="1">
<ImageButton
android:id="#+id/widget_bluethooth"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:layout_marginEnd="1dp"
android:scaleType="fitXY"
android:background="#drawable/widget_bluethooth_btn" />
<ImageButton
android:id="#+id/widget_settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:scaleType="fitXY"
android:background="#drawable/widget_settings_btn" />
<ImageButton
android:id="#+id/widget_wifi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:scaleType="fitXY"
android:background="#drawable/widget_wifi_btn" />
<ImageButton
android:id="#+id/widget_brightnes"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:layout_marginStart="1dp"
android:scaleType="fitXY"
android:background="#drawable/widget_brightnes1_btn" />
i would need to read brightness too, becouse it is wierd if that button will have drawable of 100% but someone will decrease brightness manualy to 0%...
so can someone help me to get premission for reading and writing to brightness... ?
if you will be way to kind you could help me with others staff
That's not a real error, just an error produced by your IDE. If you want to remove it, you just have to add to your Manifest:
uses-permission android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions"
Related
I am working on new app in which I have to take care of design over mobile devices and tablets.I already read on SO that for this thing I need to create several buckets for sizes to avoid bad look of app on larger or smaller screen at the same time. here is the code I am working on
[![<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_margin="35dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/lblLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoSizeTextType="uniform"
android:gravity="center"
android:padding="15dp"
android:text="My App Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/colorPrimaryDark"
android:textSize="32sp" />
<!-- Email Label -->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilLoginEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etLoginEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>
<!-- Password Label -->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilLoginPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etLoginPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="#+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:padding="12dp"
android:text="#string/btnLogin" />
</LinearLayout>
]
This is how the above code looks like on mobile phone (i.e Nexus 6)
**This is how the above code looks like on tablet (i.e Nexus 10)
Notice that on tablet is looking so bad. I know how to handle design in different design buckets. but I want to check if there is any
other solution without replicating the same design file in different
screen sizes buckets
Thanks in advance......
Instead of duplicate the layout try to:
avoid to hardcode the dimension in the layout.
use a ConstraintLayout
use the different qualifiers
For example the margin in your root view:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/login_layout_margin"
android:layout_marginEnd="#dimen/login_layout_margin"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/lblLogo"
..>
</LinearLayout>
Then create different dimension in different folder:
res/values/dimens.xml:
<dimen name="login_layout_margin">35dp</dimen>
res/values-sw600dp/dimens.xml:
<dimen name="login_layout_margin">350dp</dimen>
More details here.
So I'm a beginner to coding android and normally I'm able to find my solutions on google but I've had no luck this time. I've made an app with two activities (a login screen that also has a register button that leads to a register screen) and on the initial log in screen, clicking one of the text inputs squashes the background image, to essentially fit it into the smaller space created when the keyboard takes up some of the screen. It's pretty annoying.
Sorry for pasting such a huge block of code but as a beginner, I'm not really sure which part of this code is relevant so I've included the whole xml. Thanks!
Oh, and again - I can't stress enough that I'm a total noob - so could any answers please state crystal clear exactly what code I should be changing/including and in what file, and where abouts in that file?
<?xml version="1.0" encoding="utf-8"?>
<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:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:background="#drawable/qlogoonwallpaper"
tools:context=".MainActivity">
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:layout_marginBottom="48dp">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dropDownWidth="match_parent"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="6"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:background="#color/colorPrimaryDark"
android:text="#string/action_sign_in"
android:textAllCaps="false"
android:textColor="#android:color/background_light"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText"
android:layout_centerHorizontal="true"
android:layout_marginTop="-208dp"
android:ems="10"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="225dp"
android:background="#android:color/transparent"
android:text="#string/register_intro"
android:textAllCaps="false"
android:textColor="#android:color/background_light"
android:textSize="18sp"
android:textStyle="bold|italic" />
</RelativeLayout>
Inside the Android Manifest file, try adding the following attribute for your MainActivity :
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustPan">
...
</activity>
that makes the views pan when the soft keyboard appears but the activity's window is not resized. See if that makes any difference. If resizing would work better, instead of the "adjustPan" attribute, you can add "adjustResize". Hopefully one of the two will do the trick for you.
I have to reproduce the following circular effect on the exoplayer.
I added two views, exo_rew and exo_ffwd.
Which automatically do go back or forward by standard setting.
This is the code I've written so far:
<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="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="#+id/exo_rew"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:gravity="center"
android:clickable="true"
android:focusable="true"
android:background="#00000000"
android:foreground="?attr/selectableItemBackground"
tools:ignore="Orientation" />
<LinearLayout
android:id="#+id/exo_ffwd"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:layout_alignParentLeft="false"
android:layout_alignParentRight="true"
android:gravity="center"
android:clickable="true"
android:focusable="true"
android:background="#00000000"
android:foreground="?attr/selectableItemBackground"
tools:ignore="Orientation" />
<LinearLayout
android:id="#+id/play_pause_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#15ffffff"
android:gravity="center"
>
<ImageButton
android:id="#id/exo_play"
style="#style/ExoMediaButton.Play"
/>
<ImageButton
android:id="#id/exo_pause"
style="#style/ExoMediaButton.Pause"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignWithParentIfMissing="false"
android:layout_centerHorizontal="false"
android:layout_centerVertical="false"
android:gravity="center_vertical"
>
<TextView
android:id="#id/exo_position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="00:00"
android:textColor="#FFBEBEBE"
android:textSize="14sp"
android:textStyle="bold"
/>
<com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="#id/exo_progress"
android:layout_width="0dp"
android:layout_height="26dp"
android:layout_weight="1"
app:played_color="#4589f2"
/>
<TextView
android:id="#id/exo_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="2:00:00"
android:textColor="#FFBEBEBE"
android:textSize="14sp"
android:textStyle="bold"
/>
</LinearLayout>
</RelativeLayout>
There are two problems that I could not solve:
1) That each view takes half of the screen, exo_rew on the left and exo_ffwd on the right.
I could not find a way to specify in xml a layout_width equal to match_parent/2.
Is there a way?
I tried with weightSum at 1, but it does not seem to work.
2) Create the circular effect as in the image.
the doubts are better to use a canvas creating a circle or a "circle reveal" effect.
Can someone give me a hand?
Best way would be to use ConstraintLayout and add these images with constraint start, end, bottom and top and give them width of 0dp, in this way they'll just occupy the width according to their constraint.
ConstraintLayout is very powerful it will also reduce your view hierarchy. And it would help your purpose.
If you want to add the same double tap behavior like YouTube, you can use my library to achieve it. My basic approach is to override the onTouchEvent of the PlayerView to detect DoubleTapGesture (SimpleGestureDetector) and creating an overlay on top of it.
I've written an answer here already. Use the following to implement it:
0) Requirements:
Minimum SDK: 21 (could be lower, but I've not tested older versions yet)
ExoPlayer2 library (at least 2.10.4) since the replaced view is written above ExoPlayer's PlayerView
1) Include it to your gradle (it's hosted on jitpack.io so you've got to add it to your respositories):
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.vkay94:DoubleTapPlayerView:0.7.1'
}
2) Add the views inside your XML:
<FrameLayout
... >
<!-- Replace ExoPlayer's PlayerView -->
<com.github.vkay94.dtpv.DoubleTapPlayerView
android:id="#+id/doubletapplayerview"
app:player_layout_id="#layout/exo_simple_player_view"
app:use_controller="true"
...
/>
<!-- Other views e.g. ProgressBar etc -->
<!-- Add the overlay on top of PlayerView -->
<com.github.vkay94.dtpv.YouTubeDoubleTap
android:background="#color/dtp_overlay_dim"
android:id="#+id/youTubeDoubleTap"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
3) Set it up inside your activity:
// Link the PlayerView to the overlay to pass increment to the Player (seekTo)
// Important: set the (Simple)ExoPlayer to the PlayerView before this call
youTubeDoubleTap
.setPlayer(doubletapplayerview)
.setForwardRewindIncrementMs(5000)
// Set YouTube overlay to the PlayerView and double tapping enabled (false by default)
doubletapplayerview
.activateDoubleTap(true)
.setDoubleTapDelay(500)
.setDoubleTapListener(youTubeDoubleTap)
//.setDoubleTapListener(this) => handle event directly within´the activity
Link to the library on Github
Use FrameLayout instead of LinearLayout Like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<FrameLayout
android:id="#+id/exo_rew"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#00000000"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground" />
<FrameLayout
android:id="#+id/exo_ffwd"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#00000000"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground" />
</LinearLayout>
Edit: Thanks to everybody that helped. I found a text size library that fixes this problem.
Since I upgraded to Android Studio 3.0.1,
the text size in my app is on some devices way too small.
What can I do about that?
I put my layout file below
Thanks
And here is my layout:
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/listlayout2"
android:weightSum="1"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:id="#+id/headerImageView"
android:layout_width="match_parent"
android:layout_height="140dp"
android:scaleType="centerCrop"
android:visibility="gone"
app:srcCompat="#drawable/example" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/listlayout"
android:padding="16sp"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:gravity="center_vertical"
android:layout_width="20sp"
android:layout_height="20sp"
android:id="#+id/itemicon"
android:contentDescription="icon"
android:src="#drawable/settings"
android:layout_marginLeft="30dp"
android:layout_marginStart="0dp" />
<TextView
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="32dp"
android:textSize="16sp"
android:text="Testtext"
android:gravity="center_vertical"
android:layout_marginStart="14sp"
android:layout_marginLeft="14sp" />
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="1.2dp"
app:srcCompat="#color/example"
android:id="#+id/divider"
android:layout_weight="0.03"
android:visibility="gone"/>
</LinearLayout>
It is used in a custom navigation drawer item.
You need to enter code here to set text appearance it displays as per system need
android:textAppearance="?android:attr/textAppearanceMedium
android:textAppearance="?android:attr/textAppearanceSmall
android:textAppearance="?android:attr/textAppearanceLarge
Just use:
android:textSize="30sp"
to change the text size and adapt it to your wanted size.
You can also go for dp instead of sp
If you define your textSize in dp that won't change your text size throughout the application.
Edit: change sp to dp
I have a problem here , i just getting starter with android Development , i was just in Windows Phone , and when i put in WP some TextView in my screen , he will be the same way in other screens , but in android is not .I want to know if have some code in XML who i can define the position and not change!
Here is my XML
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".Home"
android:background="#drawable/background">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recife +"
android:textSize="40dp"
android:textColor="#android:color/white"
android:layout_marginTop="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:fontFamily=""
android:id="#+id/textView" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Horários, Rotas e Informações"
android:textSize="25dp"
android:textColor="#android:color/white"
android:layout_marginTop="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:autoText="false" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="250dp"
android:background="#drawable/trem"
android:id="#+id/butaoMetro"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"
android:layout_below="#+id/butaoMetro"
android:layout_alignEnd="#+id/textView" />
How can i fix this?thanks!
I think this library autofit-textview can help you.
But you will need to wrap it into a custom FrameLayout nammed AutiFitLayout. Take a look at the example.
The problem here is
android:textSize="25dp"
set fixed for any resolution devices. For proper display you need to create layout for various resolution devices. For this you need to create different layout folder for different resolution devices and match according to it. Hope this helps