android.widget.Toast#show ( )源码实例Demo

下面列出了android.widget.Toast#show ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: secureit   文件: UploadService.java
/**
* Called on service creation, sends a notification
*/
  @Override
  public void onCreate() {
      manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
      prefs = new SecureItPreferences(this);
      
try {
	new BluetoothServerTask(this).start();
} catch (NoBluetoothException e) {
	Log.i("UploadService", "Background bluetooth server not started");
	CharSequence text = "Background bluetooth server not started";
	int duration = Toast.LENGTH_SHORT;
	Toast toast = Toast.makeText(this, text, duration);
	toast.show();
}
      
      showNotification();
  }
 
源代码2 项目: Twire   文件: StreamFragment.java
private void playWithExternalPlayer() {
    Toast errorToast = Toast.makeText(getContext(), R.string.error_external_playback_failed, Toast.LENGTH_LONG);
    if (qualityURLs == null) {
        errorToast.show();
        return;
    }

    String castQuality = getBestCastQuality(qualityURLs, settings.getPrefStreamQuality(), 0);
    if (castQuality == null) {
        errorToast.show();
        return;
    }

    updateSelectedQuality(castQuality);
    String url = qualityURLs.get(castQuality).URL;

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse(url), "video/*");
    startActivity(Intent.createChooser(intent, getString(R.string.stream_external_play_using)));
}
 
/**
 * The file save has completed.  We can resume recording.
 */
private void fileSaveComplete(int status) {
    Log.d(TAG, "fileSaveComplete " + status);
    if (!mFileSaveInProgress) {
        throw new RuntimeException("WEIRD: got fileSaveCmplete when not in progress");
    }
    mFileSaveInProgress = false;
    updateControls();
    TextView tv = (TextView) findViewById(R.id.recording_text);
    String str = getString(R.string.nowRecording);
    tv.setText(str);

    if (status == 0) {
        str = getString(R.string.recordingSucceeded);
    } else {
        str = getString(R.string.recordingFailed, status);
    }
    Toast toast = Toast.makeText(this, str, Toast.LENGTH_SHORT);
    toast.show();
}
 
源代码4 项目: StreamHub-Android-SDK   文件: BaseActivity.java
/**
 * Custom toast as per requirement
 */
protected void customToast() {
    LayoutInflater li = getLayoutInflater();
    View layout = li.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.custom_toast_layout));
    Toast toast = new Toast(getApplicationContext());
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setView(layout);
    toast.show();
}
 
源代码5 项目: BaseRecyclerViewAdapterHelper   文件: Tips.java
/**
 * 显示 Toast
 * @param message 提示信息
 * @param duration 显示时间长短
 */
public static void show(String message, int duration) {
    Toast toast = new Toast(Utils.getContext());
    toast.setDuration(duration);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setView(createTextToastView(message));
    toast.show();
}
 
源代码6 项目: Focus   文件: DatabaseHelper.java
public boolean execSQL(String sql) {
    try {
        db.execSQL(sql);
    } catch (SQLException e) {
        Toast toast = Toast.makeText(_context,
                "android.database.sqlite.SQLiteException",
                Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
        Log.i("sqlerr_log------->", e.toString());
        Log.i("err_sql------->", sql);
        return false;
    }
    return true;
}
 
源代码7 项目: test-samples   文件: Helpers.java
public static void toastDefault(Context context, String text, int duration) {

        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = layoutInflater.inflate(R.layout.toast_default, null);

        TextView textView = (TextView) view.findViewById(R.id.toast_default_text);
        textView.setText(text);

        Toast toast = new Toast(context);
        // toast.setGravity(Gravity.TOP, 0, 250);
        toast.setDuration(duration);
        toast.setView(view);
        toast.show();
    }
 
源代码8 项目: ONE-Unofficial   文件: TextToast.java
public static void shortShow(String content){
    if (context==null){
        throw new IllegalStateException("TextToast was not initialized");
    }
    Toast toast= Toast.makeText(context, content, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
}
 
源代码9 项目: mobile-manager-tool   文件: ApolloUtils.java
/**
 * @param message
 */
public static void showToast(int message, Toast mToast, Context context) {
    if (mToast == null) {
        mToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
    }
    mToast.setText(context.getString(message));
    mToast.show();
}
 
/**
 * Helper method that displays a TOAST message. Default is TOAST.LENGTH_LONG.
 * @param message The message you wish to be displayed in TOAST.
 * @param toastLength (Optional) valid options are Toast.LENGTH_LONG or Toast.LENGTH_SHORT.
 */
public void displayToast(String message,int... toastLength) {
	int length = Toast.LENGTH_LONG;
	if(toastLength.length != 0){
		length = toastLength[0];
	}
	Toast toast = Toast.makeText(_context,
			message,
			length);
	toast.show();
}
 
源代码11 项目: Trivia-Knowledge   文件: MainGameActivity.java
@Override
public void onUnityAdsFinish(String s, UnityAds.FinishState finishState) {
    //Called when a video vinishes playing
    //you get a reward

    //   final Typeface typeface2 = Typeface.createFromAsset(this.getAssets(), "fonts/OpenSans-Semibold.ttf");
    Toast toast = Toast.makeText(getApplication(), "+1 gem added in your bucket.", Toast.LENGTH_LONG);
    toast.getView().setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.darkpink));
    TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
    v.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));
    v.setTypeface(openSansSemiBold);
    v.setTextSize(10);
    toast.show();

}
 
