Example usage for android.graphics.drawable ColorDrawable ColorDrawable

List of usage examples for android.graphics.drawable ColorDrawable ColorDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable ColorDrawable ColorDrawable.

Prototype

public ColorDrawable(@ColorInt int color) 

Source Link

Document

Creates a new ColorDrawable with the specified color.

Usage

From source file:com.luckybuy.ctrls.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//from   w ww. j  ava2  s  .  c om
 */
protected RadioButton createDefaultTabView(Context context) {
    RadioButton rbTab = new RadioButton(context);
    rbTab.setGravity(Gravity.CENTER);
    rbTab.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabTextSize);
    rbTab.setTypeface(Typeface.DEFAULT_BOLD);
    rbTab.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT));
    if (mTabLayoutEven) {
        LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(0,
                ViewGroup.LayoutParams.MATCH_PARENT, 1);
        rbTab.setLayoutParams(layoutParams);
    }
    if (mTabColorStateList != -1) {
        rbTab.setTextColor(getResources().getColorStateList(mTabColorStateList));
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        rbTab.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        rbTab.setAllCaps(true);
    }

    int padding = (int) (mTabTextPadding * getResources().getDisplayMetrics().density);
    rbTab.setPadding(padding, 0, padding, 0);

    return rbTab;
}

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++;// 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:arun.com.chromer.util.ColorUtil.java

@NonNull
public static Drawable getRippleDrawableCompat(final @ColorInt int color) {
    if (Utils.isLollipopAbove()) {
        return new RippleDrawable(ColorStateList.valueOf(color), null, null);
    }/*  w ww  .ja  v  a 2 s. co  m*/
    int translucentColor = ColorUtils.setAlphaComponent(color, 0x44);
    StateListDrawable stateListDrawable = new StateListDrawable();
    int[] states = new int[] { android.R.attr.state_pressed };
    stateListDrawable.addState(states, new ColorDrawable(translucentColor));
    return stateListDrawable;
}

From source file:com.heneryh.aquanotes.ui.controllers.OutletsDataAdapter.java

/** {@inheritDoc} */
@Override/*from   ww w  .  j  a  va  2s.c o m*/
public void bindView(View view, Context context, Cursor cursor) {

    String outletName = cursor.getString(OutletDataViewQuery.NAME);
    ((TextView) view.findViewById(R.id.outlet_title)).setText(outletName);

    String deviceId = cursor.getString(OutletDataViewQuery.DEVICE_ID);
    ((TextView) view.findViewById(R.id.outlet_subtitle)).setText(deviceId);

    Spinner spinner = (Spinner) view.findViewById(R.id.spin);
    spinner.setAdapter(adapter);

    Integer controllerId = cursor.getInt(OutletDataViewQuery.CONTROLLER_ID);

    spinner.setOnItemSelectedListener(new myOnItemSelectedListener(outletName, controllerId));

    // Assign track color to visible block
    String val = cursor.getString(OutletDataViewQuery.VALUE);
    final ImageView iconView = (ImageView) view.findViewById(android.R.id.icon1);
    Resources res = mActivity.getResources();

    ////  Axx = Auto-On or Auto-Off
    ////  OFF = Manual Off
    ////  ON = Manual On

    if (val.equalsIgnoreCase("AON")) {
        iconView.setImageDrawable(res.getDrawable(R.drawable.on));
        spinner.setSelection(0);
    } else if (val.equalsIgnoreCase("AOF")) {
        iconView.setImageDrawable(res.getDrawable(R.drawable.off));
        spinner.setSelection(0);
    } else if (val.equalsIgnoreCase("OFF")) {
        iconView.setImageDrawable(res.getDrawable(R.drawable.off));
        spinner.setSelection(1);
    } else if (val.equalsIgnoreCase("ON")) {
        iconView.setImageDrawable(res.getDrawable(R.drawable.on));
        spinner.setSelection(2);
    } else {
        iconView.setImageDrawable(new ColorDrawable(Color.BLUE));
    }
}

From source file:com.krayzk9s.imgurholo.tools.ImageUtils.java

public static void fullscreen(android.support.v4.app.Fragment fragment, JSONParcelable imageData,
        PopupWindow popupWindow, View mainView) {
    popupWindow.setBackgroundDrawable(new ColorDrawable(0x80000000));
    popupWindow.setFocusable(true);/* w  w w.  ja v  a2  s .co m*/
    popupWindow.setWindowLayoutMode(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    final ZoomableImageView zoomableImageView = new ZoomableImageView(fragment.getActivity());
    popupWindow.setContentView(zoomableImageView);
    popupWindow.showAtLocation(mainView, Gravity.TOP, 0, 0);
    LoadImageAsync loadImageAsync = new LoadImageAsync(zoomableImageView, imageData);
    loadImageAsync.execute();
}

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

private static Drawable createImageViewNormalBg(int colorControlHighlight) {
    StateListDrawable sld = new StateListDrawable();
    sld.addState(new int[] { android.R.attr.state_pressed }, createImageViewShape(colorControlHighlight));
    sld.addState(new int[] {}, new ColorDrawable(Color.TRANSPARENT));
    return sld;//w w w  .j  a va2  s  . c  om
}

From source file:com.mediatek.galleryfeature.stereo.segment.background.StereoBackgroundActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_ACTION_BAR);
    requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

    // exit if file to edit has been deleted @{
    // it mainly aims to handle language switch or LCA case here
    boolean needExit = finishIfInvalidUri();
    mNeedCheckInvalid = false;//from   www. j a va2 s  .c  o  m
    if (needExit) {
        return;
    }

    // avoid flash when launching
    getWindow().setBackgroundDrawable(new ColorDrawable(0));

    loadXML();

    mMasterImage = new MainImageMaster(this);
    mImageShowBackground.setImageMaster(mMasterImage);

    loadMainBitmapAsync();

    loadThumbnails();

    loadMainPanel();
}

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  . jav  a  2 s  .  c  om
        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));
    }
}

