com.google.android.material.snackbar.Snackbar Java Examples

The following examples show how to use com.google.android.material.snackbar.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: LttrsActivity.java    From lttrs-android with Apache License 2.0 6 votes vote down vote up
public void removeFromKeyword(Collection<String> threadIds, final String keyword) {
    final int count = threadIds.size();
    final Snackbar snackbar = Snackbar.make(
            binding.getRoot(),
            getResources().getQuantityString(
                    R.plurals.n_removed_from_x,
                    count,
                    count,
                    KeywordLabel.of(keyword).getName()
            ),
            Snackbar.LENGTH_LONG
    );
    snackbar.setAction(R.string.undo, v -> lttrsViewModel.addKeyword(threadIds, keyword));
    snackbar.show();
    lttrsViewModel.removeKeyword(threadIds, keyword);
}
 
Example #2
Source File: ActionController.java    From science-journal with Apache License 2.0 6 votes vote down vote up
private void onRecordingStopFailed(
    View anchorView,
    @RecorderController.RecordingStopErrorType int errorType,
    FragmentManager fragmentManager) {
  Resources resources = anchorView.getResources();
  if (errorType == RecorderController.ERROR_STOP_FAILED_DISCONNECTED) {
    alertFailedStopRecording(
        resources, R.string.recording_stop_failed_disconnected, fragmentManager);
  } else if (errorType == RecorderController.ERROR_STOP_FAILED_NO_DATA) {
    alertFailedStopRecording(resources, R.string.recording_stop_failed_no_data, fragmentManager);
  } else if (errorType == RecorderController.ERROR_FAILED_SAVE_RECORDING) {
    AccessibilityUtils.makeSnackbar(
            anchorView,
            resources.getString(R.string.recording_stop_failed_save),
            Snackbar.LENGTH_LONG)
        .show();
  }
}
 
Example #3
Source File: FragmentExpandableMultiLevel.java    From FlexibleAdapter with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_recursive_collapse) {
        if (mAdapter.isRecursiveCollapse()) {
            mAdapter.setRecursiveCollapse(false);
            item.setChecked(false);
            Snackbar.make(getView(), "Recursive-Collapse is disabled", Snackbar.LENGTH_SHORT).show();
        } else {
            mAdapter.setRecursiveCollapse(true);
            item.setChecked(true);
            Snackbar.make(getView(), "Recursive-Collapse is enabled", Snackbar.LENGTH_SHORT).show();
        }
    }

    return super.onOptionsItemSelected(item);
}
 
Example #4
Source File: ConversationActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void showAudioRecordingDialog() {

        if (Utils.hasMarshmallow() && PermissionsUtils.checkSelfPermissionForAudioRecording(this)) {
            new ApplozicPermissions(this, layout).requestAudio();
        } else if (PermissionsUtils.isAudioRecordingPermissionGranted(this)) {

            FragmentManager supportFragmentManager = getSupportFragmentManager();
            DialogFragment fragment = AudioMessageFragment.newInstance();

            FragmentTransaction fragmentTransaction = supportFragmentManager
                    .beginTransaction().add(fragment, "AudioMessageFragment");

            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commitAllowingStateLoss();
        } else {

            if (alCustomizationSettings.getAudioPermissionNotFoundMsg() == null) {
                showSnackBar(R.string.applozic_audio_permission_missing);
            } else {
                snackbar = Snackbar.make(layout, alCustomizationSettings.getAudioPermissionNotFoundMsg(),
                        Snackbar.LENGTH_SHORT);
                snackbar.show();
            }

        }
    }
 
Example #5
Source File: DynamicHintUtils.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
/**
 * Make a themed snack bar with text and action.
 *
 * @param view The view to show the snack bar.
 * @param text The text to show. Can be formatted text.
 * @param backgroundColor The snack bar background color.
 * @param tintColor The snack bar tint color based on the background. It will automatically
 *                  check for the contrast to provide bes visibility.
 * @param duration The duration of the snack bar.
 *                 <p>Can be {@link Snackbar#LENGTH_SHORT}, {@link Snackbar#LENGTH_LONG}
 *                 or {@link Snackbar#LENGTH_INDEFINITE}.
 *
 * @return The snack bar with the supplied parameters.
 *         <p>Use {@link Snackbar#show()} to display the snack bar.
 */
