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:cn.mimail.sdk.net.image.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView//from   w  ww. java  2  s.com
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.elephant.ediyou.imagecache.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView//from w  w  w .j a  v  a2 s  .  c o m
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        //            imageView.setBackgroundDrawable(
        //                    new BitmapDrawable(mResources, mLoadingBitmap));
        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.emergencyskills.doe.aed.UI.activity.TabsActivity.java

public void showconfirmationdialog(final int fragnumber) {
    final Dialog dialog = new Dialog(TabsActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_leaving_confirmation);
    dialog.getWindow()/*from w  w w  . jav a  2  s .c o m*/
            .setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

    Button yes = (Button) dialog.findViewById(R.id.yesbtn);
    yes.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            switch (fragnumber) {
            case 1:
                showpickupschool();
                break;
            case 2:
                showdrill();
                break;
            case 3:
                showservice();
                break;
            case 4:
                showinstall();
                break;
            case 5:
                showpending();
                break;

            }
            dialog.dismiss();

        }
    });
    Button no = (Button) dialog.findViewById(R.id.nobtn);
    no.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    ImageView close = (ImageView) dialog.findViewById(R.id.ivClose);
    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    dialog.show();
}

From source file:com.example.image.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView//from  w  w w  .  j  ava2 s. co m
 * @param bitmap
 */
private void setImageBitmap(final ImageView imageView, final Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                mLoadingBitmap != null ? getLoadingDrawable() : new ColorDrawable(android.R.color.transparent),
                new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        //imageView.setBackgroundDrawable(getLoadingDrawable());

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
        imageView.postDelayed(new Runnable() {

            @Override
            public void run() {
                imageView.setImageBitmap(bitmap);
            }

        }, FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.fastbootmobile.encore.app.MainActivity.java

@Override
public boolean onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    boolean result = true;
    if (mCurrentFragmentIndex == position) {
        return false;
    }//from   w  w  w . ja v  a  2s .c om

    try {
        if (position + 1 < SECTION_DRIVE_MODE) {
            mCurrentFragmentIndex = position;
        }

        final String fragmentTag = "" + position + "_" + mOrientation;

        if (mPlayingBarLayout != null) {
            mPlayingBarLayout.animate().alpha(1).setDuration(400).start();
        }

        Fragment newFrag = null;
        boolean needsBackground = true;
        switch (position + 1) {
        case SECTION_LISTEN_NOW:
            newFrag = ListenNowFragment.newInstance();
            break;
        case SECTION_PLAYLISTS:
            newFrag = PlaylistListFragment.newInstance(true);
            break;
        case SECTION_MY_SONGS:
            newFrag = MySongsFragment.newInstance();
            needsBackground = false;
            break;
        case SECTION_AUTOMIX:
            newFrag = AutomixFragment.newInstance();
            break;
        case SECTION_RECOGNITION:
            newFrag = RecognitionFragment.newInstance();
            break;
        case SECTION_HISTORY:
            newFrag = HistoryFragment.newInstance();
            break;
        case SECTION_LYRICS:
            newFrag = LyricsFragment.newInstance();
            break;
        case SECTION_NOW_PLAYING:
            newFrag = PlaybackQueueFragment.newInstance();
            mPlayingBarLayout.animate().alpha(0).setDuration(400).start();
            break;
        case SECTION_DRIVE_MODE + 1: // offset the divider
            startActivity(new Intent(this, DriveModeActivity.class));
            break;
        case SECTION_SETTINGS + 1: // offset the divider
            startActivity(new Intent(this, SettingsActivity.class));
            break;
        }

        if (needsBackground) {
            getWindow().setBackgroundDrawable(
                    new ColorDrawable(getResources().getColor(R.color.default_fragment_background)));
        } else {
            getWindow().setBackgroundDrawable(null);
        }

        if (newFrag != null) {
            showFragment(newFrag, position + 1 != SECTION_LISTEN_NOW, fragmentTag);
            result = true;
        } else {
            result = false;
        }
    } catch (IllegalStateException e) {
        // The app is pausing
    }

    return result;
}

From source file:com.keju.maomao.imagecache.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView/*ww w .j  a  v a 2 s .  co  m*/
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        //            imageView.setBackgroundDrawable(
        //                    new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.androguide.apkreator.MainActivity.java

/**
 * Method to set the color scheme according to the color defined in
 * config.xml/* w  ww  .  jav  a  2  s .co  m*/
 *
 * @param newColor : the color retrieved from config.xml
 */
public void changeColor(int newColor) {
    tabs.setIndicatorColor(newColor);
    Drawable colorDrawable = new ColorDrawable(newColor);
    Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom);
    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
            getSupportActionBar().setBackgroundDrawable(ld);

    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
            td.setCallback(drawableCallback);
        else
            getSupportActionBar().setBackgroundDrawable(td);
        td.startTransition(200);
    }
    oldBackground = ld;
    currentColor = newColor;

    /**
     * The following is a work-around to avoid NPE, see the following
     * thread:
     *
     * @see http://stackoverflow.com/questions/11002691/actionbar-
     *      setbackgrounddrawable-nulling-background-from-thread-handler
     */
    try {
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
    } catch (NullPointerException e) {
        Log.e("NPE", e.getMessage());
    }

}

