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:org.catrobat.catroid.utils.UtilMerge.java

private static void showDifferentResolutionDialog(Project projectToMergeFrom, final Activity activity) {
    XmlHeader currentProject = project.getXmlHeader();
    XmlHeader headerFrom = projectToMergeFrom.getXmlHeader();
    final Project copyProjectToMergeFrom = projectToMergeFrom;
    final Activity copyActivity = activity;

    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {

        @Override//from   ww w .  j a v a2s .  co m
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
                if (!checkMergeConflicts(project, copyProjectToMergeFrom, copyActivity)) {
                    Log.d("MERGE", "no mergeConflicts");
                    try {
                        ProjectManager.getInstance()
                                .setProject(appendProjects(project, copyProjectToMergeFrom, copyActivity));
                        ProjectManager.getInstance().saveProject(activity.getApplicationContext());
                    } catch (IOException e) {
                        ToastUtil.showError(copyActivity, R.string.error_merge);
                        Log.e(TAG, "IOException " + e.getMessage());
                    }
                }
                break;
            }
        }
    };
    String question = activity.getString(R.string.error_different_resolutions1) + " "
            + currentProject.getProgramName() + " " + activity.getString(R.string.error_different_resolutions2)
            + " " + currentProject.getVirtualScreenHeight() + "x" + currentProject.getVirtualScreenWidth() + " "
            + activity.getString(R.string.and) + " " + headerFrom.getProgramName() + " "
            + activity.getString(R.string.error_different_resolutions2) + " "
            + headerFrom.getVirtualScreenHeight() + "x" + headerFrom.getVirtualScreenWidth() + ". "
            + activity.getString(R.string.error_different_resolutions3) + " " + currentProject.getProgramName()
            + ".";

    AlertDialog.Builder builder = new CustomAlertDialogBuilder(activity);
    builder.setTitle(R.string.warning);
    builder.setMessage(question);
    builder.setPositiveButton(activity.getString(R.string.main_menu_continue), dialogClickListener);
    builder.setNegativeButton(activity.getString(R.string.abort), dialogClickListener);
    Dialog errorDialog = builder.create();
    errorDialog.show();
}

From source file:org.catrobat.catroid.ui.controller.LookController.java

public void copyLook(int position, ArrayList<LookData> lookDataList, final Activity activity,
        LookFragment fragment) {/*  w  w w .jav a 2 s  .c o  m*/
    LookData lookData = lookDataList.get(position);

    try {
        String projectName = ProjectManager.getInstance().getCurrentProject().getName();

        StorageHandler.getInstance().copyImage(projectName, lookData.getAbsolutePath(), null);

        String imageName = lookData.getLookName() + "_" + activity.getString(R.string.copy_addition);
        String imageFileName = lookData.getLookFileName();

        updateLookAdapter(imageName, imageFileName, lookDataList, fragment);
    } catch (IOException ioException) {
        Utils.showErrorDialog(activity, R.string.error_load_image);
        Log.e(TAG, Log.getStackTraceString(ioException));
    }
    activity.sendBroadcast(new Intent(ScriptActivity.ACTION_BRICK_LIST_CHANGED));
}

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

/**
 * Clears the winner flag from all contacts in the database.
 */// w  w w.j  av a2 s  . c om
private void clearWinners() {
    final Activity activity = getActivity();
    if (activity == null) {
        Log.e(TAG, "Not attached to Activity: cannot clear winners in DB");
        return;
    }

    DataHelper.clearAllWinners(activity);

    if (activity instanceof MainActivity) {
        final MainActivity mainActivity = (MainActivity) activity;
        mainActivity.showCroutonNao(mainActivity.getString(R.string.info_winners_cleared), Style.INFO);
        mainActivity.updateParticipantsCount();
    } else {
        Log.e(TAG, "The parent Activity is not MainActivity! Wat is this I don't even");
        if (DEBUG)
            Log.d(TAG, "Activity class: " + activity.getLocalClassName());
        Toast.makeText(activity, activity.getString(R.string.clear_winners_failed_wrong_parent),
                Toast.LENGTH_SHORT).show();
    }
}

From source file:org.deviceconnect.android.deviceplugin.sphero.setting.fragment.DeviceSelectionPageFragment.java

@Override
public void onClicked(final int position, final Sphero device) {

    Activity activity = getActivity();
    if (activity == null) {
        return;//from ww w  .  j  a  v  a 2s  .co  m
    }

    if (device.isConnected()) {
        ((SettingActivity) activity).sendDisonnectBroadcast(device.getUniqueId());
        if (mAdapter.getCount() == 0) {
            // ???????????.
            stopDiscovery();
            startDiscovery();
        }
    } else {
        mIndView = new ProgressDialog(activity);
        mIndView.setMessage(activity.getString(R.string.connecting));
        mIndView.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        mIndView.setCancelable(false);
        mIndView.show();
        ((SettingActivity) activity).sendConnectBroadcast(device.getUniqueId());
    }
}

