back/ cancel button in ZXing QR code scanner - java

I am very new to developing apps, and I have an android application with zxing-android-embedded 4.3.0 and implemented a QR code scanner. I wish to add a back button in the scanning layout and if I add elements, it disappears when executing the code.
Part of the QR code scanner (as IntentIntegrator is deprecated now)
scanQRCodeButton.setOnClickListener(view -> {
if (requestNecessaryPermissions()) {
enableEditTexts(editTexts);
ScanOptions options = new ScanOptions();
options.setDesiredBarcodeFormats(ScanOptions.QR_CODE);
options.setPrompt("Scan ID");
options.setTimeout(10000);
options.setCameraId(0); // Use a specific camera of the device
options.setBeepEnabled(false);
options.setBarcodeImageEnabled(true);
options.setOrientationLocked(true);
barcodeLauncher.launch(options);
}
});
part of the XML file
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/scan_qr_code_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:src="#drawable/ic_baseline_qr_code_scanner_24" />
Once this QR/scan button is hit, the zxing scanner is opened to scan the code. How do I add a floating button in the scanning page to get back to the main window?

Related

How do I make a button that quits the application in Android Studio using the Java programming language?

I've been trying to use Google to search on how to make a simple quit button in java on Android Studio IDE. Unfortunately all of the tutorials on Youtube or otherwise are all tutorials on how to make functioning buttons in the Kotlin programming language. The reason why I need to make the button in Java is that it is for College. I am new to the software developing world so any help would be appreciated.
Create a button with the following code in your .xml file:
<Button
android:text="Quit"
android:id="#+id/quit"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
In your Activity, get the button view in onCreate or where you need it and add an onClicklistener:
Button quit = findViewById(R.id.quit);
quit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
finishAndRemoveTask();
}
});
This works for API 21 and above.

How to show progressbar with blurry background and disabled UI

so I am making an app which has a lot of connections to the database, so there is a "waiting" time everywhere.
I want to put a progress bar everywhere where is a connection to the database. It should look like this:
-The progress bar is shown after clicking the Login button with the blurry background.
In short - Show progress bar, blur the background, deactivate UI controls while progressbar is activated.
I'll try to show you the pseudo code here:
loginBtn.setOnClickListener {
progressBar.visibility = View.VISIBLE
BlurTheBackground()
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
DoTheLoginStuff()
}
And after Login I want to disable progress bar and reactivate fully UI.
PS: After Login the activity changes to another,but after hitting back button on the smartphone it comes back without refresh
You can try https://android-arsenal.com/details/1/4409 this library. I think it can help You.
<RelativeLayout
android:id="#+id/progressBar_blurLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.armboldmind.natalipharm.view.customViews.RealtimeBlurView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:realtimeBlurRadius="15dp"
app:realtimeOverlayColor="#99FFFFFF" />
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
Set it on top of your layout, and on login button click change visibility of progress bar layout.

How to achieve the following Image + Text in button in android app?

