Java Code Examples for android.support.design.widget.Snackbar

The following examples show how to use android.support.design.widget.Snackbar. These examples are extracted from open source projects. 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
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 2
Source Project: Watch-Me-Build-a-Finance-Startup   Source File: LoginActivity.java    License: MIT License 6 votes vote down vote up
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 Project: AndroidHttpCapture   Source File: MainActivity.java    License: MIT License 6 votes vote down vote up
@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 4
@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 5
@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 6
Source Project: BlogDemo   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@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 7
Source Project: homeassist   Source File: ConnectActivity.java    License: Apache License 2.0 6 votes vote down vote up
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 8
Source Project: PracticeDemo   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@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 9
@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 10
@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 11
/**
 * 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 12
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 13
@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 14
Source Project: atlas   Source File: LoginActivity.java    License: Apache License 2.0 6 votes vote down vote up
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 15
@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 16
Source Project: OpenCV-android   Source File: ImageFragment.java    License: Apache License 2.0 6 votes vote down vote up
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 17
private void disableService() {
    if (mAutofillManager != null && mAutofillManager.hasEnabledAutofillServices()) {
        mAutofillManager.disableAutofillServices();
        Snackbar.make(findViewById(R.id.settings_layout),
                R.string.settings_autofill_disabled_message, Snackbar.LENGTH_SHORT).show();
    } else {
        logd("Sample service already disabled.");
    }
}
 
Example 18
Source Project: android-showcase-template   Source File: BaseAppView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void showMessage(String message) {
    Context ctx = getContext();
    if (ctx != null) {
        Snackbar snackbar = Snackbar.make(this.fragment.getActivity().getCurrentFocus(), message, Snackbar.LENGTH_SHORT)
                .setAction("Action", null);
        snackbar.getView().setBackgroundResource(R.color.white);
        snackbar.show();
    }
}
 
Example 19
Source Project: SteamGifts   Source File: SavedGiveawaysFragment.java    License: MIT License 5 votes vote down vote up
/**
 * Callback for {@link #enteredGameListTask}
 * <p>Note: do NOT call this from within this class.</p>
 */
@Override
public void addItems(List<? extends IEndlessAdaptable> items, boolean clearExistingItems) {
    if (items != null) {
        // closed or not deleted
        boolean foundAnyClosedGiveaways = false;

        // do nothing much except update the status of existing giveaways.
        for (IEndlessAdaptable endlessAdaptable : items) {
            ProfileGiveaway giveaway = (ProfileGiveaway) endlessAdaptable;
            if (!giveaway.isOpen() && !giveaway.isDeleted()) {
                foundAnyClosedGiveaways = true;
                break;
            }

            Giveaway existingGiveaway = adapter.findItem(giveaway.getGiveawayId());
            if (existingGiveaway != null) {
                existingGiveaway.setEntries(giveaway.getEntries());
                existingGiveaway.setEntered(true);
                adapter.notifyItemChanged(existingGiveaway);
            }
        }

        FragmentActivity activity = getActivity();
        if (activity != null)
            activity.supportInvalidateOptionsMenu();

        // have we found any non-closed giveaways?
        if (foundAnyClosedGiveaways) {
            enteredGameListTask = null;
        } else {
            enteredGameListTask = new LoadEnteredGameListTask(this, enteredGameListTask.getPage() + 1);
            enteredGameListTask.execute();
        }
    } else {
        showSnack("Failed to update entered giveaways", Snackbar.LENGTH_LONG);
    }
}
 
Example 20
@Override
public void onPublishSuccess() {
    Snackbar.make(mScrollView, R.string.publish_success, Snackbar.LENGTH_SHORT)
            .addCallback(new Snackbar.Callback(){
                @Override
                public void onDismissed(Snackbar transientBottomBar, int event) {
                    finish();
                }
            })
            .show();
}
 
Example 21
Source Project: input-samples   Source File: SettingsActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void disableService() {
    if (mAutofillManager != null && mAutofillManager.hasEnabledAutofillServices()) {
        mAutofillManager.disableAutofillServices();
        Snackbar.make(findViewById(R.id.settings_layout),
                R.string.settings_autofill_disabled_message, Snackbar.LENGTH_SHORT).show();
    } else {
        logd("Sample service already disabled.");
    }
}
 
Example 22
Source Project: AppPlus   Source File: AppFileListFragment.java    License: MIT License 5 votes vote down vote up
private void loadingDataEmpty(String emptyInfo) {
    final Snackbar errorSnack = Snackbar.make(mRecyclerView, emptyInfo, Snackbar.LENGTH_LONG);
    errorSnack.setAction(R.string.action_retry, new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            errorSnack.dismiss();
            fillData();
        }
    });
    errorSnack.show();
}
 
Example 23
Source Project: Travel-Mate   Source File: MyTripsFragment.java    License: MIT License 5 votes vote down vote up
/**
 * Plays the no results animation in the view
 */
private void noResults() {
    ArrayList<Trip> trips = new ArrayList<>();
    mMyTripsAdapter.initData(trips);
    TravelmateSnackbars.createSnackBar(mTripsView.findViewById(R.id.my_trips_frag), R.string.no_trips,
            Snackbar.LENGTH_SHORT).show();
    animationView.setAnimation(R.raw.empty_list);
    animationView.setVisibility(View.VISIBLE);
    animationView.playAnimation();
}
 
Example 24
public void setTitle(String s) {
    if (title != null) {
        title.setText(s);
        Snackbar mySnackbar = Snackbar.make(coord,
                AddressDetailActivity.this.getResources().getString(R.string.detail_acc_name_changed_suc), Snackbar.LENGTH_SHORT);
        mySnackbar.show();
    }
}
 
Example 25
Source Project: droidkaigi2016   Source File: ContributorsActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void renderSavedContributors(Throwable throwable) {
    Log.e(TAG, "Failed to fetchContributors.", throwable);
    Crashlytics.logException(throwable);

    List<Contributor> contributors = dao.findAll();

    if (contributors.isEmpty()) {
        Snackbar.make(binding.getRoot(), R.string.contributors_load_error, Snackbar.LENGTH_LONG).show();
    } else {
        bindContributors(contributors);
    }
}
 
Example 26
Source Project: UltimateRefreshView   Source File: UltimateViewActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_utril_view);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mFragments.add(new RecyclerViewFragment());
    mFragments.add(new ListViewFragment());
    mFragments.add(new ScrollViewFragment());
    mFragments.add(new WebViewFragment());

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), mFragments);

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

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

    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 27
Source Project: gcm-android-client   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@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, "Click to send an email to the maker", Snackbar.LENGTH_LONG)
          .setAction("EMAIL", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                      "mailto", "[email protected]", null));
              emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Regarding:GCMLibrary");
              startActivity(Intent.createChooser(emailIntent, "Send email..."));
            }
          })
          .show();
    }
  });

  receiver = new RegistrationCompletedReceiver();
  filter = new IntentFilter(RegistrationIntentService.REGISTRATION_COMPLETE);
  App.getInstance().getMixpanelAPI().track("App_Opened");
  App.getInstance().getMixpanelAPI().getPeople().set("last_active", new Date());
  Localytics.tagEvent("App_Opened");

}
 
Example 28
Source Project: Slide   Source File: CommentPage.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 29
Source Project: Synapse   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
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 30
Source Project: island   Source File: FloatingActionButtonBehavior.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}