public static @NonNull Snackbar getSnackBar(@NonNull View view,
        @NonNull CharSequence text, @ColorInt int backgroundColor,
        @ColorInt int tintColor, @Snackbar.Duration int duration) {
    if (DynamicTheme.getInstance().get().isBackgroundAware()) {
        backgroundColor = DynamicColorUtils.getContrastColor(backgroundColor,
                DynamicTheme.getInstance().get().getBackgroundColor());
        tintColor = DynamicColorUtils.getContrastColor(tintColor, backgroundColor);
    }

    Snackbar snackbar = Snackbar.make(view, text, duration);
    DynamicDrawableUtils.setBackground(snackbar.getView(),
            DynamicDrawableUtils.getCornerDrawable(DynamicTheme.getInstance()
                    .get().getCornerSizeDp(), backgroundColor));
    ((TextView) snackbar.getView().findViewById(
            R.id.snackbar_text)).setTextColor(tintColor);
    ((TextView) snackbar.getView().findViewById(
            R.id.snackbar_text)).setMaxLines(Integer.MAX_VALUE);
    snackbar.setActionTextColor(tintColor);

    return snackbar;
}
 
Example #6
Source File: PrefHelper.java    From Easy_xkcd with Apache License 2.0 6 votes vote down vote up
public void showFeatureSnackbar(final Activity activity, FloatingActionButton fab) {
    if (!sharedPrefs.getBoolean(CUSTOM_THEMES_SNACKBAR, false)) {
        View.OnClickListener oc = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, NestedSettingsActivity.class);
                intent.putExtra("key", "appearance");
                activity.startActivityForResult(intent, 1);
            }
        };
        SharedPreferences.Editor editor = sharedPrefs.edit();
        editor.putBoolean(CUSTOM_THEMES_SNACKBAR, true);
        editor.apply();
        Snackbar.make(fab, R.string.snackbar_feature, Snackbar.LENGTH_LONG)
                .setAction(R.string.snackbar_feature_oc, oc)
                .show();
    }
}
 
Example #7
Source File: SnackbarUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 内部显示方法
 * @param text     显示文本
 * @param duration 显示时长 {@link Snackbar#LENGTH_SHORT}、{@link Snackbar#LENGTH_LONG}、{@link Snackbar#LENGTH_INDEFINITE}
 */
private void priShow(final String text, final int duration) {
    Snackbar snackbar = getSnackbar();
    if (snackbar != null && !snackbar.isShownOrQueued()) {
        // 防止内容为 null
        if (!TextUtils.isEmpty(text)) {
            // 设置样式
            setSnackbarStyle(snackbar);
            try {
                // 设置坐标位置
                setSnackbarLocation(snackbar);
            } catch (Exception e) {
                LogPrintUtils.eTag(TAG, e, "priShow - setSnackbarLocation");
            }
            // 显示 SnackBar
            snackbar.setText(text).setDuration(duration).show();
        }
    }
}
 
Example #8
Source File: UndoSnackbarManager.java    From Maying with Apache License 2.0 6 votes vote down vote up
public void remove(int index, T item) {
    recycleBin.append(index, item);
    int count = recycleBin.size();
    last = Snackbar.make(view, view.getResources().getQuantityString(R.plurals.removed, count, count), Snackbar.LENGTH_LONG)
            .setCallback(removedCallback)
            .setAction(R.string.undo, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (undo != null) {
                        undo.onUndo(recycleBin);
                    }
                    recycleBin.clear();
                }
            });
    last.show();
}
 
Example #9
Source File: ExportOptionsDialogFragment.java    From science-journal with Apache License 2.0 6 votes vote down vote up
private void updateProgress(ExportProgress progress) {
  progressBar.setVisibility(
      progress.getState() == ExportProgress.EXPORTING ? View.VISIBLE : View.INVISIBLE);
  exportButton.setEnabled(progress.getState() != ExportProgress.EXPORTING);
  if (progress.getState() == ExportProgress.EXPORTING) {
    progressBar.setProgress(progress.getProgress());
  } else if (progress.getState() == ExportProgress.EXPORT_COMPLETE) {
    // Finish dialog and send the filename.
    if (getActivity() != null) {
      if (saveLocally) {
        requestDownload(progress);
      } else {
        requestExport(progress);
      }
    }
  } else if (progress.getState() == ExportProgress.ERROR) {
    if (getActivity() != null) {
      Snackbar bar =
          AccessibilityUtils.makeSnackbar(
              getView(), getString(R.string.export_error), Snackbar.LENGTH_LONG);
      bar.show();
    }
  }
}
 
