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

The following examples show how to use com.google.android.material.snackbar.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
@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 2
Source Project: science-journal   Source File: ActionController.java    License: 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 Project: dynamic-support   Source File: DynamicHintUtils.java    License: 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 4
Source Project: Easy_xkcd   Source File: PrefHelper.java    License: 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 5
Source Project: DevUtils   Source File: SnackbarUtils.java    License: 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 6
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 7
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 8
@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 9
Source Project: MHViewer   Source File: SignInRequiredActivityPreference.java    License: 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 10
@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 11
Source Project: lttrs-android   Source File: LttrsActivity.java    License: 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 12
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 13
Source Project: Maying   Source File: UndoSnackbarManager.java    License: 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 14
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 15
@Override
public void OnFailureRequest(VolleyError error) {
    String message = getString(R.string.request_failed_unknown);
    try {
        message = Utility.parseNetworkError(error, getApplicationContext(), R.string.request_failed, R.string.request_failed_unknown);
    }
    catch (Exception ignored) {}
    Snackbar.make(layout, message, Snackbar.LENGTH_SHORT).show();
}
 
Example 16
Source Project: location-samples   Source File: MainActivity.java    License: 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 17
/**
 * 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;
}
 
Example 18
@Override
protected void onPostExecute(Void result) {
  if (this.showProgress && this.progressDialog != null) {
    this.progressDialog.dismiss();
    this.progressDialog = null;
  }

  Snackbar.make(view, snackbarText, snackbarDuration)
          .setAction(snackbarActionText, this)
          .setActionTextColor(view.getResources().getColor(R.color.white))
          .show();
}
 
Example 19
Source Project: UploadToJitpack   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, AwesomeLib.getInstance().makeAwesome("Nishant"), Snackbar.LENGTH_LONG)
          .setAction("Action", null)
          .show();
    }
  });
}
 
Example 20
Source Project: odyssey   Source File: OdysseyMainActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void requestPermissionExternalStorage() {
    // ask for permissions
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.READ_EXTERNAL_STORAGE)) {

            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
            View layout = findViewById(R.id.drawer_layout);
            if (layout != null) {
                Snackbar sb = Snackbar.make(layout, R.string.permission_request_snackbar_explanation, Snackbar.LENGTH_INDEFINITE);
                sb.setAction(R.string.permission_request_snackbar_button, view -> ActivityCompat.requestPermissions(OdysseyMainActivity.this,
                        new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        PermissionHelper.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE));
                // style the snackbar text
                TextView sbText = sb.getView().findViewById(com.google.android.material.R.id.snackbar_text);
                sbText.setTextColor(ThemeUtils.getThemeColor(this, R.attr.odyssey_color_text_accent));
                sb.show();
            }
        } else {

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    PermissionHelper.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
        }
    }
}
 
Example 21
Source Project: PixelWatchFace   Source File: MainActivity.java    License: 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 22
Source Project: weather   Source File: SnackbarUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Add view to the snackbar.
 * <p>Call it after {@link #show()}</p>
 *
 * @param child  The child view.
 * @param params The params.
 */
public static void addView(@NonNull final View child,
                           @NonNull final ViewGroup.LayoutParams params) {
  final View view = getView();
  if (view != null) {
    view.setPadding(0, 0, 0, 0);
    Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) view;
    layout.addView(child, params);
  }
}
 
Example 23
Source Project: storage-chooser   Source File: MainActivity.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && coordinatorLayout != null && ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        Snackbar.make(coordinatorLayout, "Demo app needs storage permission to display file list", Snackbar.LENGTH_INDEFINITE)
                .setAction("GRANT", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 199);
                    }
                }).show();
    }
}
 
