Example usage for android.view View setBackgroundColor

List of usage examples for android.view View setBackgroundColor

Introduction

In this page you can find the example usage for android.view View setBackgroundColor.

Prototype

@RemotableViewMethod
public void setBackgroundColor(@ColorInt int color) 

Source Link

Document

Sets the background color for this view.

Usage

From source file:com.vidinoti.pixlive.PixLive.java

protected void pluginInitialize() {

    startSDK(cordova.getActivity());/*from w  ww. j  a v  a 2s  . c  om*/

    VDARSDKController.getInstance().setEnableCodesRecognition(true);

    VDARSDKController.getInstance().setActivity(cordova.getActivity());
    VDARSDKController.getInstance().registerEventReceiver(this);

    VDARSDKController.getInstance().addNewAfterLoadingTask(new Runnable() {
        @Override
        public void run() {

            Intent intent = cordova.getActivity().getIntent();

            if (intent != null && intent.getExtras() != null && intent.getExtras().getString("nid") != null) {

                VDARSDKController.getInstance().processNotification(intent.getExtras().getString("nid"),
                        intent.getExtras().getBoolean("remote"));
            }
        }
    });

    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            if (touchView == null) {
                View v = webView.getView();

                FrameLayout parent = ((FrameLayout) v.getParent());
                parent.removeView(v);

                touchView = new TouchInterceptorView(cordova.getActivity());

                touchView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT));

                cordova.getActivity().setContentView(touchView);

                touchView.addView(v);

                v.setBackgroundColor(Color.TRANSPARENT);
            }
        }
    });
}

From source file:org.gluu.super_gluu.app.fragments.SettingsFragment.SettingsList.SettingsListFragmentAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;

    if (view == null) {
        LayoutInflater inflater = mInflater;
        view = inflater.inflate(R.layout.fragment_setting_list, null);
    }/*  w ww.  j  a  va  2s . c  o m*/
    Map<String, Integer> item = list.get(position);
    Map.Entry<String, Integer> entry = item.entrySet().iterator().next();
    view.setTag(entry);
    TextView settingName = (TextView) view.findViewById(R.id.settings_name);

    if (settingName != null) {
        settingName.setText(entry.getKey());
        settingName.setTypeface(face);
    }
    ImageView settingArrow = (ImageView) view.findViewById(R.id.settingArrow);
    TextView info = (TextView) view.findViewById(R.id.textInfo);
    settingArrow.setVisibility(View.VISIBLE);
    settingArrow.setVisibility(View.GONE);
    if (entry.getValue() == FragmentType.SETTINGS_FRAGMENT_TYPE.VERSION_FRAGMENT.ordinal()) {
        int versionCode = BuildConfig.VERSION_CODE;
        String versionName = BuildConfig.VERSION_NAME;
        info.setText(versionName + " - " + String.valueOf(versionCode));
        view.setBackgroundColor(Color.WHITE);
        info.setVisibility(View.VISIBLE);
        info.setTypeface(face);
    } else if (entry.getValue() != FragmentType.SETTINGS_FRAGMENT_TYPE.EMPTY_FRAGMENT.ordinal()) {
        info.setVisibility(View.GONE);
        settingArrow.setVisibility(View.VISIBLE);
        view.setBackgroundColor(Color.WHITE);
    } else {
        view.setBackgroundColor(Color.parseColor("#efeff4"));
    }

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Map.Entry<String, Integer> entry = (Map.Entry<String, Integer>) v.getTag();
            if (mListener != null
                    && entry.getValue() == FragmentType.SETTINGS_FRAGMENT_TYPE.PIN_CODE_FRAGMENT.ordinal()) {
                mListener.onSettingsList(new SettingsPinCode());
            } else if (mListener != null
                    && entry.getValue() == FragmentType.SETTINGS_FRAGMENT_TYPE.FINGERPRINT_FRAGMENT.ordinal()) {
                mListener.onSettingsList(createSettingsFragment("FingerprintSettings"));
            } else if (mListener != null
                    && entry.getValue() == FragmentType.SETTINGS_FRAGMENT_TYPE.SSL_FRAGMENT.ordinal()) {
                mListener.onSettingsList(createSettingsFragment("SSLConnectionSettings"));
            } else if (entry.getValue() == FragmentType.SETTINGS_FRAGMENT_TYPE.USER_GUIDE_FRAGMENT.ordinal()) {
                Uri uri = Uri.parse("https://gluu.org/docs/supergluu/3.0.0/user-guide/");
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                activity.startActivity(intent);
            } else if (entry.getValue() == FragmentType.SETTINGS_FRAGMENT_TYPE.PRIVACY_POLICY_FRAGMENT
                    .ordinal()) {
                LicenseFragment licenseFragment = new LicenseFragment();
                licenseFragment.setForFirstLoading(false);
                mListener.onSettingsList(licenseFragment);
            } else if (entry.getValue() == FragmentType.SETTINGS_FRAGMENT_TYPE.AD_FREE_FRAGMENT.ordinal()) {
                PurchaseFragment purchaseFragment = new PurchaseFragment();
                mListener.onSettingsList(purchaseFragment);
            }
        }
    });

    return view;
}