I am trying to make a clickable phone number button with an icon in my app. I was checking for some references and found google maps implementation good. How can I achieve this in my app?
I have tried the Image Button view but that does not solve the problem. I have put 'onClick' attribute for text & image views, but the button animation isn't there and both text & image icon does not look together.
Please guide me as to what view/s we have to use to achieve the result as in the image and how to get that animation on click of the button. Or is there any better way to achieve this?
I am aware of intents, so that part is clear.
If you can let me know how to make that phone number copied to the clipboard automatically on hold of that button, that would be really great.
Try this code
Change spacing dimens according to your use and also change icon.
<LinearLayout
android:id="#+id/callButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/spacing_small"
android:padding="#dimen/spacing_small"
android:clickable="false"
app:srcCompat="#drawable/ic_download"
android:tint="#color/black" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/amaranth"
android:gravity="center_vertical"
android:paddingLeft="#dimen/spacing_xxhuge"
android:paddingTop="#dimen/spacing_medium"
android:paddingBottom="#dimen/spacing_medium"
android:text="000 0000 000"
android:textColor="#color/grey_70"
android:textSize="#dimen/textsize_large" />
</LinearLayout>
and set on click listener on callButton. use below code in java code.
And also i have added a code to copy phone number directly on click event. You have to save text in clipboard.
LinearLayout callButton = findViewById("callButton");
callButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(label, text);
// You have to get text from phoneNumber textview. and set it to clipboard.
clipboard.setPrimaryClip(clip);
}
});
Some questions:
Do you have any experience with Android development?
If so, do you have anything up and running?
I'm gonna assume you do have experience but you're asking before you start coding anything. There are many ways to implement this, the way that would be easiest would be to have a custom listview (here's a simple and easy tutorial for that) and use an item in the listview to display a phone number. Each listview item has a setOnItemLongClickListener which you can use and inside it use the ClipboardManager to copy or use an intent to the phone calling service.
list.setOnItemLongClickListener(new OnItemLongClickListener() { //list is my listView
#Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
final int pos, long id) {
//Whatever you wanna do
ClipboardManager clipboard = (ClipboardManager)
getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(label, text);
clipboard.setPrimaryClip(clip);
}
});
I believe this is what you want to achieve
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Your other layouts-->
<TextView
android:background="?selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:padding="#dimen/activity_vertical_margin"
android:drawableStart="#drawable/ic_phone"
android:drawablePadding="16dp"
android:text="The mobile number here"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
android:background="?selectableItemBackground"
This will add the default system animation of ripple(or anything) on click.
Also android:focusable=" and android:clickable="true" is necessary for this to work.
If you want to customize the click events, you better be using selectors in the background of your view.
For the 'Copy to Clipboard' feature you can refer to the other answers.
Happy Coding!

how to display this notification in Android?

Im looking for this library to display this kind of notification that i could display when there is a new update on my list.
Here is the sample like in Facebook or LinkedIn.
You can use this library popup bubble for the above requirement
In your xml
<com.webianks.library.PopupBubble
android:layout_margin="16dp"
android:id="#+id/popup_bubble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
In your activity
PopupBubble popupBubble = (PopupBubble) findViewById(R.id.popup_bubble);
popupBubble.setPopupBubbleListener(new PopupBubble.PopupBubbleClickListener() {
#Override
public void bubbleClicked(Context context) {
//popup_bubble is clicked
}
});
you can also attach this to your recycler view
popupBubble.setRecyclerView(recyclerView);
set an onScrollListener to your RecyclerView. On every scroll call your API which fetches the data.
Use a TextView with Gone/Visible fadein/fadeout animation if new data is added. This can be simply done from the adapter.

Android AutoCompleteTextView can't exit input keyboard

Hello fellow Android programmers,
today I wanted to create a simple AutoCompleteTextView with a custom Adapter, which works perfectly fine on the Emulator. But if I now run the whole thing on my Samsung Galaxy Young and I enter some text into the ACTextView, it suggests me everything as it should, but I can't click the "OK" button in the bottom right corner of the keyboard that is showing up.
If I flip the Smartphone and change orientation, I get rid of the annoying keyboard, but I can't close it any other way. Solutions? Here is the code and xml used:
<AutoCompleteTextView
android:id="#+id/vereinAutoComplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:hint="#string/vereinHint"
android:inputType="textNoSuggestions">
</AutoCompleteTextView>
And the Java code for the Adapter (it's a custom one):
rootView = inflater.inflate(R.layout.verein_layout, container, false);
AutoCompleteTextView acTextView = (AutoCompleteTextView)rootView.findViewById(R.id.vereinAutoComplete);
acTextView.setAdapter(new SuggestionAdapter(getActivity(),acTextView.getText().toString()));
acTextView.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
I am using the whole thing in a Fragment, so don't wonder the rootView and so on...
There is some code for the Listener, but I don't think it is important for my question.

Categories