Java Code Examples for com.blankj.utilcode.util.SPUtils

The following examples show how to use com.blankj.utilcode.util.SPUtils. 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
Source Project: YCAudioPlayer   Source File: DebugActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initData() {
    int anInt = SPUtils.getInstance(Constant.SP_NAME).getInt(SELECT_STATUS);
    switch (anInt){
        case 1001:
            changeTest.setChecked(true);
            changePreview.setChecked(false);
            changeRelease.setChecked(false);
            break;
        case 2001:
            changeTest.setChecked(false);
            changePreview.setChecked(true);
            changeRelease.setChecked(false);
            break;
        case 3001:
            changeTest.setChecked(false);
            changePreview.setChecked(false);
            changeRelease.setChecked(true);
            break;
        default:
            changeTest.setChecked(true);
            changePreview.setChecked(false);
            changeRelease.setChecked(false);
            break;
    }
}
 
Example 2
Source Project: YCAudioPlayer   Source File: DebugActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.ll_title_menu:
            finish();
            break;
        case R.id.change_test:
            SPUtils.getInstance(Constant.SP_NAME).put(SELECT_STATUS, 1001);
            break;
        case R.id.change_preview:
            SPUtils.getInstance(Constant.SP_NAME).put(SELECT_STATUS, 2001);
            break;
        case R.id.change_release:
            SPUtils.getInstance(Constant.SP_NAME).put(SELECT_STATUS, 3001);
            break;
        case R.id.tv_restart_app:
            RestartAppUtils.restartAPP(this);
            break;
        default:
            break;
    }
}
 
Example 3
Source Project: YCAudioPlayer   Source File: PlayService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 播放索引为position的音乐
 * @param position              索引
 */
public void play(int position) {
    if (audioMusics.isEmpty()) {
        return;
    }

    if (position < 0) {
        position = audioMusics.size() - 1;
    } else if (position >= audioMusics.size()) {
        //如果是最后一首音乐,则播放时直接播放第一首音乐
        position = 0;
    }

    mPlayingPosition = position;
    AudioBean music = audioMusics.get(mPlayingPosition);
    String id = music.getId();
    LogUtils.e("PlayService"+"----id----"+ id);
    //保存当前播放的musicId,下次进来可以记录状态
    long musicId = Long.parseLong(id);
    SPUtils.getInstance(Constant.SP_NAME).put(Constant.MUSIC_ID,musicId);
    play(music);
}
 
Example 4
Source Project: YCAudioPlayer   Source File: AppInfoService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<AppInfo> getAppInfo(String sign) throws RemoteException {
    List<AppInfo> list=new ArrayList<>();
    String aidlCheckAppInfoSign = AppToolUtils.getAidlCheckAppInfoSign();
    LogUtils.e("AppInfoService--AppInfoService",aidlCheckAppInfoSign+"-------------"+sign);
    if(!aidlCheckAppInfoSign.equals(sign)){
        return list;
    }
    list.add(new AppInfo("app版本号(versionName)", BuildConfig.VERSION_NAME));
    list.add(new AppInfo("app版本名称(versionCode)", BuildConfig.VERSION_CODE+""));
    list.add(new AppInfo("打包时间", BuildConfig.BUILD_TIME));
    list.add(new AppInfo("app包名", getPackageName()));
    list.add(new AppInfo("app作者", SPUtils.getInstance(Constant.SP_NAME).getString("name","杨充")));
    list.add(new AppInfo("app渠道", SPUtils.getInstance(Constant.SP_NAME).getString("channel")));
    list.add(new AppInfo("token", SPUtils.getInstance(Constant.SP_NAME).getString("token")));
    list.add(new AppInfo("App签名", AppToolUtils.getSingInfo(getApplicationContext(), getPackageName(), AppToolUtils.SHA1)));
    return list;
}
 
Example 5
Source Project: YCAudioPlayer   Source File: PlayMusicFragment.java    License: Apache License 2.0 6 votes vote down vote up
private void switchPlayMode() {
    int playMode = SPUtils.getInstance(Constant.SP_NAME).getInt(Constant.PLAY_MODE, 0);
    PlayModeEnum mode = PlayModeEnum.valueOf(playMode);
    switch (mode) {
        case LOOP:
            mode = PlayModeEnum.SHUFFLE;
            ToastUtils.showShort(R.string.mode_shuffle);
            break;
        case SHUFFLE:
            mode = PlayModeEnum.SINGLE;
            ToastUtils.showShort(R.string.mode_one);
            break;
        case SINGLE:
            mode = PlayModeEnum.LOOP;
            ToastUtils.showShort(R.string.mode_loop);
            break;
        default:
            break;
    }
    SPUtils.getInstance(Constant.SP_NAME).put(Constant.PLAY_MODE, mode.value());
    initPlayMode();
}
 