From source file:com.money.manager.ex.reports.PayeeReportAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    TextView txtColumn1 = (TextView) view.findViewById(R.id.textViewColumn1);
    TextView txtColumn2 = (TextView) view.findViewById(R.id.textViewColumn2);
    double total = cursor.getDouble(cursor.getColumnIndex("TOTAL"));
    if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(ViewMobileData.PAYEE)))) {
        txtColumn1.setText(cursor.getString(cursor.getColumnIndex(ViewMobileData.PAYEE)));
    } else {/*  w ww. j  av  a2s  .c om*/
        txtColumn1.setText(context.getString(R.string.empty_payee));
    }

    CurrencyService currencyService = new CurrencyService(mContext);

    txtColumn2.setText(currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(),
            MoneyFactory.fromDouble(total)));
    Core core = new Core(context);
    UIHelper uiHelper = new UIHelper(context);
    if (total < 0) {
        txtColumn2.setTextColor(
                ContextCompat.getColor(context, uiHelper.resolveAttribute(R.attr.holo_red_color_theme)));
    } else {
        txtColumn2.setTextColor(
                ContextCompat.getColor(context, uiHelper.resolveAttribute(R.attr.holo_green_color_theme)));
    }

    view.setBackgroundColor(core.resolveColorAttribute(
            cursor.getPosition() % 2 == 1 ? R.attr.row_dark_theme : R.attr.row_light_theme));
}

