Example usage for android.app Activity getString

List of usage examples for android.app Activity getString

Introduction

In this page you can find the example usage for android.app Activity getString.

Prototype

@NonNull
public final String getString(@StringRes int resId) 

Source Link

Document

Returns a localized string from the application's package's default string table.

Usage

From source file:com.activiti.android.app.fragments.HelpDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.app_webview, container, false);

    getToolbar().setVisibility(View.GONE);

    webView = (WebView) v.findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    emptyView = v.findViewById(R.id.empty);
    emptyTextView = (TextView) v.findViewById(R.id.empty_text);
    emptyTextView.setText(Html.fromHtml(getString(R.string.error_offline)));

    final Activity activity = getActivity();

    defaultUrl = activity.getString(R.string.help_user_guide_default_url);

    webView.setWebViewClient(new WebViewClient() {
        boolean hasError = false;

        @Override//from  ww  w.  java2 s  . c om
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            hasError = false;
            getActivity().setProgressBarIndeterminateVisibility(true);
            refreshIcon.setVisible(false);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);

            // We redirect to default EN documentation if locale docs are
            // not available.
            if ((errorCode == ERROR_FILE_NOT_FOUND || errorCode == ERROR_HOST_LOOKUP) && !isDefault
                    && failingUrl.equals(rootUrl)) {
                hasError = true;
                view.loadUrl(defaultUrl);
                view.setVisibility(View.GONE);
            } else if (!ConnectivityUtils.hasInternetAvailable(getActivity())) {
                view.setVisibility(View.GONE);
                emptyView.setVisibility(View.VISIBLE);
                hasError = true;
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (hasError) {
                view.setVisibility(View.GONE);
            } else {
                view.setVisibility(View.VISIBLE);
            }

            if (getActivity() != null) {
                getActivity().setProgressBarIndeterminateVisibility(false);
                refreshIcon.setVisible(true);
            }
        }

        public void onFormResubmission(WebView view, Message dontResend, Message resend) {
            resend.sendToTarget();
        }

    });

    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                        return true;
                    }
                    break;
                }
            }
            return false;
        }
    });

    rootUrl = getUrl(activity);
    webView.loadUrl(rootUrl);

    return v;
}

From source file:io.github.hidroh.materialistic.KeyDelegate.java

/**
 * Attaches this delegate to given activity lifecycle
 * Should call {@link #detach(Activity)} accordingly
 * @param activity    active activity to receive key events
 * @see {@link #detach(Activity)}//from  w w w.j  av  a2 s.co  m
 */
public void attach(Activity activity) {
    mPreferenceKey = activity.getString(R.string.pref_volume);
    mEnabled = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(mPreferenceKey, false);
    PreferenceManager.getDefaultSharedPreferences(activity)
            .registerOnSharedPreferenceChangeListener(mPreferenceListener);
}

From source file:com.codepiex.droidlibx.permission.PermissionRequestor.java

private void showRequestPermissionRationaleDialog(final Activity activity) {

    AlertXUtils.decisionAlertOnMainThread(activity, android.R.drawable.ic_dialog_info, R.string.permission_info,
            appendNote(activity, rationalMessage), activity.getString(R.string.proceed), new OnClickListener() {

                @Override// w w w . j  av a2s.  c o m
                public void onClick(DialogInterface dialog, int which) {
                    requestPermissions(activity, permissions);
                }
            }, activity.getString(R.string.cancel), new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (listener != null) {
                        listener.onPermissionDenied();
                    }
                }
            });

}

From source file:it.imwatch.nfclottery.dialogs.WinnersListDialog.java

/**
 * Shows the UI that asks the user to confirm revoking the
 * victory for the specified position in the list.
 *
 * @param position The position in the list to show the UI for
 *//*  ww w. j av  a  2 s. c  om*/
private void showRevokeVictoryUi(int position) {
    if (mWinnersCursor.moveToPosition(position)) {
        final int nameColIndex = mWinnersCursor.getColumnIndex(NFCMLContent.Geeks.Columns.NAME.getName());
        final int idColIndex = mWinnersCursor.getColumnIndex(NFCMLContent.Geeks.Columns.ID.getName());

        String name = mWinnersCursor.getString(nameColIndex);
        TextView txt_prompt = (TextView) mSwitcher.findViewById(R.id.txt_prompt);
        txt_prompt.setText(getString(R.string.dialog_winners_delete_prompt, name));

        mPendingRevokeId = mWinnersCursor.getInt(idColIndex);

        mSwitcher.showNext();
    } else {
        final Activity activity = getActivity();
        if (activity != null) {
            Toast.makeText(activity, activity.getString(R.string.err_revoke_failed_toast), Toast.LENGTH_SHORT)
                    .show();
        }
        Log.e(TAG, "Unable to revoke victory for contact #" + position + ": unable to move Cursor");
    }
}

