Java Code Examples for android.app.ActivityManager#TaskDescription

The following examples show how to use android.app.ActivityManager#TaskDescription . 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: XposedApp.java    From EdXposedManager with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
    public static void setColors(ActionBar actionBar, Integer value, Activity activity) {
        int color = value;
        SharedPreferences prefs = activity.getSharedPreferences(activity.getPackageName() + "_preferences", MODE_PRIVATE);

        int drawable = iconsValues[Integer.parseInt(Objects.requireNonNull(prefs.getString("custom_icon", "0")))];

        if (actionBar != null)
            actionBar.setBackgroundDrawable(new ColorDrawable(color));

        ActivityManager.TaskDescription tDesc = new ActivityManager.TaskDescription(activity.getString(R.string.app_name),
                drawableToBitmap(activity.getDrawable(drawable)), color);
//        ActivityManager.TaskDescription tDesc = new ActivityManager.TaskDescription(activity.getString(R.string.app_name),
//                drawable, color);
        activity.setTaskDescription(tDesc);

        if (getPreferences().getBoolean("nav_bar", false)) {
            activity.getWindow().setNavigationBarColor(darkenColor(color, 0.85f));
        } else {
            int black = activity.getResources().getColor(android.R.color.black, null);
            activity.getWindow().setNavigationBarColor(black);
        }
    }
 
Example 2
Source File: SettingActivity.java    From Toutiao with Apache License 2.0 6 votes vote down vote up
@Override
public void onColorSelection(@NonNull ColorChooserDialog dialog, @ColorInt int selectedColor) {
    if (getSupportActionBar() != null)
        getSupportActionBar().setBackgroundDrawable(new ColorDrawable(selectedColor));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // 状态栏上色
        getWindow().setStatusBarColor(CircleView.shiftColorDown(selectedColor));
        // 最近任务栏上色
        ActivityManager.TaskDescription tDesc = new ActivityManager.TaskDescription(
                getString(R.string.app_name),
                BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_rect),
                selectedColor);
        setTaskDescription(tDesc);
        // 导航栏上色
        if (SettingUtil.getInstance().getNavBar()) {
            getWindow().setNavigationBarColor(CircleView.shiftColorDown(selectedColor));
        } else {
            getWindow().setNavigationBarColor(Color.BLACK);
        }
    }
    if (!dialog.isAccentMode()) {
        SettingUtil.getInstance().setColor(selectedColor);
    }
}
 
Example 3
Source File: SettingsActivity.java    From rcloneExplorer with MIT License 6 votes vote down vote up
private void applyTheme() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    int customPrimaryColor = sharedPreferences.getInt(getString(R.string.pref_key_color_primary), -1);
    int customAccentColor = sharedPreferences.getInt(getString(R.string.pref_key_color_accent), -1);
    boolean isDarkTheme = sharedPreferences.getBoolean(getString(R.string.pref_key_dark_theme), false);
    getTheme().applyStyle(CustomColorHelper.getPrimaryColorTheme(this, customPrimaryColor), true);
    getTheme().applyStyle(CustomColorHelper.getAccentColorTheme(this, customAccentColor), true);
    if (isDarkTheme) {
        getTheme().applyStyle(R.style.DarkTheme, true);
    } else {
        getTheme().applyStyle(R.style.LightTheme, true);
    }

    // set recents app color to the primary color
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round);
    ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(getString(R.string.app_name), bm, customPrimaryColor);
    setTaskDescription(taskDesc);
}
 