From source file:com.nttec.everychan.ui.tabs.TabsAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView == null ? inflater.inflate(R.layout.sidebar_tabitem, parent, false) : convertView;
    View dragHandler = view.findViewById(R.id.tab_drag_handle);
    ImageView favIcon = (ImageView) view.findViewById(R.id.tab_favicon);
    TextView title = (TextView) view.findViewById(R.id.tab_text_view);
    ImageView closeBtn = (ImageView) view.findViewById(R.id.tab_close_button);

    dragHandler.getLayoutParams().width = position == draggingItem ? ViewGroup.LayoutParams.WRAP_CONTENT : 0;
    dragHandler.setLayoutParams(dragHandler.getLayoutParams());

    if (position == selectedItem) {
        TypedValue typedValue = ThemeUtils.resolveAttribute(context.getTheme(), R.attr.sidebarSelectedItem,
                true);//  w  w  w  . jav  a2  s .  co m
        if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT
                && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
            view.setBackgroundColor(typedValue.data);
        } else {
            view.setBackgroundResource(typedValue.resourceId);
        }
    } else {
        view.setBackgroundColor(Color.TRANSPARENT);
    }

    TabModel model = this.getItem(position);

    switch (model.type) {
    case TabModel.TYPE_NORMAL:
    case TabModel.TYPE_LOCAL:
        closeBtn.setVisibility(View.VISIBLE);
        String titleText = model.title;
        if (model.unreadPostsCount > 0 || model.autoupdateError) {
            StringBuilder titleStringBuilder = new StringBuilder();
            if (model.unreadSubscriptions)
                titleStringBuilder.append("[*] ");
            if (model.autoupdateError)
                titleStringBuilder.append("[X] ");
            if (model.unreadPostsCount > 0)
                titleStringBuilder.append('[').append(model.unreadPostsCount).append("] ");
            titleText = titleStringBuilder.append(titleText).toString();
        }
        title.setText(titleText);
        ChanModule chan = MainApplication.getInstance().getChanModule(model.pageModel.chanName);
        Drawable icon = chan != null ? chan.getChanFavicon()
                : ResourcesCompat.getDrawable(context.getResources(), android.R.drawable.ic_delete, null);
        if (icon != null) {
            if (model.type == TabModel.TYPE_LOCAL) {
                Drawable[] layers = new Drawable[] { icon, ResourcesCompat.getDrawable(context.getResources(),
                        R.drawable.favicon_overlay_local, null) };
                icon = new LayerDrawable(layers);
            }
            /* XXX
             ?       ( overlay  favicon    ),
             ?   ?? ,   ,     (   ).
            ?    ? ? , , ? -? -  ,    ?.
               ??  ?,   ? ?  .
                    
            else if (model.type == TabModel.TYPE_NORMAL && model.pageModel != null &&
                    model.pageModel.type == UrlPageModel.TYPE_THREADPAGE && model.autoupdateBackground &&
                    MainApplication.getInstance().settings.isAutoupdateEnabled() &&
                    MainApplication.getInstance().settings.isAutoupdateBackground()) {
                Drawable[] layers = new Drawable[] {
                        icon, ResourcesCompat.getDrawable(context.getResources(), R.drawable.favicon_overlay_autoupdate, null) };
                icon = new LayerDrawable(layers);
            }
            */
            favIcon.setImageDrawable(icon);
            favIcon.setVisibility(View.VISIBLE);
        } else {
            favIcon.setVisibility(View.GONE);
        }
        break;
    default:
        closeBtn.setVisibility(View.GONE);
        title.setText(R.string.error_deserialization);
        favIcon.setVisibility(View.GONE);
    }

    closeBtn.setTag(position);
    closeBtn.setOnClickListener(onCloseClick);
    return view;
}

From source file:im.neon.adapters.VectorMessagesAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = super.getView(position, convertView, parent);

    if (null != view) {
        view.setBackgroundColor(Color.TRANSPARENT);
    }//from   www  .  j  a  v  a  2 s .com

    ImageView e2eIconView = (ImageView) view.findViewById(R.id.message_adapter_e2e_icon);
    View senderMargin = view.findViewById(R.id.e2e_sender_margin);
    View senderNameView = view.findViewById(R.id.messagesAdapter_sender);

    // GA issue
    if (position >= getCount()) {
        return view;
    }

    MessageRow row = getItem(position);
    final Event event = row.getEvent();

    if (mE2eIconByEventId.containsKey(event.eventId)) {
        senderMargin.setVisibility(senderNameView.getVisibility());
        e2eIconView.setVisibility(View.VISIBLE);
        e2eIconView.setImageResource(mE2eIconByEventId.get(event.eventId));

        int type = getItemViewType(position);

        if ((type == ROW_TYPE_IMAGE) || (type == ROW_TYPE_VIDEO)) {
            View bodyLayoutView = view.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_body_layout);
            ViewGroup.MarginLayoutParams bodyLayout = (ViewGroup.MarginLayoutParams) bodyLayoutView
                    .getLayoutParams();
            ViewGroup.MarginLayoutParams e2eIconViewLayout = (ViewGroup.MarginLayoutParams) e2eIconView
                    .getLayoutParams();

            e2eIconViewLayout.setMargins(bodyLayout.leftMargin, e2eIconViewLayout.topMargin,
                    e2eIconViewLayout.rightMargin, e2eIconViewLayout.bottomMargin);
            bodyLayout.setMargins(4, bodyLayout.topMargin, bodyLayout.rightMargin, bodyLayout.bottomMargin);
            e2eIconView.setLayoutParams(e2eIconViewLayout);
            bodyLayoutView.setLayoutParams(bodyLayout);
        }

        e2eIconView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mVectorMessagesAdapterEventsListener) {
                    mVectorMessagesAdapterEventsListener.onE2eIconClick(event,
                            mE2eDeviceByEventId.get(event.eventId));
                }
            }
        });
    } else {
        e2eIconView.setVisibility(View.GONE);
        senderMargin.setVisibility(View.GONE);
    }

    return view;
}