From source file:com.klinker.android.twitter.activities.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++;/*  ww  w .j av  a  2 s. c  o 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 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
    }

    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 || !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 = ((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));
    }
}

From source file:com.android.deskclock.alarms.AlarmActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final long instanceId = AlarmInstance.getId(getIntent().getData());
    mAlarmInstance = AlarmInstance.getInstance(getContentResolver(), instanceId);
    if (mAlarmInstance == null) {
        // The alarm was deleted before the activity got created, so just finish()
        LogUtils.e(LOGTAG, "Error displaying alarm for intent: %s", getIntent());
        finish();/*ww w .j  a va  2 s  .  c  o  m*/
        return;
    } else if (mAlarmInstance.mAlarmState != AlarmInstance.FIRED_STATE) {
        LogUtils.i(LOGTAG, "Skip displaying alarm for instance: %s", mAlarmInstance);
        finish();
        return;
    }

    LogUtils.i(LOGTAG, "Displaying alarm for instance: %s", mAlarmInstance);

    // Get the volume/camera button behavior setting
    mVolumeBehavior = Utils.getDefaultSharedPreferences(this).getString(SettingsActivity.KEY_VOLUME_BUTTONS,
            SettingsActivity.DEFAULT_VOLUME_BEHAVIOR);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);

    // Hide navigation bar to minimize accidental tap on Home key
    hideNavigationBar();

    // Close dialogs and window shade, so this is fully visible
    sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

    // In order to allow tablets to freely rotate and phones to stick
    // with "nosensor" (use default device orientation) we have to have
    // the manifest start with an orientation of unspecified" and only limit
    // to "nosensor" for phones. Otherwise we get behavior like in b/8728671
    // where tablets start off in their default orientation and then are
    // able to freely rotate.
    if (!getResources().getBoolean(R.bool.config_rotateAlarmAlert)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    }

    mAccessibilityManager = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);

    setContentView(R.layout.alarm_activity);

    mAlertView = (ViewGroup) findViewById(R.id.alert);
    mAlertTitleView = (TextView) mAlertView.findViewById(R.id.alert_title);
    mAlertInfoView = (TextView) mAlertView.findViewById(R.id.alert_info);

    mContentView = (ViewGroup) findViewById(R.id.content);
    mAlarmButton = (ImageView) mContentView.findViewById(R.id.alarm);
    mSnoozeButton = (ImageView) mContentView.findViewById(R.id.snooze);
    mDismissButton = (ImageView) mContentView.findViewById(R.id.dismiss);
    mHintView = (TextView) mContentView.findViewById(R.id.hint);

    final TextView titleView = (TextView) mContentView.findViewById(R.id.title);
    final TextClock digitalClock = (TextClock) mContentView.findViewById(R.id.digital_clock);
    final CircleView pulseView = (CircleView) mContentView.findViewById(R.id.pulse);

    titleView.setText(mAlarmInstance.getLabelOrDefault(this));
    Utils.setTimeFormat(this, digitalClock);

    mCurrentHourColor = Utils.getCurrentHourColor();
    getWindow().setBackgroundDrawable(new ColorDrawable(mCurrentHourColor));

    mAlarmButton.setOnTouchListener(this);
    mSnoozeButton.setOnClickListener(this);
    mDismissButton.setOnClickListener(this);

    mAlarmAnimator = AnimatorUtils.getScaleAnimator(mAlarmButton, 1.0f, 0.0f);
    mSnoozeAnimator = getButtonAnimator(mSnoozeButton, Color.WHITE);
    mDismissAnimator = getButtonAnimator(mDismissButton, mCurrentHourColor);
    mPulseAnimator = ObjectAnimator.ofPropertyValuesHolder(pulseView,
            PropertyValuesHolder.ofFloat(CircleView.RADIUS, 0.0f, pulseView.getRadius()),
            PropertyValuesHolder.ofObject(CircleView.FILL_COLOR, AnimatorUtils.ARGB_EVALUATOR,
                    ColorUtils.setAlphaComponent(pulseView.getFillColor(), 0)));
    mPulseAnimator.setDuration(PULSE_DURATION_MILLIS);
    mPulseAnimator.setInterpolator(PULSE_INTERPOLATOR);
    mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE);
    mPulseAnimator.start();
}