From source file:jahirfiquitiva.iconshowcase.activities.ViewerActivity.java

private void saveWallpaper(final Activity context, final String wallName, final MaterialDialog downloadDialog,
        final Bitmap result) {
    downloadDialog.setContent(context.getString(R.string.saving_wallpaper));
    new Thread(new Runnable() {
        @Override// w  w  w  .  ja v a  2s  .c  om
        public void run() {
            if (mPrefs.getDownloadsFolder() != null) {
                downloadsFolder = new File(mPrefs.getDownloadsFolder());
            } else {
                downloadsFolder = new File(context.getString(R.string.walls_save_location,
                        Environment.getExternalStorageDirectory().getAbsolutePath()));
            }
            //noinspection ResultOfMethodCallIgnored
            downloadsFolder.mkdirs();
            final File destFile = new File(downloadsFolder, wallName + ".png");
            String snackbarText;
            if (!destFile.exists()) {
                try {
                    result.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(destFile));
                    snackbarText = context.getString(R.string.wallpaper_downloaded, destFile.getAbsolutePath());
                } catch (final Exception e) {
                    snackbarText = context.getString(R.string.error);
                }
            } else {
                snackbarText = context.getString(R.string.wallpaper_downloaded, destFile.getAbsolutePath());
            }
            final String finalSnackbarText = snackbarText;
            context.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    downloadDialog.dismiss();

                    if (toHide1 != null && toHide2 != null) {
                        toHide1.setVisibility(View.GONE);
                        toHide2.setVisibility(View.GONE);
                    }

                    Snackbar longSnackbar = Snackbar.make(layout, finalSnackbarText, Snackbar.LENGTH_LONG);
                    final int snackbarLight = ContextCompat.getColor(context, R.color.snackbar_light);
                    final int snackbarDark = ContextCompat.getColor(context, R.color.snackbar_dark);
                    ViewGroup snackbarView = (ViewGroup) longSnackbar.getView();
                    snackbarView.setBackgroundColor(ThemeUtils.darkTheme ? snackbarDark : snackbarLight);
                    longSnackbar.show();
                    longSnackbar.setCallback(new Snackbar.Callback() {
                        @Override
                        public void onDismissed(Snackbar snackbar, int event) {
                            super.onDismissed(snackbar, event);
                            if (toHide1 != null && toHide2 != null) {
                                toHide1.setVisibility(View.VISIBLE);
                                toHide2.setVisibility(View.VISIBLE);
                            }
                        }
                    });
                }
            });
        }
    }).start();
}

From source file:hku.fyp14017.blencode.ui.controller.LookController.java

public void copyLook(int position, ArrayList<LookData> lookDataList, final Activity activity,
        LookFragment fragment) {/*w w w.  j  ava  2 s . c  o  m*/
    LookData lookData = lookDataList.get(position);

    try {
        String projectName = ProjectManager.getInstance().getCurrentProject().getName();

        StorageHandler.getInstance().copyImage(projectName, lookData.getAbsolutePath(), null);

        String imageName = lookData.getLookName() + "_"
                + activity.getString(hku.fyp14017.blencode.R.string.copy_addition);
        String imageFileName = lookData.getLookFileName();

        updateLookAdapter(imageName, imageFileName, lookDataList, fragment);
    } catch (IOException ioException) {
        Utils.showErrorDialog(activity, hku.fyp14017.blencode.R.string.error_load_image);
        Log.e(TAG, Log.getStackTraceString(ioException));
    }
    activity.sendBroadcast(new Intent(ScriptActivity.ACTION_BRICK_LIST_CHANGED));
}

From source file:com.rincliu.library.common.reference.social.weibo.RLWeiboHelper.java

/**
 * @param activity// w  ww .  j av  a  2  s  .com
 * @param handler
 * @return
 */
public SsoHandler auth(final Activity activity, final ReqHandler handler) {
    SsoHandler ssoHandler = new SsoHandler(activity, weibo);
    ssoHandler.authorize(new WeiboAuthListener() {
        @Override
        public void onComplete(Bundle data) {
            AccessTokenKeeper.clear(activity);
            Oauth2AccessToken token = new Oauth2AccessToken(data.getString("access_token"),
                    data.getString("expires_in"));
            AccessTokenKeeper.keepAccessToken(activity, token);
            handler.onSucceed();
        }

        @Override
        public void onCancel() {
            handler.onFail(activity.getString(R.string.weibo_auth_cancel));
        }

        @Override
        public void onError(WeiboDialogError error) {
            handler.onFail(error.getMessage());
        }

        @Override
        public void onWeiboException(WeiboException exception) {
            handler.onFail(exception.getMessage());
        }
    });
    return ssoHandler;
}

From source file:jahirfiquitiva.iconshowcase.activities.WallpaperViewerActivity.java

