Example usage for android.view View setLayoutParams

List of usage examples for android.view View setLayoutParams

Introduction

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

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.mfh.framework.uikit.widget.SideSlidingTabStrip.java

/**
 * views?ViewView?parentViewHeight//  w  w  w . j a  va  2s .co  m
 * 
 * @param views
 *            ?View?
 * @param parentViewHeight
 *            Vie 
 * @param parentWidthMeasureSpec
 *            View
 * @param parentHeightMeasureSpec
 *            View
 */
private void adjustChildHeightWithParent(List<View> views, int parentViewHeight, int parentWidthMeasureSpec,
        int parentHeightMeasureSpec) {
    // ?View?
    for (View view : views) {
        if (view.getLayoutParams() instanceof MarginLayoutParams) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) view.getLayoutParams();
            parentViewHeight -= lp.topMargin + lp.bottomMargin;
        }
    }

    // ?View???
    int averageHeight = parentViewHeight / views.size();
    int bigTabCount = views.size();
    while (true) {
        Iterator<View> iterator = views.iterator();
        while (iterator.hasNext()) {
            View view = iterator.next();
            if (view.getMeasuredWidth() > averageHeight) {
                parentViewHeight -= view.getMeasuredHeight();
                bigTabCount--;
                iterator.remove();
            }
        }
        averageHeight = parentViewHeight / bigTabCount;
        boolean end = true;
        for (View view : views) {
            if (view.getMeasuredWidth() > averageHeight) {
                end = false;
            }
        }
        if (end) {
            break;
        }
    }

    // ??View
    for (View view : views) {
        if (view.getMeasuredHeight() < averageHeight) {
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
            layoutParams.height = averageHeight;
            view.setLayoutParams(layoutParams);
            // ??
            if (layoutParams instanceof MarginLayoutParams) {
                measureChildWithMargins(view, parentWidthMeasureSpec, 0, parentHeightMeasureSpec, 0);
            } else {
                measureChild(view, parentWidthMeasureSpec, parentHeightMeasureSpec);
            }
        }
    }
}

From source file:com.miz.functions.MizLib.java

/**
 * Add a margin with a combined height of the ActionBar and Status bar to the top of a given View contained in a FrameLayout
 * @param c//from  ww  w.j  av  a  2 s.c  o  m
 * @param v
 */
public static void addActionBarAndStatusBarMargin(Context c, View v) {
    int mActionBarHeight = 0, mStatusBarHeight = 0;
    TypedValue tv = new TypedValue();
    if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                c.getResources().getDisplayMetrics());
    else
        mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme)

    if (hasKitKat())
        mStatusBarHeight = convertDpToPixels(c, 25);

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    params.setMargins(0, mActionBarHeight + mStatusBarHeight, 0, 0);

    v.setLayoutParams(params);
}

From source file:com.bw.luzz.monkeyapplication.View.DateTimePicker.time.TimePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.mdtp_time_picker_dialog, container, false);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);

    // If an accent color has not been set manually, get it from the context
    if (mAccentColor == -1) {
        mAccentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity());
    }/*from ww  w .java 2s .c o  m*/

    // if theme mode has not been set by java code, check if it is specified in Style.xml
    if (!mThemeDarkChanged) {
        mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark);
    }

    Resources res = getResources();
    Context context = getActivity();
    mHourPickerDescription = res.getString(R.string.mdtp_hour_picker_description);
    mSelectHours = res.getString(R.string.mdtp_select_hours);
    mMinutePickerDescription = res.getString(R.string.mdtp_minute_picker_description);
    mSelectMinutes = res.getString(R.string.mdtp_select_minutes);
    mSecondPickerDescription = res.getString(R.string.mdtp_second_picker_description);
    mSelectSeconds = res.getString(R.string.mdtp_select_seconds);
    mSelectedColor = ContextCompat.getColor(context, R.color.mdtp_white);
    mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_accent_color_focused);

    mHourView = (TextView) view.findViewById(R.id.hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mSecondSpaceView = (TextView) view.findViewById(R.id.seconds_space);
    mSecondView = (TextView) view.findViewById(R.id.seconds);
    mSecondView.setOnKeyListener(keyboardListener);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnKeyListener(keyboardListener);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mHapticFeedbackController = new HapticFeedbackController(getActivity());
    mInitialTime = roundToNearest(mInitialTime);

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), this, mInitialTime, mIs24HourMode);

    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mTimePicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mSecondView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            setCurrentItemShowing(SECOND_INDEX, true, false, true);
            tryVibrate();
        }
    });

    mOkButton = (Button) view.findViewById(R.id.ok);
    mOkButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                tryVibrate();
            }
            notifyOnDateListener();
            dismiss();
        }
    });
    mOkButton.setOnKeyListener(keyboardListener);
    mOkButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mOkString != null)
        mOkButton.setText(mOkString);
    else
        mOkButton.setText(mOkResid);

    mCancelButton = (Button) view.findViewById(R.id.cancel);
    mCancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tryVibrate();
            if (getDialog() != null)
                getDialog().cancel();
        }
    });
    mCancelButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mCancelString != null)
        mCancelButton.setText(mCancelString);
    else
        mCancelButton.setText(mCancelResid);
    mCancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE);

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        updateAmPmDisplay(mInitialTime.isAM() ? AM : PM);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Don't do anything if either AM or PM are disabled
                if (isAmDisabled() || isPmDisabled())
                    return;

                tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                mTimePicker.setAmOrPm(amOrPm);
            }
        });
    }

    // Disable seconds picker
    if (!mEnableSeconds) {
        mSecondSpaceView.setVisibility(View.GONE);
        view.findViewById(R.id.separator_seconds).setVisibility(View.GONE);
    }

    // Center stuff depending on what's visible
    if (mIs24HourMode && !mEnableSeconds) {
        // center first separator
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else if (mEnableSeconds) {
        // link separator to minutes
        final View separator = view.findViewById(R.id.separator);
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.LEFT_OF, R.id.minutes_space);
        paramsSeparator.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        separator.setLayoutParams(paramsSeparator);

        if (!mIs24HourMode) {
            // center minutes
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.CENTER_IN_PARENT);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        } else {
            // move minutes to right of center
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.RIGHT_OF, R.id.center_view);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        }
    }

    mAllowAutoAdvance = true;
    setHour(mInitialTime.getHour(), true);
    setMinute(mInitialTime.getMinute());
    setSecond(mInitialTime.getSecond());

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.mdtp_time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.mdtp_deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<>();
    }

    // Set the title (if any)
    TextView timePickerHeader = (TextView) view.findViewById(R.id.time_picker_header);
    if (!mTitle.isEmpty()) {
        timePickerHeader.setVisibility(TextView.VISIBLE);
        timePickerHeader.setText(mTitle.toUpperCase(Locale.getDefault()));
    }

    // Set the theme at the end so that the initialize()s above don't counteract the theme.
    mOkButton.setTextColor(mAccentColor);
    mCancelButton.setTextColor(mAccentColor);
    timePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor));
    view.findViewById(R.id.time_display_background).setBackgroundColor(mAccentColor);
    view.findViewById(R.id.time_display).setBackgroundColor(mAccentColor);

    if (getDialog() == null) {
        view.findViewById(R.id.done_background).setVisibility(View.GONE);
    }

    int circleBackground = ContextCompat.getColor(context, R.color.mdtp_circle_background);
    int backgroundColor = ContextCompat.getColor(context, R.color.mdtp_background_color);
    int darkBackgroundColor = ContextCompat.getColor(context, R.color.mdtp_light_gray);
    int lightGray = ContextCompat.getColor(context, R.color.mdtp_light_gray);

    mTimePicker.setBackgroundColor(mThemeDark ? lightGray : circleBackground);
    view.findViewById(R.id.time_picker_dialog)
            .setBackgroundColor(mThemeDark ? darkBackgroundColor : backgroundColor);
    return view;
}