Example 4
Source File: ChangelogActivity.java    From rcloneExplorer with MIT License 6 votes vote down vote up
private void applyTheme() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    int customPrimaryColor = sharedPreferences.getInt(getString(R.string.pref_key_color_primary), -1);
    int customAccentColor = sharedPreferences.getInt(getString(R.string.pref_key_color_accent), -1);
    Boolean isDarkTheme = sharedPreferences.getBoolean(getString(R.string.pref_key_dark_theme), false);
    getTheme().applyStyle(CustomColorHelper.getPrimaryColorTheme(this, customPrimaryColor), true);
    getTheme().applyStyle(CustomColorHelper.getAccentColorTheme(this, customAccentColor), true);
    if (isDarkTheme) {
        getTheme().applyStyle(R.style.DarkTheme, true);
    } else {
        getTheme().applyStyle(R.style.LightTheme, true);
    }

    // set recents app color to the primary color
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round);
    ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(getString(R.string.app_name), bm, customPrimaryColor);
    setTaskDescription(taskDesc);
}
 
Example 5
Source File: MainActivity.java    From rcloneExplorer with MIT License 6 votes vote down vote up
private void applyTheme() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    int customPrimaryColor = sharedPreferences.getInt(getString(R.string.pref_key_color_primary), -1);
    int customAccentColor = sharedPreferences.getInt(getString(R.string.pref_key_color_accent), -1);
    isDarkTheme = sharedPreferences.getBoolean(getString(R.string.pref_key_dark_theme), false);
    getTheme().applyStyle(CustomColorHelper.getPrimaryColorTheme(this, customPrimaryColor), true);
    getTheme().applyStyle(CustomColorHelper.getAccentColorTheme(this, customAccentColor), true);
    if (isDarkTheme) {
        getTheme().applyStyle(R.style.DarkTheme, true);
    } else {
        getTheme().applyStyle(R.style.LightTheme, true);
    }

    TypedValue typedValue = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
    getWindow().setStatusBarColor(typedValue.data);

    // set recents app color to the primary color
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round);
    ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(getString(R.string.app_name), bm, customPrimaryColor);
    setTaskDescription(taskDesc);
}
 
Example 6
Source File: AboutActivity.java    From rcloneExplorer with MIT License 6 votes vote down vote up
private void applyTheme() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    int customPrimaryColor = sharedPreferences.getInt(getString(R.string.pref_key_color_primary), -1);
    int customAccentColor = sharedPreferences.getInt(getString(R.string.pref_key_color_accent), -1);
    Boolean isDarkTheme = sharedPreferences.getBoolean(getString(R.string.pref_key_dark_theme), false);
    getTheme().applyStyle(CustomColorHelper.getPrimaryColorTheme(this, customPrimaryColor), true);
    getTheme().applyStyle(CustomColorHelper.getAccentColorTheme(this, customAccentColor), true);
    if (isDarkTheme) {
        getTheme().applyStyle(R.style.DarkTheme, true);
    } else {
        getTheme().applyStyle(R.style.LightTheme, true);
    }

    // set recents app color to the primary color
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round);
    ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(getString(R.string.app_name), bm, customPrimaryColor);
    setTaskDescription(taskDesc);
}
 
Example 7
Source File: BaseActivity.java    From Toutiao with Apache License 2.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    int color = SettingUtil.getInstance().getColor();
    int drawable = Constant.ICONS_DRAWABLES[SettingUtil.getInstance().getCustomIconValue()];
    if (getSupportActionBar() != null)
        getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(CircleView.shiftColorDown(color));
        // 最近任务栏上色
        ActivityManager.TaskDescription tDesc = new ActivityManager.TaskDescription(
                getString(R.string.app_name),
                BitmapFactory.decodeResource(getResources(), drawable),
                color);
        setTaskDescription(tDesc);
        if (SettingUtil.getInstance().getNavBar()) {
            getWindow().setNavigationBarColor(CircleView.shiftColorDown(color));
        } else {
            getWindow().setNavigationBarColor(Color.BLACK);
        }
    }
}
 
Example 8
Source File: BaseActivity.java    From LyricHere with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LogUtils.d(GlobalConst.Log.TAG_TRACE, "onCreate:" + this.getClass().getName());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Since our app icon has the same color as colorPrimary, our entry in the Recent Apps
        // list gets weird. We need to change either the icon or the color of the TaskDescription.
        ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(
                getTitle().toString(),
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_white),
                ResourceHelper.getThemeColor(this, R.attr.colorPrimary, android.R.color.darker_gray));
        setTaskDescription(taskDesc);
    }
    Icepick.restoreInstanceState(this, savedInstanceState);
}
 
