1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.example.android.support.design.widget;
18
19import com.example.android.support.design.R;
20
21import android.os.Bundle;
22import android.support.design.widget.Snackbar;
23import android.support.v7.app.AppCompatActivity;
24import android.view.View;
25import android.view.ViewGroup;
26import android.widget.Toast;
27
28/**
29 * This demonstrates idiomatic usage of the Floating Action Button
30 */
31public class SnackbarUsage extends AppCompatActivity {
32
33    private ViewGroup mContentView;
34
35    @Override
36    protected void onCreate(Bundle savedInstanceState) {
37        super.onCreate(savedInstanceState);
38        setContentView(getLayoutId());
39
40        mContentView = (ViewGroup) findViewById(R.id.content_view);
41    }
42
43    protected int getLayoutId() {
44        return R.layout.design_snackbar;
45    }
46
47    public void showShort(View view) {
48        Snackbar.make(mContentView, "Short snackbar message", Snackbar.LENGTH_SHORT).show();
49    }
50
51    public void showAction(View view) {
52        Snackbar.make(mContentView, "Short snackbar message", Snackbar.LENGTH_SHORT)
53                .setAction("Action", new View.OnClickListener() {
54                    @Override
55                    public void onClick(View view) {
56                        Toast.makeText(SnackbarUsage.this, "Snackbar Action pressed",
57                                Toast.LENGTH_SHORT).show();
58                    }
59                }).show();
60    }
61
62    public void showLong(View view) {
63        Snackbar.make(mContentView, "Long snackbar message which wraps onto another line and"
64                + "makes the Snackbar taller", Snackbar.LENGTH_SHORT).show();
65    }
66
67    public void showLongAction(View view) {
68        Snackbar.make(mContentView, "Long snackbar message which wraps onto another line and"
69                + "makes the Snackbar taller", Snackbar.LENGTH_SHORT)
70                .setAction("Action", new View.OnClickListener() {
71                    @Override
72                    public void onClick(View view) {
73                        Toast.makeText(SnackbarUsage.this, "Snackbar Action pressed",
74                                Toast.LENGTH_SHORT).show();
75                    }
76                }).show();
77    }
78
79    public void showLongLongAction(View view) {
80        Snackbar.make(mContentView, "Long snackbar message which wraps onto another line and"
81                + "makes the Snackbar taller", Snackbar.LENGTH_SHORT)
82                .setAction("Action which wraps", new View.OnClickListener() {
83                    @Override
84                    public void onClick(View view) {
85                        Toast.makeText(SnackbarUsage.this, "Snackbar Action pressed",
86                                Toast.LENGTH_SHORT).show();
87                    }
88                }).show();
89    }
90
91}