Example #10
Source File: DetailsActivity.java    From tracker-control-android with GNU General Public License v3.0 6 votes vote down vote up
protected void onPostExecute(final Boolean success) {
    if (this.dialog.isShowing()) {
        this.dialog.dismiss();
    }

    if (!success) {
        Toast.makeText(DetailsActivity.this, R.string.export_failed, Toast.LENGTH_SHORT).show();
        return;
    }

    // Export successful, ask user to further share file!
    View v = findViewById(R.id.view_pager);
    Snackbar s = Snackbar.make(v, R.string.exported, Snackbar.LENGTH_LONG);
    s.setAction(R.string.share_csv, v1 -> shareExport());
    s.setActionTextColor(getResources().getColor(R.color.colorPrimary));
    s.show();
}
 
Example #11
Source File: BookSourcePresenter.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
private MyObserver<List<BookSourceBean>> getImportObserver() {
    return new MyObserver<List<BookSourceBean>>() {
        @SuppressLint("DefaultLocale")
        @Override
        public void onNext(List<BookSourceBean> bookSourceBeans) {
            if (bookSourceBeans.size() > 0) {
                mView.refreshBookSource();
                mView.showSnackBar(String.format("导入成功%d个书源", bookSourceBeans.size()), Snackbar.LENGTH_SHORT);
                mView.setResult(RESULT_OK);
            } else {
                mView.showSnackBar("格式不对", Snackbar.LENGTH_SHORT);
            }
        }

        @Override
        public void onError(Throwable e) {
            mView.showSnackBar(e.getMessage(), Snackbar.LENGTH_SHORT);
        }
    };
}
 
Example #12
Source File: ConfigurationServerActivity.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onRefresh() {
    final MeshModel model = mViewModel.getSelectedModel().getValue();
    if (!checkConnectivity() || model == null) {
        mSwipe.setRefreshing(false);
    }
    final ProvisionedMeshNode node = mViewModel.getSelectedMeshNode().getValue();
    final Element element = mViewModel.getSelectedElement().getValue();
    if (node != null && element != null &&
            model instanceof ConfigurationServerModel) {
        mViewModel.displaySnackBar(this, mContainer,
                getString(R.string.listing_model_configuration), Snackbar.LENGTH_LONG);
        mViewModel.getMessageQueue().add(new ConfigHeartbeatSubscriptionGet());
        mViewModel.getMessageQueue().add(new ConfigHeartbeatPublicationGet());
        mViewModel.getMessageQueue().add(new ConfigHeartbeatSubscriptionGet());
        mViewModel.getMessageQueue().add(new ConfigRelayGet());
        mViewModel.getMessageQueue().add(new ConfigNetworkTransmitGet());
        //noinspection ConstantConditions
        sendMessage(node.getUnicastAddress(), mViewModel.getMessageQueue().peek());
    } else {
        mSwipe.setRefreshing(false);
    }
}
 
Example #13
Source File: SignInRequiredActivityPreference.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
@Override
protected void onClick() {
  EhCookieStore store = EhApplication.getEhCookieStore(getContext());
  HttpUrl e = HttpUrl.get(EhUrl.HOST_E);
  HttpUrl ex = HttpUrl.get(EhUrl.HOST_EX);

  if (store.contains(e, EhCookieStore.KEY_IPD_MEMBER_ID) ||
      store.contains(e, EhCookieStore.KEY_IPD_PASS_HASH) ||
      store.contains(ex, EhCookieStore.KEY_IPD_MEMBER_ID) ||
      store.contains(ex, EhCookieStore.KEY_IPD_PASS_HASH)) {
    super.onClick();
  } else {
    if (view != null) {
      Snackbar.make(view, R.string.error_please_login_first, 3000).show();
    } else {
      Toast.makeText(getContext(), R.string.error_please_login_first, Toast.LENGTH_LONG).show();
    }
  }
}
 
Example #14
Source File: ConversationActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void onPostExecute(Boolean aBoolean) {
    super.onPostExecute(aBoolean);
    if (applozicClient.isAccountClosed() || applozicClient.isNotAllowed()) {
        LinearLayout linearLayout = null;
        Snackbar snackbar = null;
        if (snackBarWeakReference != null) {
            snackbar = snackBarWeakReference.get();
        }
        if (linearLayoutWeakReference != null) {
            linearLayout = linearLayoutWeakReference.get();
        }
        if (snackbar != null && linearLayout != null) {
            snackbar = Snackbar.make(linearLayout, applozicClient.isAccountClosed() ?
                            R.string.applozic_account_closed : R.string.applozic_free_version_not_allowed_on_release_build,
                    Snackbar.LENGTH_INDEFINITE);
            snackbar.show();
        }
    }
}
 