Example 24
Source Project: EdXposedManager   Source File: LogsFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != RESULT_OK) {
        return;
    }
    if (requestCode == REQUEST_CODE) {
        if (data != null) {
            Uri uri = data.getData();
            if (uri != null) {
                try {
                    OutputStream os = requireContext().getContentResolver().openOutputStream(uri);
                    if (os != null) {
                        FileInputStream in = new FileInputStream(LOG_PATH + activatedConfig.get("fileName") + LOG_SUFFIX);
                        byte[] buffer = new byte[1024];
                        int len;
                        while ((len = in.read(buffer)) > 0) {
                            os.write(buffer, 0, len);
                        }
                        os.close();
                    }
                } catch (Exception e) {
                    Snackbar.make(requireView().findViewById(R.id.container), getResources().getString(R.string.logs_save_failed) + "\n" + e.getMessage(), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    }
}
 
Example 25
Source Project: DevUtils   Source File: SnackbarUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 向 Snackbar 布局中添加 View ( Google 不建议, 复杂的布局应该使用 DialogFragment 进行展示 )
 * @param layoutId R.layout.id
 * @param index    添加索引
 * @return {@link SnackbarUtils}
 */
public SnackbarUtils addView(@LayoutRes final int layoutId, final int index) {
    Snackbar snackbar = getSnackbar();
    if (snackbar != null) {
        try {
            // 加载布局文件新建 View
            View view = LayoutInflater.from(snackbar.getView().getContext()).inflate(layoutId, null);
            return addView(view, index);
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "addView");
        }
    }
    return this;
}
 
Example 26
@Override
public void onOutputOOBActionSelected(final OutputOOBAction action) {
    final UnprovisionedMeshNode node = mViewModel.getUnprovisionedMeshNode().getValue();
    if (node != null) {
        try {
            node.setNodeName(mViewModel.getNetworkLiveData().getNodeName());
            setupProvisionerStateObservers(provisioningStatusContainer);
            mProvisioningProgressBar.setVisibility(View.VISIBLE);
            mViewModel.getMeshManagerApi().startProvisioningWithOutputOOB(node, action);
        } catch (IllegalArgumentException ex) {
            mViewModel.displaySnackBar(this, mCoordinatorLayout, ex.getMessage(), Snackbar.LENGTH_LONG);
        }
    }
}
 
Example 27
private void displaySnackBar(@NonNull final ApplicationKey appKey) {
    Snackbar.make(container, getString(R.string.app_key_deleted), Snackbar.LENGTH_LONG)
            .setAction(getString(R.string.undo), view -> {
                mEmptyView.setVisibility(View.INVISIBLE);
                mViewModel.getNetworkLiveData().getMeshNetwork().addAppKey(appKey);
            })
            .setActionTextColor(getResources().getColor(R.color.colorSecondary))
            .show();
}
 
Example 28
private void downloadCollectionSuccess(Context c, DownloadMissionEntity entity) {
    if (Mysplash.getInstance() != null
            && Mysplash.getInstance().getTopActivity() != null) {
        NotificationHelper.showActionSnackbar(
                c.getString(R.string.feedback_download_collection_success),
                c.getString(R.string.check),
                Snackbar.LENGTH_LONG,
                new OnCheckCollectionListener(c, entity.title));
    } else {
        NotificationHelper.sendDownloadCollectionSuccessNotification(c, entity);
    }
}
 
Example 29
@Override
public void onItemSelected(final AdapterView<?> parent, final View view, final int position, final long id) {
	if (position > 0) { // FIXME this is called twice after rotation.
		try {
			final String xml = databaseHelper.getConfiguration(id);
			final Format format = new Format(new HyphenStyle());
			final Serializer serializer = new Persister(format);
			configuration = serializer.read(UartConfiguration.class, xml);
			configurationListener.onConfigurationChanged(configuration);
		} catch (final Exception e) {
			Log.e(TAG, "Selecting configuration failed", e);

			String message;
			if (e.getLocalizedMessage() != null)
				message = e.getLocalizedMessage();
			else if (e.getCause() != null && e.getCause().getLocalizedMessage() != null)
				message = e.getCause().getLocalizedMessage();
			else
				message = "Unknown error";
			final String msg = message;
			Snackbar.make(container, R.string.uart_configuration_loading_failed, Snackbar.LENGTH_INDEFINITE)
					.setAction(R.string.uart_action_details, v ->
							new AlertDialog.Builder(UARTActivity.this)
									.setMessage(msg)
									.setTitle(R.string.uart_action_details)
									.setPositiveButton(R.string.ok, null)
									.show())
					.show();
			return;
		}

		preferences.edit().putLong(PREFS_CONFIGURATION, id).apply();
	}
}
 
Example 30
Source Project: a   Source File: MBaseSimpleActivity.java    License: 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();
}