From source file:com.mojtaba.materialdatetimepicker.time.TimePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.mdtp_time_picker_dialog, container, false);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);

    // If an accent color has not been set manually, get it from the context
    if (mAccentColor == -1) {
        mAccentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity());
    }// ww  w. j  a  va2  s. c om

    // if theme mode has not been set by java code, check if it is specified in Style.xml
    if (!mThemeDarkChanged) {
        mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark);
    }

    Resources res = getResources();
    Context context = getActivity();
    mHourPickerDescription = res.getString(R.string.mdtp_hour_picker_description);
    mSelectHours = res.getString(R.string.mdtp_select_hours);
    mMinutePickerDescription = res.getString(R.string.mdtp_minute_picker_description);
    mSelectMinutes = res.getString(R.string.mdtp_select_minutes);
    mSecondPickerDescription = res.getString(R.string.mdtp_second_picker_description);
    mSelectSeconds = res.getString(R.string.mdtp_select_seconds);
    mSelectedColor = ContextCompat.getColor(context, R.color.mdtp_white);
    mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_accent_color_focused);

    mHourView = (TextView) view.findViewById(R.id.hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mSecondSpaceView = (TextView) view.findViewById(R.id.seconds_space);
    mSecondView = (TextView) view.findViewById(R.id.seconds);
    mSecondView.setOnKeyListener(keyboardListener);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnKeyListener(keyboardListener);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = "";
    mPmText = "";

    mHapticFeedbackController = new HapticFeedbackController(getActivity());
    mInitialTime = roundToNearest(mInitialTime);

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), this, mInitialTime, mIs24HourMode);

    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mTimePicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mSecondView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            setCurrentItemShowing(SECOND_INDEX, true, false, true);
            tryVibrate();
        }
    });

    mOkButton = (Button) view.findViewById(R.id.ok);
    mOkButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                tryVibrate();
            }
            notifyOnDateListener();
            dismiss();
        }
    });
    mOkButton.setOnKeyListener(keyboardListener);
    mOkButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mOkString != null)
        mOkButton.setText(mOkString);
    else
        mOkButton.setText(mOkResid);

    mCancelButton = (Button) view.findViewById(R.id.cancel);
    mCancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tryVibrate();
            if (getDialog() != null)
                getDialog().cancel();
        }
    });
    mCancelButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mCancelString != null)
        mCancelButton.setText(mCancelString);
    else
        mCancelButton.setText(mCancelResid);
    mCancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE);

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        updateAmPmDisplay(mInitialTime.isAM() ? AM : PM);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Don't do anything if either AM or PM are disabled
                if (isAmDisabled() || isPmDisabled())
                    return;

                tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                mTimePicker.setAmOrPm(amOrPm);
            }
        });
    }

    // Disable seconds picker
    if (!mEnableSeconds) {
        mSecondSpaceView.setVisibility(View.GONE);
        view.findViewById(R.id.separator_seconds).setVisibility(View.GONE);
    }

    // Center stuff depending on what's visible
    if (mIs24HourMode && !mEnableSeconds) {
        // center first separator
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else if (mEnableSeconds) {
        // link separator to minutes
        final View separator = view.findViewById(R.id.separator);
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.LEFT_OF, R.id.minutes_space);
        paramsSeparator.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        separator.setLayoutParams(paramsSeparator);

        if (!mIs24HourMode) {
            // center minutes
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.CENTER_IN_PARENT);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        } else {
            // move minutes to right of center
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.RIGHT_OF, R.id.center_view);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        }
    }

    mAllowAutoAdvance = true;
    setHour(mInitialTime.getHour(), true);
    setMinute(mInitialTime.getMinute());
    setSecond(mInitialTime.getSecond());

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.mdtp_time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.mdtp_deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<>();
    }

    // Set the title (if any)
    TextView timePickerHeader = (TextView) view.findViewById(R.id.time_picker_header);
    if (!mTitle.isEmpty()) {
        timePickerHeader.setVisibility(TextView.VISIBLE);
        timePickerHeader.setText(mTitle.toUpperCase(Locale.getDefault()));
    }

    // Set the theme at the end so that the initialize()s above don't counteract the theme.
    mOkButton.setTextColor(mAccentColor);
    mCancelButton.setTextColor(mAccentColor);
    timePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor));
    view.findViewById(R.id.time_display_background).setBackgroundColor(mAccentColor);
    view.findViewById(R.id.time_display).setBackgroundColor(mAccentColor);

    if (getDialog() == null) {
        view.findViewById(R.id.done_background).setVisibility(View.GONE);
    }

    int circleBackground = ContextCompat.getColor(context, R.color.mdtp_circle_background);
    int backgroundColor = ContextCompat.getColor(context, R.color.mdtp_background_color);
    int darkBackgroundColor = ContextCompat.getColor(context, R.color.mdtp_light_gray);
    int lightGray = ContextCompat.getColor(context, R.color.mdtp_light_gray);

    mTimePicker.setBackgroundColor(mThemeDark ? lightGray : circleBackground);
    view.findViewById(R.id.time_picker_dialog)
            .setBackgroundColor(mThemeDark ? darkBackgroundColor : backgroundColor);
    return view;
}

From source file:de.dfki.iui.opentok.cordova.plugin.OpenTokPlugin.java

private void doUpdateViewLayoutParams(final View view, final LayoutParams newLayoutParams) {
    this.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override//  www .  j  ava 2  s . c o m
        public void run() {
            view.setLayoutParams(newLayoutParams);
        }
    });
}

From source file:com.lybeat.lilyplayer.widget.media.IjkVideoView.java

public void setRenderView(IRenderView renderView) {
    if (mRenderView != null) {
        if (mMediaPlayer != null)
            mMediaPlayer.setDisplay(null);

        View renderUIView = mRenderView.getView();
        mRenderView.removeRenderCallback(mSHCallback);
        mRenderView = null;/*from  w w w  .  j av  a2s  .  com*/
        removeView(renderUIView);
    }

    if (renderView == null)
        return;

    mRenderView = renderView;
    renderView.setAspectRatio(mCurrentAspectRatio);
    if (mVideoWidth > 0 && mVideoHeight > 0)
        renderView.setVideoSize(mVideoWidth, mVideoHeight);
    if (mVideoSarNum > 0 && mVideoSarDen > 0)
        renderView.setVideoSampleAspectRatio(mVideoSarNum, mVideoSarDen);

    View renderUIView = mRenderView.getView();
    LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
    renderUIView.setLayoutParams(lp);
    addView(renderUIView);

    mRenderView.addRenderCallback(mSHCallback);
    mRenderView.setVideoRotation(mVideoRotationDegree);
}