From source file:com.google.android.exoplayer2.demo.MediaPlayerFragment.java

public void updateColor(View root) {
    getView().setBackgroundColor(ExplorerActivity.BASE_BACKGROUND);
    debugTextView.setTextColor(ExplorerActivity.TEXT_COLOR);
    //      debugRootView.setBackgroundColor(ExplorerfragActivity.BASE_BACKGROUND);
    root.setBackgroundColor(ExplorerActivity.BASE_BACKGROUND);
    simpleExoPlayerView.setBackgroundColor(ExplorerActivity.BASE_BACKGROUND);
}

From source file:com.facebook.react.views.webview.ReactWebViewManager.java

@Override
protected WebView createViewInstance(final ThemedReactContext reactContext) {
    final ReactWebView webView = new ReactWebView(reactContext);

    /**//from www  . j  a v  a 2  s .  com
     * cookie?
     * 5.0???cookie,5.0?false
     * 
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
    }

    webView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            reactContext.getCurrentActivity().startActivity(intent);

            //                DownloadManager.Request request = new DownloadManager.Request(
            //                        Uri.parse(url));
            //
            //                request.setMimeType(mimetype);
            //                String cookies = CookieManager.getInstance().getCookie(url);
            //                request.addRequestHeader("cookie", cookies);
            //                request.addRequestHeader("User-Agent", userAgent);
            //                request.allowScanningByMediaScanner();
            ////                request.setTitle()
            //                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
            //                request.setDestinationInExternalPublicDir(
            //                        Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(
            //                                url, contentDisposition, mimetype));
            //                DownloadManager dm = (DownloadManager) reactContext.getCurrentActivity().getSystemService(DOWNLOAD_SERVICE);
            //                dm.enqueue(request);
            //                Toast.makeText(reactContext, "...", //To notify the Client that the file is being downloaded
            //                        Toast.LENGTH_LONG).show();

        }
    });
    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onConsoleMessage(ConsoleMessage message) {
            if (ReactBuildConfig.DEBUG) {
                return super.onConsoleMessage(message);
            }
            // Ignore console logs in non debug builds.
            return true;
        }

        @Override
        public void onGeolocationPermissionsShowPrompt(String origin,
                GeolocationPermissions.Callback callback) {
            callback.invoke(origin, true, false);
        }

        private File createImageFile() throws IOException {
            // Create an image file name
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            String imageFileName = "JPEG_" + timeStamp + "_";
            File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
            File imageFile = new File(storageDir, /* directory */
                    imageFileName + ".jpg" /* filename */
            );
            return imageFile;
        }

        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                WebChromeClient.FileChooserParams fileChooserParams) {
            if (mFilePathCallback != null) {
                mFilePathCallback.onReceiveValue(null);
            }
            mFilePathCallback = filePathCallback;

            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent
                    .resolveActivity(reactContext.getCurrentActivity().getPackageManager()) != null) {
                // Create the File where the photo should go
                File photoFile = null;
                try {
                    photoFile = createImageFile();
                    takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
                } catch (IOException ex) {
                    // Error occurred while creating the File
                    FLog.e(ReactConstants.TAG, "Unable to create Image File", ex);
                }

                // Continue only if the File was successfully created
                if (photoFile != null) {
                    mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                } else {
                    takePictureIntent = null;
                }
            }

            Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
            contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
            contentSelectionIntent.setType("*/*");

            Intent[] intentArray;
            if (takePictureIntent != null) {
                intentArray = new Intent[] { takePictureIntent };
            } else {
                intentArray = new Intent[0];
            }

            Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
            chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
            chooserIntent.putExtra(Intent.EXTRA_TITLE, "?");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
            reactContext.getCurrentActivity().startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);

            // final Intent galleryIntent = new Intent(Intent.ACTION_PICK);
            // galleryIntent.setType("image/*");
            // final Intent chooserIntent = Intent.createChooser(galleryIntent, "Choose File");
            // reactContext.getCurrentActivity().startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);

            return true;
        }

        @Override
        public void onShowCustomView(View view, CustomViewCallback callback) {

            if (mVideoView != null) {
                callback.onCustomViewHidden();
                return;
            }

            // Store the view and it's callback for later, so we can dispose of them correctly
            mVideoView = view;
            mCustomViewCallback = callback;

            view.setBackgroundColor(Color.BLACK);
            getRootView().addView(view, FULLSCREEN_LAYOUT_PARAMS);
            webView.setVisibility(View.GONE);

            UiThreadUtil.runOnUiThread(new Runnable() {
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void run() {
                    // If the status bar is translucent hook into the window insets calculations
                    // and consume all the top insets so no padding will be added under the status bar.
                    View decorView = reactContext.getCurrentActivity().getWindow().getDecorView();
                    decorView.setOnApplyWindowInsetsListener(null);
                    ViewCompat.requestApplyInsets(decorView);
                }
            });

            reactContext.getCurrentActivity()
                    .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        }

        @Override
        public void onHideCustomView() {
            if (mVideoView == null) {
                return;
            }

            mVideoView.setVisibility(View.GONE);
            getRootView().removeView(mVideoView);
            mVideoView = null;
            mCustomViewCallback.onCustomViewHidden();
            webView.setVisibility(View.VISIBLE);
            //                View decorView = reactContext.getCurrentActivity().getWindow().getDecorView();
            //                // Show Status Bar.
            //                int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
            //                decorView.setSystemUiVisibility(uiOptions);

            UiThreadUtil.runOnUiThread(new Runnable() {
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void run() {
                    // If the status bar is translucent hook into the window insets calculations
                    // and consume all the top insets so no padding will be added under the status bar.
                    View decorView = reactContext.getCurrentActivity().getWindow().getDecorView();
                    //                                decorView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
                    //                                    @Override
                    //                                    public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                    //                                        WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
                    //                                        return defaultInsets.replaceSystemWindowInsets(
                    //                                                defaultInsets.getSystemWindowInsetLeft(),
                    //                                                0,
                    //                                                defaultInsets.getSystemWindowInsetRight(),
                    //                                                defaultInsets.getSystemWindowInsetBottom());
                    //                                    }
                    //                                });
                    decorView.setOnApplyWindowInsetsListener(null);
                    ViewCompat.requestApplyInsets(decorView);
                }
            });

            reactContext.getCurrentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        }

        private ViewGroup getRootView() {
            return ((ViewGroup) reactContext.getCurrentActivity().findViewById(android.R.id.content));
        }

    });

    reactContext.addLifecycleEventListener(webView);
    reactContext.addActivityEventListener(new ActivityEventListener() {
        @Override
        public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
            if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
                return;
            }
            Uri[] results = null;

            // Check that the response is a good one
            if (resultCode == Activity.RESULT_OK) {
                if (data == null) {
                    // If there is not data, then we may have taken a photo
                    if (mCameraPhotoPath != null) {
                        results = new Uri[] { Uri.parse(mCameraPhotoPath) };
                    }
                } else {
                    String dataString = data.getDataString();
                    if (dataString != null) {
                        results = new Uri[] { Uri.parse(dataString) };
                    }
                }
            }

            if (results == null) {
                mFilePathCallback.onReceiveValue(new Uri[] {});
            } else {
                mFilePathCallback.onReceiveValue(results);
            }
            mFilePathCallback = null;
            return;
        }

        @Override
        public void onNewIntent(Intent intent) {
        }
    });
    mWebViewConfig.configWebView(webView);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setDefaultFontSize(16);
    webView.getSettings().setTextZoom(100);
    // Fixes broken full-screen modals/galleries due to body height being 0.
    webView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    return webView;
}

