Example usage for android.graphics.drawable ColorDrawable ColorDrawable

List of usage examples for android.graphics.drawable ColorDrawable ColorDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable ColorDrawable ColorDrawable.

Prototype

public ColorDrawable(@ColorInt int color) 

Source Link

Document

Creates a new ColorDrawable with the specified color.

Usage

From source file:com.example.casthelloworld.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Fragment fragment = new ConnectFragment();
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.add(R.id.main, fragment, "first");
    transaction.addToBackStack(null);//from  w  w  w . j  a v  a2 s.c  o m
    transaction.commit();
    Log.d("Start", "ONcreate");
    waiting = false;

    m_lastMagFields = new float[3];
    m_lastAccels = new float[3];
    mRotationMatrix = new float[16];
    m_remappedR = new float[16];
    m_orientation = new float[4];
    orientationVals = new float[3];
    directionMessage = new JSONObject();
    playerId = "";

    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

    v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    lastVal = 999;
    sManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    // Configure Cast device discovery
    mMediaRouter = MediaRouter.getInstance(getApplicationContext());
    mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(
            CastMediaControlIntent.categoryForCast(getResources().getString(R.string.app_id))).build();
    mMediaRouterCallback = new MyMediaRouterCallback();
}

From source file:com.mikepenz.materialize.view.ScrimInsetsFrameLayout.java

@Override
public void setInsetForeground(int mInsetForegroundColor) {
    this.mInsetForeground = new ColorDrawable(mInsetForegroundColor);
}

From source file:com.senior.chromecastcheckers.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Set random UserID identifier
    Random rand = new Random();
    UserID = rand.nextInt(1000);//from   w  w w. j a  v  a2 s.c  o  m

    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

    // Configure Cast device discovery
    mMediaRouter = MediaRouter.getInstance(getApplicationContext());
    mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(
            CastMediaControlIntent.categoryForCast(getResources().getString(R.string.app_id))).build();
    mMediaRouterCallback = new MyMediaRouterCallback();
}

From source file:com.apptentive.android.sdk.module.messagecenter.view.AttachmentPreviewDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().getAttributes().windowAnimations = R.style.ApptentiveDialogAnimation;

    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.gravity = Gravity.BOTTOM;//  www .j  av a 2 s  .  c  om
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.MATCH_PARENT;
    dialog.getWindow().setAttributes(lp);
    return dialog;
}

From source file:com.ibuildapp.ZopimChatPlugin.ZopimChat.java

public void setNavbarBackgroundColor(final int color, View view) {
    float density = getResources().getDisplayMetrics().density;

    Drawable background = new LayerDrawable(new Drawable[] { new ColorDrawable(color), new ColorDrawable(
            color == Color.WHITE ? Color.parseColor("#33000000") : Color.parseColor("#66FFFFFF")) });

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        view.setBackground(background);/*from  w  w w.j a v  a  2 s.  c  om*/
    else
        view.setBackgroundDrawable(background);

    view.setPadding((int) (density * 10), (int) (density * 10), (int) (density * 10), (int) (density * 10));
}

From source file:com.musenkishi.atelier.Atelier.java

private static void applyColorToView(final PaletteTarget target, int color, boolean fromCache) {
    if (target.getView() instanceof TextView) {
        applyColorToView((TextView) target.getView(), color, fromCache);
    } else if (target.getView() instanceof CardView) {
        applyColorToView((CardView) target.getView(), color, fromCache);
    } else if (target.getView() instanceof FloatingActionButton) {
        applyColorToView((FloatingActionButton) target.getView(), color, fromCache,
                target.shouldMaskDrawable());
    } else if (target.getView() instanceof ImageView) {
        applyColorToView((ImageView) target.getView(), color, fromCache, target.shouldMaskDrawable());
    } else {/*from w w  w.j a  v  a  2 s .c  om*/
        if (fromCache) {
            target.getView().setBackgroundColor(color);
        } else {
            Drawable preDrawable;

            if (target.getView().getBackground() == null) {
                preDrawable = new ColorDrawable(Color.TRANSPARENT);
            } else {
                preDrawable = target.getView().getBackground();
            }

            TransitionDrawable transitionDrawable = new TransitionDrawable(
                    new Drawable[] { preDrawable, new ColorDrawable(color) });
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                target.getView().setBackground(transitionDrawable);
            } else {
                target.getView().setBackgroundDrawable(transitionDrawable);
            }
            transitionDrawable.startTransition(300);
        }
    }
}

