I have some items in recyclerview, loaded from a server...
i managed to set onClicks in the item & then show a Dialog...
I gave some conditions for dialog...
if(isDownloading()){
//Dialog shows Cancel Download button
}
else if(isDownloaded()){
//Dialog shows Delete Button...
}
else{
//Dialog shows Download Button
}
my problem is that I want to allow only One Download at a time...
if the user selects another item then how can i show a dialog sayin like "Download Pendin, try later"
Any Help will be appreciated :)
maybe not best approach , you can use sharedpreferences ,
checkdownload();
int v = pref.getInt("key_name", 3)
if(v==1){
//download
}else{
// show download is pending
}
as you told you already have method to check status ....
public void checkdownload(){
....
....
if(pending){
editor.putInt("key_name", 0)
editor.commit();
}else{
editor.putInt("key_name", 1)
editor.commit();
}
}
Related
https://www.google.com/search?q=message+image+on+last&sxsrf=ALeKk01qNrLQ61yRXCMSPRxyNaoI0MF_kA:1605295893515&source=lnms&tbm=isch&sa=X&ved=2ahUKEwjj2veboYDtAhWeIbcAHebnB4QQ_AUoAXoECAwQAw&biw=1366&bih=657#imgrc=wzgnznL_g7kUsM
I want to show profile image like shown in above link only at last message of every consecutive messages from same person. Please help me with this.
I have tried many ways but I don't know to hide visibility of top images
if (position > 0) {
if (messageList.get(i).getFrom.equalsIgnoreCase(messagesList.get(position - 1).getFrom()))
{
viewHolder.mProfileImage.setVisibility(View.INVISIBLE);
}
else
{
viewHolder.mProfileImage.setVisibility(View.VISIBLE);
}
}
else
{
viewHolder.mProfileImage.setVisibility(View.VISIBLE);
}
I have used above code and get this result which is shown in this http://i.stack.imgur.com/92SUb.jpg link. With this code I am able to hide all the images other than the first one image. can you please show me the way to hide top message image and not the last one of streak.
I have to assume few things in my answer.
i.e.
messageList is the list of all messages. not the list of only consecutive/streak messages.
you need to show profile images for both sender and receiver.
And you want to only show the profileImage of last consecutive message.
So, here what you should do.
int length = messageList.lenght; //getTotalLenght;
String fromCurrent = messageList[position].getFrom(); //getFrom of current message being painted or shown
String fromNext = fromCurrent; //next message is set to current by default, to avoid error
if(length > postition+1) {
fromNext = messageList[position+1].getFrom(); //if there is next message then get its sender but if it is the last message then nextSender and currentSender are same as I set its default value to the currentSender.
}
console.log("TAG", "FromNext: " + fromNext);
console.log("TAG", "FromCurrent: " + fromCurrent);
if(!fromCurrent.equals(fromNext)) { //checking if last message or not
viewHolder.mProfileImage.setVisibility(View.VISIBLE);
}
else {
viewHolder.mProfileImage.setVisibility(View.INVISIBLE);
}
if there is no internet means I'm not able to load web resources. For this reason I'm giving the toast like "Check internet connectivity". After this toast, user may enable the internet option at notification bar and comes back. When he comes back, i want to reload the activity. For this requirement, i tried
onWindowFocusChanged and onActivityReenter
override methods but these are not working properly
MyCode
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(hasFocus){
Intent intent = new Intent(CommonActivity.this, OtherActivity.class);
startActivity(intent);
}
}
When I'm using above code, my activity reloading again and again
There is a solution which i know is not perfect but it will work.
Define a activity level veriable like this
Boolean isAlreadyFocused = false;
Then in your onFocusChanged method do like this.
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(hasFocus && !isAlreadyFocused ){
isAlreadyFocused = true;
Intent intent = new Intent(CommonActivity.this,OtherActivity.class);
startActivity(intent);
}else{
isAlreadyFocused = false;
}
}
Check this and tell me if this does not work.
By fallowing another way (i got this idea when i saw the flipkart app) i solved this internet checking
I'm checking for the internet connection, if there is no internet means i'm redirecting to NoInternetActivity that's design looks like
When user clicks on Retry button means i'm again checking for internet. If internet was accessible means i'm allowing user to home page of my app otherwise i'm redirecting to the NoInternetActivity again
I have an Activity that loads all vouchers on the server to customer's phone. In that Activity, I have 2 buttons. The first button will get all vouchers that bought by the customer. The second will get the list of all available vouchers that customer can buy.
Now, the problem is, I need only onListItemClick for the list of available vouchers (when they click on those vouchers, they have option to buy). I use ListView as ListActivity. When I set onListItemClick, the event apply for bought vouchers as well.
How can I somehow deactivate onListItemClick event when customers view their own vouchers and activate it when customers choosing voucher to buy?
This is my code of the two buttons:
public void btn_Own(View v){
if(!isConnected){
Toast toast = Toast.makeText(Voucher.this, "Cannot connect to internet", Toast.LENGTH_LONG);
toast.show();
return;
//finish();
}
if(email.equals("")){
Toast toast = Toast.makeText(Voucher.this, "Please log in to see your voucher!", Toast.LENGTH_LONG);
toast.show();
}else{
url = "http://wswob.somee.com/wobservice.svc/checkOwnVoucher/" + email + "/";
new checkingTask().execute();
}
}
public void btn_Shop(View v){
if(!isConnected){
Toast toast = Toast.makeText(Voucher.this, "Cannot connect to internet", Toast.LENGTH_LONG);
toast.show();
return;
//finish();
}
url = "http://wswob.somee.com/wobservice.svc/showVoucher";
new MyTask().execute();
}
I'm new to Android, so I just came to know that I have to use custom adapter to do so (as far as I know). But I wonder how can I do that while I'm using asynctask and pass different parameters when I need that do execute different tasks from web service.
This is how I get the list after calling web service:
protected void onPostExecute(Void result){
super.onPostExecute(result);
ListAdapter adapter = new SimpleAdapter(
Voucher.this, voucherList,
R.layout.voucher_list, new String[]{"detail","price"},
new int[]{R.id.detail, R.id.price});
setListAdapter(null);
setListAdapter(adapter);
}
You should be able to use setEnabled to true or false to control when the user can actually click the link or button.
You should use the button click events of activity,you have two button,onclick of frist but just make the listview Itemclicklistener disable after loading all vocher from server and on click of second button which loads available vochers only make your listviewItem clickable.
We have to show a license agreement dialog when user use the application at the first time, now I have two questions about this:
1 Where to put this dialog?
Add another activity or put the dialog just at the MainActivity which is the launch acitivty?
2 How to close the app if user hit "Reject"
Once user hit the "Reject" button which means that he/she does not agree our license, then we have to exit the application completely. How to make it?
According to the answer of "Ahmad", I will decide to open a dialog or not at the beginning of the activity(the onCreate method):
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
this.setupLicense();
this.setupViews();
this.initSomeJob();
}
private void setupLicense() {
SharedPreferences setting = getSharedPreferences(IConstant.Map_License, 0);
boolean mapLicenseAccept = setting.getBoolean(IConstant.Map_License, false);
if (!mapLicenseAccept) {
//user does not accept the license yet, we will open the dialog
showDialog(Dialog_Map_License);
}
}
#Override
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
switch (id) {
case Dialog_Map_License:
builder.setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(R.string.map_license_title)
.setMessage(R.string.map_license_content)
.setPositiveButton(R.string.map_license_accept, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//License accepted, persisted it.
SharedPreferences settings = getSharedPreferences(IConstant.Map_License, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(IConstant.Map_License, true);
editor.commit();
}
})
.setNegativeButton(R.string.map_license_reject, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//do nothing and exit
Process.killProcess(Process.myPid());
System.exit(0);
}
});
Dialog target = builder.create();
target.setCanceledOnTouchOutside(false);
return target;
}
return null;
}
But now I have meet two problem:
1 Event I choose the "Accept" button, once I open my app the second time, the dialog will show.
It seems that the following code does not work:
editor.putBoolean(IConstant.Map_License, true);
editor.commit();
2 When I show the dialog, the code:
this.setupViews();
this.initSomeJob();
will still run , they are not blocked which is out of expected, since nothing should be done before user hit the "Accept" button.
Any idea to fix it?
onCreateDialog has been deprecated. Use dialog fragment instead. The advantage will be that the code for displaying dialog will be moved from activity and you can then display dialog from any activity. Also move
SharedPreferences setting = getSharedPreferences(IConstant.Map_License, 0);
boolean mapLicenseAccept = setting.getBoolean(IConstant.Map_License, false);
to a utility method like isLicenceAccepted and similarly for storing the data
SharedPreferences settings = getSharedPreferences(IConstant.Map_License, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(IConstant.Map_License, true);
editor.commit();
to method like acceptLicence in utility.
You can find how to make communication between dialog Fragment and your activity here. In your interface instead of onArticleSelected you will have to implement two methods onLicence accepted and onLicenceRejected. Implement the interface in you activity override these two methods and take appropriate action.
Where to put this dialog?
Right at the beginning, when the user opens the app for the first time. Keep track of that by saving it in your shared preferences, if this dialog has been already shown or not. You don't have to create a separate activity for this. You could, but most apps I've seen out there don't.
How to close the app if user hit "Reject"
Just finish the Activity and also save that in your shared preferences as well. So every time the user opens your app you check weather the boolean value for "hasUserAcceptedOurAgreement" is true or not and proceed depending on that.
I'm only answering from a technical standpoint on how this could be done reliably. I'm not a lawyer, but as far as I know, it's perfectly valid to just submit your license agreement to the play store, so it's available from the applications application page (Why else would there be this option?).
The thing is like this. I have a zip file with images that uncompressing in the background (using a Thread) I start a new Activity from my main one to show these images. To show the first image I call this function on onResume:
public boolean showImage(String validFile){
File page = new File(validFile);
System.err.println("Attempting to show " + validFile);
boolean found = false;
if (page.exists()){
System.err.println("Page exist");
found = true;
}
else{
System.err.println("Page does not exist");
long start = System.currentTimeMillis();
//ProgressDialog loading = ProgressDialog.show(this, "", "Loading....",true);
Toast.makeText(this, "Loading...", Toast.LENGTH_LONG);
while (((System.currentTimeMillis() - start) < 5000) && (!found)){
if (page.exists()){
found = true;
//t.cancel();
System.err.println("Page found");
}
else{
System.err.println("Page does not exist");
}
}
}
if (!found){
return false;
}
else{
System.err.println("Setting up image");
ims.setImageDrawable(new BitmapDrawable(BitmapFactory.decodeFile(validFile)));
return true;
}
}
All I want to do is to show a Toast a progress dialog or something that says Loading... while the first image uncompresses. However neither the toast or the image are shown. Now I know the image is there for two reasons: 1 the Setting up Image and File found messages appear and I can use fling to move through the images and work just fine.
This is what happens. My activity starts and enters the code above but the first image is never shown. I fling and see the second image and the third and so forth.
So what am I doing wrong?
Thanks for any help!
There might be another issue besides this, but the toast will not appear if you don't call the show() method:
Toast.makeText(this, "Loading...", Toast.LENGTH_LONG).show();