Example 9
Source File: SettingsActivity.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
@Override
public void onPostCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
    super.onPostCreate(savedInstanceState, persistentState);
    try {
        Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round);
        ActivityManager.TaskDescription description;
        description = new ActivityManager.TaskDescription("Simplicity", bm, 0);
        setTaskDescription(description);
    }catch (Exception i){
        i.printStackTrace();
    }
}
 
Example 10
Source File: RxBaseActivity.java    From HeroVideo-master with Apache License 2.0 5 votes vote down vote up
protected void initStatusBar(){
    if (Build.VERSION.SDK_INT >= 21) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(ThemeUtils.getColorById(this, R.color.theme_color_primary));
        ActivityManager.TaskDescription description = new ActivityManager.TaskDescription(null, null, ThemeUtils.getThemeAttrColor(this, android.R.attr.colorPrimary));
        setTaskDescription(description);
    }
}
 
Example 11
Source File: RecentTasks.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new RecentTaskInfo from a TaskRecord.
 */
ActivityManager.RecentTaskInfo createRecentTaskInfo(TaskRecord tr) {
    // Compose the recent task info
    ActivityManager.RecentTaskInfo rti = new ActivityManager.RecentTaskInfo();
    rti.id = tr.getTopActivity() == null ? INVALID_TASK_ID : tr.taskId;
    rti.persistentId = tr.taskId;
    rti.baseIntent = new Intent(tr.getBaseIntent());
    rti.origActivity = tr.origActivity;
    rti.realActivity = tr.realActivity;
    rti.description = tr.lastDescription;
    rti.stackId = tr.getStackId();
    rti.userId = tr.userId;
    rti.taskDescription = new ActivityManager.TaskDescription(tr.lastTaskDescription);
    rti.lastActiveTime = tr.lastActiveTime;
    rti.affiliatedTaskId = tr.mAffiliatedTaskId;
    rti.affiliatedTaskColor = tr.mAffiliatedTaskColor;
    rti.numActivities = 0;
    if (!tr.matchParentBounds()) {
        rti.bounds = new Rect(tr.getOverrideBounds());
    }
    rti.supportsSplitScreenMultiWindow = tr.supportsSplitScreenWindowingMode();
    rti.resizeMode = tr.mResizeMode;
    rti.configuration.setTo(tr.getConfiguration());

    tr.getNumRunningActivities(mTmpReport);
    rti.numActivities = mTmpReport.numActivities;
    rti.baseActivity = (mTmpReport.base != null) ? mTmpReport.base.intent.getComponent() : null;
    rti.topActivity = (mTmpReport.top != null) ? mTmpReport.top.intent.getComponent() : null;

    return rti;
}
 
Example 12
Source File: MainActivity.java    From Android-SmartWebView with MIT License 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    asw_view.onResume();
    //Coloring the "recent apps" tab header; doing it onResume, as an insurance
    if (Build.VERSION.SDK_INT >= 23) {
        Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
        ActivityManager.TaskDescription taskDesc;
        taskDesc = new ActivityManager.TaskDescription(getString(R.string.app_name), bm, getColor(R.color.colorPrimary));
        MainActivity.this.setTaskDescription(taskDesc);
    }
    get_location();
}
 
Example 13
Source File: MainActivity.java    From MagicaSakura with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= 21) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(ThemeUtils.getColorById(this, R.color.theme_color_primary_dark));
        ActivityManager.TaskDescription description = new ActivityManager.TaskDescription(null, null,
                ThemeUtils.getThemeAttrColor(this, android.R.attr.colorPrimary));
        setTaskDescription(description);
    }
}
 
