Java Code Examples for android.support.v7.app.AppCompatActivity#getString()

The following examples show how to use android.support.v7.app.AppCompatActivity#getString() . 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: MusicUtils.java    From Rey-MusicPlayer with Apache License 2.0 5 votes vote down vote up
public static void setRingtone(AppCompatActivity context, long id) {
    if (!checkSystemWritePermission(context)) return;

    ContentResolver resolver = context.getContentResolver();
    Uri ringUri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id);

    try {
        ContentValues values = new ContentValues(2);
        values.put(MediaStore.Audio.Media.IS_RINGTONE, "1");
        values.put(MediaStore.Audio.Media.IS_ALARM, "1");
        resolver.update(ringUri, values, null, null);
    } catch (UnsupportedOperationException ex) {
        Log.e("Notset", "couldn't set ringtone flag for id " + id);
        return;
    }

    String[] cols = new String[]{
            MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.DATA,
            MediaStore.Audio.Media.TITLE
    };

    String where = MediaStore.Audio.Media._ID + "=" + id;
    Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            cols, where, null, null);
    try {
        if (cursor != null && cursor.getCount() == 1) {
            cursor.moveToFirst();
            Settings.System.putString(resolver, Settings.System.RINGTONE, ringUri.toString());
            String message = context.getString(R.string.ringtone_set);
            String filename = '"' + cursor.getString(2) + '"';
            Toast.makeText(context, filename + " " + message, Toast.LENGTH_SHORT).show();
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example 2
Source File: MarketsListAdapter.java    From CryptoBuddy with GNU Affero General Public License v3.0 5 votes vote down vote up
public MarketsListAdapter(List<MarketNode> markets, AppCompatActivity context, CustomItemClickListener listener) {
    this.markets = markets;
    this.currencyFormatter = CurrencyFormatterSingleton.getInstance(context);
    this.contextRef = new WeakReference<>(context);
    this.listener = listener;
    this.negativePctFormat = context.getString(R.string.negative_pct_format);
    this.positivPctFormat = context.getString(R.string.positive_pct_format);
    this.negativeRedColor = this.contextRef.get().getResources().getColor(R.color.percentNegativeRed);
    this.positiveGreenColor = this.contextRef.get().getResources().getColor(R.color.percentPositiveGreen);
}
 
Example 3
Source File: SqliteManagerPresenter.java    From SqliteManager with Apache License 2.0 4 votes vote down vote up
private String getApplicationName(AppCompatActivity appCompatActivity) {
    ApplicationInfo applicationInfo = appCompatActivity.getApplicationInfo();
    int stringId = applicationInfo.labelRes;
    return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : appCompatActivity.getString(stringId);
}
 
Example 4
Source File: CommonActivityTitleView.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
public CommonActivityTitleView(@NonNull AppCompatActivity activity, @StringRes int resId) {
    this(activity, activity.getString(resId), true);
}
 
Example 5
Source File: CommonActivityTitleView.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
public CommonActivityTitleView(@NonNull AppCompatActivity activity, @StringRes int resId, boolean isSupportScroll) {
    this(activity, activity.getString(resId), isSupportScroll);
}
 
Example 6
Source File: MainTopUtils.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
/**
 * 设置主页顶部的按钮
 *
 * @param activity
 * @param buttonConfig
 */
public static void setMainTopbar(final AppCompatActivity activity, ButtonConfig buttonConfig, ArrayList<Fragment> fragments, int positionInViewPager) {

    if (buttonConfig == null || buttonConfig.getButtonType() == null)
        return;

    Fragment fragment = fragments.get(positionInViewPager);

    int ibEditVisible = View.GONE, tvPreDoVisible = View.GONE, tvDoVisible = View.GONE, ibSignInVisible = View.GONE;
    int ibMenu0Visiable = View.GONE, ibMenu1Visiable = View.GONE;
    tvTitle.setText(buttonConfig.getButtonName());

    resetMainTopMenu();

    switch (buttonConfig.getButtonType()) {
        case BottomButtonType.HOME_PAGE:

            String title = "";
            if (BottomTabMainActivity.NOW_POSITION_IN_VIEWPAGER == 0) {
                title = activity.getString(R.string.forum_name);
            } else if (fragment instanceof WebFragment) {
                title = ((WebFragment) fragment).getWebTitle();
            } else {
                title = buttonConfig.getButtonName();
            }
            tvTitle.setText(title);

            HashMap<String, Integer> visableMenu = MainTopUtils.setActivityTopbarMenu(activity, buttonConfig.getViewTabConfig(), MainTopUtils.ibMenu0, MainTopUtils.ibMenu1);
            if (!MapUtils.isNullOrContainEmpty(visableMenu)) {
                ibMenu0Visiable = visableMenu.get("ibMenu0Visiable");
                ibMenu1Visiable = visableMenu.get("ibMenu1Visiable");
            }
            break;
        case BottomButtonType.FORUM_NAV:
            tvTitle.setText("论坛");
            break;
        case BottomButtonType.MESSAGE:
            tvTitle.setText("消息");
            final MessageFragment messageFragment = (MessageFragment) fragments.get(positionInViewPager);
            //每次切换到这里 都要刷新
            if (AppSPUtils.isLogined(activity))
                messageFragment.refresh();

            messageFragment.initMainMenu();

            ServiceUtils.startClanService(activity, Action.ACTION_CHECK_NEW_MESSAGE);

            break;

        case BottomButtonType.MINE:
            tvTitle.setText("");
            final MineProfileFragment mineProfileFragment = (MineProfileFragment) fragments.get(positionInViewPager);
            mineProfileFragment.initMainMenu();

            break;
    }


    if (ibMenu0Visiable == View.VISIBLE) {
        ibMenu0.setVisibility(View.VISIBLE);
    } else
        ibMenu0.setVisibility(View.GONE);


    if (ibMenu1Visiable == View.VISIBLE) {
        ibMenu1.setVisibility(View.VISIBLE);
    } else
        ibMenu1.setVisibility(View.GONE);


}