private void saveWallpaper(final Activity context, final String wallName, final MaterialDialog downloadDialog,
        final Bitmap result) {
    downloadDialog.setContent(context.getString(R.string.saving_wallpaper));
    new Thread(new Runnable() {
        @Override//ww w  . j  a  va2 s .c  o m
        public void run() {
            if (mPrefs.getDownloadsFolder() != null) {
                downloadsFolder = new File(mPrefs.getDownloadsFolder());
            } else {
                downloadsFolder = new File(context.getString(R.string.walls_save_location,
                        Environment.getExternalStorageDirectory().getAbsolutePath()));
            }
            //noinspection ResultOfMethodCallIgnored
            downloadsFolder.mkdirs();
            final File destFile = new File(downloadsFolder, wallName + ".png");
            String snackbarText;
            if (!destFile.exists()) {
                try {
                    result.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(destFile));
                    snackbarText = context.getString(R.string.wallpaper_downloaded, destFile.getAbsolutePath());
                } catch (final Exception e) {
                    snackbarText = context.getString(R.string.error);
                }
            } else {
                snackbarText = context.getString(R.string.wallpaper_downloaded, destFile.getAbsolutePath());
            }
            final String finalSnackbarText = snackbarText;
            context.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    downloadDialog.dismiss();

                    if (toHide1 != null && toHide2 != null) {
                        toHide1.setVisibility(View.GONE);
                        toHide2.setVisibility(View.GONE);
                    }

                    Utils.snackbar(context, layout, finalSnackbarText, Snackbar.LENGTH_LONG)
                            .setCallback(new Snackbar.Callback() {
                                @Override
                                public void onDismissed(Snackbar snackbar, int event) {
                                    super.onDismissed(snackbar, event);
                                    if (toHide1 != null && toHide2 != null) {
                                        toHide1.setVisibility(View.VISIBLE);
                                        toHide2.setVisibility(View.VISIBLE);
                                    }
                                }
                            }).show();
                }
            });
        }
    }).start();
}

From source file:pl.wasat.smarthma.adapter.SearchListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final Activity activity = (Activity) getContext();
    LayoutInflater inflater = activity.getLayoutInflater();

    View rowView = inflater.inflate(R.layout.view_cell_collection_search, parent, false);
    final EntryISO searchItem = getItem(position);

    TextView textView = (TextView) rowView.findViewById(R.id.search_list_name);
    textView.setText(searchItem.getTitle());

    TextView dateView = (TextView) rowView.findViewById(R.id.search_listing_smallprint);

    /*        final String pubDate = "These data were published: %1$s  and updated: %1$s"
        + DateUtils.getISOPubDate(searchItem) + " and updated: "
        + searchItem.getUpdated();*/
    final String pubDate = String.format(activity.getString(R.string.these_data_are_published_and_updated),
            DateUtils.getISOPubDate(searchItem), searchItem.getUpdated());
    dateView.setText(pubDate);//from   www  . j  a  va 2  s  .c o  m

    if (!searchItem.isNotRead()) {
        View row = rowView.findViewById(R.id.view_cell_collection_search_row_background);
        row.setBackgroundColor(ContextCompat.getColor(activity, R.color.row_selected));
    }

    final ImageView button = (ImageView) rowView.findViewById(R.id.star_button);
    updateFavourite(searchItem.isFavourite(), button, activity);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setFavourite(!searchItem.isFavourite(), button, activity, searchItem);
            FavouritesDbAdapter dba = new FavouritesDbAdapter(activity);
            if (searchItem.isFavourite()) {
                dba.openToWrite();
                dba.insertEntry(searchItem);
                dba.close();
                Toast.makeText(activity, activity.getString(R.string.collection_added_to_favourites),
                        Toast.LENGTH_LONG).show();
            } else {
                dba.openToWrite();
                dba.removeEntry(searchItem);
                dba.close();
            }
            dba.openToRead();
            dba.close();
        }
    });
    SwipeDetector swipeDetector = new SwipeDetector(rowView, position);
    swipeDetector.setOnClickListener(listener);
    rowView.setOnTouchListener(swipeDetector);
    return rowView;
}

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

/**
 * Clears the database.//from   w ww.j a v a  2s.c om
 */
private void clearDB() {
    final Activity activity = getActivity();
    if (activity == null) {
        Log.e(TAG, "Not attached to Activity: cannot clear DB");
        return;
    }

    ContentResolver cr = activity.getContentResolver();
    cr.delete(NFCMLContent.Geeks.CONTENT_URI, null, null);

    if (activity instanceof MainActivity) {
        final MainActivity mainActivity = (MainActivity) activity;
        mainActivity.showCroutonNao(mainActivity.getString(R.string.info_db_cleared), Style.INFO);
        mainActivity.updateParticipantsCount();
    } else {
        Log.e(TAG, "The parent Activity is not MainActivity! Wat is this I don't even");
        if (DEBUG)
            Log.d(TAG, "Activity class: " + activity.getLocalClassName());
        Toast.makeText(activity, activity.getString(R.string.clear_db_failed_wrong_parent), Toast.LENGTH_SHORT)
                .show();
    }
}