From source file:com.hyzs.onekeyhelp.home.adapter.HomeRightSlideAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder holder;// w  w w .j a  va  2 s. c om
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = mLayoutInflater.inflate(R.layout.item_right_slide, parent, false);
        holder.mIvIcon = (TextView) convertView.findViewById(R.id.item_right_slide_tv);
        holder.line = convertView.findViewById(R.id.item_right_slide_line);
        holder.mImage = (ImageView) convertView.findViewById(R.id.item_right_slide_img);
        convertView.setTag(holder);
    }
    holder = (ViewHolder) convertView.getTag();
    holder.mIvIcon.setText(type[position]);
    holder.mImage.setImageResource(drawableResource[position]);
    int backType;
    if (position < 4) {
        backType = 0;
    } else if (position > 3 && position < 8) {
        backType = 1;
    } else if (position > 7 && position < 12) {
        backType = 2;
    } else if (position > 11 && position < 16) {
        backType = 3;
    } else
        backType = 4;
    switch (backType) {
    case 0:
        convertView.setBackgroundColor(ContextCompat.getColor(context, R.color.color_e5f8fc));
        holder.mIvIcon.setTextColor(ContextCompat.getColor(context, R.color.color_bb8));
        break;
    case 1:
        convertView.setBackgroundColor(ContextCompat.getColor(context, R.color.color_fbf1f2));
        holder.mIvIcon.setTextColor(ContextCompat.getColor(context, R.color.color_c94048));
        break;
    case 2:
        convertView.setBackgroundColor(ContextCompat.getColor(context, R.color.color_effcf2));
        holder.mIvIcon.setTextColor(ContextCompat.getColor(context, R.color.color_05a028));
        break;
    case 3:
        convertView.setBackgroundColor(ContextCompat.getColor(context, R.color.color_fcfcf0));
        holder.mIvIcon.setTextColor(ContextCompat.getColor(context, R.color.color_b88d0d));
        break;

    case 4:
        convertView.setBackgroundColor(ContextCompat.getColor(context, R.color.color_fdeffe));
        holder.mIvIcon.setTextColor(ContextCompat.getColor(context, R.color.color_9830a3));
        break;

    }
    final View finalConvertView = convertView;
    convertView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!MySharedPreferences.isLogin(context)) {
                pop = HelpDialog.createDialogNoAlert(context, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pop.dismiss();
                    }
                }, "", 0);
                pop.showAtLocation(finalConvertView, Gravity.CENTER, 0, 0);
                return;
            }
            switch (position) {
            case 0:
                intentStart(LifeHelpHomeActivity.class);
                break;
            case 1:
                intentStart(CarResuceActivity.class);
                break;
            case 2:
                intentStart(CarResuceActivity.class);
                break;
            case 3:
                intentStartActive(MovableListActivity.class, 3, type[position]);
                break;
            case 4:
                intentStartActive(MovableListActivity.class, 4, type[position]);
                break;
            case 5:
                intentStartActive(MovableListActivity.class, 5, type[position]);
                break;
            case 6:
                intentStartCircle(CircleActivity.class, 1);
                break;
            case 7:
                intentStartCircle(CircleActivity.class, 2);
                break;
            case 8:
                intentStartCircle(CircleActivity.class, 3);
                break;
            case 9:
                intentStartCircle(CircleActivity.class, 4);
                break;
            case 10:
                intentStartCircle(CircleActivity.class, 5);
                break;
            case 11:
                intentStartCircle(CircleActivity.class, 6);
                break;
            case 12:
                intentStartCircle(CircleActivity.class, 7);
                break;
            case 13:
                intentStart(CommunityNoticeBaseActivity.class);
                break;
            case 14:
                intentStartCircle(BaseNewsActivity.class, 1);
                break;
            case 15:
                intentStartCircle(BaseNewsActivity.class, 2);
                break;
            case 16:
                intentStartCircle(BaseNewsActivity.class, 3);
                break;
            case 17:
                intentStartCircle(ForumActivity.class, 1);
                break;
            case 18:
                intentStartCircle(ForumActivity.class, 2);
                break;
            case 19:
                intentStartCircle(ForumActivity.class, 3);
                break;
            }
        }
    });
    return convertView;
}

