Search in sources :

Example 66 with Toast

use of android.widget.Toast in project apps-android-commons by commons-app.

the class ShareActivity method onAuthFailure.

@Override
protected void onAuthFailure() {
    Toast failureToast = Toast.makeText(this, R.string.authentication_failed, Toast.LENGTH_LONG);
    failureToast.show();
    finish();
}
Also used : Toast(android.widget.Toast)

Example 67 with Toast

use of android.widget.Toast in project apps-android-commons by commons-app.

the class MultipleShareActivity method onAuthFailure.

@Override
protected void onAuthFailure() {
    Toast failureToast = Toast.makeText(this, R.string.authentication_failed, Toast.LENGTH_LONG);
    failureToast.show();
    finish();
}
Also used : Toast(android.widget.Toast)

Example 68 with Toast

use of android.widget.Toast in project apps-android-commons by commons-app.

the class UploadService method uploadContribution.

private void uploadContribution(Contribution contribution) {
    MWApi api = app.getMWApi();
    ApiResult result;
    InputStream file = null;
    String notificationTag = contribution.getLocalUri().toString();
    try {
        //FIXME: Google Photos bug
        file = this.getContentResolver().openInputStream(contribution.getLocalUri());
    } catch (FileNotFoundException e) {
        Timber.d("File not found");
        Toast fileNotFound = Toast.makeText(this, R.string.upload_failed, Toast.LENGTH_LONG);
        fileNotFound.show();
    }
    Timber.d("Before execution!");
    curProgressNotification = new NotificationCompat.Builder(this).setAutoCancel(true).setSmallIcon(R.drawable.ic_launcher).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)).setAutoCancel(true).setContentTitle(getString(R.string.upload_progress_notification_title_start, contribution.getDisplayTitle())).setContentText(getResources().getQuantityString(R.plurals.uploads_pending_notification_indicator, toUpload, toUpload)).setOngoing(true).setProgress(100, 0, true).setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, ContributionsActivity.class), 0)).setTicker(getString(R.string.upload_progress_notification_title_in_progress, contribution.getDisplayTitle()));
    this.startForeground(NOTIFICATION_UPLOAD_IN_PROGRESS, curProgressNotification.build());
    String filename = null;
    try {
        filename = Utils.fixExtension(contribution.getFilename(), MimeTypeMap.getSingleton().getExtensionFromMimeType((String) contribution.getTag("mimeType")));
        synchronized (unfinishedUploads) {
            Timber.d("making sure of uniqueness of name: %s", filename);
            filename = findUniqueFilename(filename);
            unfinishedUploads.add(filename);
        }
        if (!api.validateLogin()) {
            // Need to revalidate!
            if (app.revalidateAuthToken()) {
                Timber.d("Successfully revalidated token!");
            } else {
                Timber.d("Unable to revalidate :(");
                // TODO: Put up a new notification, ask them to re-login
                stopForeground(true);
                Toast failureToast = Toast.makeText(this, R.string.authentication_failed, Toast.LENGTH_LONG);
                failureToast.show();
                return;
            }
        }
        NotificationUpdateProgressListener notificationUpdater = new NotificationUpdateProgressListener(notificationTag, getString(R.string.upload_progress_notification_title_in_progress, contribution.getDisplayTitle()), getString(R.string.upload_progress_notification_title_finishing, contribution.getDisplayTitle()), contribution);
        result = api.upload(filename, file, contribution.getDataLength(), contribution.getPageContents(), contribution.getEditSummary(), notificationUpdater);
        Timber.d("Response is %s", Utils.getStringFromDOM(result.getDocument()));
        curProgressNotification = null;
        String resultStatus = result.getString("/api/upload/@result");
        if (!resultStatus.equals("Success")) {
            String errorCode = result.getString("/api/error/@code");
            showFailedNotification(contribution);
            EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT).param("username", app.getCurrentAccount().name).param("source", contribution.getSource()).param("multiple", contribution.getMultiple()).param("result", errorCode).param("filename", contribution.getFilename()).log();
        } else {
            Date dateUploaded = null;
            dateUploaded = Utils.parseMWDate(result.getString("/api/upload/imageinfo/@timestamp"));
            // Title vs Filename
            String canonicalFilename = "File:" + result.getString("/api/upload/@filename").replace("_", " ");
            String imageUrl = result.getString("/api/upload/imageinfo/@url");
            contribution.setFilename(canonicalFilename);
            contribution.setImageUrl(imageUrl);
            contribution.setState(Contribution.STATE_COMPLETED);
            contribution.setDateUploaded(dateUploaded);
            contribution.save();
            EventLog.schema(CommonsApplication.EVENT_UPLOAD_ATTEMPT).param("username", app.getCurrentAccount().name).param("source", //FIXME
            contribution.getSource()).param("filename", contribution.getFilename()).param("multiple", contribution.getMultiple()).param("result", "success").log();
        }
    } catch (IOException e) {
        Timber.d("I have a network fuckup");
        showFailedNotification(contribution);
        return;
    } finally {
        if (filename != null) {
            unfinishedUploads.remove(filename);
        }
        toUpload--;
        if (toUpload == 0) {
            // Sync modifications right after all uplaods are processed
            ContentResolver.requestSync((CommonsApplication.getInstance()).getCurrentAccount(), ModificationsContentProvider.AUTHORITY, new Bundle());
            stopForeground(true);
        }
    }
}
Also used : InputStream(java.io.InputStream) Bundle(android.os.Bundle) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) IOException(java.io.IOException) Date(java.util.Date) ApiResult(org.mediawiki.api.ApiResult) Toast(android.widget.Toast) NotificationCompat(android.support.v4.app.NotificationCompat)