Example #15
Source File: SnackBarUtil.java    From FastLib with Apache License 2.0 5 votes vote down vote up
/**
 * 显示SnackBar
 */
public void show() {
    final View view = mParent.get();
    if (view == null) {
        return;
    }
    if (mMessageColor != DEFAULT_COLOR) {
        SpannableString spannableString = new SpannableString(mMessage);
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(mMessageColor);
        spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mWeakReference = new WeakReference<>(Snackbar.make(view, spannableString, mDuration));
    } else {
        mWeakReference = new WeakReference<>(Snackbar.make(view, mMessage, mDuration));
    }
    final Snackbar snackbar = mWeakReference.get();
    final View snackView = snackbar.getView();
    if (mBgResource != -1) {
        snackView.setBackgroundResource(mBgResource);
    } else if (mBgColor != DEFAULT_COLOR) {
        snackView.setBackgroundColor(mBgColor);
    }
    if (mBottomMargin != 0) {
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) snackView.getLayoutParams();
        params.bottomMargin = mBottomMargin;
    }
    if (mActionText.length() > 0 && mActionListener != null) {
        if (mActionTextColor != DEFAULT_COLOR) {
            snackbar.setActionTextColor(mActionTextColor);
        }
        snackbar.setAction(mActionText, mActionListener);
    }
    snackbar.show();
}
 
Example #16
Source File: ViewTaskFragment.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Completes the current task.
 */
private void completeTask()
{
    TaskFieldAdapters.STATUS.set(mContentSet, Tasks.STATUS_COMPLETED);
    TaskFieldAdapters.PINNED.set(mContentSet, false);
    persistTask();
    Snackbar.make(getActivity().getWindow().getDecorView(), getString(R.string.toast_task_completed, TaskFieldAdapters.TITLE.get(mContentSet)),
            Snackbar.LENGTH_SHORT).show();
    mCallback.onTaskCompleted(mTaskUri);
    if (mShowFloatingActionButton)
    {
        // hide fab in two pane mode
        mFloatingActionButton.hide();
    }
}
 
Example #17
Source File: FlagEightLoginActivity.java    From InjuredAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flag_eight_login);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FirebaseAuth mAuth;
    mAuth = FirebaseAuth.getInstance();

    mAuth.signInAnonymously()
            .addOnCompleteListener(this, task -> {
                if (task.isSuccessful()) {
                    // Sign in success, update UI with the signed-in user's information
                    Log.d(TAG, "signInAnonymously:success");

                } else {
                    // If sign in fails, display a message to the user.
                    Log.w(TAG, "signInAnonymously:failure", task.getException());
                    Toast.makeText(FlagEightLoginActivity.this, "Authentication failed.",
                            Toast.LENGTH_SHORT).show();
                }
            });

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(view -> {
        if (click == 0) {
            Snackbar.make(view, "AWS CLI.", Snackbar.LENGTH_LONG)
                    .setAction("Action",null).show();
            click = click + 1;
        } else if (click == 1) {
            Snackbar.make(view, "AWS profiles and credentials.", Snackbar.LENGTH_LONG)
                    .setAction("Action",null).show();
            click = 0;
        }
    });
}
 