From source file:com.bitants.wally.fragments.MaterialDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (getActivity() != null) {
        final Dialog dialog = new Dialog(getActivity(),
                android.support.v7.appcompat.R.style.Base_Theme_AppCompat_Light_Dialog);
        //                    android.R.style.Theme_DeviceDefault_Light_Dialog);
        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.setContentView(R.layout.dialog_base_material);
        textViewTitle = (TextView) dialog.findViewById(R.id.dialog_title);
        buttonNegative = (Button) dialog.findViewById(R.id.dialog_button_negative);
        buttonPositive = (Button) dialog.findViewById(R.id.dialog_button_positive);
        scrollView = (ScrollView) dialog.findViewById(R.id.dialog_scrollview);
        viewStub = (ViewStub) dialog.findViewById(R.id.dialog_viewstub);

        setupViews(dialog.getContext());
        hideEmptyViews();//  w w w  .j  av  a2  s  .c  o  m

        if (!isCancelable()) {
            buttonNegative.setVisibility(View.GONE);
        }

        return dialog;
    } else {
        return null;
    }
}

From source file:com.ksharkapps.musicnow.ui.activities.HomeActivity.java

public void changeActionBarColor(int newColor) {

    int color = newColor != 0 ? newColor : SettingsActivity.getActionBarColor(this);
    Drawable colorDrawable = new ColorDrawable(color);
    Drawable bottomDrawable = getResources().getDrawable(R.drawable.transparent_overlay);
    LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });

    if (oldBackground == null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            ld.setCallback(drawableCallback);
        } else {/*from w  w  w.  j  a v  a2 s .  co m*/
            actBar.setBackgroundDrawable(colorDrawable);
        }

    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
        // workaround for broken ActionBarContainer drawable handling on
        // pre-API 17 builds
        // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            td.setCallback(drawableCallback);
        } else {
            actBar.setBackgroundDrawable(td);
        }
        td.startTransition(200);
    }

    oldBackground = ld;

    ScrollableTabView mScrollingTabs = (ScrollableTabView) findViewById(R.id.fragment_home_phone_pager_titles);
    mScrollingTabs.setBackgroundColor(color);

    // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
    actBar.setDisplayShowTitleEnabled(false);
    actBar.setDisplayShowTitleEnabled(true);

    if (Utils.hasKitKat()) {
        if (SettingsActivity.getTranslucentMode(this)) {
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintColor(color);

        }

    }

}

From source file:com.inc.playground.playground.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    globalVariables = ((GlobalVariables) getApplication());
    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    setPlayGroundActionBar();//from  ww w. j a  va 2 s .com
    //set actionBar color
    actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.primaryColor)));
    actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.secondaryColor)));
    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    //actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(actionBar.newTab().setTabListener(this));
    }
    actionBar.getTabAt(0).setIcon(R.drawable.pg_list_view);
    actionBar.getTabAt(1).setIcon(R.drawable.pg_map_view);
    actionBar.getTabAt(2).setIcon(R.drawable.pg_calendar_view);
    //NavigationDrawer handling (e.g the list from leftside):
    mTitle = mDrawerTitle = getTitle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.menu_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.pg_menu, /* nav drawer icon to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description */
            R.string.drawer_close /* "close drawer" description */
    ) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            getActionBar().setTitle(mTitle);
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            getActionBar().setTitle(mDrawerTitle);
        }
    };

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerLayout.closeDrawers();
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // all linear layout from slider menu

    /*Home button */
    LinearLayout ll_Home = (LinearLayout) findViewById(R.id.ll_home);
    ll_Home.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this, MainActivity.class);
            startActivity(iv);
            finish();
        }
    });
    /*Login button */
    LinearLayout ll_Login = (LinearLayout) findViewById(R.id.ll_login);
    ll_Login.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            LinearLayout ll_Login = (LinearLayout) v;
            TextView loginTxt = (TextView) findViewById(R.id.login_txt);
            if (loginTxt.getText().equals("Login")) {
                Intent iv = new Intent(MainActivity.this, Login.class);
                startActivity(iv);
                finish();
            } else if (loginTxt.getText().equals("Logout")) {
                final Dialog alertDialog = new Dialog(MainActivity.this);
                alertDialog.setContentView(R.layout.logout_dilaog);
                alertDialog.setTitle("Logout");
                alertDialog.findViewById(R.id.ok_btn).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
                        SharedPreferences.Editor editor = prefs.edit();
                        editor.clear();
                        editor.commit();
                        ImageView loginImg = (ImageView) findViewById(R.id.login_img);
                        TextView loginTxt = (TextView) findViewById(R.id.login_txt);
                        loginTxt.setText("Login");
                        loginImg.setImageResource(R.drawable.pg_action_lock_open);

                        globalVariables = ((GlobalVariables) getApplication());
                        globalVariables.SetCurrentUser(null);
                        globalVariables.SetUserPictureBitMap(null);
                        globalVariables.SetUsersList(null);
                        globalVariables.SetUsersImagesMap(null);

                        Util.clearCookies(getApplicationContext());

                        Intent iv = new Intent(MainActivity.this, MainActivity.class);
                        startActivity(iv);
                        finish();
                    }
                });

                alertDialog.findViewById(R.id.cancel_btn).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent iv = new Intent(MainActivity.this, MainActivity.class);
                        startActivity(iv);
                        finish();
                    }
                });

                alertDialog.show(); //<-- See This!
            }

        }
    });

    /*Setting button*/
    LinearLayout ll_Setting = (LinearLayout) findViewById(R.id.ll_settings);
    ll_Setting.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this,
                    com.inc.playground.playground.upLeft3StripesButton.SettingsActivity.class);
            startActivity(iv);
            finish();
        }
    });

    /*My profile button*/
    LinearLayout ll_my_profile = (LinearLayout) findViewById(R.id.ll_my_profile);
    ll_my_profile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // new changes
            globalVariables = ((GlobalVariables) getApplication());
            User currentUser = globalVariables.GetCurrentUser();
            if (currentUser == null) {
                Toast.makeText(MainActivity.this, "You are not logged in", Toast.LENGTH_LONG).show();
            } else {

                Intent iv = new Intent(MainActivity.this,
                        com.inc.playground.playground.upLeft3StripesButton.MyProfile.class);

                //for my profile
                iv.putExtra("name", currentUser.getName());
                iv.putExtra("createdNumOfEvents", currentUser.getCreatedNumOfEvents());
                //pass events
                iv.putExtra("events", currentUser.getEvents());
                iv.putExtra("events_wait4approval", currentUser.getEvents_wait4approval());
                iv.putExtra("events_decline", currentUser.getEvents_decline());

                iv.putExtra("photoUrl", currentUser.getPhotoUrl());
                startActivity(iv);
                //
            }
        }
    });

    LinearLayout ll_aboutUs = (LinearLayout) findViewById(R.id.ll_about);
    ll_aboutUs.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this, AboutUs.class);
            startActivity(iv);
            finish();
        }
    });

}