源代码12 项目: Puff-Android   文件: CheatSheet.java
/**
 * Internal helper method to show the cheat sheet toast.
 */
private static boolean showCheatSheet(View view, CharSequence text) {
    if (TextUtils.isEmpty(text)) {
        return false;
    }

    final int[] screenPos = new int[2]; // origin is device display
    final Rect displayFrame = new Rect(); // includes decorations (e.g. status bar)
    view.getLocationOnScreen(screenPos);
    view.getWindowVisibleDisplayFrame(displayFrame);

    final Context context = view.getContext();
    final int viewWidth = view.getWidth();
    final int viewHeight = view.getHeight();
    final int viewCenterX = screenPos[0] + viewWidth / 2;
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
    final int estimatedToastHeight = (int) (ESTIMATED_TOAST_HEIGHT_DIPS
            * context.getResources().getDisplayMetrics().density);

    Toast cheatSheet = Toast.makeText(context, text, Toast.LENGTH_SHORT);
    boolean showBelow = screenPos[1] < estimatedToastHeight;
    if (showBelow) {
        // Show below
        // Offsets are after decorations (e.g. status bar) are factored in
        cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL,
                viewCenterX - screenWidth / 2,
                screenPos[1] - displayFrame.top + viewHeight);
    } else {
        // Show above
        // Offsets are after decorations (e.g. status bar) are factored in
        // NOTE: We can't use Gravity.BOTTOM because when the keyboard is up
        // its height isn't factored in.
        cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL,
                viewCenterX - screenWidth / 2,
                screenPos[1] - displayFrame.top - estimatedToastHeight);
    }

    cheatSheet.show();
    return true;
}
 
源代码13 项目: RemoteLogger   文件: MainActivity.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean result;
    int id = item.getItemId();

    switch(id) {
        case R.id.menu_opt_log_startstop:
            if (!RemoteLogger.toggleLogging(this)) {
                RemoteLogger.launchSendLogWithAttachment(this);
                item.setTitle("Start logging");
            } else {
                item.setTitle("Stop logging");
            }
            result = true;
            break;
        case R.id.menu_opt_deletelog:
            RemoteLogger.deleteLog(this);
            Toast toast = Toast.makeText(this, "Log file deleted.", Toast.LENGTH_SHORT);
            toast.show();
            result = true;
            break;
        default:
            result = super.onOptionsItemSelected(item);

    }
    return result;
}
 
源代码14 项目: iBeebo   文件: CheatSheet.java
/**
 * Internal helper method to show the cheat sheet toast.
 */
private static boolean showCheatSheet(Activity activity, View view, CharSequence text) {
    if (TextUtils.isEmpty(text)) {
        return false;
    }

    final int[] screenPos = new int[2]; // origin is device display
    final Rect displayFrame = new Rect(); // includes decorations (e.g.
    // status bar)
    view.getLocationOnScreen(screenPos);
    view.getWindowVisibleDisplayFrame(displayFrame);

    final Context context = view.getContext();
    final int viewWidth = view.getWidth();
    final int viewHeight = view.getHeight();
    final int viewCenterX = screenPos[0] + viewWidth / 2;
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
    final int estimatedToastHeight = (int) (ESTIMATED_TOAST_HEIGHT_DIPS * context.getResources().getDisplayMetrics().density);

    Toast cheatSheet = Toast.makeText(context, text, Toast.LENGTH_SHORT);
    boolean showBelow = screenPos[1] < estimatedToastHeight;
    if (showBelow) {
        // Show below
        // Offsets are after decorations (e.g. status bar) are factored in
        cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1]
                - displayFrame.top + viewHeight);
    } else {
        // Show above
        // Offsets are after decorations (e.g. status bar) are factored in

        // softkeyboard height
        int height = SmileyPickerUtility.getScreenHeight(activity) - SmileyPickerUtility.getStatusBarHeight(activity)
                - SmileyPickerUtility.getAppHeight(activity);

        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2,
                displayFrame.bottom - screenPos[1] + height);
    }

    cheatSheet.show();
    return true;
}
 
