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.demo.frame.pageslidingtabstrip.PagerSlidingTabStripActivity.java

private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);//from  ww w . j av a 2s  .  co m

    // change ActionBar color just if an ActionBar is available
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        Drawable colorDrawable = new ColorDrawable(newColor);
        Drawable bottomDrawable = getResources().getDrawable(R.mipmap.ic_launcher);
        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 {
                getActionBar().setBackgroundDrawable(ld);
            }

        } 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 {
                getActionBar().setBackgroundDrawable(td);
            }

            td.startTransition(200);

        }

        oldBackground = ld;

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

    }

    currentColor = newColor;

}

From source file:com.king.base.BaseDialogFragment.java

@Nullable
@Override//from   w  ww.j a  v  a2 s  .c  om
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    super.getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    context = getActivity();
    rootView = inflater.inflate(inflaterRootView(), container, false);

    curPage = 1;
    initUI();
    initData();
    addListeners();
    if (rootView != null)
        return rootView;

    return super.onCreateView(inflater, container, savedInstanceState);
}

From source file:com.lithidsw.wallbox.app.colorwall.ColorWallFrag.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    fa = super.getActivity();
    prefs = fa.getSharedPreferences(C.PREF, Context.MODE_PRIVATE);
    ll = (LinearLayout) inflater.inflate(R.layout.colorwall_frag, container, false);
    mColorCode = (EditText) ll.findViewById(R.id.color_code);
    mColorCode.addTextChangedListener(new TextWatcher() {
        @Override//from   w  w  w.  jav  a 2s  . c  om
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() == 7) {
                if (s.toString().startsWith("#")) {
                    try {
                        mColor = Color.parseColor(s.toString());
                        mPicker.setImageDrawable(new ColorDrawable(mColor));
                    } catch (NumberFormatException e) {
                        mColorCode.setText("");
                        Toast.makeText(fa, "Invalid color format: " + s.toString()
                                + "\nPlease use a valid 6 digit color code", Toast.LENGTH_SHORT).show();
                    }
                } else {
                    mColorCode.setText("");
                    Toast.makeText(fa, "Needs to start with # symbol before color code", Toast.LENGTH_SHORT)
                            .show();
                }
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    wm = WallpaperManager.getInstance(fa);
    ll.findViewById(R.id.color_black).setOnClickListener(this);
    ll.findViewById(R.id.color_white).setOnClickListener(this);
    ll.findViewById(R.id.color_blue).setOnClickListener(this);
    ll.findViewById(R.id.color_green).setOnClickListener(this);
    ll.findViewById(R.id.color_purple).setOnClickListener(this);
    ll.findViewById(R.id.color_yellow).setOnClickListener(this);
    ll.findViewById(R.id.color_red).setOnClickListener(this);

    mPicker = (ImageView) ll.findViewById(R.id.picker);

    if (!prefs.getBoolean(C.PREF_COLORWALL_FIRST_RUN_MAIN, false)) {
        prefs.edit().putBoolean(C.PREF_COLORWALL_FIRST_RUN_MAIN, true).commit();
        String title = getResources().getString(R.string.main_title_colorwall);
        String message = getResources().getString(R.string.colorwall_description);
        new CustomDialogs().openFirstDialog(fa, title, message);
    }
    setHasOptionsMenu(true);
    return ll;
}

From source file:com.marlonjones.voidlauncher.Hotseat.java

public Hotseat(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mLauncher = Launcher.getLauncher(context);
    mHasVerticalHotseat = mLauncher.getDeviceProfile().isVerticalBarLayout();
    mBackgroundColor = ColorUtils//w ww.  java2  s  .  c  o m
            .setAlphaComponent(ContextCompat.getColor(context, R.color.all_apps_container_color), 0);
    mBackground = new ColorDrawable(mBackgroundColor);
    setBackground(mBackground);
}

From source file:com.example.h156252.connected_cars.CarGrid.java

/** Called when the activity is first created. */
@Override/*from ww  w. jav a 2s.  c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_car_grid);
    try {
        Window window = getWindow();

        // clear FLAG_TRANSLUCENT_STATUS flag:
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

        // finally change the color
        window.setStatusBarColor(Color.rgb(0, 0, 0));
        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        actionBar.setBackgroundDrawable(new ColorDrawable(Color.rgb(0, 0, 0)));
    } catch (Exception e) {
        // Toast.makeText(getApplicationContext(),"Exception in actionbar  "+e.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
    }
    session = new SessionManagement(this);
    tts = new TextToSpeech(this, this);
    //Toast.makeText(getApplicationContext(),"Entering activity",Toast.LENGTH_SHORT).show();
    Intent intent = getIntent();
    String result = intent.getStringExtra(HomeScreen.EXTRA_MESSAGE);
    //Toast.makeText(getApplicationContext(),"obtaining result: " +result,Toast.LENGTH_SHORT).show();
    ArrayList<String> listdata = new ArrayList<String>();

    try {

        JSONArray jArray = new JSONArray(result);
        if (jArray != null) {
            for (int i = 0; i < jArray.length(); i++) {

                String jstr = jArray.get(i).toString();
                JSONObject jObj = new JSONObject(jstr);
                String id = jObj.getString("id");
                //String phone = jObj.getString("phone");
                String brand = jObj.getString("text");
                String text = jObj.getString("cartext");
                String carno = jObj.getString("carnum");
                String color = jObj.getString("color");
                //String isDone = jObj.getString("isDone");
                String result_combine = "CAR " + i + ":\nCar id : #" + id + "*\n" + "License No.   : " + carno
                        + "\n" + "Color   : " + color + "\n" + "Brand   : " + brand + "\n"
                        + "Text behind car   : " + text;
                String rr = "Success " + result_combine;
                //Toast.makeText(getApplicationContext(),rr,Toast.LENGTH_SHORT).show();
                String own_id = session.getID();
                if (!(id.equals(own_id)))
                    listdata.add(result_combine);
            }
        }
    } catch (Exception e) {
        //Toast.makeText(getApplicationContext(),e.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
    }

    //Toast.makeText(getApplicationContext(),"out of json",Toast.LENGTH_SHORT).show();
    final GridView gridview = (GridView) findViewById(R.id.gridview);
    // final String[] items = new String[] { "Item1", "Item2", "Item3","Item4", "Item5", "Item6", "Item7", "Item8" };

    ArrayAdapter<String> ad = new ArrayAdapter<String>(getApplicationContext(),
            android.R.layout.simple_list_item_1, listdata);
    //Toast.makeText(getApplicationContext(),"setting array adapter",Toast.LENGTH_SHORT).show();
    //gridview.setBackgroundColor(Color.GRAY);

    gridview.setNumColumns(2);
    gridview.setGravity(Gravity.CENTER);
    gridview.setAdapter(ad);
    gridview.setBackgroundColor(Color.GRAY);
    //Toast.makeText(getApplicationContext(),"setting grid view",Toast.LENGTH_SHORT).show();
    gridview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
            // TODO Auto-generated method stub
            // Toast.makeText(getApplicationContext(), "" + arg2,Toast.LENGTH_SHORT).show();
            //Toast.makeText(getApplicationContext(),"Prompting speech",Toast.LENGTH_SHORT).show();

            try {
                String s = ((TextView) v).getText().toString();

                int start = 0; // '(' position in string
                int end = 0; // ')' position in string
                for (int i = 0; i < s.length(); i++) {
                    if (s.charAt(i) == '#') // Looking for '(' position in string
                        start = i;
                    else if (s.charAt(i) == '*') // Looking for ')' position in  string
                        end = i;
                }
                receiver_id = s.substring(start + 1, end);

                //Toast.makeText(getApplicationContext(), "ID: " + receiver_id, Toast.LENGTH_SHORT).show();
                //promptSpeechInput();

            } catch (Exception e) {
                // Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
            }

            //receiver_id = grid_text.substring(grid_text.indexOf("#") + 1, grid_text.indexOf("#"));
            //Toast.makeText(getApplicationContext(),receiver_id,Toast.LENGTH_SHORT).show();

            try {
                promptSpeechInput();
            } catch (Exception e) {
                //Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
            }

            try {
                Intent intent_rate = new Intent(getApplicationContext(), RateDriving.class);
                intent_rate.putExtra(EXTRA_MESSAGE, receiver_id);
                startActivity(intent_rate);

            } catch (Exception e) {
                //Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
            }

            //new VoiceTask().execute("http://myfirst.au-syd.mybluemix.net/api/Items");
        }
    });

}

From source file:com.adithya321.sharesanalysis.fragments.DashboardFragment.java

@Nullable
@Override/*from   w w w  .  j  a v a2s  .  co  m*/
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_dashboard, container, false);

    Window window = getActivity().getWindow();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        window.setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
    ((AppCompatActivity) getActivity()).getSupportActionBar()
            .setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary)));

    databaseHandler = new DatabaseHandler(getContext());
    sharesRecyclerView = (RecyclerView) root.findViewById(R.id.shares_recycler_view);
    setRecyclerViewAdapter();

    return root;
}

