public void onCallStateChanged(int state, String incomingNumber) { Log.i(Constants.AppNameForLogging, "onCallStateChanged" + incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_IDLE: if (toast != null) toast.cancel(); break; case TelephonyManager.CALL_STATE_OFFHOOK: if (toast != null) toast.cancel(); break; case TelephonyManager.CALL_STATE_RINGING: if (RegexCaller.number != null) { Pattern r = Pattern.compile(RegexCaller.number); Matcher m = r.matcher(incomingNumber); if (m.find()) { String msg = RegexCaller.name + " is calling"; toast = Toast.makeText(activityContext, msg, Toast.LENGTH_LONG); toast.show(); /* try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } activityContext.startActivity(i1);*/ } } break; } }
/** * This function loads all the songs corresponding to the artist selected by the user. * * <p>If there are no songs for that artist, or there is an error retrieving them, the function * returns in between without loading any album names. */ private void loadFileSystem() { ContentResolver contentResolver = this.getContentResolver(); Uri uri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0 AND " + MediaStore.Audio.Media.ARTIST + " LIKE ?"; String[] projection = { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST }; String[] arguments = {artistName}; Log.d("SingleArtistListing", "The uri is " + uri.getEncodedPath()); Cursor cursor = contentResolver.query(uri, projection, selection, arguments, MediaStore.Audio.Media.TITLE); // if there is an error reading the songs on the SD card of the phone if (cursor == null) { Log.d( "SingleArtistListing", "There was an error reading music files from the music library."); messageToast.cancel(); messageToast = Toast.makeText( activity, "There was an error reading music files from the music library", Toast.LENGTH_SHORT); messageToast.show(); return; } // if there are no songs present in the music library of the SD card of the phone memory. else if (cursor.getCount() == 0) { Log.d("SingleArtistListing", "There are no music files present in the library!"); messageToast.cancel(); messageToast = Toast.makeText(activity, "There are no songs for this artist", Toast.LENGTH_SHORT); messageToast.show(); return; } // songs are present in the music library on the SD card of the phone memory. else { Log.d("SingleArtistListing", "Songs present for the artist"); artistSongNamesAdapter = new ArrayAdapter<String>( this.getApplicationContext(), R.layout.album_name_view, R.id.albumName, songNames); if (artistSongNamesAdapter == null) { Log.d("songListing", "Artist List data is null"); messageToast.cancel(); messageToast = Toast.makeText( activity, "Error reading music files from the music library!", Toast.LENGTH_SHORT); messageToast.show(); return; } while (cursor.moveToNext()) { artistSongNamesAdapter.add(cursor.getString(1)); } this.artistSongs.setAdapter(artistSongNamesAdapter); } }
@Override protected void onPause() { super.onPause(); if (debug) Log.d(TAG, "onPause()"); if (blankPasswordToast != null) blankPasswordToast.cancel(); if (invalidPasswordToast != null) invalidPasswordToast.cancel(); if (confirmPasswordFailToast != null) confirmPasswordFailToast.cancel(); if (dbHelper != null) { dbHelper.close(); dbHelper = null; } }
private void showToast(String msg) { if (mToast != null) { mToast.cancel(); } mToast = Toast.makeText(this, msg, Toast.LENGTH_SHORT); mToast.show(); }
public void showToast(String message, int length) { if (progressCurrentState != null) progressCurrentState.cancel(); if (toastCurrentState != null) toastCurrentState.cancel(); toastCurrentState = Toast.makeText(myCurrentActivity, message, length); toastCurrentState.show(); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { Uri uri = data.getData(); if (uri != null) { Cursor c = null; try { c = getContentResolver().query(uri, new String[] {BaseColumns._ID}, null, null, null); if (c != null && c.moveToFirst()) { int id = c.getInt(0); if (mToast != null) { mToast.cancel(); } String txt = mPendingResult.mMsg + ":\n" + uri + "\nid: " + id; mToast = Toast.makeText(this, txt, Toast.LENGTH_LONG); mToast.show(); } } finally { if (c != null) { c.close(); } } } } }
/** * Long toast message TOAST_DURATION_MILLS controls the duration currently set to 6 seconds * * @param context Application Context * @param msg Message to send */ public static void msgLong(final Context context, final String msg) { if (context != null && msg != null) { if (toast != null) { toast.cancel(); } new Handler(context.getMainLooper()) .post( new Runnable() { @SuppressLint("ShowToast") @Override public void run() { toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT); new CountDownTimer( Math.max(TOAST_DURATION_MILLS - SHORT_TOAST_DURATION, 1000), 1000) { @Override public void onFinish() { toast.show(); } @Override public void onTick(long millisUntilFinished) { toast.show(); } }.start(); } }); } }
/** Ends the effect and then executes the runnable after the effect is finished. */ public void end(final Runnable runnableOnODone) { // Cancel the tooltip if it's still showing. if ((tooltip != null) && (tooltip.getView().getParent() != null)) { tooltip.cancel(); tooltip = null; } // End tool editing by canceling unfinished touch events. toolKit.cancel(); // Output the pushed filter if it wasn't outputted. if (pushedFilter && disableFilterOutput) { outputFilter(); } // Wait till last output callback is done before finishing. if ((lastFilterChangedCallback == null) || lastFilterChangedCallback.done) { finish(runnableOnODone); } else { lastFilterChangedCallback.runnableOnReady = new Runnable() { @Override public void run() { finish(runnableOnODone); } }; } }
private void update() { Log.d(TAG, "Update"); // mAdapter.initData(); mAdapter.notifyDataSetChanged(); toast.cancel(); // progressDialog.dismiss(); Log.d(TAG, "Update Completed"); }
public void onButtonsClick(View view) { int id = view.getId(); String strToast = ""; switch (id) { case R.id.btSpotStreamer: strToast = "Launch Spotify Streamer app"; break; case R.id.btScores: strToast = "Launch Scores app"; break; case R.id.btLibrary: strToast = "Launch Library app"; break; case R.id.btBuildBigger: strToast = "Launch Build it Bigger app"; break; case R.id.btXYZReader: strToast = "Launch XYZ Reader app"; break; case R.id.btCapstone: strToast = "Launch Capstone Project app"; break; } if (mToast != null) mToast.cancel(); mToast = Toast.makeText(this, strToast, Toast.LENGTH_SHORT); mToast.show(); }
@Override public void run() { isOnKeyBacking = false; if (mBackToast != null) { mBackToast.cancel(); } }
private void disable() { if (activityToast != null) { activityToast.cancel(); } contextDisabled = true; }
@Override public void onPause(boolean multitasking) { if (mostRecentToast != null) { mostRecentToast.cancel(); getViewGroup().setOnTouchListener(null); } this.isPaused = true; }
/** * displayToast create Toast which correct text. * * @param appName app Name that will be show in Toast message */ public void displayToast(String appName) { // Add to cancel Toast if previous toast is still showing and I want to show next. if (toast != null) { toast.cancel(); } toast = Toast.makeText(this, toastMessage(appName), Toast.LENGTH_SHORT); toast.show(); }
private void sendMessage(final String message, final boolean error) { Toast toast = Toast.makeText(this, message, Toast.LENGTH_SHORT); if (lastToast != null) { lastToast.cancel(); } toast.show(); lastToast = toast; }
@Override public void handleMessage(Message msg) { if (lastToast != null) { lastToast.cancel(); } lastToast = Toast.makeText(Rokon.getActivity(), toastMessage, toastType); lastToast.show(); }
/** Hide the toast message if visible */ private void hideToast() { if (toast == null) { return; } toast.cancel(); }
// Log |msg| and Toast about it. private void logAndToast(String msg) { Log.d(TAG, msg); if (logToast != null) { logToast.cancel(); } logToast = Toast.makeText(this, msg, Toast.LENGTH_SHORT); logToast.show(); }
// This resets everything - reset button onClick public void reset(View view) { TextView score11 = (TextView) findViewById(R.id.game_points_player_1); TextView score21 = (TextView) findViewById(R.id.games_won_player_1); TextView score31 = (TextView) findViewById(R.id.set_points_player_1); TextView score41 = (TextView) findViewById(R.id.match_points_player_1); TextView score12 = (TextView) findViewById(R.id.game_points_player_2); TextView score22 = (TextView) findViewById(R.id.games_won_player_2); TextView score32 = (TextView) findViewById(R.id.set_points_player_2); TextView score42 = (TextView) findViewById(R.id.match_points_player_2); TextView tiebreaker1 = (TextView) findViewById(R.id.tiebreaker1); TextView tiebreaker2 = (TextView) findViewById(R.id.tiebreaker2); score11.setText(R.string.love_init); score21.setText(R.string.placeholder_number); score31.setText(R.string.placeholder_number); score41.setText(R.string.placeholder_number); score12.setText(R.string.love_init); score22.setText(R.string.placeholder_number); score32.setText(R.string.placeholder_number); score42.setText(R.string.placeholder_number); tiebreaker1.setText(""); tiebreaker2.setText(""); count1 = 0; count2 = 0; gamecount1 = 0; gamecount2 = 0; set1 = 0; set2 = 0; match1 = 0; match2 = 0; tie1 = 0; tie2 = 0; first_tie = 0; game1toast.cancel(); game2toast.cancel(); deuce.cancel(); advantage1.cancel(); advantage2.cancel(); set1toast.cancel(); set2toast.cancel(); match1toast.cancel(); match2toast.cancel(); tiebreakertoast.cancel(); }
@Override protected void onStop() { Log.e("SDL", "onStop()"); super.onStop(); if (player != null) player.onStop(); if (toastShot != null) toastShot.cancel(); }
@Override public void onPause() { super.onPause(); mGoogleApiClient.disconnect(); if (toast != null) { toast.cancel(); } }
/** * Shows a message to the user in the current activity * * @param message The message to display */ public void showMessage(String message) { // If there is a toast already, get rid of it if (toast != null) { toast.cancel(); } toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT); toast.show(); }
private void showToast(String string) { if (toast == null) { toast = Toast.makeText(this, string, Toast.LENGTH_SHORT); } else { toast.cancel(); toast = Toast.makeText(this, string, Toast.LENGTH_SHORT); } toast.show(); }
private void showToast(Button btn) { if (toast != null) { toast.cancel(); } String text = "Clicked: " + btn.getText(); toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); toast.show(); }
@Override public void showMessage(String text) { if (toast != null) { toast.cancel(); } toast = Toast.makeText(getContext(), text, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }
@Override protected void onProgressUpdate(String... progress) { if (toast != null) { toast.cancel(); } Timber.d(progress[0]); toast = Toast.makeText(activity, progress[0], Toast.LENGTH_SHORT); toast.show(); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Object itemAtPosition = parent.getItemAtPosition(position); if (previousToast != null) { previousToast.cancel(); } Toast toast = Toast.makeText(view.getContext(), itemAtPosition.toString(), Toast.LENGTH_SHORT); toast.show(); previousToast = toast; }
/* * 解决 Toast 重复显示问题 */ public static void toastShow(Context mContext, int resId) { String tipStr = mContext.getString(resId); if (netStateToast == null) { netStateToast = Toast.makeText(mContext, tipStr, Toast.LENGTH_SHORT); } else { netStateToast.cancel(); netStateToast.setText(tipStr); } netStateToast.show(); }
@Override public void handleMessage(Message msg) { if (mToast != null) { mToast.cancel(); } String text = (String) msg.obj; int duration = msg.arg2; Toast.makeText(ApplicationControl.getInstance(), text, duration).show(); }
private void exitByDoubleClick() { try { long cTime = System.currentTimeMillis(); if (cTime - lastBackClickTime > 2000) { if (toast != null) { toast.cancel(); } lastBackClickTime = cTime; (toast = Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT)).show(); } else { if (toast != null) { toast.cancel(); } exit(); } } catch (Exception e) { e.printStackTrace(); } }