Example #18
Source File: FileViewFragment.java    From lbry-android with MIT License 5 votes vote down vote up
private void onMainActionButtonClicked() {
    // Check if the claim is free
    Claim.GenericMetadata metadata = claim.getValue();
    if (metadata instanceof Claim.StreamMetadata) {
        View root = getView();
        if (root != null) {
            root.findViewById(R.id.file_view_main_action_button).setVisibility(View.INVISIBLE);
            root.findViewById(R.id.file_view_main_action_loading).setVisibility(View.VISIBLE);
        }
        if (claim.getFile() == null && !claim.isFree()) {
            if (!Lbry.SDK_READY) {
                if (root != null) {
                    Snackbar.make(root.findViewById(R.id.file_view_global_layout),
                            R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show();
                }
                restoreMainActionButton();
                return;
            }

            checkAndConfirmPurchaseUrl();
        } else {
            if (claim != null && !claim.isPlayable() && !Lbry.SDK_READY) {
                if (root != null) {
                    Snackbar.make(root.findViewById(R.id.file_view_global_layout),
                            R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show();
                }
                restoreMainActionButton();
                return;
            }

            handleMainActionForClaim();
        }
    } else {
        showError(getString(R.string.cannot_view_claim));
    }
}
 
Example #19
Source File: MBaseActivity.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
public void showSnackBar(View view, String msg, int length) {
    if (snackbar == null) {
        snackbar = Snackbar.make(view, msg, length);
    } else {
        snackbar.setText(msg);
        snackbar.setDuration(length);
    }
    snackbar.show();
}
 
Example #20
Source File: BrandedSnackbar.java    From nextcloud-notes with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
public static Snackbar make(@NonNull View view, @NonNull CharSequence text, @BaseTransientBottomBar.Duration int duration) {
    final Snackbar snackbar = Snackbar.make(view, text, duration);
    if (BrandingUtil.isBrandingEnabled(view.getContext())) {
        int color = BrandingUtil.readBrandMainColor(view.getContext());
        snackbar.setActionTextColor(ColorUtil.isColorDark(color) ? Color.WHITE : color);
    }
    return snackbar;
}
 
Example #21
Source File: ShowMessage.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@NonNull public static Completable asObservableSnack(Activity activity, int msg, int actionMsg,
    View.OnClickListener action) {
  Snackbar snackbar = asSnackInternal(activity, msg, actionMsg, action, Snackbar.LENGTH_SHORT);
  if (snackbar != null) {
    return asSnackObservableInternal(snackbar);
  }
  return Completable.error(new IllegalStateException("Extracted view from activity is null"));
}
 
Example #22
Source File: SnackbarUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 构造函数
 * @param view {@link View}
 */
private SnackbarUtils(final View view) {
    if (view != null) {
        try {
            sSnackbarReference = new WeakReference<>(Snackbar.make(view, "", Snackbar.LENGTH_SHORT));
        } catch (Exception e) {
        }
    }
}
 
Example #23
Source File: Advance3DDrawer1Activity.java    From Drawer-Behavior with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_advance_3d_1);
    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();
        }
    });

    drawer = (Advance3DDrawerLayout) 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 = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    drawer.setViewScale(GravityCompat.START, 0.96f);
    drawer.setRadius(GravityCompat.START, 20);
    drawer.setViewElevation(GravityCompat.START, 8);
    drawer.setViewRotation(GravityCompat.START, 15);



}
 
Example #24
Source File: MessagesActivity.java    From android with MIT License 5 votes vote down vote up
private void showDeletionSnackbar() {
    View view = swipeRefreshLayout;
    Snackbar snackbar = Snackbar.make(view, R.string.snackbar_deleted, Snackbar.LENGTH_LONG);
    snackbar.setAction(R.string.snackbar_undo, v -> undoDelete());
    snackbar.addCallback(new SnackbarCallback());
    snackbar.show();
}
 
Example #25
Source File: MainActivity.java    From location-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Shows a {@link Snackbar} using {@code text}.
 *
 * @param text The Snackbar text.
 */
private void showSnackbar(final String text) {
    View container = findViewById(android.R.id.content);
    if (container != null) {
        Snackbar.make(container, text, Snackbar.LENGTH_LONG).show();
    }
}
 
Example #26
Source File: SyncManagerFragment.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void showLocalDataDeleted(boolean error) {

    if (!error) {
        binding.eventsEditText.setText(String.valueOf(0));
        binding.teiEditText.setText(String.valueOf(0));
    }

    Snackbar deleteDataSnack = Snackbar.make(binding.getRoot(),
            error ? R.string.delete_local_data_error : R.string.delete_local_data_done,
            BaseTransientBottomBar.LENGTH_SHORT);
    deleteDataSnack.show();
}
 
Example #27
Source File: ShowMessage.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private static Snackbar asSnackInternal(Activity activity, String msg, int actionMsg,
    View.OnClickListener action, int duration) {
  View view = getViewFromActivity(activity);
  if (view == null) {
    return null;
  }
  return Snackbar.make(view, msg, duration)
      .setAction(actionMsg, action);
}
 