From source file:com.example.josetalito.questapp.SampleGridPagerAdapter.java

public SampleGridPagerAdapter(Context ctx, FragmentManager fm) {
    super(fm);//from  w  w  w .j  a  v a 2s  .  c  o m
    mContext = ctx;

    mRows = new ArrayList<Row>();

    mRows.add(new Row(cardFragment(R.string.welcome_title, R.string.welcome_text)));
    mRows.add(new Row(cardFragment(R.string.about_title, R.string.about_text)));
    mRows.add(new Row(cardFragment(R.string.cards_title, R.string.cards_text),
            cardFragment(R.string.expansion_title, R.string.expansion_text)));
    mRows.add(new Row(cardFragment(R.string.backgrounds_title, R.string.backgrounds_text),
            cardFragment(R.string.columns_title, R.string.columns_text)));
    mRows.add(new Row(new CustomFragment()));
    mRows.add(new Row(cardFragment(R.string.dismiss_title, R.string.dismiss_text)));
    mDefaultBg = new ColorDrawable(R.color.dark_grey);
    mClearBg = new ColorDrawable(android.R.color.transparent);
}

From source file:com.jpventura.xyzreader.ui.ArticleDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    }/*  ww w.  jav  a2  s . c o m*/
    setContentView(R.layout.activity_article_detail);

    getLoaderManager().initLoader(0, null, this);

    mPagerAdapter = new MyPagerAdapter(getFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mPager.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1,
            getResources().getDisplayMetrics()));
    mPager.setPageMarginDrawable(new ColorDrawable(0x22000000));

    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageScrollStateChanged(int state) {
            super.onPageScrollStateChanged(state);

            if (null == mUpButton)
                return;

            mUpButton.animate().alpha((state == ViewPager.SCROLL_STATE_IDLE) ? 1f : 0f).setDuration(300);
        }

        @Override
        public void onPageSelected(int position) {
            if (mCursor != null) {
                mCursor.moveToPosition(position);
            }
            mSelectedItemId = mCursor.getLong(ArticleLoader.Query._ID);
            updateUpButtonPosition();
        }
    });

    mUpButtonContainer = findViewById(R.id.up_container);

    mUpButton = findViewById(R.id.action_up);
    if (null != mUpButton) {
        mUpButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onSupportNavigateUp();
            }
        });
    }

    if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) && (null != mUpButtonContainer)) {
        mUpButtonContainer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @Override
            public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
                view.onApplyWindowInsets(windowInsets);
                mTopInset = windowInsets.getSystemWindowInsetTop();
                mUpButtonContainer.setTranslationY(mTopInset);
                updateUpButtonPosition();
                return windowInsets;
            }
        });
    }

    if (savedInstanceState == null) {
        if (getIntent() != null && getIntent().getData() != null) {
            mStartId = ItemsContract.Items.getItemId(getIntent().getData());
            mSelectedItemId = mStartId;
        }
    }
}

