Search in sources :

Example 41 with Build

use of android.os.Build in project scroball by peterjosling.

the class LastfmClientTest method updateNowPlaying_returnsResultOnSuccess.

@Test
public void updateNowPlaying_returnsResultOnSuccess() {
    String track = "My Track";
    String artist = "Some Artist";
    when(lastfmApi.updateNowPlaying(any(), any())).thenReturn(scrobbleResult);
    when(scrobbleResult.isSuccessful()).thenReturn(true);
    client.updateNowPlaying(Track.builder().track(track).artist(artist).build(), callback);
    ScrobbleData expectedScrobbleData = new ScrobbleData();
    expectedScrobbleData.setTrack(track);
    expectedScrobbleData.setArtist(artist);
    verify(lastfmApi).updateNowPlaying(refEq(expectedScrobbleData, "timestamp"), refEq(session));
    verify(callback).handleMessage(argThat(message -> ((LastfmClient.Result) message.obj).isSuccessful()));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) Session(com.softartdev.lastfm.Session) ArgumentMatchers.refEq(org.mockito.ArgumentMatchers.refEq) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) ScrobbleData(com.softartdev.lastfm.scrobble.ScrobbleData) Mockito.verify(org.mockito.Mockito.verify) MockitoAnnotations(org.mockito.MockitoAnnotations) Handler(android.os.Handler) Result(com.softartdev.lastfm.Result) Build(android.os.Build) Caller(com.softartdev.lastfm.Caller) ScrobbleResult(com.softartdev.lastfm.scrobble.ScrobbleResult) Before(org.junit.Before) ScrobbleData(com.softartdev.lastfm.scrobble.ScrobbleData) Result(com.softartdev.lastfm.Result) ScrobbleResult(com.softartdev.lastfm.scrobble.ScrobbleResult) Test(org.junit.Test)

Example 42 with Build

use of android.os.Build in project Taskbar by farmerbb.

the class MainActivity method proceedWithAppLaunch.