From source file:com.miz.functions.MizLib.java

/**
 * Add a margin with a combined height of the ActionBar and Status bar to the top of a given View contained in a FrameLayout
 * @param c/*w ww .  j  a  va2s .  c o  m*/
 * @param v
 */
public static void addActionBarAndStatusBarMargin(Context c, View v, FrameLayout.LayoutParams layoutParams) {
    int mActionBarHeight = 0, mStatusBarHeight = 0;
    TypedValue tv = new TypedValue();
    if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                c.getResources().getDisplayMetrics());
    else
        mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme)

    if (hasKitKat())
        mStatusBarHeight = convertDpToPixels(c, 25);

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    params.setMargins(0, mActionBarHeight + mStatusBarHeight, 0, 0);
    params.gravity = layoutParams.gravity;
    v.setLayoutParams(params);
}

From source file:com.daiv.android.twitter.ui.drawer_activities.DrawerActivity.java

public void setUpDrawer(int number, final String actName) {

    int currentAccount = sharedPrefs.getInt("current_account", 1);
    for (int i = 0; i < TimelinePagerAdapter.MAX_EXTRA_PAGES; i++) {
        String pageIdentifier = "account_" + currentAccount + "_page_" + (i + 1);
        int type = sharedPrefs.getInt(pageIdentifier, AppSettings.PAGE_TYPE_NONE);

        if (type != AppSettings.PAGE_TYPE_NONE) {
            number++;/*from w w  w .j a  v a 2 s .co m*/
        }
    }

    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }

    actionBar = getActionBar();

    adapter = new MainDrawerArrayAdapter(context);
    MainDrawerArrayAdapter.setCurrent(context, number);

    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.drawerIcon });
    int resource = a.getResourceId(0, 0);
    a.recycle();

    a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.read_button });
    openMailResource = a.getResourceId(0, 0);
    a.recycle();

    a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.unread_button });
    closedMailResource = a.getResourceId(0, 0);
    a.recycle();

    mDrawerLayout = (NotificationDrawerLayout) findViewById(R.id.drawer_layout);
    mDrawer = (LinearLayout) findViewById(R.id.left_drawer);

    HoloTextView name = (HoloTextView) mDrawer.findViewById(R.id.name);
    HoloTextView screenName = (HoloTextView) mDrawer.findViewById(R.id.screen_name);
    backgroundPic = (NetworkedCacheableImageView) mDrawer.findViewById(R.id.background_image);
    profilePic = (NetworkedCacheableImageView) mDrawer.findViewById(R.id.profile_pic_contact);
    final ImageButton showMoreDrawer = (ImageButton) mDrawer.findViewById(R.id.options);
    final LinearLayout logoutLayout = (LinearLayout) mDrawer.findViewById(R.id.logoutLayout);
    final Button logoutDrawer = (Button) mDrawer.findViewById(R.id.logoutButton);
    drawerList = (ListView) mDrawer.findViewById(R.id.drawer_list);
    notificationList = (EnhancedListView) findViewById(R.id.notificationList);

    try {
        mDrawerLayout = (NotificationDrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_rev, Gravity.END);

        mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
                mDrawerLayout, /* DrawerLayout object */
                resource, /* nav drawer icon to replace 'Up' caret */
                R.string.app_name, /* "open drawer" description */
                R.string.app_name /* "close drawer" description */
        ) {

            public void onDrawerClosed(View view) {

                actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

                if (logoutVisible) {
                    Animation ranim = AnimationUtils.loadAnimation(context, R.anim.drawer_rotate_back);
                    ranim.setFillAfter(true);
                    showMoreDrawer.startAnimation(ranim);

                    logoutLayout.setVisibility(View.GONE);
                    drawerList.setVisibility(View.VISIBLE);

                    logoutVisible = false;
                }

                if (MainDrawerArrayAdapter.current > adapter.pageTypes.size()) {
                    actionBar.setTitle(actName);
                } else {
                    int position = mViewPager.getCurrentItem();
                    String title = "";
                    try {
                        title = "" + mSectionsPagerAdapter.getPageTitle(position);
                    } catch (NullPointerException e) {
                        title = "";
                    }
                    actionBar.setTitle(title);
                }

                try {
                    if (oldInteractions.getText().toString()
                            .equals(getResources().getString(R.string.new_interactions))) {
                        oldInteractions.setText(getResources().getString(R.string.old_interactions));
                        readButton.setImageResource(openMailResource);
                        notificationList.enableSwipeToDismiss();
                        notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource
                                .getInstance(context).getUnreadCursor(DrawerActivity.settings.currentAccount));
                        notificationList.setAdapter(notificationAdapter);
                    }
                } catch (Exception e) {
                    // don't have Test pull on
                }

                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                actionBar.setTitle(getResources().getString(R.string.app_name));
                actionBar.setIcon(R.mipmap.ic_launcher);

                try {
                    notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource
                            .getInstance(context).getUnreadCursor(settings.currentAccount));
                    notificationList.setAdapter(notificationAdapter);
                    notificationList.enableSwipeToDismiss();
                    oldInteractions.setText(getResources().getString(R.string.old_interactions));
                    readButton.setImageResource(openMailResource);
                    sharedPrefs.edit().putBoolean("new_notification", false).commit();
                } catch (Exception e) {
                    // don't have Test pull on
                }

                invalidateOptionsMenu();
            }

            public void onDrawerSlide(View drawerView, float slideOffset) {
                super.onDrawerSlide(drawerView, slideOffset);

                if (!actionBar.isShowing()) {
                    actionBar.show();
                }

                if (translucent) {
                    statusBar.setVisibility(View.VISIBLE);
                }
            }
        };

        mDrawerLayout.setDrawerListener(mDrawerToggle);
    } catch (Exception e) {
        // landscape mode
    }

    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    showMoreDrawer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (logoutLayout.getVisibility() == View.GONE) {
                Animation ranim = AnimationUtils.loadAnimation(context, R.anim.drawer_rotate);
                ranim.setFillAfter(true);
                showMoreDrawer.startAnimation(ranim);

                Animation anim = AnimationUtils.loadAnimation(context, R.anim.fade_out);
                anim.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        drawerList.setVisibility(View.GONE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                anim.setDuration(300);
                drawerList.startAnimation(anim);

                Animation anim2 = AnimationUtils.loadAnimation(context, R.anim.fade_in);
                anim2.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        logoutLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                anim2.setDuration(300);
                logoutLayout.startAnimation(anim2);

                logoutVisible = true;
            } else {
                Animation ranim = AnimationUtils.loadAnimation(context, R.anim.drawer_rotate_back);
                ranim.setFillAfter(true);
                showMoreDrawer.startAnimation(ranim);

                Animation anim = AnimationUtils.loadAnimation(context, R.anim.fade_in);
                anim.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        drawerList.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                anim.setDuration(300);
                drawerList.startAnimation(anim);

                Animation anim2 = AnimationUtils.loadAnimation(context, R.anim.fade_out);
                anim2.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        logoutLayout.setVisibility(View.GONE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                anim2.setDuration(300);
                logoutLayout.startAnimation(anim2);

                logoutVisible = false;
            }
        }
    });

    logoutDrawer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            logoutFromTwitter();
        }
    });

    final String sName = settings.myName;
    final String sScreenName = settings.myScreenName;
    final String backgroundUrl = settings.myBackgroundUrl;
    final String profilePicUrl = settings.myProfilePicUrl;

    final BitmapLruCache mCache = App.getInstance(context).getProfileCache();

    if (!backgroundUrl.equals("")) {
        backgroundPic.loadImage(backgroundUrl, false, null);
        //ImageUtils.loadImage(context, backgroundPic, backgroundUrl, mCache);
    } else {
        backgroundPic.setImageDrawable(getResources().getDrawable(R.drawable.default_header_background));
    }

    backgroundPic.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                mDrawerLayout.closeDrawer(Gravity.START);
            } catch (Exception e) {

            }

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {

                }
            }, 400);
        }
    });

    backgroundPic.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {

            try {
                mDrawerLayout.closeDrawer(Gravity.START);
            } catch (Exception e) {

            }

            return false;
        }
    });

    try {
        name.setText(sName);
        screenName.setText("@" + sScreenName);
        name.setTextSize(15);
        screenName.setTextSize(15);
    } catch (Exception e) {
        // 7 inch tablet in portrait
    }

    try {
        if (settings.roundContactImages) {
            //profilePic.loadImage(profilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
            ImageUtils.loadCircleImage(context, profilePic, profilePicUrl, mCache);
        } else {
            profilePic.loadImage(profilePicUrl, false, null);
            ImageUtils.loadImage(context, profilePic, profilePicUrl, mCache);
        }
    } catch (Exception e) {
        // empty path again
    }

    drawerList.setAdapter(adapter);

    drawerList.setOnItemClickListener(new MainDrawerClickListener(context, mDrawerLayout, mViewPager));

    // set up for the second account
    int count = 0; // number of accounts logged in

    if (sharedPrefs.getBoolean("is_logged_in_1", false)) {
        count++;
    }

    if (sharedPrefs.getBoolean("is_logged_in_2", false)) {
        count++;
    }

    RelativeLayout secondAccount = (RelativeLayout) findViewById(R.id.second_profile);
    HoloTextView name2 = (HoloTextView) findViewById(R.id.name_2);
    HoloTextView screenname2 = (HoloTextView) findViewById(R.id.screen_name_2);
    NetworkedCacheableImageView proPic2 = (NetworkedCacheableImageView) findViewById(R.id.profile_pic_2);

    name2.setTextSize(15);
    screenname2.setTextSize(15);

    final int current = sharedPrefs.getInt("current_account", 1);

    // make a second account
    if (count == 1) {
        name2.setText(getResources().getString(R.string.new_account));
        screenname2.setText(getResources().getString(R.string.tap_to_setup));
        secondAccount.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (canSwitch) {
                    if (current == 1) {
                        sharedPrefs.edit().putInt("current_account", 2).commit();
                    } else {
                        sharedPrefs.edit().putInt("current_account", 1).commit();
                    }
                    context.sendBroadcast(new Intent("com.daiv.android.twitter.STOP_PUSH_SERVICE"));
                    context.sendBroadcast(new Intent("com.daiv.android.twitter.MARK_POSITION"));

                    Intent login = new Intent(context, LoginActivity.class);
                    AppSettings.invalidate();
                    finish();
                    startActivity(login);
                }
            }
        });
    } else { // switch accounts
        if (current == 1) {
            name2.setText(sharedPrefs.getString("twitter_users_name_2", ""));
            screenname2.setText("@" + sharedPrefs.getString("twitter_screen_name_2", ""));
            try {
                if (settings.roundContactImages) {
                    //proPic2.loadImage(sharedPrefs.getString("profile_pic_url_2", ""), true, null, NetworkedCacheableImageView.CIRCLE);
                    ImageUtils.loadCircleImage(context, proPic2, sharedPrefs.getString("profile_pic_url_2", ""),
                            mCache);
                } else {
                    //proPic2.loadImage(sharedPrefs.getString("profile_pic_url_2", ""), true, null);
                    ImageUtils.loadImage(context, proPic2, sharedPrefs.getString("profile_pic_url_2", ""),
                            mCache);
                }
            } catch (Exception e) {

            }

            secondAccount.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (canSwitch) {
                        context.sendBroadcast(new Intent("com.daiv.android.twitter.STOP_PUSH_SERVICE"));
                        context.sendBroadcast(new Intent("com.daiv.android.twitter.MARK_POSITION")
                                .putExtra("current_account", current));

                        Toast.makeText(context, "Preparing to switch", Toast.LENGTH_SHORT).show();

                        // we want to wait a second so that the mark position broadcast will work
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    Thread.sleep(1000);
                                } catch (Exception e) {

                                }
                                sharedPrefs.edit().putInt("current_account", 2).commit();
                                sharedPrefs.edit().remove("new_notifications").remove("new_retweets")
                                        .remove("new_favorites").remove("new_follows").commit();
                                AppSettings.invalidate();
                                finish();
                                Intent next = new Intent(context, MainActivity.class);
                                startActivity(next);
                            }
                        }).start();

                    }
                }
            });
        } else {
            name2.setText(sharedPrefs.getString("twitter_users_name_1", ""));
            screenname2.setText("@" + sharedPrefs.getString("twitter_screen_name_1", ""));
            try {
                if (settings.roundContactImages) {
                    //proPic2.loadImage(sharedPrefs.getString("profile_pic_url_1", ""), true, null, NetworkedCacheableImageView.CIRCLE);
                    ImageUtils.loadCircleImage(context, proPic2, sharedPrefs.getString("profile_pic_url_1", ""),
                            mCache);
                } else {
                    //proPic2.loadImage(sharedPrefs.getString("profile_pic_url_1", ""), true, null);
                    ImageUtils.loadImage(context, proPic2, sharedPrefs.getString("profile_pic_url_1", ""),
                            mCache);
                }
            } catch (Exception e) {

            }
            secondAccount.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (canSwitch) {
                        context.sendBroadcast(new Intent("com.daiv.android.twitter.STOP_PUSH_SERVICE"));
                        context.sendBroadcast(new Intent("com.daiv.android.twitter.MARK_POSITION")
                                .putExtra("current_account", current));

                        Toast.makeText(context, "Preparing to switch", Toast.LENGTH_SHORT).show();
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    Thread.sleep(1000);
                                } catch (Exception e) {

                                }

                                sharedPrefs.edit().putInt("current_account", 1).commit();
                                sharedPrefs.edit().remove("new_notifications").remove("new_retweets")
                                        .remove("new_favorites").remove("new_follows").commit();
                                AppSettings.invalidate();
                                finish();
                                Intent next = new Intent(context, MainActivity.class);
                                startActivity(next);
                            }
                        }).start();
                    }
                }
            });
        }
    }

    statusBar = findViewById(R.id.activity_status_bar);

    statusBarHeight = Utils.getStatusBarHeight(context);
    navBarHeight = Utils.getNavBarHeight(context);

    try {
        RelativeLayout.LayoutParams statusParams = (RelativeLayout.LayoutParams) statusBar.getLayoutParams();
        statusParams.height = statusBarHeight;
        statusBar.setLayoutParams(statusParams);
    } catch (Exception e) {
        try {
            LinearLayout.LayoutParams statusParams = (LinearLayout.LayoutParams) statusBar.getLayoutParams();
            statusParams.height = statusBarHeight;
            statusBar.setLayoutParams(statusParams);
        } catch (Exception x) {
            // in the trends
        }
    }

    View navBarSeperater = findViewById(R.id.nav_bar_seperator);

    if (translucent && Utils.hasNavBar(context)) {
        try {
            RelativeLayout.LayoutParams navParams = (RelativeLayout.LayoutParams) navBarSeperater
                    .getLayoutParams();
            navParams.height = navBarHeight;
            navBarSeperater.setLayoutParams(navParams);
        } catch (Exception e) {
            try {
                LinearLayout.LayoutParams navParams = (LinearLayout.LayoutParams) navBarSeperater
                        .getLayoutParams();
                navParams.height = navBarHeight;
                navBarSeperater.setLayoutParams(navParams);
            } catch (Exception x) {
                // in the trends
            }
        }
    }

    if (translucent) {
        if (Utils.hasNavBar(context)) {
            View footer = new View(context);
            footer.setOnClickListener(null);
            footer.setOnLongClickListener(null);
            ListView.LayoutParams params = new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT,
                    Utils.getNavBarHeight(context));
            footer.setLayoutParams(params);
            drawerList.addFooterView(footer);
            drawerList.setFooterDividersEnabled(false);
        }

        View drawerStatusBar = findViewById(R.id.drawer_status_bar);
        LinearLayout.LayoutParams status2Params = (LinearLayout.LayoutParams) drawerStatusBar.getLayoutParams();
        status2Params.height = statusBarHeight;
        drawerStatusBar.setLayoutParams(status2Params);
        drawerStatusBar.setVisibility(View.VISIBLE);

        statusBar.setVisibility(View.VISIBLE);

        drawerStatusBar = findViewById(R.id.drawer_status_bar_2);
        status2Params = (LinearLayout.LayoutParams) drawerStatusBar.getLayoutParams();
        status2Params.height = statusBarHeight;
        drawerStatusBar.setLayoutParams(status2Params);
        drawerStatusBar.setVisibility(View.VISIBLE);
    }

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
            || getResources().getBoolean(R.bool.isTablet)) {
        actionBar.setDisplayHomeAsUpEnabled(false);
    }

    if (!settings.pushNotifications || !settings.useInteractionDrawer) {
        try {
            mDrawerLayout.setDrawerLockMode(NotificationDrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.END);
        } catch (Exception e) {
            // no drawer?
        }
    } else {
        mDrawerLayout.setDrawerRightEdgeSize(this, .1f);

        try {
            if (Build.VERSION.SDK_INT < 18 && DrawerActivity.settings.uiExtras) {
                View viewHeader2 = context.getLayoutInflater().inflate(R.layout.ab_header, null);
                notificationList.addHeaderView(viewHeader2, null, false);
                notificationList.setHeaderDividersEnabled(false);
            }
        } catch (Exception e) {
            // i don't know why it does this to be honest...
        }

        notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource.getInstance(context)
                .getUnreadCursor(DrawerActivity.settings.currentAccount));
        try {
            notificationList.setAdapter(notificationAdapter);
        } catch (Exception e) {

        }

        View viewHeader = context.getLayoutInflater().inflate(R.layout.interactions_footer_1, null);
        notificationList.addFooterView(viewHeader, null, false);
        oldInteractions = (HoloTextView) findViewById(R.id.old_interactions_text);
        readButton = (ImageView) findViewById(R.id.read_button);

        LinearLayout footer = (LinearLayout) viewHeader.findViewById(R.id.footer);
        footer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (oldInteractions.getText().toString()
                        .equals(getResources().getString(R.string.old_interactions))) {
                    oldInteractions.setText(getResources().getString(R.string.new_interactions));
                    readButton.setImageResource(closedMailResource);

                    notificationList.disableSwipeToDismiss();

                    notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource
                            .getInstance(context).getCursor(DrawerActivity.settings.currentAccount));
                } else {
                    oldInteractions.setText(getResources().getString(R.string.old_interactions));
                    readButton.setImageResource(openMailResource);

                    notificationList.enableSwipeToDismiss();

                    notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource
                            .getInstance(context).getUnreadCursor(DrawerActivity.settings.currentAccount));
                }

                notificationList.setAdapter(notificationAdapter);
            }
        });

        if (DrawerActivity.translucent) {
            if (Utils.hasNavBar(context)) {
                View nav = new View(context);
                nav.setOnClickListener(null);
                nav.setOnLongClickListener(null);
                ListView.LayoutParams params = new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT,
                        Utils.getNavBarHeight(context));
                nav.setLayoutParams(params);
                notificationList.addFooterView(nav);
                notificationList.setFooterDividersEnabled(false);
            }
        }

        notificationList.setDismissCallback(new EnhancedListView.OnDismissCallback() {
            @Override
            public EnhancedListView.Undoable onDismiss(EnhancedListView listView, int position) {
                Log.v("Test_interactions_delete", "position to delete: " + position);
                InteractionsDataSource data = InteractionsDataSource.getInstance(context);
                data.markRead(settings.currentAccount, position);
                notificationAdapter = new InteractionsCursorAdapter(context,
                        data.getUnreadCursor(DrawerActivity.settings.currentAccount));
                notificationList.setAdapter(notificationAdapter);

                oldInteractions.setText(getResources().getString(R.string.old_interactions));
                readButton.setImageResource(openMailResource);

                if (notificationAdapter.getCount() == 0) {
                    setNotificationFilled(false);
                }

                return null;
            }
        });

        notificationList.enableSwipeToDismiss();
        notificationList.setSwipeDirection(EnhancedListView.SwipeDirection.START);

        notificationList
                .setOnItemClickListener(new InteractionClickListener(context, mDrawerLayout, mViewPager));
    }
}