Example 69 with Toast

use of android.widget.Toast in project android_frameworks_base by DirtyUnicorns.

the class MediaRouteButton method performLongClick.

@Override
public boolean performLongClick() {
    if (super.performLongClick()) {
        return true;
    }
    if (!mCheatSheetEnabled) {
        return false;
    }
    final CharSequence contentDesc = getContentDescription();
    if (TextUtils.isEmpty(contentDesc)) {
        // Don't show the cheat sheet if we have no description
        return false;
    }
    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);
    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int midy = screenPos[1] + height / 2;
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
    Toast cheatSheet = Toast.makeText(context, contentDesc, Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | Gravity.END, screenWidth - screenPos[0] - width / 2, height);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
    performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    return true;
}
Also used : Context(android.content.Context) Rect(android.graphics.Rect) Toast(android.widget.Toast)

Example 70 with Toast

use of android.widget.Toast in project NetGuard by M66B.

the class ActivityMain method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    Log.i(TAG, "onActivityResult request=" + requestCode + " result=" + requestCode + " ok=" + (resultCode == RESULT_OK));
    Util.logExtras(data);
    if (requestCode == REQUEST_VPN) {
        // Handle VPN approval
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        prefs.edit().putBoolean("enabled", resultCode == RESULT_OK).apply();
        if (resultCode == RESULT_OK) {
            ServiceSinkhole.start("prepared", this);
            Toast on = Toast.makeText(ActivityMain.this, R.string.msg_on, Toast.LENGTH_LONG);
            on.setGravity(Gravity.CENTER, 0, 0);
            on.show();
            checkDoze();
        } else if (resultCode == RESULT_CANCELED)
            Toast.makeText(this, R.string.msg_vpn_cancelled, Toast.LENGTH_LONG).show();
    } else if (requestCode == REQUEST_INVITE) {
    // Do nothing
    } else if (requestCode == REQUEST_LOGCAT) {
        // Send logcat by e-mail
        if (resultCode == RESULT_OK) {
            Uri target = data.getData();
            if (data.hasExtra("org.openintents.extra.DIR_PATH"))
                target = Uri.parse(target + "/logcat.txt");
            Log.i(TAG, "Export URI=" + target);
            Util.sendLogcat(target, this);
        }
    } else {
        Log.w(TAG, "Unknown activity result request=" + requestCode);
        super.onActivityResult(requestCode, resultCode, data);
    }
}
Also used : Toast(android.widget.Toast) SharedPreferences(android.content.SharedPreferences) Uri(android.net.Uri)

Aggregations

Toast (android.widget.Toast)485 Context (android.content.Context)89 View (android.view.View)86 TextView (android.widget.TextView)74 Intent (android.content.Intent)55 Rect (android.graphics.Rect)34 LayoutInflater (android.view.LayoutInflater)31 SuppressLint (android.annotation.SuppressLint)30 JSONObject (org.json.JSONObject)23 ImageView (android.widget.ImageView)21 RequestQueue (com.android.volley.RequestQueue)20 Response (com.android.volley.Response)20 EditText (android.widget.EditText)19 JSONException (org.json.JSONException)18 VolleyError (com.android.volley.VolleyError)17 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)17 User (model.User)16 PendingIntent (android.app.PendingIntent)15 File (java.io.File)15 HashMap (java.util.HashMap)15