@SuppressWarnings("ResultOfMethodCallIgnored")
private void proceedWithAppLaunch(Bundle savedInstanceState) {
    try {
        setContentView(R.layout.tb_main);
    } catch (IllegalStateException e) {
        setTheme(R.style.Theme_AppCompat_Light);
        setContentView(R.layout.tb_main);
    }
    if (!U.isLibrary(this)) {
        setSupportActionBar(findViewById(R.id.toolbar));
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);
        }
    }
    theSwitch = findViewById(R.id.the_switch);
    helpButton = findViewById(R.id.help_button);
    if (theSwitch != null) {
        final SharedPreferences pref = U.getSharedPreferences(this);
        theSwitch.setChecked(pref.getBoolean(PREF_TASKBAR_ACTIVE, false));
        theSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
            if (b) {
                if (U.canDrawOverlays(this)) {
                    boolean firstRun = pref.getBoolean(PREF_FIRST_RUN, true);
                    startTaskbarService();
                    if (firstRun)
                        U.showRecentAppsDialog(this);
                } else {
                    U.showPermissionDialog(this);
                    compoundButton.setChecked(false);
                }
            } else
                stopTaskbarService();
        });
    }
    if (savedInstanceState == null) {
        U.initPrefs(this);
        File restoreInProgress = new File(getFilesDir(), "restore_in_progress");
        File restoreSuccessful = new File(getFilesDir(), "restore_successful");
        if (restoreInProgress.exists() || restoreSuccessful.exists()) {
            if (restoreInProgress.exists()) {
                U.showToastLong(this, R.string.tb_restore_failed);
                restoreInProgress.delete();
            }
            if (restoreSuccessful.exists()) {
                U.showToastLong(this, R.string.tb_restore_successful);
                restoreSuccessful.delete();
            }
            navigateTo(new ManageAppDataFragment());
        } else if (!getIntent().hasExtra("theme_change"))
            navigateTo(new AboutFragment());
        else
            navigateTo(new AppearanceFragment());
    } else
        try {
            Fragment oldFragment = getFragmentManager().findFragmentById(R.id.fragmentContainer);
            navigateTo(oldFragment.getClass().newInstance());
        } catch (IllegalAccessException | InstantiationException ignored) {
        }
    SharedPreferences pref = U.getSharedPreferences(this);
    if (!getPackageName().equals(BuildConfig.BASE_APPLICATION_ID) && freeVersionInstalled()) {
        if (!pref.getBoolean(PREF_DONT_SHOW_UNINSTALL_DIALOG, false)) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.tb_settings_imported_successfully).setMessage(R.string.tb_import_dialog_message).setPositiveButton(R.string.tb_action_uninstall, (dialog, which) -> {
                pref.edit().putBoolean(PREF_UNINSTALL_DIALOG_SHOWN, true).apply();
                try {
                    startActivity(new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + BuildConfig.BASE_APPLICATION_ID)));
                } catch (ActivityNotFoundException ignored) {
                }
            });
            if (pref.getBoolean(PREF_UNINSTALL_DIALOG_SHOWN, false))
                builder.setNegativeButton(R.string.tb_action_dont_show_again, (dialogInterface, i) -> pref.edit().putBoolean(PREF_DONT_SHOW_UNINSTALL_DIALOG, true).apply());
            AlertDialog dialog = builder.create();
            dialog.show();
            dialog.setCancelable(false);
        }
        if (!pref.getBoolean(PREF_UNINSTALL_DIALOG_SHOWN, false)) {
            if (theSwitch != null)
                theSwitch.setChecked(false);
            SharedPreferences.Editor editor = pref.edit();
            String iconPack = pref.getString(PREF_ICON_PACK, BuildConfig.BASE_APPLICATION_ID);
            if (iconPack.contains(BuildConfig.BASE_APPLICATION_ID)) {
                editor.putString(PREF_ICON_PACK, getPackageName());
            } else {
                U.refreshPinnedIcons(this);
            }
            editor.putBoolean(PREF_FIRST_RUN, true);
            editor.apply();
        }
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && !U.isLibrary(this)) {
        ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
        if (shortcutManager.getDynamicShortcuts().size() == 0) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClass(this, StartTaskbarActivity.class);
            intent.putExtra(EXTRA_IS_LAUNCHING_SHORTCUT, true);
            ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "start_taskbar").setShortLabel(getString(R.string.tb_start_taskbar)).setIcon(Icon.createWithResource(this, R.drawable.tb_shortcut_icon_start)).setIntent(intent).build();
            if (U.enableFreeformModeShortcut(this)) {
                Intent intent2 = new Intent(Intent.ACTION_MAIN);
                intent2.setClass(this, ShortcutActivity.class);
                intent2.putExtra(EXTRA_IS_LAUNCHING_SHORTCUT, true);
                ShortcutInfo shortcut2 = new ShortcutInfo.Builder(this, "freeform_mode").setShortLabel(getString(R.string.tb_pref_header_freeform)).setIcon(Icon.createWithResource(this, R.drawable.tb_shortcut_icon_freeform)).setIntent(intent2).build();
                shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut, shortcut2));
            } else
                shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
        }
    }
    if (pref.getInt("show_changelog", 0) < latestChangelogVersion && U.isConsumerBuild(this)) {
        Snackbar snackbar = Snackbar.make(findViewById(R.id.main_activity_layout), R.string.tb_see_whats_new, Snackbar.LENGTH_INDEFINITE);
        snackbar.setAction(R.string.tb_action_view, v -> {
            pref.edit().putInt("show_changelog", latestChangelogVersion).apply();
            Uri uri = Uri.parse("https://github.com/farmerbb/Taskbar/blob/" + BuildConfig.VERSION_CODE + "/CHANGELOG.md");
            try {
                DependencyUtils.openChromeCustomTab(this, uri);
            } catch (ActivityNotFoundException | IllegalArgumentException ignored) {
            }
        });
        snackbar.show();
    }
}
Also used : AlertDialog(android.app.AlertDialog) Context(android.content.Context) Arrays(java.util.Arrays) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) StartMenuService(com.farmerbb.taskbar.service.StartMenuService) Uri(android.net.Uri) ImageView(android.widget.ImageView) GlobalHelper(com.farmerbb.taskbar.helper.GlobalHelper) Intent(android.content.Intent) FragmentTransaction(android.app.FragmentTransaction) NotificationService(com.farmerbb.taskbar.service.NotificationService) DependencyUtils(com.farmerbb.taskbar.util.DependencyUtils) PackageInfo(android.content.pm.PackageInfo) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) DesktopModeFragment(com.farmerbb.taskbar.fragment.DesktopModeFragment) ActionBar(androidx.appcompat.app.ActionBar) SettingsFragment(com.farmerbb.taskbar.fragment.SettingsFragment) FreeformModeFragment(com.farmerbb.taskbar.fragment.FreeformModeFragment) View(android.view.View) AboutFragment(com.farmerbb.taskbar.fragment.AboutFragment) Icon(android.graphics.drawable.Icon) Build(android.os.Build) ManageAppDataFragment(com.farmerbb.taskbar.fragment.ManageAppDataFragment) TargetApi(android.annotation.TargetApi) Fragment(android.app.Fragment) BuildConfig(com.farmerbb.taskbar.BuildConfig) SwitchCompat(androidx.appcompat.widget.SwitchCompat) R(com.farmerbb.taskbar.R) ShortcutInfo(android.content.pm.ShortcutInfo) U(com.farmerbb.taskbar.util.U) AdvancedFragment(com.farmerbb.taskbar.fragment.AdvancedFragment) AppearanceFragment(com.farmerbb.taskbar.fragment.AppearanceFragment) BroadcastReceiver(android.content.BroadcastReceiver) ShortcutManager(android.content.pm.ShortcutManager) File(java.io.File) LauncherHelper(com.farmerbb.taskbar.helper.LauncherHelper) AlertDialog(android.app.AlertDialog) TaskbarService(com.farmerbb.taskbar.service.TaskbarService) FreeformHackHelper(com.farmerbb.taskbar.helper.FreeformHackHelper) TextView(android.widget.TextView) SharedPreferences(android.content.SharedPreferences) DashboardService(com.farmerbb.taskbar.service.DashboardService) ActivityNotFoundException(android.content.ActivityNotFoundException) Snackbar(com.google.android.material.snackbar.Snackbar) Collections(java.util.Collections) Constants(com.farmerbb.taskbar.util.Constants) AboutFragment(com.farmerbb.taskbar.fragment.AboutFragment) ShortcutInfo(android.content.pm.ShortcutInfo) SharedPreferences(android.content.SharedPreferences) ManageAppDataFragment(com.farmerbb.taskbar.fragment.ManageAppDataFragment) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) AppearanceFragment(com.farmerbb.taskbar.fragment.AppearanceFragment) DesktopModeFragment(com.farmerbb.taskbar.fragment.DesktopModeFragment) SettingsFragment(com.farmerbb.taskbar.fragment.SettingsFragment) FreeformModeFragment(com.farmerbb.taskbar.fragment.FreeformModeFragment) AboutFragment(com.farmerbb.taskbar.fragment.AboutFragment) ManageAppDataFragment(com.farmerbb.taskbar.fragment.ManageAppDataFragment) Fragment(android.app.Fragment) AdvancedFragment(com.farmerbb.taskbar.fragment.AdvancedFragment) AppearanceFragment(com.farmerbb.taskbar.fragment.AppearanceFragment) Uri(android.net.Uri) ActivityNotFoundException(android.content.ActivityNotFoundException) File(java.io.File) ActionBar(androidx.appcompat.app.ActionBar) Snackbar(com.google.android.material.snackbar.Snackbar)

Aggregations

Build (android.os.Build)42 Context (android.content.Context)30 Intent (android.content.Intent)22 List (java.util.List)22 PackageManager (android.content.pm.PackageManager)20 ArrayList (java.util.ArrayList)19 View (android.view.View)16 Toast (android.widget.Toast)15 File (java.io.File)15 Bundle (android.os.Bundle)14 Uri (android.net.Uri)13 TextView (android.widget.TextView)13 Locale (java.util.Locale)13 Manifest (android.Manifest)11 SharedPreferences (android.content.SharedPreferences)11 NonNull (android.support.annotation.NonNull)11 Activity (android.app.Activity)10 DialogInterface (android.content.DialogInterface)10 EditText (android.widget.EditText)10 Arrays (java.util.Arrays)10