Example usage for android.widget Toast setGravity

List of usage examples for android.widget Toast setGravity

Introduction

In this page you can find the example usage for android.widget Toast setGravity.

Prototype

public void setGravity(int gravity, int xOffset, int yOffset) 

Source Link

Document

Set the location at which the notification should appear on the screen.

Usage

From source file:com.nbplus.vbroadlauncher.HomeLauncherActivity.java

public void handleMessage(Message msg) {
    if (msg == null) {
        return;//from www.  ja v  a 2 s .c  o  m
    }
    switch (msg.what) {
    case HANDLER_MESSAGE_LAUNCHER_ACTIVITY_RUNNING:
        Long runningTime = (Long) msg.obj;

        if (runningTime > this.mActivityRunningTime) {
            Log.d(TAG, "HANDLER_MESSAGE_LAUNCHER_ACTIVITY_RUNNING. new activity is create.. finish");
            finish();
        }
        break;
    case HANDLER_ERMERGENCY_CALL_DEVICE_ACTIVATED: {
        // BT device   2 ? broadcast ? sleep  .
        //                if (mLastDeviceEmergencyCallSent > 0) {
        //                    long currTimeMs = System.currentTimeMillis();
        //                    if (currTimeMs - mLastDeviceEmergencyCallSent  < 120 * 1000) {
        //                        Log.d(TAG, "Already emergency call sent = " + mLastDeviceEmergencyCallSent);
        //                        return;
        //                    }
        //                }
        if (mIsSendingEmergencyCall) {
            Log.d(TAG, "Emergency call send task already running... ");
            return;
        }
        BaseServerApiAsyncTask task;
        VBroadcastServer serverData = LauncherSettings.getInstance(this).getServerInformation();

        try {
            task = SendEmergencyCallTask.class.newInstance();
            if (task != null) {
                showProgressDialog();
                task.setBroadcastApiData(this, mHandler,
                        serverData.getApiServer() + getString(R.string.shortcut_addr_call_emergency));
                task.execute();
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (java.lang.InstantiationException e) {
            e.printStackTrace();
        }
        break;
    }

    case Constants.HANDLER_MESSAGE_SEND_EMERGENCY_CALL_COMPLETE_TASK: {
        mIsSendingEmergencyCall = false;
        mLastDeviceEmergencyCallSent = System.currentTimeMillis();

        BaseApiResult result = (BaseApiResult) msg.obj;
        Toast toast;
        dismissProgressDialog();
        if (result != null) {
            Log.d(TAG, ">> EMERGENCY CALL result code = " + result.getResultCode() + ", message = "
                    + result.getResultMessage());
            if (Constants.RESULT_OK.equals(result.getResultCode())) {
                toast = Toast.makeText(this, R.string.emergency_call_success_message, Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();

            } else {
                toast = Toast.makeText(this, result.getResultMessage(), Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            }
        } else {
            toast = Toast.makeText(this, R.string.emergency_call_fail_message, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
        break;
    }
    }
}

From source file:com.edible.ocr.CaptureActivity.java

/** Displays a pop-up message showing the name of the current OCR source language. */
void showLanguageName() {
    Toast toast = Toast.makeText(this, "OCR: " + sourceLanguageReadable, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.TOP, 0, 0);
    toast.show();/*from  w  ww . j a  v a2  s  .  c o m*/
}

From source file:com.easemob.ui.ChatActivity.java

/**
 * ?uri??//ww w  .  j  a v  a 2 s.  c o  m
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    // String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getContentResolver().query(selectedImage, null, null, null, null);
    cursor.moveToFirst();
    int columnIndex = cursor.getColumnIndex("_data");
    String picturePath = cursor.getString(columnIndex);
    cursor.close();
    if (picturePath == null || picturePath.equals("null")) {
        Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
        return;
    }
    sendPicture(picturePath);
}

From source file:com.edible.ocr.CaptureActivity.java

/** Called when the shutter button is pressed in continuous mode. */
void onShutterButtonPressContinuous() {
    isPaused = true;//from ww  w. ja  v a2  s  .  co m
    handler.stop();
    beepManager.playBeepSoundAndVibrate();
    if (lastResult != null) {
        handleOcrDecode(lastResult);
    } else {
        Toast toast = Toast.makeText(this, "OCR failed. Please try again.", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.TOP, 0, 0);
        toast.show();
        resumeContinuousDecoding();
    }
}

From source file:com.edible.ocr.CaptureActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    switch (item.getItemId()) {

    case OPTIONS_COPY_RECOGNIZED_TEXT_ID:
        clipboardManager.setText(ocrResultView.getText());
        if (clipboardManager.hasText()) {
            Toast toast = Toast.makeText(this, "Text copied.", Toast.LENGTH_LONG);
            toast.setGravity(Gravity.BOTTOM, 0, 0);
            toast.show();/*  w  w  w .  j a v a2s  .c  o m*/
        }
        return true;
    case OPTIONS_SHARE_RECOGNIZED_TEXT_ID:
        Intent shareRecognizedTextIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareRecognizedTextIntent.setType("text/plain");
        shareRecognizedTextIntent.putExtra(android.content.Intent.EXTRA_TEXT, ocrResultView.getText());
        startActivity(Intent.createChooser(shareRecognizedTextIntent, "Share via"));
        return true;
    case OPTIONS_COPY_TRANSLATED_TEXT_ID:
        clipboardManager.setText(translationView.getText());
        if (clipboardManager.hasText()) {
            Toast toast = Toast.makeText(this, "Text copied.", Toast.LENGTH_LONG);
            toast.setGravity(Gravity.BOTTOM, 0, 0);
            toast.show();
        }
        return true;
    case OPTIONS_SHARE_TRANSLATED_TEXT_ID:
        Intent shareTranslatedTextIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareTranslatedTextIntent.setType("text/plain");
        shareTranslatedTextIntent.putExtra(android.content.Intent.EXTRA_TEXT, translationView.getText());
        startActivity(Intent.createChooser(shareTranslatedTextIntent, "Share via"));
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:org.xingjitong.InCallActivity.java

private void toastdsp(String str) {

    LayoutInflater inflater = getLayoutInflater();
    //LayoutInflater inflater = LayoutInflater.from(getContext());
    View layout = inflater.inflate(R.layout.customtoast, (ViewGroup) findViewById(R.id.llcustomtoast));

    //ImageView image = (ImageView) layout.findViewById(R.id.customtoast_img);
    //image.setImageResource(R.drawable.status_green); //yypp

    TextView text = (TextView) layout.findViewById(R.id.customtoast_text);
    text.setText(str);/*from w  ww  . ja v a 2  s  .  c  om*/
    Toast toast = new Toast(getApplicationContext());
    //Toast toast = new Toast(getContext());
    toast.setGravity(Gravity.CENTER, 0, 60);
    //toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();

}

From source file:com.xxjwd.chat.ChatActivity.java

 /**
 * ?uri??//  ww w . j  a va2  s .c  o  m
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
   // String[] filePathColumn = { MediaStore.Images.Media.DATA };
   Cursor cursor = getContentResolver().query(selectedImage, null, null, null, null);
   if (cursor != null) {
      cursor.moveToFirst();
      int columnIndex = cursor.getColumnIndex("_data");
      String picturePath = cursor.getString(columnIndex);
      cursor.close();
      cursor = null;

      if (picturePath == null || picturePath.equals("null")) {
         Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT);
         toast.setGravity(Gravity.CENTER, 0, 0);
         toast.show();
         return;
      }
      sendPicture(picturePath);
   } else {
      File file = new File(selectedImage.getPath());
      if (!file.exists()) {
         Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT);
         toast.setGravity(Gravity.CENTER, 0, 0);
         toast.show();
         return;

      }
      sendPicture(file.getAbsolutePath());
   }

}

From source file:com.edible.ocr.CaptureActivity.java

/**
 * Displays information relating to the result of OCR, and requests a translation if necessary.
 * /*from   w w w  .java2 s  . c o  m*/
 * @param ocrResult Object representing successful OCR results
 * @return True if a non-null result was received for OCR
 */
boolean handleOcrDecode(OcrResult ocrResult) {
    lastResult = ocrResult;

    // Test whether the result is null
    if (ocrResult.getText() == null || ocrResult.getText().equals("")) {
        Toast toast = Toast.makeText(this, "OCR failed. Please try again.", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.TOP, 0, 0);
        toast.show();
        return false;
    }

    // Turn off capture-related UI elements
    shutterButton.setVisibility(View.GONE);
    statusViewBottom.setVisibility(View.GONE);
    statusViewTop.setVisibility(View.GONE);
    cameraButtonView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView bitmapImageView = (ImageView) findViewById(R.id.image_view);
    lastBitmap = ocrResult.getBitmap();
    if (lastBitmap == null) {
        bitmapImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
    } else {
        bitmapImageView.setImageBitmap(lastBitmap);
    }

    // Display the recognized text
    TextView sourceLanguageTextView = (TextView) findViewById(R.id.source_language_text_view);
    sourceLanguageTextView.setText(sourceLanguageReadable);
    TextView ocrResultTextView = (TextView) findViewById(R.id.ocr_result_text_view);
    ocrResultTextView.setText(stripNoise(ocrResult.getText()));
    // Crudely scale betweeen 22 and 32 -- bigger font for shorter text
    int scaledSize = Math.max(22, 32 - ocrResult.getText().length() / 4);
    ocrResultTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView translationLanguageLabelTextView = (TextView) findViewById(
            R.id.translation_language_label_text_view);
    TextView translationLanguageTextView = (TextView) findViewById(R.id.translation_language_text_view);
    TextView translationTextView = (TextView) findViewById(R.id.translation_text_view);
    if (isTranslationActive) {
        // Handle translation text fields
        translationLanguageLabelTextView.setVisibility(View.VISIBLE);
        translationLanguageTextView.setText(targetLanguageReadable);
        translationLanguageTextView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL), Typeface.NORMAL);
        translationLanguageTextView.setVisibility(View.VISIBLE);

        // Activate/re-activate the indeterminate progress indicator
        translationTextView.setVisibility(View.GONE);
        progressView.setVisibility(View.VISIBLE);
        setProgressBarVisibility(true);

        // Get the translation asynchronously
        new TranslateAsyncTask(this, sourceLanguageCodeTranslation, targetLanguageCodeTranslation,
                stripNoise(ocrResult.getText())).execute();
    } else {
        translationLanguageLabelTextView.setVisibility(View.GONE);
        translationLanguageTextView.setVisibility(View.GONE);
        translationTextView.setVisibility(View.GONE);
        progressView.setVisibility(View.GONE);
        setProgressBarVisibility(false);
    }
    return true;
}

From source file:doext.easemob.activity.ChatActivity.java

/**
 * ?uri??/*ww  w.  ja v  a  2s  .  c om*/
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    // String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getContentResolver().query(selectedImage, null, null, null, null);
    String st8 = getResources()
            .getString(DoResourcesHelper.getIdentifier("cant_find_pictures", "string", this));
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex("_data");
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(this, st8, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
        }
        sendPicture(picturePath);
    } else {
        File file = new File(selectedImage.getPath());
        if (!file.exists()) {
            Toast toast = Toast.makeText(this, st8, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;

        }
        sendPicture(file.getAbsolutePath());
    }

}

From source file:com.givon.anhao.activity.ChatActivity.java

/**
 * ?uri??/*  w  w  w . j a v a2  s.  co  m*/
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    addFriend(mUserBean, chatType);
    // String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getContentResolver().query(selectedImage, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex("_data");
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
        }
        sendPicture(picturePath);
    } else {
        File file = new File(selectedImage.getPath());
        if (!file.exists()) {
            Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;

        }
        sendPicture(file.getAbsolutePath());
    }

}