Example 14
Source File: SetTaskDescription.java    From container with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    ActivityManager.TaskDescription td = (ActivityManager.TaskDescription) args[1];
    String label = td.getLabel();
    Bitmap icon = td.getIcon();

    // If the activity label/icon isn't specified, the application's label/icon is shown instead
    // Android usually does that for us, but in this case we want info about the contained app, not VIrtualApp itself
    if (label == null || icon == null) {
        Application app = VClientImpl.get().getCurrentApplication();
        if (app != null) {
            try {
                if (label == null) {
                    label = app.getApplicationInfo().loadLabel(app.getPackageManager()).toString();
                }
                if (icon == null) {
                    Drawable drawable = app.getApplicationInfo().loadIcon(app.getPackageManager());
                    if (drawable != null) {
                        icon = DrawableUtils.drawableToBitMap(drawable);
                    }
                }
                td = new ActivityManager.TaskDescription(label, icon, td.getPrimaryColor());
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }

    TaskDescriptionDelegate descriptionDelegate = VirtualCore.get().getTaskDescriptionDelegate();
    if (descriptionDelegate != null) {
        td = descriptionDelegate.getTaskDescription(td);
    }

    args[1] = td;
    return method.invoke(who, args);
}
 
Example 15
Source File: RxBaseActivity.java    From HeroVideo-master with Apache License 2.0 5 votes vote down vote up
protected void initStatusBar(){
    if (Build.VERSION.SDK_INT >= 21) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(ThemeUtils.getColorById(this, R.color.theme_color_primary));
        ActivityManager.TaskDescription description = new ActivityManager.TaskDescription(null, null, ThemeUtils.getThemeAttrColor(this, android.R.attr.colorPrimary));
        setTaskDescription(description);
    }
}
 
Example 16
Source File: BrowserActivity.java    From Ninja with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.TaskDescription description = new ActivityManager.TaskDescription(
                getString(R.string.app_name),
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher),
                getResources().getColor(R.color.background_dark)
        );
        setTaskDescription(description);
    }

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    anchor = Integer.valueOf(sp.getString(getString(R.string.sp_anchor), "1"));
    if (anchor == 0) {
        setContentView(R.layout.main_top);
    } else {
        setContentView(R.layout.main_bottom);
    }

    create = true;
    shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
    mediumAnimTime = getResources().getInteger(android.R.integer.config_mediumAnimTime);
    longAnimTime = getResources().getInteger(android.R.integer.config_longAnimTime);
    switcherPanel = (SwitcherPanel) findViewById(R.id.switcher_panel);
    switcherPanel.setStatusListener(new SwitcherPanel.StatusListener() {
        @Override
        public void onFling() {}

        @Override
        public void onExpanded() {}

        @Override
        public void onCollapsed() {
            inputBox.clearFocus();
        }
    });

    dimen156dp = getResources().getDimensionPixelSize(R.dimen.layout_width_156dp);
    dimen144dp = getResources().getDimensionPixelSize(R.dimen.layout_width_144dp);
    dimen117dp = getResources().getDimensionPixelSize(R.dimen.layout_height_117dp);
    dimen108dp = getResources().getDimensionPixelSize(R.dimen.layout_height_108dp);
    dimen48dp = getResources().getDimensionPixelOffset(R.dimen.layout_height_48dp);

    initSwitcherView();
    initOmnibox();
    initSearchPanel();
    relayoutOK = (Button) findViewById(R.id.main_relayout_ok);
    contentFrame = (FrameLayout) findViewById(R.id.main_content);

    new AdBlock(this); // For AdBlock cold boot
    dispatchIntent(getIntent());
}
 
Example 17
Source File: BaseActivity.java    From Easy_xkcd with Apache License 2.0 4 votes vote down vote up
/**
 * Sets up the colors of toolbar, status bar and nav drawer
 */
