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:ir.isilearning.lmsapp.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, mPlayer, activityOptions);
}

From source file:com.amazon.android.ui.fragments.LogoutSettingsFragment.java

/**
 * Creates a {@link ReadDialogFragment} and attaches it to the fragment manager.
 *
 * @param activity The activity.//w w  w. jav  a  2  s. co m
 * @param layout   The layout id.
 * @param manager  The fragment manager.
 */
private void setUpDialog(Activity activity, FragmentManager manager, int layout) {

    final ReadDialogFragment dialog = new ReadDialogFragment();
    dialog.setDialogLayout(R.layout.simple_dialog_layout);
    dialog.setContentViewProvider(getSingleViewProvider(dialog, activity, layout));
    dialog.setArguments(getArguments(getDefaultHeight(activity, layout), getDefaultWidth(activity)));
    commitFragment(manager, dialog, activity.getString(R.string.logout_settings_fragment_tag));

}

From source file:org.webinos.android.app.wrt.ui.WidgetListActivity.java

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.activity_widget_list);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);
    } else {// www . ja v  a2  s . c  o m
        Log.i(TAG, "WidgetListActivity has no action bar.");
    }

    registerForContextMenu(getListView());
    asyncRefreshHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            initList();
        }
    };
    mgr = WidgetManagerService.getWidgetManagerInstance(this, this);
    if (mgr != null) {
        mgr.addEventListener(this);
        initList();
    }

    scanner = new WidgetImportHelper(this);

    /* populate stores array */
    stores = getStores();

    synchronized (this) {
        if (mgr == null) {
            blocked = true;
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    /* put up progress dialog until the service is
                     * available */
                    Activity context = WidgetListActivity.this;
                    progressDialog = new ProgressDialog(context);
                    progressDialog.setCancelable(false);
                    progressDialog.setMessage(context.getString(R.string.initialising_runtime));
                    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                    progressDialog.setIndeterminate(false);
                    progressDialog.setMax(PROGRESS_MAX);
                    progressDialog.show();
                    progressDialog.setProgressNumberFormat(null);
                }
            });
        }
    }

    /* BroadcastReceiver to receive module loading progress */
    progressBroadcastReceiver = new ProgressBroadcastReceiver();
}

From source file:com.facebook.login.LoginClient.java

boolean checkInternetPermission() {
    if (checkedInternetPermission) {
        return true;
    }//from   ww w  .  j a  va  2  s  .  c  o  m

    int permissionCheck = checkPermission(Manifest.permission.INTERNET);
    if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
        Activity activity = getActivity();
        String errorType = activity.getString(R.string.com_facebook_internet_permission_error_title);
        String errorDescription = activity.getString(R.string.com_facebook_internet_permission_error_message);
        complete(Result.createErrorResult(pendingRequest, errorType, errorDescription));

        return false;
    }

    checkedInternetPermission = true;
    return true;
}

From source file:mobile.client.iot.pzalejko.iothome.mqtt.event.InEventReceiver.java

public InEventReceiver(Activity context, LocalBroadcastManager broadcaster, MqttServiceConnection connection) {
    this.connection = connection;
    this.broadcaster = broadcaster;

    temperatureView = (TextView) context.findViewById(R.id.temperatureTextView);
    connectingTextView = (TextView) context.findViewById(R.id.connectingTextView);
    ledImageView = (ImageView) context.findViewById(R.id.ledImageView);
    temperatureAlertView = (TextView) context.findViewById(R.id.tempAlertValueText);

    if (temperatureAlertView == null) {
        throw new IllegalStateException(context.getString(R.string.temperature_view_missing));
    }//from ww  w . ja  v a2  s  . com

    if (connectingTextView == null) {
        throw new IllegalStateException(context.getString(R.string.connecting_status_view_missing));
    }

    if (ledImageView == null) {
        throw new IllegalStateException(context.getString(R.string.led_status_view_missing));
    }

    if (temperatureAlertView == null) {
        throw new IllegalStateException(context.getString(R.string.temperature_alert_view_missing));
    }

    dateFormat = new SimpleDateFormat(context.getString(R.string.dateFormat));
    isAlertValueObtained = false;
}

From source file:net.kourlas.voipms_sms.Notifications.java

