How to make Float Action Button infobox - java

I want to add an information box above the floataction button as in the image below. How can I do that? Thank u
Image URL CLICK
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.Fab_Bottom_app_bar"
app:hideOnScroll="true"
android:layout_gravity="bottom"
app:fabCradleMargin="15dp"
app:fabCradleRoundedCornerRadius="60dp"
app:layout_scrollFlags="scroll|enterAlways"
app:fabCradleVerticalOffset="10dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:theme="#style/Theme.Fab_Bottom_app_bar"
android:background="#drawable/dropbutton"
android:layout_height="match_parent"
app:menu="#menu/bottom_nav_menu" />
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
app:backgroundTint="#2770DC"
app:tint="#fff"
android:src="#drawable/icon_add"
app:layout_anchor="#id/bottomAppBar" />

https://developer.android.com/reference/android/widget/PopupWindow
PopupWindow should serve your purpose
"This class represents a popup window that can be used to display an arbitrary view. The popup window is a floating container that appears on top of the current activity."
You can pass whatever "contentView" you want to show into its constructor and call the "showAtLocation" method to determine where to show it.

Related

Place a TextInput above the Android keyboard without it drawing a black rectangle?

In my Android app I have an Activity where a user can add some text to an image. When the button to initiate this is pressed a TextInput appears at the bottom of the screen with the "Save" button overlayed.
The relevant config looks like this:
<activity
android:name=".ImageEditorActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/title_activity_image_editor"
android:parentActivityName=".MainActivity"
android:windowSoftInputMode="adjustResize|stateHidden"
android:theme="#style/FullscreenTheme">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="myApp.MainActivity" />
</activity>
The activity xml looks like this - I have trimmed out a couple of extra buttons that don't related to this feature:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context=".ImageEditorActivity"
android:id="#+id/fullscreen_content">
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginTop="50dp"
android:isScrollContainer="true" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/edit_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"></ImageView>
<EditText
android:id="#+id/image_comment"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:paddingLeft="8dp"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="2"
android:hint="notes"
android:text=""
android:textColor="#android:color/black"
android:background="#android:color/white"
android:layout_alignParentBottom="true"
android:visibility="invisible"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toBottomOf="parent" />
<Button
android:id="#+id/image_comment_save_button"
android:layout_width="100dp"
android:layout_height="45dp"
android:layout_marginBottom="2dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Save"
android:visibility="invisible"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toBottomOf="parent"
/>
</RelativeLayout>
</ScrollView>
<Button
android:id="#+id/note_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_note"
app:layout_constraintBottom_toTopOf="parent"></Button>
The activity is started with the path to an image, which it then loads into the image. When the note button is pressed it shows the textbox.
noteButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
writeNotes();
}
});
private void writeNotes() {
InputMethodManager methodMan = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if (noteBox.getVisibility() == View.VISIBLE) {
String text = noteBox.getText().toString();
if ( 0 < text.trim().length() ) {
Bitmap image = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
writeOnImage(image, text);
imageView.setImageBitmap(image);
saveImage(image, lastTaken);
exifData.put(ExifInterface.TAG_USER_COMMENT, text);
}
noteBox.setVisibility(View.INVISIBLE);
noteSaveButton.setVisibility(View.INVISIBLE);
methodMan.hideSoftInputFromWindow(noteBox.getWindowToken(), 0);
}
else {
noteBox.setText("");
noteBox.setVisibility(View.VISIBLE);
noteSaveButton.setVisibility(View.VISIBLE);
noteBox.requestFocus();
methodMan.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
}
The problem is that when the keyboard opens, there is a big black rectangle over it, that completely obscures the EditText and the Save button. This only happens on my phone, which is on 7.1.1, the emulator variants I have tried seem to work normally. Interestingly although they are obscured, they still work - if I type something on the keyboard and then press where the Save button should be, it saves the text as expected.
This screenshot shows the problem in action:
By changing the settings around the config file, I have found situations where the black rectangle is not shown, but in every case I have found that also hides the EditText component and even after the keyboard is closed I never see it again, leaving the activity in a weird state where there is no way to press the Save button.
If the keyboard is open the whole time the black rectangle only appears once the EditText has focus, prior to that the keyboard looks normal.
The closest thing I can find in previous questions suggests that android:inputType="textNoSuggestions" might help but it doesn't seem to make any difference - this doesn't seem to be a suggestion box, just an arbitrary black rectangle.
What do I need to do to stop my keyboard drawing a pointless black rectangle right over my input box or, if I am approaching this the wrong way somehow, what do I need to do to have an input box that allows the user to see the text that they are writing and then save it when they are content that it is complete?
The problem turned out to be related to the Android software buttons at the bottom of the screen, rather than the keyboard itself- for some reason they were causing the layout to measure the screen incorrectly whenever the keyboard was opened.
The solution was to add android:fitsSystemWindows="true" to the FrameLayout at the root of the view.

Changing the default size of the notification (Android)

So I wanted to create a special notification, and that's why I have used the remote views and not the default kind of notifications. I know that with that kind I'm able to use expanded notification or something... The problem is that with this kind of notifications, I don't know if I'm able to change the size...
This is the creation of my notification:
RemoteViews contentView = new RemoteViews(packageName, R.layout.new_event_notification);
contentView.setTextViewText(R.id.eventName,eventToDisplay.getName());
contentView.setTextViewText(R.id.eventDayOfTheWeekTxt, dateTextToDisplay.getDateTextToDisplay(context,eventToDisplay.getEventDate())); contentView.setTextViewText(R.id.eventTimeTxt,context.getString(R.string.at_time) + " " + eventToDisplay.getEventTime().toString());
contentView.setOnClickPendingIntent(R.id.attendButton, acceptPendingIntent);
contentView.setOnClickPendingIntent(R.id.declineButton, declinePendingIntent);
//Building the notification
NotificationCompat.Builder eventsNotification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.notification_template_icon_bg)
.setContentText("Incoming notifications")
.setContent(contentView);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
//Sending out the notification
notificationManager.notify(notificationID, eventsNotification.build());
The notification's layout XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
android:layout_marginTop="-4dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Event Name"
android:tag="event"
android:id="#+id/eventName"
android:layout_gravity="left"
android:textColor="#android:color/black"
android:textSize="21sp"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/eventDayOfTheWeekTxt"
android:layout_alignEnd="#+id/eventDayOfTheWeekTxt" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Going"
android:id="#+id/attendButton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="-5dip"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not Going"
android:id="#+id/declineButton"
android:layout_alignTop="#+id/attendButton"
android:layout_toRightOf="#+id/attendButton"
android:layout_toEndOf="#+id/attendButton"
android:layout_marginLeft="-7dip"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="EventDayOfWeek"
android:id="#+id/eventDayOfTheWeekTxt"
android:textColor="#000000"
android:singleLine="true"
android:layout_below="#+id/eventName"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="EventTime"
android:id="#+id/eventTimeTxt"
android:textColor="#000000"
android:layout_below="#+id/eventDayOfTheWeekTxt"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2"
android:layout_below="#+id/attendButton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
After it is created, it looks like this(the top one):
What I need you to look at, is the rest of the notifications in the picture, look how bigger they are than my notification.
Is there any way that I'll be able to change my notification size to a wanted size?
Or
at least to the size of the other notifications in the picture?
Just to be clear: I'm not talking about expanded size of the notification, but the default size.
You can't change the height your notification gets. The height of a notification is set by the system and you need to fit your contents into that space. If you need more space, you'll have to set a "big" content view (setCustomBigContentView) and try to get it to be expanded (use PRIORITY_HIGH, but this is no guarantee).
I don't know what kind of phone you have, but it seems to be rendering your layout larger than my phone does. The same layout code on my phone fits just fine.
I tried to force the buttons larger and at 70dp the layout just forced the lower button to be smaller so that it would fit.
However, I have seen a LinearLayout with items that get lost because they extend past the bottom of the notification area, which seems more like what you are seeing on your phone.
Maybe you can explicitly set your font size/button height to ensure everything fits?
If you are looking to provide space between text views (or buttons) then apply marginTop, marginBottom & other margins as per your requirement. You can play around with different values till you get desired result