@Override
public void networkContextDidConnect( LFXNetworkContext networkContext)
{
	Toast toast = Toast.makeText( this, "CONNECTED", Toast.LENGTH_SHORT);
	toast.show();
}
 
源代码16 项目: sniffer154   文件: PcapExporter.java
private void toastMessage(String mess) {
	Toast toast = Toast.makeText(getApplicationContext(), mess, Toast.LENGTH_LONG);
	toast.show();
}
 
源代码17 项目: app-indexing   文件: RecipeActivity.java
private void showRecipe(Uri recipeUri) {
    Log.d("Recipe Uri", recipeUri.toString());

    String[] projection = {RecipeTable.ID, RecipeTable.TITLE,
            RecipeTable.DESCRIPTION, RecipeTable.PHOTO,
            RecipeTable.PREP_TIME};
    Cursor cursor = getContentResolver().query(recipeUri, projection, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {

        mRecipe = Recipe.fromCursor(cursor);

        Uri ingredientsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("ingredients").appendPath(mRecipe.getId()).build();
        Cursor ingredientsCursor = getContentResolver().query(ingredientsUri, projection,
                null, null, null);
        if (ingredientsCursor != null && ingredientsCursor.moveToFirst()) {
            do {
                Recipe.Ingredient ingredient = new Recipe.Ingredient();
                ingredient.setAmount(ingredientsCursor.getString(0));
                ingredient.setDescription(ingredientsCursor.getString(1));
                mRecipe.addIngredient(ingredient);
                ingredientsCursor.moveToNext();
            } while (!ingredientsCursor.isAfterLast());
            ingredientsCursor.close();
        }

        Uri instructionsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath
                ("instructions").appendPath(mRecipe.getId()).build();
        Cursor instructionsCursor = getContentResolver().query(instructionsUri, projection,
                null, null, null);
        if (instructionsCursor != null && instructionsCursor.moveToFirst()) {
            do {
                Recipe.Step step = new Recipe.Step();
                step.setDescription(instructionsCursor.getString(1));
                step.setPhoto(instructionsCursor.getString(2));
                mRecipe.addStep(step);
                instructionsCursor.moveToNext();
            } while (!instructionsCursor.isAfterLast());
            instructionsCursor.close();
        }

        Uri noteUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath("notes")
                .appendPath(mRecipe.getId()).build();
        Cursor noteCursor = getContentResolver().query(noteUri, projection, null, null, null);
        if (noteCursor != null && noteCursor.moveToFirst()) {
            Note note = Note.fromCursor(noteCursor);
            mRecipe.setNote(note);
            noteCursor.close();
        }

        // always close the cursor
        cursor.close();
    } else {
        Toast toast = Toast.makeText(getApplicationContext(),
                "No match for deep link " + recipeUri.toString(),
                Toast.LENGTH_SHORT);
        toast.show();
    }

    if (mRecipe != null) {
        // Create the adapter that will return a fragment for each of the steps of the recipe.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        // Set the recipe title
        TextView recipeTitle = (TextView) findViewById(R.id.recipeTitle);
        recipeTitle.setText(mRecipe.getTitle());

        // Set the recipe prep time
        TextView recipeTime = (TextView) findViewById(R.id.recipeTime);
        recipeTime.setText("  " + mRecipe.getPrepTime());

        //Set the note button toggle
        ToggleButton addNoteToggle = (ToggleButton) findViewById(R.id.addNoteToggle);
        addNoteToggle.setChecked(mRecipe.getNote() != null);
        addNoteToggle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mRecipe.getNote() != null) {
                    displayNoteDialog(getString(R.string.dialog_update_note), getString(R
                            .string.dialog_delete_note));
                } else {
                    displayNoteDialog(getString(R.string.dialog_add_note), getString(R.string
                            .dialog_cancel_note));
                }
            }
        });
    }
}
 
@Override
public void networkContextDidConnect( LFXNetworkContext networkContext)
{
	Toast toast = Toast.makeText( this, "CONNECTED", Toast.LENGTH_SHORT);
	toast.show();
}
 
源代码19 项目: dropbox-sdk-java   文件: OpenWithActivity.java
private void showToast(String msg) {
    Toast error = Toast.makeText(this, msg, Toast.LENGTH_LONG);
    error.show();
}
 
源代码20 项目: CourierApplication   文件: NewOrderFragment.java
public void makeToast(String message) {
    Toast toast = Toast.makeText(getContext(),
            message, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
}