protected void setupToolbar(Toolbar toolbar) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Bitmap ic = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_easy_xkcd_recents);
        int color = themePrefs.getPrimaryColor(false);
        ActivityManager.TaskDescription description = new ActivityManager.TaskDescription("Easy xkcd", ic, color);
        setTaskDescription(description);

        if (!(this instanceof MainActivity)) {
            getWindow().setStatusBarColor(themePrefs.getPrimaryDarkColor());
        }

        int navBarColor;
        int uiOptions = getWindow().getDecorView().getSystemUiVisibility();
        int flagForLightNavBar = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR : 0;
        TypedValue backgroundColor = new TypedValue();
        getTheme().resolveAttribute(android.R.attr.windowBackground, backgroundColor, true);

        if (themePrefs.nightThemeEnabled()) {
            uiOptions = uiOptions & Integer.reverse(flagForLightNavBar);

            if (themePrefs.amoledThemeEnabled()) {
                navBarColor = Color.BLACK;
            } else if (backgroundColor.type >= TypedValue.TYPE_FIRST_COLOR_INT && backgroundColor.type <= TypedValue.TYPE_LAST_COLOR_INT) {
                navBarColor = backgroundColor.data;
            } else {
                navBarColor = Color.BLACK;
            }
        } else {
            uiOptions = uiOptions | flagForLightNavBar;

            if (backgroundColor.type >= TypedValue.TYPE_FIRST_COLOR_INT && backgroundColor.type <= TypedValue.TYPE_LAST_COLOR_INT &&
                    Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                navBarColor = backgroundColor.data;
            } else {
                navBarColor = Color.BLACK;
            }
        }
        getWindow().setNavigationBarColor(navBarColor);
        getWindow().getDecorView().setSystemUiVisibility(uiOptions);
    }
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    toolbar.setBackgroundColor(themePrefs.getPrimaryColor(false));
    if (themePrefs.amoledThemeEnabled()) {
        toolbar.setPopupTheme(R.style.ThemeOverlay_AmoledBackground);
    }

}
 
Example 18
Source File: SearchActivity.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    updateSearchProviders();

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    int[] themes = new int[]{R.style.Theme_QuickLyric, R.style.Theme_QuickLyric_Red,
            R.style.Theme_QuickLyric_Purple, R.style.Theme_QuickLyric_Indigo,
            R.style.Theme_QuickLyric_Green, R.style.Theme_QuickLyric_Lime,
            R.style.Theme_QuickLyric_Brown, R.style.Theme_QuickLyric_Dark};
    int themeNum = Integer.valueOf(sharedPref.getString("pref_theme", "0"));
    boolean nightMode = sharedPref.getBoolean("pref_night_mode", false);
    if (nightMode && NightTimeVerifier.check(this))
        setTheme(R.style.Theme_QuickLyric_Night);
    else
        setTheme(themes[themeNum]);
    setStatusBarColor(null);
    setNavBarColor(null);

    setContentView(R.layout.search_view_pager);
    Toolbar toolbar = findViewById(R.id.search_toolbar);
    setSupportActionBar(toolbar);
    if (getActionBar() != null)
        getActionBar().setDisplayHomeAsUpEnabled(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.TaskDescription taskDescription =
                new ActivityManager.TaskDescription
                        (null, null, toolbar.getSolidColor());
        this.setTaskDescription(taskDescription);
    }

    ViewPager viewPager = getViewPager();
    viewPager.setAdapter(new SearchPagerAdapter(
            this.getFragmentManager(), this, searchQuery));
    boolean online = OnlineAccessVerifier.check(this);
    viewPager.setCurrentItem(online ? 1 : 0);
    PagerTitleStrip titleIndicator = findViewById(R.id.pager_title_strip);
    titleIndicator.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    setSearchQuery(getIntent().getStringExtra("query"));
}
 