From source file:com.google.samples.apps.sergio.ui.BaseActivity.java

/**
 * Sets up the navigation drawer as appropriate. Note that the nav drawer will be
 * different depending on whether the attendee indicated that they are attending the
 * event on-site vs. attending remotely.
 *//* w w w.  ja v a  2  s.  co  m*/
private void setupNavDrawer() {
    // What nav drawer item should be selected?
    int selfItem = getSelfNavDrawerItem();

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (mDrawerLayout == null) {
        return;
    }
    mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.theme_primary_dark));
    ScrimInsetsScrollView navDrawer = (ScrimInsetsScrollView) mDrawerLayout.findViewById(R.id.navdrawer);
    if (selfItem == NAVDRAWER_ITEM_INVALID) {
        // do not show a nav drawer
        if (navDrawer != null) {
            ((ViewGroup) navDrawer.getParent()).removeView(navDrawer);
        }
        mDrawerLayout = null;
        return;
    }

    if (navDrawer != null) {
        final View chosenAccountContentView = findViewById(R.id.chosen_account_content_view);
        final View chosenAccountView = findViewById(R.id.chosen_account_view);
        final int navDrawerChosenAccountHeight = getResources()
                .getDimensionPixelSize(R.dimen.navdrawer_chosen_account_height);
        navDrawer.setOnInsetsCallback(new ScrimInsetsScrollView.OnInsetsCallback() {
            @Override
            public void onInsetsChanged(Rect insets) {
                ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) chosenAccountContentView
                        .getLayoutParams();
                lp.topMargin = insets.top;
                chosenAccountContentView.setLayoutParams(lp);

                ViewGroup.LayoutParams lp2 = chosenAccountView.getLayoutParams();
                lp2.height = navDrawerChosenAccountHeight + insets.top;
                chosenAccountView.setLayoutParams(lp2);
            }
        });
    }

    if (mActionBarToolbar != null) {
        mActionBarToolbar.setNavigationIcon(R.drawable.ic_drawer);
        mActionBarToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mDrawerLayout.openDrawer(Gravity.START);
            }
        });
    }

    mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
        @Override
        public void onDrawerClosed(View drawerView) {
            // run deferred action, if we have one
            if (mDeferredOnDrawerClosedRunnable != null) {
                mDeferredOnDrawerClosedRunnable.run();
                mDeferredOnDrawerClosedRunnable = null;
            }
            if (mAccountBoxExpanded) {
                mAccountBoxExpanded = false;
                setupAccountBoxToggle();
            }
            onNavDrawerStateChanged(false, false);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            onNavDrawerStateChanged(true, false);
        }

        @Override
        public void onDrawerStateChanged(int newState) {
            onNavDrawerStateChanged(isNavDrawerOpen(), newState != DrawerLayout.STATE_IDLE);
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            onNavDrawerSlide(slideOffset);
        }
    });

    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);

    // populate the nav drawer with the correct items
    populateNavDrawer();

    // When the user runs the app for the first time, we want to land them with the
    // navigation drawer open. But just the first time.
    if (!PrefUtils.isWelcomeDone(this)) {
        // first run of the app starts with the nav drawer open
        PrefUtils.markWelcomeDone(this);
        mDrawerLayout.openDrawer(Gravity.START);
    }
}