progress fill on button click [duplicate]

I have a Button that is defined in a RelativeLayout as follows:
<Button
android:id="#+id/search_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/current_location"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingBottom="30dp"
android:paddingTop="30dp"
android:text="#string/search" />
I would like to add a ProgressBar behind the Button that occupies the exact same space as the Button, so that when the button is disabled (translucent), you can see the progress bar behind it. How would I do this?
To do this I had to define the button in my main.xml first, followed by the progress bar as follows:
<Button
android:id="#+id/search_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/current_location"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingBottom="30dp"
android:paddingTop="30dp"
android:text="#string/search" />
<ProgressBar
android:id="#+id/cooldown_bar"
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/search_button"
android:layout_below="#id/current_location"
android:layout_marginBottom="6dp"
android:layout_marginLeft="9dp"
android:layout_marginRight="9dp"
android:layout_marginTop="1dp"
android:indeterminate="false"
android:progressDrawable="#drawable/progress_bar" />
Then, once I had initialized all the GUI components, I had to bring the button back in front of the progress bar with:
searchButton.bringToFront();
The end result
Button when enabled:
Button when disabled with progress bar:
put this right before the button inside the relative layout in your xml:
<ProgressBar
android:id="#+id/descriptive_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/current_location"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingBottom="30dp"
android:paddingTop="30dp"
/>
by using all of the same layotu and padding attributes we can make sure the View will be in the same spot and roughly the same size (height could be different because of wrap_content) I think if you put the progress bar first in the layout file then the button should appear on top.
But also you can enforce whatever policy you want with view.setVisibility(visibility-ness)just make sure whenever you make one visible you make the other invisible.
that way in-case I am wrong about how they stack by default based on their position in the file (which I could be, I didn't verify it just now) and in the event you don't want to move the progress bar to bellow the button in the file, you could still achieve the same thing from the users perspective.

ImageView backgroud does not change smoothly on button click

I am writing a simple app that changes the application background randomly on button click.
I have a arraylist that contains 5 id's of images that the application should use:
ArrayList<Integer> imageID = new ArrayList<Integer>();
imageID.add(R.drawable.frame_blue);
imageID.add(R.drawable.frame_green);
imageID.add(R.drawable.frame_lilac);
imageID.add(R.drawable.frame_pink);
imageID.add(R.drawable.frame_yellow);
I have two buttons in my layout xml file for next and previous. Both should change Application background when clicked.
I change the image background from this arraylist:
iM.setBackgroundResource(imageID.get(r.nextInt(5)));
and my layout xml looks like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/parentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="76dp"
android:onClick="previous"
android:text="Previous" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_alignParentRight="true"
android:onClick="next"
android:text="Next" />
</RelativeLayout>
All works fine on button click's, ImageView background change as I expect, but the problem is the background is not changing smoothly.
It hangs some time. May be the main ui thread will be block for 1 or 2 second and this look like application hangs.
Hangs mean: Some time button remain clicked for a few seconds.
I tried asynctask did not have success. Is there a way to make it change smoothly?
you need to use caching in order to save time and not inflate every time the images
like this : Drawable image_frame_green = getResources().getDrawable(
R.drawable.frame_green);
Have you tried to preload all drawables in cache and then instead of setting the background resource, set the background drawable as background directly.

Hiding the sliding drawer handle

I am building a view in my Android application using a sliding drawer widget. I have implemented my own custom handles (just a row of menu buttons which then changes the content of the drawer and then activates the openAmination). I have managed to disable the standard handle provided with the slidingdrawer but I want to completely remove it.
None of the standard visibility stuff in xml or java works in hiding/removing the handle:
<SlidingDrawer android:layout_width="fill_parent"
android:id="#+id/slidingDrawer1"
android:layout_height="fill_parent"
android:handle="#+id/handle"
android:content="#+id/content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:allowSingleTap="false"
>
<Button android:layout_width="wrap_content"
android:text="Close"
android:layout_height="wrap_content"
android:id="#+id/handle"
android:visibility="gone" //DOES NOT WORK
</Button>
<LinearLayout android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
</LinearLayout>
</SlidingDrawer>
I also tried importing the view in java and doing the same but also does not work.
View h = findViewById(R.id.handle);
h.setVisibility(View.GONE);
I have then tried extending the slidingDrawer class and making my own but it still requires a handle!. Is there anyway I have a sliding drawer without a default handle?
-----SOLUTION----
draw = (SlidingDrawer)findViewById(R.id.slidingDrawer1);
//Close the draw if opened when the user touches elsewhere on the screen
draw.setOnTouchListener(new OnTouchListener(){
#Override
public boolean onTouch(View v, MotionEvent event) {
if(draw.isOpened())
((SlidingDrawer)v).animateOpen();
return false;
}});
//Open the draw by external button
((Button) findViewById(R.id.quiz_button)).setOnClickListener(
new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
draw.animateOpen();
} });
An the XML for the sliding draw view was:
<SlidingDrawer android:layout_width="fill_parent" android:allowSingleTap="false" android:id="#+id/slidingDrawer1" android:content="#+id/content" android:handle="#+id/handle" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:layout_alignParentLeft="true">
<Button android:layout_height="wrap_content" android:layout_width="0px" android:visibility="invisible" android:text="Close" android:id="#+id/handle"></Button>
<LinearLayout android:id="#+id/content" android:gravity="center" android:background="#4FFFFF44" android:layout_width="fill_parent" android:layout_height="76dp"></LinearLayout>
</SlidingDrawer>
Many Thanks
Sam
I tried for many hours and failed to get rid of the handle, the best I could do wass move it far away from the view window. If you have already extended the slidingdrawer class it should be easy.
In the onLayout method find the line
handle.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
and change it to
handle.layout(10000, 10000, 10000, 10000);
Basically its just setting its position to way of screen.
I found a better way to fix the problem.
Do not hide a handle itself, but it's content. I had an ImageView as a handle, but I changed it to a LinearLayout holding an ImageView.
<LinearLayout
android:id="#id/handle"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/handleImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/sliding_drawer_handle" />
</LinearLayout>
Now handleImage.setVisibility(View.INVISIBLE) works fine in onAnimationEnd.
Hope that helped :)
I have the same problem, I don't want to show the handle because I have a personal button that shows the SlidingDrawer at the click. So, I solve it setting the handle height to 0dp.
This is my handle code:
<ImageButton
android:id="#+id/cash_menuGruop_handle"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_contetn"
android:layout_height="0dp"/>
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/handle"
android:visibility="gone" //DOES NOT WORK
</Button>
use height and width 0dp
,for open and close use handle.performclick();
it is working for me

Categories

Resources