Example 6
Source Project: YCAudioPlayer   Source File: PlayService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 下一首
 * 记住有播放类型,单曲循环,顺序循环,随机播放
 * 逻辑:如果不是最后一首,则还有下一首;如果是最后一首,则切换回第一首
 */
public void next() {
    //建议都添加这个判断
    if (audioMusics.isEmpty()) {
        return;
    }
    int playMode = SPUtils.getInstance(Constant.SP_NAME).getInt(Constant.PLAY_MODE, 0);
    int size = audioMusics.size();
    PlayModeEnum mode = PlayModeEnum.valueOf(playMode);
    switch (mode) {
        //随机
        case SHUFFLE:
            mPlayingPosition = new Random().nextInt(size);
            play(mPlayingPosition);
            break;
        //单曲
        case SINGLE:
            play(mPlayingPosition);
            break;
        //顺序播放并且循环
        case LOOP:
        default:
            if (mPlayingPosition != size - 1) {
                // 如果不是最后一首,则还有下一首
                mPlayingPosition++;
            } else {
                // 如果是最后一首,则切换回第一首
                mPlayingPosition = 0;
            }
            LogUtils.e("PlayService"+"----mPlayingPosition----"+ mPlayingPosition);
            play(mPlayingPosition);
            break;
    }
}
 
Example 7
Source Project: YCAudioPlayer   Source File: AppInfoService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean setChannel(String sign, String channel) throws RemoteException {
    if(!AppToolUtils.getAidlCheckAppInfoSign().equals(sign)){
        return false;
    }
    SPUtils.getInstance(Constant.SP_NAME).put("channel",channel);
    LogUtils.i("AppInfoService--setChannel:"+ channel);
    return true;
}
 
Example 8
Source Project: YCAudioPlayer   Source File: AppInfoService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean setAppAuthorName(String sign, String name) throws RemoteException {
    if(!AppToolUtils.getAidlCheckAppInfoSign().equals(sign)){
        return false;
    }
    SPUtils.getInstance(Constant.SP_NAME).put("name",name);
    LogUtils.i("AppInfoService--setAppAuthorName:"+ name);
    return true;
}
 
Example 9
Source Project: YCAudioPlayer   Source File: SplashPagerActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void initView() {
    if(SPUtils.getInstance(Constant.SP_NAME).getBoolean(Constant.KEY_FIRST_SPLASH,true)){
        initGetImage();
        initBanner();
    } else {
        ActivityUtils.startActivity(GuideActivity.class);
        finish();
    }
}
 
Example 10
Source Project: youqu_master   Source File: SplashActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    super.handleMessage(msg);
    boolean isFirst=SPUtils.getInstance().getBoolean(AppConstant.IS_FIRST_ENTER,true);
    if(isFirst){
        TaskStackBuilder.create(SplashActivity.this)
                .addNextIntentWithParentStack(new Intent(SplashActivity.this, MainActivity.class))
                .addNextIntent(new Intent(SplashActivity.this, IntroActivity.class))
                .startActivities();
        finish();
    }else{
        startActivity(MainActivity.class);
        finish();
    }
}
 
Example 11
Source Project: DanDanPlayForAndroid   Source File: ExoPlayerView.java    License: MIT License 5 votes vote down vote up
private void initViewBefore(Context context) {
    if (!(context instanceof AppCompatActivity)) {
        throw new IllegalArgumentException("Context must be AppCompatActivity");
    }
    //是否使用surface view
    isUseSurfaceView = SPUtils.getInstance().getBoolean("surface_renders", true);
    //获取绑定的Activity实例
    mAttachActivity = (AppCompatActivity) context;
    //加载布局
    View.inflate(context, R.layout.layout_exo_player_view, this);
    //获取播放器实例,ffmpeg扩展不支持TextureView
    exoPlayer = isUseSurfaceView
            ? new ExoFFmpegPlayer(mAttachActivity, trackSelector)
            : ExoPlayerFactory.newSimpleInstance(mAttachActivity, trackSelector);
    //屏幕翻转控制
    mOrientationListener = new OrientationEventListener(mAttachActivity) {
        @Override
        public void onOrientationChanged(int orientation) {
            if (mIsNeverPlay) {
                return;
            }
            // 根据角度进行横屏切换
            if (orientation >= 60 && orientation <= 120) {
                mAttachActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
            } else if (orientation >= 240 && orientation <= 300) {
                mAttachActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            }
        }
    };
    //声音管理器
    mAudioManager = (AudioManager) mAttachActivity.getSystemService(Context.AUDIO_SERVICE);
    if (mAudioManager != null)
        mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
}
 
