android.support.design.widget.Snackbar Java Examples
The following examples show how to use
android.support.design.widget.Snackbar.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConnectActivity.java From homeassist with Apache License 2.0 | 6 votes |
private void showError(String message) { Drawable warningIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_warning_white_18dp, null); SpannableStringBuilder builder = new SpannableStringBuilder(); builder.append(message); mSnackbar = Snackbar.make(findViewById(android.R.id.content), builder, Snackbar.LENGTH_LONG) .setAction(getString(R.string.action_retry), new OnClickListener() { @Override public void onClick(View view) { attemptLogin(); } }); TextView textView = mSnackbar.getView().findViewById(android.support.design.R.id.snackbar_text); textView.setCompoundDrawablesWithIntrinsicBounds(warningIcon, null, null, null); textView.setCompoundDrawablePadding(getResources().getDimensionPixelOffset(R.dimen.icon_8dp)); mSnackbar.getView().setBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.md_red_A200, null)); mSnackbar.show(); }
Example #2
Source File: LoginActivity.java From Watch-Me-Build-a-Finance-Startup with MIT License | 6 votes |
private boolean mayRequestContacts() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return true; } if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) { return true; } if (shouldShowRequestPermissionRationale(READ_CONTACTS)) { Snackbar.make(mEmailView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE) .setAction(android.R.string.ok, new View.OnClickListener() { @Override @TargetApi(Build.VERSION_CODES.M) public void onClick(View v) { requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); } }); } else { requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); } return false; }
Example #3
Source File: SettingsActivity.java From good-weather with GNU General Public License v3.0 | 6 votes |
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { switch (key) { case Constants.KEY_PREF_WIDGET_THEME: Intent intent = new Intent(Constants.ACTION_APPWIDGET_THEME_CHANGED); getActivity().sendBroadcast(intent); break; case Constants.KEY_PREF_WIDGET_UPDATE_PERIOD: Intent intent1 = new Intent(Constants.ACTION_APPWIDGET_UPDATE_PERIOD_CHANGED); getActivity().sendBroadcast(intent1); setSummary(); break; case Constants.KEY_PREF_WIDGET_UPDATE_LOCATION: int fineLocationPermission = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION); if (fineLocationPermission != PackageManager.PERMISSION_GRANTED) { Snackbar.make(getActivity().findViewById(android.R.id.content), R.string.permission_location_need, Snackbar.LENGTH_SHORT).show(); CheckBoxPreference updateLocation = (CheckBoxPreference) findPreference(key); updateLocation.setChecked(false); } break; } }
Example #4
Source File: MapActivity.java From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void deleteNode() { final OSMNode deletedNode = osmMap.deleteNode(); Snackbar.make(findViewById(R.id.mapActivity), "Deleted Node", Snackbar.LENGTH_LONG) .setAction("UNDO", new View.OnClickListener() { // undo action @Override public void onClick(View v) { osmMap.addNode(deletedNode); } }) .setActionTextColor(Color.rgb(126,188,111)) .show(); }
Example #5
Source File: DeploymentsActivity.java From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void findDeployment(URL url) { String slug = findSlug(url.getPath()); int idx = Deployments.singleton().getIdxForName(slug); if (idx > -1) { Intent deploymentDetailsActivity = new Intent(this, DeploymentDetailsActivity.class); deploymentDetailsActivity.putExtra("POSITION", idx); startActivity(deploymentDetailsActivity); } else { Snackbar.make(findViewById(R.id.deploymentsActivity), "There is no deployment for the field paper: " + slug, Snackbar.LENGTH_LONG) .setAction("Retry", new View.OnClickListener() { // undo action @Override public void onClick(View v) { scanFieldPaper(null); } }) .setActionTextColor(Color.rgb(126, 188, 111)) .show(); } }
Example #6
Source File: ImageFragment.java From OpenCV-android with Apache License 2.0 | 6 votes |
private void processHough() { final Bitmap bm = ((BitmapDrawable) ivOrigin.getDrawable()).getBitmap(); ProcessHelper.get().hough(bm, new ProcessHelper.ProcessCallback() { @Override public void onSuccess(Bitmap bitmap) { ivAfter.setImageBitmap(bitmap); bm.recycle(); } @Override public void onFailed(String msg) { System.out.println(msg); Snackbar.make(ivOrigin, msg, Snackbar.LENGTH_SHORT).show(); bm.recycle(); } }); }
Example #7
Source File: ClientDetailActivity.java From faveo-helpdesk-android-app with Open Software License 3.0 | 6 votes |
/** * Display the snackbar if network connection is not there. * * @param isConnected is a boolean value of network connection. */ private void showSnackIfNoInternet(boolean isConnected) { if (!isConnected) { final Snackbar snackbar = Snackbar .make(findViewById(android.R.id.content), R.string.sry_not_connected_to_internet, Snackbar.LENGTH_INDEFINITE); View sbView = snackbar.getView(); TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text); textView.setTextColor(Color.RED); snackbar.setAction("X", new View.OnClickListener() { @Override public void onClick(View v) { snackbar.dismiss(); } }); snackbar.show(); } }
Example #8
Source File: FourthActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fourth); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); }
Example #9
Source File: MainActivity.java From BlogDemo with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); }
Example #10
Source File: LargeToolbarFixActivity.java From CoordinatorLayoutSample with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_large_toolbar_fix); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); }
Example #11
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); DrawerLayout drawer = findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); }
Example #12
Source File: LoginActivity.java From atlas with Apache License 2.0 | 6 votes |
private boolean mayRequestContacts() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return true; } if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) { return true; } if (shouldShowRequestPermissionRationale(READ_CONTACTS)) { Snackbar.make(mEmailView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE) .setAction(android.R.string.ok, new View.OnClickListener() { @Override @TargetApi(Build.VERSION_CODES.M) public void onClick(View v) { requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); } }); } else { requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS); } return false; }
Example #13
Source File: ThirdActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_third); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); }
Example #14
Source File: MainActivity.java From PracticeDemo with Apache License 2.0 | 6 votes |
@OnClick({R.id.fab}) public void onClick(View view) { switch (view.getId()) { case R.id.fab: // Log.d(TAG,Log.getStackTraceString(new Throwable()));//简单暴力 打出堆栈 String jni = HelloJni.helloJni(); Snackbar.make(mFab, jni, Snackbar.LENGTH_SHORT).setAction("TODO", new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(mContext, "TODO", Toast.LENGTH_SHORT).show(); } }).show(); break; } // throw new IllegalArgumentException("Hello crashcatcher"); }
Example #15
Source File: MainActivity.java From AndroidHttpCapture with MIT License | 6 votes |
@Override public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) { try { JSONObject jsonObject = new JSONObject(serverResponse.getBodyAsString()); if (jsonObject.getInt("errId") == 0) { Snackbar.make(rootView, "上传成功!", Snackbar.LENGTH_LONG).setAction("Action", null).show(); } else if (jsonObject.getInt("errId") == 2 || jsonObject.getInt("errId") == 11004) { Snackbar.make(rootView, "验证码错误!", Snackbar.LENGTH_LONG).setAction("Action", null).show(); showUploadDialog(MainActivity.this); } else { Snackbar.make(rootView, "上传失败!", Snackbar.LENGTH_LONG).setAction("Action", null).show(); } } catch (Exception e) { Snackbar.make(rootView, "上传失败!", Snackbar.LENGTH_LONG).setAction("Action", null).show(); } dismissLoading(); }
Example #16
Source File: BookDetailsActivity.java From NHentai-android with GNU General Public License v3.0 | 6 votes |
@Override protected void onPostExecute(BaseMessage result) { if (result.getCode() == 0) { book = result.getData(); updateUIContent(); } else { mProgressWheel.setVisibility(View.GONE); Snackbar.make( $(R.id.main_content), R.string.tips_network_error, Snackbar.LENGTH_LONG ).setAction( R.string.snack_action_try_again, new View.OnClickListener() { @Override public void onClick(View view) { startBookGet(); } }).show(); } }
Example #17
Source File: MainActivity.java From Synapse with Apache License 2.0 | 5 votes |
private void handleDecompressComplete(MANEvent event) { final boolean success = event.obj != null ? (Boolean) event.obj : false; @StringRes final int res; if (success) { mButler.setWelcome(new WelcomeItem(WelcomeItem.READY)) .notifyDataSetChanged(); mRecyclerView.postDelayed(new Runnable() { @Override public void run() { if (!MainActivity.this.isFinishing()) { solveData(); } } }, 1500); res = R.string.text_decompress_success; } else { mButler.setWelcome(getDataSetItem(WelcomeItem.UNREADY)) .notifyDataSetChanged(); res = R.string.text_decompress_error; } Snackbar.make(mRecyclerView, res, Snackbar.LENGTH_SHORT) .show(); }
Example #18
Source File: OcrCaptureActivity.java From android-vision with Apache License 2.0 | 5 votes |
/** * Handles the requesting of the camera permission. This includes * showing a "Snackbar" message of why the permission is needed then * sending the request. */ private void requestCameraPermission() { Log.w(TAG, "Camera permission is not granted. Requesting permission"); final String[] permissions = new String[]{Manifest.permission.CAMERA}; if (!ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { ActivityCompat.requestPermissions(this, permissions, RC_HANDLE_CAMERA_PERM); return; } final Activity thisActivity = this; View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { ActivityCompat.requestPermissions(thisActivity, permissions, RC_HANDLE_CAMERA_PERM); } }; Snackbar.make(graphicOverlay, R.string.permission_camera_rationale, Snackbar.LENGTH_INDEFINITE) .setAction(R.string.ok, listener) .show(); }
Example #19
Source File: LikeController.java From social-app-android with Apache License 2.0 | 5 votes |
public void changeAnimationType() { if (getLikeAnimationType() == LikeController.AnimationType.BOUNCE_ANIM) { setLikeAnimationType(LikeController.AnimationType.COLOR_ANIM); } else { setLikeAnimationType(LikeController.AnimationType.BOUNCE_ANIM); } Snackbar snackbar = Snackbar .make(likesImageView, "Animation was changed", Snackbar.LENGTH_LONG); snackbar.show(); }
Example #20
Source File: NewsChannelFragment.java From NewsMe with Apache License 2.0 | 5 votes |
private void showError(Throwable error) { LogUtils.e(TAG, getString(R.string.error), error); if (error instanceof UnknownHostException) { View root = ((MainActivity) getActivity()).getBinding().coordinator; Snackbar.make(root, getString(R.string.error_network), Snackbar.LENGTH_LONG) .setAction(R.string.setting, new View.OnClickListener() { @Override public void onClick(View v) { openNetSetting(); } }).show(); } else { showMsgLong(getString(R.string.error_loading)); } }
Example #21
Source File: FloatingActionButtonBehavior.java From island with Apache License 2.0 | 5 votes |
@Override public boolean onDependentViewChanged(final CoordinatorLayout parent, final FloatingActionButton child, final View dependency) { // Block parent behavior for SnackBar if bottom sheet is visible if (dependency instanceof Snackbar.SnackbarLayout) { final ViewGroup.LayoutParams fab_general_params = child.getLayoutParams(); if (fab_general_params instanceof CoordinatorLayout.LayoutParams) { final CoordinatorLayout.LayoutParams fab_params = ((CoordinatorLayout.LayoutParams) fab_general_params); final int anchor_id = fab_params.getAnchorId(); if (anchor_id != 0) { final View anchor = parent.findViewById(anchor_id); if (anchor != null && anchor.getVisibility() == View.VISIBLE) return false; } } } return super.onDependentViewChanged(parent, child, dependency); }
Example #22
Source File: ActionUtil.java From AppPlus with MIT License | 5 votes |
/** * 传送安装包 * @param entity */ public static void shareApk(Activity activity, AppEntity entity) { final File srcFile = new File(entity.getSrcPath()); if(!srcFile.exists()){ Snackbar.make(activity.getWindow().getDecorView(),String.format(activity.getString(R.string.fail_share_app),entity.getAppName()),Snackbar.LENGTH_LONG).show(); return; } Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(entity.getSrcPath()))); intent.setType("application/vnd.android.package-archive"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activity.startActivity(Intent.createChooser(intent, FormatUtil.warpChooserTitle(activity,entity.getAppName()))); }
Example #23
Source File: MyElectricMainFragment.java From AndroidApp with GNU Affero General Public License v3.0 | 5 votes |
@Override public void showMessage(String message) { isMessage = true; if (myElectricSettings != null) { Log.d("me", "showing message " + myElectricSettings.getName() + " - " + message); } Snackbar snackbar = getSnackbar(); if (snackbar != null) { snackbar.setText(message); if (isVisibleInPager) { getSnackbar().show(); } } }
Example #24
Source File: ShareArticleActivity.java From AndroidPlusJava with GNU General Public License v3.0 | 5 votes |
private void publishArticle() { String title = mArticleTitle.getText().toString().trim(); if (title.length() == 0) { Snackbar.make(mScrollView, getString(R.string.title_not_null), Snackbar.LENGTH_SHORT).show(); return; } if (mTag == -1) { Snackbar.make(mScrollView, getString(R.string.tag_not_null), Snackbar.LENGTH_SHORT).show(); return; } Article article = new Article(); article.setTitle(title); String desc = mArticleDescription.getText().toString().trim(); article.setDesc(desc); article.setUrl(mArticleUrl.getText().toString()); article.setTag(mTag); User user = AVUser.getCurrentUser(User.class); article.setUser(user); mArticleDataSource.saveArticle(article, new SaveCallback() { @Override public void onSaveSuccess() { Snackbar.make(mScrollView, getString(R.string.publish_success), Snackbar.LENGTH_SHORT).show(); } @Override public void onSaveFailed(String errorMsg) { Snackbar.make(mScrollView, getString(R.string.publish_failed), Snackbar.LENGTH_SHORT).show(); } }); }
Example #25
Source File: NewsListFragment.java From Pioneer with Apache License 2.0 | 5 votes |
@Override public void showSnackBar(String text, String actionLabel, View.OnClickListener actionListener) { if (!isVisible()) { return; } Snackbar.make(getView(), text, Snackbar.LENGTH_LONG) .setActionTextColor(Color.YELLOW) .setAction(actionLabel, actionListener) .show(); }
Example #26
Source File: CommentPage.java From Slide with GNU General Public License v3.0 | 5 votes |
private void changeSubscription(Subreddit subreddit, boolean isChecked) { UserSubscriptions.addSubreddit(subreddit.getDisplayName().toLowerCase(Locale.ENGLISH), getContext()); Snackbar s = Snackbar.make(toolbar, isChecked ? getString(R.string.misc_subscribed) : getString(R.string.misc_unsubscribed), Snackbar.LENGTH_SHORT); View view = s.getView(); TextView tv = view.findViewById(android.support.design.R.id.snackbar_text); tv.setTextColor(Color.WHITE); s.show(); }
Example #27
Source File: IndividualProduct.java From MagicPrint-ECommerce-App-Android with MIT License | 5 votes |
public void addToCart(View view) { if ( customheader.getText().toString().length() == 0 || custommessage.getText().toString().length() ==0 ){ Snackbar.make(view, "Header or Message Empty", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); }else{ mDatabaseReference.child("cart").child(usermobile).push().setValue(getProductObject()); session.increaseCartValue(); Log.e("Cart Value IP", session.getCartValue() + " "); Toasty.success(IndividualProduct.this, "Added to Cart", Toast.LENGTH_SHORT).show(); } }
Example #28
Source File: BaseApplication.java From MarkdownEditors with Apache License 2.0 | 5 votes |
public static Snackbar showSnackbar(@NonNull View view, @NonNull int messageRes, @Snackbar.Duration int duration, @Nullable View.OnClickListener listener, @Nullable String actionStr) { Snackbar snackbar = Snackbar.make(view, messageRes, duration); if (listener != null && Check.isEmpty(actionStr)) { snackbar.setAction(actionStr, listener); } snackbar.show(); return snackbar; }
Example #29
Source File: MainActivity.java From good-weather with GNU General Public License v3.0 | 5 votes |
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { switch (requestCode) { case REQUEST_LOCATION: if (PermissionUtil.verifyPermissions(grantResults)) { Snackbar.make(findViewById(android.R.id.content), R.string.permission_available_location, Snackbar.LENGTH_SHORT).show(); } else { Snackbar.make(findViewById(android.R.id.content), R.string.permission_not_granted, Snackbar.LENGTH_SHORT).show(); } break; default: super.onRequestPermissionsResult(requestCode, permissions, grantResults); break; } }
Example #30
Source File: MainActivity.java From android-RuntimePermissions with Apache License 2.0 | 5 votes |
/** * Requests the Camera permission. * If the permission has been denied previously, a SnackBar will prompt the user to grant the * permission, otherwise it is requested directly. */ private void requestCameraPermission() { Log.i(TAG, "CAMERA permission has NOT been granted. Requesting permission."); // BEGIN_INCLUDE(camera_permission_request) if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { // Provide an additional rationale to the user if the permission was not granted // and the user would benefit from additional context for the use of the permission. // For example if the user has previously denied the permission. Log.i(TAG, "Displaying camera permission rationale to provide additional context."); Snackbar.make(mLayout, R.string.permission_camera_rationale, Snackbar.LENGTH_INDEFINITE) .setAction(R.string.ok, new View.OnClickListener() { @Override public void onClick(View view) { ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA); } }) .show(); } else { // Camera permission has not been granted yet. Request it directly. ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA); } // END_INCLUDE(camera_permission_request) }