From source file:com.eleybourn.bookcatalogue.utils.Utils.java

public static void initBackground(int bgResource, View root, boolean bright) {
    try {//w  ww . j a va 2  s  . c  o  m
        final int backgroundColor = BookCatalogueApp.context.getResources().getColor(R.color.background_grey);

        if (BookCatalogueApp.isBackgroundImageDisabled()) {
            root.setBackgroundColor(backgroundColor);
            if (root instanceof ListView) {
                setCacheColorHintSafely((ListView) root, backgroundColor);
            }
        } else {
            if (root instanceof ListView) {
                ListView lv = ((ListView) root);
                setCacheColorHintSafely(lv, 0x00000000);
            }
            //Drawable d = cleanupTiledBackground(a.getResources().getDrawable(bgResource));
            Drawable d = makeTiledBackground(bright);

            root.setBackgroundDrawable(d);
        }
        root.invalidate();
    } catch (Exception e) {
        // Usually the errors result from memory problems; do a gc just in case.
        System.gc();
        // This is a purely cosmetic function; just log the error
        Logger.logError(e, "Error setting background");
    }
}

From source file:im.neon.adapters.VectorMessagesAdapter.java

@Override
protected boolean manageSubView(int position, View convertView, View subView, int msgType) {
    MessageRow row = getItem(position);//from   ww w  .  ja va  2 s. c o m
    Event event = row.getEvent();

    // mother class implementation
    boolean isMergedView = super.manageSubView(position, convertView, subView, msgType);

    // remove the message separator when it is not required
    View view = convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_message_separator);
    if (null != view) {
        View line = convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_message_separator_line);

        if (null != line) {
            line.setBackgroundColor(Color.TRANSPARENT);
        }
    }

    // display the day separator
    View headerLayout = convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_message_header);
    if (null != headerLayout) {
        String header = headerMessage(position);

        if (null != header) {
            TextView headerText = (TextView) convertView
                    .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_message_header_text);
            headerText.setText(header);
            headerLayout.setVisibility(View.VISIBLE);

            View topHeaderMargin = headerLayout.findViewById(R.id.messagesAdapter_message_header_top_margin);
            topHeaderMargin.setVisibility((0 == position) ? View.GONE : View.VISIBLE);
        } else {
            headerLayout.setVisibility(View.GONE);
        }
    }

    // the timestamp is hidden except for the latest message and when there is no search
    View rightTsTextLayout = convertView
            .findViewById(org.matrix.androidsdk.R.id.message_timestamp_layout_right);

    if (null != rightTsTextLayout) {
        TextView tsTextView = (TextView) rightTsTextLayout
                .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_timestamp);

        if (null != tsTextView) {
            tsTextView.setVisibility(
                    (((position + 1) == this.getCount()) || mIsSearchMode) ? View.VISIBLE : View.GONE);
        }
    }

    // On Vector application, the read receipts are displayed in a dedicated line under the message
    View avatarsListView = convertView.findViewById(R.id.messagesAdapter_avatars_list);

    if (null != avatarsListView) {
        displayReadReceipts(avatarsListView, event.eventId, row.getRoomState());
    }

    // selection mode
    manageSelectionMode(convertView, event);

    // search message mode
    View highlightMakerView = convertView.findViewById(R.id.messagesAdapter_highlight_message_marker);

    if (null != highlightMakerView) {
        if (TextUtils.equals(mSearchedEventId, event.eventId)) {
            View avatarView = convertView
                    .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_roundAvatar_left);
            ViewGroup.LayoutParams avatarLayout = avatarView.getLayoutParams();

            // align marker view with the message
            ViewGroup.MarginLayoutParams highlightMakerLayout = (ViewGroup.MarginLayoutParams) highlightMakerView
                    .getLayoutParams();

            if (isMergedView) {
                highlightMakerLayout.setMargins(avatarLayout.width + 5, highlightMakerLayout.topMargin, 5,
                        highlightMakerLayout.bottomMargin);

            } else {
                highlightMakerLayout.setMargins(5, highlightMakerLayout.topMargin, 5,
                        highlightMakerLayout.bottomMargin);
            }

            highlightMakerView.setLayoutParams(highlightMakerLayout);

            // move left the body
            View bodyLayoutView = convertView
                    .findViewById(org.matrix.androidsdk.R.id.messagesAdapter_body_layout);
            ViewGroup.MarginLayoutParams bodyLayout = (ViewGroup.MarginLayoutParams) bodyLayoutView
                    .getLayoutParams();
            bodyLayout.setMargins(4, bodyLayout.topMargin, 4, bodyLayout.bottomMargin);

            highlightMakerView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.vector_green_color));
        } else {
            highlightMakerView
                    .setBackgroundColor(ContextCompat.getColor(mContext, android.R.color.transparent));
        }
    }

    // download / upload progress layout
    if ((ROW_TYPE_IMAGE == msgType) || (ROW_TYPE_FILE == msgType) || (ROW_TYPE_VIDEO == msgType)) {
        View bodyLayoutView = convertView.findViewById(org.matrix.androidsdk.R.id.messagesAdapter_body_layout);
        ViewGroup.MarginLayoutParams bodyLayoutParams = (ViewGroup.MarginLayoutParams) bodyLayoutView
                .getLayoutParams();
        int marginLeft = bodyLayoutParams.leftMargin;

        View downloadProgressLayout = convertView
                .findViewById(org.matrix.androidsdk.R.id.content_download_progress_layout);

        if (null != downloadProgressLayout) {
            ViewGroup.MarginLayoutParams downloadProgressLayoutParams = (ViewGroup.MarginLayoutParams) downloadProgressLayout
                    .getLayoutParams();
            downloadProgressLayoutParams.setMargins(marginLeft, downloadProgressLayoutParams.topMargin,
                    downloadProgressLayoutParams.rightMargin, downloadProgressLayoutParams.bottomMargin);
            downloadProgressLayout.setLayoutParams(downloadProgressLayoutParams);
        }

        View uploadProgressLayout = convertView
                .findViewById(org.matrix.androidsdk.R.id.content_upload_progress_layout);

        if (null != uploadProgressLayout) {
            ViewGroup.MarginLayoutParams uploadProgressLayoutParams = (ViewGroup.MarginLayoutParams) uploadProgressLayout
                    .getLayoutParams();
            uploadProgressLayoutParams.setMargins(marginLeft, uploadProgressLayoutParams.topMargin,
                    uploadProgressLayoutParams.rightMargin, uploadProgressLayoutParams.bottomMargin);
            uploadProgressLayout.setLayoutParams(uploadProgressLayoutParams);
        }
    }
    return isMergedView;
}