From source file:com.filemanager.free.activities.TextReader.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Sp = PreferenceManager.getDefaultSharedPreferences(this);

    if (theme1 == 1) {
        getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(c, R.color.holo_dark_background));
    }/*from   ww  w.  j  a  v a 2 s .c  o  m*/
    setContentView(R.layout.search);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    skin = PreferenceUtils.getPrimaryColorString(Sp);
    findViewById(R.id.lin).setBackgroundColor(Color.parseColor(skin));
    if (Build.VERSION.SDK_INT >= 21) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("File Manager",
                ((BitmapDrawable) ContextCompat.getDrawable(c, R.mipmap.ic_launcher)).getBitmap(),
                Color.parseColor(skin));
        ((Activity) this).setTaskDescription(taskDescription);
    }
    int skinStatusBar = PreferenceUtils.getStatusColor(skin);
    assert (getSupportActionBar()) != null;
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(skin)));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    if (Build.VERSION.SDK_INT == 20 || Build.VERSION.SDK_INT == 19) {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setStatusBarTintColor(Color.parseColor(skin));
        FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.texteditor)
                .getLayoutParams();
        SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
        p.setMargins(0, config.getStatusBarHeight(), 0, 0);
    } else if (Build.VERSION.SDK_INT >= 21) {
        boolean colourednavigation = Sp.getBoolean("colorednavigation", true);
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor((PreferenceUtils.getStatusColor(skin)));
        if (colourednavigation)
            window.setNavigationBarColor((PreferenceUtils.getStatusColor(skin)));

    }
    mInput = (EditText) findViewById(R.id.fname);
    scrollView = (ScrollView) findViewById(R.id.editscroll);

    try {
        if (getIntent().getData() != null) {
            uri = getIntent().getData();

            mFile = new File(getIntent().getData().getPath());
        } else
            mFile = new File(getIntent().getStringExtra("path"));
    } catch (Exception e) {
        mFile = null;
    }
    String fileName = null;
    try {
        if (uri.getScheme().equals("file")) {
            fileName = uri.getLastPathSegment();
        } else {
            Cursor cursor = null;
            try {
                cursor = getContentResolver().query(uri,
                        new String[] { MediaStore.Images.ImageColumns.DISPLAY_NAME }, null, null, null);

                if (cursor != null && cursor.moveToFirst()) {
                    fileName = cursor
                            .getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME));
                }
            } finally {

                if (cursor != null) {
                    cursor.close();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (fileName == null || fileName.trim().length() == 0)
        fileName = f.getName();
    getSupportActionBar().setTitle(fileName);
    mInput.addTextChangedListener(this);
    try {
        if (theme1 == 1)
            mInput.setBackgroundColor(ContextCompat.getColor(c, R.color.holo_dark_background));
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    } catch (Exception ignored) {

    }
    if (savedInstanceState != null) {
        mOriginal = savedInstanceState.getString(KEY_ORIGINAL_TEXT);
        int index = savedInstanceState.getInt(KEY_INDEX);
        mInput.setText(savedInstanceState.getString(KEY_MODIFIED_TEXT));
        mInput.setScrollY(index);
    } else {
        load(mFile);
    }
}