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();
Related
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();
}
}
I'm developing an app using Flash CC. I'm using the Google Play Services to login the people in the App, but I have a problem.
When I install the App, I have to login. When I'm logged in, I don't have problems. If I close the app and then I open again the game, says that I'm not logged in. So, I click login, I log in but then I recive the SIGN_IN_FAILS error. In the code, first I check if the user is logged in and if is not logged in, I show the Log In button. But what happens with the people who has connected before? I have an "else" telling that if he is already logged in, he can 'Continue'. But always says that I'm not logged and I have to log in! But if I log in another time I get the error!
PS. I'm using freshplanet/laurentiu ANE/library.
** EDIT **
CODE:
import com.freshplanet.ane.AirGooglePlayGames.AirGooglePlayGames;
import com.freshplanet.ane.AirGooglePlayGames.AirGooglePlayGamesEvent;
import com.laurentiu.ane.AirGooglePlayServices.AirGooglePlayServices;
var airGooglePlayGames: AirGooglePlayGames = AirGooglePlayGames.getInstance();
airGooglePlayGames.addEventListener(AirGooglePlayGamesEvent.ON_SIGN_IN_SUCCESS, onSignInSuccess);
airGooglePlayGames.addEventListener(AirGooglePlayGamesEvent.ON_SIGN_OUT_SUCCESS, onSignOutSuccess);
airGooglePlayGames.addEventListener(AirGooglePlayGamesEvent.ON_SIGN_IN_FAIL, onSignInFail);
this.checkeStatus();
button_login.addEventListener(MouseEvent.CLICK, googleSignIn);
btn_out.addEventListener(MouseEvent.CLICK, googleSignOut);
btn_out.visible = false;
button_login.visible = false;
function googleSignIn(e: MouseEvent = null): void {
AirGooglePlayGames.getInstance().signIn();
}
function checkeStatus() {
if (!AirGooglePlayGames.getInstance().isSignedIn()) {
// Always stay here when I reopen the app
btn_out.visible = false;
button_login.visible = true;
} else {
// I never arrive here
texto.text = "PLAYERID: " + AirGooglePlayGames.getInstance().getActivePlayerID();
loadingBar.gotoAndStop(2);
button_login.visible = false;
btn_out.visible = true;
}
}
function onSignInSuccess(e: AirGooglePlayGamesEvent): void {
// I only arrive here if is the first time I open the app and login for first time
texto.text = "PLAYERID: " + AirGooglePlayGames.getInstance().getActivePlayerID();
loadingBar.gotoAndStop(2);
button_login.visible = false;
btn_out.visible = true;
}
function onSignOutSuccess(e: AirGooglePlayGamesEvent): void {
texto.text = "SIGN OUT OKAY!";
loadingBar.gotoAndStop(1);
button_login.visible = true;
btn_out.visible = false;
}
function onSignInFail(e: AirGooglePlayGamesEvent): void {
texto.text = "SING IN FAIL: " + e;
loadingBar.gotoAndStop(1);
button_login.visible = true;
btn_out.visible = false;
}
function googleSignOut(e: AirGooglePlayGamesEvent): void {
texto.text = "SIGN OUT PROGRESS";
airGooglePlayGames.signOut();
loadingBar.gotoAndStop(1);
button_login.visible = true;
btn_out.visible = false;
}
Any idea what could happen?
A few things that might help:
I think your stuff at the top should be in a constructor function. For this type of code, with event listeners, you might be much better off making an external .as3 file and attach to a document class or movieClip base class, than putting the code in the timeline, as I think your code might not always be available as you move around??
And I notice you do:
this.checkeStatus();
Right away, which might do this:
btn_out.visible = false;
button_login.visible = true;
Or it might do this:
button_login.visible = false;
btn_out.visible = true;
But I think it doesn't matter because right after that, you return to the line under this.checkeStatus(), and get this:
btn_out.visible = false;
button_login.visible = false;
So no matter what happened with this.checkeStatus(), you end up with both buttons turned off, no? So maybe try moving this.checkeStatus(); down to the bottom of the constructor function so it goes last.
It might be more compact and less confusing to break off all these repeating visible = false / true lines into their own function like:
private function setStatusButtonsVisible(status:Boolean){
button_login.visible = status;
btn_out.visible = !status;
if (status){
loadingBar.gotoAndStop(2);
}else{
loadingBar.gotoAndStop(1);
}
}
Since in all cases but the first you're toggling the 2nd to be the opposite of the first.
In the setup part of my app, I want to take a picture then display it. I want to display a Progress Dialog while saving the image to disk. My ProgressDialog code works except on a Droid Mini running KitKat.
I have tried a number of approaches, including this blog https://www.workreloaded.com/2011/06/how-to-use-the-android-camera/. I liked the approach but the ProgressDialog did not appear for me.
I think the root of the problem is some timing issue using the UI thread. But I can't precisely diagnose it and definitely can't solve it. My questions:
1. Does camera.takePicture() run on the UI thread?
2. What would prevent a ProgressDialog from appearing?
3. Does someone have a working example (besides the above post) that I could use?
I'm posting code that works but is bad practice and code that doesn't work but would be more maintainable.
The following code with a test for KitKat works, but is bad practice.
public class PreviewTestNextButtonListener implements Button.OnClickListener {
private static final String TAG = "PreviewTestButtonListener";
PreviewTest previewTest;
Camera camera;
public PreviewTestNextButtonListener(PreviewTest context, Camera camera) {
this.previewTest = context;
this.camera = camera;
}
public void onClick(View v) {
Log.v(TAG, "Taking picture");
try {
PhotoSaverPreviewTest photoSaver = new PhotoSaverPreviewTest(previewTest);
if (Build.VERSION.SDK_INT != Build.VERSION_CODES.KITKAT) {
// don't display the progress dialog in kit kat because my Droid Mini running KitKat has a problem with
// this. But the Mini is so fast that the save is instantaneous
previewTest.showProgressDialog();
}
// photoSaver will launch the StoredRotationTest
camera.takePicture(null, null, photoSaver);
} catch (Exception e) {
Log.e(TAG, "failed to start Stored Rotation Test because " + e, e);
}
}
}
In an alternative version, I tried simply calling the ProgressDialog from takePicture() but that doesn't work. I also tried an AsyncTask, but that did not present a ProgressDialog either.
public void onPictureTaken(final byte[] imageData, Camera camera) {
Log.e(TAG, "starting onPictureTaken");
// **** this does not present the ProgressDialog
activity.showProgressDialog();
if (imageData != null) {
Log.e(TAG, "got image data");
camera.startPreview();
Display display = ((android.view.WindowManager) activity.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
int displayRotation = display.getRotation();
try {
// showProgressDialog();
// save the image to disk in the background
RotateAndWriteImageAsync imageWrite = new RotateAndWriteImageAsync(activity, displayRotation, imageData);
imageWrite.mySpecialMove();
Intent intent;
// during set up, launch the stored image rotation test
intent = new Intent(activity, StoredRotationTest.class);
activity.startActivity(intent);
PreviewTest.dismissProgressDialog();
} catch (Exception e) {
Log.e(TAG, "error saving image or start rotation test: " + e);
}
} else {
Log.e(TAG, " ");
Log.e(TAG, "NO IMAGE DATA passed in parameter from camera");
Log.e(TAG, " ");
}
}
And finally, the method that presents the ProgressDialog from the PreviewTest Activity.
/** Called by Next Button which is a bit of kludge.*/
public void showProgressDialog() {
if (progress == null) {
progress = new ProgressDialog(this);
progress.setTitle("Saving picture");
}
progress.show();
}
/** Called by StoredRotationSetup which is a bit of a kludge.*/
public static void dismissProgressDialog() {
if (progress != null && progress.isShowing()) {
progress.dismiss();
}
}
Mark Murphy(aka Commonsware) gave me some guidance during his office hours. ProgressDialogs are bad form: https://ux.stackexchange.com/questions/12637/what-research-is-there-suggesting-modal-dialogs-are-disruptive. My ProgressBar only shows when the user is waiting, but it does not pop up.
ProgressBar solved my problem. Here is the .xml:
<ProgressBar
android:id="#+id/next_progress_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/rotate_orientation_button"
style="#android:style/Widget.ProgressBar.Large"
android:indeterminate="true"
android:visibility="invisible" />
And the Java:
// progress bar
ProgressBar progressBar = (ProgressBar) findViewById(R.id.next_progress_bar);
progressBar.setVisibility(View.VISIBLE);
Hi I am fairly an amateur at android so I might not be realizing something obvious.
I have a method that populates a global File Array variable with a list of flies in a specific directory. Problem is everything works fine if the directory has been made before by using my app to save a file there however when the user hasn't done that an error message is suppose to pop up saying they haven't saved a file yet.
I do a check if the directory exist but the app crashes when the directory has not been created.
This is what my code looks like any assistance would be appreciated
private void getTemplates()
{
//Gets file directory for saved templates
File finalMarkTemplateDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Final Mark Templates");
//Checks if path exists in other word if any templates have been saved before
if(finalMarkTemplateDir.exists())
{
templatePaths = finalMarkTemplateDir.listFiles();
}
else
{
Toast.makeText(this, "No previous templates have been saved.", Toast.LENGTH_LONG).show();
setResult(RESULT_CANCELED);
finish();
}
}
I am too an amateur, you have not created a file in your code, calling a new file() method does not create a file. Pls check that out
try {
finalMarkTemplateDir.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I managed to solve my problem when I call the setResult and finish methods I did not realize the flow of the program is returned to my onCreate method which meant the rest of my method calls in onCreate was still being called and they require the templatePaths array.
So basically I thought finish would stop the processing and move back to the calling class(using startActivityForResult). Instead I now call finish from my onCreate and use a boolean to determine if I could successfully access the directory.
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//setContentView(R.layout.dialog_load_template);
boolean fileLoadStatus = getTemplates();
if(fileLoadStatus)
{
populateTemplateList(templatePaths);
}
else
{
setResult(RESULT_CANCELED);
finish();
}
}
private boolean getTemplates()
{
boolean fileLoadStatus = false;
//Gets file directory for saved templates
File finalMarkTemplateDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Final Mark Templates");
//Checks if path exists in other word if any templates have been saved before
if(finalMarkTemplateDir.isDirectory())
{
templatePaths = finalMarkTemplateDir.listFiles();
fileLoadStatus = true;
}
else
{
Toast.makeText(this, "No previous templates have been saved.", Toast.LENGTH_LONG).show();
}
return fileLoadStatus;
}
When my submit button is clicked, it calls a method which checks if a certain EditText is empty and displays a toast message as an error message accordingly. However, if I rapidly tap on submit, it "queues" a lot of toast messages. How can I prevent this?
Here's my method:
private void checkName() {
if (etName.getText().toString().isEmpty()) {
Toast toast = Toast.makeText(this, "Please enter your name", Toast.LENGTH_LONG);
toast.show();
} else {
submit();
}
}
What happens is you are creating new toasts each time checkName() is called, hence they are "queued" by the system and shown one after another. You can try the following to ensure you are just making one toast and simply show it when needed:
Toast mToast;
private void checkName() {
if (etName.getText().toString().isEmpty()) {
if (mToast == null) { // Initialize toast if needed
mToast = Toast.makeText(this, "", Toast.LENGTH_LONG);
}
mToast.setText("Please enter your name"); // Simply set the text of the toast
mToast.show(); // Show it, or just refresh the duration if it's already shown
} else {
submit();
}
}