Example 19
Source File: HomeActivity.java    From Pasta-Music with Apache License 2.0 4 votes vote down vote up
public void setListeners(Fragment f) {
    if (f instanceof FullScreenFragment) {
        appbar.setExpanded(false, false);
        fab.hide();

        ((FullScreenFragment) f).setDataListener(new FullScreenFragment.DataListener(){
            @Override
            public void onDataReady(String title, int statusColor, int windowColor) {
                setTitle(title);
                statusBackground.setBackgroundColor(ImageUtils.darkColor(statusColor));
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    setTaskDescription(new ActivityManager.TaskDescription(getTitle().toString(), ImageUtils.drawableToBitmap(ContextCompat.getDrawable(HomeActivity.this, R.mipmap.ic_launcher)), windowColor));
                }
            }
        });

        materialDrawer.setSelection(-1, false);
    } else {
        appbar.setExpanded(true, false);

        setTitle(title);
        if (f instanceof HomeFragment) materialDrawer.setSelection(1, false);
        else if (f instanceof FavoritesFragment) materialDrawer.setSelection(2, false);
        else if (f instanceof CategoriesFragment) materialDrawer.setSelection(3, false);
        else if (f instanceof SettingsFragment) materialDrawer.setSelection(5, false);
        else if (f instanceof AboutFragment) materialDrawer.setSelection(6, false);

        statusBackground.setBackgroundColor(ImageUtils.darkColor(PreferenceUtils.getPrimaryColor(this)));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ActivityManager.TaskDescription desc = new ActivityManager.TaskDescription(title, ImageUtils.drawableToBitmap(ContextCompat.getDrawable(this, R.mipmap.ic_launcher)), PreferenceUtils.getPrimaryColor(this));
            setTaskDescription(desc);
        }

        if (f instanceof FabFragment) {
            ((FabFragment) f).setFabListener(new FabFragment.FabListener() {
                @Override
                public void onDataReady(boolean visible, int iconRes, View.OnClickListener clickListener) {
                    if (visible) fab.show();
                    else fab.hide();
                    fab.setImageDrawable(ImageUtils.getVectorDrawable(HomeActivity.this, iconRes));
                    fab.setOnClickListener(clickListener);
                }
            });
        }

        fab.hide();

        if (f instanceof SearchFragment || f instanceof CategoriesFragment || f instanceof SettingsFragment || f instanceof AboutFragment) {
            ViewCompat.setElevation(findViewById(R.id.collapsing_toolbar), TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics()));
        } else ViewCompat.setElevation(findViewById(R.id.collapsing_toolbar), 0);

        if (f instanceof SearchFragment && (searchPool == null || !searchPool.isExecuting()) && (searchDatas != null && searchDatas.size() > 0)) {
            ((SearchFragment) f).swapData(searchDatas);
        }
    }

    if (searchPool != null && searchPool.isExecuting() && !(f instanceof SearchFragment))
        searchPool.cancel();
}
 
Example 20
Source File: MainActivity.java    From wirebug with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(
            getString(R.string.app_name),
            BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher),
            ContextCompat.getColor(this, R.color.colorTaskDescription));
        setTaskDescription(taskDescription);
    }

    toggleDebuggingButton = (ToggleButton) findViewById(R.id.switch_enable_debugging);
    connectedView = findViewById(R.id.view_connected);
    instructionsView = findViewById(R.id.view_instructions);
    connectCommandTextView = (TextView) findViewById(R.id.text_connect_command);
    wifiNetworkTextView = (TextView) findViewById(R.id.text_wifi_network);
    notConnectedView = findViewById(R.id.view_not_connected);

    enableSwitchChangeListener = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            DebugManager.setTcpDebuggingEnabled(isChecked);
            boolean isActuallyEnabled = DebugManager.isTcpDebuggingEnabled();
            if (isChecked == isActuallyEnabled) {
                updateInstructions(isChecked);
                updateStatus();
            } else {
                Timber.i("Could NOT %s debugging", isChecked ? "enable" : "disable");
                String toastText = isChecked
                    ? getString(R.string.could_not_enable)
                    : getString(R.string.could_not_disable);
                Toast.makeText(MainActivity.this, toastText, Toast.LENGTH_SHORT).show();
                toggleDebuggingButton.setChecked(isActuallyEnabled);
            }
        }
    };

    Shell.getShell().setLoggingEnabled(true);
    Shell.getShell().setLogPriority(Log.DEBUG);

    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
}