• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.documentsui.ui;
18 
19 import android.annotation.StringRes;
20 import android.app.Activity;
21 import android.support.design.widget.Snackbar;
22 import android.view.Gravity;
23 import android.view.View;
24 import android.widget.TextView;
25 
26 import com.android.documentsui.R;
27 import com.android.documentsui.base.Shared;
28 
29 public final class Snackbars {
Snackbars()30     private Snackbars() {}
31 
showDocumentsClipped(Activity activity, int docCount)32     public static final void showDocumentsClipped(Activity activity, int docCount) {
33         String msg = Shared.getQuantityString(
34                 activity, R.plurals.clipboard_files_clipped, docCount);
35         Snackbars.makeSnackbar(activity, msg, Snackbar.LENGTH_SHORT).show();
36     }
37 
showMove(Activity activity, int docCount)38     public static final void showMove(Activity activity, int docCount) {
39         CharSequence message = Shared.getQuantityString(activity, R.plurals.move_begin, docCount);
40         makeSnackbar(activity, message, Snackbar.LENGTH_SHORT).show();
41     }
42 
showCopy(Activity activity, int docCount)43     public static final void showCopy(Activity activity, int docCount) {
44         CharSequence message = Shared.getQuantityString(activity, R.plurals.copy_begin, docCount);
45         makeSnackbar(activity, message, Snackbar.LENGTH_SHORT).show();
46     }
47 
showCompress(Activity activity, int docCount)48     public static final void showCompress(Activity activity, int docCount) {
49         CharSequence message = Shared.getQuantityString(activity, R.plurals.compress_begin, docCount);
50         makeSnackbar(activity, message, Snackbar.LENGTH_SHORT).show();
51     }
52 
showExtract(Activity activity, int docCount)53     public static final void showExtract(Activity activity, int docCount) {
54         CharSequence message = Shared.getQuantityString(activity, R.plurals.extract_begin, docCount);
55         makeSnackbar(activity, message, Snackbar.LENGTH_SHORT).show();
56     }
57 
showDelete(Activity activity, int docCount)58     public static final void showDelete(Activity activity, int docCount) {
59         CharSequence message = Shared.getQuantityString(activity, R.plurals.deleting, docCount);
60         makeSnackbar(activity, message, Snackbar.LENGTH_SHORT).show();
61     }
62 
showOperationRejected(Activity activity)63     public static final void showOperationRejected(Activity activity) {
64         makeSnackbar(activity, R.string.file_operation_rejected, Snackbar.LENGTH_SHORT).show();
65     }
66 
showOperationFailed(Activity activity)67     public static final void showOperationFailed(Activity activity) {
68         makeSnackbar(activity, R.string.file_operation_error, Snackbar.LENGTH_SHORT).show();
69     }
70 
showRenameFailed(Activity activity)71     public static final void showRenameFailed(Activity activity) {
72         makeSnackbar(activity, R.string.rename_error, Snackbar.LENGTH_SHORT).show();
73     }
74 
showInspectorError(Activity activity)75     public static final void showInspectorError(Activity activity) {
76 
77         //Document Inspector uses a different view from other files app activities.
78         final View view = activity.findViewById(R.id.fragment_container);
79         Snackbar.make(view, R.string.file_inspector_load_error, Snackbar.LENGTH_INDEFINITE).show();
80     }
81 
showCustomTextWithImage(Activity activity, String text, int imageRes)82     public static final void showCustomTextWithImage(Activity activity, String text, int imageRes) {
83         Snackbar snackbar = makeSnackbar(activity, text, Snackbar.LENGTH_SHORT);
84         View snackbarLayout = snackbar.getView();
85         TextView textView = (TextView)snackbarLayout.findViewById(
86                 android.support.design.R.id.snackbar_text);
87         textView.setGravity(Gravity.CENTER_HORIZONTAL);
88         textView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
89         textView.setCompoundDrawablesWithIntrinsicBounds(imageRes, 0, 0, 0);
90         snackbar.show();
91     }
92 
makeSnackbar(Activity activity, @StringRes int messageId, int duration)93     public static final Snackbar makeSnackbar(Activity activity, @StringRes int messageId,
94             int duration) {
95         return Snackbars.makeSnackbar(
96                 activity, activity.getResources().getText(messageId), duration);
97     }
98 
makeSnackbar( Activity activity, CharSequence message, int duration)99     public static final Snackbar makeSnackbar(
100             Activity activity, CharSequence message, int duration) {
101         final View view = activity.findViewById(R.id.coordinator_layout);
102         return Snackbar.make(view, message, duration);
103     }
104 }
105