/**
 * Enable SMS notifications by configuring the VoIP.ms URL callback, registering for GCM and making the appropriate
 * changes to the application preferences.
 *
 * @param activity The source activity./*  w  ww.j  ava2s .  c  om*/
 */
public void enableNotifications(final Activity activity) {
    if (preferences.getEmail().equals("") || preferences.getPassword().equals("")
            || preferences.getDid().equals("")) {
        Utils.showInfoDialog(activity,
                applicationContext.getString(R.string.notifications_callback_username_password_did));
        return;
    }

    final ProgressDialog progressDialog = new ProgressDialog(activity);
    progressDialog.setMessage(activity.getString(R.string.notifications_callback_progress));
    progressDialog.setCancelable(false);
    progressDialog.show();

    new AsyncTask<Boolean, Void, Boolean>() {
        @Override
        protected Boolean doInBackground(Boolean... params) {
            try {
                String url = "https://www.voip.ms/api/v1/rest.php?" + "api_username="
                        + URLEncoder.encode(preferences.getEmail(), "UTF-8") + "&" + "api_password="
                        + URLEncoder.encode(preferences.getPassword(), "UTF-8") + "&" + "method=setSMS" + "&"
                        + "did=" + URLEncoder.encode(preferences.getDid(), "UTF-8") + "&" + "enable=1" + "&"
                        + "url_callback_enable=1" + "&" + "url_callback=" + URLEncoder
                                .encode("http://voipmssms-kourlas.rhcloud.com/sms_callback?did={TO}", "UTF-8")
                        + "&" + "url_callback_retry=0";

                JSONObject result = Utils.getJson(url);
                String status = result.optString("status");
                return !(status == null || !status.equals("success"));
            } catch (Exception ex) {
                return false;
            }
        }

        @Override
        protected void onPostExecute(Boolean success) {
            progressDialog.hide();

            DialogInterface.OnClickListener gcmOnClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    gcm.registerForGcm(activity, true, true);
                }
            };

            if (!success) {
                Utils.showAlertDialog(activity, null,
                        applicationContext.getString(R.string.notifications_callback_fail),
                        applicationContext.getString(R.string.ok), gcmOnClickListener, null, null);
            } else {
                Utils.showAlertDialog(activity, null,
                        applicationContext.getString(R.string.notifications_callback_success),
                        applicationContext.getString(R.string.ok), gcmOnClickListener, null, null);
            }
        }
    }.execute();
}

From source file:com.gelakinetic.mtgfam.helpers.ZipUtils.java

/**
 * This method exports any data in this application's getFilesDir() into a zip file on external storage
 *
 * @param activity The application activity, for getting files and the like
 *///from  www.  j  av  a2s .  c  o m
public static void exportData(Activity activity) {

    /* Make sure external storage exists */
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        ToastWrapper.makeAndShowText(activity, R.string.card_view_no_external_storage,
                ToastWrapper.LENGTH_LONG);
        return;
    }

    /* Check if permission is granted */
    if (ContextCompat.checkSelfPermission(activity,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        /* Request the permission */
        ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                FamiliarActivity.REQUEST_WRITE_EXTERNAL_STORAGE_BACKUP);
        return;
    }

    assert activity.getFilesDir() != null;

    String sharedPrefsDir = activity.getFilesDir().getPath();
    sharedPrefsDir = sharedPrefsDir.substring(0, sharedPrefsDir.lastIndexOf("/")) + "/shared_prefs/";

    ArrayList<File> files = findAllFiles(activity.getFilesDir(), new File(sharedPrefsDir));

    File sdCard = Environment.getExternalStorageDirectory();
    File zipOut = new File(sdCard, BACKUP_FILE_NAME);
    if (zipOut.exists()) {
        if (!zipOut.delete()) {
            return;
        }
    }
    try {
        zipIt(zipOut, files, activity);
        ToastWrapper.makeAndShowText(activity,
                activity.getString(R.string.main_export_success) + " " + zipOut.getAbsolutePath(),
                ToastWrapper.LENGTH_SHORT);
    } catch (ZipException e) {
        if (e.getMessage().equals("No entries")) {
            ToastWrapper.makeAndShowText(activity, R.string.main_export_no_data, ToastWrapper.LENGTH_SHORT);
        } else {
            ToastWrapper.makeAndShowText(activity, R.string.main_export_fail, ToastWrapper.LENGTH_SHORT);
        }
    } catch (IOException e) {
        ToastWrapper.makeAndShowText(activity, R.string.main_export_fail, ToastWrapper.LENGTH_SHORT);
    }
}