From source file:com.applivery.applvsdklib.ui.views.update.MustUpdateViewImpl.java

/**
 * Overrided in order to get fullScreen dialog
 * @param savedInstanceState/*  w  w  w  . j  a  va 2  s  . c  om*/
 * @return
 */
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {

    final RelativeLayout root = new RelativeLayout(getActivity());
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    final Dialog dialog = new Dialog(getActivity());
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(root);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.YELLOW));
    dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    return dialog;
}

From source file:com.adithya321.sharesanalysis.fragments.FundFlowFragment.java

@Nullable
@Override/*from  w ww.  ja  v a  2 s .  c  om*/
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_fund_flow, container, false);

    Window window = getActivity().getWindow();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        window.setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
    ((AppCompatActivity) getActivity()).getSupportActionBar()
            .setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary)));

    databaseHandler = new DatabaseHandler(getContext());
    fundIn = (TextView) root.findViewById(R.id.fund_in);
    fundOut = (TextView) root.findViewById(R.id.fund_out);
    fundsListView = (ListView) root.findViewById(R.id.funds_list_view);
    setViews();

    FloatingActionButton addFundFab = (FloatingActionButton) root.findViewById(R.id.add_fund_fab);
    addFundFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            final Dialog dialog = new Dialog(getContext());
            dialog.setTitle("Add Fund Flow");
            dialog.setContentView(R.layout.dialog_add_fund);
            dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.WRAP_CONTENT);
            dialog.show();

            Calendar calendar = Calendar.getInstance();
            year_start = calendar.get(Calendar.YEAR);
            month_start = calendar.get(Calendar.MONTH) + 1;
            day_start = calendar.get(Calendar.DAY_OF_MONTH);
            final Button selectDate = (Button) dialog.findViewById(R.id.select_date);
            selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/")
                    .append(year_start));
            selectDate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Dialog dialog = new DatePickerDialog(getActivity(), onDateSetListener, year_start,
                            month_start - 1, day_start);
                    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            selectDate.setText(new StringBuilder().append(day_start).append("/")
                                    .append(month_start).append("/").append(year_start));
                        }
                    });
                    dialog.show();
                }
            });

            final EditText amount = (EditText) dialog.findViewById(R.id.amount);
            Button addFundBtn = (Button) dialog.findViewById(R.id.add_fund_btn);
            addFundBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Fund fund = new Fund();
                    fund.setId(databaseHandler.getNextKey("fund"));

                    String stringStartDate = year_start + " " + month_start + " " + day_start;
                    DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH);
                    try {
                        Date date = format.parse(stringStartDate);
                        fund.setDate(date);
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    try {
                        fund.setAmount(Double.parseDouble(amount.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Amount", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    if (((RadioButton) dialog.findViewById(R.id.radioBtn_fund_in)).isChecked())
                        fund.setType("in");
                    else if (((RadioButton) dialog.findViewById(R.id.radioBtn_fund_out)).isChecked())
                        fund.setType("out");
                    else {
                        Toast.makeText(getActivity(), "Invalid Fund Type", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    databaseHandler.addFund(fund);
                    setViews();
                    dialog.dismiss();
                }
            });
        }
    });

    return root;
}