Example usage for android.graphics Color TRANSPARENT

List of usage examples for android.graphics Color TRANSPARENT

Introduction

In this page you can find the example usage for android.graphics Color TRANSPARENT.

Prototype

int TRANSPARENT

To view the source code for android.graphics Color TRANSPARENT.

Click Source Link

Usage

From source file:com.mobiroller.tools.inappbrowser.MobirollerInAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject//from w w w . j a  va2 s .co m
 */
public String showWebPage(final String url, final HashMap<String, Boolean> features) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    showZoomControls = false;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean zoom = features.get(ZOOM);
        if (zoom != null) {
            showZoomControls = zoom.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
        Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON);
        if (hardwareBack != null) {
            hadwareBackButton = hardwareBack.booleanValue();
        }
        Boolean cache = features.get(CLEAR_ALL_CACHE);
        if (cache != null) {
            clearAllCache = cache.booleanValue();
        } else {
            cache = features.get(CLEAR_SESSION_CACHE);
            if (cache != null) {
                clearSessionCache = cache.booleanValue();
            }
        }
    }

    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new MobirollerInAppBrowserDialog(cordova.getActivity(),
                    android.R.style.Theme_Translucent_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setInAppBroswer(getInAppBrowser());

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setBackgroundColor(Color.TRANSPARENT);
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            //Please, no more black!
            toolbar.setBackgroundColor(Color.TRANSPARENT);
            toolbar.setLayoutParams(new RelativeLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
                    this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            Resources activityRes = cordova.getActivity().getResources();
            int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable backIcon = activityRes.getDrawable(backResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                back.setBackgroundDrawable(backIcon);
            } else {
                back.setBackground(backIcon);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable fwdIcon = activityRes.getDrawable(fwdResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                forward.setBackgroundDrawable(fwdIcon);
            } else {
                forward.setBackground(fwdIcon);
            }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close/Done button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable closeIcon = activityRes.getDrawable(closeResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                close.setBackgroundDrawable(closeIcon);
            } else {
                close.setBackground(closeIcon);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new MobirollerInAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(showZoomControls);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null ? true
                    : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (clearAllCache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (clearSessionCache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            //                toolbar.addView(actionButtonContainer);
            //                toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(inAppWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            //Mobiroller Needs
            DisplayMetrics metrics = cordova.getActivity().getResources().getDisplayMetrics();
            Rect windowRect = new Rect();
            webView.getView().getWindowVisibleDisplayFrame(windowRect);

            int bottomGap = 0;
            if (features.containsKey("hasTabs")) {
                if (features.get("hasTabs")) {
                    bottomGap += Math.ceil(44 * metrics.density);
                }
            }
            lp.height = (windowRect.bottom - windowRect.top) - (bottomGap);
            lp.gravity = Gravity.TOP;
            lp.format = PixelFormat.TRANSPARENT;
            close.setAlpha(0);
            //Mobiroller Needs

            dialog.setContentView(main);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.show();
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.htc.dotdesign.DrawingView.java

private Bitmap handlePicture() {
    Paint paint = new Paint();
    Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    int[][] mCloneArray = new int[mRowSize][mColSize];
    float left = 0;
    float top = 0;
    float right = sDotPixelWidth;
    float bottom = sDotPixelHeight;
    for (int row = 0; row < mRowSize; ++row) {
        for (int col = 0; col < mColSize; ++col) {
            if (mImgDotMatrix[row][col] == Color.TRANSPARENT) {
                mCloneArray[row][col] = Color.BLACK;
            } else {
                mCloneArray[row][col] = mImgDotMatrix[row][col];
            }/* w ww  .j  ava  2s.c o  m*/
            paint.setColor(mCloneArray[row][col]);
            canvas.drawRect(left, top, right, bottom, paint);
            left += sDotPixelWidth;
            right += sDotPixelWidth;
        }
        left = 0;
        right = sDotPixelWidth;
        top += sDotPixelHeight;
        bottom += sDotPixelHeight;
    }
    return bitmap;
}

From source file:com.android.messaging.ui.conversationlist.ConversationListItemView.java

@VisibleForAnimation
public void setSwipeTranslationX(final float translationX) {
    mSwipeableContainer.setTranslationX(translationX);
    if (translationX == 0) {
        mCrossSwipeBackground.setVisibility(View.GONE);
        mCrossSwipeArchiveLeftImageView.setVisibility(GONE);
        mCrossSwipeArchiveRightImageView.setVisibility(GONE);

        mSwipeableContainer.setBackgroundColor(Color.TRANSPARENT);
    } else {/*from w ww. ja  va  2s . com*/
        mCrossSwipeBackground.setVisibility(View.VISIBLE);
        if (translationX > 0) {
            mCrossSwipeArchiveLeftImageView.setVisibility(VISIBLE);
            mCrossSwipeArchiveRightImageView.setVisibility(GONE);
        } else {
            mCrossSwipeArchiveLeftImageView.setVisibility(GONE);
            mCrossSwipeArchiveRightImageView.setVisibility(VISIBLE);
        }
        mSwipeableContainer.setBackgroundResource(R.drawable.swipe_shadow_drag);
    }
}

From source file:android.support.v7.widget.AppCompatDrawableManager.java

private ColorStateList createBorderlessButtonColorStateList(Context context) {
    return createButtonColorStateList(context, Color.TRANSPARENT);
}

From source file:com.example.amapdemo.heatmap.HeatmapTileProvider.java

/**
 * Converts a grid of intensity values to a colored Bitmap, using a given color map
 *
 * @param grid     the input grid (assumed to be square)
 * @param colorMap color map (created by generateColorMap)
 * @param max      Maximum intensity value: maps to 100% on gradient
 * @return the colorized grid in Bitmap form, with same dimensions as grid
 *///from ww w  .j a v a 2  s.c o m
static Bitmap colorize(double[][] grid, int[] colorMap, double max) {
    // Maximum color value
    int maxColor = colorMap[colorMap.length - 1];
    // Multiplier to "scale" intensity values with, to map to appropriate color
    double colorMapScaling = (colorMap.length - 1) / max;
    // Dimension of the input grid (and dimension of output bitmap)
    int dim = grid.length;

    int i, j, index, col;
    double val;
    // Array of colors
    int colors[] = new int[dim * dim];
    for (i = 0; i < dim; i++) {
        for (j = 0; j < dim; j++) {
            // [x][y]
            // need to enter each row of x coordinates sequentially (x first)
            // -> [j][i]
            val = grid[j][i];
            index = i * dim + j;
            col = (int) (val * colorMapScaling);

            if (val != 0) {
                // Make it more resilient: cant go outside colorMap
                if (col < colorMap.length)
                    colors[index] = colorMap[col];
                else
                    colors[index] = maxColor;
            } else {
                colors[index] = Color.TRANSPARENT;
            }
        }
    }

    // Now turn these colors into a bitmap
    Bitmap tile = Bitmap.createBitmap(dim, dim, Bitmap.Config.ARGB_8888);
    // (int[] pixels, int offset, int stride, int x, int y, int width, int height)
    tile.setPixels(colors, 0, dim, 0, 0, dim, dim);
    return tile;
}

From source file:com.heinrichreimersoftware.materialintro.app.IntroActivity.java

private void updateBackground() {
    @ColorInt/*from  w w  w .j  a v a  2 s  . c  o m*/
    int background;
    @ColorInt
    int backgroundNext;
    @ColorInt
    int backgroundDark;
    @ColorInt
    int backgroundDarkNext;

    if (position == getCount()) {
        background = Color.TRANSPARENT;
        backgroundNext = Color.TRANSPARENT;
        backgroundDark = Color.TRANSPARENT;
        backgroundDarkNext = Color.TRANSPARENT;
    } else {
        background = ContextCompat.getColor(IntroActivity.this, getBackground(position));
        backgroundNext = ContextCompat.getColor(IntroActivity.this,
                getBackground(Math.min(position + 1, getCount() - 1)));

        background = ColorUtils.setAlphaComponent(background, 0xFF);
        backgroundNext = ColorUtils.setAlphaComponent(backgroundNext, 0xFF);

        try {
            backgroundDark = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(position));
        } catch (Resources.NotFoundException e) {
            backgroundDark = ContextCompat.getColor(IntroActivity.this, R.color.mi_status_bar_background);
        }
        try {
            backgroundDarkNext = ContextCompat.getColor(IntroActivity.this,
                    getBackgroundDark(Math.min(position + 1, getCount() - 1)));
        } catch (Resources.NotFoundException e) {
            backgroundDarkNext = ContextCompat.getColor(IntroActivity.this, R.color.mi_status_bar_background);
        }
    }

    if (position + positionOffset >= adapter.getCount() - 1) {
        backgroundNext = ColorUtils.setAlphaComponent(background, 0x00);
        backgroundDarkNext = ColorUtils.setAlphaComponent(backgroundDark, 0x00);
    }

    background = (Integer) evaluator.evaluate(positionOffset, background, backgroundNext);
    backgroundDark = (Integer) evaluator.evaluate(positionOffset, backgroundDark, backgroundDarkNext);

    miFrame.setBackgroundColor(background);

    float[] backgroundDarkHsv = new float[3];
    Color.colorToHSV(backgroundDark, backgroundDarkHsv);
    //Slightly darken the background color a bit for more contrast
    backgroundDarkHsv[2] *= 0.95;
    int backgroundDarker = Color.HSVToColor(backgroundDarkHsv);
    miPagerIndicator.setPageIndicatorColor(backgroundDarker);
    ViewCompat.setBackgroundTintList(miButtonNext, ColorStateList.valueOf(backgroundDarker));
    ViewCompat.setBackgroundTintList(miButtonBack, ColorStateList.valueOf(backgroundDarker));

    @ColorInt
    int backgroundButtonCta = buttonCtaTintMode == BUTTON_CTA_TINT_MODE_TEXT
            ? ContextCompat.getColor(this, android.R.color.white)
            : backgroundDarker;
    ViewCompat.setBackgroundTintList(miButtonCta.getChildAt(0), ColorStateList.valueOf(backgroundButtonCta));
    ViewCompat.setBackgroundTintList(miButtonCta.getChildAt(1), ColorStateList.valueOf(backgroundButtonCta));

    int iconColor;
    if (ColorUtils.calculateLuminance(backgroundDark) > 0.4) {
        //Light background
        iconColor = ContextCompat.getColor(this, R.color.mi_icon_color_light);
    } else {
        //Dark background
        iconColor = ContextCompat.getColor(this, R.color.mi_icon_color_dark);
    }
    miPagerIndicator.setCurrentPageIndicatorColor(iconColor);
    DrawableCompat.setTint(miButtonNext.getDrawable(), iconColor);
    DrawableCompat.setTint(miButtonBack.getDrawable(), iconColor);

    @ColorInt
    int textColorButtonCta = buttonCtaTintMode == BUTTON_CTA_TINT_MODE_TEXT ? backgroundDarker : iconColor;
    ((Button) miButtonCta.getChildAt(0)).setTextColor(textColorButtonCta);
    ((Button) miButtonCta.getChildAt(1)).setTextColor(textColorButtonCta);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(backgroundDark);

        if (position == adapter.getCount()) {
            getWindow().setNavigationBarColor(Color.TRANSPARENT);
        } else if (position + positionOffset >= adapter.getCount() - 1) {
            TypedValue typedValue = new TypedValue();
            TypedArray a = obtainStyledAttributes(typedValue.data,
                    new int[] { android.R.attr.navigationBarColor });

            int defaultNavigationBarColor = a.getColor(0, Color.BLACK);

            a.recycle();

            int navigationBarColor = (Integer) evaluator.evaluate(positionOffset, defaultNavigationBarColor,
                    Color.TRANSPARENT);
            getWindow().setNavigationBarColor(navigationBarColor);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            int systemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();
            int flagLightStatusBar = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
            if (ColorUtils.calculateLuminance(backgroundDark) > 0.4) {
                //Light background
                systemUiVisibility |= flagLightStatusBar;
            } else {
                //Dark background
                systemUiVisibility &= ~flagLightStatusBar;
            }
            getWindow().getDecorView().setSystemUiVisibility(systemUiVisibility);
        }
    }
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static int getTextColorPrimary(final Context context) {
    final TypedArray a = context.obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary });
    try {/* ww w.ja v a 2s  . co m*/
        return a.getColor(0, Color.TRANSPARENT);
    } finally {
        a.recycle();
    }
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static int getTextColorSecondary(final Context context) {
    final TypedArray a = context.obtainStyledAttributes(new int[] { android.R.attr.textColorSecondary });
    try {/*w w  w .j ava  2  s. c o m*/
        return a.getColor(0, Color.TRANSPARENT);
    } finally {
        a.recycle();
    }
}

From source file:android.support.v7.widget.AppCompatDrawableManager.java

private static PorterDuffColorFilter createTintFilter(ColorStateList tint, PorterDuff.Mode tintMode,
        final int[] state) {
    if (tint == null || tintMode == null) {
        return null;
    }/*  ww  w  .j  av  a 2 s . c  om*/
    final int color = tint.getColorForState(state, Color.TRANSPARENT);
    return getPorterDuffColorFilter(color, tintMode);
}