From source file:com.google.plus.wigwamnow.social.FacebookProvider.java

/**
 * Handle a Facebook error and display an appropriate dialog to the user.
 *
 * @param error the error to handle./*from w  w  w .  j  a v a 2s .  c o  m*/
 */
private void handleError(FacebookRequestError error, final Activity activity) {
    String dialogBody = null;
    DialogInterface.OnClickListener listener = null;

    if (error == null) {
        // There was no response from the server
        dialogBody = activity.getString(R.string.error_dialog_default_text);
    } else {
        switch (error.getCategory()) {
        case AUTHENTICATION_RETRY:
            // Tell the user what happened by getting the message id and retry the operation
            // later
            String userAction = error.shouldNotifyUser() ? ""
                    : activity.getString(error.getUserActionMessageId());
            dialogBody = activity.getString(R.string.error_authentication_retry, userAction);

            listener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    // Go to the Facebook mobile site
                    Intent intent = new Intent(Intent.ACTION_VIEW, M_FACEBOOK_URL);
                    activity.startActivity(intent);
                }
            };
            break;

        case AUTHENTICATION_REOPEN_SESSION:
            // Close the session and reopen it
            dialogBody = activity.getString(R.string.error_authentication_reopen);
            listener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Session session = Session.getActiveSession();
                    if (session != null && !session.isClosed()) {
                        session.closeAndClearTokenInformation();
                    }
                }
            };
            break;

        case PERMISSION:
            // Error related to permissions
            dialogBody = activity.getString(R.string.error_permission);
            listener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    // TODO(samstern): Set this in the activity
                    // mPendingStructuredShare = true;
                    requestPublishPermissions(Session.getActiveSession(), activity);
                }
            };
            break;

        case SERVER:
        case THROTTLING:
            // This error is usually temporary, just ask the user to try again
            dialogBody = activity.getString(R.string.error_server);
            break;

        case BAD_REQUEST:
            // Coding error, ask the user to file a bug if appropriate
            dialogBody = activity.getString(R.string.error_bad_request, error.getErrorMessage());
            break;

        case OTHER:
        case CLIENT:
        default:
            // An unknown issue occurred. Could be a coding error or server side.
            dialogBody = activity.getString(R.string.error_unknown, error.getErrorMessage());
            break;
        }

        // Show the error dialog
        new AlertDialog.Builder(activity).setPositiveButton("OK", listener).setTitle("Error")
                .setMessage(dialogBody).show();
    }
}

From source file:org.thialfihar.android.apg.ui.dialog.ProgressDialogFragment.java

/**
 * Creates dialog//from w ww  .  j  ava  2s . c  om
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();

    ProgressDialog dialog = new ProgressDialog(activity);
    dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);

    String message = getArguments().getString(ARG_MESSAGE);
    int style = getArguments().getInt(ARG_STYLE);
    boolean cancelable = getArguments().getBoolean(ARG_CANCELABLE);

    dialog.setMessage(message);
    dialog.setProgressStyle(style);

    if (cancelable) {
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, activity.getString(R.string.progress_cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
    }

    // Disable the back button
    OnKeyListener keyListener = new OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                return true;
            }
            return false;
        }

    };
    dialog.setOnKeyListener(keyListener);

    return dialog;
}

From source file:com.enstage.wibmo.sdk.inapp.InAppInitActivity.java

@Override
public void onBackPressed() {
    final Activity activity = this;
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setMessage(activity.getString(R.string.confirm_iap_cancel)).setCancelable(false)
            .setPositiveButton(activity.getString(R.string.label_yes), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    sendAbort("sdk init - backpress");
                }//w w  w.ja  va  2s .c o m
            }).setNegativeButton(activity.getString(R.string.label_no), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // User cancelled the dialog
                    if (dialog != null) {
                        try {
                            dialog.dismiss();
                        } catch (IllegalArgumentException e) {
                            Log.e(TAG, "Error: " + e);
                        }
                    }
                }
            });

    Dialog dialog = builder.create();
    try {
        dialog.show();
    } catch (Throwable e) {
        Log.e(TAG, "Error: " + e, e);

        sendAbort("sdk init - backpress");
    }
}