Search in sources :

Example 1 with LayoutParams

use of android.widget.AbsListView.LayoutParams in project android-betterpickers by code-troopers.

the class MonthAdapter method getView.

@SuppressLint("NewApi")
@SuppressWarnings("unchecked")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    MonthView monthView;
    HashMap<String, Integer> drawingParams = null;
    if (convertView != null) {
        monthView = (MonthView) convertView;
        // We store the drawing parameters in the view so it can be recycled
        drawingParams = (HashMap<String, Integer>) monthView.getTag();
    } else {
        monthView = createMonthView(mContext);
        monthView.setTheme(mThemeColors);
        // Set up the new view
        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        monthView.setLayoutParams(params);
        monthView.setClickable(true);
        monthView.setOnDayClickListener(this);
    }
    if (drawingParams == null) {
        drawingParams = new HashMap<String, Integer>();
    }
    drawingParams.clear();
    final int month = (position + mController.getMinDate().month) % MONTHS_IN_YEAR;
    final int year = (position + mController.getMinDate().month) / MONTHS_IN_YEAR + mController.getMinDate().year;
    int selectedDay = -1;
    if (isSelectedDayInMonth(year, month)) {
        selectedDay = mSelectedDay.day;
    }
    int rangeMin = -1;
    if (isRangeMinInMonth(year, month)) {
        rangeMin = mController.getMinDate().day;
    }
    int rangeMax = -1;
    if (isRangeMaxInMonth(year, month)) {
        rangeMax = mController.getMaxDate().day;
    }
    // Invokes requestLayout() to ensure that the recycled view is set with the appropriate
    // height/number of weeks before being displayed.
    monthView.reuse();
    // Set disabled days if they exist
    if (mController.getDisabledDays() != null) {
        monthView.setDisabledDays(mController.getDisabledDays());
    }
    drawingParams.put(MonthView.VIEW_PARAMS_SELECTED_DAY, selectedDay);
    drawingParams.put(MonthView.VIEW_PARAMS_YEAR, year);
    drawingParams.put(MonthView.VIEW_PARAMS_MONTH, month);
    drawingParams.put(MonthView.VIEW_PARAMS_WEEK_START, mController.getFirstDayOfWeek());
    drawingParams.put(MonthView.VIEW_PARAMS_RANGE_MIN, rangeMin);
    drawingParams.put(MonthView.VIEW_PARAMS_RANGE_MAX, rangeMax);
    monthView.setMonthParams(drawingParams);
    monthView.invalidate();
    return monthView;
}
Also used : LayoutParams(android.widget.AbsListView.LayoutParams) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 2 with LayoutParams

use of android.widget.AbsListView.LayoutParams in project BlurEffectForAndroidDesign by PomepuyN.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_main);
    // Get the screen width
    final int screenWidth = ImageUtils.getScreenWidth(this);
    // Find the view
    mBlurredImage = (ImageView) findViewById(R.id.blurred_image);
    mNormalImage = (ImageView) findViewById(R.id.normal_image);
    mBlurredImageHeader = (ScrollableImageView) findViewById(R.id.blurred_image_header);
    mSwitch = (Switch) findViewById(R.id.background_switch);
    mList = (ListView) findViewById(R.id.list);
    // prepare the header ScrollableImageView
    mBlurredImageHeader.setScreenWidth(screenWidth);
    // Action for the switch
    mSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mBlurredImage.setAlpha(alpha);
            } else {
                mBlurredImage.setAlpha(0f);
            }
        }
    });
    // Try to find the blurred image
    final File blurredImage = new File(getFilesDir() + BLURRED_IMG_PATH);
    if (!blurredImage.exists()) {
        // launch the progressbar in ActionBar
        setProgressBarIndeterminateVisibility(true);
        new Thread(new Runnable() {

            @Override
            public void run() {
                // No image found => let's generate it!
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 2;
                Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.image, options);
                Bitmap newImg = Blur.fastblur(MainActivity.this, image, 12);
                ImageUtils.storeImage(newImg, blurredImage);
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        updateView(screenWidth);
                        // And finally stop the progressbar
                        setProgressBarIndeterminateVisibility(false);
                    }
                });
            }
        }).start();
    } else {
        // The image has been found. Let's update the view
        updateView(screenWidth);
    }
    String[] strings = getResources().getStringArray(R.array.list_content);
    // Prepare the header view for our list
    headerView = new View(this);
    headerView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, TOP_HEIGHT));
    mList.addHeaderView(headerView);
    mList.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, strings));
    mList.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        /**
			 * Listen to the list scroll. This is where magic happens ;)
			 */
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            // Calculate the ratio between the scroll amount and the list
            // header weight to determinate the top picture alpha
            alpha = (float) -headerView.getTop() / (float) TOP_HEIGHT;
            // Apply a ceil
            if (alpha > 1) {
                alpha = 1;
            }
            // Apply on the ImageView if needed
            if (mSwitch.isChecked()) {
                mBlurredImage.setAlpha(alpha);
            }
            // Parallax effect : we apply half the scroll amount to our
            // three views
            mBlurredImage.setTop(headerView.getTop() / 2);
            mNormalImage.setTop(headerView.getTop() / 2);
            mBlurredImageHeader.handleScroll(headerView.getTop() / 2);
        }
    });
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) LayoutParams(android.widget.AbsListView.LayoutParams) AbsListView(android.widget.AbsListView) ImageView(android.widget.ImageView) AbsListView(android.widget.AbsListView) View(android.view.View) ListView(android.widget.ListView) Bitmap(android.graphics.Bitmap) OnScrollListener(android.widget.AbsListView.OnScrollListener) BitmapFactory(android.graphics.BitmapFactory) File(java.io.File) CompoundButton(android.widget.CompoundButton)