Example 12
Source Project: DanDanPlayForAndroid   Source File: AppConfig.java    License: MIT License 5 votes vote down vote up
/**
 * 上次播放的视频
 */
public String getLastPlayVideo() {
    if (lastPlayPath == null) {
        lastPlayPath = SPUtils.getInstance().getString(Constants.Config.LAST_PLAY_VIDEO_PATH, "");
    }
    return lastPlayPath;
}
 
Example 13
Source Project: Socket.io-FLSocketIM-Android   Source File: LoginActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void initView() {
    super.initView();


    userName.setText(SPUtils.getInstance().getString("username"));
    password.setText(SPUtils.getInstance().getString("password"));
}
 
Example 14
Source Project: DanDanPlayForAndroid   Source File: AppConfig.java    License: MIT License 5 votes vote down vote up
/**
 * 上次使用的SMB连接工具
 */
public SmbType getSmbTools() {
    String typeStr = SPUtils.getInstance().getString(Constants.Config.SMB_TOOLS_TYPE);
    if (!TextUtils.isEmpty(typeStr)){
        return SmbType.valueOf(typeStr);
    }
    return SmbType.SMBJ_RPC;
}
 
Example 15
Source Project: YCAudioPlayer   Source File: FileMusicScanManager.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 扫描歌曲
 */
@NonNull
public List<AudioBean> scanMusic(Context context) {
    List<AudioBean> musicList = new ArrayList<>();
    String mFilterSize = SPUtils.getInstance(Constant.SP_NAME).getString(Constant.FILTER_SIZE,"0");
    String mFilterTime = SPUtils.getInstance(Constant.SP_NAME).getString(Constant.FILTER_TIME,"0");

    long filterSize = parseLong(mFilterSize) * 1024;
    long filterTime = parseLong(mFilterTime) * 1000;

    Cursor cursor = context.getContentResolver().query(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            new String[]{
                    BaseColumns._ID,
                    MediaStore.Audio.AudioColumns.IS_MUSIC,
                    MediaStore.Audio.AudioColumns.TITLE,
                    MediaStore.Audio.AudioColumns.ARTIST,
                    MediaStore.Audio.AudioColumns.ALBUM,
                    MediaStore.Audio.AudioColumns.ALBUM_ID,
                    MediaStore.Audio.AudioColumns.DATA,
                    MediaStore.Audio.AudioColumns.DISPLAY_NAME,
                    MediaStore.Audio.AudioColumns.SIZE,
                    MediaStore.Audio.AudioColumns.DURATION
            },
            SELECTION,
            new String[]{String.valueOf(filterSize), String.valueOf(filterTime)},
            MediaStore.Audio.Media.DEFAULT_SORT_ORDER);

    if (cursor == null) {
        return musicList;
    }

    int i = 0;
    while (cursor.moveToNext()) {
        // 是否为音乐,魅族手机上始终为0
        int isMusic = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.AudioColumns.IS_MUSIC));
        if (!isFly() && isMusic == 0) {
            continue;
        }

        long id = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
        String title = cursor.getString((cursor.getColumnIndex(MediaStore.Audio.AudioColumns.TITLE)));
        String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.AudioColumns.ARTIST));
        String album = cursor.getString((cursor.getColumnIndex(MediaStore.Audio.AudioColumns.ALBUM)));
        long albumId = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.AudioColumns.ALBUM_ID));
        long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.DURATION));
        String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.AudioColumns.DATA));
        String fileName = cursor.getString((cursor.getColumnIndex(MediaStore.Audio.AudioColumns.DISPLAY_NAME)));
        long fileSize = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.SIZE));

        AudioBean music = new AudioBean();
        music.setId(String.valueOf(id));
        music.setType(AudioBean.Type.LOCAL);
        music.setTitle(title);
        music.setArtist(artist);
        music.setAlbum(album);
        music.setAlbumId(albumId);
        music.setDuration(duration);
        music.setPath(path);
        music.setFileName(fileName);
        music.setFileSize(fileSize);
        if (++i <= 20) {
            // 只加载前20首的缩略图
            CoverLoader.getInstance().loadThumbnail(music);
        }
        musicList.add(music);
    }
    cursor.close();
    return musicList;
}
 