From source file:com.klinker.android.twitter.ui.drawer_activities.DrawerActivity.java

public void setUpDrawer(int number, final String actName) {

    try {//from  w  w  w  .  java 2s  .co  m
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }

    actionBar = getActionBar();

    MainDrawerArrayAdapter.current = number;

    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.drawerIcon });
    int resource = a.getResourceId(0, 0);
    a.recycle();

    a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.read_button });
    openMailResource = a.getResourceId(0, 0);
    a.recycle();

    a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.unread_button });
    closedMailResource = a.getResourceId(0, 0);
    a.recycle();

    mDrawerLayout = (NotificationDrawerLayout) findViewById(R.id.drawer_layout);
    mDrawer = (LinearLayout) findViewById(R.id.left_drawer);

    HoloTextView name = (HoloTextView) mDrawer.findViewById(R.id.name);
    HoloTextView screenName = (HoloTextView) mDrawer.findViewById(R.id.screen_name);
    backgroundPic = (NetworkedCacheableImageView) mDrawer.findViewById(R.id.background_image);
    profilePic = (NetworkedCacheableImageView) mDrawer.findViewById(R.id.profile_pic_contact);
    final ImageButton showMoreDrawer = (ImageButton) mDrawer.findViewById(R.id.options);
    final LinearLayout logoutLayout = (LinearLayout) mDrawer.findViewById(R.id.logoutLayout);
    final Button logoutDrawer = (Button) mDrawer.findViewById(R.id.logoutButton);
    drawerList = (ListView) mDrawer.findViewById(R.id.drawer_list);
    notificationList = (EnhancedListView) findViewById(R.id.notificationList);

    try {
        mDrawerLayout = (NotificationDrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_rev, Gravity.END);

        mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
                mDrawerLayout, /* DrawerLayout object */
                resource, /* nav drawer icon to replace 'Up' caret */
                R.string.app_name, /* "open drawer" description */
                R.string.app_name /* "close drawer" description */
        ) {

            public void onDrawerClosed(View view) {

                actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

                if (logoutVisible) {
                    Animation ranim = AnimationUtils.loadAnimation(context, R.anim.drawer_rotate_back);
                    ranim.setFillAfter(true);
                    showMoreDrawer.startAnimation(ranim);

                    logoutLayout.setVisibility(View.GONE);
                    drawerList.setVisibility(View.VISIBLE);

                    logoutVisible = false;
                }

                if (MainDrawerArrayAdapter.current > 2) {
                    actionBar.setTitle(actName);
                } else {
                    int position = mViewPager.getCurrentItem();
                    String title = "";
                    try {
                        title = "" + mSectionsPagerAdapter.getPageTitle(position);
                    } catch (NullPointerException e) {
                        title = "";
                    }
                    actionBar.setTitle(title);
                }

                try {
                    if (oldInteractions.getText().toString()
                            .equals(getResources().getString(R.string.new_interactions))) {
                        oldInteractions.setText(getResources().getString(R.string.old_interactions));
                        readButton.setImageResource(openMailResource);
                        notificationList.enableSwipeToDismiss();
                        notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource
                                .getInstance(context).getUnreadCursor(DrawerActivity.settings.currentAccount));
                        notificationList.setAdapter(notificationAdapter);
                    }
                } catch (Exception e) {
                    // don't have talon pull on
                }

                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                actionBar.setTitle(getResources().getString(R.string.app_name));
                actionBar.setIcon(R.mipmap.ic_launcher);

                try {
                    notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource
                            .getInstance(context).getUnreadCursor(settings.currentAccount));
                    notificationList.setAdapter(notificationAdapter);
                    notificationList.enableSwipeToDismiss();
                    oldInteractions.setText(getResources().getString(R.string.old_interactions));
                    readButton.setImageResource(openMailResource);
                    sharedPrefs.edit().putBoolean("new_notification", false).commit();
                } catch (Exception e) {
                    // don't have talon pull on
                }

                invalidateOptionsMenu();
            }

            public void onDrawerSlide(View drawerView, float slideOffset) {
                super.onDrawerSlide(drawerView, slideOffset);

                if (!actionBar.isShowing()) {
                    actionBar.show();
                }

                if (translucent) {
                    statusBar.setVisibility(View.VISIBLE);
                }
            }
        };

        mDrawerLayout.setDrawerListener(mDrawerToggle);
    } catch (Exception e) {
        // landscape mode
    }

    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    showMoreDrawer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (logoutLayout.getVisibility() == View.GONE) {
                Animation ranim = AnimationUtils.loadAnimation(context, R.anim.drawer_rotate);
                ranim.setFillAfter(true);
                showMoreDrawer.startAnimation(ranim);

                Animation anim = AnimationUtils.loadAnimation(context, R.anim.fade_out);
                anim.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        drawerList.setVisibility(View.GONE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                anim.setDuration(300);
                drawerList.startAnimation(anim);

                Animation anim2 = AnimationUtils.loadAnimation(context, R.anim.fade_in);
                anim2.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        logoutLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                anim2.setDuration(300);
                logoutLayout.startAnimation(anim2);

                logoutVisible = true;
            } else {
                Animation ranim = AnimationUtils.loadAnimation(context, R.anim.drawer_rotate_back);
                ranim.setFillAfter(true);
                showMoreDrawer.startAnimation(ranim);

                Animation anim = AnimationUtils.loadAnimation(context, R.anim.fade_in);
                anim.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        drawerList.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                anim.setDuration(300);
                drawerList.startAnimation(anim);

                Animation anim2 = AnimationUtils.loadAnimation(context, R.anim.fade_out);
                anim2.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        logoutLayout.setVisibility(View.GONE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                anim2.setDuration(300);
                logoutLayout.startAnimation(anim2);

                logoutVisible = false;
            }
        }
    });

    logoutDrawer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            logoutFromTwitter();
        }
    });

    final String sName = settings.myName;
    final String sScreenName = settings.myScreenName;
    final String backgroundUrl = settings.myBackgroundUrl;
    final String profilePicUrl = settings.myProfilePicUrl;

    final BitmapLruCache mCache = App.getInstance(context).getProfileCache();

    if (!backgroundUrl.equals("")) {
        backgroundPic.loadImage(backgroundUrl, false, null);
        //ImageUtils.loadImage(context, backgroundPic, backgroundUrl, mCache);
    } else {
        backgroundPic.setImageDrawable(getResources().getDrawable(R.drawable.default_header_background));
    }

    backgroundPic.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                mDrawerLayout.closeDrawer(Gravity.START);
            } catch (Exception e) {

            }

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent viewProfile = new Intent(context, ProfilePager.class);
                    viewProfile.putExtra("name", sName);
                    viewProfile.putExtra("screenname", sScreenName);
                    viewProfile.putExtra("proPic", profilePicUrl);
                    viewProfile.putExtra("tweetid", 0);
                    viewProfile.putExtra("retweet", false);
                    viewProfile.putExtra("long_click", false);

                    context.startActivity(viewProfile);
                }
            }, 400);
        }
    });

    backgroundPic.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {

            try {
                mDrawerLayout.closeDrawer(Gravity.START);
            } catch (Exception e) {

            }

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent viewProfile = new Intent(context, ProfilePager.class);
                    viewProfile.putExtra("name", sName);
                    viewProfile.putExtra("screenname", sScreenName);
                    viewProfile.putExtra("proPic", profilePicUrl);
                    viewProfile.putExtra("tweetid", 0);
                    viewProfile.putExtra("retweet", false);
                    viewProfile.putExtra("long_click", true);

                    context.startActivity(viewProfile);
                }
            }, 400);

            return false;
        }
    });

    try {
        name.setText(sName);
        screenName.setText("@" + sScreenName);
        name.setTextSize(15);
        screenName.setTextSize(15);
    } catch (Exception e) {
        // 7 inch tablet in portrait
    }

    try {
        if (settings.roundContactImages) {
            //profilePic.loadImage(profilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
            ImageUtils.loadCircleImage(context, profilePic, profilePicUrl, mCache);
        } else {
            profilePic.loadImage(profilePicUrl, false, null);
            ImageUtils.loadImage(context, profilePic, profilePicUrl, mCache);
        }
    } catch (Exception e) {
        // empty path again
    }

    MainDrawerArrayAdapter adapter = new MainDrawerArrayAdapter(context,
            new ArrayList<String>(Arrays.asList(MainDrawerArrayAdapter.getItems(context))));
    drawerList.setAdapter(adapter);

    drawerList.setOnItemClickListener(new MainDrawerClickListener(context, mDrawerLayout, mViewPager));

    // set up for the second account
    int count = 0; // number of accounts logged in

    if (sharedPrefs.getBoolean("is_logged_in_1", false)) {
        count++;
    }

    if (sharedPrefs.getBoolean("is_logged_in_2", false)) {
        count++;
    }

    RelativeLayout secondAccount = (RelativeLayout) findViewById(R.id.second_profile);
    HoloTextView name2 = (HoloTextView) findViewById(R.id.name_2);
    HoloTextView screenname2 = (HoloTextView) findViewById(R.id.screen_name_2);
    NetworkedCacheableImageView proPic2 = (NetworkedCacheableImageView) findViewById(R.id.profile_pic_2);

    name2.setTextSize(15);
    screenname2.setTextSize(15);

    final int current = sharedPrefs.getInt("current_account", 1);

    // make a second account
    if (count == 1) {
        name2.setText(getResources().getString(R.string.new_account));
        screenname2.setText(getResources().getString(R.string.tap_to_setup));
        secondAccount.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (canSwitch) {
                    if (current == 1) {
                        sharedPrefs.edit().putInt("current_account", 2).commit();
                    } else {
                        sharedPrefs.edit().putInt("current_account", 1).commit();
                    }
                    context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH_SERVICE"));
                    context.sendBroadcast(new Intent("com.klinker.android.twitter.MARK_POSITION"));

                    Intent login = new Intent(context, LoginActivity.class);
                    AppSettings.invalidate();
                    finish();
                    startActivity(login);
                }
            }
        });
    } else { // switch accounts
        if (current == 1) {
            name2.setText(sharedPrefs.getString("twitter_users_name_2", ""));
            screenname2.setText("@" + sharedPrefs.getString("twitter_screen_name_2", ""));
            try {
                if (settings.roundContactImages) {
                    //proPic2.loadImage(sharedPrefs.getString("profile_pic_url_2", ""), true, null, NetworkedCacheableImageView.CIRCLE);
                    ImageUtils.loadCircleImage(context, proPic2, sharedPrefs.getString("profile_pic_url_2", ""),
                            mCache);
                } else {
                    //proPic2.loadImage(sharedPrefs.getString("profile_pic_url_2", ""), true, null);
                    ImageUtils.loadImage(context, proPic2, sharedPrefs.getString("profile_pic_url_2", ""),
                            mCache);
                }
            } catch (Exception e) {

            }

            secondAccount.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (canSwitch) {
                        context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH_SERVICE"));
                        context.sendBroadcast(new Intent("com.klinker.android.twitter.MARK_POSITION")
                                .putExtra("current_account", current));

                        Toast.makeText(context, "Preparing to switch", Toast.LENGTH_SHORT).show();

                        // we want to wait a second so that the mark position broadcast will work
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    Thread.sleep(1000);
                                } catch (Exception e) {

                                }
                                sharedPrefs.edit().putInt("current_account", 2).commit();
                                sharedPrefs.edit().remove("new_notifications").remove("new_retweets")
                                        .remove("new_favorites").remove("new_follows").commit();
                                AppSettings.invalidate();
                                finish();
                                Intent next = new Intent(context, MainActivity.class);
                                startActivity(next);
                            }
                        }).start();

                    }
                }
            });
        } else {
            name2.setText(sharedPrefs.getString("twitter_users_name_1", ""));
            screenname2.setText("@" + sharedPrefs.getString("twitter_screen_name_1", ""));
            try {
                if (settings.roundContactImages) {
                    //proPic2.loadImage(sharedPrefs.getString("profile_pic_url_1", ""), true, null, NetworkedCacheableImageView.CIRCLE);
                    ImageUtils.loadCircleImage(context, proPic2, sharedPrefs.getString("profile_pic_url_1", ""),
                            mCache);
                } else {
                    //proPic2.loadImage(sharedPrefs.getString("profile_pic_url_1", ""), true, null);
                    ImageUtils.loadImage(context, proPic2, sharedPrefs.getString("profile_pic_url_1", ""),
                            mCache);
                }
            } catch (Exception e) {

            }
            secondAccount.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (canSwitch) {
                        context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH_SERVICE"));
                        context.sendBroadcast(new Intent("com.klinker.android.twitter.MARK_POSITION")
                                .putExtra("current_account", current));

                        Toast.makeText(context, "Preparing to switch", Toast.LENGTH_SHORT).show();
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    Thread.sleep(1000);
                                } catch (Exception e) {

                                }

                                sharedPrefs.edit().putInt("current_account", 1).commit();
                                sharedPrefs.edit().remove("new_notifications").remove("new_retweets")
                                        .remove("new_favorites").remove("new_follows").commit();
                                AppSettings.invalidate();
                                finish();
                                Intent next = new Intent(context, MainActivity.class);
                                startActivity(next);
                            }
                        }).start();
                    }
                }
            });
        }
    }

    statusBar = findViewById(R.id.activity_status_bar);

    statusBarHeight = Utils.getStatusBarHeight(context);
    navBarHeight = Utils.getNavBarHeight(context);

    try {
        RelativeLayout.LayoutParams statusParams = (RelativeLayout.LayoutParams) statusBar.getLayoutParams();
        statusParams.height = statusBarHeight;
        statusBar.setLayoutParams(statusParams);
    } catch (Exception e) {
        try {
            LinearLayout.LayoutParams statusParams = (LinearLayout.LayoutParams) statusBar.getLayoutParams();
            statusParams.height = statusBarHeight;
            statusBar.setLayoutParams(statusParams);
        } catch (Exception x) {
            // in the trends
        }
    }

    View navBarSeperater = findViewById(R.id.nav_bar_seperator);

    if (translucent && Utils.hasNavBar(context)) {
        try {
            RelativeLayout.LayoutParams navParams = (RelativeLayout.LayoutParams) navBarSeperater
                    .getLayoutParams();
            navParams.height = navBarHeight;
            navBarSeperater.setLayoutParams(navParams);
        } catch (Exception e) {
            try {
                LinearLayout.LayoutParams navParams = (LinearLayout.LayoutParams) navBarSeperater
                        .getLayoutParams();
                navParams.height = navBarHeight;
                navBarSeperater.setLayoutParams(navParams);
            } catch (Exception x) {
                // in the trends
            }
        }
    }

    if (translucent) {
        if (Utils.hasNavBar(context)) {
            View footer = new View(context);
            footer.setOnClickListener(null);
            footer.setOnLongClickListener(null);
            ListView.LayoutParams params = new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT,
                    Utils.getNavBarHeight(context));
            footer.setLayoutParams(params);
            drawerList.addFooterView(footer);
            drawerList.setFooterDividersEnabled(false);
        }

        View drawerStatusBar = findViewById(R.id.drawer_status_bar);
        LinearLayout.LayoutParams status2Params = (LinearLayout.LayoutParams) drawerStatusBar.getLayoutParams();
        status2Params.height = statusBarHeight;
        drawerStatusBar.setLayoutParams(status2Params);
        drawerStatusBar.setVisibility(View.VISIBLE);

        statusBar.setVisibility(View.VISIBLE);

        drawerStatusBar = findViewById(R.id.drawer_status_bar_2);
        status2Params = (LinearLayout.LayoutParams) drawerStatusBar.getLayoutParams();
        status2Params.height = statusBarHeight;
        drawerStatusBar.setLayoutParams(status2Params);
        drawerStatusBar.setVisibility(View.VISIBLE);
    }

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
            || getResources().getBoolean(R.bool.isTablet)) {
        actionBar.setDisplayHomeAsUpEnabled(false);
    }

    if (!settings.pushNotifications) {
        try {
            mDrawerLayout.setDrawerLockMode(NotificationDrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.END);
        } catch (Exception e) {
            // no drawer?
        }
    } else {
        try {
            if (Build.VERSION.SDK_INT < 18 && DrawerActivity.settings.uiExtras) {
                View viewHeader2 = ((Activity) context).getLayoutInflater().inflate(R.layout.ab_header, null);
                notificationList.addHeaderView(viewHeader2, null, false);
                notificationList.setHeaderDividersEnabled(false);
            }
        } catch (Exception e) {
            // i don't know why it does this to be honest...
        }

        notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource.getInstance(context)
                .getUnreadCursor(DrawerActivity.settings.currentAccount));
        try {
            notificationList.setAdapter(notificationAdapter);
        } catch (Exception e) {

        }

        View viewHeader = ((Activity) context).getLayoutInflater().inflate(R.layout.interactions_footer_1,
                null);
        notificationList.addFooterView(viewHeader, null, false);
        oldInteractions = (HoloTextView) findViewById(R.id.old_interactions_text);
        readButton = (ImageView) findViewById(R.id.read_button);

        LinearLayout footer = (LinearLayout) viewHeader.findViewById(R.id.footer);
        footer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (oldInteractions.getText().toString()
                        .equals(getResources().getString(R.string.old_interactions))) {
                    oldInteractions.setText(getResources().getString(R.string.new_interactions));
                    readButton.setImageResource(closedMailResource);

                    notificationList.disableSwipeToDismiss();

                    notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource
                            .getInstance(context).getCursor(DrawerActivity.settings.currentAccount));
                } else {
                    oldInteractions.setText(getResources().getString(R.string.old_interactions));
                    readButton.setImageResource(openMailResource);

                    notificationList.enableSwipeToDismiss();

                    notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource
                            .getInstance(context).getUnreadCursor(DrawerActivity.settings.currentAccount));
                }

                notificationList.setAdapter(notificationAdapter);
            }
        });

        if (DrawerActivity.translucent) {
            if (Utils.hasNavBar(context)) {
                View nav = new View(context);
                nav.setOnClickListener(null);
                nav.setOnLongClickListener(null);
                ListView.LayoutParams params = new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT,
                        Utils.getNavBarHeight(context));
                nav.setLayoutParams(params);
                notificationList.addFooterView(nav);
                notificationList.setFooterDividersEnabled(false);
            }
        }

        notificationList.setDismissCallback(new EnhancedListView.OnDismissCallback() {
            @Override
            public EnhancedListView.Undoable onDismiss(EnhancedListView listView, int position) {
                Log.v("talon_interactions_delete", "position to delete: " + position);
                InteractionsDataSource data = InteractionsDataSource.getInstance(context);
                data.markRead(settings.currentAccount, position);
                notificationAdapter = new InteractionsCursorAdapter(context,
                        data.getUnreadCursor(DrawerActivity.settings.currentAccount));
                notificationList.setAdapter(notificationAdapter);

                oldInteractions.setText(getResources().getString(R.string.old_interactions));
                readButton.setImageResource(openMailResource);

                if (notificationAdapter.getCount() == 0) {
                    setNotificationFilled(false);
                }

                return null;
            }
        });

        notificationList.enableSwipeToDismiss();
        notificationList.setSwipeDirection(EnhancedListView.SwipeDirection.START);

        notificationList
                .setOnItemClickListener(new InteractionClickListener(context, mDrawerLayout, mViewPager));
    }
}