From source file:com.brettyin.cardshelper.fragment.SignInFragment.java

private void performSignInWithTransition(View v) {
    final Activity activity = getActivity();

    final Pair[] pairs = TransitionHelper.createSafeTransitionParticipants(activity, true,
            new Pair<>(v, activity.getString(R.string.transition_avatar)));
    ActivityOptions activityOptions = ActivityOptions.makeSceneTransitionAnimation(activity, pairs);
    //CategorySelectionActivity.start(activity, mPlayer, activityOptions);
}

From source file:com.hufeiya.SignIn.fragment.SignInFragment.java

private void performSignInWithTransition(View v) {
    final Activity activity = getActivity();

    final Pair[] pairs = TransitionHelper.createSafeTransitionParticipants(activity, true,
            new Pair<>(v, activity.getString(R.string.transition_avatar)));
    @SuppressWarnings("unchecked")
    ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, pairs);
    CategorySelectionActivity.start(activity, mUser, activityOptions);
}

From source file:com.pinkwerther.support.PinkwertherSupport.java

/** Be careful, is stopped only if called by the same Class again */
public void showLoadingWheel(boolean loading) {
    StackTraceElement[] stack = Thread.currentThread().getStackTrace();
    String name = stack[1].getClassName();
    if (loading) {
        mLoadingWheelCallers.add(name);/*  w w  w  .j a v a  2s  . c o  m*/
    } else {
        if (!mLoadingWheelCallers.remove(name) && PinkwertherActivityInterface.DEVEL)
            Log.e(TAG, name + " can not be removed from mLoadingWheelCallers");
    }
    if (loading && ((mLoadingWheelDialog == null) || (!mLoadingWheelDialog.isShowing()))) {
        Activity activity = (Activity) mPinkwertherActivity;
        mLoadingWheelDialog = ProgressDialog.show(activity, "", activity.getString(R.string.loading), true);
    } else if (!loading && mLoadingWheelCallers.isEmpty()) {
        if ((mLoadingWheelDialog != null) && (mLoadingWheelDialog.isShowing())) {
            mLoadingWheelDialog.cancel();
            mLoadingWheelDialog = null;
        }
    }
}

From source file:com.github.fi3te.iliasdownloader.view.Eula.java

@Override
public MaterialDialog onCreateDialog(Bundle savedInstanceState) {
    setCancelable(false);//from  ww w.j  a  va2s  .c o m

    Activity activity = getActivity();

    PackageInfo versionInfo = getPackageInfo(activity);
    final String eulaKey = EULA_PREFIX + versionInfo.versionCode;
    final SharedPreferences preferences = PreferencesUtil.getPreferences(activity);

    String title = activity.getString(R.string.app_name) + " v" + versionInfo.versionName;

    String message = activity.getString(R.string.eula);

    return new MaterialDialog.Builder(getActivity()).title(title).content(message)
            .positiveText(android.R.string.ok).negativeText(android.R.string.cancel)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putBoolean(eulaKey, true);
                    editor.commit();

                    FragmentManager fm = getFragmentManager();
                    Fragment eula = fm.findFragmentByTag(EULA_FFRAGMENT_TAG);
                    FragmentTransaction ft = fm.beginTransaction();
                    ft.remove(eula);
                    ft.commitAllowingStateLoss();
                    fm.executePendingTransactions();
                }
            }).onNegative(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    getActivity().finishAffinity();
                }
            }).cancelable(false).build();
}

From source file:ir.isilearning.lmsapp.fragment.CategorySelectionFragment.java

private void startQuizActivityWithTransition(Activity activity, View toolbar, Category category) {

    final Pair[] pairs = TransitionHelper.createSafeTransitionParticipants(activity, false,
            new Pair<>(toolbar, activity.getString(R.string.transition_toolbar)));
    @SuppressWarnings("unchecked")
    ActivityOptionsCompat sceneTransitionAnimation = ActivityOptionsCompat
            .makeSceneTransitionAnimation(activity, pairs);

    // Start the activity with the participants, animating from one to the other.
    final Bundle transitionBundle = sceneTransitionAnimation.toBundle();
    Intent startIntent = QuizActivity.getStartIntent(activity, category, mAdapter);
    ActivityCompat.startActivityForResult(activity, startIntent, REQUEST_CATEGORY, transitionBundle);
}

From source file:com.dalaran.annotation.validator.Validator.java

private boolean checkFiled(Activity a, Length length, EditText o) {
    o.setError(null);//from   w  w  w.j  a  v  a  2s .  co m
    String text = o.getText().toString();
    if (text.length() == 0 && length.required()) {
        o.setError(a.getString(length.messageRequired()));
        return true;
    }
    if (text.length() < length.min()) {
        o.setError(a.getString(length.messageMin()));
        return true;
    }

    if (text.length() > length.max()) {
        o.setError(a.getString(length.messageMax()));
        return true;
    }
    return false;
}