Example 16
Source Project: DanDanPlayForAndroid   Source File: AppConfig.java    License: MIT License 4 votes vote down vote up
public void setCloudDanmuFilter(boolean isOpen) {
    SPUtils.getInstance().put(Constants.Config.CLOUD_DANMU_FILTER, isOpen);
}
 
Example 17
Source Project: DanDanPlayForAndroid   Source File: AppConfig.java    License: MIT License 4 votes vote down vote up
/**
 * 上一次远程登录数据
 */
public String getRemoteLoginData() {
    return SPUtils.getInstance().getString(Constants.Config.REMOTE_LOGIN_DATA);
}
 
Example 18
Source Project: YCAudioPlayer   Source File: PlayMusicFragment.java    License: Apache License 2.0 4 votes vote down vote up
private void initPlayMode() {
    int playMode = SPUtils.getInstance(Constant.SP_NAME).getInt(Constant.PLAY_MODE, 0);
    ivMode.setImageLevel(playMode);
}
 
Example 19
Source Project: DanDanPlayForAndroid   Source File: AppConfig.java    License: MIT License 4 votes vote down vote up
public void setUpdateFilterTime(long time) {
    SPUtils.getInstance().put(Constants.Config.UPDATE_FILTER_TIME, time);
}
 
Example 20
Source Project: YCAudioPlayer   Source File: MeFragment.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void initView(View view) {
    tvAuthor.setText(SPUtils.getInstance(Constant.SP_NAME).getString("name", "杨充"));
}
 
Example 21
Source Project: DoraemonKit   Source File: FloatIconConfig.java    License: Apache License 2.0 4 votes vote down vote up
public static int getLastPosX() {
    return SPUtils.getInstance().getInt(SharedPrefsKey.FLOAT_ICON_POS_X, 0);
}
 
Example 22
Source Project: DoraemonKit   Source File: FloatIconConfig.java    License: Apache License 2.0 4 votes vote down vote up
public static int getLastPosY() {
    return SPUtils.getInstance().getInt(SharedPrefsKey.FLOAT_ICON_POS_Y, 0);
}
 
Example 23
Source Project: DanDanPlayForAndroid   Source File: AppConfig.java    License: MIT License 4 votes vote down vote up
public void setOnlinePlayLogEnable(boolean isEnable) {
    SPUtils.getInstance().put(Constants.PlayerConfig.ONLINE_PLAY_LOG, isEnable);
}
 
Example 24
Source Project: TikTok   Source File: AppSettingUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return app是否是第一次启动
 */
public static boolean isFirstStart() {
    return SPUtils.getInstance(spName).getBoolean("isFirstStart", true);
}
 
Example 25
Source Project: DanDanPlayForAndroid   Source File: AppConfig.java    License: MIT License 4 votes vote down vote up
/**
 * 在线播放是否生成日志
 */
public boolean isOnlinePlayLogEnable() {
    return SPUtils.getInstance().getBoolean(Constants.PlayerConfig.ONLINE_PLAY_LOG, true);
}
 
Example 26
Source Project: DanDanPlayForAndroid   Source File: TorrentConfig.java    License: MIT License 4 votes vote down vote up
/**
 * 下载引擎
 */
public String getDownloadEngine() {
    return SPUtils.getInstance().getString(DOWNLOAD_ENGINE, Engine.LIB_TORRENT);
}
 
Example 27
Source Project: DanDanPlayForAndroid   Source File: TorrentConfig.java    License: MIT License 4 votes vote down vote up
public void setDownloadEngine(String engine) {
    SPUtils.getInstance().put(DOWNLOAD_ENGINE, engine);
}
 
Example 28
Source Project: DanDanPlayForAndroid   Source File: TorrentConfig.java    License: MIT License 4 votes vote down vote up
/**
 * 最大同时活动任务数量
 */
public int getMaxTaskCount() {
    return SPUtils.getInstance().getInt(MAX_ACTIVITY_TASK, 3);
}
 
Example 29
Source Project: DanDanPlayForAndroid   Source File: TorrentConfig.java    License: MIT License 4 votes vote down vote up
public void setMaxTaskCount(int taskCount) {
    SPUtils.getInstance().put(MAX_ACTIVITY_TASK, taskCount);
}
 
Example 30
Source Project: DanDanPlayForAndroid   Source File: TorrentConfig.java    License: MIT License 4 votes vote down vote up
/**
 * 最大下载速度
 */
public int getMaxDownloadRate() {
    return SPUtils.getInstance().getInt(MAX_DOWNLOAD_RATE, 0);
}