Example 3 with LayoutParams

use of android.widget.AbsListView.LayoutParams in project KJFrameForAndroid by kymjs.

the class EmojiGridAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = new ImageView(cxt);
        LayoutParams params = new LayoutParams(120, 120);
        convertView.setLayoutParams(params);
        convertView.setPadding(10, 10, 10, 10);
        holder.image = (ImageView) convertView;
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    holder.image.setImageResource(datas.get(position).getResId());
    return convertView;
}
Also used : LayoutParams(android.widget.AbsListView.LayoutParams) ImageView(android.widget.ImageView)

Example 4 with LayoutParams

use of android.widget.AbsListView.LayoutParams in project Etar-Calendar by Etar-Group.

the class SimpleWeeksAdapter method getView.

@SuppressWarnings("unchecked")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    SimpleWeekView v;
    HashMap<String, Integer> drawingParams = null;
    if (convertView != null) {
        v = (SimpleWeekView) convertView;
        // We store the drawing parameters in the view so it can be recycled
        drawingParams = (HashMap<String, Integer>) v.getTag();
    } else {
        v = new SimpleWeekView(mContext);
        // Set up the new view
        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        v.setLayoutParams(params);
        v.setClickable(true);
        v.setOnTouchListener(this);
    }
    if (drawingParams == null) {
        drawingParams = new HashMap<String, Integer>();
    }
    drawingParams.clear();
    int selectedDay = -1;
    if (mSelectedWeek == position) {
        selectedDay = mSelectedDay.weekDay;
    }
    // pass in all the view parameters
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_HEIGHT, (parent.getHeight() - WEEK_7_OVERHANG_HEIGHT) / mNumWeeks);
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_SELECTED_DAY, selectedDay);
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_SHOW_WK_NUM, mShowWeekNumber ? 1 : 0);
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_WEEK_START, mFirstDayOfWeek);
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_NUM_DAYS, mDaysPerWeek);
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_WEEK, position);
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_FOCUS_MONTH, mFocusMonth);
    v.setWeekParams(drawingParams, mSelectedDay.timezone);
    v.invalidate();
    return v;
}
Also used : LayoutParams(android.widget.AbsListView.LayoutParams)

Example 5 with LayoutParams

use of android.widget.AbsListView.LayoutParams in project Etar-Calendar by Etar-Group.

the class MonthByWeekAdapter method getView.

@SuppressWarnings("unchecked")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (mIsMiniMonth) {
        return super.getView(position, convertView, parent);
    }
    MonthWeekEventsView v;
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    HashMap<String, Integer> drawingParams = null;
    boolean isAnimatingToday = false;
    if (convertView != null) {
        v = (MonthWeekEventsView) convertView;
        // params, so this is assuming the view is relatively stable
        if (mAnimateToday && v.updateToday(mSelectedDay.timezone)) {
            long currentTime = System.currentTimeMillis();
            // before reaching today.
            if (currentTime - mAnimateTime > ANIMATE_TODAY_TIMEOUT) {
                mAnimateToday = false;
                mAnimateTime = 0;
            } else {
                isAnimatingToday = true;
                // There is a bug that causes invalidates to not work some
                // of the time unless we recreate the view.
                v = new MonthWeekEventsView(mContext);
            }
        } else {
            drawingParams = (HashMap<String, Integer>) v.getTag();
        }
    } else {
        v = new MonthWeekEventsView(mContext);
    }
    if (drawingParams == null) {
        drawingParams = new HashMap<String, Integer>();
    }
    drawingParams.clear();
    v.setLayoutParams(params);
    v.setClickable(true);
    v.setOnTouchListener(this);
    int selectedDay = -1;
    if (mSelectedWeek == position) {
        selectedDay = mSelectedDay.weekDay;
    }
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_HEIGHT, parent.getHeight() / mNumWeeks);
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_SELECTED_DAY, selectedDay);
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_SHOW_WK_NUM, mShowWeekNumber ? 1 : 0);
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_WEEK_START, mFirstDayOfWeek);
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_NUM_DAYS, mDaysPerWeek);
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_WEEK, position);
    drawingParams.put(SimpleWeekView.VIEW_PARAMS_FOCUS_MONTH, mFocusMonth);
    drawingParams.put(MonthWeekEventsView.VIEW_PARAMS_ORIENTATION, mOrientation);
    if (isAnimatingToday) {
        drawingParams.put(MonthWeekEventsView.VIEW_PARAMS_ANIMATE_TODAY, 1);
        mAnimateToday = false;
    }
    v.setWeekParams(drawingParams, mSelectedDay.timezone);
    sendEventsToView(v);
    return v;
}
Also used : LayoutParams(android.widget.AbsListView.LayoutParams)

Aggregations

LayoutParams (android.widget.AbsListView.LayoutParams)7 SuppressLint (android.annotation.SuppressLint)3 ImageView (android.widget.ImageView)2 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 OnScrollListener (android.widget.AbsListView.OnScrollListener)1 CompoundButton (android.widget.CompoundButton)1 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)1 ListView (android.widget.ListView)1 File (java.io.File)1