From source file:com.blanink.activity.EaseChat.util.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be 
 * set on the ImageView./* w  w  w.ja  v a2  s  .  c  o  m*/
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(Color.CYAN), drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.atgc.cotton.util.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView.//from  ww w.  j  a v  a2  s  .  co m
 *
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final drawable
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(mResources.getColor(R.color.transparent)), drawable });
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.birdeye.MainActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!Prefs.usernames.isSet()) {
        Prefs.usernames.set(Twitter.getSessionManager().getActiveSession().getUserName());
    }//from w  ww  .  j  av  a  2  s .c o m

    setContentView(R.layout.main);
    ButterKnife.bind(this);

    // hideSystemUI(this);
    Chartboost.startWithAppId(MainActivity.this, "57552756f6cd4526e365b9d1",
            "239b2e3aa657ccdcdf0b9674c8750f077b5e0aed");
    Chartboost.setLoggingLevel(CBLogging.Level.ALL);
    Chartboost.setDelegate(delegate);
    Chartboost.onCreate(this);

    tv_cancel = (TextView) findViewById(R.id.tv_cancel);
    tvSetTimer = (Button) findViewById(R.id.tvSetTimer);

    if (!BillingProcessor.isIabServiceAvailable(MainActivity.this)) {
        // showToast("In-app billing service is unavailable, please upgrade Android Market/Play to version >= 3.9.16");
        onBackPressed();
    }

    bp = new BillingProcessor(this, LICENSE_KEY, MERCHANT_ID, new BillingProcessor.IBillingHandler() {
        @Override
        public void onProductPurchased(String productId, TransactionDetails details) {
            showToast("onProductPurchased: " + productId);
            // updateTextViews();
        }

        @Override
        public void onBillingError(int errorCode, Throwable error) {
            showToast("onBillingError: " + Integer.toString(errorCode));
        }

        @Override
        public void onBillingInitialized() {
            showToast("onBillingInitialized");
            readyToPurchase = true;
            //updateTextViews();
        }

        @Override
        public void onPurchaseHistoryRestored() {
            showToast("onPurchaseHistoryRestored");
            for (String sku : bp.listOwnedProducts())
                Log.d(LOG_TAG, "Owned Managed Product: " + sku);
            for (String sku : bp.listOwnedSubscriptions())
                Log.d(LOG_TAG, "Owned Subscription: " + sku);
            //updateTextViews();
            Log.i(LOG_TAG, String.format("%s is%s subscribed", SUBSCRIPTION_ID,
                    bp.isSubscribed(SUBSCRIPTION_ID) ? "" : " not"));
        }
    });

    subs = bp.getSubscriptionListingDetails(SUBSCRIPTION_ID);
    // showToast(subs != null ? subs.toString() : "Failed to load subscription details");

    if (subs == null) {
        //  showToast(subs != null ? subs.toString() : "Failed to load subscription details");
        Globals.hasPaid = false;
    } else {
        Globals.hasPaid = true;
    }

    if (Globals.hasPaid) {
        tvSetTimer.setVisibility(View.VISIBLE);

        message4.setVisibility(View.VISIBLE);
        message5.setVisibility(View.VISIBLE);
        message6.setVisibility(View.VISIBLE);
        message7.setVisibility(View.VISIBLE);
        message8.setVisibility(View.VISIBLE);
        message9.setVisibility(View.VISIBLE);
        message10.setVisibility(View.VISIBLE);
        message11.setVisibility(View.VISIBLE);
        message12.setVisibility(View.VISIBLE);
        message13.setVisibility(View.VISIBLE);
        message14.setVisibility(View.VISIBLE);
        message15.setVisibility(View.VISIBLE);
        message16.setVisibility(View.VISIBLE);
        message17.setVisibility(View.VISIBLE);
        message18.setVisibility(View.VISIBLE);
        message19.setVisibility(View.VISIBLE);
        message20.setVisibility(View.VISIBLE);
        message21.setVisibility(View.VISIBLE);
        message22.setVisibility(View.VISIBLE);
        message23.setVisibility(View.VISIBLE);
        message24.setVisibility(View.VISIBLE);
        message25.setVisibility(View.VISIBLE);

        ets = Arrays.asList(usernames, hashtags, message1, message2, message3, message4, message5, message6,
                message7, message8, message9, message10, message11, message12, message13, message14, message15,
                message16, message17, message18, message19, message20, message21, message22, message23,
                message24, message25);

    } else {
        tvSetTimer.setVisibility(View.GONE);
        message4.setVisibility(View.GONE);
        message5.setVisibility(View.GONE);
        message6.setVisibility(View.GONE);
        message7.setVisibility(View.GONE);
        message8.setVisibility(View.GONE);
        message9.setVisibility(View.GONE);
        message10.setVisibility(View.GONE);
        message11.setVisibility(View.GONE);
        message12.setVisibility(View.GONE);
        message13.setVisibility(View.GONE);
        message14.setVisibility(View.GONE);
        message15.setVisibility(View.GONE);
        message16.setVisibility(View.GONE);
        message17.setVisibility(View.GONE);
        message18.setVisibility(View.GONE);
        message19.setVisibility(View.GONE);
        message20.setVisibility(View.GONE);
        message21.setVisibility(View.GONE);
        message22.setVisibility(View.GONE);
        message23.setVisibility(View.GONE);
        message24.setVisibility(View.GONE);
        message25.setVisibility(View.GONE);
        ets = Arrays.asList(usernames, hashtags, message1, message2, message3);
    }

    tvSetTimer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final Dialog dialog = new Dialog(MainActivity.this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
            dialog.setContentView(R.layout.input_time);
            dialog.setCancelable(true);

            Button bt_set = (Button) dialog.findViewById(R.id.bt_set);
            final EditText et_time = (EditText) dialog.findViewById(R.id.et_time);

            bt_set.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (et_time.getText().toString().equalsIgnoreCase("")) {
                        Toast.makeText(MainActivity.this, "Please enter time to auto shut down",
                                Toast.LENGTH_SHORT).show();
                    }

                    else {

                        int valueTimer = Integer.parseInt(et_time.getText().toString()) * 1000;

                        initateCounter(valueTimer);
                        tv_cancel.setText("Auto ShutDown started");
                        tvSetTimer.setVisibility(View.GONE);
                        tv_cancel.setVisibility(View.VISIBLE);
                        dialog.dismiss();
                    }

                }
            });

            dialog.show();

        }
    });

    cameras.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, Facing.values()));
    //noinspection ConstantConditions
    cameras.setSelection(Prefs.facing.get().ordinal());
    cameras.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Prefs.facing.set(Facing.values()[position]);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    for (TextInputEditText et : ets) {
        DrawableCompat.setTint(et.getBackground(), ContextCompat.getColor(this, R.color.colorAccent));
        final TextInputLayout til = textLayout(et);
        til.setError(null);
        til.setErrorEnabled(false);
    }

    TextViews.setText(usernames, Prefs.usernames.get());
    TextViews.setText(hashtags, Prefs.hashtags.get());
    TextViews.setText(message1, Prefs.message1.get());
    TextViews.setText(message2, Prefs.message2.get());
    TextViews.setText(message3, Prefs.message3.get());

    TextViews.setText(message4, Prefs.message4.get());
    TextViews.setText(message5, Prefs.message5.get());
    TextViews.setText(message6, Prefs.message6.get());
    TextViews.setText(message7, Prefs.message7.get());
    TextViews.setText(message8, Prefs.message8.get());
    TextViews.setText(message9, Prefs.message9.get());
    TextViews.setText(message10, Prefs.message10.get());
    TextViews.setText(message11, Prefs.message11.get());
    TextViews.setText(message12, Prefs.message12.get());
    TextViews.setText(message13, Prefs.message13.get());
    TextViews.setText(message14, Prefs.message14.get());
    TextViews.setText(message15, Prefs.message15.get());
    TextViews.setText(message16, Prefs.message16.get());
    TextViews.setText(message17, Prefs.message17.get());
    TextViews.setText(message18, Prefs.message18.get());
    TextViews.setText(message19, Prefs.message19.get());
    TextViews.setText(message20, Prefs.message20.get());
    TextViews.setText(message21, Prefs.message21.get());
    TextViews.setText(message22, Prefs.message22.get());
    TextViews.setText(message23, Prefs.message23.get());
    TextViews.setText(message24, Prefs.message24.get());
    TextViews.setText(message25, Prefs.message25.get());

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    getWindow().setBackgroundDrawableResource(R.color.bg);

    mAdView = (AdView) findViewById(R.id.adView);
    mInterstitialAd = new InterstitialAd(this);

    // set the ad unit ID
    mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));

    adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            // Check the LogCat to get your test device ID
            .addTestDevice("EB02375D2DA62FFA0F6F145AD2302B3D").build();

    // adRequest = new AdRequest.Builder().build();

    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
        }

        @Override
        public void onAdClosed() {
            //   Toast.makeText(getApplicationContext(), "Ad is closed!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            //  Toast.makeText(getApplicationContext(), "Ad failed to load! error code: " + errorCode, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdLeftApplication() {
            //  Toast.makeText(getApplicationContext(), "Ad left application!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdOpened() {
            super.onAdOpened();
        }
    });

    mAdView.loadAd(adRequest);
    mInterstitialAd.loadAd(adRequest);

    mInterstitialAd.setAdListener(new AdListener() {
        public void onAdLoaded() {
            showInterstitial();
        }

        @Override
        public void onAdClosed() {
            Toast.makeText(getApplicationContext(), "Ad is closed!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            Toast.makeText(getApplicationContext(), "Ad failed to load! error code: " + errorCode,
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdLeftApplication() {
            Toast.makeText(getApplicationContext(), "Ad left application!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdOpened() {
            Toast.makeText(getApplicationContext(), "Ad is opened!", Toast.LENGTH_SHORT).show();
        }
    });

    if (Globals.hasPaid) {
        tv_cancel.setVisibility(View.GONE);
        mAdView.setVisibility(View.GONE);
    } else {

        // initateCounter(120000);
        startRepeatingTask();
        mAdView.setVisibility(View.VISIBLE);
    }

}