Example #28
Source File: NotificationHelper.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void showActionSnackbar(String content, String action,
                                      int duration, View.OnClickListener l) {
    if (Mysplash.getInstance().getActivityCount() > 0) {
        MysplashActivity a = Mysplash.getInstance().getTopActivity();
        View container = a.provideSnackbarContainer();

        Snackbar snackbar = Snackbar
                .make(container, content, duration)
                .setAction(action, l);

        Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbar.getView();

        TextView contentTxt = (TextView) snackbarLayout.findViewById(R.id.snackbar_text);
        DisplayUtils.setTypeface(a, contentTxt);

        Button actionBtn = (Button) snackbarLayout.findViewById(R.id.snackbar_action);

        if (Mysplash.getInstance().isLightTheme()) {
            contentTxt.setTextColor(ContextCompat.getColor(a, R.color.colorTextContent_light));
            actionBtn.setTextColor(ContextCompat.getColor(a, R.color.colorTextTitle_light));
            snackbarLayout.setBackgroundResource(R.color.colorRoot_light);
        } else {
            contentTxt.setTextColor(ContextCompat.getColor(a, R.color.colorTextContent_dark));
            actionBtn.setTextColor(ContextCompat.getColor(a, R.color.colorTextTitle_dark));
            snackbarLayout.setBackgroundResource(R.color.colorRoot_dark);
        }

        snackbar.show();
    }
}
 
Example #29
Source File: MainActivity.java    From PixelWatchFace with GNU General Public License v3.0 5 votes vote down vote up
private void syncToWear() {
  //Toast.makeText(this, "something changed, syncing to watch", Toast.LENGTH_SHORT).show();
  Snackbar.make(findViewById(android.R.id.content), "Syncing to watch...", Snackbar.LENGTH_SHORT)
      .show();
  loadPreferences();
  String TAG = "syncToWear";
  DataClient mDataClient = Wearable.getDataClient(this);
  PutDataMapRequest putDataMapReq = PutDataMapRequest.create("/settings");

      /* Reference DataMap retrieval code on the WearOS app
              mShowTemperature = dataMap.getBoolean("show_temperature");
              mUseCelsius = dataMap.getBoolean("use_celsius");
              mShowWeather = dataMap.getBoolean("show_weather");
              */

  putDataMapReq.getDataMap().putLong("timestamp", System.currentTimeMillis());
  putDataMapReq.getDataMap().putBoolean("show_temperature", showTemperature);
  putDataMapReq.getDataMap().putBoolean("use_celsius", useCelsius);
  putDataMapReq.getDataMap().putBoolean("show_weather", showWeather);
  putDataMapReq.getDataMap().putBoolean("show_temperature_decimal", showTemperatureDecimalPoint);
  putDataMapReq.getDataMap().putBoolean("use_thin", useThin);
  putDataMapReq.getDataMap().putBoolean("use_thin_ambient", useThinAmbient);
  putDataMapReq.getDataMap().putBoolean("use_gray_info_ambient", useGrayInfoAmbient);
  putDataMapReq.getDataMap().putBoolean("show_infobar_ambient", showInfoBarAmbient);
  putDataMapReq.getDataMap().putString("dark_sky_api_key", darkSkyAPIKey);
  putDataMapReq.getDataMap().putBoolean("use_dark_sky", useDarkSky);
  putDataMapReq.getDataMap().putBoolean("show_battery", showBattery);
  putDataMapReq.getDataMap().putBoolean("show_wear_icon", showWearIcon);
  putDataMapReq.getDataMap().putBoolean("advanced", advanced);

  putDataMapReq.setUrgent();
  Task<DataItem> putDataTask = mDataClient.putDataItem(putDataMapReq.asPutDataRequest());
  if (putDataTask.isSuccessful()) {
    Log.d(TAG, "Settings synced to wearable");
  }
}
 
Example #30
Source File: LogFeatureActivity.java    From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * check it we have the permission to write data on the sd
 * @return true if we have it, false if we ask for it
 */
public boolean checkWriteSDPermission(final int requestCode){
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {

        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            final View viewRoot = ((ViewGroup) this
                    .findViewById(android.R.id.content)).getChildAt(0);
            Snackbar.make(viewRoot, R.string.WriteSDRationale,
                    Snackbar.LENGTH_INDEFINITE)
                    .setAction(android.R.string.ok, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            ActivityCompat.requestPermissions(LogFeatureActivity.this,
                                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                    requestCode);
                        }//onClick
                    }).show();
        } else {
            // No explanation needed, we can request the permission.
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    requestCode);
        }//if-else
        return false;
    }else
        return  true;
}